forest/state_migration/nv25/
miner.rs

1// Copyright 2019-2025 ChainSafe Systems
2// SPDX-License-Identifier: Apache-2.0, MIT
3
4use crate::state_migration::common::{
5    ActorMigration, ActorMigrationInput, ActorMigrationOutput, TypeMigration, TypeMigrator,
6};
7use crate::utils::db::CborStoreExt as _;
8use cid::Cid;
9use fil_actor_miner_state::v15::State as MinerStateOld;
10use fil_actor_miner_state::v16::State as MinerStateNew;
11use fvm_ipld_blockstore::Blockstore;
12
13pub struct MinerMigrator {
14    pub new_code_cid: Cid,
15}
16
17impl<BS: Blockstore> ActorMigration<BS> for MinerMigrator {
18    fn migrate_state(
19        &self,
20        store: &BS,
21        input: ActorMigrationInput,
22    ) -> anyhow::Result<Option<ActorMigrationOutput>> {
23        let in_state: MinerStateOld = store.get_cbor_required(&input.head)?;
24        let out_state: MinerStateNew = TypeMigrator::migrate_type(in_state, store)?;
25        let new_head = store.put_cbor_default(&out_state)?;
26        Ok(Some(ActorMigrationOutput {
27            new_code_cid: self.new_code_cid,
28            new_head,
29        }))
30    }
31}