Skip to content

Commit 9428d77

Browse files
authored
Merge pull request #263 from bane-labs/avoid-rpc-estimate-error
internal/ethapi: set default fees before gas estimation
2 parents 84a003d + c4df340 commit 9428d77

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

internal/ethapi/api.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1284,6 +1284,9 @@ func DoEstimateGas(ctx context.Context, b Backend, args TransactionArgs, blockNr
12841284
// configuration (if non-zero).
12851285
// Note: Required blob gas is not computed in this method.
12861286
func (s *BlockChainAPI) EstimateGas(ctx context.Context, args TransactionArgs, blockNrOrHash *rpc.BlockNumberOrHash, overrides *StateOverride) (hexutil.Uint64, error) {
1287+
if err := args.setFeeMinAllowed(ctx, s.b); err != nil {
1288+
return 0, err
1289+
}
12871290
bNrOrHash := rpc.BlockNumberOrHashWithNumber(rpc.LatestBlockNumber)
12881291
if blockNrOrHash != nil {
12891292
bNrOrHash = *blockNrOrHash

internal/ethapi/transaction_args.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,32 @@ func (args *TransactionArgs) setDefaults(ctx context.Context, b Backend) error {
143143
return nil
144144
}
145145

146+
// setFeeMinAllowed fills in minimum allowed fee values for underpriced tx.
147+
func (args *TransactionArgs) setFeeMinAllowed(ctx context.Context, b Backend) error {
148+
if head := b.CurrentHeader(); b.ChainConfig().IsNeoXBurn(head.Number, head.Time) {
149+
if args.GasPrice != nil || args.MaxFeePerGas != nil || args.MaxPriorityFeePerGas != nil {
150+
gastip, err := b.SuggestGasTipCap(ctx)
151+
if err != nil {
152+
return err
153+
}
154+
gasprice := new(big.Int).Add(gastip, head.BaseFee)
155+
if args.GasPrice != nil {
156+
if args.GasPrice.ToInt().Cmp(gasprice) < 0 {
157+
args.GasPrice = (*hexutil.Big)(gasprice)
158+
}
159+
} else {
160+
if args.MaxPriorityFeePerGas == nil || args.MaxPriorityFeePerGas.ToInt().Cmp(gastip) < 0 {
161+
args.MaxPriorityFeePerGas = (*hexutil.Big)(gastip)
162+
}
163+
if args.MaxFeePerGas == nil || args.MaxFeePerGas.ToInt().Cmp(gasprice) < 0 {
164+
args.MaxFeePerGas = (*hexutil.Big)(gasprice)
165+
}
166+
}
167+
}
168+
}
169+
return nil
170+
}
171+
146172
// setFeeDefaults fills in default fee values for unspecified tx fields.
147173
func (args *TransactionArgs) setFeeDefaults(ctx context.Context, b Backend) error {
148174
// If both gasPrice and at least one of the EIP-1559 fee parameters are specified, error.

0 commit comments

Comments
 (0)