internal/ethapi: refactor `TxArgs.setCancunFeeDefaults` (#30541)

calculating a reasonable tx blob fee cap (`max_blob_fee_per_gas *
total_blob_gas`) only depends on the excess blob gas of the parent
header. The parent header is assumed to be correct, so the method should
not be able to fail and return an error.
pull/30602/head
jwasinger 1 month ago committed by GitHub
parent add5709cb5
commit 4b9c7821b9
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 7
      internal/ethapi/transaction_args.go

@ -189,9 +189,7 @@ func (args *TransactionArgs) setFeeDefaults(ctx context.Context, b Backend) erro
if args.BlobFeeCap != nil && args.BlobFeeCap.ToInt().Sign() == 0 { if args.BlobFeeCap != nil && args.BlobFeeCap.ToInt().Sign() == 0 {
return errors.New("maxFeePerBlobGas, if specified, must be non-zero") return errors.New("maxFeePerBlobGas, if specified, must be non-zero")
} }
if err := args.setCancunFeeDefaults(ctx, head, b); err != nil { args.setCancunFeeDefaults(head)
return err
}
// If both gasPrice and at least one of the EIP-1559 fee parameters are specified, error. // If both gasPrice and at least one of the EIP-1559 fee parameters are specified, error.
if args.GasPrice != nil && (args.MaxFeePerGas != nil || args.MaxPriorityFeePerGas != nil) { if args.GasPrice != nil && (args.MaxFeePerGas != nil || args.MaxPriorityFeePerGas != nil) {
return errors.New("both gasPrice and (maxFeePerGas or maxPriorityFeePerGas) specified") return errors.New("both gasPrice and (maxFeePerGas or maxPriorityFeePerGas) specified")
@ -243,7 +241,7 @@ func (args *TransactionArgs) setFeeDefaults(ctx context.Context, b Backend) erro
} }
// setCancunFeeDefaults fills in reasonable default fee values for unspecified fields. // setCancunFeeDefaults fills in reasonable default fee values for unspecified fields.
func (args *TransactionArgs) setCancunFeeDefaults(ctx context.Context, head *types.Header, b Backend) error { func (args *TransactionArgs) setCancunFeeDefaults(head *types.Header) {
// Set maxFeePerBlobGas if it is missing. // Set maxFeePerBlobGas if it is missing.
if args.BlobHashes != nil && args.BlobFeeCap == nil { if args.BlobHashes != nil && args.BlobFeeCap == nil {
var excessBlobGas uint64 var excessBlobGas uint64
@ -258,7 +256,6 @@ func (args *TransactionArgs) setCancunFeeDefaults(ctx context.Context, head *typ
val := new(big.Int).Mul(blobBaseFee, big.NewInt(2)) val := new(big.Int).Mul(blobBaseFee, big.NewInt(2))
args.BlobFeeCap = (*hexutil.Big)(val) args.BlobFeeCap = (*hexutil.Big)(val)
} }
return nil
} }
// setLondonFeeDefaults fills in reasonable default fee values for unspecified fields. // setLondonFeeDefaults fills in reasonable default fee values for unspecified fields.

Loading…
Cancel
Save