Skip to content

Commit

Permalink
Filter transaction
Browse files Browse the repository at this point in the history
  • Loading branch information
ganeshvanahalli committed Nov 22, 2024
1 parent 91a7a31 commit 4e387ee
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
21 changes: 21 additions & 0 deletions core/state/statedb.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package state

import (
"bytes"
"errors"
"fmt"
"maps"
"math/big"
Expand Down Expand Up @@ -86,6 +87,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

db Database
prefetcher *triePrefetcher
Expand Down Expand Up @@ -219,6 +221,19 @@ func New(root common.Hash, db Database, snaps *snapshot.Tree) (*StateDB, error)
return sdb, nil
}

func (s *StateDB) FilterTx(withBlock bool) {
if s.arbTxFilter == 0 {
s.arbTxFilter = 1
if withBlock {
s.arbTxFilter = 2
}
}
}

func (s *StateDB) IsTxValid() bool {
return s.arbTxFilter == 1
}

// SetLogger sets the logger for account update hooks.
func (s *StateDB) SetLogger(l *tracing.Hooks) {
s.logger = l
Expand Down Expand Up @@ -835,6 +850,9 @@ 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 {
s.arbTxFilter = 0
}

// Replay the journal to undo changes and remove invalidated snapshots
s.journal.revert(s, snapshot)
Expand Down Expand Up @@ -1220,6 +1238,9 @@ 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")
}
// Short circuit in case any database failure occurred earlier.
if s.dbErr != nil {
return common.Hash{}, fmt.Errorf("commit aborted due to earlier error: %v", s.dbErr)
Expand Down
4 changes: 4 additions & 0 deletions core/vm/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ type StateDB interface {
// Arbitrum: preserve old empty account behavior
CreateZombieIfDeleted(common.Address)

// Arbitrum
FilterTx(bool)
IsTxValid() bool

Deterministic() bool
Database() state.Database

Expand Down

0 comments on commit 4e387ee

Please sign in to comment.