Skip to content

Commit ca1ae7b

Browse files
fix(ci): speed up snapshot downloading on CI (#6592)
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
1 parent 58ba383 commit ca1ae7b

File tree

7 files changed

+32
-2
lines changed

7 files changed

+32
-2
lines changed

.github/workflows/forest.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ env:
3636
CXX: sccache clang++
3737
FIL_PROOFS_PARAMETER_CACHE: /var/tmp/filecoin-proof-parameters
3838
SHELL_IMAGE: busybox
39+
FOREST_AUTO_DOWNLOAD_SNAPSHOT_PATH: /var/tmp/forest_snapshot_calibnet_latest.forest.car.zst
3940
jobs:
4041
build-macos:
4142
name: Build MacOS

docs/docs/users/reference/env_variables.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ process.
5656
| `FOREST_ETH_BLOCK_CACHE_SIZE` | positive integer | 500 | 1 | The size of Eth block cache |
5757
| `FOREST_RPC_BACKFILL_FULL_TIPSET_FROM_NETWORK` | 1 or true | false | 1 | Whether or not to backfill full tipsets from the p2p network |
5858
| `FOREST_STRICT_JSON` | 1 or true | false | 1 | Enable strict JSON validation to detect duplicate keys in RPC requests |
59+
| `FOREST_AUTO_DOWNLOAD_SNAPSHOT_PATH` | URL or file path | empty | `/var/tmp/forest_snapshot_calibnet.forest.car.zst` | Override snapshot path for `--auto-download-snapshot` |
5960

6061
### `FOREST_F3_SIDECAR_FFI_BUILD_OPT_OUT`
6162

scripts/tests/calibnet_kademlia_check.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ cat <<- EOF > $CONFIG_PATH
2424
kademlia = true
2525
EOF
2626

27+
handle_auto_download_snapshot_env
2728
$FOREST_PATH --chain calibnet --encrypt-keystore false --auto-download-snapshot --config "$CONFIG_PATH" --save-token ./admin_token --rpc-address 127.0.0.1:12345 --metrics-address 127.0.0.1:6117 --healthcheck-address 127.0.0.1:2347 &
2829
FOREST_NODE_PID=$!
2930
# Verify that more peers are connected via kademlia

scripts/tests/calibnet_no_discovery_check.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ function shutdown {
1111

1212
trap shutdown EXIT
1313

14+
handle_auto_download_snapshot_env
1415
$FOREST_PATH --chain calibnet --encrypt-keystore false --mdns false --kademlia false --auto-download-snapshot --exit-after-init
1516
$FOREST_PATH --chain calibnet --encrypt-keystore false --mdns false --kademlia false --auto-download-snapshot --log-dir "$LOG_DIRECTORY" &
1617
FOREST_NODE_PID=$!

scripts/tests/calibnet_stateless_mode_check.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ cat <<- EOF > $CONFIG_PATH
2424
kademlia = false
2525
EOF
2626

27+
handle_auto_download_snapshot_env
2728
# Disable discovery to not connect to more nodes
2829
$FOREST_PATH --chain calibnet --encrypt-keystore false --auto-download-snapshot --config "$CONFIG_PATH" --rpc false --metrics-address 127.0.0.1:6117 --healthcheck-address 127.0.0.1:2347 &
2930
FOREST_NODE_PID=$!

scripts/tests/harness.sh

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,27 @@ LOG_DIRECTORY=$TMP_DIR/logs
1616
export TMP_DIR
1717
export LOG_DIRECTORY
1818

19+
# Use `aria2` to fetch the latest calibnet snapshot
20+
# when `FOREST_AUTO_DOWNLOAD_SNAPSHOT_PATH` is set
21+
# This optimization is used on CI to speed up snapshot downloading
22+
function handle_auto_download_snapshot_env {
23+
if [[ -n "${FOREST_AUTO_DOWNLOAD_SNAPSHOT_PATH:-}" ]]; then
24+
echo "Downloading calibnet snapshot to ${FOREST_AUTO_DOWNLOAD_SNAPSHOT_PATH}"
25+
mkdir -p "$(dirname "${FOREST_AUTO_DOWNLOAD_SNAPSHOT_PATH}")"
26+
aria2c -x5 -c https://forest-archive.chainsafe.dev/latest/calibnet/ \
27+
-d "$(dirname "${FOREST_AUTO_DOWNLOAD_SNAPSHOT_PATH}")" \
28+
-o "$(basename "${FOREST_AUTO_DOWNLOAD_SNAPSHOT_PATH}")"
29+
fi
30+
}
31+
1932
function forest_import_non_calibnet_snapshot {
2033
echo "Importing a non calibnet snapshot"
2134
$FOREST_PATH --chain calibnet --encrypt-keystore false --halt-after-import --import-snapshot ./test-snapshots/chain4.car
2235
}
2336

2437
function forest_download_and_import_snapshot {
2538
echo "Downloading and importing snapshot"
39+
handle_auto_download_snapshot_env
2640
$FOREST_PATH --chain calibnet --encrypt-keystore false --halt-after-import --height=-200 --auto-download-snapshot
2741
}
2842

src/daemon/mod.rs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -709,8 +709,19 @@ async fn maybe_set_snapshot_path(
709709
(false, _, _) => {} // noop - don't need a snapshot
710710
(true, true, _) => {} // noop - we need a snapshot, and we have one
711711
(true, false, true) => {
712-
let url = crate::cli_shared::snapshot::stable_url(vendor, chain)?;
713-
config.client.snapshot_path = Some(url.to_string().into());
712+
const AUTO_SNAPSHOT_PATH_ENV_KEY: &str = "FOREST_AUTO_DOWNLOAD_SNAPSHOT_PATH";
713+
match std::env::var(AUTO_SNAPSHOT_PATH_ENV_KEY) {
714+
Ok(path) if !path.is_empty() => {
715+
tracing::info!(
716+
"importing snapshot from {path} set by `{AUTO_SNAPSHOT_PATH_ENV_KEY}`"
717+
);
718+
config.client.snapshot_path = Some(path.into());
719+
}
720+
_ => {
721+
let url = crate::cli_shared::snapshot::stable_url(vendor, chain)?;
722+
config.client.snapshot_path = Some(url.to_string().into());
723+
}
724+
}
714725
}
715726
(true, false, false) => {
716727
// we need a snapshot, don't have one, and don't have permission to download one, so ask the user

0 commit comments

Comments
 (0)