Skip to content

Commit

Permalink
fix estimate gas
Browse files Browse the repository at this point in the history
Signed-off-by: pandainzoo <gary.zhu@mantle.xyz>
  • Loading branch information
pandainzoo committed May 30, 2024
1 parent be781ff commit d7cdd5e
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 26 deletions.
6 changes: 1 addition & 5 deletions internal/ethapi/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -1290,11 +1290,7 @@ func DoEstimateGas(ctx context.Context, b Backend, args TransactionArgs, blockNr
// calculate sponsor & from allowance with sponsorPercent, use min value as allowance
fromAllowanceWithSponsorPercent := calculateGasAllowanceWithSponsorPercent(allowance, types.OneHundredPercent-metaTxParams.SponsorPercent)
sponsorAllowanceWithSponsorPercent := calculateGasAllowanceWithSponsorPercent(sponsorAllowance, metaTxParams.SponsorPercent)
if sponsorAllowanceWithSponsorPercent.Cmp(fromAllowanceWithSponsorPercent) < 0 {
allowance = sponsorAllowanceWithSponsorPercent
} else {
allowance = fromAllowanceWithSponsorPercent
}
allowance = math.BigMin(sponsorAllowanceWithSponsorPercent, fromAllowanceWithSponsorPercent)
}
}

Expand Down
23 changes: 2 additions & 21 deletions internal/ethapi/transaction_args.go
Original file line number Diff line number Diff line change
Expand Up @@ -258,27 +258,8 @@ func (args *TransactionArgs) ToMessage(globalGasCap uint64, baseFee *big.Int, ru

// use suggested gasPrice for estimateGas to calculate gasUsed
if runMode == core.GasEstimationMode || runMode == core.GasEstimationWithSkipCheckBalanceMode {
// use default gasPrice if user does not set gasPrice or gasPrice is 0
if args.GasPrice == nil || gasPrice.Cmp(common.Big0) == 0 {
gasPrice = gasPriceForEstimate.ToInt()
}
// use gasTipCap to set gasFeeCap
if args.MaxFeePerGas == nil && args.MaxPriorityFeePerGas != nil {
gasFeeCap = args.MaxPriorityFeePerGas.ToInt()
}
// use gasFeeCap to set gasTipCap
if args.MaxPriorityFeePerGas == nil && args.MaxFeePerGas != nil {
gasTipCap = args.MaxFeePerGas.ToInt()
}
// use default gasPrice to set gasFeeCap & gasTipCap if user set gasPrice
if args.GasPrice != nil {
gasFeeCap = gasPrice
gasTipCap = gasPrice
}
// use default gasPrice to set gasFeeCap & gasTipCap if user does not set any value
if args.MaxFeePerGas == nil && args.MaxPriorityFeePerGas == nil && args.GasPrice == nil {
gasFeeCap = gasPriceForEstimate.ToInt()
gasTipCap = gasPriceForEstimate.ToInt()
if gasPrice.BitLen() == 0 && gasFeeCap.BitLen() == 0 && gasTipCap.BitLen() == 0 {
gasPrice, gasFeeCap, gasTipCap = gasPriceForEstimate.ToInt(), gasPriceForEstimate.ToInt(), gasPriceForEstimate.ToInt()
}
}

Expand Down

0 comments on commit d7cdd5e

Please sign in to comment.