Skip to content

Commit b87b9b4

Browse files
authored
internal/ethapi:fix zero rpc gas cap in eth_createAccessList (ethereum#28846)
This PR enhances eth_createAccessList RPC call to support scenarios where the node is launched with an unlimited gas cap (--rpc.gascap 0). The eth_createAccessList RPC call returns failure if user doesn't explicitly set a gas limit.
1 parent e47a7c2 commit b87b9b4

File tree

2 files changed

+34
-34
lines changed

2 files changed

+34
-34
lines changed

internal/ethapi/api.go

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -453,7 +453,7 @@ func (s *PersonalAccountAPI) signTransaction(ctx context.Context, args *Transact
453453
return nil, err
454454
}
455455
// Set some sanity defaults and terminate on failure
456-
if err := args.setDefaults(ctx, s.b); err != nil {
456+
if err := args.setDefaults(ctx, s.b, false); err != nil {
457457
return nil, err
458458
}
459459
// Assemble the transaction and sign with the wallet
@@ -1485,14 +1485,9 @@ func AccessList(ctx context.Context, b Backend, blockNrOrHash rpc.BlockNumberOrH
14851485
if db == nil || err != nil {
14861486
return nil, 0, nil, err
14871487
}
1488-
// If the gas amount is not set, default to RPC gas cap.
1489-
if args.Gas == nil {
1490-
tmp := hexutil.Uint64(b.RPCGasCap())
1491-
args.Gas = &tmp
1492-
}
14931488

14941489
// Ensure any missing fields are filled, extract the recipient and input data
1495-
if err := args.setDefaults(ctx, b); err != nil {
1490+
if err := args.setDefaults(ctx, b, true); err != nil {
14961491
return nil, 0, nil, err
14971492
}
14981493
var to common.Address
@@ -1795,7 +1790,7 @@ func (s *TransactionAPI) SendTransaction(ctx context.Context, args TransactionAr
17951790
}
17961791

17971792
// Set some sanity defaults and terminate on failure
1798-
if err := args.setDefaults(ctx, s.b); err != nil {
1793+
if err := args.setDefaults(ctx, s.b, false); err != nil {
17991794
return common.Hash{}, err
18001795
}
18011796
// Assemble the transaction and sign with the wallet
@@ -1815,7 +1810,7 @@ func (s *TransactionAPI) FillTransaction(ctx context.Context, args TransactionAr
18151810
args.blobSidecarAllowed = true
18161811

18171812
// Set some sanity defaults and terminate on failure
1818-
if err := args.setDefaults(ctx, s.b); err != nil {
1813+
if err := args.setDefaults(ctx, s.b, false); err != nil {
18191814
return nil, err
18201815
}
18211816
// Assemble the transaction and obtain rlp
@@ -1884,7 +1879,7 @@ func (s *TransactionAPI) SignTransaction(ctx context.Context, args TransactionAr
18841879
if args.Nonce == nil {
18851880
return nil, errors.New("nonce not specified")
18861881
}
1887-
if err := args.setDefaults(ctx, s.b); err != nil {
1882+
if err := args.setDefaults(ctx, s.b, false); err != nil {
18881883
return nil, err
18891884
}
18901885
// Before actually sign the transaction, ensure the transaction fee is reasonable.
@@ -1933,7 +1928,7 @@ func (s *TransactionAPI) Resend(ctx context.Context, sendArgs TransactionArgs, g
19331928
if sendArgs.Nonce == nil {
19341929
return common.Hash{}, errors.New("missing transaction nonce in transaction spec")
19351930
}
1936-
if err := sendArgs.setDefaults(ctx, s.b); err != nil {
1931+
if err := sendArgs.setDefaults(ctx, s.b, false); err != nil {
19371932
return common.Hash{}, err
19381933
}
19391934
matchTx := sendArgs.toTransaction()

internal/ethapi/transaction_args.go

Lines changed: 28 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ func (args *TransactionArgs) data() []byte {
9696
}
9797

9898
// setDefaults fills in default values for unspecified tx fields.
99-
func (args *TransactionArgs) setDefaults(ctx context.Context, b Backend) error {
99+
func (args *TransactionArgs) setDefaults(ctx context.Context, b Backend, skipGasEstimation bool) error {
100100
if err := args.setBlobTxSidecar(ctx, b); err != nil {
101101
return err
102102
}
@@ -136,30 +136,35 @@ func (args *TransactionArgs) setDefaults(ctx context.Context, b Backend) error {
136136
}
137137
}
138138

139-
// Estimate the gas usage if necessary.
140139
if args.Gas == nil {
141-
// These fields are immutable during the estimation, safe to
142-
// pass the pointer directly.
143-
data := args.data()
144-
callArgs := TransactionArgs{
145-
From: args.From,
146-
To: args.To,
147-
GasPrice: args.GasPrice,
148-
MaxFeePerGas: args.MaxFeePerGas,
149-
MaxPriorityFeePerGas: args.MaxPriorityFeePerGas,
150-
Value: args.Value,
151-
Data: (*hexutil.Bytes)(&data),
152-
AccessList: args.AccessList,
153-
BlobFeeCap: args.BlobFeeCap,
154-
BlobHashes: args.BlobHashes,
155-
}
156-
latestBlockNr := rpc.BlockNumberOrHashWithNumber(rpc.LatestBlockNumber)
157-
estimated, err := DoEstimateGas(ctx, b, callArgs, latestBlockNr, nil, b.RPCGasCap())
158-
if err != nil {
159-
return err
140+
if skipGasEstimation { // Skip gas usage estimation if a precise gas limit is not critical, e.g., in non-transaction calls.
141+
gas := hexutil.Uint64(b.RPCGasCap())
142+
if gas == 0 {
143+
gas = hexutil.Uint64(math.MaxUint64 / 2)
144+
}
145+
args.Gas = &gas
146+
} else { // Estimate the gas usage otherwise.
147+
// These fields are immutable during the estimation, safe to
148+
// pass the pointer directly.
149+
data := args.data()
150+
callArgs := TransactionArgs{
151+
From: args.From,
152+
To: args.To,
153+
GasPrice: args.GasPrice,
154+
MaxFeePerGas: args.MaxFeePerGas,
155+
MaxPriorityFeePerGas: args.MaxPriorityFeePerGas,
156+
Value: args.Value,
157+
Data: (*hexutil.Bytes)(&data),
158+
AccessList: args.AccessList,
159+
}
160+
latestBlockNr := rpc.BlockNumberOrHashWithNumber(rpc.LatestBlockNumber)
161+
estimated, err := DoEstimateGas(ctx, b, callArgs, latestBlockNr, nil, b.RPCGasCap())
162+
if err != nil {
163+
return err
164+
}
165+
args.Gas = &estimated
166+
log.Trace("Estimate gas usage automatically", "gas", args.Gas)
160167
}
161-
args.Gas = &estimated
162-
log.Trace("Estimate gas usage automatically", "gas", args.Gas)
163168
}
164169

165170
// If chain id is provided, ensure it matches the local chain id. Otherwise, set the local

0 commit comments

Comments
 (0)