diff --git a/contracts/coconut-dkg/src/contract.rs b/contracts/coconut-dkg/src/contract.rs index 6f3e331ed3..d5d525dd4c 100644 --- a/contracts/coconut-dkg/src/contract.rs +++ b/contracts/coconut-dkg/src/contract.rs @@ -255,10 +255,12 @@ pub fn query(deps: Deps<'_>, env: Env, msg: QueryMsg) -> Result, _env: Env, _msg: MigrateMsg) -> Result { +pub fn migrate(deps: DepsMut<'_>, env: Env, _msg: MigrateMsg) -> Result { set_build_information!(deps.storage)?; cw2::ensure_from_older_version(deps.storage, CONTRACT_NAME, CONTRACT_VERSION)?; + crate::queued_migrations::introduce_historical_epochs(deps, env)?; + Ok(Response::new()) } diff --git a/contracts/coconut-dkg/src/queued_migrations.rs b/contracts/coconut-dkg/src/queued_migrations.rs index 7e1e3cacd6..54c149a518 100644 --- a/contracts/coconut-dkg/src/queued_migrations.rs +++ b/contracts/coconut-dkg/src/queued_migrations.rs @@ -1,2 +1,21 @@ // Copyright 2025 - Nym Technologies SA // SPDX-License-Identifier: Apache-2.0 + +use crate::epoch_state::storage::HISTORICAL_EPOCH; +use crate::error::ContractError; +use cosmwasm_std::{DepsMut, Env}; + +pub fn introduce_historical_epochs(deps: DepsMut, env: Env) -> Result<(), ContractError> { + if HISTORICAL_EPOCH.may_load(deps.storage)?.is_some() { + return Err(ContractError::FailedMigration { + comment: "this migration has already been run before".to_string(), + }); + } + + #[allow(deprecated)] + let current = crate::epoch_state::storage::CURRENT_EPOCH.load(deps.storage)?; + // we won't have information on intermediate states prior to now, but that's not the end of the world + HISTORICAL_EPOCH.save(deps.storage, ¤t, env.block.height)?; + + Ok(()) +}