diff --git a/Cargo.lock b/Cargo.lock index 17ac2c6..2ca77cb 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3265,9 +3265,9 @@ dependencies = [ [[package]] name = "init4-bin-base" -version = "0.5.0" +version = "0.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "100791001b102736de187914994c7b359bd5ddedc4346b825f9ed0353af47045" +checksum = "cd40a042a02db58529e28c17b4da70c0d48553fae93a6a8268acf49ece9c5a99" dependencies = [ "alloy", "async-trait", diff --git a/Cargo.toml b/Cargo.toml index 4d86a7a..096621b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -25,7 +25,7 @@ path = "bin/submit_transaction.rs" integration = [] [dependencies] -init4-bin-base = { version = "0.5.0", features = ["perms"] } +init4-bin-base = { version = "0.6.0", features = ["perms"] } signet-constants = { version = "0.4.2" } signet-sim = { version = "0.4.2" } diff --git a/src/tasks/block/sim.rs b/src/tasks/block/sim.rs index 6af48f5..f9775e0 100644 --- a/src/tasks/block/sim.rs +++ b/src/tasks/block/sim.rs @@ -209,7 +209,8 @@ impl Simulator { /// the time left in the current slot and adding that to the current timestamp in UNIX seconds. pub fn calculate_deadline(&self) -> Instant { // Get the current timepoint within the slot. - let timepoint = self.slot_calculator().current_timepoint_within_slot(); + let timepoint = + self.slot_calculator().current_point_within_slot().expect("host chain has started"); // We have the timepoint in seconds into the slot. To find out what's // remaining, we need to subtract it from the slot duration diff --git a/src/tasks/submit/task.rs b/src/tasks/submit/task.rs index 025b9cd..7bb9993 100644 --- a/src/tasks/submit/task.rs +++ b/src/tasks/submit/task.rs @@ -20,7 +20,7 @@ use init4_bin_base::deps::{ tracing::{Instrument, debug, debug_span, error, info, warn}, }; use signet_constants::SignetSystemConstants; -use std::time::Instant; +use std::{ops::Range, time::Instant}; use tokio::{sync::mpsc, task::JoinHandle}; macro_rules! spawn_provider_send { @@ -131,8 +131,16 @@ impl SubmitTask { ) -> eyre::Result { let submitting_start_time = Instant::now(); let now = utils::now(); - let (expected_slot, start, end) = self.calculate_slot_window(); - debug!(expected_slot, start, end, now, "calculating target slot window"); + + let (expected_slot, window) = self.get_expected_slot_and_window(); + + debug!( + expected_slot, + start = window.start, + end = window.end, + now, + "calculating target slot window" + ); let mut req = bumpable.req().clone(); @@ -172,7 +180,10 @@ impl SubmitTask { return Ok(ControlFlow::Skip); } drop(guard); - debug!(retries = bumpable.bump_count(), start, end, "retrying block"); + debug!( + retries = bumpable.bump_count(), + window.start, window.end, "retrying block" + ); continue; } ControlFlow::Skip => { @@ -199,9 +210,20 @@ impl SubmitTask { Ok(result) } + /// Gets the expected slot and the slot window for the current slot. + fn get_expected_slot_and_window(&self) -> (usize, Range) { + let expected_slot = + self.config.slot_calculator.current_slot().expect("host chain has started"); + + let window = self.config.slot_calculator.slot_window(expected_slot); + + (expected_slot, window) + } + /// Checks if a slot is still valid during submission retries. - fn slot_still_valid(&self, initial_slot: u64) -> Option> { - let (current_slot, _, _) = self.calculate_slot_window(); + fn slot_still_valid(&self, initial_slot: usize) -> Option> { + let current_slot = + self.config.slot_calculator.current_slot().expect("host chain has started"); if current_slot != initial_slot { // If the slot has changed, skip the block debug!(current_slot, initial_slot, "slot changed before submission - skipping block"); @@ -212,14 +234,6 @@ impl SubmitTask { None } - /// Calculates and returns the slot number and its start and end timestamps for the current instant. - fn calculate_slot_window(&self) -> (u64, u64, u64) { - let now_ts = utils::now(); - let current_slot = self.config.slot_calculator.calculate_slot(now_ts); - let (start, end) = self.config.slot_calculator.calculate_slot_window(current_slot); - (current_slot, start, end) - } - /// Task future for the submit task. This function runs the main loop of the task. async fn task_future(self, mut inbound: mpsc::UnboundedReceiver) { loop {