Store: Inside a Heap Migration

What the viewer will understand

What happens when the incoming code needs different Rust layouts? Follow the nested Nyxus tree through one V1-to-V2 KEEP upgrade. The viewer should be able to point to the accepted source contract, the owner that converts each cell, and the exact moment the new contract becomes active. Reuse the state and startup checks from lesson 7. Aim for about three and a half minutes of narration and holds.

The worked example

Continue the PocketIC lifecycle runner with the same populated canister. The revision-two artifact compiles its V2 target Catalog and expressly admits the exact V1 Catalog. It opens the V1 root and delegates conversion to the branch and leaf owners. The new root adds added = 900, branches add added = 800, and leaves add added = 700. The root moves its Vec<u64> and each leaf moves its Rc<Vec<u8>> as owned values. The runner compares the old and new root and direct leaf buffer addresses and the payload snapshots. Admission hook · Root converter · Branch converter · Leaf converter

The runner starts on business-two with schema 1, sets fail_upgrade and tries V2. The root's child-conversion callback traps after attaching the converted children, and the IC restores the previous V1 snapshot. The installed code accepts append(9, 700), then the runner clears the flag and tries V2 again. The successful revision-two artifact uses the original business code, so it reports business 1 and schema 2. After two V2 KEEP checks, append(256, 1000) exercises the converted tree. Build features · Conversion and rollback assertions

The story in one pass

Pick up at the same V1 tree. The incoming V2 code recognizes the exact saved V1 Catalog and uses it to open the source. Follow the root's conversion, then watch it hand child tickets to each owning converter. A forced failure brings the whole canister back to V1. Run the accepted path again after a successful write to the old tree. Finish with the installed V2 Catalog, rebuilt App, and a write against the new layout.

Components and views

Use the shared visual language and the arena positions from lesson 7. Reuse MemoryModule, CatalogFingerprint, CatalogGate and PauseAndExplain. In each owner close-up, show the extracted source fields as inputs to the converter. It allocates a new typed cell and places it at the same position in the ownership drawing. The directory keeps the owner's identity and advances its binding epoch. Use the address ticks for the two checked payload buffers. A Detached ticket follows the established attachment path and is consumed when the parent reattaches the converted child. Soften the candidate tree and hold the ordinary entry paths closed until the upgrade finishes. Cell conversion and epoch change

View Camera and visible objects
arena_status Same query framing and address ticks as lesson 7. Make schema and business visually independent.
arena_startup Reuse the startup view. Add the compiled V1 predecessor card beside the incoming V2 target card at CatalogGate.
arena_owners Fit root Data and Children, items[7], branch and its leaf, and the empty scratch slot.
arena_owner_close Center the named owner's source and target fields. Keep its related attachment socket and the retained allocation it owns in frame when relevant.
arena_canister Fit the completed tree and the transient App above it. The saved Catalog is readable beside the startup path.

Scene admit_predecessor — Open the saved V1 root

Enters with Lesson seven's final arena_status frame. The installed business-two build reports business 2 and schema 1.

Beat request_v2 — Give the candidate a different target

View and focus In arena_status, focus on the saved schema 1 result, then follow the new Wasm card to arena_startup.

Narration

Business revision two is running on schema one. The test sets a flag in the root to make the first conversion trap after it has processed the children. Then it asks the canister to install code that needs schema two.

Cue and animation On “Business revision two is running,” hold on business 2 and schema 1. At “sets a flag in the root,” show set_upgrade_failure(true) changing fail_upgrade. At “needs schema two,” send the candidate revision-two inward. Replay the established teardown and startup order through the removal of App and HELD, marker consumption and static replay.

Leaves with The V2 candidate has fresh statics and the saved Catalog is ready to compare.

Beat accept_exact_v1 — Admit the source it can read

View and focus In arena_startup, frame the saved V1 digest and the candidate's compiled V1 predecessor and V2 target.

Narration

