My token ledger was originally on the U64 version, but I accidentally performed an upgrade using the U256 WASM, which caused issues with the icrc1_total_supply
return value. How should I resolve this?
I think my token ledger current version is base on release-2024-06-26_23-01-storage-layer-disabled. It might download from somewhere, but I forget know.
And I search ledger release here: ledger · Releases · dfinity/ic · GitHub. I can only found oldest ledger suite release in 2024-9-13(But I can’t upgrade to this version, failed by: failed to decode ledger state: Semantic(None, "invalid type: enum, expected u64 or { e8s: u64 } struct).
Also I can’t download aim wasm from https://download.dfinity.systems.
So I decide to build locally, I just run cargo build --release --target wasm32-unknown-unknown --package ic-icrc1-ledger
, but I got a huge wasm file(50+M) which can’t upload for upgrade.
What version were you initially using, and what version are you running now? If you don’t know the exact versions, the rough date when you installed/upgraded the canister, and how you performed the install/upgrade could help. What is the canister module hash and the git commit id of the currently installed canister? You can see the module hash from the dashboard (https://dashboard.internetcomputer.org/canister/CANISTER_ID), and retrieve the git commit id using dfx
: dfx canister --ic metadata CANISTER_ID git_commit_id
.
Current git commit id is: https://github.com/dfinity/ic/tree/b6c3687fb3a03ca65fcd49f0aadc499367904c8b
The last version I think is alson this commit, but it’s build base u64, current is u256. I mean the u64 or u256 is just compilation feature. And I remember that I download them from https://download.dfinity.systems/ic/b6c3687fb3a03ca65fcd49f0aadc499367904c8b/canisters/ic-icrc1-ledger.wasm.gz and https://download.dfinity.systems/ic/b6c3687fb3a03ca65fcd49f0aadc499367904c8b/canisters/ic-icrc1-ledger-u256.wasm.gz.
So the what I did:
- Deploy u64 version icrc ledger wasm.
- Upgrade with u256 versioin icrc ledger wasm.
- I found icrc1_total_supply will be uncorrect. Since the implementation:
pub fn total_supply(&self) -> S::Tokens {
S::Tokens::max_value().checked_sub(&self.token_pool).expect(
"It is expected that the token_pool is always smaller than \
or equal to Tokens::max_value(), yet subtracting it lead to underflow",
)
}
-
So I think maybe I need to rollback to u64 version wasm. But when I upgrade, I met error: failed to decode ledger state: Semantic(None, "invalid type: enum, expected u64 or { e8s: u64 } struct.
-
Now I think what can I do is to modify some logic of icrc code to make roll back successful. But when I build icrc ledger code locally(I just use
cargo build --release --target wasm32-unknown-unknown --package ic-icrc1-ledger
). The aim wasm is huge(50M) which is too big to upload, but the wasm.gz file I download from https://download.dfinity.systems/ic is small(around 600KB). So do you know how to build correctly?
Thanks for the clarification!
To build the canisters, from the root of the checked out ic
repository, run: ./ci/container/build-ic.sh -c
. This will build the canisters and place them under ./artifacts/canisters/
.
The more recent ledger suite canister versions should be more robust wrt. upgrading with a different variant (u64
vs u256
), but I would recommend that you try to fix the issue using the current commit as a base, rather than upgrading to a more recent version, since with the later versions, switching to the other variant will be much more difficult.
I see! Thanks for that, I will try it.