Skip to content

Commit

Permalink
add a bool flag to bypass gas estimation in setDefaults
Browse files Browse the repository at this point in the history
  • Loading branch information
colinlyguo committed Jan 29, 2024
1 parent 76cad9b commit 9424531
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 17 deletions.
22 changes: 6 additions & 16 deletions internal/ethapi/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -451,7 +451,7 @@ func (s *PersonalAccountAPI) signTransaction(ctx context.Context, args *Transact
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
Expand Down Expand Up @@ -1511,19 +1511,9 @@ func AccessList(ctx context.Context, b Backend, blockNrOrHash rpc.BlockNumberOrH
if db == nil || err != nil {
return nil, 0, nil, err
}
// If the gas amount is not set, default to RPC gas cap.
if args.Gas == nil {
if b.RPCGasCap() != 0 {
tmp := hexutil.Uint64(b.RPCGasCap())
args.Gas = &tmp
} else {
tmp := hexutil.Uint64(math.MaxUint64 / 2)
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
Expand Down Expand Up @@ -1828,7 +1818,7 @@ func (s *TransactionAPI) SendTransaction(ctx context.Context, args TransactionAr
}

// 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
Expand All @@ -1846,7 +1836,7 @@ func (s *TransactionAPI) SendTransaction(ctx context.Context, args TransactionAr
// processing (signing + broadcast).
func (s *TransactionAPI) 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
Expand Down Expand Up @@ -1916,7 +1906,7 @@ func (s *TransactionAPI) SignTransaction(ctx context.Context, args TransactionAr
if args.Nonce == nil {
return nil, errors.New("nonce not specified")
}
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.
Expand Down Expand Up @@ -1965,7 +1955,7 @@ func (s *TransactionAPI) Resend(ctx context.Context, sendArgs TransactionArgs, g
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()
Expand Down
8 changes: 7 additions & 1 deletion internal/ethapi/transaction_args.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,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, infiniteGas bool) error {
if err := args.setFeeDefaults(ctx, b); err != nil {
return err
}
Expand All @@ -107,6 +107,12 @@ 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`)
}
// 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 {
// These fields are immutable during the estimation, safe to
Expand Down

0 comments on commit 9424531

Please sign in to comment.