Skip to content

Commit

Permalink
Remove persistent state size restriction (#2339)
Browse files Browse the repository at this point in the history
This PR removes the size restriction on the persistent state memory.
The reason is, that the persistent state is saved during the
`pre_upgrade` hook. If the canister hits the size restriction, it
will panic and hence the canister would be un-upgradeable.

The size restriction included a safety margin of 20x, but given
that the limitation is only enforced in specific places, not having
a size limit is much safer.
We will add an alert that triggers on the memory size instead.
Additionally, we should get rid of the `pre_upgrade` hook
altogether.
  • Loading branch information
frederikrothenberger committed Mar 6, 2024
1 parent 4c9438e commit af9fc63
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions src/internet_identity/src/storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -178,8 +178,8 @@ pub struct Storage<M: Memory> {
archive_buffer_memory_wrapper: MemoryWrapper<NestedRestrictedMemory<M>>,
archive_entries_buffer: StableBTreeMap<u64, BufferedEntryWrapper, NestedRestrictedMemory<M>>,
/// Memory wrapper used to report the size of the persistent state memory.
persistent_state_memory_wrapper: MemoryWrapper<NestedRestrictedMemory<M>>,
persistent_state: StableCell<StorablePersistentState, NestedRestrictedMemory<M>>,
persistent_state_memory_wrapper: MemoryWrapper<VirtualMemory<RestrictedMemory<M>>>,
persistent_state: StableCell<StorablePersistentState, VirtualMemory<RestrictedMemory<M>>>,
}

#[repr(packed)]
Expand Down Expand Up @@ -238,8 +238,7 @@ impl<M: Memory + Clone> Storage<M> {
// To have space for 10_000 entries (accounting for ~10% overhead) we need 82 pages or ~5 MB.
// Since the memory manager allocates memory in buckets of 128 pages, we use a full bucket here.
let archive_buffer_memory = single_bucket_memory(&memory_manager, ARCHIVE_BUFFER_MEMORY_ID);
let persistent_state_memory =
single_bucket_memory(&memory_manager, PERSISTENT_STATE_MEMORY_ID);
let persistent_state_memory = memory_manager.get(PERSISTENT_STATE_MEMORY_ID);
Self {
header,
header_memory,
Expand Down

0 comments on commit af9fc63

Please sign in to comment.