Check lockorders in tests with a trivial lockorder tracker
[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.36.0 is MSRV for Rust-Lightning, lightning-invoice, and lightning-persister
14                      1.36.0,
15                      # 1.41.0 is Debian stable
16                      1.41.0,
17                      # 1.45.2 is MSRV for lightning-net-tokio, lightning-block-sync, and coverage generation
18                      1.45.2,
19                      # 1.47.0 will be the MSRV for no-std builds using hashbrown once core2 is updated
20                      1.47.0]
21         include:
22           - toolchain: stable
23             build-net-tokio: true
24             build-no-std: true
25           - toolchain: stable
26             platform: macos-latest
27             build-net-tokio: true
28             build-no-std: true
29           - toolchain: beta
30             platform: macos-latest
31             build-net-tokio: true
32             build-no-std: true
33           - toolchain: stable
34             platform: windows-latest
35             build-net-tokio: true
36             build-no-std: true
37           - toolchain: beta
38             platform: windows-latest
39             build-net-tokio: true
40             build-no-std: true
41           - toolchain: beta
42             build-net-tokio: true
43             build-no-std: true
44           - toolchain: 1.36.0
45             build-no-std: false
46             test-log-variants: true
47           - toolchain: 1.41.0
48             build-no-std: false
49           - toolchain: 1.45.2
50             build-net-old-tokio: true
51             build-net-tokio: true
52             build-no-std: false
53             coverage: true
54           - toolchain: 1.47.0
55             build-no-std: true
56     runs-on: ${{ matrix.platform }}
57     steps:
58       - name: Checkout source code
59         uses: actions/checkout@v2
60       - name: Install Rust ${{ matrix.toolchain }} toolchain
61         uses: actions-rs/toolchain@v1
62         with:
63           toolchain: ${{ matrix.toolchain }}
64           override: true
65           profile: minimal
66       - name: Pin tokio to 1.14 for Rust 1.45
67         if: "matrix.build-net-old-tokio"
68         run: cargo update -p tokio --precise "1.14.0" --verbose
69       - name: Build on Rust ${{ matrix.toolchain }} with net-tokio
70         if: "matrix.build-net-tokio && !matrix.coverage"
71         run: cargo build --verbose --color always
72       - name: Build on Rust ${{ matrix.toolchain }} with net-tokio and full code-linking for coverage generation
73         if: matrix.coverage
74         run: RUSTFLAGS="-C link-dead-code" cargo build --verbose --color always
75       - name: Build on Rust ${{ matrix.toolchain }}
76         if: "! matrix.build-net-tokio"
77         run: |
78           cargo build --verbose  --color always -p lightning
79           cargo build --verbose  --color always -p lightning-invoice
80           cargo build --verbose  --color always -p lightning-persister
81       - name: Build on Rust ${{ matrix.toolchain }} with all Log-Limiting features
82         if: matrix.test-log-variants
83         run: |
84           cd lightning
85           for FEATURE in $(cat Cargo.toml | grep '^max_level_' | awk '{ print $1 }'); do
86             cargo build --verbose --color always --features $FEATURE
87           done
88       - name: Build Block Sync Clients on Rust ${{ matrix.toolchain }} with features
89         if: "matrix.build-net-tokio && !matrix.coverage"
90         run: |
91           cd lightning-block-sync
92           cargo build --verbose --color always --features rest-client
93           cargo build --verbose --color always --features rpc-client
94           cargo build --verbose --color always --features rpc-client,rest-client
95           cargo build --verbose --color always --features rpc-client,rest-client,tokio
96       - name: Build Block Sync Clients on Rust ${{ matrix.toolchain }} with features and full code-linking for coverage generation
97         if: matrix.coverage
98         run: |
99           cd lightning-block-sync
100           RUSTFLAGS="-C link-dead-code" cargo build --verbose --color always --features rest-client
101           RUSTFLAGS="-C link-dead-code" cargo build --verbose --color always --features rpc-client
102           RUSTFLAGS="-C link-dead-code" cargo build --verbose --color always --features rpc-client,rest-client
103           RUSTFLAGS="-C link-dead-code" cargo build --verbose --color always --features rpc-client,rest-client,tokio
104       - name: Test backtrace-debug builds on Rust ${{ matrix.toolchain }}
105         if: "matrix.build-no-std"
106         run: |
107           cd lightning && cargo test --verbose --color always --features backtrace
108       - name: Test on Rust ${{ matrix.toolchain }} with net-tokio
109         if: "matrix.build-net-tokio && !matrix.coverage"
110         run: cargo test --verbose --color always
111       - name: Test on Rust ${{ matrix.toolchain }} with net-tokio and full code-linking for coverage generation
112         if: matrix.coverage
113         run: RUSTFLAGS="-C link-dead-code" cargo test --verbose --color always
114       - name: Test on no-std bullds Rust ${{ matrix.toolchain }}
115         if: "matrix.build-no-std && !matrix.coverage"
116         shell: bash # Default on Winblows is powershell
117         run: |
118           cd lightning
119           cargo test --verbose --color always --no-default-features --features no-std
120           # check if there is a conflict between no-std and the default std feature
121           cargo test --verbose --color always --features no-std
122           # check if there is a conflict between no-std and the c_bindings cfg
123           RUSTFLAGS="--cfg=c_bindings" cargo test --verbose --color always --no-default-features --features=no-std
124           cd ..
125       - name: Test on no-std builds Rust ${{ matrix.toolchain }} and full code-linking for coverage generation
126         if: "matrix.build-no-std && matrix.coverage"
127         run: |
128           cd lightning
129           RUSTFLAGS="-C link-dead-code" cargo test --verbose --color always --no-default-features --features no-std
130           cd ..
131       - name: Test on Rust ${{ matrix.toolchain }}
132         if: "! matrix.build-net-tokio"
133         run: |
134           cargo test --verbose --color always  -p lightning
135           cargo test --verbose --color always  -p lightning-invoice
136           cargo build --verbose  --color always -p lightning-persister
137           cargo build --verbose  --color always -p lightning-background-processor
138       - name: Test C Bindings Modifications on Rust ${{ matrix.toolchain }}
139         if: "! matrix.build-net-tokio"
140         run: |
141           RUSTFLAGS="--cfg=c_bindings" cargo test --verbose --color always  -p lightning
142           RUSTFLAGS="--cfg=c_bindings" cargo test --verbose --color always  -p lightning-invoice
143           RUSTFLAGS="--cfg=c_bindings" cargo build --verbose  --color always -p lightning-persister
144           RUSTFLAGS="--cfg=c_bindings" cargo build --verbose  --color always -p lightning-background-processor
145       - name: Test Block Sync Clients on Rust ${{ matrix.toolchain }} with features
146         if: "matrix.build-net-tokio && !matrix.coverage"
147         run: |
148           cd lightning-block-sync
149           cargo test --verbose --color always --features rest-client
150           cargo test --verbose --color always --features rpc-client
151           cargo test --verbose --color always --features rpc-client,rest-client
152           cargo test --verbose --color always --features rpc-client,rest-client,tokio
153       - name: Test Block Sync Clients on Rust ${{ matrix.toolchain }} with features and full code-linking for coverage generation
154         if: matrix.coverage
155         run: |
156           cd lightning-block-sync
157           RUSTFLAGS="-C link-dead-code" cargo test --verbose --color always --features rest-client
158           RUSTFLAGS="-C link-dead-code" cargo test --verbose --color always --features rpc-client
159           RUSTFLAGS="-C link-dead-code" cargo test --verbose --color always --features rpc-client,rest-client
160           RUSTFLAGS="-C link-dead-code" cargo test --verbose --color always --features rpc-client,rest-client,tokio
161       - name: Install deps for kcov
162         if: matrix.coverage
163         run: |
164           sudo apt-get update
165           sudo apt-get -y install binutils-dev libcurl4-openssl-dev zlib1g-dev libdw-dev libiberty-dev
166       - name: Install kcov
167         if: matrix.coverage
168         run: |
169           wget https://github.com/SimonKagstrom/kcov/archive/master.tar.gz
170           tar xzf master.tar.gz
171           cd kcov-master && mkdir build && cd build
172           cmake ..
173           make
174           make install DESTDIR=../../kcov-build
175           cd ../.. && rm -rf kcov-master master.tar.gz
176       - name: Generate coverage report
177         if: matrix.coverage
178         run: |
179           for file in target/debug/deps/lightning*; do
180             [ -x "${file}" ] || continue;
181             mkdir -p "target/cov/$(basename $file)";
182             ./kcov-build/usr/local/bin/kcov --exclude-pattern=/.cargo,/usr/lib --verify "target/cov/$(basename $file)" "$file";
183           done
184       - name: Upload coverage
185         if: matrix.coverage
186         uses: codecov/codecov-action@v2
187         with:
188           # Could you use this to fake the coverage report for your PR? Sure.
189           # Will anyone be impressed by your amazing coverage? No
190           # Maybe if codecov wasn't broken we wouldn't need to do this...
191           token: f421b687-4dc2-4387-ac3d-dc3b2528af57
192           fail_ci_if_error: true
193
194   benchmark:
195     runs-on: ubuntu-latest
196     env:
197       TOOLCHAIN: nightly
198     steps:
199       - name: Checkout source code
200         uses: actions/checkout@v2
201       - name: Install Rust ${{ env.TOOLCHAIN }} toolchain
202         uses: actions-rs/toolchain@v1
203         with:
204           toolchain: ${{ env.TOOLCHAIN }}
205           override: true
206           profile: minimal
207       - name: Cache routing graph snapshot
208         id: cache-graph
209         uses: actions/cache@v2
210         with:
211           path: lightning/net_graph-2021-05-31.bin
212           key: ldk-net_graph-v0.0.15-2021-05-31.bin
213       - name: Fetch routing graph snapshot
214         if: steps.cache-graph.outputs.cache-hit != 'true'
215         run: |
216           wget -O lightning/net_graph-2021-05-31.bin https://bitcoin.ninja/ldk-net_graph-v0.0.15-2021-05-31.bin
217           if [ "$(sha256sum lightning/net_graph-2021-05-31.bin | awk '{ print $1 }')" != "05a5361278f68ee2afd086cc04a1f927a63924be451f3221d380533acfacc303" ]; then
218             echo "Bad hash"
219             exit 1
220           fi
221       - name: Test with Network Graph on Rust ${{ matrix.toolchain }}
222         run: |
223           cd lightning
224           RUSTFLAGS="--cfg=require_route_graph_test" cargo test
225           RUSTFLAGS="--cfg=require_route_graph_test" cargo test --features hashbrown
226           cd ..
227       - name: Run benchmarks on Rust ${{ matrix.toolchain }}
228         run: |
229           cargo bench --features unstable
230
231   check_commits:
232     runs-on: ubuntu-latest
233     env:
234       # rustc 1.53 regressed and panics when building our (perfectly fine) docs.
235       # See https://github.com/rust-lang/rust/issues/84738
236       TOOLCHAIN: 1.52.1
237     steps:
238       - name: Checkout source code
239         uses: actions/checkout@v2
240         with:
241           fetch-depth: 0
242       - name: Install Rust ${{ env.TOOLCHAIN }} toolchain
243         uses: actions-rs/toolchain@v1
244         with:
245           toolchain: ${{ env.TOOLCHAIN }}
246           override: true
247           profile: minimal
248       - name: Fetch full tree and rebase on upstream
249         run: |
250           git remote add upstream https://github.com/rust-bitcoin/rust-lightning
251           git fetch upstream
252           export GIT_COMMITTER_EMAIL="rl-ci@example.com"
253           export GIT_COMMITTER_NAME="RL CI"
254           git rebase upstream/main
255       - name: For each commit, run cargo check (including in fuzz)
256         run: ci/check-each-commit.sh upstream/main
257
258   fuzz:
259     runs-on: ubuntu-latest
260     env:
261       TOOLCHAIN: stable
262     steps:
263       - name: Checkout source code
264         uses: actions/checkout@v2
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: Install dependencies for honggfuzz
272         run: |
273           sudo apt-get update
274           sudo apt-get -y install build-essential binutils-dev libunwind-dev
275       - name: Sanity check fuzz targets on Rust ${{ env.TOOLCHAIN }}
276         run: cd fuzz && RUSTFLAGS="--cfg=fuzzing" cargo test --verbose --color always
277       - name: Run fuzzers
278         run: cd fuzz && ./ci-fuzz.sh && cd ..
279       - name: Run lightning-invoice fuzzers
280         run: cd lightning-invoice/fuzz && RUSTFLAGS="--cfg=fuzzing" cargo test --verbose && ./ci-fuzz.sh
281
282   linting:
283     runs-on: ubuntu-latest
284     env:
285       TOOLCHAIN: 1.47.0
286     steps:
287       - name: Checkout source code
288         uses: actions/checkout@v2
289       - name: Install Rust ${{ env.TOOLCHAIN }} toolchain
290         uses: actions-rs/toolchain@v1
291         with:
292           toolchain: ${{ env.TOOLCHAIN }}
293           override: true
294           profile: minimal
295       - name: Install clippy
296         run: |
297           rustup component add clippy
298       - name: Run default clippy linting
299         run: |
300           cargo clippy -- -Aclippy::erasing_op -Aclippy::never_loop -Aclippy::if_same_then_else -Dclippy::try_err