Skip to content

Commit

Permalink
refactored implementation of pluginStateUpdate injection
Browse files Browse the repository at this point in the history
  • Loading branch information
philip-morlier committed Oct 28, 2024
1 parent 64fd449 commit 9a37cee
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 28 deletions.
20 changes: 18 additions & 2 deletions core/state/statedb.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,6 @@ func New(root common.Hash, db Database, snaps *snapshot.Tree) (*StateDB, error)
if sdb.snaps != nil {
sdb.snap = sdb.snaps.Snapshot(root)
}

return sdb, nil
}

Expand Down Expand Up @@ -1661,6 +1660,7 @@ func (s *StateDB) commit(deleteEmptyObjects bool) (*stateUpdate, error) {
return nodes.Merge(set)
}
)

// Given that some accounts could be destroyed and then recreated within
// the same block, account deletions must be processed first. This ensures
// that the storage trie nodes deleted during destruction and recreated
Expand Down Expand Up @@ -1767,6 +1767,19 @@ func (s *StateDB) commitAndFlush(block uint64, deleteEmptyObjects bool) (*stateU
if err != nil {
return nil, err
}

// begin PluGeth injection
codeUpdates := make(map[common.Hash][]byte)
for _, code := range ret.codes {
if len(code.blob) > 0 {
// Empty code may or may not be included in this list by Geth based on
// factors I'm not certain of, so to normalize our pending batches,
// exclude empty blobs.
codeUpdates[code.hash] = code.blob
}
}
// end PluGeth injection

// Commit dirty contract code if any exists
if db := s.db.DiskDB(); db != nil && len(ret.codes) > 0 {
batch := db.NewBatch()
Expand All @@ -1780,8 +1793,11 @@ func (s *StateDB) commitAndFlush(block uint64, deleteEmptyObjects bool) (*stateU
if !ret.empty() {
// If snapshotting is enabled, update the snapshot tree with this new version
if s.snap != nil {
//begin PluGeth code injection
pluginStateUpdate(ret.root, ret.originRoot, s.snap, s.trie, ret.destructs, ret.accounts, ret.storages, codeUpdates)
//end PluGeth code injection
s.snap = nil

start := time.Now()
if err := s.snaps.Update(ret.root, ret.originRoot, ret.destructs, ret.accounts, ret.storages); err != nil {
log.Warn("Failed to update snapshot tree", "from", ret.originRoot, "to", ret.root, "err", err)
Expand Down
26 changes: 0 additions & 26 deletions core/state/xplugeth_hooks.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package state

import (
"fmt"
"bytes"
"time"

Expand All @@ -19,31 +18,6 @@ var (
acctCheckTimer = metrics.NewRegisteredTimer("plugeth/statedb/accounts/checks", nil)
)

type pluginSnapshot struct {
root common.Hash
}

// This function is being brought over from foundation to enable our producer plugin to work agnostically across networks.
func (s *StateDB) GetTrie() Trie {
return s.trie
}

func (s *pluginSnapshot) Root() common.Hash {
return s.root
}

func (s *pluginSnapshot) Account(hash common.Hash) (*types.SlimAccount, error) {
return nil, fmt.Errorf("not implemented")
}

func (s *pluginSnapshot) AccountRLP(hash common.Hash) ([]byte, error) {
return nil, fmt.Errorf("not implemented")
}

func (s *pluginSnapshot) Storage(accountHash, storageHash common.Hash) ([]byte, error) {
return nil, fmt.Errorf("not implemented")
}

type acctChecker struct {
snap snapshot.Snapshot
trie Trie
Expand Down

0 comments on commit 9a37cee

Please sign in to comment.