Skip to content

Commit 5300118

Browse files
authored
fix: make retry attempts respect current slot number (#108)
# fix: make retry attempts respect current slot number Retry attempts were happening but if the slot changed in the middle of a retry attempt, it wouldn't recognize it and would get into an error loop, exhausting all retry attempts on an obviously incorrect block. Instead, this PR checks the initial slot number and each retry attempt will only happen if the slot is still valid. Closes ENG-1127
1 parent dd1fd3f commit 5300118

File tree

1 file changed

+22
-3
lines changed

1 file changed

+22
-3
lines changed

src/tasks/submit/task.rs

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -130,9 +130,9 @@ impl SubmitTask {
130130
retry_limit: usize,
131131
) -> eyre::Result<ControlFlow> {
132132
let submitting_start_time = Instant::now();
133-
134-
let (current_slot, start, end) = self.calculate_slot_window();
135-
debug!(current_slot, start, end, "calculating target slot window");
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");
136136

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

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

158161
match inbound_result {
159162
ControlFlow::Retry => {
163+
if let Some(value) = self.slot_still_valid(expected_slot) {
164+
return value;
165+
}
160166
// bump the req
161167
req = bumpable.bumped();
162168
if bumpable.bump_count() > retry_limit {
@@ -192,6 +198,19 @@ impl SubmitTask {
192198
Ok(result)
193199
}
194200

201+
/// Checks if a slot is still valid during submission retries.
202+
fn slot_still_valid(&self, initial_slot: u64) -> Option<Result<ControlFlow, eyre::Error>> {
203+
let (current_slot, _, _) = self.calculate_slot_window();
204+
if current_slot != initial_slot {
205+
// If the slot has changed, skip the block
206+
debug!(current_slot, initial_slot, "slot changed before submission - skipping block");
207+
counter!("builder.slot_missed").increment(1);
208+
return Some(Ok(ControlFlow::Skip));
209+
}
210+
debug!(current_slot, "slot still valid - continuing submission");
211+
None
212+
}
213+
195214
/// Calculates and returns the slot number and its start and end timestamps for the current instant.
196215
fn calculate_slot_window(&self) -> (u64, u64, u64) {
197216
let now_ts = utils::now();

0 commit comments

Comments
 (0)