From 5c69c82e13104a5e3d0f97ebbce41772e2ef2dfa Mon Sep 17 00:00:00 2001 From: Tsahi Zidenberg Date: Wed, 6 Nov 2024 15:36:55 -0700 Subject: [PATCH 1/3] switch geth-hook to PostingGasHook --- execution/nodeInterface/NodeInterface.go | 10 ++++------ execution/nodeInterface/virtual-contracts.go | 20 ++++++-------------- 2 files changed, 10 insertions(+), 20 deletions(-) diff --git a/execution/nodeInterface/NodeInterface.go b/execution/nodeInterface/NodeInterface.go index 005cc62d44..00da1ba4b6 100644 --- a/execution/nodeInterface/NodeInterface.go +++ b/execution/nodeInterface/NodeInterface.go @@ -522,11 +522,10 @@ func (n NodeInterface) GasEstimateL1Component( args.Gas = (*hexutil.Uint64)(&randomGas) // We set the run mode to eth_call mode here because we want an exact estimate, not a padded estimate - gasLimitNotSetByUser := args.Gas == nil - if err := args.CallDefaults(randomGas, evm.Context.BaseFee, evm.ChainConfig().ChainID, gasLimitNotSetByUser); err != nil { + if err := args.CallDefaults(randomGas, evm.Context.BaseFee, evm.ChainConfig().ChainID); err != nil { return 0, nil, nil, err } - msg := args.ToMessage(evm.Context.BaseFee, randomGas, n.header, evm.StateDB.(*state.StateDB), core.MessageEthcallMode, evm.ChainConfig().ChainID, gasLimitNotSetByUser) + msg := args.ToMessage(evm.Context.BaseFee, randomGas, n.header, evm.StateDB.(*state.StateDB), core.MessageEthcallMode) pricing := c.State.L1PricingState() l1BaseFeeEstimate, err := pricing.PricePerUnit() @@ -579,11 +578,10 @@ func (n NodeInterface) GasEstimateComponents( // Setting the gas currently doesn't affect the PosterDataCost, // but we do it anyways for accuracy with potential future changes. args.Gas = &totalRaw - gasLimitNotSetByUser := args.Gas == nil - if err := args.CallDefaults(gasCap, evm.Context.BaseFee, evm.ChainConfig().ChainID, gasLimitNotSetByUser); err != nil { + if err := args.CallDefaults(gasCap, evm.Context.BaseFee, evm.ChainConfig().ChainID); err != nil { return 0, 0, nil, nil, err } - msg := args.ToMessage(evm.Context.BaseFee, gasCap, n.header, evm.StateDB.(*state.StateDB), core.MessageGasEstimationMode, evm.ChainConfig().ChainID, gasLimitNotSetByUser) + msg := args.ToMessage(evm.Context.BaseFee, gasCap, n.header, evm.StateDB.(*state.StateDB), core.MessageGasEstimationMode) brotliCompressionLevel, err := c.State.BrotliCompressionLevel() if err != nil { return 0, 0, nil, nil, fmt.Errorf("failed to get brotli compression level: %w", err) diff --git a/execution/nodeInterface/virtual-contracts.go b/execution/nodeInterface/virtual-contracts.go index d04be10857..53c64a0ed3 100644 --- a/execution/nodeInterface/virtual-contracts.go +++ b/execution/nodeInterface/virtual-contracts.go @@ -23,7 +23,6 @@ import ( "github.com/offchainlabs/nitro/precompiles" "github.com/offchainlabs/nitro/solgen/go/node_interfacegen" "github.com/offchainlabs/nitro/solgen/go/precompilesgen" - "github.com/offchainlabs/nitro/util/arbmath" ) type addr = common.Address @@ -115,35 +114,28 @@ func init() { return msg, nil, nil } - core.InterceptRPCGasCap = func(gascap *uint64, msg *core.Message, header *types.Header, statedb *state.StateDB) { - if *gascap == 0 { - // It's already unlimited - return - } + core.PostingGasHook = func(msg *core.Message, header *types.Header, statedb *state.StateDB) (uint64, error) { arbosVersion := arbosState.ArbOSVersion(statedb) if arbosVersion == 0 { // ArbOS hasn't been installed, so use the vanilla gas cap - return + return 0, nil } state, err := arbosState.OpenSystemArbosState(statedb, nil, true) if err != nil { - log.Error("failed to open ArbOS state", "err", err) - return + return 0, err } if header.BaseFee.Sign() == 0 { // if gas is free or there's no reimbursable poster, the user won't pay for L1 data costs - return + return 0, nil } brotliCompressionLevel, err := state.BrotliCompressionLevel() if err != nil { - log.Error("failed to get brotli compression level", "err", err) - return + return 0, err } posterCost, _ := state.L1PricingState().PosterDataCost(msg, l1pricing.BatchPosterAddress, brotliCompressionLevel) // Use estimate mode because this is used to raise the gas cap, so we don't want to underestimate. - posterCostInL2Gas := arbos.GetPosterGas(state, header.BaseFee, core.MessageGasEstimationMode, posterCost) - *gascap = arbmath.SaturatingUAdd(*gascap, posterCostInL2Gas) + return arbos.GetPosterGas(state, header.BaseFee, core.MessageGasEstimationMode, posterCost), nil } core.GetArbOSSpeedLimitPerSecond = func(statedb *state.StateDB) (uint64, error) { From a4809d448c48063340d595cd7bcb286bd0a52f66 Mon Sep 17 00:00:00 2001 From: Tsahi Zidenberg Date: Wed, 6 Nov 2024 15:37:05 -0700 Subject: [PATCH 2/3] update geth pin for posting gas hook --- go-ethereum | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/go-ethereum b/go-ethereum index c4334737c9..319e72fe9d 160000 --- a/go-ethereum +++ b/go-ethereum @@ -1 +1 @@ -Subproject commit c4334737c95dc2b1bd398d2fe7feefee72da2f0f +Subproject commit 319e72fe9d0779bac3a6864214f7bb5dbf2babe3 From 967074af3e2b3c136f636f993518dfc9dba31636 Mon Sep 17 00:00:00 2001 From: Tsahi Zidenberg Date: Wed, 6 Nov 2024 18:17:45 -0700 Subject: [PATCH 3/3] rename to RPCPostingGasHook --- execution/nodeInterface/virtual-contracts.go | 2 +- go-ethereum | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/execution/nodeInterface/virtual-contracts.go b/execution/nodeInterface/virtual-contracts.go index 53c64a0ed3..86382870b7 100644 --- a/execution/nodeInterface/virtual-contracts.go +++ b/execution/nodeInterface/virtual-contracts.go @@ -114,7 +114,7 @@ func init() { return msg, nil, nil } - core.PostingGasHook = func(msg *core.Message, header *types.Header, statedb *state.StateDB) (uint64, error) { + core.RPCPostingGasHook = func(msg *core.Message, header *types.Header, statedb *state.StateDB) (uint64, error) { arbosVersion := arbosState.ArbOSVersion(statedb) if arbosVersion == 0 { // ArbOS hasn't been installed, so use the vanilla gas cap diff --git a/go-ethereum b/go-ethereum index 319e72fe9d..973f8a3c27 160000 --- a/go-ethereum +++ b/go-ethereum @@ -1 +1 @@ -Subproject commit 319e72fe9d0779bac3a6864214f7bb5dbf2babe3 +Subproject commit 973f8a3c278c961ac5cb5049167c8e28dd16262b