Skip to content
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

feat: ICP-ledger: FI-1440: Implement V4 for ICP ledger - migrate balances to stable structures #3314

Open
wants to merge 72 commits into
base: master
Choose a base branch
from

Conversation

maciejdfinity
Copy link
Contributor

@maciejdfinity maciejdfinity commented Jan 3, 2025

This version of the ledger migrates the balances stored by the ledger from heap to stable memory stable structures. This allows the ledger to store more data (heap memory is limited to 4GB) and reduces the number of instructions used during the upgrades - there is no need to serialize and deserialize the balances stored in heap memory. Since we are no longer limited by the heap size, the logic for trimming balances and related init/upgrade arguments (maximum_number_of_accounts, accounts_overflow_trim_quantity) were removed. The migration to stable structures is performed during the upgrade and, if 250B instruction limit is reached, using timer invocations after the upgrade. If timer invocations are used by the migration, the ledger is unavailable for transfers and approvals until migration is finished. The migration status can be checked by calling the is_ledger_ready endpoint. After migration is finished, it is no longer possible to downgrade the ledger to the previous version .

@maciejdfinity maciejdfinity changed the title Maciej icp v4 feat: ICP-ledger: FI-1440: Implement V4 for ICP ledger - migrate balances to stable structures Jan 3, 2025
@github-actions github-actions bot added the feat label Jan 3, 2025
Err(e) => eprintln!("Could not write ledger_stable_memory.txt: {}", e),
};

let ledger: ledger_canister::Ledger = match serde_cbor::from_reader(File::open(cbor).unwrap()) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I guess this tool is not used very often, as this would fail since https://dashboard.internetcomputer.org/proposal/133946 was executed. The ledger stable memory now contains the stable structures memory manager and cannot be directly deserialized to the Ledger struct. Also, the balances are no longer stored in the Ledger struct directly but in BALANCES_MEMORY instead. The reason I am removing it only now is that the balances().store below no longer provides an iter(). I suggest we remove this code now and reimplement it later if needed.

Copy link
Contributor

Choose a reason for hiding this comment

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

cc @aterga

@maciejdfinity maciejdfinity marked this pull request as ready for review January 7, 2025 12:36
@maciejdfinity maciejdfinity requested review from a team as code owners January 7, 2025 12:36
Copy link
Member

@mbjorkqvist mbjorkqvist left a comment

Choose a reason for hiding this comment

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

Thanks a lot for this, @maciejdfinity ! I made a first pass and it looks very good! I have the following comments that weren't related to any changed code, so I'm leaving them here:

  • Should we consider slightly bumping the MAX_INSTRUCTIONS_PER_UPGRADE value, in case that would allow us to perform the whole migration as part of the post_upgrade?
  • Could we update the rs/ledger_suite/icp/tests/golden_nns_state.rs test in this PR also as in the previous one for the ICRC ledger? When run from this PR branch it's currently failing: https://dash.idx.dfinity.network/invocation/9562aced-5ecc-44d4-a4f3-6d262efb51f6
  • We should potentially wait with upgrading the ledger until NNS1-3526 has been addressed (see this Slack thread)

rs/ledger_suite/icp/ledger/src/main.rs Outdated Show resolved Hide resolved
@maciejdfinity
Copy link
Contributor Author

maciejdfinity commented Jan 8, 2025

Thanks a lot for this, @maciejdfinity ! I made a first pass and it looks very good! I have the following comments that weren't related to any changed code, so I'm leaving them here:

Thank you for checking this!

  • Should we consider slightly bumping the MAX_INSTRUCTIONS_PER_UPGRADE value, in case that would allow us to perform the whole migration as part of the post_upgrade?

I bumped it to 250B. When running the golden state test I noticed that we need ~225B, but I think we can add some margin.

Done!

Good point, let's wait!

Copy link
Contributor

@nmattia nmattia left a comment

Choose a reason for hiding this comment

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

IDX rubber stamp

@maciejdfinity maciejdfinity requested a review from mraszyk January 14, 2025 13:20
Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

If this pull request affects the behavior of any canister owned by
the Governance team, remember to update the corresponding
unreleased_changes.md file(s).

To acknowldge this reminder (and unblock the PR), dismiss this
code review by going to the bottom of the pull request page, and
supply one of the following reasons:

  1. Done.

  2. No canister behavior changes.

@mbjorkqvist
Copy link
Member

mbjorkqvist commented Jan 14, 2025

Good point, let's wait!

The fix was apparently already part of this PR for NNS1-3496, so we should be good to go!

@maciejdfinity
Copy link
Contributor Author

No canister behavior changes.

@mraszyk
Copy link
Contributor

mraszyk commented Jan 16, 2025

No canister behavior changes.

See https://dfinity.slack.com/archives/C0175CHJ0P6/p1737022510708759

@maciejdfinity maciejdfinity dismissed github-actions[bot]’s stale review January 17, 2025 10:13

No canister behavior changes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants