forest/state_migration/nv18/
init.rs

1// Copyright 2019-2025 ChainSafe Systems
2// SPDX-License-Identifier: Apache-2.0, MIT
3
4//! This module contains the migration logic for the `NV18` upgrade for the Init
5//! actor.
6
7use std::sync::Arc;
8
9use crate::state_migration::common::{
10    ActorMigration, ActorMigrationInput, ActorMigrationOutput, TypeMigration, TypeMigrator,
11};
12use crate::utils::db::CborStoreExt;
13use cid::Cid;
14use fil_actor_init_state::{v9::State as InitStateOld, v10::State as InitStateNew};
15use fvm_ipld_blockstore::Blockstore;
16
17pub struct InitMigrator(Cid);
18
19pub(in crate::state_migration) fn init_migrator<BS: Blockstore>(
20    cid: Cid,
21) -> Arc<dyn ActorMigration<BS> + Send + Sync> {
22    Arc::new(InitMigrator(cid))
23}
24
25impl<BS: Blockstore> ActorMigration<BS> for InitMigrator {
26    fn migrate_state(
27        &self,
28        store: &BS,
29        input: ActorMigrationInput,
30    ) -> anyhow::Result<Option<ActorMigrationOutput>> {
31        let in_state: InitStateOld = store.get_cbor_required(&input.head)?;
32        let out_state: InitStateNew = TypeMigrator::migrate_type(in_state, &store)?;
33        let new_head = store.put_cbor_default(&out_state)?;
34        Ok(Some(ActorMigrationOutput {
35            new_code_cid: self.0,
36            new_head,
37        }))
38    }
39}