Skip to content

Commit

Permalink
address PR comments
Browse files Browse the repository at this point in the history
  • Loading branch information
ganeshvanahalli committed Dec 11, 2024
1 parent e9a5f8a commit 6205f5e
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 11 deletions.
17 changes: 6 additions & 11 deletions core/state/statedb.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ package state

import (
"bytes"
"errors"
"fmt"
"maps"
"math/big"
Expand Down Expand Up @@ -75,8 +74,6 @@ func (m *mutation) isDelete() bool {
return m.typ == deletion
}

var ErrArbTxFilter error = errors.New("internal error")

// StateDB structs within the ethereum protocol are used to store anything
// within the merkle trie. StateDBs take care of caching and storing
// nested states. It's the general query interface to retrieve:
Expand All @@ -90,7 +87,6 @@ var ErrArbTxFilter error = errors.New("internal error")
// commit states.
type StateDB struct {
arbExtraData *ArbitrumExtraData // must be a pointer - can't be a part of StateDB allocation, otherwise its finalizer might not get called
arbTxFilter bool

db Database
prefetcher *triePrefetcher
Expand Down Expand Up @@ -225,13 +221,11 @@ func New(root common.Hash, db Database, snaps *snapshot.Tree) (*StateDB, error)
}

func (s *StateDB) FilterTx() {
if !s.arbTxFilter {
s.arbTxFilter = true
}
s.arbExtraData.arbTxFilter = true
}

func (s *StateDB) IsTxFiltered() bool {
return s.arbTxFilter
return s.arbExtraData.arbTxFilter
}

// SetLogger sets the logger for account update hooks.
Expand Down Expand Up @@ -751,6 +745,7 @@ func (s *StateDB) Copy() *StateDB {
recentWasms: s.arbExtraData.recentWasms.Copy(),
openWasmPages: s.arbExtraData.openWasmPages,
everWasmPages: s.arbExtraData.everWasmPages,
arbTxFilter: s.arbExtraData.arbTxFilter,
},

db: s.db,
Expand Down Expand Up @@ -834,7 +829,7 @@ func (s *StateDB) Copy() *StateDB {
func (s *StateDB) Snapshot() int {
id := s.nextRevisionId
s.nextRevisionId++
s.validRevisions = append(s.validRevisions, revision{id, s.journal.length(), new(big.Int).Set(s.arbExtraData.unexpectedBalanceDelta), s.arbTxFilter})
s.validRevisions = append(s.validRevisions, revision{id, s.journal.length(), new(big.Int).Set(s.arbExtraData.unexpectedBalanceDelta), s.arbExtraData.arbTxFilter})
return id
}

Expand All @@ -850,7 +845,7 @@ func (s *StateDB) RevertToSnapshot(revid int) {
revision := s.validRevisions[idx]
snapshot := revision.journalIndex
s.arbExtraData.unexpectedBalanceDelta = new(big.Int).Set(revision.unexpectedBalanceDelta)
s.arbTxFilter = revision.arbTxFilter
s.arbExtraData.arbTxFilter = revision.arbTxFilter

// Replay the journal to undo changes and remove invalidated snapshots
s.journal.revert(s, snapshot)
Expand Down Expand Up @@ -1236,7 +1231,7 @@ func (s *StateDB) GetTrie() Trie {
// The associated block number of the state transition is also provided
// for more chain context.
func (s *StateDB) Commit(block uint64, deleteEmptyObjects bool) (common.Hash, error) {
if s.arbTxFilter {
if s.arbExtraData.arbTxFilter {
return common.Hash{}, ErrArbTxFilter
}
// Short circuit in case any database failure occurred earlier.
Expand Down
3 changes: 3 additions & 0 deletions core/state/statedb_arbitrum.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,13 +164,16 @@ func (s *StateDB) Deterministic() bool {
return s.deterministic
}

var ErrArbTxFilter error = errors.New("internal error")

type ArbitrumExtraData struct {
unexpectedBalanceDelta *big.Int // total balance change across all accounts
userWasms UserWasms // user wasms encountered during execution
openWasmPages uint16 // number of pages currently open
everWasmPages uint16 // largest number of pages ever allocated during this tx's execution
activatedWasms map[common.Hash]ActivatedWasm // newly activated WASMs
recentWasms RecentWasms
arbTxFilter bool
}

func (s *StateDB) SetArbFinalizer(f func(*ArbitrumExtraData)) {
Expand Down

0 comments on commit 6205f5e

Please sign in to comment.