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

Posting gas hook #2774

Merged
merged 4 commits into from
Nov 7, 2024
Merged
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
10 changes: 4 additions & 6 deletions execution/nodeInterface/NodeInterface.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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)
Expand Down
20 changes: 6 additions & 14 deletions execution/nodeInterface/virtual-contracts.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.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
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) {
Expand Down
Loading