Skip to content

Commit

Permalink
PEVM-fix: assesslist append and optimize mergeSlotDB (#168)
Browse files Browse the repository at this point in the history
  • Loading branch information
sunny2022da authored Sep 10, 2024
1 parent 1b233e1 commit 96c4ba0
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 2 deletions.
33 changes: 33 additions & 0 deletions core/state/access_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,3 +134,36 @@ func (al *accessList) DeleteSlot(address common.Address, slot common.Hash) {
func (al *accessList) DeleteAddress(address common.Address) {
delete(al.addresses, address)
}

// Copy creates an independent copy of an accessList.
func (dest *accessList) Append(src *accessList) *accessList {
for addr, sIdx := range src.addresses {
if i, present := dest.addresses[addr]; present {
// dest already has addr.
if sIdx >= 0 {
// has slot in list
if i == -1 {
dest.addresses[addr] = len(dest.slots)
slotmap := src.slots[sIdx]
dest.slots = append(dest.slots, slotmap)
} else {
slotmap := src.slots[sIdx]
for hash := range slotmap {
if _, ok := dest.slots[i][hash]; !ok {
dest.slots[i][hash] = struct{}{}
}
}
}
}
} else {
// dest doesn't have the address
dest.addresses[addr] = -1
if sIdx >= 0 {
dest.addresses[addr] = len(dest.slots)
slotmap := src.slots[sIdx]
dest.slots = append(dest.slots, slotmap)
}
}
}
return dest
}
2 changes: 1 addition & 1 deletion core/state/state_object.go
Original file line number Diff line number Diff line change
Expand Up @@ -1003,7 +1003,7 @@ func (s *stateObject) GetCommittedStateNoUpdate(key common.Hash) common.Hash {
func (s *stateObject) fixUpOriginAndResetPendingStorage() {
if s.db.isParallel && s.db.parallel.isSlotDB {
mainDB := s.db.parallel.baseStateDB
origObj := mainDB.getStateObjectNoUpdate(s.address)
origObj := mainDB.getStateObject(s.address)
s.storageRecordsLock.Lock()
if origObj != nil && origObj.originStorage.Length() != 0 {
// There can be racing issue with CopyForSlot/LightCopy
Expand Down
3 changes: 2 additions & 1 deletion core/state/statedb.go
Original file line number Diff line number Diff line change
Expand Up @@ -2653,8 +2653,9 @@ func (s *StateDB) MergeSlotDB(slotDb *ParallelStateDB, slotReceipt *types.Receip
for hash, preimage := range slotDb.preimages {
s.preimages[hash] = preimage
}

if s.accessList != nil && slotDb.accessList != nil {
s.accessList = slotDb.accessList.Copy()
s.accessList.Append(slotDb.accessList)
}

for k := range slotDb.snapDestructs {
Expand Down

0 comments on commit 96c4ba0

Please sign in to comment.