Skip to content

refactor: use mint indices in ConsolidatedDeposits event#66

Merged
lpahlavi merged 2 commits intomainfrom
lpahlavi/consolidation-mint-indices
Mar 25, 2026
Merged

refactor: use mint indices in ConsolidatedDeposits event#66
lpahlavi merged 2 commits intomainfrom
lpahlavi/consolidation-mint-indices

Conversation

@lpahlavi
Copy link
Copy Markdown
Contributor

Replace the (Account, Lamport) pairs in the ConsolidatedDeposits event with mint indices. The internal funds_to_consolidate map is renamed to deposits_to_consolidate and re-keyed from Account to LedgerMintIndex. Deposits are now added to the consolidation queue when minted rather than when accepted. Multiple deposits to the same account are merged into a single transfer instruction during consolidation.

@lpahlavi lpahlavi force-pushed the lpahlavi/consolidation-mint-indices branch 4 times, most recently from 5102da6 to 218b6e7 Compare March 24, 2026 10:18
Base automatically changed from lpahlavi/consolidation-timer-tests to main March 24, 2026 14:06
@lpahlavi lpahlavi force-pushed the lpahlavi/consolidation-mint-indices branch from 218b6e7 to eadd0cc Compare March 24, 2026 14:22
Copilot AI review requested due to automatic review settings March 24, 2026 14:22
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Refactors the minter’s deposit consolidation flow and event schema so ConsolidatedDeposits reports consolidated mint indices (instead of (Account, Lamport) pairs), and consolidation work is queued at mint time with per-account deposits merged into fewer transfer instructions.

Changes:

  • Updated ConsolidatedDeposits event payload across CBOR, Candid (.did), and internal event types to emit mint_indices.
  • Reworked State consolidation tracking from funds_to_consolidate: BTreeMap<Account, Lamport> to deposits_to_consolidate: BTreeMap<LedgerMintIndex, (Account, Lamport)>, populated on Minted.
  • Updated consolidation logic/tests to batch by unique accounts and merge multiple deposits to the same account into a single transfer.

Reviewed changes

Copilot reviewed 13 out of 14 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
minter/src/test_fixtures/mod.rs Updates proptest event generator to produce mint_indices for ConsolidatedDeposits.
minter/src/state/tests.rs Adjusts state initialization expectations for renamed consolidation map.
minter/src/state/mod.rs Renames/rekeys consolidation queue; moves enqueueing from accept → mint; updates consolidation replay handling.
minter/src/state/event/cbor/mod.rs Adds minicbor encode/decode helpers for Vec<LedgerMintIndex>.
minter/src/state/event.rs Changes ConsolidatedDeposits event definition to mint_indices with CBOR customization.
minter/src/state/audit.rs Updates audit replay to apply consolidation by mint_indices.
minter/src/main.rs Maps internal LedgerMintIndex list to candid nat64 list in get_events.
minter/src/consolidate/tests.rs Updates consolidation tests and adds coverage for merging multiple deposits to one account into one transfer.
minter/src/consolidate/mod.rs Groups deposits by account for transfer creation; emits ConsolidatedDeposits { mint_indices }.
minter/cksol-minter.did Updates public Candid event schema for ConsolidatedDeposits.
minter/Cargo.toml Adds itertools dependency (workspace).
libs/types-internal/src/event.rs Updates Candid-compatible Rust event type for ConsolidatedDeposits to use mint_indices.
Cargo.toml Adds itertools = "0.14.0" to workspace dependencies.
Cargo.lock Locks itertools dependency addition.

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

Comment thread minter/src/consolidate/mod.rs
Comment thread libs/types-internal/src/event.rs
Replace the (Account, Lamport) pairs in the ConsolidatedDeposits event
with mint indices. Rename funds_to_consolidate to deposits_to_consolidate
and re-key it from Account to LedgerMintIndex. Deposits are now added
to the consolidation queue during Minted (not AcceptedDeposit), and
multiple deposits to the same account are merged into a single transfer
instruction.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@lpahlavi lpahlavi force-pushed the lpahlavi/consolidation-mint-indices branch from eadd0cc to 2e3d998 Compare March 24, 2026 14:32
@lpahlavi lpahlavi marked this pull request as ready for review March 24, 2026 14:51
@lpahlavi lpahlavi requested a review from a team as a code owner March 24, 2026 14:51
Copilot AI review requested due to automatic review settings March 24, 2026 14:51
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 14 out of 15 changed files in this pull request and generated 4 comments.


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

Comment on lines 870 to 877
for event in &events_after {
if let EventType::ConsolidatedDeposits { deposits } = &event.payload {
let total: Lamport = deposits.iter().map(|(_, amount)| amount).sum();
assert_eq!(
total, DEPOSIT_AMOUNT,
"Consolidated amount should match the deposit amount"
if let EventType::ConsolidatedDeposits { mint_indices } = &event.payload {
assert!(
!mint_indices.is_empty(),
"ConsolidatedDeposits should contain at least one mint index"
);
}
}
Copy link

Copilot AI Mar 24, 2026

Choose a reason for hiding this comment

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

This integration assertion became very weak after switching from (Account, Lamport) to mint_indices: it only checks that the list is non-empty. Since the preceding call returns DepositStatus::Minted, you can extract the minted mint_block_index from the Minted event(s) in events_after and assert that at least one ConsolidatedDeposits.mint_indices contains that index (and possibly only indices for minted deposits in this test).

Copilot uses AI. Check for mistakes.
Comment thread minter/src/consolidate/mod.rs
Comment thread minter/src/consolidate/mod.rs
Comment thread minter/src/state/mod.rs
@lpahlavi lpahlavi merged commit 740d436 into main Mar 25, 2026
10 checks passed
@lpahlavi lpahlavi deleted the lpahlavi/consolidation-mint-indices branch March 25, 2026 14:31
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.

3 participants