Skip to content

Commit

Permalink
PEVM-fix: clear useless legacy pevm code (bnb-chain#216)
Browse files Browse the repository at this point in the history
  • Loading branch information
sunny2022da committed Nov 14, 2024
1 parent fd1d062 commit 5c7ee6d
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 279 deletions.
27 changes: 3 additions & 24 deletions core/state/journal.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,16 +153,7 @@ type (

func (ch createObjectChange) revert(dber StateDBer) {
s := dber.getBaseStateDB()
if s.parallel.isSlotDB {
delete(s.parallel.dirtiedStateObjectsInSlot, *ch.account)
delete(s.parallel.addrStateChangesInSlot, *ch.account)
delete(s.parallel.nonceChangesInSlot, *ch.account)
delete(s.parallel.balanceChangesInSlot, *ch.account)
delete(s.parallel.codeChangesInSlot, *ch.account)
delete(s.parallel.kvChangesInSlot, *ch.account)
} else {
s.deleteStateObj(*ch.account)
}
s.deleteStateObj(*ch.account)
delete(s.stateObjectsDirty, *ch.account)
}

Expand All @@ -172,25 +163,13 @@ func (ch createObjectChange) dirtied() *common.Address {

func (ch resetObjectChange) revert(dber StateDBer) {
s := dber.getBaseStateDB()
if s.parallel.isSlotDB {
// ch.prev must be from dirtiedStateObjectsInSlot, put it back
s.parallel.dirtiedStateObjectsInSlot[ch.prev.address] = ch.prev
} else {
// ch.prev was got from main DB, put it back to main DB.
s.setStateObject(ch.prev)
}
// ch.prev was got from main DB, put it back to main DB.
s.setStateObject(ch.prev)

if !ch.prevdestruct {
s.stateObjectDestructLock.Lock()
s.removeStateObjectsDestruct(ch.prev.address)
s.stateObjectDestructLock.Unlock()
if s.isParallel && s.parallel.isSlotDB {
s.snapParallelLock.Lock()
if _, ok := s.snapDestructs[ch.prev.address]; ok {
delete(s.snapDestructs, ch.prev.address)
}
s.snapParallelLock.Unlock()
}
}
if ch.prevAccount != nil {
s.accounts[ch.prev.addrHash] = ch.prevAccount
Expand Down
83 changes: 0 additions & 83 deletions core/state/state_object.go
Original file line number Diff line number Diff line change
Expand Up @@ -325,15 +325,6 @@ func (s *stateObject) GetState(key common.Hash) common.Hash {
// Otherwise return the entry's original value
result := s.GetCommittedState(key)
// Record first read for conflict verify
if s.db.isParallel && s.db.parallel.isSlotDB {
addr := s.address
if s.db.parallel.kvReadsInSlot[addr] == nil {
s.db.parallel.kvReadsInSlot[addr] = newStorage(false)
}
if _, ok := s.db.parallel.kvReadsInSlot[addr].GetValue(key); !ok {
s.db.parallel.kvReadsInSlot[addr].StoreValue(key, result)
}
}
return result
}

Expand All @@ -348,32 +339,6 @@ func (s *stateObject) GetCommittedState(key common.Hash) common.Hash {
return value
}

if s.db.isParallel && s.db.parallel.isSlotDB {
// Need to confirm the object is not destructed in unconfirmed db and resurrected in this tx.
// otherwise there is an issue for cases like:
// B0: TX0 --> createAccount @addr1 -- merged into DB
// B1: Tx1 and Tx2
// Tx1 account@addr1, setState(key0), setState(key1) selfDestruct -- unconfirmed
// Tx2 recreate account@addr2, setState(key0) -- executing
// TX2 GetState(addr2, key1) ---
// key1 is never set after recurrsect, and should not return state in trie as it destructed in unconfirmed
if s.db.parallel.useDAG != true {
obj, exist := s.dbItf.GetStateObjectFromUnconfirmedDB(s.address)
if exist {
if obj.deleted || obj.selfDestructed {
return common.Hash{}
}
}
}
// also test whether the object is in mainDB and deleted.
pdb := s.db.parallel.baseStateDB
obj, exist := pdb.getStateObjectFromStateObjects(s.address)
if exist {
if obj.deleted || obj.selfDestructed {
return common.Hash{}
}
}
}
// If the object was destructed in *this* block (and potentially resurrected),
// the storage has been cleared out, and we should *not* consult the previous
// database about any storage values. The only possible alternatives are:
Expand Down Expand Up @@ -451,10 +416,6 @@ func (s *stateObject) SetState(key, value common.Hash) {
key: key,
prevalue: prev,
})

if s.db.isParallel && s.db.parallel.isSlotDB {
s.db.parallel.kvChangesInSlot[s.address][key] = struct{}{}
}
s.setState(key, value)
}

Expand Down Expand Up @@ -529,14 +490,6 @@ func (s *stateObject) finaliseRWSet() {
// storage change at all.
func (s *stateObject) updateTrie() (Trie, error) {
maindb := s.db
if s.db.isParallel && s.db.parallel.isSlotDB {
// we need to fixup the origin storage with the mainDB. otherwise the changes maybe problematic since the origin
// is wrong.
maindb = s.db.parallel.baseStateDB
// For dirty/pending/origin Storage access and update.
s.storageRecordsLock.Lock()
defer s.storageRecordsLock.Unlock()
}
// Make sure all dirty slots are finalized into the pending storage area
s.finalise(false)

Expand Down Expand Up @@ -973,39 +926,3 @@ func (s *stateObject) GetCommittedStateNoUpdate(key common.Hash) common.Hash {
}
return value
}

// fixUpOriginAndResetPendingStorage is used for slot object only, the target is to fix up the origin storage of the
// object with the latest mainDB. And reset the pendingStorage as the execution recorded the changes in dirty and the
// dirties will be merged to pending at finalise. so the current pendingStorage contains obsoleted info mainly from
// lightCopy()
func (s *stateObject) fixUpOriginAndResetPendingStorage() {
if s.db.isParallel && s.db.parallel.isSlotDB {
mainDB := s.db.parallel.baseStateDB
origObj := mainDB.getStateObject(s.address)
s.storageRecordsLock.Lock()
if origObj != nil && origObj.originStorage.Length() != 0 {
// There can be racing issue with CopyForSlot/LightCopy
origObj.storageRecordsLock.RLock()
originStorage := origObj.originStorage.Copy()
origObj.storageRecordsLock.RUnlock()
// During the tx execution, the originStorage can be updated with GetCommittedState()
// But is never get updated for the already existed one as there is no finalise called in execution.
// so here get the latest object in MainDB, and update the object storage with
s.originStorage.Range(func(keyItf, valueItf interface{}) bool {
key := keyItf.(common.Hash)
value := valueItf.(common.Hash)
// Skip noop changes, persist actual changes
if _, ok := originStorage.GetValue(key); !ok {
originStorage.StoreValue(key, value)
}
return true
})
s.originStorage = originStorage
}
// isParallel is unnecessary since the pendingStorage for slotObject will be used serially from now on.
if s.pendingStorage.Length() > 0 {
s.pendingStorage = newStorage(false)
}
s.storageRecordsLock.Unlock()
}
}
Loading

0 comments on commit 5c7ee6d

Please sign in to comment.