This build carries the exact V1 contract as an accepted source. The saved Catalog matches that source, so the candidate can open the old root with its V1 type. The V2 card tells us what it will publish after restore.

Cue and animation At “matches that source,” align the saved digest with the compiled V1 predecessor. On “open the old root,” trace the accepted route through provider recovery and the restore hook to the retained root. The saved V1 contract sends restore through conversion, while the target digest stays on the candidate's card. Restore dispatch

Leaves with The candidate has admitted and opened the V1 root. Its target Catalog awaits completed restore.

Scene convert_owners — Convert each owner's cell

Enters with The V1 root is open under its admitted type. Each module is still in its established position.

Beat move_root_vector — Write the new root fields

View and focus In arena_owner_close, frame the root Data and its Vec<u64> allocation in the retained band.

Narration

The root converter builds its V2 fields from V1. It adds a field set to nine hundred and moves the vector into the new cell. The backing buffer stays at the same address.

Cue and animation At “field set to nine hundred,” add added = 900 to the candidate fields. On “moves the vector,” move the vector header with those fields into the newly allocated V2 cell and reconnect its route to the pinned buffer. Preserve the flag value extracted from V1.

Hold or transition Settle the ownership move before “The backing buffer stays”. Hold on that phrase with the dashed leader at the address tick. Resume on “For its first child” in the next beat.

On-screen text or code Balloon Same vector allocation.

Leaves with The root's candidate V2 Data is ready. Its V1 Children still hold their attachments.

Beat convert_direct_leaf — Delegate child seven

View and focus In arena_owners, center on items[7], then follow that owner into arena_owner_close.

Narration

For its first child, the root takes the attachment at key seven and passes the ticket to the leaf's converter. The leaf adds seven hundred in its own record and moves its owning reference to the same byte buffer. The root attaches the returned leaf at key seven.

Cue and animation At “passes the ticket,” lift the Detached ticket from the V1 items[7] socket and hand it to the leaf converter. At “moves its owning reference,” move the leaf's Rc<Vec<u8>> handle into its new cell and keep the Rc block and byte buffer pinned. On “attaches the returned leaf,” consume the V2 ticket in the V2 root slot.

On-screen text or code added = 700 in the V2 leaf. Keep the ticket and the buffer distinct in size and color.

Leaves with The new root owns the converted direct leaf. The branch route is still to be processed.

Beat convert_branch_leaf — Follow the next owner

View and focus Pan along the branch socket to the branch cell, then to its own leaf.

Narration

The branch converts its own fields and adds eight hundred. It delegates its leaf to the same leaf converter, then attaches that result. When the root attaches the branch again, every converted path leads back to the same actor.

Cue and animation At “adds eight hundred,” reveal added = 800 in the branch record. On “delegates its leaf,” repeat the same ticket and conversion motions for that leaf. At “attaches the branch again,” root branch consumes the branch's V2 ticket. End with the entire candidate tree in one frame.

Leaves with Every populated attachment for this run has a V2 successor. The candidate root callback is still running with the first attempt's test flag set.

Scene late_trap — Return to the prior app

Enters with The candidate has already changed the layout and attached the converted children. The installed state is still awaiting the upgrade outcome.

Beat restore_after_trap — Lose the attempted conversion

View and focus Use arena_canister with the candidate tree and host upgrade path visible. End in arena_status.

Narration

With the children attached, the root converter checks the flag it carried from V1 and traps. The IC rolls back the upgrade. Business revision two resumes on schema one, with the same payload and addresses as before the attempt.

Cue and animation At “checks the flag it carried,” highlight fail_upgrade = true in the root converter's child callback. Show the trap there and carry the failure back along the upgrade route. The candidate still has the saved V1 fingerprint and the App and HELD positions are empty. On “rolls back the upgrade,” restore the whole pre-attempt frame, including the old App and its alias. At “Business revision two resumes,” show business 2 and schema 1 on the restored response.

