@@ -177,6 +177,14 @@ func (args *TransactionArgs) setDefaults(ctx context.Context, b Backend) error {
177
177
178
178
// setFeeDefaults fills in default fee values for unspecified tx fields.
179
179
func (args * TransactionArgs ) setFeeDefaults (ctx context.Context , b Backend ) error {
180
+ head := b .CurrentHeader ()
181
+ // Sanity check the EIP-4844 fee parameters.
182
+ if args .BlobFeeCap != nil && args .BlobFeeCap .ToInt ().Sign () == 0 {
183
+ return errors .New ("maxFeePerBlobGas, if specified, must be non-zero" )
184
+ }
185
+ if err := args .setCancunFeeDefaults (ctx , head , b ); err != nil {
186
+ return err
187
+ }
180
188
// If both gasPrice and at least one of the EIP-1559 fee parameters are specified, error.
181
189
if args .GasPrice != nil && (args .MaxFeePerGas != nil || args .MaxPriorityFeePerGas != nil ) {
182
190
return errors .New ("both gasPrice and (maxFeePerGas or maxPriorityFeePerGas) specified" )
@@ -186,7 +194,6 @@ func (args *TransactionArgs) setFeeDefaults(ctx context.Context, b Backend) erro
186
194
// other tx values. See https://github.com/ethereum/go-ethereum/pull/23274
187
195
// for more information.
188
196
eip1559ParamsSet := args .MaxFeePerGas != nil && args .MaxPriorityFeePerGas != nil
189
-
190
197
// Sanity check the EIP-1559 fee parameters if present.
191
198
if args .GasPrice == nil && eip1559ParamsSet {
192
199
if args .MaxFeePerGas .ToInt ().Sign () == 0 {
@@ -198,13 +205,7 @@ func (args *TransactionArgs) setFeeDefaults(ctx context.Context, b Backend) erro
198
205
return nil // No need to set anything, user already set MaxFeePerGas and MaxPriorityFeePerGas
199
206
}
200
207
201
- // Sanity check the EIP-4844 fee parameters.
202
- if args .BlobFeeCap != nil && args .BlobFeeCap .ToInt ().Sign () == 0 {
203
- return errors .New ("maxFeePerBlobGas must be non-zero" )
204
- }
205
-
206
208
// Sanity check the non-EIP-1559 fee parameters.
207
- head := b .CurrentHeader ()
208
209
isLondon := b .ChainConfig ().IsLondon (head .Number )
209
210
if args .GasPrice != nil && ! eip1559ParamsSet {
210
211
// Zero gas-price is not allowed after London fork
@@ -215,21 +216,14 @@ func (args *TransactionArgs) setFeeDefaults(ctx context.Context, b Backend) erro
215
216
}
216
217
217
218
// Now attempt to fill in default value depending on whether London is active or not.
218
- if b .ChainConfig ().IsCancun (head .Number , head .Time ) {
219
- if err := args .setCancunFeeDefaults (ctx , head , b ); err != nil {
220
- return err
221
- }
222
- } else if isLondon {
223
- if args .BlobFeeCap != nil {
224
- return errors .New ("maxFeePerBlobGas is not valid before Cancun is active" )
225
- }
219
+ if isLondon {
226
220
// London is active, set maxPriorityFeePerGas and maxFeePerGas.
227
221
if err := args .setLondonFeeDefaults (ctx , head , b ); err != nil {
228
222
return err
229
223
}
230
224
} else {
231
- if args .MaxFeePerGas != nil || args .MaxPriorityFeePerGas != nil || args . BlobFeeCap != nil {
232
- return errors .New ("maxFeePerGas and maxPriorityFeePerGas and maxFeePerBlobGas are not valid before London is active" )
225
+ if args .MaxFeePerGas != nil || args .MaxPriorityFeePerGas != nil {
226
+ return errors .New ("maxFeePerGas and maxPriorityFeePerGas are not valid before London is active" )
233
227
}
234
228
// London not active, set gas price.
235
229
price , err := b .SuggestGasTipCap (ctx )
@@ -245,15 +239,19 @@ func (args *TransactionArgs) setFeeDefaults(ctx context.Context, b Backend) erro
245
239
func (args * TransactionArgs ) setCancunFeeDefaults (ctx context.Context , head * types.Header , b Backend ) error {
246
240
// Set maxFeePerBlobGas if it is missing.
247
241
if args .BlobHashes != nil && args .BlobFeeCap == nil {
242
+ var excessBlobGas uint64
243
+ if head .ExcessBlobGas != nil {
244
+ excessBlobGas = * head .ExcessBlobGas
245
+ }
248
246
// ExcessBlobGas must be set for a Cancun block.
249
- blobBaseFee := eip4844 .CalcBlobFee (* head . ExcessBlobGas )
247
+ blobBaseFee := eip4844 .CalcBlobFee (excessBlobGas )
250
248
// Set the max fee to be 2 times larger than the previous block's blob base fee.
251
249
// The additional slack allows the tx to not become invalidated if the base
252
250
// fee is rising.
253
251
val := new (big.Int ).Mul (blobBaseFee , big .NewInt (2 ))
254
252
args .BlobFeeCap = (* hexutil .Big )(val )
255
253
}
256
- return args . setLondonFeeDefaults ( ctx , head , b )
254
+ return nil
257
255
}
258
256
259
257
// setLondonFeeDefaults fills in reasonable default fee values for unspecified fields.
0 commit comments