@@ -4,7 +4,7 @@ use crate::{
4
4
utils:: extract_signature_components,
5
5
} ;
6
6
use alloy:: {
7
- consensus:: SimpleCoder ,
7
+ consensus:: { SimpleCoder , constants :: GWEI_TO_WEI } ,
8
8
eips:: BlockNumberOrTag ,
9
9
network:: { TransactionBuilder , TransactionBuilder4844 } ,
10
10
primitives:: { FixedBytes , TxHash , U256 } ,
@@ -21,12 +21,19 @@ use init4_bin_base::deps::{
21
21
use signet_sim:: BuiltBlock ;
22
22
use signet_types:: { SignRequest , SignResponse } ;
23
23
use signet_zenith:: {
24
- BundleHelper :: { self , BlockHeader , FillPermit2 , submitCall } ,
24
+ BundleHelper :: { self , submitCall , BlockHeader , FillPermit2 } ,
25
25
Zenith :: { self , IncorrectHostBlock } ,
26
26
} ;
27
27
use std:: time:: { Instant , UNIX_EPOCH } ;
28
28
use tokio:: { sync:: mpsc, task:: JoinHandle } ;
29
29
30
+ /// Base maximum fee per gas to use as a starting point for retry bumps
31
+ pub const BASE_FEE_PER_GAS : u128 = 10 * GWEI_TO_WEI as u128 ;
32
+ /// Base max priority fee per gas to use as a starting point for retry bumps
33
+ pub const BASE_MAX_PRIORITY_FEE_PER_GAS : u128 = 2 * GWEI_TO_WEI as u128 ;
34
+ /// Base maximum fee per blob gas to use as a starting point for retry bumps
35
+ pub const BASE_MAX_FEE_PER_BLOB_GAS : u128 = 1 * GWEI_TO_WEI as u128 ;
36
+
30
37
macro_rules! spawn_provider_send {
31
38
( $provider: expr, $tx: expr) => {
32
39
{
@@ -88,7 +95,7 @@ impl SubmitTask {
88
95
} )
89
96
}
90
97
91
- /// Builds blob transaction from the provided header and signature values
98
+ /// Builds blob transaction and encodes the sidecar for it from the provided header and signature values
92
99
fn build_blob_tx (
93
100
& self ,
94
101
fills : Vec < FillPermit2 > ,
@@ -187,17 +194,23 @@ impl SubmitTask {
187
194
) -> Result < TransactionRequest , eyre:: Error > {
188
195
// TODO: ENG-1082 Implement fills
189
196
let fills = vec ! [ ] ;
197
+
198
+ // manually retrieve nonce
199
+ let nonce =
200
+ self . provider ( ) . get_transaction_count ( self . provider ( ) . default_signer_address ( ) ) . await ?;
201
+ debug ! ( nonce, "assigned nonce" ) ;
202
+
190
203
// Extract the signature components from the response
191
204
let ( v, r, s) = extract_signature_components ( & resp. sig ) ;
192
205
193
206
// Calculate gas limits based on retry attempts
194
207
let ( max_fee_per_gas, max_priority_fee_per_gas, max_fee_per_blob_gas) =
195
- calculate_gas_limits ( retry_count ) ;
196
-
197
- // manually retrieve nonce // TODO: Maybe this should be done in Env task and passed through elsewhere
198
- let nonce =
199
- self . provider ( ) . get_transaction_count ( self . provider ( ) . default_signer_address ( ) ) . await ? ;
200
- debug ! ( nonce , "assigned nonce" ) ;
208
+ calculate_gas_limits (
209
+ retry_count ,
210
+ BASE_FEE_PER_GAS ,
211
+ BASE_MAX_PRIORITY_FEE_PER_GAS ,
212
+ BASE_MAX_FEE_PER_BLOB_GAS ,
213
+ ) ;
201
214
202
215
// Build the block header
203
216
let header: BlockHeader = BlockHeader {
@@ -249,9 +262,8 @@ impl SubmitTask {
249
262
250
263
if let Err ( e) = fut. await ? {
251
264
// Detect and handle transaction underprice errors
252
- if matches ! ( e, TransportError :: ErrorResp ( ref err) if err. code == -32000 && err. message. contains( "replacement transaction underpriced" ) )
253
- {
254
- debug ! ( ?tx, "underpriced transaction error - retrying tx with gas bump" ) ;
265
+ if matches ! ( e, TransportError :: ErrorResp ( ref err) if err. code == -32603 ) {
266
+ debug ! ( tx_hash = ?tx. hash( ) , "underpriced transaction error - retrying tx with gas bump" ) ;
255
267
return Ok ( ControlFlow :: Retry ) ;
256
268
}
257
269
@@ -303,7 +315,7 @@ impl SubmitTask {
303
315
) -> eyre:: Result < ControlFlow > {
304
316
let mut retries = 0 ;
305
317
let building_start_time = Instant :: now ( ) ;
306
- let ( current_slot, start, end) = self . calculate_slot_window ( ) ? ;
318
+ let ( current_slot, start, end) = self . calculate_slot_window ( ) ;
307
319
debug ! ( current_slot, start, end, "calculating target slot window" ) ;
308
320
309
321
// Retry loop
@@ -317,7 +329,7 @@ impl SubmitTask {
317
329
Err ( err) => {
318
330
// Delay until next slot if we get a 403 error
319
331
if err. to_string ( ) . contains ( "403 Forbidden" ) {
320
- let ( slot_number, _, _) = self . calculate_slot_window ( ) ? ;
332
+ let ( slot_number, _, _) = self . calculate_slot_window ( ) ;
321
333
debug ! ( slot_number, "403 detected - skipping slot" ) ;
322
334
return Ok ( ControlFlow :: Skip ) ;
323
335
} else {
@@ -363,11 +375,11 @@ impl SubmitTask {
363
375
}
364
376
365
377
/// Calculates and returns the slot number and its start and end timestamps for the current instant.
366
- fn calculate_slot_window ( & self ) -> eyre :: Result < ( u64 , u64 , u64 ) > {
378
+ fn calculate_slot_window ( & self ) -> ( u64 , u64 , u64 ) {
367
379
let now_ts = self . now ( ) ;
368
380
let current_slot = self . config . slot_calculator . calculate_slot ( now_ts) ;
369
381
let ( start, end) = self . config . slot_calculator . calculate_slot_window ( current_slot) ;
370
- Ok ( ( current_slot, start, end) )
382
+ ( current_slot, start, end)
371
383
}
372
384
373
385
/// Returns the current timestamp in seconds since the UNIX epoch.
@@ -397,12 +409,6 @@ impl SubmitTask {
397
409
} ;
398
410
debug ! ( block_number = block. block_number( ) , ?block, "submit channel received block" ) ;
399
411
400
- // Check if a block number was set and skip if not
401
- if block. block_number ( ) == 0 {
402
- debug ! ( "block number is 0 - skipping" ) ;
403
- continue ;
404
- }
405
-
406
412
// Only attempt each block number once
407
413
if block. block_number ( ) == last_block_attempted {
408
414
debug ! ( "block number is unchanged from last attempt - skipping" ) ;
@@ -429,18 +435,20 @@ impl SubmitTask {
429
435
}
430
436
}
431
437
432
- fn calculate_gas_limits ( retry_count : usize ) -> ( u128 , u128 , u128 ) {
433
- let base_fee_per_gas: u128 = 100_000_000_000 ;
434
- let base_priority_fee_per_gas: u128 = 2_000_000_000 ;
435
- let base_fee_per_blob_gas: u128 = 1_000_000_000 ;
436
-
438
+ // Returns gas parameters based on retry counts. This uses
439
+ fn calculate_gas_limits (
440
+ retry_count : usize ,
441
+ base_max_fee_per_gas : u128 ,
442
+ base_max_priority_fee_per_gas : u128 ,
443
+ base_max_fee_per_blob_gas : u128 ,
444
+ ) -> ( u128 , u128 , u128 ) {
437
445
let bump_multiplier = 1150u128 . pow ( retry_count as u32 ) ; // 15% bump
438
446
let blob_bump_multiplier = 2000u128 . pow ( retry_count as u32 ) ; // 100% bump (double each time) for blob gas
439
447
let bump_divisor = 1000u128 . pow ( retry_count as u32 ) ;
440
448
441
- let max_fee_per_gas = base_fee_per_gas * bump_multiplier / bump_divisor;
442
- let max_priority_fee_per_gas = base_priority_fee_per_gas * bump_multiplier / bump_divisor;
443
- let max_fee_per_blob_gas = base_fee_per_blob_gas * blob_bump_multiplier / bump_divisor;
449
+ let max_fee_per_gas = base_max_fee_per_gas * bump_multiplier / bump_divisor;
450
+ let max_priority_fee_per_gas = base_max_priority_fee_per_gas * bump_multiplier / bump_divisor;
451
+ let max_fee_per_blob_gas = base_max_fee_per_blob_gas * blob_bump_multiplier / bump_divisor;
444
452
445
453
debug ! (
446
454
retry_count,
0 commit comments