Skip to main content

forest/state_migration/common/macros/
verifier.rs

1// Copyright 2019-2026 ChainSafe Systems
2// SPDX-License-Identifier: Apache-2.0, MIT
3
4/// Implements `Verifier`, requiring proper `Manifest` types and system actor
5/// `State` types being defined by `define_manifests` and `define_system_states`
6/// macros respectively.
7#[macro_export]
8macro_rules! impl_verifier {
9    () => {
10        pub(super) mod verifier {
11            use $crate::cid_collections::CidHashMap;
12            use $crate::shim::{address::Address, machine::BuiltinActorManifest, state_tree::StateTree};
13            use $crate::state_migration::common::{verifier::ActorMigrationVerifier, Migrator};
14            use $crate::utils::db::CborStoreExt as _;
15            use ::fvm_ipld_blockstore::Blockstore;
16            use super::*;
17
18            #[derive(Default)]
19            pub struct Verifier {}
20
21            impl<BS: Blockstore> ActorMigrationVerifier<BS> for Verifier {
22                fn verify_migration(
23                    &self,
24                    store: &BS,
25                    migrations: &CidHashMap<Migrator<BS>>,
26                    actors_in: &StateTree<BS>,
27                ) -> anyhow::Result<()> {
28                    let system_actor = actors_in
29                        .get_required_actor(&Address::SYSTEM_ACTOR)?;
30                    let system_actor_state = store
31                        .get_cbor_required::<SystemStateOld>(&system_actor.state)?;
32                    let manifest =
33                        BuiltinActorManifest::load_v1_actor_list(&store, &system_actor_state.builtin_actors)?;
34                    let manifest_actors_count = manifest.builtin_actors().len();
35                    if manifest_actors_count == migrations.len() {
36                        tracing::debug!("Migration spec is correct.");
37                    } else {
38                        tracing::warn!(
39                            "Incomplete migration spec. Count: {}, expected: {manifest_actors_count}",
40                            migrations.len()
41                        );
42                    }
43
44                    Ok(())
45                }
46            }
47        }
48    };
49}