Skip to content

Commit

Permalink
feat: NV24 skeleton with base migration (#4819)
Browse files Browse the repository at this point in the history
  • Loading branch information
LesnyRumcajs authored Oct 1, 2024
1 parent aabfe39 commit 5fd1ec5
Show file tree
Hide file tree
Showing 11 changed files with 139 additions and 2 deletions.
2 changes: 2 additions & 0 deletions src/networks/butterflynet/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,8 @@ pub static HEIGHT_INFOS: Lazy<HashMap<Height, HeightInfo>> = 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),
])
});

Expand Down
2 changes: 2 additions & 0 deletions src/networks/calibnet/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ pub static HEIGHT_INFOS: Lazy<HashMap<Height, HeightInfo>> = 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),
])
});

Expand Down
4 changes: 4 additions & 0 deletions src/networks/devnet/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,10 @@ pub static HEIGHT_INFOS: Lazy<HashMap<Height, HeightInfo>> = 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)
),
])
});

Expand Down
2 changes: 2 additions & 0 deletions src/networks/mainnet/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ pub static HEIGHT_INFOS: Lazy<HashMap<Height, HeightInfo>> = 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),
])
});

Expand Down
5 changes: 4 additions & 1 deletion src/networks/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ pub enum Height {
DragonFix,
Phoenix,
Waffle,
TukTuk,
}

impl Default for Height {
Expand Down Expand Up @@ -183,6 +184,7 @@ impl From<Height> for NetworkVersion {
Height::DragonFix => NetworkVersion::V22,
Height::Phoenix => NetworkVersion::V22,
Height::Waffle => NetworkVersion::V23,
Height::TukTuk => NetworkVersion::V24,
}
}
}
Expand Down Expand Up @@ -472,7 +474,7 @@ mod tests {
fn heights_are_present(height_infos: &HashMap<Height, HeightInfo>) {
/// 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,
Expand Down Expand Up @@ -500,6 +502,7 @@ mod tests {
Height::Dragon,
Height::Phoenix,
Height::Waffle,
Height::TukTuk,
];

for height in &REQUIRED_HEIGHTS {
Expand Down
2 changes: 2 additions & 0 deletions src/rpc/methods/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)?,
})
}
}
1 change: 1 addition & 0 deletions src/shim/version.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
9 changes: 9 additions & 0 deletions src/state_migration/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ mod nv21fix2;
mod nv22;
mod nv22fix;
mod nv23;
mod nv24;
mod type_migrations;

type RunMigration<DB> = fn(&ChainConfig, &Arc<DB>, &Cid, ChainEpoch) -> anyhow::Result<Cid>;
Expand All @@ -46,6 +47,8 @@ where
(Height::Watermelon, nv21::run_migration::<DB>),
(Height::Dragon, nv22::run_migration::<DB>),
(Height::Waffle, nv23::run_migration::<DB>),
// TODO(forest): https://github.com/ChainSafe/forest/issues/4801
// (Height::TukTuk, nv24::run_migration::<DB>),
]
}
NetworkChain::Calibnet => {
Expand All @@ -59,12 +62,16 @@ where
(Height::Dragon, nv22::run_migration::<DB>),
(Height::DragonFix, nv22fix::run_migration::<DB>),
(Height::Waffle, nv23::run_migration::<DB>),
// TODO(forest): https://github.com/ChainSafe/forest/issues/4800
// (Height::TukTuk, nv24::run_migration::<DB>),
]
}
NetworkChain::Butterflynet => {
vec![
(Height::Dragon, nv22::run_migration::<DB>),
(Height::Waffle, nv23::run_migration::<DB>),
// TODO(forest): https://github.com/ChainSafe/forest/issues/4799
// (Height::TukTuk, nv24::run_migration::<DB>),
]
}
NetworkChain::Devnet(_) => {
Expand All @@ -75,6 +82,8 @@ where
(Height::Watermelon, nv21::run_migration::<DB>),
(Height::Dragon, nv22::run_migration::<DB>),
(Height::Waffle, nv23::run_migration::<DB>),
// TODO(forest): https://github.com/ChainSafe/forest/issues/4802
// (Height::TukTuk, nv24::run_migration::<DB>),
]
}
};
Expand Down
90 changes: 90 additions & 0 deletions src/state_migration/nv24/migration.rs
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, &current_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)
}
22 changes: 22 additions & 0 deletions src/state_migration/nv24/mod.rs
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!();
2 changes: 1 addition & 1 deletion src/utils/misc/logo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
}
}
Expand Down Expand Up @@ -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###"
Expand Down

0 comments on commit 5fd1ec5

Please sign in to comment.