forest/state_migration/nv25/
evm.rs

1// Copyright 2019-2025 ChainSafe Systems
2// SPDX-License-Identifier: Apache-2.0, MIT
3
4//! This module contains the logic for adding transient storage (EIP-1153).
5//! actor. See the [FIP-0097](https://github.com/filecoin-project/FIPs/blob/b258e36e5e085afd48525cb6442f2301553df528/FIPS/fip-0097.md) for more details.
6
7use crate::state_migration::common::{
8    ActorMigration, ActorMigrationInput, ActorMigrationOutput, TypeMigration, TypeMigrator,
9};
10use crate::utils::db::CborStoreExt as _;
11use cid::Cid;
12use fil_actor_evm_state::v15::State as EvmStateOld;
13use fil_actor_evm_state::v16::State as EvmStateNew;
14use fvm_ipld_blockstore::Blockstore;
15
16pub struct EvmMigrator {
17    pub new_code_cid: Cid,
18}
19
20impl<BS: Blockstore> ActorMigration<BS> for EvmMigrator {
21    fn migrate_state(
22        &self,
23        store: &BS,
24        input: ActorMigrationInput,
25    ) -> anyhow::Result<Option<ActorMigrationOutput>> {
26        let in_state: EvmStateOld = store.get_cbor_required(&input.head)?;
27        let out_state: EvmStateNew = TypeMigrator::migrate_type(in_state, store)?;
28        let new_head = store.put_cbor_default(&out_state)?;
29        Ok(Some(ActorMigrationOutput {
30            new_code_cid: self.new_code_cid,
31            new_head,
32        }))
33    }
34}