-
Notifications
You must be signed in to change notification settings - Fork 160
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: NV24 skeleton with base migration (#4819)
- Loading branch information
1 parent
aabfe39
commit 5fd1ec5
Showing
11 changed files
with
139 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
// Copyright 2019-2024 ChainSafe Systems | ||
// SPDX-License-Identifier: Apache-2.0, MIT | ||
// | ||
//! This module contains the migration logic for the `NV24` upgrade. | ||
|
||
use std::sync::Arc; | ||
|
||
use crate::networks::{ChainConfig, Height}; | ||
use crate::shim::{ | ||
address::Address, | ||
clock::ChainEpoch, | ||
machine::BuiltinActorManifest, | ||
state_tree::{StateTree, StateTreeVersion}, | ||
}; | ||
use crate::utils::db::CborStoreExt as _; | ||
use anyhow::Context; | ||
use cid::Cid; | ||
|
||
use fvm_ipld_blockstore::Blockstore; | ||
|
||
use super::{system, verifier::Verifier, SystemStateOld}; | ||
use crate::state_migration::common::{migrators::nil_migrator, StateMigration}; | ||
|
||
impl<BS: Blockstore> StateMigration<BS> { | ||
pub fn add_nv24_migrations( | ||
&mut self, | ||
store: &Arc<BS>, | ||
state: &Cid, | ||
new_manifest: &BuiltinActorManifest, | ||
_chain_config: &ChainConfig, | ||
) -> anyhow::Result<()> { | ||
let state_tree = StateTree::new_from_root(store.clone(), state)?; | ||
let system_actor = state_tree.get_required_actor(&Address::SYSTEM_ACTOR)?; | ||
let system_actor_state = store.get_cbor_required::<SystemStateOld>(&system_actor.state)?; | ||
|
||
let current_manifest_data = system_actor_state.builtin_actors; | ||
|
||
let current_manifest = | ||
BuiltinActorManifest::load_v1_actor_list(store, ¤t_manifest_data)?; | ||
|
||
for (name, code) in current_manifest.builtin_actors() { | ||
let new_code = new_manifest.get(name)?; | ||
self.add_migrator(code, nil_migrator(new_code)) | ||
} | ||
|
||
self.add_migrator( | ||
current_manifest.get_system(), | ||
system::system_migrator(new_manifest), | ||
); | ||
|
||
Ok(()) | ||
} | ||
} | ||
|
||
/// Runs the migration for `NV24`. Returns the new state root. | ||
#[allow(dead_code)] | ||
pub fn run_migration<DB>( | ||
chain_config: &ChainConfig, | ||
blockstore: &Arc<DB>, | ||
state: &Cid, | ||
epoch: ChainEpoch, | ||
) -> anyhow::Result<Cid> | ||
where | ||
DB: Blockstore + Send + Sync, | ||
{ | ||
let new_manifest_cid = chain_config | ||
.height_infos | ||
.get(&Height::TukTuk) | ||
.context("no height info for network version NV24")? | ||
.bundle | ||
.as_ref() | ||
.context("no bundle for network version NV24")?; | ||
|
||
blockstore.get(new_manifest_cid)?.context(format!( | ||
"manifest for network version NV24 not found in blockstore: {new_manifest_cid}" | ||
))?; | ||
|
||
// Add migration specification verification | ||
let verifier = Arc::new(Verifier::default()); | ||
|
||
let new_manifest = BuiltinActorManifest::load_manifest(blockstore, new_manifest_cid)?; | ||
let mut migration = StateMigration::<DB>::new(Some(verifier)); | ||
migration.add_nv24_migrations(blockstore, state, &new_manifest, chain_config)?; | ||
|
||
let actors_in = StateTree::new_from_root(blockstore.clone(), state)?; | ||
let actors_out = StateTree::new(blockstore.clone(), StateTreeVersion::V5)?; | ||
let new_state = migration.migrate_state_tree(blockstore, epoch, actors_in, actors_out)?; | ||
|
||
Ok(new_state) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
// Copyright 2019-2024 ChainSafe Systems | ||
// SPDX-License-Identifier: Apache-2.0, MIT | ||
|
||
//! This module contains the migration logic for the `NV24` upgrade. | ||
mod migration; | ||
|
||
/// Run migration for `NV24`. This should be the only exported method in this | ||
/// module. | ||
#[allow(unused_imports)] | ||
pub use migration::run_migration; | ||
|
||
use crate::{define_system_states, impl_system, impl_verifier}; | ||
|
||
define_system_states!( | ||
fil_actor_system_state::v14::State, | ||
// TODO(forest): https://github.com/ChainSafe/forest/issues/4804 | ||
// This should point to the new state type, e.g., `fil_actor_system_state::v15::State` | ||
fil_actor_system_state::v14::State | ||
); | ||
|
||
impl_system!(); | ||
impl_verifier!(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters