From 9b704241a485e365f23db1a7ffd50b2f5b8262df Mon Sep 17 00:00:00 2001 From: durch Date: Fri, 15 Apr 2022 10:30:19 +0200 Subject: [PATCH] Cleanup migration --- contracts/mixnet/src/contract.rs | 88 ++------------------------------ 1 file changed, 3 insertions(+), 85 deletions(-) diff --git a/contracts/mixnet/src/contract.rs b/contracts/mixnet/src/contract.rs index 0dc0fffc28..bb2e1ae5bd 100644 --- a/contracts/mixnet/src/contract.rs +++ b/contracts/mixnet/src/contract.rs @@ -30,12 +30,10 @@ use crate::rewards::queries::{ }; use crate::rewards::storage as rewards_storage; use cosmwasm_std::{ - entry_point, to_binary, Addr, Deps, DepsMut, Env, MessageInfo, QueryResponse, Response, - Storage, Uint128, + entry_point, to_binary, Addr, Deps, DepsMut, Env, MessageInfo, QueryResponse, Response, Uint128, }; -use cw_storage_plus::PrimaryKey; use mixnet_contract_common::{ - ContractStateParams, ExecuteMsg, InstantiateMsg, MigrateMsg, QueryMsg, SphinxKey, + ContractStateParams, ExecuteMsg, InstantiateMsg, MigrateMsg, QueryMsg, }; use time::OffsetDateTime; @@ -386,87 +384,7 @@ pub fn query(deps: Deps<'_>, env: Env, msg: QueryMsg) -> Result, _env: Env, _msg: MigrateMsg) -> Result { - use crate::mixnodes::storage::StoredMixnodeBond; - use cw_storage_plus::{Index, IndexList, IndexedSnapshotMap, Strategy, UniqueIndex}; - use mixnet_contract_common::{Addr, IdentityKeyRef}; - - const MIXNODES_PK_NAMESPACE: &str = "mn"; - const MIXNODES_PK_CHECKPOINTS: &str = "mn__check"; - const MIXNODES_PK_CHANGELOG: &str = "mn__change"; - const MIXNODES_OWNER_IDX_NAMESPACE: &str = "mno"; - const MIXNODES_SPHINX_IDX_NAMESPACE: &str = "mns"; - - pub(crate) struct MixnodeBondIndex<'a> { - pub(crate) owner: UniqueIndex<'a, Addr, StoredMixnodeBond>, - } - - impl<'a> IndexList for MixnodeBondIndex<'a> { - fn get_indexes( - &'_ self, - ) -> Box> + '_> { - let v: Vec<&dyn Index> = vec![&self.owner]; - Box::new(v.into_iter()) - } - } - - pub(crate) fn old_mixnodes<'a>( - ) -> IndexedSnapshotMap<'a, IdentityKeyRef<'a>, StoredMixnodeBond, MixnodeBondIndex<'a>> { - let indexes = MixnodeBondIndex { - owner: UniqueIndex::new(|d| d.owner.clone(), MIXNODES_OWNER_IDX_NAMESPACE), - }; - IndexedSnapshotMap::new( - MIXNODES_PK_NAMESPACE, - MIXNODES_PK_CHECKPOINTS, - MIXNODES_PK_CHANGELOG, - Strategy::Never, - indexes, - ) - } - - const PAGE_SIZE: usize = 50; - - fn migrate_page( - store: &mut dyn Storage, - start_after: Option, - index: &mut UniqueIndex<'_, SphinxKey, StoredMixnodeBond>, - ) -> Option { - let start = start_after - .as_deref() - .map(cw_storage_plus::Bound::exclusive); - - let page: Vec<_> = old_mixnodes() - .range(store, start, None, cosmwasm_std::Order::Ascending) - .map(|v| v.expect("failed to deserialize stored mixnode")) - .collect(); - - let last_pk = if page.len() == PAGE_SIZE { - Some(page.last().unwrap().0.clone()) - } else { - None - }; - - for (pk, mix) in page { - index - .save(store, &pk.joined_key(), &mix) - .expect("failed to save new index information"); - } - - last_pk - } - - // attempt to just add indices, see how it works out - let mut sphinx_index: UniqueIndex<'_, SphinxKey, StoredMixnodeBond> = UniqueIndex::new( - |d| d.mix_node.sphinx_key.clone(), - MIXNODES_SPHINX_IDX_NAMESPACE, - ); - - let mut start_after = None; - - while let Some(new_start) = migrate_page(deps.storage, start_after.clone(), &mut sphinx_index) { - start_after = Some(new_start) - } - +pub fn migrate(_deps: DepsMut<'_>, _env: Env, _msg: MigrateMsg) -> Result { Ok(Default::default()) }