diff --git a/core/state/state_object.go b/core/state/state_object.go index 66be5becf6..707e42dbaa 100644 --- a/core/state/state_object.go +++ b/core/state/state_object.go @@ -74,6 +74,7 @@ type stateObject struct { originStorage Storage // Storage cache of original entries to dedup rewrites pendingStorage Storage // Storage entries that need to be flushed to disk, at the end of an entire block dirtyStorage Storage // Storage entries that have been modified in the current transaction execution, reset for every transaction + readStorage []common.Hash // Cache flags. dirtyCode bool // true if the code was updated @@ -111,6 +112,7 @@ func newObject(db *StateDB, address common.Address, acct *types.StateAccount) *s originStorage: make(Storage), pendingStorage: make(Storage), dirtyStorage: make(Storage), + readStorage: []common.Hash{}, } } @@ -256,12 +258,23 @@ func (s *stateObject) finalise(prefetch bool) { slotsToPrefetch = append(slotsToPrefetch, common.CopyBytes(key[:])) // Copy needed for closure } } + + // prefetch slots that are read so that they will appear in witness + for _, value := range s.readStorage { + if _, ok := s.dirtyStorage[value]; !ok { + slotsToPrefetch = append(slotsToPrefetch, common.CopyBytes(value[:])) + } + } + if s.db.prefetcher != nil && prefetch && len(slotsToPrefetch) > 0 && s.data.Root != types.EmptyRootHash { s.db.prefetcher.prefetch(s.addrHash, s.data.Root, s.address, slotsToPrefetch) } if len(s.dirtyStorage) > 0 { s.dirtyStorage = make(Storage) } + if len(s.readStorage) > 0 { + s.readStorage = []common.Hash{} + } } // updateTrie is responsible for persisting cached storage changes into the @@ -394,6 +407,7 @@ func (s *stateObject) commit() (*trienode.NodeSet, map[string][]byte, error) { return nil, nil, err } s.data.Root = root + fmt.Printf("node count %d\n", len(nodes.Leaves)) // Update original account data after commit s.origin = s.data.Copy() diff --git a/core/state/statedb.go b/core/state/statedb.go index c5e5f720d1..12075d3e9d 100644 --- a/core/state/statedb.go +++ b/core/state/statedb.go @@ -1232,6 +1232,9 @@ func (s *StateDB) Commit(block uint64, deleteEmptyObjects bool) (common.Hash, er if err != nil { return common.Hash{}, err } + if set != nil { + fmt.Printf("leaf count: %d\n", len(set.Leaves)) + } // Merge the dirty nodes of account trie into global set if set != nil { if err := nodes.Merge(set); err != nil {