Skip to content

Commit 4b8220b

Browse files
committed
Manually download bitcoind/electrs for CI tests
Previously, we used the auto-download feature of the `electrsd`/`bitcoind` crates. While convenient, they unnecessarily introduced a lot of dependecies (`zip`, `zstd`, `time`, etc.) to our test environment which needed pinning for the MSRV of 1.63. Here, we introduce a new `no_download` config flag allowing us to disable this auto-download feature in CI, where we now opt to download the corresponding binaries manually. We keep the default-auto-download as a convenience feature for running tests locally though.
1 parent 3fdd3b0 commit 4b8220b

File tree

3 files changed

+61
-6
lines changed

3 files changed

+61
-6
lines changed

.github/workflows/rust.yml

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,13 +46,18 @@ jobs:
4646
cargo update -p proptest --precise "1.2.0" --verbose # proptest 1.3.0 requires rustc 1.64.0
4747
cargo update -p reqwest --precise "0.11.20" --verbose # reqwest 0.11.21 broke 1.63.0 MSRV
4848
cargo update -p regex --precise "1.9.6" --verbose # regex 1.10.0 requires rustc 1.65.0
49-
cargo update -p jobserver --precise "0.1.26" --verbose # jobserver 0.1.27 requires rustc 1.66.0
50-
cargo update -p zstd-sys --precise "2.0.8+zstd.1.5.5" --verbose # zstd-sys 2.0.9+zstd.1.5.5 requires rustc 1.64.0
51-
cargo update -p petgraph --precise "0.6.3" --verbose # petgraph v0.6.4, requires rustc 1.64 or newer
5249
cargo update -p home --precise "0.5.5" --verbose # home v0.5.9, requires rustc 1.70 or newer
5350
- name: Set RUSTFLAGS to deny warnings
5451
if: "matrix.toolchain == 'stable'"
5552
run: echo "RUSTFLAGS=-D warnings" >> "$GITHUB_ENV"
53+
- name: Download bitcoind/electrs and set environment variables
54+
if: "matrix.platform != 'windows-latest'"
55+
run: |
56+
source ./scripts/download_bitcoind_electrs.sh
57+
cp "$BITCOIND_EXE" "$HOME"/bitcoind
58+
cp "$ELECTRS_EXE" "$HOME"/electrs
59+
echo "BITCOIND_EXE=$HOME/bitcoind" >> "$GITHUB_ENV"
60+
echo "ELECTRS_EXE=$HOME/electrs" >> "$GITHUB_ENV"
5661
- name: Build on Rust ${{ matrix.toolchain }}
5762
run: cargo build --verbose --color always
5863
- name: Build with UniFFI support on Rust ${{ matrix.toolchain }}
@@ -69,10 +74,12 @@ jobs:
6974
run: cargo check --release --features uniffi --verbose --color always
7075
- name: Test on Rust ${{ matrix.toolchain }}
7176
if: "matrix.platform != 'windows-latest'"
72-
run: cargo test
77+
run: |
78+
RUSTFLAGS="--cfg no_download" cargo test
7379
- name: Test with UniFFI support on Rust ${{ matrix.toolchain }}
7480
if: "matrix.platform != 'windows-latest' && matrix.build-uniffi"
75-
run: cargo test --features uniffi
81+
run: |
82+
RUSTFLAGS="--cfg no_download" cargo test --features uniffi
7683
- name: Check formatting on Rust ${{ matrix.toolchain }}
7784
if: matrix.check-fmt
7885
run: rustup component add rustfmt && cargo fmt --all -- --check

Cargo.toml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,12 +76,17 @@ winapi = { version = "0.3", features = ["winbase"] }
7676
[dev-dependencies]
7777
lightning = { version = "0.0.119", features = ["std", "_test_utils"] }
7878
#lightning = { git = "https://github.com/lightningdevkit/rust-lightning", branch="main", features = ["std", "_test_utils"] }
79-
electrsd = { version = "0.26.0", features = ["legacy", "esplora_a33e97e1", "bitcoind_25_0"] }
8079
electrum-client = { version = "0.15.1", default-features = true }
8180
bitcoincore-rpc = { version = "0.17.0", default-features = false }
8281
proptest = "1.0.0"
8382
regex = "1.5.6"
8483

