@@ -140,10 +140,7 @@ impl SubmitTask {
140
140
141
141
// Simulate the transaction with a call to the host provider
142
142
if let Some ( maybe_error) = self . sim_with_call ( & tx) . await {
143
- warn ! (
144
- error = ?maybe_error,
145
- "error in transaction simulation"
146
- ) ;
143
+ warn ! ( error = ?maybe_error, "error in transaction simulation" ) ;
147
144
if let Err ( e) = maybe_error {
148
145
return Err ( e) ;
149
146
}
@@ -207,20 +204,11 @@ impl SubmitTask {
207
204
) -> Result < TransactionRequest , eyre:: Error > {
208
205
// TODO: ENG-1082 Implement fills
209
206
let fills = vec ! [ ] ;
210
-
211
207
// Extract the signature components from the response
212
208
let ( v, r, s) = extract_signature_components ( & resp. sig ) ;
213
209
214
- // Bump gas with each retry to replace the previous
215
- // transaction while maintaining the same nonce
216
- // TODO: Clean this up if this works
217
- let gas_coefficient: u64 = ( 15 * ( retry_count + 1 ) ) . try_into ( ) . unwrap ( ) ;
218
- let gas_limit: u64 = 1_500_000 + ( gas_coefficient * 1_000_000 ) ;
219
- let max_priority_fee_per_gas: u128 = ( retry_count as u128 ) ;
220
- debug ! (
221
- retry_count,
222
- gas_coefficient, gas_limit, max_priority_fee_per_gas, "calculated gas limit"
223
- ) ;
210
+ // Calculate gas limits based on retry attempts
211
+ let ( max_fee_per_gas, max_priority_fee_per_gas) = calculate_gas_limits ( retry_count) ;
224
212
225
213
// manually retrieve nonce
226
214
let nonce =
@@ -242,8 +230,9 @@ impl SubmitTask {
242
230
. build_blob_tx ( fills, header, v, r, s, block) ?
243
231
. with_from ( self . provider ( ) . default_signer_address ( ) )
244
232
. with_to ( self . config . builder_helper_address )
245
- . with_gas_limit ( gas_limit )
233
+ . with_max_fee_per_gas ( max_fee_per_gas . into ( ) )
246
234
. with_max_priority_fee_per_gas ( max_priority_fee_per_gas)
235
+ . with_max_fee_per_blob_gas ( max_fee_per_gas)
247
236
. with_nonce ( nonce) ;
248
237
249
238
debug ! ( ?tx, "prepared transaction request" ) ;
@@ -258,9 +247,12 @@ impl SubmitTask {
258
247
tx : TransactionRequest ,
259
248
) -> Result < ControlFlow , eyre:: Error > {
260
249
debug ! (
250
+ ?tx. max_fee_per_gas,
251
+ ?tx. max_fee_per_blob_gas,
252
+ ?tx. max_priority_fee_per_gas,
253
+ nonce = ?tx. nonce,
261
254
host_block_number = %resp. req. host_block_number,
262
255
gas_limit = %resp. req. gas_limit,
263
- nonce = ?tx. nonce,
264
256
"sending transaction to network"
265
257
) ;
266
258
@@ -286,6 +278,12 @@ impl SubmitTask {
286
278
// question mark unwraps join error, which would be an internal panic
287
279
// then if let checks for rpc error
288
280
if let Err ( e) = fut. await ? {
281
+ let err_str = e. to_string ( ) ;
282
+ if err_str. contains ( "replacement transaction underpriced" ) {
283
+ // bump gas and repeat
284
+ debug ! ( "UNDERPRICE ERROR DETECTED" ) ;
285
+ return Ok ( ControlFlow :: Retry ) ;
286
+ }
289
287
error ! ( error = %e, "Primary tx broadcast failed. Skipping transaction." ) ;
290
288
return Ok ( ControlFlow :: Skip ) ;
291
289
}
@@ -341,54 +339,42 @@ impl SubmitTask {
341
339
342
340
// Retry loop
343
341
let result = loop {
342
+ // Log the retry attempt
344
343
let span = debug_span ! ( "SubmitTask::retrying_handle_inbound" , retries) ;
345
344
346
- let inbound_result = match self
347
- . handle_inbound ( retries, block)
348
- . instrument ( span. clone ( ) )
349
- . await
350
- {
351
- Ok ( control_flow) => {
352
- debug ! ( ?control_flow, retries, "successfully handled inbound block" ) ;
353
- control_flow
354
- }
355
- Err ( err) => {
356
- // Log the retry attempt
357
- retries += 1 ;
358
-
359
- // Delay until next slot if we get a 403 error
360
- if err. to_string ( ) . contains ( "403 Forbidden" ) {
361
- let ( slot_number, _, _) = self . calculate_slot_window ( ) ?;
362
- debug ! ( slot_number, ?block, "403 detected - not assigned to slot" ) ;
363
- return Ok ( ControlFlow :: Skip ) ;
364
- } else {
365
- error ! ( error = %err, "error handling inbound block" ) ;
345
+ let inbound_result =
346
+ match self . handle_inbound ( retries, block) . instrument ( span. clone ( ) ) . await {
347
+ Ok ( control_flow) => {
348
+ debug ! ( ?control_flow, retries, "successfully handled inbound block" ) ;
349
+ control_flow
366
350
}
367
-
368
- ControlFlow :: Retry
369
- }
370
- } ;
351
+ Err ( err) => {
352
+ retries += 1 ;
353
+ // Delay until next slot if we get a 403 error
354
+ if err. to_string ( ) . contains ( "403 Forbidden" ) {
355
+ let ( slot_number, _, _) = self . calculate_slot_window ( ) ?;
356
+ debug ! ( slot_number, ?block, "403 detected - not assigned to slot" ) ;
357
+ return Ok ( ControlFlow :: Skip ) ;
358
+ } else {
359
+ error ! ( error = %err, "error handling inbound block" ) ;
360
+ }
361
+
362
+ ControlFlow :: Retry
363
+ }
364
+ } ;
371
365
372
366
let guard = span. entered ( ) ;
373
367
374
368
match inbound_result {
375
369
ControlFlow :: Retry => {
370
+ retries += 1 ;
376
371
if retries > retry_limit {
377
372
counter ! ( "builder.building_too_many_retries" ) . increment ( 1 ) ;
378
373
debug ! ( "retries exceeded - skipping block" ) ;
379
374
return Ok ( ControlFlow :: Skip ) ;
380
375
}
381
376
drop ( guard) ;
382
-
383
- // Detect a slot change and break out of the loop in that case too
384
- let ( this_slot, start, end) = self . calculate_slot_window ( ) ?;
385
- if this_slot != current_slot {
386
- debug ! ( "slot changed - skipping block" ) ;
387
- break inbound_result;
388
- }
389
-
390
- // Otherwise retry the block
391
- debug ! ( retries, this_slot, start, end, "retrying block" ) ;
377
+ debug ! ( retries, start, end, "retrying block" ) ;
392
378
continue ;
393
379
}
394
380
ControlFlow :: Skip => {
@@ -471,3 +457,21 @@ impl SubmitTask {
471
457
( sender, handle)
472
458
}
473
459
}
460
+
461
+ fn calculate_gas_limits ( retry_count : usize ) -> ( u128 , u128 ) {
462
+ // Set a base gas amount
463
+ let base_gas = 1_500_000 ;
464
+ // Define a gas coefficient
465
+ let gas_coefficient: u64 = 1 + ( retry_count as u64 ) ;
466
+ // Determine gas limit by multiplying base gas by the coefficient
467
+ let max_fee_per_gas: u128 = ( base_gas + ( gas_coefficient * base_gas) ) as u128 ;
468
+ // Determine priority gas fee by multiplying retry count by the coefficient
469
+ let max_priority_fee_per_gas: u128 =
470
+ ( 1 + retry_count as u128 ) * ( gas_coefficient as u128 * 100_000 ) ;
471
+
472
+ debug ! (
473
+ retry_count,
474
+ gas_coefficient, max_fee_per_gas, max_priority_fee_per_gas, "calculated gas limits"
475
+ ) ;
476
+ ( max_fee_per_gas, max_priority_fee_per_gas)
477
+ }
0 commit comments