diff --git a/Cargo.toml b/Cargo.toml index 6bb353cdeb7a..3cd408149639 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -12,6 +12,7 @@ exclude = [".config", ".github", ".maintain", "documentation", "scripts", "inter name = "forest" [workspace.dependencies] +ahash = "0.8" anyhow = "1" cid = { version = "0.11", default-features = false, features = ["std"] } flume = "0.12" @@ -22,10 +23,12 @@ libp2p = { version = "0.56", default-features = false } libp2p-swarm-test = { version = "0.6", default-features = false, features = ["tokio"] } multihash-codetable = { version = "0.1", features = ["blake2b", "blake2s", "blake3", "sha2", "sha3", "strobe"] } rust2go = "0.4" +serde = { version = "1", default-features = false, features = ["derive"] } +serde_yaml = "0.9" tokio = "1" [dependencies] -ahash = "0.8" +ahash = { workspace = true } anes = "0.2" anyhow = { workspace = true } argon2 = "0.5" @@ -185,11 +188,11 @@ rust2go = { workspace = true } schemars = { version = "1", features = ["chrono04", "uuid1"] } scopeguard = "1" semver = "1" -serde = { version = "1", default-features = false, features = ["derive"] } +serde = { workspace = true } serde_ipld_dagcbor = "0.6" serde_json = { version = "1", features = ["raw_value"] } serde_with = { version = "3", features = ["chrono_0_4"] } -serde_yaml = "0.9" +serde_yaml = { workspace = true } sha2 = { version = "0.10", default-features = false } similar = "2" slotmap = "1" @@ -263,7 +266,10 @@ syn = { version = "2", default-features = false, features = ["full", "parsing", tokio-test = "0.4" [build-dependencies] +ahash = { workspace = true } rust2go = { workspace = true, features = ["build"] } +serde = { workspace = true } +serde_yaml = { workspace = true } # https://doc.rust-lang.org/stable/cargo/guide/build-performance.html#reduce-amount-of-generated-debug-information [profile.dev] diff --git a/build.rs b/build.rs index ce1c81d829b9..79158d99d02f 100644 --- a/build.rs +++ b/build.rs @@ -1,7 +1,13 @@ // Copyright 2019-2026 ChainSafe Systems // SPDX-License-Identifier: Apache-2.0, MIT -use std::io::Write; +use ahash::HashMap; +use serde::{Deserialize, Serialize}; +use std::{ + fs::File, + io::{BufWriter, Write}, + path::PathBuf, +}; fn main() { // Only needed when profiling Forest with `gperftools`. This might not work on all platforms. @@ -39,6 +45,7 @@ fn main() { } rpc_regression_tests_gen(); + state_compute_tests_gen(); } // See @@ -54,10 +61,7 @@ fn is_env_truthy(env: &str) -> bool { } fn rpc_regression_tests_gen() { - use std::{fs::File, io::BufWriter, path::PathBuf}; - println!("cargo:rerun-if-changed=src/tool/subcommands/api_cmd/test_snapshots.txt"); - let tests: Vec<&str> = include_str!("src/tool/subcommands/api_cmd/test_snapshots.txt") .lines() .map(|i| { @@ -92,3 +96,33 @@ fn rpc_regression_tests_gen() { .unwrap(); } } + +fn state_compute_tests_gen() { + println!("cargo:rerun-if-changed=src/state_manager/state_compute_tests.yaml"); + let StateComputeTests { tests } = + serde_yaml::from_str(include_str!("src/state_manager/state_compute_tests.yaml")).unwrap(); + let out_dir = PathBuf::from(std::env::var("OUT_DIR").unwrap()); + let out_path = out_dir.join("__state_compute_tests_gen.rs"); + let mut w = BufWriter::new(File::create(&out_path).unwrap()); + for (chain, epochs) in tests { + for epoch in epochs { + writeln!( + w, + r#" + #[cfg(feature = "cargo-test")] + #[tokio::test(flavor = "multi_thread")] + #[fickle::fickle] + async fn cargo_test_state_compute_{chain}_{epoch}() {{ + state_compute_test_run("{chain}".parse().unwrap(), {epoch}).await + }} + "#, + ) + .unwrap(); + } + } +} + +#[derive(Debug, Clone, Serialize, Deserialize)] +struct StateComputeTests { + tests: HashMap>, +} diff --git a/src/state_manager/state_compute_tests.yaml b/src/state_manager/state_compute_tests.yaml new file mode 100644 index 000000000000..0771ca9e7184 --- /dev/null +++ b/src/state_manager/state_compute_tests.yaml @@ -0,0 +1,25 @@ +tests: + mainnet: + # FVM@4 + - 5709604 + calibnet: + # FVM@4 + - 3408952 + # Shark state migration with FVM@2 + - 16801 + # Hygge state migration with FVM@2 + - 322355 + # Lightning state migration with FVM@3 + - 489095 + # Watermelon state migration with FVM@3 + - 1013135 + # Dragon state migration with FVM@4 + - 1427975 + # Waffle state migration with FVM@4 + - 1779095 + # TukTuk state migration with FVM@4 + - 2078795 + # Teep state migration with FVM@4 + - 2523455 + # GoldenWeek state migration with FVM@4 + - 3007295 diff --git a/src/state_manager/utils.rs b/src/state_manager/utils.rs index 91da729ee0d0..1ef2beb94925 100644 --- a/src/state_manager/utils.rs +++ b/src/state_manager/utils.rs @@ -376,123 +376,11 @@ pub mod state_compute { get_state_snapshot_file(&files[0]).await.unwrap(); } - // FVM@4 - #[cfg(feature = "cargo-test")] - #[tokio::test(flavor = "multi_thread")] - #[fickle::fickle] - async fn cargo_test_state_compute_mainnet_5709604() { - let chain = NetworkChain::Mainnet; - let snapshot = get_state_compute_snapshot(&chain, 5709604).await.unwrap(); - let (sm, ts, ts_next) = prepare_state_compute(&chain, &snapshot).await.unwrap(); - state_compute(&sm, ts, &ts_next).await.unwrap(); - } - - // FVM@4 - #[cfg(feature = "cargo-test")] - #[tokio::test(flavor = "multi_thread")] - #[fickle::fickle] - async fn cargo_test_state_compute_calibnet_3408952() { - let chain = NetworkChain::Calibnet; - let snapshot = get_state_compute_snapshot(&chain, 3408952).await.unwrap(); - let (sm, ts, ts_next) = prepare_state_compute(&chain, &snapshot).await.unwrap(); - state_compute(&sm, ts, &ts_next).await.unwrap(); - } - - // Shark state migration with FVM@2 - #[cfg(feature = "cargo-test")] - #[tokio::test(flavor = "multi_thread")] - #[fickle::fickle] - async fn cargo_test_state_compute_calibnet_16801() { - let chain = NetworkChain::Calibnet; - let snapshot = get_state_compute_snapshot(&chain, 16801).await.unwrap(); - let (sm, ts, ts_next) = prepare_state_compute(&chain, &snapshot).await.unwrap(); - state_compute(&sm, ts, &ts_next).await.unwrap(); - } + include!(concat!(env!("OUT_DIR"), "/__state_compute_tests_gen.rs")); - // Hygge state migration with FVM@2 - #[cfg(feature = "cargo-test")] - #[tokio::test(flavor = "multi_thread")] - #[fickle::fickle] - async fn cargo_test_state_compute_calibnet_322355() { - let chain = NetworkChain::Calibnet; - let snapshot = get_state_compute_snapshot(&chain, 322355).await.unwrap(); - let (sm, ts, ts_next) = prepare_state_compute(&chain, &snapshot).await.unwrap(); - state_compute(&sm, ts, &ts_next).await.unwrap(); - } - - // Lightning state migration with FVM@3 - #[cfg(feature = "cargo-test")] - #[tokio::test(flavor = "multi_thread")] - #[fickle::fickle] - async fn cargo_test_state_compute_calibnet_489095() { - let chain = NetworkChain::Calibnet; - let snapshot = get_state_compute_snapshot(&chain, 489095).await.unwrap(); - let (sm, ts, ts_next) = prepare_state_compute(&chain, &snapshot).await.unwrap(); - state_compute(&sm, ts, &ts_next).await.unwrap(); - } - - // Watermelon state migration with FVM@3 - #[cfg(feature = "cargo-test")] - #[tokio::test(flavor = "multi_thread")] - #[fickle::fickle] - async fn cargo_test_state_compute_calibnet_1013135() { - let chain = NetworkChain::Calibnet; - let snapshot = get_state_compute_snapshot(&chain, 1013135).await.unwrap(); - let (sm, ts, ts_next) = prepare_state_compute(&chain, &snapshot).await.unwrap(); - state_compute(&sm, ts, &ts_next).await.unwrap(); - } - - // Dragon state migration with FVM@4 - #[cfg(feature = "cargo-test")] - #[tokio::test(flavor = "multi_thread")] - #[fickle::fickle] - async fn cargo_test_state_compute_calibnet_1427975() { - let chain = NetworkChain::Calibnet; - let snapshot = get_state_compute_snapshot(&chain, 1427975).await.unwrap(); - let (sm, ts, ts_next) = prepare_state_compute(&chain, &snapshot).await.unwrap(); - state_compute(&sm, ts, &ts_next).await.unwrap(); - } - - // Waffle state migration with FVM@4 - #[cfg(feature = "cargo-test")] - #[tokio::test(flavor = "multi_thread")] - #[fickle::fickle] - async fn cargo_test_state_compute_calibnet_1779095() { - let chain = NetworkChain::Calibnet; - let snapshot = get_state_compute_snapshot(&chain, 1779095).await.unwrap(); - let (sm, ts, ts_next) = prepare_state_compute(&chain, &snapshot).await.unwrap(); - state_compute(&sm, ts, &ts_next).await.unwrap(); - } - - // TukTuk state migration with FVM@4 - #[cfg(feature = "cargo-test")] - #[tokio::test(flavor = "multi_thread")] - #[fickle::fickle] - async fn cargo_test_state_compute_calibnet_2078795() { - let chain = NetworkChain::Calibnet; - let snapshot = get_state_compute_snapshot(&chain, 2078795).await.unwrap(); - let (sm, ts, ts_next) = prepare_state_compute(&chain, &snapshot).await.unwrap(); - state_compute(&sm, ts, &ts_next).await.unwrap(); - } - - // Teep state migration with FVM@4 - #[cfg(feature = "cargo-test")] - #[tokio::test(flavor = "multi_thread")] - #[fickle::fickle] - async fn cargo_test_state_compute_calibnet_2523455() { - let chain = NetworkChain::Calibnet; - let snapshot = get_state_compute_snapshot(&chain, 2523455).await.unwrap(); - let (sm, ts, ts_next) = prepare_state_compute(&chain, &snapshot).await.unwrap(); - state_compute(&sm, ts, &ts_next).await.unwrap(); - } - - // GoldenWeek state migration with FVM@4 - #[cfg(feature = "cargo-test")] - #[tokio::test(flavor = "multi_thread")] - #[fickle::fickle] - async fn cargo_test_state_compute_calibnet_3007295() { - let chain = NetworkChain::Calibnet; - let snapshot = get_state_compute_snapshot(&chain, 3007295).await.unwrap(); + #[allow(dead_code)] + async fn state_compute_test_run(chain: NetworkChain, epoch: i64) { + let snapshot = get_state_compute_snapshot(&chain, epoch).await.unwrap(); let (sm, ts, ts_next) = prepare_state_compute(&chain, &snapshot).await.unwrap(); state_compute(&sm, ts, &ts_next).await.unwrap(); }