Skip to content

Commit

Permalink
Merge pull request ethereum#215 from OffchainLabs/message-run-mode-ev…
Browse files Browse the repository at this point in the history
…erywhere

Supply a RunMode everywhere we make a message
  • Loading branch information
rachel-bousfield authored May 9, 2023
2 parents d136b0f + cedaff1 commit 48482e5
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 23 deletions.
2 changes: 1 addition & 1 deletion eth/tracers/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -928,7 +928,7 @@ func (api *API) TraceCall(ctx context.Context, args ethapi.TransactionArgs, bloc
config.BlockOverrides.Apply(&vmctx)
}
// Execute the trace
msg, err := args.ToMessage(api.backend.RPCGasCap(), block.Header(), statedb)
msg, err := args.ToMessage(api.backend.RPCGasCap(), block.Header(), statedb, types.MessageEthcallMode)
if err != nil {
return nil, err
}
Expand Down
4 changes: 2 additions & 2 deletions graphql/graphql.go
Original file line number Diff line number Diff line change
Expand Up @@ -1072,7 +1072,7 @@ func (b *Block) Call(ctx context.Context, args struct {
return nil, err
}
}
result, err := ethapi.DoCall(ctx, b.r.backend, args.Data, *b.numberOrHash, nil, b.r.backend.RPCEVMTimeout(), b.r.backend.RPCGasCap(), false)
result, err := ethapi.DoCall(ctx, b.r.backend, args.Data, *b.numberOrHash, nil, b.r.backend.RPCEVMTimeout(), b.r.backend.RPCGasCap(), types.MessageEthcallMode)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -1142,7 +1142,7 @@ func (p *Pending) Call(ctx context.Context, args struct {
Data ethapi.TransactionArgs
}) (*CallResult, error) {
pendingBlockNr := rpc.BlockNumberOrHashWithNumber(rpc.PendingBlockNumber)
result, err := ethapi.DoCall(ctx, p.r.backend, args.Data, pendingBlockNr, nil, p.r.backend.RPCEVMTimeout(), p.r.backend.RPCGasCap(), false)
result, err := ethapi.DoCall(ctx, p.r.backend, args.Data, pendingBlockNr, nil, p.r.backend.RPCEVMTimeout(), p.r.backend.RPCGasCap(), types.MessageEthcallMode)
if err != nil {
return nil, err
}
Expand Down
22 changes: 6 additions & 16 deletions internal/ethapi/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -959,7 +959,7 @@ func (diff *BlockOverrides) Apply(blockCtx *vm.BlockContext) {
}
}

