diff --git a/core/state/statedb.go b/core/state/statedb.go index 7ad7ff7e6..c3534cabf 100644 --- a/core/state/statedb.go +++ b/core/state/statedb.go @@ -74,6 +74,15 @@ func (m *mutation) isDelete() bool { return m.typ == deletion } +type arbFiltered int + +const ( + txFiltered arbFiltered = 1 + iota + blockFiltered +) + +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: @@ -87,7 +96,7 @@ func (m *mutation) isDelete() bool { // 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 int + arbTxFilter arbFiltered db Database prefetcher *triePrefetcher @@ -223,15 +232,15 @@ func New(root common.Hash, db Database, snaps *snapshot.Tree) (*StateDB, error) func (s *StateDB) FilterTx(withBlock bool) { if s.arbTxFilter == 0 { - s.arbTxFilter = 1 + s.arbTxFilter = txFiltered if withBlock { - s.arbTxFilter = 2 + s.arbTxFilter = blockFiltered } } } func (s *StateDB) IsTxInvalid() bool { - return s.arbTxFilter == 1 + return s.arbTxFilter == txFiltered } // SetLogger sets the logger for account update hooks. @@ -850,7 +859,7 @@ func (s *StateDB) RevertToSnapshot(revid int) { revision := s.validRevisions[idx] snapshot := revision.journalIndex s.arbExtraData.unexpectedBalanceDelta = new(big.Int).Set(revision.unexpectedBalanceDelta) - if s.arbTxFilter == 1 { + if s.arbTxFilter == txFiltered { s.arbTxFilter = 0 } @@ -1238,8 +1247,8 @@ 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 == 2 { - return common.Hash{}, errors.New("internal error") + if s.arbTxFilter == blockFiltered { + return common.Hash{}, ErrArbTxFilter } // Short circuit in case any database failure occurred earlier. if s.dbErr != nil {