Pin tokio to 1.26 on windows to fix CI
[rust-lightning] / .github / workflows / build.yml
1 name: Continuous Integration Checks
2
3 on: [push, pull_request]
4
5 jobs:
6   build:
7     strategy:
8       fail-fast: false
9       matrix:
10         platform: [ ubuntu-latest ]
11         toolchain: [ stable,
12                      beta,
13                      # 1.41.1 is MSRV for Rust-Lightning, lightning-invoice, and lightning-persister
14                      1.41.1,
15                      # 1.45.2 is MSRV for lightning-net-tokio, lightning-block-sync, lightning-background-processor
16                      1.45.2,
17                      # 1.47.0 will be the MSRV for no-std builds using hashbrown once core2 is updated
18                      1.47.0]
19         include:
20           - toolchain: stable
21             build-net-tokio: true
22             build-no-std: true
23             build-futures: true
24             build-tx-sync: true
25             coverage: true
26           - toolchain: stable
27             platform: macos-latest
28             build-net-tokio: true
29             build-no-std: true
30             build-futures: true
31             build-tx-sync: true
32           - toolchain: stable
33             test-custom-message: true
34           - toolchain: beta
35             platform: macos-latest
36             build-net-tokio: true
37             build-no-std: true
38             build-futures: true
39             build-tx-sync: true
40           - toolchain: stable
41             platform: windows-latest
42             build-net-tokio: true
43             build-no-std: true
44             build-futures: true
45             build-tx-sync: false
46           - toolchain: beta
47             platform: windows-latest
48             build-net-tokio: true
49             build-no-std: true
50             build-futures: true
51             build-tx-sync: false
52           - toolchain: beta
53             build-net-tokio: true
54             build-no-std: true
55             build-futures: true
56             build-tx-sync: true
57           - toolchain: beta
58             test-custom-message: true
59           - toolchain: 1.41.1
60             build-no-std: false
61             test-log-variants: true
62             build-futures: false
63             build-tx-sync: false
64           - toolchain: 1.45.2
65             build-net-old-tokio: true
66             build-net-tokio: true
67             build-no-std: false
68             build-futures: true
69             build-tx-sync: false
70           - toolchain: 1.47.0
71             build-futures: true
72             build-no-std: true
73             build-tx-sync: false
74     runs-on: ${{ matrix.platform }}
75     steps:
76       - name: Checkout source code
77         uses: actions/checkout@v3
78       - name: Install Rust ${{ matrix.toolchain }} toolchain
79         uses: actions-rs/toolchain@v1
80         with:
81           toolchain: ${{ matrix.toolchain }}
82           override: true
83           profile: minimal
84       - name: Pin tokio to 1.14 for Rust 1.45
85         if: "matrix.build-net-old-tokio"
86         run: cargo update -p tokio --precise "1.14.0" --verbose
87         env:
88           CARGO_NET_GIT_FETCH_WITH_CLI: "true"
89       - name: Pin tokio to 1.26 for Windows
90         if: "matrix.platform == 'windows-latest'"
91         run: cargo update -p tokio --precise "1.26.0" --verbose
92         env:
93           CARGO_NET_GIT_FETCH_WITH_CLI: "true"
94       - name: Build on Rust ${{ matrix.toolchain }} with net-tokio
95         if: "matrix.build-net-tokio && !matrix.coverage"
96         run: cargo build --verbose --color always
97       - name: Build on Rust ${{ matrix.toolchain }} with net-tokio, and full code-linking for coverage generation
98         if: matrix.coverage
99         run: RUSTFLAGS="-C link-dead-code" cargo build --verbose --color always
100       - name: Build on Rust ${{ matrix.toolchain }}
101         if: "! matrix.build-net-tokio"
102         run: |
103           cargo build --verbose  --color always -p lightning
104           cargo build --verbose  --color always -p lightning-invoice
105           cargo build --verbose  --color always -p lightning-persister
106       - name: Build on Rust ${{ matrix.toolchain }} with all Log-Limiting features
107         if: matrix.test-log-variants
108         run: |
109           cd lightning
110           for FEATURE in $(cat Cargo.toml | grep '^max_level_' | awk '{ print $1 }'); do
111             cargo build --verbose --color always --features $FEATURE
112           done
113       - name: Build Block Sync Clients on Rust ${{ matrix.toolchain }} with features
114         if: "matrix.build-net-tokio && !matrix.coverage"
115         run: |
116           cd lightning-block-sync
117           cargo build --verbose --color always --features rest-client
118           cargo build --verbose --color always --features rpc-client
119           cargo build --verbose --color always --features rpc-client,rest-client
120           cargo build --verbose --color always --features rpc-client,rest-client,tokio
121       - name: Build Block Sync Clients on Rust ${{ matrix.toolchain }} with features and full code-linking for coverage generation
122         if: matrix.coverage
123         run: |
124           cd lightning-block-sync
125           RUSTFLAGS="-C link-dead-code" cargo build --verbose --color always --features rest-client
126           RUSTFLAGS="-C link-dead-code" cargo build --verbose --color always --features rpc-client
127           RUSTFLAGS="-C link-dead-code" cargo build --verbose --color always --features rpc-client,rest-client
128           RUSTFLAGS="-C link-dead-code" cargo build --verbose --color always --features rpc-client,rest-client,tokio
129       - name: Build Transaction Sync Clients on Rust ${{ matrix.toolchain }} with features
130         if: "matrix.build-tx-sync && !matrix.coverage"
131         run: |
132           cd lightning-transaction-sync
133           cargo build --verbose --color always --features esplora-blocking
134           cargo build --verbose --color always --features esplora-async
135           cargo build --verbose --color always --features esplora-async-https
136       - name: Build transaction sync clients on Rust ${{ matrix.toolchain }} with features and full code-linking for coverage generation
137         if: "matrix.build-tx-sync && matrix.coverage"
138         run: |
139           cd lightning-transaction-sync
140           RUSTFLAGS="-C link-dead-code" cargo build --verbose --color always --features esplora-blocking
141           RUSTFLAGS="-C link-dead-code" cargo build --verbose --color always --features esplora-async
142           RUSTFLAGS="-C link-dead-code" cargo build --verbose --color always --features esplora-async-https
143       - name: Test transaction sync clients on Rust ${{ matrix.toolchain }} with features
144         if: "matrix.build-tx-sync"
145         run: |
146           cd lightning-transaction-sync
147           cargo test --verbose --color always --features esplora-blocking
148           cargo test --verbose --color always --features esplora-async
149           cargo test --verbose --color always --features esplora-async-https
150       - name: Test backtrace-debug builds on Rust ${{ matrix.toolchain }}
151         if: "matrix.toolchain == 'stable'"
152         shell: bash # Default on Winblows is powershell
153         run: |
154           cd lightning && RUST_BACKTRACE=1 cargo test --verbose --color always --features backtrace
155       - name: Test on Rust ${{ matrix.toolchain }} with net-tokio
156         if: "matrix.build-net-tokio && !matrix.coverage"
157         run: cargo test --verbose --color always
158       - name: Test on Rust ${{ matrix.toolchain }} with net-tokio, and full code-linking for coverage generation
159         if: matrix.coverage
160         run: RUSTFLAGS="-C link-dead-code" cargo test --verbose --color always
161       - name: Test no-std builds on Rust ${{ matrix.toolchain }}
162         if: "matrix.build-no-std && !matrix.coverage"
163         shell: bash # Default on Winblows is powershell
164         run: |
165           for DIR in lightning lightning-invoice lightning-rapid-gossip-sync; do
166           cd $DIR
167             cargo test --verbose --color always --no-default-features --features no-std
168             # check if there is a conflict between no-std and the default std feature
169             cargo test --verbose --color always --features no-std
170             # check that things still pass without grind_signatures
171             # note that outbound_commitment_test only runs in this mode, because of hardcoded signature values
172             cargo test --verbose --color always --no-default-features --features std
173             # check if there is a conflict between no-std and the c_bindings cfg
174             RUSTFLAGS="--cfg=c_bindings" cargo test --verbose --color always --no-default-features --features=no-std
175             cd ..
176           done
177           # check no-std compatibility across dependencies
178           cd no-std-check
179           cargo check --verbose --color always --features lightning-transaction-sync
180       - name: Build no-std-check on Rust ${{ matrix.toolchain }} for ARM Embedded
181         if: "matrix.build-no-std && matrix.platform == 'ubuntu-latest'"
182         run: |
183           cd no-std-check
184           rustup target add thumbv7m-none-eabi
185           sudo apt-get -y install gcc-arm-none-eabi
186           cargo build --target=thumbv7m-none-eabi
187       - name: Test on no-std builds Rust ${{ matrix.toolchain }} and full code-linking for coverage generation
188         if: "matrix.build-no-std && matrix.coverage"
189         run: |
190           cd lightning
191           RUSTFLAGS="-C link-dead-code" cargo test --verbose --color always --no-default-features --features no-std
192       - name: Test futures builds on Rust ${{ matrix.toolchain }}
193         if: "matrix.build-futures && !matrix.coverage"
194         shell: bash # Default on Winblows is powershell
195         run: |
196           cd lightning-background-processor
197           cargo test --verbose --color always --no-default-features --features futures
198       - name: Test futures builds on Rust ${{ matrix.toolchain }} and full code-linking for coverage generation
199         if: "matrix.build-futures && matrix.coverage"
200         shell: bash # Default on Winblows is powershell
201         run: |
202           cd lightning-background-processor
203           RUSTFLAGS="-C link-dead-code" cargo test --verbose --color always --no-default-features --features futures
204       - name: Test on Rust ${{ matrix.toolchain }}
205         if: "! matrix.build-net-tokio"
206         run: |
207           cargo test --verbose --color always -p lightning
208           cargo test --verbose --color always -p lightning-invoice
209           cargo test --verbose --color always -p lightning-rapid-gossip-sync
210           cargo test --verbose --color always -p lightning-persister
211           cargo test --verbose --color always -p lightning-background-processor
212       - name: Test C Bindings Modifications on Rust ${{ matrix.toolchain }}
213         if: "! matrix.build-net-tokio"
214         run: |
215           RUSTFLAGS="--cfg=c_bindings" cargo test --verbose --color always  -p lightning
216           RUSTFLAGS="--cfg=c_bindings" cargo test --verbose --color always  -p lightning-invoice
217           RUSTFLAGS="--cfg=c_bindings" cargo build --verbose  --color always -p lightning-persister
218           RUSTFLAGS="--cfg=c_bindings" cargo build --verbose  --color always -p lightning-background-processor
219       - name: Test Block Sync Clients on Rust ${{ matrix.toolchain }} with features
220         if: "matrix.build-net-tokio && !matrix.coverage"
221         run: |
222           cd lightning-block-sync
223           cargo test --verbose --color always --features rest-client
224           cargo test --verbose --color always --features rpc-client
225           cargo test --verbose --color always --features rpc-client,rest-client
226           cargo test --verbose --color always --features rpc-client,rest-client,tokio
227       - name: Test Block Sync Clients on Rust ${{ matrix.toolchain }} with features and full code-linking for coverage generation
228         if: matrix.coverage
229         run: |
230           cd lightning-block-sync
231           RUSTFLAGS="-C link-dead-code" cargo test --verbose --color always --features rest-client
232           RUSTFLAGS="-C link-dead-code" cargo test --verbose --color always --features rpc-client
233           RUSTFLAGS="-C link-dead-code" cargo test --verbose --color always --features rpc-client,rest-client
234           RUSTFLAGS="-C link-dead-code" cargo test --verbose --color always --features rpc-client,rest-client,tokio
235       - name: Test Custom Message Macros on Rust ${{ matrix.toolchain }}
236         if: "matrix.test-custom-message"
237         run: |
238           cd lightning-custom-message
239           cargo test --verbose --color always
240       - name: Install deps for kcov
241         if: matrix.coverage
242         run: |
243           sudo apt-get update
244           sudo apt-get -y install binutils-dev libcurl4-openssl-dev zlib1g-dev libdw-dev libiberty-dev
245       - name: Install kcov
246         if: matrix.coverage
247         run: |
248           wget https://github.com/SimonKagstrom/kcov/archive/master.tar.gz
249           tar xzf master.tar.gz
250           cd kcov-master && mkdir build && cd build
251           cmake ..
252           make
253           make install DESTDIR=../../kcov-build
254           cd ../.. && rm -rf kcov-master master.tar.gz
255       - name: Generate coverage report
256         if: matrix.coverage
257         run: |
258           for file in target/debug/deps/lightning*; do
259             [ -x "${file}" ] || continue;
260             mkdir -p "target/cov/$(basename $file)";
261             ./kcov-build/usr/local/bin/kcov --exclude-pattern=/.cargo,/usr/lib --verify "target/cov/$(basename $file)" "$file";
262           done
263       - name: Upload coverage
264         if: matrix.coverage
265         uses: codecov/codecov-action@v3
266         with:
267           # Could you use this to fake the coverage report for your PR? Sure.
268           # Will anyone be impressed by your amazing coverage? No
269           # Maybe if codecov wasn't broken we wouldn't need to do this...
270           token: f421b687-4dc2-4387-ac3d-dc3b2528af57
271           fail_ci_if_error: true
272
273   benchmark:
274     runs-on: ubuntu-latest
275     env:
276       TOOLCHAIN: stable
277     steps:
278       - name: Checkout source code
279         uses: actions/checkout@v3
280       - name: Install Rust ${{ env.TOOLCHAIN }} toolchain
281         uses: actions-rs/toolchain@v1
282         with:
283           toolchain: ${{ env.TOOLCHAIN }}
284           override: true
285           profile: minimal
286       - name: Cache routing graph snapshot
287         id: cache-graph
288         uses: actions/cache@v3
289         with:
290           path: lightning/net_graph-2023-01-18.bin
291           key: ldk-net_graph-v0.0.113-2023-01-18.bin
292       - name: Fetch routing graph snapshot
293         if: steps.cache-graph.outputs.cache-hit != 'true'
294         run: |
295           curl --verbose -L -o lightning/net_graph-2023-01-18.bin https://bitcoin.ninja/ldk-net_graph-v0.0.113-2023-01-18.bin
296           echo "Sha sum: $(sha256sum lightning/net_graph-2023-01-18.bin | awk '{ print $1 }')"
297           if [ "$(sha256sum lightning/net_graph-2023-01-18.bin | awk '{ print $1 }')" != "${EXPECTED_ROUTING_GRAPH_SNAPSHOT_SHASUM}" ]; then
298             echo "Bad hash"
299             exit 1
300           fi
301         env:
302           EXPECTED_ROUTING_GRAPH_SNAPSHOT_SHASUM: da6066f2bddcddbe7d8a6debbd53545697137b310bbb8c4911bc8c81fc5ff48c
303       - name: Fetch rapid graph sync reference input
304         run: |
305           curl --verbose -L -o lightning-rapid-gossip-sync/res/full_graph.lngossip https://bitcoin.ninja/ldk-compressed_graph-285cb27df79-2022-07-21.bin
306           echo "Sha sum: $(sha256sum lightning-rapid-gossip-sync/res/full_graph.lngossip | awk '{ print $1 }')"
307           if [ "$(sha256sum lightning-rapid-gossip-sync/res/full_graph.lngossip | awk '{ print $1 }')" != "${EXPECTED_RAPID_GOSSIP_SHASUM}" ]; then
308             echo "Bad hash"
309             exit 1
310           fi
311         env:
312           EXPECTED_RAPID_GOSSIP_SHASUM: e0f5d11641c11896d7af3a2246d3d6c3f1720b7d2d17aab321ecce82e6b7deb8
313       - name: Test with Network Graph on Rust ${{ matrix.toolchain }}
314         run: |
315           cd lightning
316           RUSTFLAGS="--cfg=require_route_graph_test" cargo test
317           RUSTFLAGS="--cfg=require_route_graph_test" cargo test --features hashbrown
318           cd ..
319       - name: Run benchmarks on Rust ${{ matrix.toolchain }}
320         run: |
321           RUSTC_BOOTSTRAP=1 cargo bench --features _bench_unstable
322
323   check_commits:
324     runs-on: ubuntu-latest
325     env:
326       TOOLCHAIN: 1.57.0
327     steps:
328       - name: Checkout source code
329         uses: actions/checkout@v3
330         with:
331           fetch-depth: 0
332       - name: Install Rust ${{ env.TOOLCHAIN }} toolchain
333         uses: actions-rs/toolchain@v1
334         with:
335           toolchain: ${{ env.TOOLCHAIN }}
336           override: true
337           profile: minimal
338       - name: Fetch full tree and rebase on upstream
339         run: |
340           git remote add upstream https://github.com/lightningdevkit/rust-lightning
341           git fetch upstream
342           export GIT_COMMITTER_EMAIL="rl-ci@example.com"
343           export GIT_COMMITTER_NAME="RL CI"
344           git rebase upstream/main
345       - name: For each commit, run cargo check (including in fuzz)
346         run: ci/check-each-commit.sh upstream/main
347
348   check_release:
349     runs-on: ubuntu-latest
350     env:
351       TOOLCHAIN: stable
352     steps:
353       - name: Checkout source code
354         uses: actions/checkout@v3
355         with:
356           fetch-depth: 0
357       - name: Install Rust ${{ env.TOOLCHAIN }} toolchain
358         uses: actions-rs/toolchain@v1
359         with:
360           toolchain: ${{ env.TOOLCHAIN }}
361           override: true
362           profile: minimal
363       - name: Run cargo check for release build.
364         run: |
365           cargo check --release
366           cargo check --no-default-features --features=no-std --release
367           cargo check --no-default-features --features=futures --release
368           cargo doc --release
369
370   fuzz:
371     runs-on: ubuntu-latest
372     env:
373       TOOLCHAIN: stable
374     steps:
375       - name: Checkout source code
376         uses: actions/checkout@v3
377       - name: Install Rust 1.58 toolchain
378         uses: actions-rs/toolchain@v1
379         with:
380           toolchain: 1.58
381           override: true
382           profile: minimal
383       - name: Install dependencies for honggfuzz
384         run: |
385           sudo apt-get update
386           sudo apt-get -y install build-essential binutils-dev libunwind-dev
387       - name: Sanity check fuzz targets on Rust ${{ env.TOOLCHAIN }}
388         run: cd fuzz && RUSTFLAGS="--cfg=fuzzing" cargo test --verbose --color always
389       - name: Run fuzzers
390         run: cd fuzz && ./ci-fuzz.sh && cd ..
391       - name: Run lightning-invoice fuzzers
392         run: cd lightning-invoice/fuzz && RUSTFLAGS="--cfg=fuzzing" cargo test --verbose && ./ci-fuzz.sh
393
394   linting:
395     runs-on: ubuntu-latest
396     env:
397       TOOLCHAIN: stable
398     steps:
399       - name: Checkout source code
400         uses: actions/checkout@v3
401       - name: Install Rust ${{ env.TOOLCHAIN }} toolchain
402         uses: actions-rs/toolchain@v1
403         with:
404           toolchain: ${{ env.TOOLCHAIN }}
405           override: true
406           profile: minimal
407       - name: Install clippy
408         run: |
409           rustup component add clippy
410       - name: Run default clippy linting
411         run: |
412           cargo clippy -- -Aclippy::erasing_op -Aclippy::never_loop -Aclippy::if_same_then_else -Dclippy::try_err