Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix builds of lightning-rapid-gossip-sync and lightning-background-processor crates #3289

Merged
merged 3 commits into from
Sep 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 2 additions & 7 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -149,16 +149,11 @@ jobs:
run: |
cd lightning
RUSTFLAGS="--cfg=require_route_graph_test" cargo test
RUSTFLAGS="--cfg=require_route_graph_test" cargo test --features hashbrown
cd ..
- name: Run benchmarks on Rust ${{ matrix.toolchain }}
run: |
cd bench
RUSTFLAGS="--cfg=ldk_bench --cfg=require_route_graph_test" cargo bench
- name: Run benchmarks with hashbrown on Rust ${{ matrix.toolchain }}
run: |
cd bench
RUSTFLAGS="--cfg=ldk_bench --cfg=require_route_graph_test" cargo bench --features hashbrown
check_commits:
runs-on: ubuntu-latest
Expand Down Expand Up @@ -199,15 +194,15 @@ jobs:
- name: Run cargo check for release build.
run: |
cargo check --release
cargo check --no-default-features --features=no-std --release
tnull marked this conversation as resolved.
Show resolved Hide resolved
cargo check --no-default-features --features=futures,std --release
cargo doc --release
- name: Run cargo check for Taproot build.
run: |
cargo check --release
cargo check --no-default-features --features=no-std --release
cargo check --no-default-features --release
cargo check --no-default-features --features=futures,std --release
cargo doc --release
cargo doc --no-default-features --release
env:
RUSTFLAGS: '--cfg=taproot'
RUSTDOCFLAGS: '--cfg=taproot'
Expand Down
2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
[workspace]
resolver = "2"

