Skip to content

Commit 5fd1ec5

Browse files
authored
feat: NV24 skeleton with base migration (#4819)
1 parent aabfe39 commit 5fd1ec5

File tree

11 files changed

+139
-2
lines changed

11 files changed

+139
-2
lines changed

src/networks/butterflynet/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,8 @@ pub static HEIGHT_INFOS: Lazy<HashMap<Height, HeightInfo>> = Lazy::new(|| {
101101
make_height!(Dragon, -25, get_bundle_cid("v13.0.0")),
102102
make_height!(Phoenix, i64::MIN),
103103
make_height!(Waffle, 100, get_bundle_cid("v14.0.0-rc.1")),
104+
// TODO(forest): https://github.com/ChainSafe/forest/issues/4799
105+
make_height!(TukTuk, i64::MAX),
104106
])
105107
});
106108

src/networks/calibnet/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,8 @@ pub static HEIGHT_INFOS: Lazy<HashMap<Height, HeightInfo>> = Lazy::new(|| {
7373
make_height!(Phoenix, 1_428_094),
7474
// 2024-07-11 12:00:00Z
7575
make_height!(Waffle, 1_779_094, get_bundle_cid("v14.0.0-rc.1")),
76+
// TODO(forest): https://github.com/ChainSafe/forest/issues/4800
77+
make_height!(TukTuk, i64::MAX),
7678
])
7779
});
7880

src/networks/devnet/mod.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,10 @@ pub static HEIGHT_INFOS: Lazy<HashMap<Height, HeightInfo>> = Lazy::new(|| {
145145
get_upgrade_height_from_env("FOREST_WAFFLE_HEIGHT").unwrap_or(9999999999),
146146
get_bundle_cid("v14.0.0-rc.1")
147147
),
148+
make_height!(
149+
TukTuk,
150+
get_upgrade_height_from_env("FOREST_TUKTUK_HEIGHT").unwrap_or(9999999999)
151+
),
148152
])
149153
});
150154

src/networks/mainnet/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,8 @@ pub static HEIGHT_INFOS: Lazy<HashMap<Height, HeightInfo>> = Lazy::new(|| {
7373
make_height!(Phoenix, 3_855_480),
7474
// Tue 6 Aug 12:00:00 UTC 2024
7575
make_height!(Waffle, 4_154_640, get_bundle_cid("v14.0.0")),
76+
// TODO(forest): https://github.com/ChainSafe/forest/issues/4801
77+
make_height!(TukTuk, i64::MAX),
7678
])
7779
});
7880

src/networks/mod.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@ pub enum Height {
142142
DragonFix,
143143
Phoenix,
144144
Waffle,
145+
TukTuk,
145146
}
146147

147148
impl Default for Height {
@@ -183,6 +184,7 @@ impl From<Height> for NetworkVersion {
183184
Height::DragonFix => NetworkVersion::V22,
184185
Height::Phoenix => NetworkVersion::V22,
185186
Height::Waffle => NetworkVersion::V23,
187+
Height::TukTuk => NetworkVersion::V24,
186188
}
187189
}
188190
}
@@ -472,7 +474,7 @@ mod tests {
472474
fn heights_are_present(height_infos: &HashMap<Height, HeightInfo>) {
473475
/// These are required heights that need to be defined for all networks, for, e.g., conformance
474476
/// with `Filecoin.StateGetNetworkParams` RPC method.
475-
const REQUIRED_HEIGHTS: [Height; 27] = [
477+
const REQUIRED_HEIGHTS: [Height; 28] = [
476478
Height::Breeze,
477479
Height::Smoke,
478480
Height::Ignition,
@@ -500,6 +502,7 @@ mod tests {
500502
Height::Dragon,
501503
Height::Phoenix,
502504
Height::Waffle,
505+
Height::TukTuk,
503506
];
504507

505508
for height in &REQUIRED_HEIGHTS {

src/rpc/methods/state.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2663,6 +2663,8 @@ impl TryFrom<&ChainConfig> for ForkUpgradeParams {
26632663
upgrade_dragon_height: get_height(Dragon)?,
26642664
upgrade_phoenix_height: get_height(Phoenix)?,
26652665
upgrade_waffle_height: get_height(Waffle)?,
2666+
// TODO(forest): https://github.com/ChainSafe/forest/issues/4800
2667+
// upgrade_tuktuk_height: get_height(TukTuk)?,
26662668
})
26672669
}
26682670
}

src/shim/version.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ impl NetworkVersion {
6161
pub const V21: Self = Self(NetworkVersion_latest::new(21));
6262
pub const V22: Self = Self(NetworkVersion_latest::new(22));
6363
pub const V23: Self = Self(NetworkVersion_latest::new(23));
64+
pub const V24: Self = Self(NetworkVersion_latest::new(24));
6465
}
6566

6667
impl Deref for NetworkVersion {

src/state_migration/mod.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ mod nv21fix2;
2323
mod nv22;
2424
mod nv22fix;
2525
mod nv23;
26+
mod nv24;
2627
mod type_migrations;
2728

2829
type RunMigration<DB> = fn(&ChainConfig, &Arc<DB>, &Cid, ChainEpoch) -> anyhow::Result<Cid>;
@@ -46,6 +47,8 @@ where
4647
(Height::Watermelon, nv21::run_migration::<DB>),
4748
(Height::Dragon, nv22::run_migration::<DB>),
4849
(Height::Waffle, nv23::run_migration::<DB>),
50+
// TODO(forest): https://github.com/ChainSafe/forest/issues/4801
51+
// (Height::TukTuk, nv24::run_migration::<DB>),
4952
]
5053
}
5154
NetworkChain::Calibnet => {
@@ -59,12 +62,16 @@ where
5962
(Height::Dragon, nv22::run_migration::<DB>),
6063
(Height::DragonFix, nv22fix::run_migration::<DB>),
6164
(Height::Waffle, nv23::run_migration::<DB>),
65+
// TODO(forest): https://github.com/ChainSafe/forest/issues/4800
66+
// (Height::TukTuk, nv24::run_migration::<DB>),
6267
]
6368
}
6469
NetworkChain::Butterflynet => {
6570
vec![
6671
(Height::Dragon, nv22::run_migration::<DB>),
6772
(Height::Waffle, nv23::run_migration::<DB>),
73+
// TODO(forest): https://github.com/ChainSafe/forest/issues/4799
74+
// (Height::TukTuk, nv24::run_migration::<DB>),
6875
]
6976
}
7077
NetworkChain::Devnet(_) => {
@@ -75,6 +82,8 @@ where
7582
(Height::Watermelon, nv21::run_migration::<DB>),
7683
(Height::Dragon, nv22::run_migration::<DB>),
7784
(Height::Waffle, nv23::run_migration::<DB>),
85+
// TODO(forest): https://github.com/ChainSafe/forest/issues/4802
86+
// (Height::TukTuk, nv24::run_migration::<DB>),
7887
]
7988
}
8089
};

