Skip to content

Commit

Permalink
Skip debit/credit during gas estimation (#2258)
Browse files Browse the repository at this point in the history
* Zero out fee tip and fee cap during gas estimation

* Skip debit/credit for estimateGas
  • Loading branch information
palango authored Feb 21, 2024
1 parent 0406a0f commit 6f0c8d6
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
7 changes: 7 additions & 0 deletions core/state_transition.go
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,9 @@ func (st *StateTransition) canPayFee(accountOwner common.Address, feeCurrency *c
}

func (st *StateTransition) debitFee(from common.Address, feeCurrency *common.Address) (err error) {
if st.evm.Config.SkipDebitCredit {
return nil
}
effectiveFee := new(big.Int).Mul(new(big.Int).SetUint64(st.msg.Gas()), st.gasPrice)
// If GatewayFeeRecipient is unspecified, the gateway fee value is ignore and the sender is not charged.
if st.msg.GatewayFeeRecipient() != nil {
Expand Down Expand Up @@ -527,6 +530,10 @@ func (st *StateTransition) TransitionDb() (*ExecutionResult, error) {

// creditTxFees calculates the amounts and recipients of transaction fees and credits the accounts.
func (st *StateTransition) creditTxFees() error {
if st.evm.Config.SkipDebitCredit {
return nil
}

// Run only primary evm.Call() with tracer
if st.evm.GetDebug() {
st.evm.SetDebug(false)
Expand Down
3 changes: 3 additions & 0 deletions core/vm/interpreter.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ type Config struct {
JumpTable [256]*operation // EVM instruction table, automatically populated if unset

ExtraEips []int // Additional EIPS that are to be enabled

// Celo
SkipDebitCredit bool
}

// ScopeContext contains the things that are per-call, such as stack and memory,
Expand Down
5 changes: 4 additions & 1 deletion internal/ethapi/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -909,7 +909,7 @@ func DoCall(ctx context.Context, b Backend, args TransactionArgs, blockNrOrHash
if err != nil {
return nil, err
}
evm, vmError, err := b.GetEVM(ctx, msg, state, header, &vm.Config{NoBaseFee: true})
evm, vmError, err := b.GetEVM(ctx, msg, state, header, &vm.Config{NoBaseFee: true, SkipDebitCredit: true})
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -1014,6 +1014,9 @@ func DoEstimateGas(ctx context.Context, b Backend, args TransactionArgs, blockNr
// also fail with gas limit B, which may not be the case if the gas price is non-zero,
// depending on the account's balance.
args.GasPrice = nil
// If a fee tip or fee cap are passed, those will override the gas price, so zero them out as well.
args.MaxFeePerGas = nil
args.MaxPriorityFeePerGas = nil
// Create a helper to check if a gas allowance results in an executable transaction
executable := func(gas uint64) (bool, *core.ExecutionResult, error) {
args.Gas = (*hexutil.Uint64)(&gas)
Expand Down

0 comments on commit 6f0c8d6

Please sign in to comment.