# When the workspace members change, make sure to update the list here as well
# as in `ci/ci-tests.sh`.
members = [
"lightning",
"lightning-types",
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ Crates
-----------
1. [lightning](./lightning)
The core of the LDK library, implements the Lightning protocol, channel state machine,
and on-chain logic. Supports `no-std` and exposes only relatively low-level interfaces.
and on-chain logic. Supports `no_std` and exposes only relatively low-level interfaces.
2. [lightning-background-processor](./lightning-background-processor)
Utilities to perform required background tasks for Rust Lightning.
3. [lightning-block-sync](./lightning-block-sync)
Expand Down
3 changes: 0 additions & 3 deletions bench/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@ edition = "2021"
name = "bench"
harness = false

[features]
hashbrown = ["lightning/hashbrown"]

[dependencies]
lightning = { path = "../lightning", features = ["_test_utils", "criterion"] }
lightning-persister = { path = "../lightning-persister", features = ["criterion"] }
Expand Down
3 changes: 0 additions & 3 deletions bench/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
This crate uses criterion to benchmark various LDK functions.

It can be run as `RUSTFLAGS=--cfg=ldk_bench cargo bench`.

For routing or other HashMap-bottlenecked functions, the `hashbrown` feature
should also be benchmarked.
2 changes: 1 addition & 1 deletion ci/check-compiles.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ cargo check
cargo doc
cargo doc --document-private-items
cd fuzz && RUSTFLAGS="--cfg=fuzzing --cfg=secp256k1_fuzz --cfg=hashes_fuzz" cargo check --features=stdin_fuzz
cd ../lightning && cargo check --no-default-features --features=no-std
cd ../lightning && cargo check --no-default-features
cd .. && RUSTC_BOOTSTRAP=1 RUSTFLAGS="--cfg=c_bindings" cargo check -Z avoid-dev-deps
42 changes: 31 additions & 11 deletions ci/ci-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,33 @@ PIN_RELEASE_DEPS # pin the release dependencies in our main workspace

export RUST_BACKTRACE=1

echo -e "\n\nBuilding and testing all workspace crates..."
cargo test --verbose --color always
echo -e "\n\nChecking the full workspace."
cargo check --verbose --color always

echo -e "\n\nBuilding and testing Block Sync Clients with features"
# When the workspace members change, make sure to update the list here as well
# as in `Cargo.toml`.
WORKSPACE_MEMBERS=(
lightning
tnull marked this conversation as resolved.
Show resolved Hide resolved
lightning-types
lightning-block-sync
lightning-invoice
lightning-net-tokio
lightning-persister
lightning-background-processor
lightning-rapid-gossip-sync
lightning-custom-message
lightning-transaction-sync
possiblyrandom
)

echo -e "\n\nChecking, testing, and building docs for all workspace members individually..."
for DIR in "${WORKSPACE_MEMBERS[@]}"; do
cargo test -p "$DIR" --verbose --color always
cargo check -p "$DIR" --verbose --color always
cargo doc -p "$DIR" --document-private-items
done

echo -e "\n\nChecking and testing Block Sync Clients with features"

cargo test -p lightning-block-sync --verbose --color always --features rest-client
cargo check -p lightning-block-sync --verbose --color always --features rest-client
Expand Down Expand Up @@ -80,38 +102,36 @@ grep '^max_level_' lightning/Cargo.toml | awk '{ print $1 }'| while read -r FEAT
RUSTFLAGS="$RUSTFLAGS -A unused_variables -A unused_macros -A unused_imports -A dead_code" cargo check -p lightning --verbose --color always --features "$FEATURE"
done

echo -e "\n\nTesting no-std builds"
echo -e "\n\nTesting no_std builds"
for DIR in lightning-invoice lightning-rapid-gossip-sync; do
cargo test -p $DIR --verbose --color always --no-default-features
done

cargo test -p lightning --verbose --color always --no-default-features --features no-std
# check if there is a conflict between no-std and the default std feature
cargo test -p lightning --verbose --color always --features no-std
cargo test -p lightning --verbose --color always --no-default-features

echo -e "\n\nTesting c_bindings builds"
# Note that because `$RUSTFLAGS` is not passed through to doctest builds we cannot selectively
# disable doctests in `c_bindings` so we skip doctests entirely here.
RUSTFLAGS="$RUSTFLAGS --cfg=c_bindings" cargo test --verbose --color always --lib --bins --tests

for DIR in lightning-invoice lightning-rapid-gossip-sync; do
# check if there is a conflict between no-std and the c_bindings cfg
# check if there is a conflict between no_std and the c_bindings cfg
RUSTFLAGS="$RUSTFLAGS --cfg=c_bindings" cargo test -p $DIR --verbose --color always --no-default-features
done

# Note that because `$RUSTFLAGS` is not passed through to doctest builds we cannot selectively
# disable doctests in `c_bindings` so we skip doctests entirely here.
RUSTFLAGS="$RUSTFLAGS --cfg=c_bindings" cargo test -p lightning-background-processor --verbose --color always --features futures --no-default-features --lib --bins --tests
RUSTFLAGS="$RUSTFLAGS --cfg=c_bindings" cargo test -p lightning --verbose --color always --no-default-features --features=no-std --lib --bins --tests
RUSTFLAGS="$RUSTFLAGS --cfg=c_bindings" cargo test -p lightning --verbose --color always --no-default-features --lib --bins --tests

echo -e "\n\nTesting other crate-specific builds"
# Note that outbound_commitment_test only runs in this mode because of hardcoded signature values
RUSTFLAGS="$RUSTFLAGS --cfg=ldk_test_vectors" cargo test -p lightning --verbose --color always --no-default-features --features=std
# This one only works for lightning-invoice
# check that compile with no-std and serde works in lightning-invoice
# check that compile with no_std and serde works in lightning-invoice
cargo test -p lightning-invoice --verbose --color always --no-default-features --features serde

echo -e "\n\nTesting no-std build on a downstream no-std crate"
echo -e "\n\nTesting no_std build on a downstream no-std crate"
# check no-std compatibility across dependencies
pushd no-std-check
cargo check --verbose --color always --features lightning-transaction-sync
Expand Down
2 changes: 1 addition & 1 deletion fuzz/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ libfuzzer_fuzz = ["libfuzzer-sys"]
stdin_fuzz = []

[dependencies]
lightning = { path = "../lightning", features = ["regex", "hashbrown", "_test_utils"] }
lightning = { path = "../lightning", features = ["regex", "_test_utils"] }
lightning-invoice = { path = "../lightning-invoice" }
lightning-rapid-gossip-sync = { path = "../lightning-rapid-gossip-sync" }
bech32 = "0.9.1"
Expand Down
4 changes: 3 additions & 1 deletion lightning-background-processor/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,14 @@ rustdoc-args = ["--cfg", "docsrs"]

[features]
futures = [ ]
std = []
std = ["lightning/std", "bitcoin-io/std", "bitcoin_hashes/std"]

default = ["std"]

[dependencies]
bitcoin = { version = "0.32.2", default-features = false }
bitcoin_hashes = { version = "0.14.0", default-features = false }
bitcoin-io = { version = "0.1.2", default-features = false }
lightning = { version = "0.0.124", path = "../lightning", default-features = false }
lightning-rapid-gossip-sync = { version = "0.0.124", path = "../lightning-rapid-gossip-sync", default-features = false }

Expand Down
5 changes: 2 additions & 3 deletions lightning-background-processor/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
//! Utilities that take 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. See docs for
//! [`BackgroundProcessor`] for more details on the nitty-gritty.

//! running properly, and (2) either can or should be run in the background.
#![cfg_attr(feature = "std", doc = "See docs for [`BackgroundProcessor`] for more details.")]
#![deny(rustdoc::broken_intra_doc_links)]
#![deny(rustdoc::private_intra_doc_links)]
#![deny(missing_docs)]
Expand Down
4 changes: 3 additions & 1 deletion lightning-rapid-gossip-sync/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,13 @@ Utility to process gossip routing data from Rapid Gossip Sync Server.

[features]
default = ["std"]
std = []
std = ["bitcoin-io/std", "bitcoin_hashes/std"]

[dependencies]
lightning = { version = "0.0.124", path = "../lightning", default-features = false }
bitcoin = { version = "0.32.2", default-features = false }
bitcoin_hashes = { version = "0.14.0", default-features = false }
bitcoin-io = { version = "0.1.2", default-features = false }

[target.'cfg(ldk_bench)'.dependencies]
criterion = { version = "0.4", optional = true, default-features = false }
Expand Down
26 changes: 20 additions & 6 deletions lightning-rapid-gossip-sync/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,15 @@
//! Note that the first ever rapid sync should use `0` for `last_sync_timestamp`.
//!
//! After the gossip data snapshot has been downloaded, one of the client's graph processing
//! functions needs to be called. In this example, we process the update by reading its contents
//! from disk, which we do by calling [`RapidGossipSync::update_network_graph`]:
//! functions needs to be called.
#![cfg_attr(
feature = "std",
doc = "In this example, we process the update by reading its contents from disk, which we do by calling [`RapidGossipSync::update_network_graph`]:"
)]
#![cfg_attr(
not(feature = "std"),
doc = "In this example, we process the update by reading its contents from disk, which we do by calling [`RapidGossipSync::update_network_graph_no_std`]:"
)]
//!
//! ```
//! use bitcoin::constants::genesis_block;
Expand All @@ -54,10 +61,17 @@
//! let network_graph = NetworkGraph::new(Network::Bitcoin, &logger);
//! let rapid_sync = RapidGossipSync::new(&network_graph, &logger);
//! let snapshot_contents: &[u8] = &[0; 0];
//! // In no-std you need to provide the current time in unix epoch seconds
//! // otherwise you can use update_network_graph
//! let current_time_unix = 0;
//! let new_last_sync_timestamp_result = rapid_sync.update_network_graph_no_std(snapshot_contents, Some(current_time_unix));
//! // In non-`std` environments you need to provide the current time in unix epoch seconds
//! // otherwise you can use `update_network_graph`:
#![cfg_attr(
feature = "std",
doc = "let new_last_sync_timestamp_result = rapid_sync.update_network_graph(snapshot_contents);"
)]
#![cfg_attr(not(feature = "std"), doc = "let current_time_unix = 0;")]
#![cfg_attr(
not(feature = "std"),
doc = "let new_last_sync_timestamp_result = rapid_sync.update_network_graph_no_std(snapshot_contents, Some(current_time_unix));"
)]
//! ```

