Skip to content

refactor: split get_requests_to_attempt in queue.rs#3286

Merged
kevindeforth merged 1 commit into
mainfrom
kd/refactor
May 20, 2026
Merged

refactor: split get_requests_to_attempt in queue.rs#3286
kevindeforth merged 1 commit into
mainfrom
kd/refactor

Conversation

@kevindeforth

Copy link
Copy Markdown
Contributor

Part of #3070

@kevindeforth kevindeforth changed the title pure reactor of queue.rs refactor: split get_requests_to_attempt in queue.rs May 19, 2026
@kevindeforth kevindeforth marked this pull request as ready for review May 19, 2026 12:52
@claude

claude Bot commented May 19, 2026

Copy link
Copy Markdown

Pull request overview

Pure refactor of crates/node/src/requests/queue.rs. The previously large get_requests_to_attempt body is split into focused helpers on QueuedRequest (update_next_check_due, has_active_attempt, is_older_than, process) and on ComputationProgress (update_computation_progress). Control flow is expressed via new RequestStatusResult and RemovalReason enums, with metric_label() centralizing the MPC_CLUSTER_FAILED_SIGNATURES_COUNT label mapping. Outward behavior is preserved.

Changes

  • Extract per-request processing into QueuedRequest::process returning a RequestStatusResult instead of an open-coded loop with continues.
  • Extract attempts/back-off bookkeeping into ComputationProgress::update_computation_progress.
  • Introduce RemovalReason enum centralizing the failure-removal metric label and tracing reason.
  • Precompute cutoff_block once outside the per-request loop instead of recomputing inline with Add.

Reviewed changes
crates/node/src/requests/queue.rs — Split get_requests_to_attempt into helpers; add RequestStatusResult and RemovalReason enums; precompute cutoff_block; drop unused std::ops::Add import.

Findings

Verified behavior matches the original on every branch:

  • Cutoff arithmetic: maximum_height.saturating_sub(REQUEST_EXPIRATION_BLOCKS) + 1 is equivalent to the previous ...saturating_sub(...).add(1). The boundary tests should_not_expire_request_at_expiration_boundary and should_expire_request_past_expiration_boundary still pin the off-by-one correctly.
  • update_next_check_due bumps the timer iff next_check_due <= now and runs before has_active_attempt, matching the original ordering (so an active attempt still defers the next check by CHECK_EACH_REQUEST_INTERVAL).
  • progress.selected_leader = Some(leader) is set under the canonical + eligible-leader path only, exactly as before; the mutex is released on every RequestStatusResult return.
  • Metric labels (max_tries_exceeded, block_not_found, timeout) and the signature-only gating are preserved via RemovalReason::metric_label.

Non-blocking nits

  • crates/node/src/requests/queue.rs:586 — some Wait reason strings (pending computation, request is not on canonical chain) are slightly less descriptive than the original log lines (e.g. lost the last-response-submitted-too-recently hint). Not a regression. On the upside, the new path now logs no-eligible-leaders and we-are-not-leader, where the original was silent.
  • crates/node/src/requests/queue.rs:570 — cutoff_block = ... + 1 would overflow only if maximum_height == u64::MAX, matching the prior add(1); saturating_add(1) would close that purely-theoretical gap.

Approved.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR refactors PendingRequests::get_requests_to_attempt in crates/node/src/requests/queue.rs by extracting per-request decision logic into QueuedRequest::process and introducing small helper enums, improving readability and making individual decision paths more explicit (as part of the broader work in #3070).

Changes:

  • Extracted request evaluation logic into QueuedRequest::process and small helper methods (update_next_check_due, has_active_attempt, is_older_than).
  • Introduced RemovalReason/RequestStatusResult to centralize removal/skip/attempt outcomes and metric label selection.
  • Simplified cutoff-block computation and removed an unused std::ops::Add import.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +201 to +204
/// If [`Self::attempts`] is less than [`MAX_ATTEMPTS_PER_REQUEST_AS_LEADER`], then increments
/// [`Self::attempts`] by one and returns [`ComputationProgressStatus::NewAttempt`].
/// Otherwise returns [`ComputationProgressStatus::MaxAttemptsExceeded`] or
/// [`ComputationProgressStatus::Pending`].
RequestStatusResult::Remove(RemovalReason::MaxAttemptsExceeded)
}
ComputationProgressStatus::Pending => {
RequestStatusResult::Wait("pending computation")

@gilcu3 gilcu3 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

@kevindeforth kevindeforth enabled auto-merge May 19, 2026 17:05

@barakeinav1 barakeinav1 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@kevindeforth kevindeforth added this pull request to the merge queue May 20, 2026
Merged via the queue into main with commit c6377dd May 20, 2026
24 checks passed
@kevindeforth kevindeforth deleted the kd/refactor branch May 20, 2026 06:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants