Skip to content

Commit 0f47e3d

Browse files
authored
fix(ci): prefetch state computation snapshots to make codecov less flaky (#6496)
1 parent d09d4a7 commit 0f47e3d

File tree

7 files changed

+227
-53
lines changed

7 files changed

+227
-53
lines changed

.github/workflows/coverage.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@ jobs:
5151
- uses: actions/checkout@v6
5252
- uses: jdx/mise-action@v3
5353
- uses: taiki-e/install-action@cargo-llvm-cov
54-
- uses: taiki-e/install-action@nextest
5554
- name: Fetch proof params and RPC test snapshots
5655
run: |
5756
cargo run --bin forest-dev --no-default-features --profile quick -- fetch-test-snapshots --actor-bundle $FOREST_ACTOR_BUNDLE_PATH

.github/workflows/unit-tests.yml

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ env:
3737
CXX: "sccache clang++"
3838
FIL_PROOFS_PARAMETER_CACHE: /var/tmp/filecoin-proof-parameters
3939
RUST_LOG: error
40+
FOREST_ACTOR_BUNDLE_PATH: /var/tmp/forest_actor_bundle.car.zst
4041

4142
jobs:
4243
tests-release:
@@ -59,13 +60,6 @@ jobs:
5960
continue-on-error: true
6061
- name: Checkout Sources
6162
uses: actions/checkout@v6
62-
- uses: actions/cache/restore@v5
63-
with:
64-
path: |
65-
/home/runner/.cache/forest/test/rpc-snapshots/rpc_test
66-
# Broad key + prefix-based restore so the latest rpcsnap-<hash> is picked up.
67-
key: rpcsnap-
68-
enableCrossOsArchive: true
6963
- name: Setup sccache
7064
uses: mozilla-actions/[email protected]
7165
timeout-minutes: ${{ fromJSON(env.CACHE_TIMEOUT_MINUTES) }}
@@ -77,7 +71,7 @@ jobs:
7771
uses: taiki-e/install-action@nextest
7872
- name: Fetch proof params and RPC test snapshots
7973
run: |
80-
cargo run --bin forest-dev --no-default-features --profile quick -- fetch-test-snapshots
74+
cargo run --bin forest-dev --no-default-features --profile quick -- fetch-test-snapshots --actor-bundle $FOREST_ACTOR_BUNDLE_PATH
8175
ls -ahl $FIL_PROOFS_PARAMETER_CACHE
8276
- uses: jdx/mise-action@v3
8377
- run: |
@@ -86,14 +80,3 @@ jobs:
8680
# To minimize compile times: https://nnethercote.github.io/perf-book/build-configuration.html#minimizing-compile-times
8781
RUSTFLAGS: "-C linker=clang -C link-arg=-fuse-ld=lld"
8882
FOREST_TEST_SKIP_PROOF_PARAM_CHECK: 1
89-
- id: get-cache-hash
90-
run: |
91-
ls -lhR ~/.cache/forest/test/rpc-snapshots/rpc_test/*
92-
echo "hash=$(openssl md5 ~/.cache/forest/test/rpc-snapshots/rpc_test/* | sort | openssl md5 | cut -d ' ' -f 2)" >> $GITHUB_OUTPUT
93-
shell: bash
94-
- uses: actions/cache/save@v5
95-
with:
96-
path: |
97-
/home/runner/.cache/forest/test/rpc-snapshots/rpc_test
98-
key: rpcsnap-${{ steps.get-cache-hash.outputs.hash }}
99-
enableCrossOsArchive: true

Cargo.lock

Lines changed: 142 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,6 @@ is-terminal = "0.4"
115115
itertools = "0.14"
116116
jsonrpsee = { version = "0.26", features = ["server", "ws-client", "http-client", "macros"] }
117117
jsonwebtoken = { version = "10", features = ["aws_lc_rs"] }
118-
justjson = "0.3"
119118
keccak-hash = "0.12"
120119
kubert-prometheus-process = "0.2"
121120
lazy-regex = "3"
@@ -196,6 +195,7 @@ similar = "2"
196195
slotmap = "1"
197196
smallvec = "1"
198197
smart-default = "0.7"
198+
sonic-rs = "0.5"
199199
spire_enum = "1"
200200
stacker = "0.1"
201201
static_assertions = "1"

src/dev/subcommands/mod.rs

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ mod state_cmd;
66
use crate::cli_shared::cli::HELP_MESSAGE;
77
use crate::networks::generate_actor_bundle;
88
use crate::rpc::Client;
9+
use crate::state_manager::utils::state_compute::{
10+
get_state_snapshot_file, list_state_snapshot_files,
11+
};
912
use crate::utils::net::{DownloadFileOption, download_file_with_cache};
1013
use crate::utils::proofs_api::ensure_proof_params_downloaded;
1114
use crate::utils::version::FOREST_VERSION_STRING;
@@ -63,8 +66,27 @@ async fn fetch_test_snapshots(actor_bundle: Option<PathBuf>) -> anyhow::Result<(
6366
println!("Wrote the actors bundle to {}", actor_bundle.display());
6467
}
6568

69+
// Prepare state computation and validation snapshots
70+
fetch_state_tests().await?;
71+
6672
// Prepare RPC test snapshots
67-
fetch_rpc_tests().await
73+
fetch_rpc_tests().await?;
74+
75+
Ok(())
76+
}
77+
78+
pub async fn fetch_state_tests() -> anyhow::Result<()> {
79+
let files = list_state_snapshot_files().await?;
80+
let mut joinset = JoinSet::new();
81+
for file in files {
82+
joinset.spawn(async move { get_state_snapshot_file(&file).await });
83+
}
84+
for result in joinset.join_all().await {
85+
if let Err(e) = result {
86+
tracing::warn!("{e}");
87+
}
88+
}
89+
Ok(())
6890
}
6991

7092
async fn fetch_rpc_tests() -> anyhow::Result<()> {

src/rpc/json_validator.rs

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
//! This means JSON like `{"/":"cid1", "/":"cid2"}` will keep only the last value, which can lead to unexpected behavior in RPC calls.
88
99
use ahash::HashSet;
10-
use justjson::Value;
1110

1211
pub const STRICT_JSON_ENV: &str = "FOREST_STRICT_JSON";
1312

@@ -36,28 +35,22 @@ pub fn validate_json_for_duplicates(json_str: &str) -> Result<(), String> {
3635
return Ok(());
3736
}
3837

39-
fn check_value(value: &Value) -> Result<(), String> {
40-
match value {
41-
Value::Object(obj) => {
38+
fn check_value(value: &sonic_rs::Value) -> Result<(), String> {
39+
match value.as_ref() {
40+
sonic_rs::ValueRef::Object(obj) => {
4241
let mut seen = HashSet::default();
43-
for entry in obj.iter() {
44-
let key = entry
45-
.key
46-
.as_str()
47-
.ok_or_else(|| "Invalid JSON key".to_string())?;
48-
42+
for (key, value) in obj.iter() {
4943
if !seen.insert(key) {
5044
return Err(format!(
51-
"duplicate key '{}' in JSON object - this likely indicates malformed input. \
52-
Set {}=0 to disable this check",
53-
key, STRICT_JSON_ENV
45+
"duplicate key '{key}' in JSON object - this likely indicates malformed input. \
46+
Set {STRICT_JSON_ENV}=0 to disable this check"
5447
));
5548
}
56-
check_value(&entry.value)?;
49+
check_value(value)?;
5750
}
5851
Ok(())
5952
}
60-
Value::Array(arr) => {
53+
sonic_rs::ValueRef::Array(arr) => {
6154
for item in arr.iter() {
6255
check_value(item)?;
6356
}
@@ -67,7 +60,7 @@ pub fn validate_json_for_duplicates(json_str: &str) -> Result<(), String> {
6760
}
6861
}
6962
// defer to serde_json for invalid JSON
70-
let value = match Value::from_json(json_str) {
63+
let value: sonic_rs::Value = match sonic_rs::from_str(json_str) {
7164
Ok(v) => v,
7265
Err(_) => return Ok(()),
7366
};

0 commit comments

Comments
 (0)