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