Skip to content

Commit 0b6779a

Browse files
authored
chore(deps): bump bin-base (#124)
* chore(deps): bump bin-base Also accomodates the new calculator changes. * chore: refactor fn to get expected slot and window
1 parent b8ba0fe commit 0b6779a

File tree

4 files changed

+33
-18
lines changed

4 files changed

+33
-18
lines changed

Cargo.lock

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ path = "bin/submit_transaction.rs"
2525
integration = []
2626

2727
[dependencies]
28-
init4-bin-base = { version = "0.5.0", features = ["perms"] }
28+
init4-bin-base = { version = "0.6.0", features = ["perms"] }
2929

3030
signet-constants = { version = "0.4.2" }
3131
signet-sim = { version = "0.4.2" }

src/tasks/block/sim.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,8 @@ impl Simulator {
209209
/// the time left in the current slot and adding that to the current timestamp in UNIX seconds.
210210
pub fn calculate_deadline(&self) -> Instant {
211211
// Get the current timepoint within the slot.
212-
let timepoint = self.slot_calculator().current_timepoint_within_slot();
212+
let timepoint =
213+
self.slot_calculator().current_point_within_slot().expect("host chain has started");
213214

214215
// We have the timepoint in seconds into the slot. To find out what's
215216
// remaining, we need to subtract it from the slot duration

src/tasks/submit/task.rs

Lines changed: 28 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ use init4_bin_base::deps::{
2020
tracing::{Instrument, debug, debug_span, error, info, warn},
2121
};
2222
use signet_constants::SignetSystemConstants;
23-
use std::time::Instant;
23+
use std::{ops::Range, time::Instant};
2424
use tokio::{sync::mpsc, task::JoinHandle};
2525

2626
macro_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

Comments
 (0)