From 0038a3f7dea705823939909c60bbd3826362bc1f Mon Sep 17 00:00:00 2001 From: Elias Rohrer Date: Mon, 10 Oct 2022 14:47:18 -0400 Subject: [PATCH] Add `futures` CI check This adds testing of the `futures` feature to CI. In order to avoid introducing a dependency on `std`, we switch to using the `futures-util` crate directly enabling only a subset of features. To this end, we also switch to using the `select_biased!` macro, which is equivalent to `select!` except that it doesn't choose ready futures pseudo-randomly at runtime. --- .github/workflows/build.yml | 37 ++++++++++++++++++----- lightning-background-processor/Cargo.toml | 5 ++- lightning-background-processor/src/lib.rs | 5 ++- lightning-block-sync/Cargo.toml | 2 +- lightning-block-sync/src/rest.rs | 2 +- lightning-block-sync/src/rpc.rs | 2 +- 6 files changed, 38 insertions(+), 15 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 799d22a64..171c57fcb 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -12,7 +12,7 @@ jobs: beta, # 1.41.1 is MSRV for Rust-Lightning, lightning-invoice, and lightning-persister 1.41.1, - # 1.45.2 is MSRV for lightning-net-tokio, lightning-block-sync, and coverage generation + # 1.45.2 is MSRV for lightning-net-tokio, lightning-block-sync, lightning-background-processor, and coverage generation 1.45.2, # 1.47.0 will be the MSRV for no-std builds using hashbrown once core2 is updated 1.47.0] @@ -20,34 +20,43 @@ jobs: - toolchain: stable build-net-tokio: true build-no-std: true + build-futures: true - toolchain: stable platform: macos-latest build-net-tokio: true build-no-std: true + build-futures: true - toolchain: beta platform: macos-latest build-net-tokio: true build-no-std: true + build-futures: true - toolchain: stable platform: windows-latest build-net-tokio: true build-no-std: true + build-futures: true - toolchain: beta platform: windows-latest build-net-tokio: true build-no-std: true + build-futures: true - toolchain: beta build-net-tokio: true build-no-std: true + build-futures: true - toolchain: 1.41.1 build-no-std: false test-log-variants: true + build-futures: false - toolchain: 1.45.2 build-net-old-tokio: true build-net-tokio: true build-no-std: false + build-futures: true coverage: true - toolchain: 1.47.0 + build-futures: true build-no-std: true runs-on: ${{ matrix.platform }} steps: @@ -109,7 +118,7 @@ jobs: - name: Test on Rust ${{ matrix.toolchain }} with net-tokio and full code-linking for coverage generation if: matrix.coverage run: RUSTFLAGS="-C link-dead-code" cargo test --verbose --color always - - name: Test on no-std bullds Rust ${{ matrix.toolchain }} + - name: Test no-std builds on Rust ${{ matrix.toolchain }} if: "matrix.build-no-std && !matrix.coverage" shell: bash # Default on Winblows is powershell run: | @@ -140,15 +149,26 @@ jobs: run: | cd lightning RUSTFLAGS="-C link-dead-code" cargo test --verbose --color always --no-default-features --features no-std - cd .. + - name: Test futures builds on Rust ${{ matrix.toolchain }} + if: "matrix.build-futures && !matrix.coverage" + shell: bash # Default on Winblows is powershell + run: | + cd lightning-background-processor + cargo test --verbose --color always --no-default-features --features futures + - name: Test futures builds on Rust ${{ matrix.toolchain }} and full code-linking for coverage generation + if: "matrix.build-futures && matrix.coverage" + shell: bash # Default on Winblows is powershell + run: | + cd lightning-background-processor + RUSTFLAGS="-C link-dead-code" cargo test --verbose --color always --no-default-features --features futures - name: Test on Rust ${{ matrix.toolchain }} if: "! matrix.build-net-tokio" run: | - cargo test --verbose --color always -p lightning - cargo test --verbose --color always -p lightning-invoice - cargo test --verbose --color always -p lightning-rapid-gossip-sync - cargo build --verbose --color always -p lightning-persister - cargo build --verbose --color always -p lightning-background-processor + cargo test --verbose --color always -p lightning + cargo test --verbose --color always -p lightning-invoice + cargo test --verbose --color always -p lightning-rapid-gossip-sync + cargo test --verbose --color always -p lightning-persister + cargo test --verbose --color always -p lightning-background-processor - name: Test C Bindings Modifications on Rust ${{ matrix.toolchain }} if: "! matrix.build-net-tokio" run: | @@ -299,6 +319,7 @@ jobs: run: | cargo check --release cargo check --no-default-features --features=no-std --release + cargo check --no-default-features --features=futures --release cargo doc --release fuzz: diff --git a/lightning-background-processor/Cargo.toml b/lightning-background-processor/Cargo.toml index 2c4d3df08..6dd06b57f 100644 --- a/lightning-background-processor/Cargo.toml +++ b/lightning-background-processor/Cargo.toml @@ -13,11 +13,14 @@ edition = "2018" all-features = true rustdoc-args = ["--cfg", "docsrs"] +[features] +futures = [ "futures-util" ] + [dependencies] bitcoin = "0.29.0" lightning = { version = "0.0.111", path = "../lightning", features = ["std"] } lightning-rapid-gossip-sync = { version = "0.0.111", path = "../lightning-rapid-gossip-sync" } -futures = { version = "0.3", optional = true } +futures-util = { version = "0.3", default-features = false, features = ["async-await-macro"], optional = true } [dev-dependencies] lightning = { version = "0.0.111", path = "../lightning", features = ["_test_utils"] } diff --git a/lightning-background-processor/src/lib.rs b/lightning-background-processor/src/lib.rs index 704398af2..055b5ca6f 100644 --- a/lightning-background-processor/src/lib.rs +++ b/lightning-background-processor/src/lib.rs @@ -35,7 +35,7 @@ use std::time::{Duration, Instant}; use std::ops::Deref; #[cfg(feature = "futures")] -use futures::{select, future::FutureExt}; +use futures_util::{select_biased, future::FutureExt}; /// `BackgroundProcessor` takes care of tasks that (1) need to happen periodically to keep /// Rust-Lightning running properly, and (2) either can or should be run in the background. Its @@ -377,7 +377,6 @@ pub async fn process_events_async< P: 'static + Deref + Send + Sync, Descriptor: 'static + SocketDescriptor + Send + Sync, CMH: 'static + Deref + Send + Sync, - CUMH: 'static + Deref + Send + Sync, RMH: 'static + Deref + Send + Sync, OMH: 'static + Deref + Send + Sync, EH: 'static + EventHandler + Send, @@ -415,7 +414,7 @@ where let mut should_continue = true; define_run_body!(persister, event_handler, chain_monitor, channel_manager, gossip_sync, peer_manager, logger, scorer, should_continue, { - select! { + select_biased! { _ = channel_manager.get_persistable_update_future().fuse() => true, cont = sleeper(Duration::from_millis(100)).fuse() => { should_continue = cont; diff --git a/lightning-block-sync/Cargo.toml b/lightning-block-sync/Cargo.toml index d213e36dd..afd2a7c30 100644 --- a/lightning-block-sync/Cargo.toml +++ b/lightning-block-sync/Cargo.toml @@ -20,7 +20,7 @@ rpc-client = [ "serde", "serde_json", "chunked_transfer" ] [dependencies] bitcoin = "0.29.0" lightning = { version = "0.0.111", path = "../lightning" } -futures = { version = "0.3" } +futures-util = { version = "0.3" } tokio = { version = "1.0", features = [ "io-util", "net", "time" ], optional = true } serde = { version = "1.0", features = ["derive"], optional = true } serde_json = { version = "1.0", optional = true } diff --git a/lightning-block-sync/src/rest.rs b/lightning-block-sync/src/rest.rs index f46e5e02e..c73b23b60 100644 --- a/lightning-block-sync/src/rest.rs +++ b/lightning-block-sync/src/rest.rs @@ -7,7 +7,7 @@ use crate::http::{BinaryResponse, HttpEndpoint, HttpClient, JsonResponse}; use bitcoin::hash_types::BlockHash; use bitcoin::hashes::hex::ToHex; -use futures::lock::Mutex; +use futures_util::lock::Mutex; use std::convert::TryFrom; use std::convert::TryInto; diff --git a/lightning-block-sync/src/rpc.rs b/lightning-block-sync/src/rpc.rs index 6e78654a9..f04769560 100644 --- a/lightning-block-sync/src/rpc.rs +++ b/lightning-block-sync/src/rpc.rs @@ -7,7 +7,7 @@ use crate::http::{HttpClient, HttpEndpoint, HttpError, JsonResponse}; use bitcoin::hash_types::BlockHash; use bitcoin::hashes::hex::ToHex; -use futures::lock::Mutex; +use futures_util::lock::Mutex; use serde_json; -- 2.39.5