Skip to content
Open
Show file tree
Hide file tree
Changes from 3 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: 22 additions & 10 deletions arbitrum/retryables/scheduled_txes.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,25 +12,32 @@ 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 !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 {
return nil, err
}

if txFilterer != nil {
txFilterer.TouchAddresses(statedb, scheduled[0], msg.From)
txFilterer.TouchScheduledTxAddresses(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
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 +54,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
10 changes: 6 additions & 4 deletions core/arbitrum_hooks.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,12 @@ 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(statedb *state.StateDB, tx *types.Transaction, sender common.Address)
// CheckFiltered applies event filtering and returns state.ErrArbTxFilter if filtered.
CheckFiltered(statedb *state.StateDB) error
// TouchFromTo marks the sender and recipient addresses for filtering.
TouchFromTo(statedb *state.StateDB, from common.Address, to *common.Address)
// TouchScheduledTxAddresses marks sender, recipient, aliased, and retryable addresses of a scheduled transaction for filtering.
TouchScheduledTxAddresses(statedb *state.StateDB, tx *types.Transaction, sender common.Address)
// ApplyEventsAndCheckFiltered applies event filtering and returns state.ErrArbTxFilter if any touched address is filtered.
ApplyEventsAndCheckFiltered(statedb *state.StateDB) error
}

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

dirtyState.TouchAddress(call.From)
if call.To != nil {
dirtyState.TouchAddress(*call.To)
}
txFilterer.TouchFromTo(dirtyState, call.From, call.To)
Comment thread
diegoximenes marked this conversation as resolved.
Outdated
}

evm := opts.Backend.GetEVM(ctx, dirtyState, opts.Header, &vm.Config{NoBaseFee: true}, &evmContext)
Expand All @@ -313,7 +309,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
16 changes: 16 additions & 0 deletions internal/ethapi/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -779,6 +779,13 @@ 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)
txFilterer.TouchFromTo(state, msg.From, msg.To)
}
// Lower the basefee to 0 to avoid breaking EVM
// invariants (basefee < feecap).
if msg.GasPrice.Sign() == 0 {
Expand All @@ -798,6 +805,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