@@ -177,6 +177,14 @@ func (args *TransactionArgs) setDefaults(ctx context.Context, b Backend) error {
177177
178178// setFeeDefaults fills in default fee values for unspecified tx fields.
179179func (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+ }
180188 // If both gasPrice and at least one of the EIP-1559 fee parameters are specified, error.
181189 if args .GasPrice != nil && (args .MaxFeePerGas != nil || args .MaxPriorityFeePerGas != nil ) {
182190 return errors .New ("both gasPrice and (maxFeePerGas or maxPriorityFeePerGas) specified" )
@@ -186,7 +194,6 @@ func (args *TransactionArgs) setFeeDefaults(ctx context.Context, b Backend) erro
186194 // other tx values. See https://github.com/ethereum/go-ethereum/pull/23274
187195 // for more information.
188196 eip1559ParamsSet := args .MaxFeePerGas != nil && args .MaxPriorityFeePerGas != nil
189-
190197 // Sanity check the EIP-1559 fee parameters if present.
191198 if args .GasPrice == nil && eip1559ParamsSet {
192199 if args .MaxFeePerGas .ToInt ().Sign () == 0 {
@@ -198,13 +205,7 @@ func (args *TransactionArgs) setFeeDefaults(ctx context.Context, b Backend) erro
198205 return nil // No need to set anything, user already set MaxFeePerGas and MaxPriorityFeePerGas
199206 }
200207
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-
206208 // Sanity check the non-EIP-1559 fee parameters.
207- head := b .CurrentHeader ()
208209 isLondon := b .ChainConfig ().IsLondon (head .Number )
209210 if args .GasPrice != nil && ! eip1559ParamsSet {
210211 // Zero gas-price is not allowed after London fork
@@ -215,21 +216,14 @@ func (args *TransactionArgs) setFeeDefaults(ctx context.Context, b Backend) erro
215216 }
216217
217218 // 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 {
226220 // London is active, set maxPriorityFeePerGas and maxFeePerGas.
227221 if err := args .setLondonFeeDefaults (ctx , head , b ); err != nil {
228222 return err
229223 }
230224 } 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" )
233227 }
234228 // London not active, set gas price.
235229 price , err := b .SuggestGasTipCap (ctx )
@@ -245,15 +239,19 @@ func (args *TransactionArgs) setFeeDefaults(ctx context.Context, b Backend) erro
245239func (args * TransactionArgs ) setCancunFeeDefaults (ctx context.Context , head * types.Header , b Backend ) error {
246240 // Set maxFeePerBlobGas if it is missing.
247241 if args .BlobHashes != nil && args .BlobFeeCap == nil {
242+ var excessBlobGas uint64
243+ if head .ExcessBlobGas != nil {
244+ excessBlobGas = * head .ExcessBlobGas
245+ }
248246 // ExcessBlobGas must be set for a Cancun block.
249- blobBaseFee := eip4844 .CalcBlobFee (* head . ExcessBlobGas )
247+ blobBaseFee := eip4844 .CalcBlobFee (excessBlobGas )
250248 // Set the max fee to be 2 times larger than the previous block's blob base fee.
251249 // The additional slack allows the tx to not become invalidated if the base
252250 // fee is rising.
253251 val := new (big.Int ).Mul (blobBaseFee , big .NewInt (2 ))
254252 args .BlobFeeCap = (* hexutil .Big )(val )
255253 }
256- return args . setLondonFeeDefaults ( ctx , head , b )
254+ return nil
257255}
258256
259257// setLondonFeeDefaults fills in reasonable default fee values for unspecified fields.
0 commit comments