Skip to content

Commit

Permalink
R4R: get min(sponsorAmount, sponsorBalance) while estimateGas with me…
Browse files Browse the repository at this point in the history
…tatx
  • Loading branch information
wwq authored and wwq committed Jan 23, 2024
1 parent 39292bf commit 3d10a09
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions internal/ethapi/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -1232,21 +1232,25 @@ func DoEstimateGas(ctx context.Context, b Backend, args TransactionArgs, blockNr
if err != nil {
return 0, err
}
if metaTxParams != nil {
sponsorAmount, _ := types.CalculateSponsorPercentAmount(metaTxParams, new(big.Int).Mul(feeCap, new(big.Int).SetUint64(b.CurrentHeader().GasLimit)))
sponsorBalance := state.GetBalance(metaTxParams.GasFeeSponsor)
if sponsorBalance.Cmp(sponsorAmount) <= 0 {
return 0, types.ErrSponsorBalanceNotEnough
}
balance = new(big.Int).Add(balance, sponsorAmount)
}

available := new(big.Int).Set(balance)
if args.Value != nil {
if args.Value.ToInt().Cmp(available) >= 0 {
return 0, core.ErrInsufficientFundsForTransfer
}
available.Sub(available, args.Value.ToInt())
}

if metaTxParams != nil {
sponsorAmount, _ := types.CalculateSponsorPercentAmount(metaTxParams, new(big.Int).Mul(feeCap, new(big.Int).SetUint64(b.CurrentHeader().GasLimit)))
sponsorBalance := state.GetBalance(metaTxParams.GasFeeSponsor)
if sponsorAmount.Cmp(sponsorBalance) < 0 {
available.Add(available, sponsorAmount)
} else {
available.Add(available, sponsorBalance)
}
}

allowance := new(big.Int).Div(available, feeCap)

// If the allowance is larger than maximum uint64, skip checking
Expand Down

0 comments on commit 3d10a09

Please sign in to comment.