Skip to content

fix: make retry attempts respect current slot number #108

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jun 16, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 22 additions & 3 deletions src/tasks/submit/task.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,9 +130,9 @@ impl SubmitTask {
retry_limit: usize,
) -> eyre::Result<ControlFlow> {
let submitting_start_time = Instant::now();

let (current_slot, start, end) = self.calculate_slot_window();
debug!(current_slot, start, end, "calculating target slot window");
let now = utils::now();
let (expected_slot, start, end) = self.calculate_slot_window();
debug!(expected_slot, start, end, now, "calculating target slot window");

let mut req = bumpable.req().clone();

Expand All @@ -147,6 +147,9 @@ impl SubmitTask {
let inbound_result = match self.send_transaction(req).instrument(span.clone()).await {
Ok(control_flow) => control_flow,
Err(error) => {
if let Some(value) = self.slot_still_valid(expected_slot) {
return value;
}
// Log error and retry
error!(%error, "error handling inbound block");
ControlFlow::Retry
Expand All @@ -157,6 +160,9 @@ impl SubmitTask {

match inbound_result {
ControlFlow::Retry => {
if let Some(value) = self.slot_still_valid(expected_slot) {
return value;
}
// bump the req
req = bumpable.bumped();
if bumpable.bump_count() > retry_limit {
Expand Down Expand Up @@ -192,6 +198,19 @@ impl SubmitTask {
Ok(result)
}

/// Checks if a slot is still valid during submission retries.
fn slot_still_valid(&self, initial_slot: u64) -> Option<Result<ControlFlow, eyre::Error>> {
let (current_slot, _, _) = self.calculate_slot_window();
if current_slot != initial_slot {
// If the slot has changed, skip the block
debug!(current_slot, initial_slot, "slot changed before submission - skipping block");
counter!("builder.slot_missed").increment(1);
return Some(Ok(ControlFlow::Skip));
}
debug!(current_slot, "slot still valid - continuing submission");
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();
Expand Down