Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Filter transaction #377

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 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 @@ -73,6 +74,16 @@ func (m *mutation) isDelete() bool {
return m.typ == deletion
}

type arbFiltered int

const (
unFiltered arbFiltered = iota
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry to be so picky, but since unfiltered is a single word in English. I'd either use unfiltered or notFiltered here.

txFiltered
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:
Expand All @@ -86,6 +97,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 arbFiltered

db Database
prefetcher *triePrefetcher
Expand Down Expand Up @@ -219,6 +231,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 == unFiltered {
s.arbTxFilter = txFiltered
if withBlock {
s.arbTxFilter = blockFiltered
}
}
}

func (s *StateDB) IsTxInvalid() bool {
return s.arbTxFilter == txFiltered
}

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

// Replay the journal to undo changes and remove invalidated snapshots
s.journal.revert(s, snapshot)
Expand Down Expand Up @@ -1220,6 +1248,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 == blockFiltered {
return common.Hash{}, ErrArbTxFilter
}
// 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
eljobe marked this conversation as resolved.
Show resolved Hide resolved
FilterTx(bool)
IsTxInvalid() bool

Deterministic() bool
Database() state.Database

Expand Down
Loading