Skip to content

Commit 4a23734

Browse files
committed
fix: make retry attempts respect current slot number
1 parent 4f0445e commit 4a23734

File tree

1 file changed

+28
-3
lines changed

1 file changed

+28
-3
lines changed

src/tasks/submit/task.rs

Lines changed: 28 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 (initial_slot, start, end) = self.calculate_slot_window();
135+
debug!(initial_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(initial_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(initial_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();
@@ -243,6 +262,12 @@ impl SubmitTask {
243262
{
244263
Ok(bumpable) => bumpable,
245264
Err(error) => {
265+
if error.to_string().contains("403 Forbidden") {
266+
// Don't error as this is expected behavior
267+
warn!(%error, "403 Forbidden detected - skipping block");
268+
continue
269+
}
270+
246271
error!(%error, "failed to prepare transaction for submission");
247272
continue;
248273
}

0 commit comments

Comments
 (0)