@@ -20,7 +20,7 @@ use init4_bin_base::deps::{
20
20
tracing:: { Instrument , debug, debug_span, error, info, warn} ,
21
21
} ;
22
22
use signet_constants:: SignetSystemConstants ;
23
- use std:: time:: Instant ;
23
+ use std:: { ops :: Range , time:: Instant } ;
24
24
use tokio:: { sync:: mpsc, task:: JoinHandle } ;
25
25
26
26
macro_rules! spawn_provider_send {
@@ -131,8 +131,16 @@ impl SubmitTask {
131
131
) -> eyre:: Result < ControlFlow > {
132
132
let submitting_start_time = Instant :: now ( ) ;
133
133
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
+ ) ;
136
144
137
145
let mut req = bumpable. req ( ) . clone ( ) ;
138
146
@@ -172,7 +180,10 @@ impl SubmitTask {
172
180
return Ok ( ControlFlow :: Skip ) ;
173
181
}
174
182
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
+ ) ;
176
187
continue ;
177
188
}
178
189
ControlFlow :: Skip => {
@@ -199,9 +210,20 @@ impl SubmitTask {
199
210
Ok ( result)
200
211
}
201
212
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
+
202
223
/// 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" ) ;
205
227
if current_slot != initial_slot {
206
228
// If the slot has changed, skip the block
207
229
debug ! ( current_slot, initial_slot, "slot changed before submission - skipping block" ) ;
@@ -212,14 +234,6 @@ impl SubmitTask {
212
234
None
213
235
}
214
236
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
-
223
237
/// Task future for the submit task. This function runs the main loop of the task.
224
238
async fn task_future ( self , mut inbound : mpsc:: UnboundedReceiver < SimResult > ) {
225
239
loop {
0 commit comments