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