Expand description
Schema-epoch in-place migration runtime.
Closes the Hopper Safety Audit’s innovation item I4 (“Schema epoch
with in-place migration helpers”). The header’s schema_epoch: u32
lets accounts self-identify the ABI version they were written in.
When a program later loads an account written at an older epoch,
the runtime consults a declared migration chain, applies each edge
in sequence atomically with a schema_epoch bump, and only then
hands the caller a typed Ref<'_, T> of the current shape.
§Design rules
- In-place. no allocation, no CPI. Migration rewrites the account body (within its existing byte range) and the 16-byte Hopper header.
- Atomic per edge. each migration edge updates both the body
and the
schema_epochheader field under a single mutable byte borrow. A mid-migration abort leaves the header and body consistent with one of the two endpoints, never a hybrid. - Idempotent. re-running an already-applied edge is a no-op
(the header epoch mismatch returns
MigrationMismatch). - Deterministic. edges are applied in strict
from_epoch → to_epochorder, and any gap in the chain fails.
Structs§
- Migration
Edge - One step in a layout’s migration chain.
Traits§
- Layout
Migration - Layouts opt into in-place migration by providing a
MIGRATIONSconstant. The default (empty slice) means “no migrations declared” and any mismatch between header andAccountLayout::SCHEMA_EPOCHis a hard failure.
Functions§
- apply_
pending_ migrations - Apply all pending migrations needed to bring the account at
current_epochup toAccountLayout::SCHEMA_EPOCH.