Skip to content
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
32 changes: 23 additions & 9 deletions arbitrum/retryables/scheduled_txes.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,16 @@ import (
)

// RunScheduledTxes executes scheduled transactions (retryable redeems) including
// cascading redeems. When txFilterer is non-nil, touches addresses for filtering.
// cascading redeems. It runs when either gas estimation is active (to account for
// scheduled gas usage) or when txFilterer is non-nil (to execute scheduled txes
// and collect their touched addresses for address-based filtering).
func RunScheduledTxes(ctx context.Context, b core.NodeInterfaceBackendAPI, statedb *state.StateDB, header *types.Header, blockCtx vm.BlockContext, runCtx *core.MessageRunContext, result *core.ExecutionResult, txFilterer core.TxFilterer) (*core.ExecutionResult, error) {
// If we're not doing gas estimation and there's no tx filter, we don't need to run scheduled txes at all.
if !runCtx.IsGasEstimation() && txFilterer == nil {
return result, nil
}
Comment thread
diegoximenes marked this conversation as resolved.
scheduled := result.ScheduledTxes
for runCtx.IsGasEstimation() && len(scheduled) > 0 {
for len(scheduled) > 0 {
// This will panic if the scheduled tx is signed, but we only schedule unsigned ones
msg, err := core.TransactionToMessage(scheduled[0], types.NewArbitrumSigner(nil), header.BaseFee, runCtx)
if err != nil {
Expand All @@ -26,11 +32,14 @@ func RunScheduledTxes(ctx context.Context, b core.NodeInterfaceBackendAPI, state
txFilterer.TouchAddresses(statedb, scheduled[0], msg.From)
}

if result.UsedGas >= msg.GasLimit {
result.UsedGas -= msg.GasLimit
} else {
log.Warn("Scheduling tx used less gas than scheduled tx has available", "usedGas", result.UsedGas, "scheduledGas", msg.GasLimit)
result.UsedGas = 0
// For gas estimation, we want to account scheduled txes' gas usage
if runCtx.IsGasEstimation() {
Comment thread
diegoximenes marked this conversation as resolved.
if result.UsedGas >= msg.GasLimit {
result.UsedGas -= msg.GasLimit
} else {
log.Warn("Scheduling tx used less gas than scheduled tx has available", "usedGas", result.UsedGas, "scheduledGas", msg.GasLimit)
result.UsedGas = 0
}
}

evm := b.GetEVM(ctx, statedb, header, &vm.Config{NoBaseFee: true}, &blockCtx)
Expand All @@ -47,9 +56,14 @@ func RunScheduledTxes(ctx context.Context, b core.NodeInterfaceBackendAPI, state
return nil, vmerr
}
if scheduledTxResult.Failed() {
return scheduledTxResult, nil
if runCtx.IsGasEstimation() {
return scheduledTxResult, nil
}
return result, nil
}
if runCtx.IsGasEstimation() {
result.UsedGas += scheduledTxResult.UsedGas
}
result.UsedGas += scheduledTxResult.UsedGas
scheduled = append(scheduled[1:], scheduledTxResult.ScheduledTxes...)
}
return result, nil
Expand Down
7 changes: 4 additions & 3 deletions core/arbitrum_hooks.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,11 @@ var RenderRPCError func(data []byte) error
type TxFilterer interface {
// Setup activates address filtering on statedb.
Setup(statedb *state.StateDB)
// TouchAddresses marks sender, recipient, aliased, and retryable addresses for filtering.
// TouchAddresses marks sender, recipient, aliased, and retryable addresses
// of a transaction for filtering.
TouchAddresses(statedb *state.StateDB, tx *types.Transaction, sender common.Address)
// CheckFiltered applies event filtering and returns state.ErrArbTxFilter if filtered.
CheckFiltered(statedb *state.StateDB) error
// ApplyEventsAndCheckFiltered applies event filtering and returns state.ErrArbTxFilter if any touched address is filtered.
ApplyEventsAndCheckFiltered(statedb *state.StateDB) error
}

type NodeInterfaceBackendAPI interface {
Expand Down
3 changes: 1 addition & 2 deletions eth/gasestimator/gasestimator.go
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,6 @@ func run(ctx context.Context, call *core.Message, opts *Options) (*core.Executio
txFilterer := opts.Backend.TxFilter()
if txFilterer != nil {
txFilterer.Setup(dirtyState)

dirtyState.TouchAddress(&filter.FilteredAddressRecord{Address: call.From, FilterReason: filter.FilterReason{Reason: filter.ReasonFrom, EventRuleMatch: nil}})
if call.To != nil {
dirtyState.TouchAddress(&filter.FilteredAddressRecord{Address: *call.To, FilterReason: filter.FilterReason{Reason: filter.ReasonTo, EventRuleMatch: nil}})
Expand Down Expand Up @@ -314,7 +313,7 @@ func run(ctx context.Context, call *core.Message, opts *Options) (*core.Executio

// Arbitrum: check address filtering result
if txFilterer != nil {
if err := txFilterer.CheckFiltered(dirtyState); err != nil {
if err := txFilterer.ApplyEventsAndCheckFiltered(dirtyState); err != nil {
return nil, err
}
}
Expand Down
20 changes: 20 additions & 0 deletions internal/ethapi/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (

"github.com/davecgh/go-spew/spew"
"github.com/ethereum/go-ethereum/accounts"
"github.com/ethereum/go-ethereum/arbitrum/filter"
"github.com/ethereum/go-ethereum/arbitrum/retryables"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/hexutil"
Expand Down Expand Up @@ -779,6 +780,16 @@ func applyMessage(ctx context.Context, b Backend, args TransactionArgs, state *s
if err != nil || res != nil {
return res, err
}

// Arbitrum: set up address filtering (after InterceptRPCMessage, matching gasestimator order)
txFilterer := b.TxFilter()
if txFilterer != nil {
txFilterer.Setup(state)
state.TouchAddress(&filter.FilteredAddressRecord{Address: msg.From, FilterReason: filter.FilterReason{Reason: filter.ReasonFrom, EventRuleMatch: nil}})
if msg.To != nil {
state.TouchAddress(&filter.FilteredAddressRecord{Address: *msg.To, FilterReason: filter.FilterReason{Reason: filter.ReasonTo, EventRuleMatch: nil}})
}
}
// Lower the basefee to 0 to avoid breaking EVM
// invariants (basefee < feecap).
if msg.GasPrice.Sign() == 0 {
Expand All @@ -798,6 +809,15 @@ func applyMessage(ctx context.Context, b Backend, args TransactionArgs, state *s
if err := state.Error(); err != nil {
return nil, err
}
// Arbitrum: run scheduled txes for address filtering and check result
if txFilterer != nil && err == nil {
if _, ferr := retryables.RunScheduledTxes(ctx, b, state, header, *blockContext, msg.TxRunContext, res, txFilterer); ferr != nil {
return nil, ferr
}
if ferr := txFilterer.ApplyEventsAndCheckFiltered(state); ferr != nil {
return nil, ferr
}
Comment thread
diegoximenes marked this conversation as resolved.
}
return res, err
}

Expand Down
Loading