@@ -20,7 +20,7 @@ use init4_bin_base::deps::{
2020 tracing:: { Instrument , debug, debug_span, error, info, warn} ,
2121} ;
2222use signet_constants:: SignetSystemConstants ;
23- use std:: time:: Instant ;
23+ use std:: { ops :: Range , time:: Instant } ;
2424use tokio:: { sync:: mpsc, task:: JoinHandle } ;
2525
2626macro_rules! spawn_provider_send {
@@ -131,8 +131,16 @@ impl SubmitTask {
131131 ) -> eyre:: Result < ControlFlow > {
132132 let submitting_start_time = Instant :: now ( ) ;
133133 let now = utils:: now ( ) ;
134- let ( expected_slot, start, end) = self . calculate_slot_window ( ) ;
135- debug ! ( expected_slot, start, end, now, "calculating target slot window" ) ;
134+
135+ let ( expected_slot, window) = self . get_expected_slot_and_window ( ) ;
136+
137+ debug ! (
138+ expected_slot,
139+ start = window. start,
140+ end = window. end,
141+ now,
142+ "calculating target slot window"
143+ ) ;
136144
137145 let mut req = bumpable. req ( ) . clone ( ) ;
138146
@@ -172,7 +180,10 @@ impl SubmitTask {
172180 return Ok ( ControlFlow :: Skip ) ;
173181 }
174182 drop ( guard) ;
175- debug ! ( retries = bumpable. bump_count( ) , start, end, "retrying block" ) ;
183+ debug ! (
184+ retries = bumpable. bump_count( ) ,
185+ window. start, window. end, "retrying block"
186+ ) ;
176187 continue ;
177188 }
178189 ControlFlow :: Skip => {
@@ -199,9 +210,20 @@ impl SubmitTask {
199210 Ok ( result)
200211 }
201212
213+ /// Gets the expected slot and the slot window for the current slot.
214+ fn get_expected_slot_and_window ( & self ) -> ( usize , Range < u64 > ) {
215+ let expected_slot =
216+ self . config . slot_calculator . current_slot ( ) . expect ( "host chain has started" ) ;
217+
218+ let window = self . config . slot_calculator . slot_window ( expected_slot) ;
219+
220+ ( expected_slot, window)
221+ }
222+
202223 /// Checks if a slot is still valid during submission retries.
203- fn slot_still_valid ( & self , initial_slot : u64 ) -> Option < Result < ControlFlow , eyre:: Error > > {
204- let ( current_slot, _, _) = self . calculate_slot_window ( ) ;
224+ fn slot_still_valid ( & self , initial_slot : usize ) -> Option < Result < ControlFlow , eyre:: Error > > {
225+ let current_slot =
226+ self . config . slot_calculator . current_slot ( ) . expect ( "host chain has started" ) ;
205227 if current_slot != initial_slot {
206228 // If the slot has changed, skip the block
207229 debug ! ( current_slot, initial_slot, "slot changed before submission - skipping block" ) ;
@@ -212,14 +234,6 @@ impl SubmitTask {
212234 None
213235 }
214236
215- /// Calculates and returns the slot number and its start and end timestamps for the current instant.
216- fn calculate_slot_window ( & self ) -> ( u64 , u64 , u64 ) {
217- let now_ts = utils:: now ( ) ;
218- let current_slot = self . config . slot_calculator . calculate_slot ( now_ts) ;
219- let ( start, end) = self . config . slot_calculator . calculate_slot_window ( current_slot) ;
220- ( current_slot, start, end)
221- }
222-
223237 /// Task future for the submit task. This function runs the main loop of the task.
224238 async fn task_future ( self , mut inbound : mpsc:: UnboundedReceiver < SimResult > ) {
225239 loop {
0 commit comments