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 10 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
16 changes: 15 additions & 1 deletion core/state/statedb.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ type revision struct {

// Arbitrum: track the total balance change across all accounts
unexpectedBalanceDelta *big.Int
arbTxFilter bool
}

type mutationType int
Expand Down Expand Up @@ -219,6 +220,14 @@ func New(root common.Hash, db Database, snaps *snapshot.Tree) (*StateDB, error)
return sdb, nil
}

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

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

// SetLogger sets the logger for account update hooks.
func (s *StateDB) SetLogger(l *tracing.Hooks) {
s.logger = l
Expand Down Expand Up @@ -736,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 @@ -819,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.validRevisions = append(s.validRevisions, revision{id, s.journal.length(), new(big.Int).Set(s.arbExtraData.unexpectedBalanceDelta), s.arbExtraData.arbTxFilter})
return id
}

Expand All @@ -835,6 +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.arbExtraData.arbTxFilter = revision.arbTxFilter

// Replay the journal to undo changes and remove invalidated snapshots
s.journal.revert(s, snapshot)
Expand Down Expand Up @@ -1220,6 +1231,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.arbExtraData.arbTxFilter {
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
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
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()
IsTxFiltered() bool

Deterministic() bool
Database() state.Database

Expand Down
Loading