Skip to content

Eth api more fixes #458

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

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
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
29 changes: 12 additions & 17 deletions internal/ethapi/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -699,35 +699,30 @@ func doCall(ctx context.Context, b Backend, args TransactionArgs, state *state.S
// Make sure the context is cancelled when the call has completed
// this makes sure resources are cleaned up.
defer cancel()
return applyMessage(ctx, b, args, state, header, timeout, globalGasCap, &blockCtx, &vm.Config{NoBaseFee: true}, precompiles, true, runMode)
}

func applyMessage(ctx context.Context, b Backend, args TransactionArgs, state *state.StateDB, header *types.Header, timeout time.Duration, globalGasCap uint64, blockContext *vm.BlockContext, vmConfig *vm.Config, precompiles vm.PrecompiledContracts, skipChecks bool, runMode core.MessageRunMode) (*core.ExecutionResult, error) {
// Get a new instance of the EVM.
gp := new(core.GasPool)
if globalGasCap == 0 {

if b.ChainConfig().IsArbitrum() {
gp.AddGas(1 << 50) // Arbitrum: static high gas pool limit to pay for l1gas
} else if globalGasCap == 0 {
gp.AddGas(gomath.MaxUint64)
} else {
gp.AddGas(globalGasCap)
}
return applyMessage(ctx, b, args, state, header, timeout, gp, &blockCtx, &vm.Config{NoBaseFee: true}, precompiles, true, runMode)
}

func applyMessage(ctx context.Context, b Backend, args TransactionArgs, state *state.StateDB, header *types.Header, timeout time.Duration, gp *core.GasPool, blockContext *vm.BlockContext, vmConfig *vm.Config, precompiles vm.PrecompiledContracts, skipChecks bool, runMode core.MessageRunMode) (*core.ExecutionResult, error) {
// Get a new instance of the EVM.
if err := args.CallDefaults(gp.Gas(), blockContext.BaseFee, b.ChainConfig().ChainID); err != nil {
return nil, err
}
msg := args.ToMessage(blockContext.BaseFee, gp.Gas(), header, state, runMode, skipChecks, skipChecks)
msg := args.ToMessage(blockContext.BaseFee, globalGasCap, header, state, runMode, skipChecks, skipChecks)

// Arbitrum: raise the gas cap to ignore L1 costs so that it's compute-only
if gp.Gas() > 0 {
postingGas, err := core.RPCPostingGasHook(msg, header, state)
if err != nil {
return nil, err
}
if gp.Gas() < gomath.MaxUint64-postingGas {
gp.AddGas(postingGas)
}
}
if msg.GasLimit > gp.Gas() {
if b.ChainConfig().IsArbitrum() && msg.GasLimit > gp.Gas() { // Arbitrum: gas limit is counted inside the message and not in the gas-pool
gp.SetGas(msg.GasLimit)
}

// Arbitrum: support NodeInterface.sol by swapping out the message if needed
var res *core.ExecutionResult
var err error
Expand Down
24 changes: 10 additions & 14 deletions internal/ethapi/transaction_args.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,10 @@ func (args *TransactionArgs) setDefaults(ctx context.Context, b Backend, skipGas
gas = hexutil.Uint64(math.MaxUint64 / 2)
}
args.Gas = &gas
if args.SkipL1Charging == nil {
skipCharging := true
args.SkipL1Charging = &skipCharging
}
} else { // Estimate the gas usage otherwise.
// These fields are immutable during the estimation, safe to
// pass the pointer directly.
Expand Down Expand Up @@ -194,6 +198,9 @@ func (args *TransactionArgs) setFeeDefaults(ctx context.Context, b Backend, head
if args.BlobFeeCap != nil && args.BlobFeeCap.ToInt().Sign() == 0 {
return errors.New("maxFeePerBlobGas, if specified, must be non-zero")
}
if b.ChainConfig().IsCancun(head.Number, head.Time, types.DeserializeHeaderExtraInformation(head).ArbOSFormatVersion) {
args.setCancunFeeDefaults(b.ChainConfig(), head)
}
// If both gasPrice and at least one of the EIP-1559 fee parameters are specified, error.
if args.GasPrice != nil && (args.MaxFeePerGas != nil || args.MaxPriorityFeePerGas != nil) {
return errors.New("both gasPrice and (maxFeePerGas or maxPriorityFeePerGas) specified")
Expand All @@ -211,10 +218,7 @@ func (args *TransactionArgs) setFeeDefaults(ctx context.Context, b Backend, head
if args.MaxFeePerGas.ToInt().Cmp(args.MaxPriorityFeePerGas.ToInt()) < 0 {
return fmt.Errorf("maxFeePerGas (%v) < maxPriorityFeePerGas (%v)", args.MaxFeePerGas, args.MaxPriorityFeePerGas)
}
// No need to set anything other than CancunFeeDefaults, user already set MaxFeePerGas and MaxPriorityFeePerGas
if err := args.setCancunFeeDefaults(ctx, b.ChainConfig(), head, b); err != nil {
return err
}
return nil // No need to set anything, user already set MaxFeePerGas and MaxPriorityFeePerGas
}

// Sanity check the non-EIP-1559 fee parameters.
Expand All @@ -228,14 +232,7 @@ func (args *TransactionArgs) setFeeDefaults(ctx context.Context, b Backend, head
}

// Now attempt to fill in default value depending on whether London is active or not.
if b.ChainConfig().IsCancun(head.Number, head.Time, types.DeserializeHeaderExtraInformation(head).ArbOSFormatVersion) {
if err := args.setCancunFeeDefaults(ctx, b.ChainConfig(), head, b); err != nil {
return err
}
} else if isLondon {
if args.BlobFeeCap != nil {
return errors.New("maxFeePerBlobGas is not valid before Cancun is active")
}
if isLondon {
// London is active, set maxPriorityFeePerGas and maxFeePerGas.
if err := args.setLondonFeeDefaults(ctx, head, b); err != nil {
return err
Expand All @@ -255,7 +252,7 @@ func (args *TransactionArgs) setFeeDefaults(ctx context.Context, b Backend, head
}

// setCancunFeeDefaults fills in reasonable default fee values for unspecified fields.
func (args *TransactionArgs) setCancunFeeDefaults(ctx context.Context, config *params.ChainConfig, head *types.Header, b Backend) error {
func (args *TransactionArgs) setCancunFeeDefaults(config *params.ChainConfig, head *types.Header) {
// Set maxFeePerBlobGas if it is missing.
if args.BlobHashes != nil && args.BlobFeeCap == nil {
blobBaseFee := eip4844.CalcBlobFee(config, head)
Expand All @@ -265,7 +262,6 @@ func (args *TransactionArgs) setCancunFeeDefaults(ctx context.Context, config *p
val := new(big.Int).Mul(blobBaseFee, big.NewInt(2))
args.BlobFeeCap = (*hexutil.Big)(val)
}
return args.setLondonFeeDefaults(ctx, head, b)
}

// setLondonFeeDefaults fills in reasonable default fee values for unspecified fields.
Expand Down
Loading