#![cfg_attr(all(not(feature = "std"), not(test)), no_std)]
Expand Down
7 changes: 3 additions & 4 deletions lightning/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ max_level_trace = []
# This is unsafe to use in production because it may result in the counterparty publishing taking our funds.
unsafe_revoked_tx_signing = []

no-std = ["hashbrown", "possiblyrandom", "libm"]
std = []

# Generates low-r bitcoin signatures, which saves 1 byte in 50% of the cases
Expand All @@ -44,12 +43,12 @@ lightning-invoice = { version = "0.32.0", path = "../lightning-invoice", default
bech32 = { version = "0.9.1", default-features = false }
bitcoin = { version = "0.32.2", default-features = false, features = ["secp-recovery"] }

hashbrown = { version = "0.13", optional = true, default-features = false }
possiblyrandom = { version = "0.2", path = "../possiblyrandom", optional = true, default-features = false }
hashbrown = { version = "0.13", default-features = false }
possiblyrandom = { version = "0.2", path = "../possiblyrandom", default-features = false }
regex = { version = "1.5.6", optional = true }
backtrace = { version = "0.3", optional = true }

libm = { version = "0.2", optional = true, default-features = false }
libm = { version = "0.2", default-features = false }

[dev-dependencies]
regex = "1.5.6"
Expand Down
11 changes: 6 additions & 5 deletions lightning/src/events/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -543,12 +543,13 @@ pub enum PaymentFailureReason {
///
/// [`ChannelManager::abandon_payment`]: crate::ln::channelmanager::ChannelManager::abandon_payment
UserAbandoned,
/// We exhausted all of our retry attempts while trying to send the payment, or we
/// exhausted the [`Retry::Timeout`] if the user set one. If at any point a retry
/// attempt failed while being forwarded along the path, an [`Event::PaymentPathFailed`] will
#[cfg_attr(feature = "std", doc = "We exhausted all of our retry attempts while trying to send the payment, or we")]
#[cfg_attr(feature = "std", doc = "exhausted the [`Retry::Timeout`] if the user set one.")]
#[cfg_attr(not(feature = "std"), doc = "We exhausted all of our retry attempts while trying to send the payment.")]
/// If at any point a retry attempt failed while being forwarded along the path, an [`Event::PaymentPathFailed`] will
/// have come before this.
///
/// [`Retry::Timeout`]: crate::ln::channelmanager::Retry::Timeout
#[cfg_attr(feature = "std", doc = "")]
#[cfg_attr(feature = "std", doc = "[`Retry::Timeout`]: crate::ln::channelmanager::Retry::Timeout")]
RetriesExhausted,
/// The payment expired while retrying, based on the provided
/// [`PaymentParameters::expiry_time`].
Expand Down
4 changes: 0 additions & 4 deletions lightning/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
//!
//! * `std`
//! * `grind_signatures`
//! * `no-std ` - exposes write trait implementations from the `core2` crate (at least one of `no-std` or `std` are required)
//! * Skip logging of messages at levels below the given log level:
//! * `max_level_off`
//! * `max_level_error`
Expand All @@ -53,9 +52,6 @@

#![cfg_attr(all(not(feature = "std"), not(test)), no_std)]

#[cfg(not(any(feature = "std", feature = "no-std")))]
compile_error!("at least one of the `std` or `no-std` features must be enabled");

#[cfg(all(fuzzing, test))]
compile_error!("Tests will always fail with cfg=fuzzing");

Expand Down
4 changes: 2 additions & 2 deletions lightning/src/ln/channelmanager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6042,7 +6042,7 @@ where
/// * Forgetting about stale outbound payments, either those that have already been fulfilled
/// or those awaiting an invoice that hasn't been delivered in the necessary amount of time.
/// The latter is determined using the system clock in `std` and the highest seen block time
/// minus two hours in `no-std`.
/// minus two hours in non-`std`.
///
/// Note that this may cause reentrancy through [`chain::Watch::update_channel`] calls or feerate
/// estimate fetches.
Expand Down Expand Up @@ -9064,7 +9064,7 @@ macro_rules! create_refund_builder { ($self: ident, $builder: ty) => {
/// See [Avoiding Duplicate Payments] for other requirements once the payment has been sent.
///
/// The builder will have the provided expiration set. Any changes to the expiration on the
/// returned builder will not be honored by [`ChannelManager`]. For `no-std`, the highest seen
/// returned builder will not be honored by [`ChannelManager`]. For non-`std`, the highest seen
/// block time minus two hours is used for the current time when determining if the refund has
/// expired.
///
Expand Down
28 changes: 16 additions & 12 deletions lightning/src/ln/invoice_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,8 @@ use core::iter::Iterator;
/// [`ChannelManager::create_inbound_payment_for_hash`]: crate::ln::channelmanager::ChannelManager::create_inbound_payment_for_hash
/// [`PhantomRouteHints::channels`]: crate::ln::channelmanager::PhantomRouteHints::channels
/// [`MIN_FINAL_CLTV_EXPIRY_DETLA`]: crate::ln::channelmanager::MIN_FINAL_CLTV_EXPIRY_DELTA
///
/// This can be used in a `no_std` environment, where [`std::time::SystemTime`] is not
/// available and the current time is supplied by the caller.
#[cfg_attr(feature = "std", doc = "")]
#[cfg_attr(feature = "std", doc = "This can be used in a `no_std` environment, where [`std::time::SystemTime`] is not available and the current time is supplied by the caller.")]
pub fn create_phantom_invoice<ES: Deref, NS: Deref, L: Deref>(
amt_msat: Option<u64>, payment_hash: Option<PaymentHash>, description: String,
invoice_expiry_delta_secs: u32, phantom_route_hints: Vec<PhantomRouteHints>, entropy_source: ES,
Expand Down Expand Up @@ -117,9 +116,8 @@ where
/// [`ChannelManager::create_inbound_payment`]: crate::ln::channelmanager::ChannelManager::create_inbound_payment
/// [`ChannelManager::create_inbound_payment_for_hash`]: crate::ln::channelmanager::ChannelManager::create_inbound_payment_for_hash
/// [`PhantomRouteHints::channels`]: crate::ln::channelmanager::PhantomRouteHints::channels
///
/// This can be used in a `no_std` environment, where [`std::time::SystemTime`] is not
/// available and the current time is supplied by the caller.
#[cfg_attr(feature = "std", doc = "")]
#[cfg_attr(feature = "std", doc = "This version can be used in a `no_std` environment, where [`std::time::SystemTime`] is not available and the current time is supplied by the caller.")]
pub fn create_phantom_invoice_with_description_hash<ES: Deref, NS: Deref, L: Deref>(
amt_msat: Option<u64>, payment_hash: Option<PaymentHash>, invoice_expiry_delta_secs: u32,
description_hash: Sha256, phantom_route_hints: Vec<PhantomRouteHints>, entropy_source: ES,
Expand Down Expand Up @@ -399,9 +397,12 @@ where
)
}

/// See [`create_invoice_from_channelmanager_with_description_hash`]
/// This version can be used in a `no_std` environment, where [`std::time::SystemTime`] is not
/// available and the current time is supplied by the caller.
/// Utility to construct an invoice. Generally, unless you want to do something like a custom
/// `cltv_expiry`, this is what you should be using to create an invoice.
#[cfg_attr(feature = "std", doc = "")]
#[cfg_attr(feature = "std", doc = "See [`create_invoice_from_channelmanager_with_description_hash`] for more information.")]
#[cfg_attr(feature = "std", doc = "")]
#[cfg_attr(feature = "std", doc = "This can be used in a `no_std` environment, where [`std::time::SystemTime`] is not available and the current time is supplied by the caller.")]
pub fn create_invoice_from_channelmanager_with_description_hash_and_duration_since_epoch<M: Deref, T: Deref, ES: Deref, NS: Deref, SP: Deref, F: Deref, R: Deref, L: Deref>(
channelmanager: &ChannelManager<M, T, ES, NS, SP, F, R, L>, node_signer: NS, logger: L,
network: Currency, amt_msat: Option<u64>, description_hash: Sha256,
Expand All @@ -424,9 +425,12 @@ pub fn create_invoice_from_channelmanager_with_description_hash_and_duration_sin
)
}

/// See [`create_invoice_from_channelmanager`]
/// This version can be used in a `no_std` environment, where [`std::time::SystemTime`] is not
/// available and the current time is supplied by the caller.
/// Utility to construct an invoice. Generally, unless you want to do something like a custom
/// `cltv_expiry`, this is what you should be using to create an invoice.
#[cfg_attr(feature = "std", doc = "")]
#[cfg_attr(feature = "std", doc = "See [`create_invoice_from_channelmanager`] for more information.")]
#[cfg_attr(feature = "std", doc = "")]
#[cfg_attr(feature = "std", doc = "This version can be used in a `no_std` environment, where [`std::time::SystemTime`] is not available and the current time is supplied by the caller.")]
pub fn create_invoice_from_channelmanager_and_duration_since_epoch<M: Deref, T: Deref, ES: Deref, NS: Deref, SP: Deref, F: Deref, R: Deref, L: Deref>(
channelmanager: &ChannelManager<M, T, ES, NS, SP, F, R, L>, node_signer: NS, logger: L,
network: Currency, amt_msat: Option<u64>, description: String, duration_since_epoch: Duration,
Expand Down
2 changes: 1 addition & 1 deletion lightning/src/ln/msgs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ pub enum DecodeError {
ShortRead,
/// A length descriptor in the packet didn't describe the later data correctly.
BadLengthDescriptor,
/// Error from [`std::io`].
/// Error from [`crate::io`].
Io(io::ErrorKind),
/// The message included zlib-compressed values, which we don't support.
UnsupportedCompression,
Expand Down
Loading
Loading