Skip to content

Commit b69c56c

Browse files
committed
fix: make retry attempts respect current slot number
1 parent 0d88be1 commit b69c56c

File tree

1 file changed

+37
-11
lines changed

1 file changed

+37
-11
lines changed

src/tasks/submit/task.rs

Lines changed: 37 additions & 11 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();
@@ -236,14 +255,21 @@ impl SubmitTask {
236255
self.config.clone(),
237256
self.constants,
238257
);
239-
let bumpable =
240-
match prep.prep_transaction(&sim_result.env.host).instrument(span.clone()).await {
241-
Ok(bumpable) => bumpable,
242-
Err(error) => {
243-
error!(%error, "failed to prepare transaction for submission");
244-
continue;
245-
}
246-
};
258+
let bumpable = match prep
259+
.prep_transaction(&sim_result.env.host)
260+
.instrument(span.clone())
261+
.await
262+
{
263+
Ok(bumpable) => bumpable,
264+
Err(error) => {
265+
// NB: I think this needs to handle 403 errors
266+
error.to_string().contains("403 Forbidden").then(|| {
267+
warn!(%error, "403 forbidden error detected - SHOULD be skipping block");
268+
});
269+
error!(%error, "failed to prepare transaction for submission");
270+
continue;
271+
}
272+
};
247273

248274
// Simulate the transaction to check for reverts
249275
if let Err(error) = self.sim_with_call(bumpable.req()).instrument(span.clone()).await {

0 commit comments

Comments
 (0)