diff --git a/core/state/statedb.go b/core/state/statedb.go index 7c20c8fb1f5c..6b96abed0eb4 100644 --- a/core/state/statedb.go +++ b/core/state/statedb.go @@ -146,6 +146,9 @@ func New(root common.Hash, db Database, snaps *snapshot.Tree) (*StateDB, error) } sdb := &StateDB{ unexpectedBalanceDelta: new(big.Int), + userWasms: make(UserWasms), + openWasmPages: 0, + everWasmPages: 0, db: db, trie: tr, @@ -725,6 +728,9 @@ func (s *StateDB) Copy() *StateDB { // Copy all the basic fields, initialize the memory ones state := &StateDB{ unexpectedBalanceDelta: new(big.Int).Set(s.unexpectedBalanceDelta), + userWasms: make(UserWasms, len(s.userWasms)), + openWasmPages: s.openWasmPages, + everWasmPages: s.everWasmPages, db: s.db, trie: s.db.CopyTrie(s.trie), @@ -796,6 +802,11 @@ func (s *StateDB) Copy() *StateDB { state.accessList = s.accessList.Copy() state.transientStorage = s.transientStorage.Copy() + // Arbitrum: copy wasm calls + for call, wasm := range s.userWasms { + state.userWasms[call] = wasm + } + // If there's a prefetcher running, make an inactive copy of it that can // only access data but does not actively preload (since the user will not // know that they need to explicitly terminate an active copy). @@ -989,6 +1000,10 @@ func (s *StateDB) IntermediateRoot(deleteEmptyObjects bool) common.Hash { func (s *StateDB) SetTxContext(thash common.Hash, ti int) { s.thash = thash s.txIndex = ti + + // Arbitrum: clear memory charging state for new tx + s.openWasmPages = 0 + s.everWasmPages = 0 } func (s *StateDB) clearJournalAndRefund() {