-
Notifications
You must be signed in to change notification settings - Fork 0
refactor: single-round timers with rescheduling #97
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
8613a52
refactor: single-round timers with immediate rescheduling
lpahlavi 6153be4
refactor: simplify timers, fixtures, and rescheduling
lpahlavi 3bbf04a
refactor: rename runtime2 to runtime in merged timer tests
lpahlavi eb397ca
test: add queue size assertions to merged timer reschedule tests
lpahlavi e7d8ccb
refactor: simplify finalize_transactions rescheduling
lpahlavi ab4a0b7
refactor: use scopeguard for both monitor timer rescheduling
lpahlavi 3712cd6
refactor: add scopeguards to all timers and clean up imports
lpahlavi 27173fb
refactor: extract sig variable in submit_consolidation_transaction_wi…
lpahlavi e4c31c2
refactor: use signature(i) directly in submit_consolidation_transacti…
lpahlavi c40f18c
refactor: rename sig to signature in submit_consolidation_transaction…
lpahlavi 4860f81
Use `MAX_CONCURRENT_RPC_CALLS + 1` transactions in `should_reschedule…
lpahlavi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -36,33 +36,46 @@ pub async fn consolidate_deposits<R: CanisterRuntime>(runtime: R) { | |
| Err(_) => return, | ||
| }; | ||
|
|
||
| let consolidation_rounds: Vec<Vec<_>> = | ||
| read_state(|s| group_deposits_by_account(s.deposits_to_consolidate())) | ||
| .into_iter() | ||
| .chunks(MAX_TRANSFERS_PER_CONSOLIDATION) | ||
| .into_iter() | ||
| .map(Iterator::collect) | ||
| .collect(); | ||
|
|
||
| for round in &consolidation_rounds | ||
| let all_deposits = read_state(|s| group_deposits_by_account(s.deposits_to_consolidate())); | ||
| let more_to_process = | ||
| all_deposits.len() > MAX_CONCURRENT_RPC_CALLS * MAX_TRANSFERS_PER_CONSOLIDATION; | ||
| let reschedule = scopeguard::guard(runtime.clone(), |runtime| { | ||
| runtime.set_timer(Duration::ZERO, consolidate_deposits); | ||
| }); | ||
|
|
||
| let batches: Vec<Vec<_>> = all_deposits | ||
| .into_iter() | ||
| .chunks(MAX_TRANSFERS_PER_CONSOLIDATION) | ||
| .into_iter() | ||
| .chunks(MAX_CONCURRENT_RPC_CALLS) | ||
| { | ||
| let (slot, recent_blockhash) = match get_recent_slot_and_blockhash(&runtime).await { | ||
| Ok((slot, blockhash)) => (slot, blockhash), | ||
| Err(e) => { | ||
| log!(Priority::Info, "Failed to fetch recent blockhash: {e}"); | ||
| return; | ||
| } | ||
| }; | ||
|
|
||
| futures::future::join_all(round.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}"), | ||
| } | ||
| })) | ||
| .await; | ||
| .take(MAX_CONCURRENT_RPC_CALLS) | ||
| .map(Iterator::collect) | ||
| .collect(); | ||
|
|
||
| if batches.is_empty() { | ||
| // Nothing to process | ||
| scopeguard::ScopeGuard::into_inner(reschedule); | ||
| return; | ||
| } | ||
|
|
||
| let (slot, recent_blockhash) = match get_recent_slot_and_blockhash(&runtime).await { | ||
| Ok(result) => result, | ||
| Err(e) => { | ||
| log!(Priority::Info, "Failed to fetch recent blockhash: {e}"); | ||
| return; | ||
| } | ||
| }; | ||
|
|
||
| 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}"), | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This code was not changed by this PR, but maybe we should log errors with error priority? |
||
| } | ||
| })) | ||
| .await; | ||
|
|
||
| if !more_to_process { | ||
| // All work fits in this round | ||
| scopeguard::ScopeGuard::into_inner(reschedule); | ||
| } | ||
| } | ||
|
|
||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.