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