From 2010e8294654afde90746e34f80426883d812979 Mon Sep 17 00:00:00 2001 From: Hubert Bugaj Date: Mon, 30 Sep 2024 12:18:44 +0200 Subject: [PATCH] feat: NV24 skeleton with base migration --- src/networks/butterflynet/mod.rs | 2 + src/networks/calibnet/mod.rs | 2 + src/networks/devnet/mod.rs | 4 ++ src/networks/mainnet/mod.rs | 2 + src/networks/mod.rs | 5 +- src/rpc/methods/state.rs | 2 + src/shim/version.rs | 1 + src/state_migration/mod.rs | 9 +++ src/state_migration/nv24/migration.rs | 90 +++++++++++++++++++++++++++ src/state_migration/nv24/mod.rs | 22 +++++++ src/utils/misc/logo.rs | 2 +- 11 files changed, 139 insertions(+), 2 deletions(-) create mode 100644 src/state_migration/nv24/migration.rs create mode 100644 src/state_migration/nv24/mod.rs diff --git a/src/networks/butterflynet/mod.rs b/src/networks/butterflynet/mod.rs index 24883c4b32b3..d4b943131064 100644 --- a/src/networks/butterflynet/mod.rs +++ b/src/networks/butterflynet/mod.rs @@ -101,6 +101,8 @@ pub static HEIGHT_INFOS: Lazy> = Lazy::new(|| { make_height!(Dragon, -25, get_bundle_cid("v13.0.0")), make_height!(Phoenix, i64::MIN), make_height!(Waffle, 100, get_bundle_cid("v14.0.0-rc.1")), + // TODO(forest): https://github.com/ChainSafe/forest/issues/4799 + make_height!(TukTuk, i64::MAX), ]) }); diff --git a/src/networks/calibnet/mod.rs b/src/networks/calibnet/mod.rs index b32f3d0c8019..5dcbfc757d3a 100644 --- a/src/networks/calibnet/mod.rs +++ b/src/networks/calibnet/mod.rs @@ -73,6 +73,8 @@ pub static HEIGHT_INFOS: Lazy> = Lazy::new(|| { make_height!(Phoenix, 1_428_094), // 2024-07-11 12:00:00Z make_height!(Waffle, 1_779_094, get_bundle_cid("v14.0.0-rc.1")), + // TODO(forest): https://github.com/ChainSafe/forest/issues/4800 + make_height!(TukTuk, i64::MAX), ]) }); diff --git a/src/networks/devnet/mod.rs b/src/networks/devnet/mod.rs index a422f5887b61..e566cf264ca7 100644 --- a/src/networks/devnet/mod.rs +++ b/src/networks/devnet/mod.rs @@ -145,6 +145,10 @@ pub static HEIGHT_INFOS: Lazy> = Lazy::new(|| { get_upgrade_height_from_env("FOREST_WAFFLE_HEIGHT").unwrap_or(9999999999), get_bundle_cid("v14.0.0-rc.1") ), + make_height!( + TukTuk, + get_upgrade_height_from_env("FOREST_TUKTUK_HEIGHT").unwrap_or(9999999999) + ), ]) }); diff --git a/src/networks/mainnet/mod.rs b/src/networks/mainnet/mod.rs index 06d44bf899ab..cbea59738f3e 100644 --- a/src/networks/mainnet/mod.rs +++ b/src/networks/mainnet/mod.rs @@ -73,6 +73,8 @@ pub static HEIGHT_INFOS: Lazy> = Lazy::new(|| { make_height!(Phoenix, 3_855_480), // Tue 6 Aug 12:00:00 UTC 2024 make_height!(Waffle, 4_154_640, get_bundle_cid("v14.0.0")), + // TODO(forest): https://github.com/ChainSafe/forest/issues/4801 + make_height!(TukTuk, i64::MAX), ]) }); diff --git a/src/networks/mod.rs b/src/networks/mod.rs index 12448d8870b8..5232753edc16 100644 --- a/src/networks/mod.rs +++ b/src/networks/mod.rs @@ -142,6 +142,7 @@ pub enum Height { DragonFix, Phoenix, Waffle, + TukTuk, } impl Default for Height { @@ -183,6 +184,7 @@ impl From for NetworkVersion { Height::DragonFix => NetworkVersion::V22, Height::Phoenix => NetworkVersion::V22, Height::Waffle => NetworkVersion::V23, + Height::TukTuk => NetworkVersion::V24, } } } @@ -472,7 +474,7 @@ mod tests { fn heights_are_present(height_infos: &HashMap) { /// These are required heights that need to be defined for all networks, for, e.g., conformance /// with `Filecoin.StateGetNetworkParams` RPC method. - const REQUIRED_HEIGHTS: [Height; 27] = [ + const REQUIRED_HEIGHTS: [Height; 28] = [ Height::Breeze, Height::Smoke, Height::Ignition, @@ -500,6 +502,7 @@ mod tests { Height::Dragon, Height::Phoenix, Height::Waffle, + Height::TukTuk, ]; for height in &REQUIRED_HEIGHTS { diff --git a/src/rpc/methods/state.rs b/src/rpc/methods/state.rs index 65dff1cf1bad..514f4bdaefd3 100644 --- a/src/rpc/methods/state.rs +++ b/src/rpc/methods/state.rs @@ -2663,6 +2663,8 @@ impl TryFrom<&ChainConfig> for ForkUpgradeParams { upgrade_dragon_height: get_height(Dragon)?, upgrade_phoenix_height: get_height(Phoenix)?, upgrade_waffle_height: get_height(Waffle)?, + // TODO(forest): https://github.com/ChainSafe/forest/issues/4800 + // upgrade_tuktuk_height: get_height(TukTuk)?, }) } } diff --git a/src/shim/version.rs b/src/shim/version.rs index 1b9a288bc217..2e7abb0a202d 100644 --- a/src/shim/version.rs +++ b/src/shim/version.rs @@ -61,6 +61,7 @@ impl NetworkVersion { pub const V21: Self = Self(NetworkVersion_latest::new(21)); pub const V22: Self = Self(NetworkVersion_latest::new(22)); pub const V23: Self = Self(NetworkVersion_latest::new(23)); + pub const V24: Self = Self(NetworkVersion_latest::new(24)); } impl Deref for NetworkVersion { diff --git a/src/state_migration/mod.rs b/src/state_migration/mod.rs index 1c837c8cf0f3..d9839785a959 100644 --- a/src/state_migration/mod.rs +++ b/src/state_migration/mod.rs @@ -23,6 +23,7 @@ mod nv21fix2; mod nv22; mod nv22fix; mod nv23; +mod nv24; mod type_migrations; type RunMigration = fn(&ChainConfig, &Arc, &Cid, ChainEpoch) -> anyhow::Result; @@ -46,6 +47,8 @@ where (Height::Watermelon, nv21::run_migration::), (Height::Dragon, nv22::run_migration::), (Height::Waffle, nv23::run_migration::), + // TODO(forest): https://github.com/ChainSafe/forest/issues/4801 + // (Height::TukTuk, nv24::run_migration::), ] } NetworkChain::Calibnet => { @@ -59,12 +62,16 @@ where (Height::Dragon, nv22::run_migration::), (Height::DragonFix, nv22fix::run_migration::), (Height::Waffle, nv23::run_migration::), + // TODO(forest): https://github.com/ChainSafe/forest/issues/4800 + // (Height::TukTuk, nv24::run_migration::), ] } NetworkChain::Butterflynet => { vec![ (Height::Dragon, nv22::run_migration::), (Height::Waffle, nv23::run_migration::), + // TODO(forest): https://github.com/ChainSafe/forest/issues/4799 + // (Height::TukTuk, nv24::run_migration::), ] } NetworkChain::Devnet(_) => { @@ -75,6 +82,8 @@ where (Height::Watermelon, nv21::run_migration::), (Height::Dragon, nv22::run_migration::), (Height::Waffle, nv23::run_migration::), + // TODO(forest): https://github.com/ChainSafe/forest/issues/4802 + // (Height::TukTuk, nv24::run_migration::), ] } }; diff --git a/src/state_migration/nv24/migration.rs b/src/state_migration/nv24/migration.rs new file mode 100644 index 000000000000..8d5f93ca9f13 --- /dev/null +++ b/src/state_migration/nv24/migration.rs @@ -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 StateMigration { + pub fn add_nv24_migrations( + &mut self, + store: &Arc, + 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::(&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( + chain_config: &ChainConfig, + blockstore: &Arc, + state: &Cid, + epoch: ChainEpoch, +) -> anyhow::Result +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::::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) +} diff --git a/src/state_migration/nv24/mod.rs b/src/state_migration/nv24/mod.rs new file mode 100644 index 000000000000..2ecf7483cc01 --- /dev/null +++ b/src/state_migration/nv24/mod.rs @@ -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!(); diff --git a/src/utils/misc/logo.rs b/src/utils/misc/logo.rs index cef095f04a5d..dc14a49fd7c1 100644 --- a/src/utils/misc/logo.rs +++ b/src/utils/misc/logo.rs @@ -29,6 +29,7 @@ pub fn reveal_upgrade_logo(network_version: NetworkVersion) { } match network_version { NetworkVersion::V23 => reveal_waffle_upgrade(), + NetworkVersion::V24 => reveal_tuktuk_upgrade(), _ => reveal_three_trees(), } } @@ -117,7 +118,6 @@ fn reveal_waffle_upgrade() { } /// Reveals a speedy `TukTuk`, the symbol and the codename of the `NV24` upgrade. -#[allow(dead_code)] fn reveal_tuktuk_upgrade() { info!( r###"