Manual touches to plugeth code to accommodate geth v1.13.0

This commit is contained in:
philip-morlier
2023-09-13 12:57:48 -07:00
parent bdc42a9128
commit 51c041850b
7 changed files with 95 additions and 31 deletions
+2 -2
View File
@@ -5,7 +5,7 @@ import (
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/log"
"github.com/ethereum/go-ethereum/plugins"
"github.com/ethereum/go-ethereum/core/state/snapshot"
"github.com/ethereum/go-ethereum/core/types"
"github.com/openrelayxyz/plugeth-utils/core"
)
@@ -17,7 +17,7 @@ func (s *pluginSnapshot) Root() common.Hash {
return s.root
}
func (s *pluginSnapshot) Account(hash common.Hash) (*snapshot.Account, error) {
func (s *pluginSnapshot) Account(hash common.Hash) (*types.SlimAccount, error) {
return nil, fmt.Errorf("not implemented")
}
+25 -17
View File
@@ -173,9 +173,7 @@ func New(root common.Hash, db Database, snaps *snapshot.Tree) (*StateDB, error)
if sdb.snap == nil {
log.Debug("Snapshots not availble. Using plugin snapshot.")
sdb.snap = &pluginSnapshot{root}
sdb.stateObjectsDestruct = make(map[common.Address]struct{})
sdb.snapAccounts = make(map[common.Hash][]byte)
sdb.snapStorage = make(map[common.Hash]map[common.Hash][]byte)
sdb.stateObjectsDestruct = make(map[common.Address]*types.StateAccount)
}
// End PluGeth section
return sdb, nil
@@ -1201,18 +1199,28 @@ func (s *StateDB) Commit(block uint64, deleteEmptyObjects bool) (common.Hash, er
codeUpdates := make(map[common.Hash][]byte)
// end PluGeth injection
for addr := range s.stateObjectsDirty {
if obj := s.stateObjects[addr]; !obj.deleted {
// Write any contract code associated with the state object
if obj.code != nil && obj.dirtyCode {
rawdb.WriteCode(codeWriter, common.BytesToHash(obj.CodeHash()), obj.code)
// begin PluGeth injection
codeUpdates[common.BytesToHash(obj.CodeHash())] = obj.code
// end PluGeth injection
obj.dirtyCode = false
}
// Write any storage changes in the state object to its storage trie
set, err := obj.commitTrie(s.db)
if err != nil {
obj := s.stateObjects[addr]
if obj.deleted {
continue
}
// Write any contract code associated with the state object
if obj.code != nil && obj.dirtyCode {
rawdb.WriteCode(codeWriter, common.BytesToHash(obj.CodeHash()), obj.code)
// begin PluGeth injection
codeUpdates[common.BytesToHash(obj.CodeHash())] = obj.code
// end PluGeth injection
obj.dirtyCode = false
}
// Write any storage changes in the state object to its storage trie
set, err := obj.commit()
if err != nil {
return common.Hash{}, err
}
// Merge the dirty nodes of storage trie into global set. It is possible
// that the account was destructed and then resurrected in the same block.
// In this case, the node set is shared by both accounts.
if set != nil {
if err := nodes.Merge(set); err != nil {
return common.Hash{}, err
}
updates, deleted := set.Size()
@@ -1261,10 +1269,10 @@ func (s *StateDB) Commit(block uint64, deleteEmptyObjects bool) (common.Hash, er
// Only update if there's a state transition (skip empty Clique blocks)
if parent := s.snap.Root(); parent != root {
//begin PluGeth code injection
pluginStateUpdate(root, parent, s.convertAccountSet(s.stateObjectsDestruct), s.snapAccounts, s.snapStorage, codeUpdates)
pluginStateUpdate(root, parent, s.convertAccountSet(s.stateObjectsDestruct), s.accounts, s.storages, codeUpdates)
if _, ok := s.snap.(*pluginSnapshot); !ok && s.snaps != nil { // This if statement (but not its content) was added by PluGeth
//end PluGeth injection
if err := s.snaps.Update(root, parent, s.convertAccountSet(s.stateObjectsDestruct), s.snapAccounts, s.snapStorage); err != nil {
if err := s.snaps.Update(root, parent, s.convertAccountSet(s.stateObjectsDestruct), s.accounts, s.storages); err != nil {
log.Warn("Failed to update snapshot tree", "from", parent, "to", root, "err", err)
}
// Keep 128 diff layers in the memory, persistent layer is 129th.