Skip to content

fix: make asset canister reserve space when saving to stable storage - #4036

Merged
13 commits merged into
masterfrom
ens/sdk-1827-upgrade-asset-canister
Dec 11, 2024
Merged

fix: make asset canister reserve space when saving to stable storage#4036
13 commits merged into
masterfrom
ens/sdk-1827-upgrade-asset-canister

Conversation

@ghost

@ghost ghost commented Dec 11, 2024

Copy link
Copy Markdown

Description

Make the asset canister estimate the size of the data to be serialized to stable memory, and reserve that much space for the ValueSerializer's buffer.

The portal fails to upgrade from dfx 0.22.0 with an opaque Canister trapped: unreachable error.

This turns out to be the chain of events:

  • asset canister calls ic_cdk::storage::stable_save, which in turn calls candid::write_args, which constructs an IDLBuilder and serializes the data onto it.
  • The IDLBuilder contains a ValueSerializer, which contains an empty Vec<u8> with 0 capacity.
  • Serialization of the portal's data, which is just over 1GB, eventually tries to grow this Vec when it is already near 1 GB.
  • This generates an AllocError.

Part of https://dfinity.atlassian.net/browse/SDK-1827

How Has This Been Tested?

Create a new project and add the portal's data to its frontend canister. I ended up reading the data from the portal canister.

In one shell, run the following:

while true ; do dfx +0.24.3 start --clean -v ; done

In another shell, with the dfx under test on the PATH, run the following:

dfx killall && dfx ping --wait-healthy && dfx deploy && dfx build && dfx canister install scraped-portal-frontend --mode upgrade --upgrade-unchanged -vv

Checklist:

  • The title of this PR complies with Conventional Commits.
  • I have edited the CHANGELOG accordingly.
  • I have made corresponding changes to the documentation.

@ghost
ghost marked this pull request as ready for review December 11, 2024 18:12
@ghost
ghost self-requested a review as a code owner December 11, 2024 18:12
lwshang
lwshang previously approved these changes Dec 11, 2024
@ghost
ghost enabled auto-merge (squash) December 11, 2024 19:13
@ghost
ghost merged commit abf4540 into master Dec 11, 2024
@ghost
ghost deleted the ens/sdk-1827-upgrade-asset-canister branch December 11, 2024 19:49
This pull request was closed.
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.

1 participant