refactor: single-round timers with rescheduling#97
Conversation
There was a problem hiding this comment.
Pull request overview
This PR refactors timer-based processing functions to execute one round of concurrent work per invocation instead of looping through multiple rounds. After each round, timers reschedule themselves immediately with Duration::ZERO if there's more work, or with the normal delay if idle. This architectural change allows the IC scheduler to interleave other canister work between timer invocations, avoiding long-running timer callbacks.
Changes:
- Timer-based functions (
consolidate_deposits,process_pending_withdrawals,monitor_submitted_transactions) now execute a single round of work per invocation - Each function reschedules itself based on whether there's remaining work
- Replaced
set_timer_intervalwithset_timerin main timer setup - Removed
MAX_WITHDRAWAL_ROUNDSconstant and associated multi-round tests
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| minter/src/consolidate/mod.rs | Refactored to process one consolidation round per invocation with automatic rescheduling |
| minter/src/monitor/mod.rs | Refactored to process one round of transaction monitoring per invocation with extracted inner function |
| minter/src/withdraw_sol/mod.rs | Refactored to process one withdrawal round per invocation; removed multi-round tests |
| minter/src/withdraw_sol/tests.rs | Updated test calls to pass cloned runtime; removed multi-round test cases |
| minter/src/main.rs | Changed timer setup to use set_timer instead of set_timer_interval |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 14 out of 14 changed files in this pull request and generated no new comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
2ca221e to
899184c
Compare
899184c to
2b725d4
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 5 out of 5 changed files in this pull request and generated 4 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
2b725d4 to
5b63fde
Compare
5b63fde to
909192f
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
909192f to
b6a0ee5
Compare
b6a0ee5 to
2dafe84
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 8 out of 8 changed files in this pull request and generated no new comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
515cfcc to
cd0cdae
Compare
cd0cdae to
df69dca
Compare
c05d5a8 to
320ef52
Compare
320ef52 to
f0c874a
Compare
Process one round of concurrent RPC calls per timer invocation, then reschedule immediately (via set_timer(0)) if work remains, instead of batching all work in a single async task. This avoids holding the timer guard across multiple async rounds and simplifies cancellation. Also simplify tests to use event helpers (events::expire_transaction, events::accept_withdrawal) instead of mocking finalize_transactions as setup, and remove the test-only MAX_SIGNATURES_PER_STATUS_CHECK override (using the real value of 256 with a usize-indexed signature helper instead). Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
f0c874a to
8613a52
Compare
- Replace set_timer(delay, future) with set_timer(delay, fn) in CanisterRuntime trait (automatically clones self) - Remove RESCHEDULE_DELAY constant; reschedule timers immediately (Duration::ZERO) - Change signature/deposit_id/account helpers to accept usize with consistent le_bytes encoding - Merge per-timer capacity + reschedule tests into single successive-rounds tests - Drop runtime_ref clone pattern; pass runtime.clone() directly to timer functions Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Use the same num_remaining pattern as resubmit_transactions instead of scopeguard + checked_count tracking. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Also fix signature() doc comment and merge MAX_CONCURRENT_RPC_CALLS import into the crate:: block in withdraw/mod.rs. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- Add scopeguard + more_to_process pattern to process_pending_withdrawals - Add comments above ScopeGuard::into_inner defuse calls in all timers - Use deposit_id(i) helper in submit_consolidation_transaction_with_signature - Merge use crate:: statements in withdraw/mod.rs - Merge use cksol_minter:: statements in main.rs Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…th_signature Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…on_with_signature Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…_with_signature Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…_until_all_transactions_resubmitted`
| futures::future::join_all(batches.into_iter().map(async |funds| { | ||
| match submit_consolidation_transaction(&runtime, funds, slot, recent_blockhash).await { | ||
| Ok(sig) => log!(Priority::Info, "Submitted consolidation transaction {sig}"), | ||
| Err(e) => log!(Priority::Info, "Deposit consolidation failed: {e}"), |
There was a problem hiding this comment.
This code was not changed by this PR, but maybe we should log errors with error priority?
| // Transactions that are in-flight (Processed/Confirmed) or whose status | ||
| // check failed are implicitly excluded from the below sets. |
There was a problem hiding this comment.
| // Transactions that are in-flight (Processed/Confirmed) or whose status | |
| // check failed are implicitly excluded from the below sets. | |
| /// Transactions that are in-flight (Processed/Confirmed) or whose status | |
| /// check failed are implicitly excluded from the below sets. |
Summary
Refactors all timer-based processing functions to a single-round, immediately-rescheduling pattern:
MAX_CONCURRENT_RPC_CALLSbatches, then immediately reschedules itself withDuration::ZEROif work remainsscopeguardthat fires on drop (including panics); defused when all work fits in the current roundmore_to_processflag is computed from a snapshot of the queue before processing begins, so items added concurrently during execution don't trigger a spurious rescheduleStack
🤖 Generated with Claude Code