func DoCall(ctx context.Context, b Backend, args TransactionArgs, blockNrOrHash rpc.BlockNumberOrHash, overrides *StateOverride, timeout time.Duration, globalGasCap uint64, gasEstimation bool) (*core.ExecutionResult, error) {
func DoCall(ctx context.Context, b Backend, args TransactionArgs, blockNrOrHash rpc.BlockNumberOrHash, overrides *StateOverride, timeout time.Duration, globalGasCap uint64, runMode types.MessageRunMode) (*core.ExecutionResult, error) {
defer func(start time.Time) { log.Debug("Executing EVM call finished", "runtime", time.Since(start)) }(time.Now())

state, header, err := b.StateAndHeaderByNumberOrHash(ctx, blockNrOrHash)
Expand All @@ -982,27 +982,17 @@ func DoCall(ctx context.Context, b Backend, args TransactionArgs, blockNrOrHash
defer cancel()

// Get a new instance of the EVM.
msg, err := args.ToMessage(globalGasCap, header, state)
msg, err := args.ToMessage(globalGasCap, header, state, runMode)
if err != nil {
return nil, err
}

// Arbitrum: mark the reason for this call
var txRunMode types.MessageRunMode
if gasEstimation {
txRunMode = types.MessageGasEstimationMode
} else {
txRunMode = types.MessageEthcallMode
}
msg.TxRunMode = txRunMode

// Arbitrum: support NodeInterface.sol by swapping out the message if needed
var res *core.ExecutionResult
msg, res, err = core.InterceptRPCMessage(msg, ctx, state, header, b)
if err != nil || res != nil {
return res, err
}
msg.TxRunMode = txRunMode

evm, vmError, err := b.GetEVM(ctx, msg, state, header, &vm.Config{NoBaseFee: true})
if err != nil {
Expand Down Expand Up @@ -1032,7 +1022,7 @@ func DoCall(ctx context.Context, b Backend, args TransactionArgs, blockNrOrHash

// Arbitrum: a tx can schedule another (see retryables)
scheduled := result.ScheduledTxes
for gasEstimation && len(scheduled) > 0 {
for runMode == types.MessageGasEstimationMode && len(scheduled) > 0 {
// make a new EVM for the scheduled Tx (an EVM must never be reused)
evm, vmError, err := b.GetEVM(ctx, msg, state, header, &vm.Config{NoBaseFee: true})
if err != nil {
Expand Down Expand Up @@ -1109,7 +1099,7 @@ func (e *revertError) ErrorData() interface{} {
// Note, this function doesn't make and changes in the state/blockchain and is
// useful to execute and retrieve values.
func (s *BlockChainAPI) Call(ctx context.Context, args TransactionArgs, blockNrOrHash rpc.BlockNumberOrHash, overrides *StateOverride) (hexutil.Bytes, error) {
result, err := DoCall(ctx, s.b, args, blockNrOrHash, overrides, s.b.RPCEVMTimeout(), s.b.RPCGasCap(), false)
result, err := DoCall(ctx, s.b, args, blockNrOrHash, overrides, s.b.RPCEVMTimeout(), s.b.RPCGasCap(), types.MessageEthcallMode)
if err != nil {
if client := fallbackClientFor(s.b, err); client != nil {
var res hexutil.Bytes
Expand Down Expand Up @@ -1213,7 +1203,7 @@ func DoEstimateGas(ctx context.Context, b Backend, args TransactionArgs, blockNr
executable := func(gas uint64) (bool, *core.ExecutionResult, error) {
args.Gas = (*hexutil.Uint64)(&gas)

result, err := DoCall(ctx, b, args, blockNrOrHash, nil, 0, vanillaGasCap, true)
result, err := DoCall(ctx, b, args, blockNrOrHash, nil, 0, vanillaGasCap, types.MessageGasEstimationMode)
if err != nil {
if errors.Is(err, core.ErrIntrinsicGas) {
return true, nil, nil // Special case, raise gas limit
Expand Down Expand Up @@ -1657,7 +1647,7 @@ func AccessList(ctx context.Context, b Backend, blockNrOrHash rpc.BlockNumberOrH
statedb := db.Copy()
// Set the accesslist to the last al
args.AccessList = &accessList
msg, err := args.ToMessage(b.RPCGasCap(), header, statedb)
msg, err := args.ToMessage(b.RPCGasCap(), header, statedb, types.MessageEthcallMode)
if err != nil {
return nil, 0, nil, err
}
Expand Down
8 changes: 4 additions & 4 deletions internal/ethapi/transaction_args.go
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ func (args *TransactionArgs) setLondonFeeDefaults(ctx context.Context, head *typ
// ToMessage converts the transaction arguments to the Message type used by the
// core evm. This method is used in calls and traces that do not require a real
// live transaction.
func (args *TransactionArgs) ToMessage(globalGasCap uint64, header *types.Header, state *state.StateDB) (types.Message, error) {
func (args *TransactionArgs) ToMessage(globalGasCap uint64, header *types.Header, state *state.StateDB, runMode types.MessageRunMode) (types.Message, error) {
baseFee := header.BaseFee

// Reject invalid combinations of pre- and post-1559 fee styles
Expand Down Expand Up @@ -268,25 +268,25 @@ func (args *TransactionArgs) ToMessage(globalGasCap uint64, header *types.Header
accessList = *args.AccessList
}
msg := types.NewMessage(addr, args.To, 0, value, gas, gasPrice, gasFeeCap, gasTipCap, data, accessList, true)
msg.TxRunMode = runMode

// Arbitrum: raise the gas cap to ignore L1 costs so that it's compute-only
if core.InterceptRPCGasCap != nil && state != nil {
// ToMessage recurses once to allow ArbOS to intercept the result for all callers
// ArbOS uses this to modify globalGasCap so that the cap will ignore this tx's specific L1 data costs
core.InterceptRPCGasCap(&globalGasCap, msg, header, state)
return args.ToMessage(globalGasCap, header, nil) // we pass a nil to avoid another recursion
return args.ToMessage(globalGasCap, header, nil, runMode) // we pass a nil to avoid another recursion
}
return msg, nil
}

// Raises the vanilla gas cap by the tx's l1 data costs in l2 terms. This creates a new gas cap that after
// data payments are made, equals the original vanilla cap for the remaining, L2-specific work the tx does.
func (args *TransactionArgs) L2OnlyGasCap(gasCap uint64, header *types.Header, state *state.StateDB, runMode types.MessageRunMode) (uint64, error) {
msg, err := args.ToMessage(gasCap, header, nil)
msg, err := args.ToMessage(gasCap, header, nil, runMode)
if err != nil {
return 0, err
}
msg.TxRunMode = runMode
core.InterceptRPCGasCap(&gasCap, msg, header, state)
return gasCap, nil
}
Expand Down

0 comments on commit 48482e5

Please sign in to comment.