84+
[target.'cfg(not(no_download))'.dev-dependencies]
85+
electrsd = { version = "0.26.0", features = ["legacy", "esplora_a33e97e1", "bitcoind_25_0"] }
86+
87+
[target.'cfg(no_download)'.dev-dependencies]
88+
electrsd = { version = "0.26.0", features = ["legacy"] }
89+
8590
[target.'cfg(cln_test)'.dev-dependencies]
8691
clightningrpc = { version = "0.3.0-beta.8", default-features = false }
8792

scripts/download_bitcoind_electrs.sh

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# Our Esplora-based tests require `electrs` and `bitcoind`
2+
# binaries. Here, we download the binaries, validate them, and export their
3+
# location via `ELECTRS_EXE`/`BITCOIND_EXE` which will be used by the
4+
# `electrsd`/`bitcoind` crates in our tests.
5+
6+
HOST_PLATFORM="$(rustc --version --verbose | grep "host:" | awk '{ print $2 }')"
7+
ELECTRS_DL_ENDPOINT="https://github.com/RCasatta/electrsd/releases/download/electrs_releases"
8+
ELECTRS_VERSION="esplora_a33e97e1a1fc63fa9c20a116bb92579bbf43b254"
9+
BITCOIND_DL_ENDPOINT="https://bitcoincore.org/bin/"
10+
BITCOIND_VERSION="25.1"
11+
if [[ "$HOST_PLATFORM" == *linux* ]]; then
12+
ELECTRS_DL_FILE_NAME=electrs_linux_"$ELECTRS_VERSION".zip
13+
ELECTRS_DL_HASH="865e26a96e8df77df01d96f2f569dcf9622fc87a8d99a9b8fe30861a4db9ddf1"
14+
BITCOIND_DL_FILE_NAME=bitcoin-"$BITCOIND_VERSION"-x86_64-linux-gnu.tar.gz
15+
BITCOIND_DL_HASH="a978c407b497a727f0444156e397b50491ce862d1f906fef9b521415b3611c8b"
16+
elif [[ "$HOST_PLATFORM" == *darwin* ]]; then
17+
ELECTRS_DL_FILE_NAME=electrs_macos_"$ELECTRS_VERSION".zip
18+
ELECTRS_DL_HASH="2d5ff149e8a2482d3658e9b386830dfc40c8fbd7c175ca7cbac58240a9505bcd"
19+
BITCOIND_DL_FILE_NAME=bitcoin-"$BITCOIND_VERSION"-x86_64-apple-darwin.tar.gz
20+
BITCOIND_DL_HASH="1acfde0ec3128381b83e3e5f54d1c7907871d324549129592144dd12a821eff1"
21+
else
22+
echo "\n\nUnsupported platform: $HOST_PLATFORM Exiting.."
23+
exit 1
24+
fi
25+
26+
DL_TMP_DIR=$(mktemp -d)
27+
trap 'rm -rf -- "$DL_TMP_DIR"' EXIT
28+
29+
pushd "$DL_TMP_DIR"
30+
ELECTRS_DL_URL="$ELECTRS_DL_ENDPOINT"/"$ELECTRS_DL_FILE_NAME"
31+
curl -L -o "$ELECTRS_DL_FILE_NAME" "$ELECTRS_DL_URL"
32+
echo "$ELECTRS_DL_HASH $ELECTRS_DL_FILE_NAME"|shasum -a 256 -c
33+
unzip "$ELECTRS_DL_FILE_NAME"
34+
export ELECTRS_EXE="$DL_TMP_DIR"/electrs
35+
chmod +x "$ELECTRS_EXE"
36+
37+
BITCOIND_DL_URL="$BITCOIND_DL_ENDPOINT"/bitcoin-core-"$BITCOIND_VERSION"/"$BITCOIND_DL_FILE_NAME"
38+
curl -L -o "$BITCOIND_DL_FILE_NAME" "$BITCOIND_DL_URL"
39+
echo "$BITCOIND_DL_HASH $BITCOIND_DL_FILE_NAME"|shasum -a 256 -c
40+
tar xzf "$BITCOIND_DL_FILE_NAME"
41+
export BITCOIND_EXE="$DL_TMP_DIR"/bitcoin-"$BITCOIND_VERSION"/bin/bitcoind
42+
chmod +x "$BITCOIND_EXE"
43+
popd

0 commit comments

Comments
 (0)