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