Leaves with V1 is accessible again with fail_upgrade = true, as it was when the attempt began.

Beat append_under_v1 — Reopen the old call path

View and focus Keep arena_status and follow a plain call arrow to the restored canister.

Narration

The test enters through the old code and appends nine more integers. The new values become part of the V1 state. The test clears the failure flag and tries the V2 upgrade again.

Cue and animation At “appends nine more integers,” send append(9, 700) into the old app. Add 700 through 708, take the root length from 147 to 156, root value from 152 to 161, and direct leaf value from 162 to 171. On “clears the failure flag,” show set_upgrade_failure(false), then bring the same V2 candidate back to startup.

Leaves with The second attempt starts from the updated V1 snapshot with its failure flag cleared. Use the addresses from this snapshot for the successful conversion comparison.

Scene publish_v2 — Finish the upgrade and write through it

Enters with The second V2 candidate is ready to compare against the updated V1 state.

Beat restore_and_publish — Complete startup

View and focus Follow admission and the already established owner sequence. End in arena_canister with the new App and saved Catalog visible.

Narration

The converters finish this time. Restore renews the leaf alias and saves a new App bound to the V2 tree. Then it writes the V2 fingerprint. When the upgrade succeeds, the IC makes the new code and state visible together. Both payload buffers kept their addresses through conversion.

Cue and animation At “The converters finish this time,” replay the predecessor check and owner conversions in order. At “renews the leaf alias,” reconnect HELD to the Rc control block. At “saves a new App,” bind the new App. On “writes the V2 fingerprint,” move the target digest card to the saved position inside the candidate. On “the IC makes the new code and state visible,” return the successful upgrade result and reopen ordinary call paths.

Leaves with The V2 executable is installed and bound to V2 memory. The matching before-and-after buffer ticks are in view.

Beat append_under_v2 — Write to the converted state

View and focus In arena_status, frame the V2 result and root vector.

Narration

The runner reads schema two. Business reads one again because this build uses the original business code. The old payloads are intact, and the root and leaf have their new fields. Another append takes the root vector to four hundred and twelve items.

Cue and animation At “reads schema two,” show schema 2 on the memory side. On “Business reads one again,” show business 1 on the code side. At “the root and leaf have their new fields,” highlight the checked 900 and 700 and the unchanged branch sum 55. At “Another append,” end the address comparison before sending append(256, 1000). Show root length 156 → 412, root value 161 → 417, and the direct leaf value 171 → 427. Draw the final buffer address only if a final capture supplies it.

Leaves with The converted tree accepts a fresh write and still has one actor root.

Review notes

  • Trace root → items[7] and root → branch → leaf through the exact owner calls. The root moves its own vector and delegates the child layouts, and the leaf's old Rc field becomes the V2 leaf's owning reference. The run's scratch slot stays empty. Keep owner drawings anchored throughout the two attempts. Root, branch, and leaf conversion
  • Match both backing-buffer ticks against the snapshot after append(9, 700). A converted owner keeps its position in the tree drawing and receives a new typed cell. The native test checks the persistent identity and rejects old bindings. Branch added = 800 and its leaf's added = 700 come from the converters. The PocketIC snapshot exposes the root and direct leaf fields and the branch sum. Track the final append separately since it can change the vector allocation. Native conversion assertions · PocketIC snapshots
  • Scrub the trap with the audio muted. The root's child callback traps before the candidate saves an App or target fingerprint. The IC restores the whole pre-attempt state. On success, restore writes the fingerprint after opening the Store, converting the owners and binding the App. Ordinary calls resume once the IC commits the upgrade. Root trap · Fixture restore hook
  • The worked conversion is synchronous and atomic at the IC upgrade boundary. It uses the same admitted platform and kernel. The full upgrade, including old and new allocations held during conversion, is subject to the runtime budget. The animation stretches its steps and condenses the runner's repeated V2 KEEP checks. Store upgrade rules