mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-06-19 21:31:37 +00:00
internal/ethapi: support unlimited rpc gas cap in eth_createAccessList (#28846)
This commit is contained in:
parent
6b8dd86b52
commit
bc14c672f2
2 changed files with 36 additions and 33 deletions
|
|
@ -440,7 +440,7 @@ func (s *PrivateAccountAPI) signTransaction(ctx context.Context, args *Transacti
|
|||
return nil, err
|
||||
}
|
||||
// Set some sanity defaults and terminate on failure
|
||||
if err := args.setDefaults(ctx, s.b); err != nil {
|
||||
if err := args.setDefaults(ctx, s.b, false); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
// Assemble the transaction and sign with the wallet
|
||||
|
|
@ -2026,14 +2026,8 @@ func AccessList(ctx context.Context, b Backend, blockNrOrHash rpc.BlockNumberOrH
|
|||
}
|
||||
owner := common.Address{}
|
||||
|
||||
// If the gas amount is not set, default to RPC gas cap.
|
||||
if args.Gas == nil {
|
||||
tmp := hexutil.Uint64(b.RPCGasCap())
|
||||
args.Gas = &tmp
|
||||
}
|
||||
|
||||
// Ensure any missing fields are filled, extract the recipient and input data
|
||||
if err := args.setDefaults(ctx, b); err != nil {
|
||||
if err := args.setDefaults(ctx, b, true); err != nil {
|
||||
return nil, 0, nil, err
|
||||
}
|
||||
var to common.Address
|
||||
|
|
@ -2365,7 +2359,7 @@ func (s *PublicTransactionPoolAPI) SendTransaction(ctx context.Context, args Tra
|
|||
}
|
||||
|
||||
// Set some sanity defaults and terminate on failure
|
||||
if err := args.setDefaults(ctx, s.b); err != nil {
|
||||
if err := args.setDefaults(ctx, s.b, false); err != nil {
|
||||
return common.Hash{}, err
|
||||
}
|
||||
// Assemble the transaction and sign with the wallet
|
||||
|
|
@ -2387,7 +2381,7 @@ func (s *PublicTransactionPoolAPI) SendTransaction(ctx context.Context, args Tra
|
|||
// processing (signing + broadcast).
|
||||
func (s *PublicTransactionPoolAPI) FillTransaction(ctx context.Context, args TransactionArgs) (*SignTransactionResult, error) {
|
||||
// Set some sanity defaults and terminate on failure
|
||||
if err := args.setDefaults(ctx, s.b); err != nil {
|
||||
if err := args.setDefaults(ctx, s.b, false); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
// Assemble the transaction and obtain rlp
|
||||
|
|
@ -3292,7 +3286,7 @@ func (s *PublicTransactionPoolAPI) SignTransaction(ctx context.Context, args Tra
|
|||
if args.Nonce == nil {
|
||||
return nil, errors.New("not specify Nonce")
|
||||
}
|
||||
if err := args.setDefaults(ctx, s.b); err != nil {
|
||||
if err := args.setDefaults(ctx, s.b, false); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
// Before actually sign the transaction, ensure the transaction fee is reasonable.
|
||||
|
|
@ -3341,7 +3335,7 @@ func (s *PublicTransactionPoolAPI) Resend(ctx context.Context, sendArgs Transact
|
|||
if sendArgs.Nonce == nil {
|
||||
return common.Hash{}, errors.New("missing transaction nonce in transaction spec")
|
||||
}
|
||||
if err := sendArgs.setDefaults(ctx, s.b); err != nil {
|
||||
if err := sendArgs.setDefaults(ctx, s.b, false); err != nil {
|
||||
return common.Hash{}, err
|
||||
}
|
||||
matchTx := sendArgs.toTransaction()
|
||||
|
|
|
|||
|
|
@ -74,7 +74,7 @@ func (args *TransactionArgs) data() []byte {
|
|||
}
|
||||
|
||||
// setDefaults fills in default values for unspecified tx fields.
|
||||
func (args *TransactionArgs) setDefaults(ctx context.Context, b Backend) error {
|
||||
func (args *TransactionArgs) setDefaults(ctx context.Context, b Backend, skipGasEstimation bool) error {
|
||||
if err := args.setFeeDefaults(ctx, b); err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
@ -94,29 +94,38 @@ func (args *TransactionArgs) setDefaults(ctx context.Context, b Backend) error {
|
|||
if args.To == nil && len(args.data()) == 0 {
|
||||
return errors.New(`contract creation without any data provided`)
|
||||
}
|
||||
// Estimate the gas usage if necessary.
|
||||
|
||||
if args.Gas == nil {
|
||||
// These fields are immutable during the estimation, safe to
|
||||
// pass the pointer directly.
|
||||
data := args.data()
|
||||
callArgs := TransactionArgs{
|
||||
From: args.From,
|
||||
To: args.To,
|
||||
GasPrice: args.GasPrice,
|
||||
MaxFeePerGas: args.MaxFeePerGas,
|
||||
MaxPriorityFeePerGas: args.MaxPriorityFeePerGas,
|
||||
Value: args.Value,
|
||||
Data: (*hexutil.Bytes)(&data),
|
||||
AccessList: args.AccessList,
|
||||
if skipGasEstimation { // Skip gas usage estimation if a precise gas limit is not critical, e.g., in non-transaction calls.
|
||||
gas := hexutil.Uint64(b.RPCGasCap())
|
||||
if gas == 0 {
|
||||
gas = hexutil.Uint64(math.MaxUint64 / 2)
|
||||
}
|
||||
args.Gas = &gas
|
||||
} else { // Estimate the gas usage otherwise.
|
||||
// These fields are immutable during the estimation, safe to
|
||||
// pass the pointer directly.
|
||||
data := args.data()
|
||||
callArgs := TransactionArgs{
|
||||
From: args.From,
|
||||
To: args.To,
|
||||
GasPrice: args.GasPrice,
|
||||
MaxFeePerGas: args.MaxFeePerGas,
|
||||
MaxPriorityFeePerGas: args.MaxPriorityFeePerGas,
|
||||
Value: args.Value,
|
||||
Data: (*hexutil.Bytes)(&data),
|
||||
AccessList: args.AccessList,
|
||||
}
|
||||
latestBlockNr := rpc.BlockNumberOrHashWithNumber(rpc.LatestBlockNumber)
|
||||
estimated, err := DoEstimateGas(ctx, b, callArgs, latestBlockNr, nil, b.RPCGasCap())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
args.Gas = &estimated
|
||||
log.Trace("Estimate gas usage automatically", "gas", args.Gas)
|
||||
}
|
||||
pendingBlockNr := rpc.BlockNumberOrHashWithNumber(rpc.PendingBlockNumber)
|
||||
estimated, err := DoEstimateGas(ctx, b, callArgs, pendingBlockNr, nil, b.RPCGasCap())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
args.Gas = &estimated
|
||||
log.Trace("Estimate gas usage automatically", "gas", args.Gas)
|
||||
}
|
||||
|
||||
// If chain id is provided, ensure it matches the local chain id. Otherwise, set the local
|
||||
// chain id as the default.
|
||||
want := b.ChainConfig().ChainId
|
||||
|
|
|
|||
Loading…
Reference in a new issue