@@ -27,6 +27,14 @@ use signet_zenith::{
2727use std:: time:: { Instant , UNIX_EPOCH } ;
2828use tokio:: { sync:: mpsc, task:: JoinHandle } ;
2929
30+ // NB: Consider pulling the below gas parameters out into env vars
31+ /// Base maximum fee per gas to use as a starting point for retry bumps
32+ pub const BASE_FEE_PER_GAS : u128 = 10_000_000_000 ; // 10 Gwei
33+ /// Base max priority fee per gas to use as a starting point for retry bumps
34+ pub const BASE_MAX_PRIORITY_FEE_PER_GAS : u128 = 2_000_000_000 ; // 2 Gwei
35+ /// Base maximum fee per blob gas to use as a starting point for retry bumps
36+ pub const BASE_MAX_FEE_PER_BLOB_GAS : u128 = 1_000_000_000 ; // 1 Gwei
37+
3038macro_rules! spawn_provider_send {
3139 ( $provider: expr, $tx: expr) => {
3240 {
@@ -88,7 +96,7 @@ impl SubmitTask {
8896 } )
8997 }
9098
91- /// Builds blob transaction from the provided header and signature values
99+ /// Builds blob transaction and encodes the sidecar for it from the provided header and signature values
92100 fn build_blob_tx (
93101 & self ,
94102 fills : Vec < FillPermit2 > ,
@@ -187,17 +195,23 @@ impl SubmitTask {
187195 ) -> Result < TransactionRequest , eyre:: Error > {
188196 // TODO: ENG-1082 Implement fills
189197 let fills = vec ! [ ] ;
198+
199+ // manually retrieve nonce
200+ let nonce =
201+ self . provider ( ) . get_transaction_count ( self . provider ( ) . default_signer_address ( ) ) . await ?;
202+ debug ! ( nonce, "assigned nonce" ) ;
203+
190204 // Extract the signature components from the response
191205 let ( v, r, s) = extract_signature_components ( & resp. sig ) ;
192206
193207 // Calculate gas limits based on retry attempts
194208 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" ) ;
209+ calculate_gas_limits (
210+ retry_count ,
211+ BASE_FEE_PER_GAS ,
212+ BASE_MAX_PRIORITY_FEE_PER_GAS ,
213+ BASE_MAX_FEE_PER_BLOB_GAS ,
214+ ) ;
201215
202216 // Build the block header
203217 let header: BlockHeader = BlockHeader {
@@ -249,8 +263,7 @@ impl SubmitTask {
249263
250264 if let Err ( e) = fut. await ? {
251265 // 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- {
266+ if matches ! ( e, TransportError :: ErrorResp ( ref err) if err. code == -32603 ) {
254267 debug ! ( ?tx, "underpriced transaction error - retrying tx with gas bump" ) ;
255268 return Ok ( ControlFlow :: Retry ) ;
256269 }
@@ -429,18 +442,20 @@ impl SubmitTask {
429442 }
430443}
431444
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-
445+ // Returns gas parameters based on retry counts. This uses
446+ fn calculate_gas_limits (
447+ retry_count : usize ,
448+ base_max_fee_per_gas : u128 ,
449+ base_max_priority_fee_per_gas : u128 ,
450+ base_max_fee_per_blob_gas : u128 ,
451+ ) -> ( u128 , u128 , u128 ) {
437452 let bump_multiplier = 1150u128 . pow ( retry_count as u32 ) ; // 15% bump
438453 let blob_bump_multiplier = 2000u128 . pow ( retry_count as u32 ) ; // 100% bump (double each time) for blob gas
439454 let bump_divisor = 1000u128 . pow ( retry_count as u32 ) ;
440455
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;
456+ let max_fee_per_gas = base_max_fee_per_gas * bump_multiplier / bump_divisor;
457+ let max_priority_fee_per_gas = base_max_priority_fee_per_gas * bump_multiplier / bump_divisor;
458+ let max_fee_per_blob_gas = base_max_fee_per_blob_gas * blob_bump_multiplier / bump_divisor;
444459
445460 debug ! (
446461 retry_count,
0 commit comments