Skip to content

Commit

Permalink
Remove dead code related to migration
Browse files Browse the repository at this point in the history
  • Loading branch information
jasonz-dfinity committed Feb 4, 2025
1 parent 950e327 commit e01349f
Show file tree
Hide file tree
Showing 10 changed files with 5 additions and 400 deletions.
1 change: 0 additions & 1 deletion rs/backend/nns-dapp-exports-production.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,4 @@ canister_update register_hardware_wallet
canister_update rename_canister
canister_update rename_sub_account
canister_update set_imported_tokens
canister_update step_migration
main
1 change: 0 additions & 1 deletion rs/backend/nns-dapp-exports-test.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,4 @@ canister_update register_hardware_wallet
canister_update rename_canister
canister_update rename_sub_account
canister_update set_imported_tokens
canister_update step_migration
main
2 changes: 0 additions & 2 deletions rs/backend/nns-dapp.did
Original file line number Diff line number Diff line change
Expand Up @@ -238,8 +238,6 @@ service: (opt Config) -> {
http_request: (request: HttpRequest) -> (HttpResponse) query;
add_stable_asset: (asset: blob) -> ();

step_migration: (nat32) -> ();

// Methods available in the test build only:
create_toy_accounts: (nat) -> (nat64);
get_toy_account: (nat64) -> (GetAccountResponse) query;
Expand Down
14 changes: 1 addition & 13 deletions rs/backend/src/accounts_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -333,18 +333,6 @@ impl AccountsStore {
}
}

/// Determines whether a migration is being performed.
#[must_use]
#[allow(dead_code)]
pub fn migration_in_progress(&self) -> bool {
self.accounts_db.migration_in_progress()
}
/// Advances the migration by one step.
///
/// Note: This is a pass-through to the underlying `AccountsDb::step_migration`. Please see that for further details.
pub fn step_migration(&mut self, step_size: u32) {
self.accounts_db.step_migration(step_size);
}
#[must_use]
pub fn get_account(&self, caller: PrincipalId) -> Option<AccountDetails> {
let account_identifier = AccountIdentifier::from(caller);
Expand Down Expand Up @@ -681,7 +669,7 @@ impl AccountsStore {
stats.accounts_count = self.accounts_db.db_accounts_len();
stats.sub_accounts_count = self.accounts_db_stats.sub_accounts_count;
stats.hardware_wallet_accounts_count = self.accounts_db_stats.hardware_wallet_accounts_count;
stats.migration_countdown = Some(self.accounts_db.migration_countdown());
stats.migration_countdown = Some(0);
}

#[must_use]
Expand Down
36 changes: 0 additions & 36 deletions rs/backend/src/accounts_store/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,7 @@ pub mod proxy;

// Mechanics
use crate::accounts_store::Account;
use candid::{CandidType, Deserialize};
use core::ops::RangeBounds;
use serde::Serialize;
use strum_macros::EnumIter;
mod label_serialization;
#[cfg(test)]
pub mod tests;

Expand Down Expand Up @@ -114,38 +110,6 @@ pub trait AccountsDbTrait {
fn range(&self, key_range: impl RangeBounds<Vec<u8>>) -> Box<dyn Iterator<Item = (Vec<u8>, Account)> + '_>;
}

/// A label to identify the schema.
///
/// Note: The numeric representations of these labels are guaranteed to be stable.
#[repr(u32)]
#[derive(Clone, Copy, Debug, EnumIter, PartialEq, Eq, CandidType, Serialize, Deserialize)]
pub enum SchemaLabel {
/// Data is stored on the heap in a `BTreeMap` and serialized to stable memory on upgrade.
/// Implemented by: [`map::AccountsDbAsMap`]
Map = 0,
/// Every account is serialized separately and stored in a `StableBTreeMap`. The remaining
/// data, mostly consisting of transactions, is serialized into a single large blob in the
/// `pre_upgrade` hook.
AccountsInStableMemory = 1,
}

impl Default for SchemaLabel {
fn default() -> Self {
Self::AccountsInStableMemory
}
}

/// Schema Label as written to stable memory.
pub type SchemaLabelBytes = [u8; SchemaLabel::MAX_BYTES];

/// Errors that can occur when de-serializing a schema label.
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
pub enum SchemaLabelError {
InvalidChecksum,
InvalidLabel(u32),
InsufficientBytes,
}

/// A trait for data stores that support `BTreeMap` for account storage.
#[cfg(test)]
pub trait AccountsDbBTreeMapTrait {
Expand Down
107 changes: 0 additions & 107 deletions rs/backend/src/accounts_store/schema/label_serialization.rs

This file was deleted.

49 changes: 0 additions & 49 deletions rs/backend/src/accounts_store/schema/label_serialization/tests.rs

This file was deleted.

40 changes: 3 additions & 37 deletions rs/backend/src/accounts_store/schema/proxy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,17 @@
//! The proxy manages migrations from one implementation to another.
use super::accounts_in_unbounded_stable_btree_map::{AccountsDbAsUnboundedStableBTreeMap, ProductionMemoryType};
use super::{map::AccountsDbAsMap, Account, AccountsDbTrait};
use core::fmt;
use core::ops::RangeBounds;

mod enum_boilerplate;
mod migration;

/// An accounts database delegates API calls to underlying implementations.
///
/// Notes:
/// - The proxy manages migrations from one implementation to another, if applicable.
/// - The proxy code itself will specify which databases are currently in
/// use and how to migrate from one database to another.
/// - It is the responsibility of the post-install hook to look at any
/// version information and set up the db accordingly.
///
/// # Current data storage
/// - Accounts are stored as a map. No migrations are undertaken.
/// TODO: delete this entirely, since the migration logic is removed and the delegation is
/// unnecessary.
#[derive(Debug)]
pub struct AccountsDbAsProxy {
authoritative_db: AccountsDb,
migration: Option<Migration>,
}

impl Default for AccountsDbAsProxy {
Expand All @@ -32,27 +22,9 @@ impl Default for AccountsDbAsProxy {
}
}

struct Migration {
/// The database being migrated to
db: AccountsDb,
/// The next account to migrate.
next_to_migrate: Option<Vec<u8>>,
}

impl fmt::Debug for Migration {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
// Note: The `next_to_migrate` field is rarely interesting so is omitted.
// The database type and number of entries suffices.
self.db.fmt(f)
}
}

impl From<AccountsDb> for AccountsDbAsProxy {
fn from(db: AccountsDb) -> Self {
AccountsDbAsProxy {
authoritative_db: db,
migration: None,
}
AccountsDbAsProxy { authoritative_db: db }
}
}

Expand All @@ -66,9 +38,6 @@ impl AccountsDbTrait for AccountsDbAsProxy {
/// Inserts into all the underlying databases.
fn db_insert_account(&mut self, account_key: &[u8], account: Account) {
self.authoritative_db.db_insert_account(account_key, account.clone());
if let Some(migration) = &mut self.migration {
migration.db.db_insert_account(account_key, account);
}
}
/// Checks the authoritative database.
fn db_contains_account(&self, account_key: &[u8]) -> bool {
Expand All @@ -81,9 +50,6 @@ impl AccountsDbTrait for AccountsDbAsProxy {
/// Removes an account from all underlying databases.
fn db_remove_account(&mut self, account_key: &[u8]) {
self.authoritative_db.db_remove_account(account_key);
if let Some(migration) = self.migration.as_mut() {
migration.db.db_remove_account(account_key);
}
}
/// Gets the length from the authoritative database.
fn db_accounts_len(&self) -> u64 {
Expand Down
Loading

0 comments on commit e01349f

Please sign in to comment.