Skip to main content

forest/state_migration/common/
migrators.rs

1// Copyright 2019-2026 ChainSafe Systems
2// SPDX-License-Identifier: Apache-2.0, MIT
3
4use std::sync::Arc;
5
6use cid::Cid;
7use fvm_ipld_blockstore::Blockstore;
8
9use super::{ActorMigration, ActorMigrationInput, ActorMigrationOutput};
10
11/// Migrator which preserves the head CID and provides a fixed result code CID.
12/// This is used to migrate actors which do not require any state migration.
13pub(in crate::state_migration) struct NilMigrator(Cid);
14
15impl<BS: Blockstore> ActorMigration<BS> for NilMigrator {
16    fn migrate_state(
17        &self,
18        _store: &BS,
19        input: ActorMigrationInput,
20    ) -> anyhow::Result<Option<ActorMigrationOutput>> {
21        Ok(Some(ActorMigrationOutput {
22            new_code_cid: self.0,
23            new_head: input.head,
24        }))
25    }
26}
27
28/// Creates a new migrator which preserves the head CID and provides a fixed
29/// result code CID.
30pub(in crate::state_migration) fn nil_migrator<BS: Blockstore>(
31    cid: Cid,
32) -> Arc<dyn ActorMigration<BS> + Send + Sync> {
33    Arc::new(NilMigrator(cid))
34}
35
36/// A migrator that does nothing but delegates the explicit migration logic to post migrator(s)
37pub(in crate::state_migration) struct DeferredMigrator;
38
39impl<BS: Blockstore> ActorMigration<BS> for DeferredMigrator {
40    fn migrate_state(
41        &self,
42        _store: &BS,
43        _input: ActorMigrationInput,
44    ) -> anyhow::Result<Option<ActorMigrationOutput>> {
45        Ok(None)
46    }
47}