mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-20 10:52:25 +00:00
address comments
This commit is contained in:
parent
2eea30de8a
commit
ee59f15a10
1 changed files with 28 additions and 29 deletions
|
|
@ -96,7 +96,7 @@ func (args *TransactionArgs) data() []byte {
|
||||||
}
|
}
|
||||||
|
|
||||||
// setDefaults fills in default values for unspecified tx fields.
|
// setDefaults fills in default values for unspecified tx fields.
|
||||||
func (args *TransactionArgs) setDefaults(ctx context.Context, b Backend, infiniteGas bool) error {
|
func (args *TransactionArgs) setDefaults(ctx context.Context, b Backend, skipGasEstimation bool) error {
|
||||||
if err := args.setBlobTxSidecar(ctx, b); err != nil {
|
if err := args.setBlobTxSidecar(ctx, b); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
@ -135,37 +135,36 @@ func (args *TransactionArgs) setDefaults(ctx context.Context, b Backend, infinit
|
||||||
return errors.New(`contract creation without any data provided`)
|
return errors.New(`contract creation without any data provided`)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Assign a very high gas limit for cases where an accurate gas limit is not critical,
|
|
||||||
// but need to ensure that gas is sufficient.
|
|
||||||
if infiniteGas {
|
|
||||||
tmp := hexutil.Uint64(math.MaxUint64 / 2)
|
|
||||||
args.Gas = &tmp
|
|
||||||
}
|
|
||||||
|
|
||||||
// Estimate the gas usage if necessary.
|
|
||||||
if args.Gas == nil {
|
if args.Gas == nil {
|
||||||
// These fields are immutable during the estimation, safe to
|
if skipGasEstimation { // Skip gas usage estimation if a precise gas limit is not critical, e.g., in non-transaction calls.
|
||||||
// pass the pointer directly.
|
gas := hexutil.Uint64(b.RPCGasCap())
|
||||||
data := args.data()
|
if gas == 0 {
|
||||||
callArgs := TransactionArgs{
|
gas = hexutil.Uint64(math.MaxUint64 / 2)
|
||||||
From: args.From,
|
}
|
||||||
To: args.To,
|
args.Gas = &gas
|
||||||
GasPrice: args.GasPrice,
|
} else { // Estimate the gas usage otherwise.
|
||||||
MaxFeePerGas: args.MaxFeePerGas,
|
// These fields are immutable during the estimation, safe to
|
||||||
MaxPriorityFeePerGas: args.MaxPriorityFeePerGas,
|
// pass the pointer directly.
|
||||||
Value: args.Value,
|
data := args.data()
|
||||||
Data: (*hexutil.Bytes)(&data),
|
callArgs := TransactionArgs{
|
||||||
AccessList: args.AccessList,
|
From: args.From,
|
||||||
BlobFeeCap: args.BlobFeeCap,
|
To: args.To,
|
||||||
BlobHashes: args.BlobHashes,
|
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)
|
||||||
}
|
}
|
||||||
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)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// If chain id is provided, ensure it matches the local chain id. Otherwise, set the local
|
// If chain id is provided, ensure it matches the local chain id. Otherwise, set the local
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue