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