From d7cdd5ee48da0921567c7d05022d2f83c6159fa9 Mon Sep 17 00:00:00 2001 From: pandainzoo Date: Thu, 30 May 2024 12:13:18 +0800 Subject: [PATCH] fix estimate gas Signed-off-by: pandainzoo --- internal/ethapi/api.go | 6 +----- internal/ethapi/transaction_args.go | 23 ++--------------------- 2 files changed, 3 insertions(+), 26 deletions(-) diff --git a/internal/ethapi/api.go b/internal/ethapi/api.go index 9282996f23..6ba14947e8 100644 --- a/internal/ethapi/api.go +++ b/internal/ethapi/api.go @@ -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) } } diff --git a/internal/ethapi/transaction_args.go b/internal/ethapi/transaction_args.go index 976839f48b..dec61b6352 100644 --- a/internal/ethapi/transaction_args.go +++ b/internal/ethapi/transaction_args.go @@ -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() } }