src/state_migration/nv24/migration.rs

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
// Copyright 2019-2024 ChainSafe Systems
2+
// SPDX-License-Identifier: Apache-2.0, MIT
3+
//
4+
//! This module contains the migration logic for the `NV24` upgrade.
5+
6+
use std::sync::Arc;
7+
8+
use crate::networks::{ChainConfig, Height};
9+
use crate::shim::{
10+
address::Address,
11+
clock::ChainEpoch,
12+
machine::BuiltinActorManifest,
13+
state_tree::{StateTree, StateTreeVersion},
14+
};
15+
use crate::utils::db::CborStoreExt as _;
16+
use anyhow::Context;
17+
use cid::Cid;
18+
19+
use fvm_ipld_blockstore::Blockstore;
20+
21+
use super::{system, verifier::Verifier, SystemStateOld};
22+
use crate::state_migration::common::{migrators::nil_migrator, StateMigration};
23+
24+
impl<BS: Blockstore> StateMigration<BS> {
25+
pub fn add_nv24_migrations(
26+
&mut self,
27+
store: &Arc<BS>,
28+
state: &Cid,
29+
new_manifest: &BuiltinActorManifest,
30+
_chain_config: &ChainConfig,
31+
) -> anyhow::Result<()> {
32+
let state_tree = StateTree::new_from_root(store.clone(), state)?;
33+
let system_actor = state_tree.get_required_actor(&Address::SYSTEM_ACTOR)?;
34+
let system_actor_state = store.get_cbor_required::<SystemStateOld>(&system_actor.state)?;
35+
36+
let current_manifest_data = system_actor_state.builtin_actors;
37+
38+
let current_manifest =
39+
BuiltinActorManifest::load_v1_actor_list(store, &current_manifest_data)?;
40+
41+
for (name, code) in current_manifest.builtin_actors() {
42+
let new_code = new_manifest.get(name)?;
43+
self.add_migrator(code, nil_migrator(new_code))
44+
}
45+
46+
self.add_migrator(
47+
current_manifest.get_system(),
48+
system::system_migrator(new_manifest),
49+
);
50+
51+
Ok(())
52+
}
53+
}
54+
55+
/// Runs the migration for `NV24`. Returns the new state root.
56+
#[allow(dead_code)]
57+
pub fn run_migration<DB>(
58+
chain_config: &ChainConfig,
59+
blockstore: &Arc<DB>,
60+
state: &Cid,
61+
epoch: ChainEpoch,
62+
) -> anyhow::Result<Cid>
63+
where
64+
DB: Blockstore + Send + Sync,
65+
{
66+
let new_manifest_cid = chain_config
67+
.height_infos
68+
.get(&Height::TukTuk)
69+
.context("no height info for network version NV24")?
70+
.bundle
71+
.as_ref()
72+
.context("no bundle for network version NV24")?;
73+
74+
blockstore.get(new_manifest_cid)?.context(format!(
75+
"manifest for network version NV24 not found in blockstore: {new_manifest_cid}"
76+
))?;
77+
78+
// Add migration specification verification
79+
let verifier = Arc::new(Verifier::default());
80+
81+
let new_manifest = BuiltinActorManifest::load_manifest(blockstore, new_manifest_cid)?;
82+
let mut migration = StateMigration::<DB>::new(Some(verifier));
83+
migration.add_nv24_migrations(blockstore, state, &new_manifest, chain_config)?;
84+
85+
let actors_in = StateTree::new_from_root(blockstore.clone(), state)?;
86+
let actors_out = StateTree::new(blockstore.clone(), StateTreeVersion::V5)?;
87+
let new_state = migration.migrate_state_tree(blockstore, epoch, actors_in, actors_out)?;
88+
89+
Ok(new_state)
90+
}

src/state_migration/nv24/mod.rs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// Copyright 2019-2024 ChainSafe Systems
2+
// SPDX-License-Identifier: Apache-2.0, MIT
3+
4+
//! This module contains the migration logic for the `NV24` upgrade.
5+
mod migration;
6+
7+
/// Run migration for `NV24`. This should be the only exported method in this
8+
/// module.
9+
#[allow(unused_imports)]
10+
pub use migration::run_migration;
11+
12+
use crate::{define_system_states, impl_system, impl_verifier};
13+
14+
define_system_states!(
15+
fil_actor_system_state::v14::State,
16+
// TODO(forest): https://github.com/ChainSafe/forest/issues/4804
17+
// This should point to the new state type, e.g., `fil_actor_system_state::v15::State`
18+
fil_actor_system_state::v14::State
19+
);
20+
21+
impl_system!();
22+
impl_verifier!();

0 commit comments

Comments
 (0)