Skip to content

Commit 545b037

Browse files
committed
Drop no-std feature
We drop the `lightning/no-std` feature and just take `hashbrown`,`possiblyrandom` and `libm` as required dependencies.
1 parent a06e7b9 commit 545b037

30 files changed

+110
-164
lines changed

.github/workflows/build.yml

+2-7
Original file line numberDiff line numberDiff line change
@@ -149,16 +149,11 @@ jobs:
149149
run: |
150150
cd lightning
151151
RUSTFLAGS="--cfg=require_route_graph_test" cargo test
152-
RUSTFLAGS="--cfg=require_route_graph_test" cargo test --features hashbrown
153152
cd ..
154153
- name: Run benchmarks on Rust ${{ matrix.toolchain }}
155154
run: |
156155
cd bench
157156
RUSTFLAGS="--cfg=ldk_bench --cfg=require_route_graph_test" cargo bench
158-
- name: Run benchmarks with hashbrown on Rust ${{ matrix.toolchain }}
159-
run: |
160-
cd bench
161-
RUSTFLAGS="--cfg=ldk_bench --cfg=require_route_graph_test" cargo bench --features hashbrown
162157
163158
check_commits:
164159
runs-on: ubuntu-latest
@@ -199,15 +194,15 @@ jobs:
199194
- name: Run cargo check for release build.
200195
run: |
201196
cargo check --release
202-
cargo check --no-default-features --features=no-std --release
203197
cargo check --no-default-features --features=futures,std --release
204198
cargo doc --release
205199
- name: Run cargo check for Taproot build.
206200
run: |
207201
cargo check --release
208-
cargo check --no-default-features --features=no-std --release
202+
cargo check --no-default-features --release
209203
cargo check --no-default-features --features=futures,std --release
210204
cargo doc --release
205+
cargo doc --no-default-features --release
211206
env:
212207
RUSTFLAGS: '--cfg=taproot'
213208
RUSTDOCFLAGS: '--cfg=taproot'

Cargo.toml

+2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
[workspace]
22
resolver = "2"
33

4+
# When the workspace members change, make sure to update the list here as well
5+
# as in `ci/ci-tests.sh`.
46
members = [
57
"lightning",
68
"lightning-types",

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ Crates
2727
-----------
2828
1. [lightning](./lightning)
2929
The core of the LDK library, implements the Lightning protocol, channel state machine,
30-
and on-chain logic. Supports `no-std` and exposes only relatively low-level interfaces.
30+
and on-chain logic. Supports `no_std` and exposes only relatively low-level interfaces.
3131
2. [lightning-background-processor](./lightning-background-processor)
3232
Utilities to perform required background tasks for Rust Lightning.
3333
3. [lightning-block-sync](./lightning-block-sync)

bench/Cargo.toml

-3
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,6 @@ edition = "2021"
88
name = "bench"
99
harness = false
1010

11-
[features]
12-
hashbrown = ["lightning/hashbrown"]
13-
1411
[dependencies]
1512
lightning = { path = "../lightning", features = ["_test_utils", "criterion"] }
1613
lightning-persister = { path = "../lightning-persister", features = ["criterion"] }

bench/README.md

-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
11
This crate uses criterion to benchmark various LDK functions.
22

33
It can be run as `RUSTFLAGS=--cfg=ldk_bench cargo bench`.
4-
5-
For routing or other HashMap-bottlenecked functions, the `hashbrown` feature
6-
should also be benchmarked.

ci/check-compiles.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,5 @@ cargo check
66
cargo doc
77
cargo doc --document-private-items
88
cd fuzz && RUSTFLAGS="--cfg=fuzzing --cfg=secp256k1_fuzz --cfg=hashes_fuzz" cargo check --features=stdin_fuzz
9-
cd ../lightning && cargo check --no-default-features --features=no-std
9+
cd ../lightning && cargo check --no-default-features
1010
cd .. && RUSTC_BOOTSTRAP=1 RUSTFLAGS="--cfg=c_bindings" cargo check -Z avoid-dev-deps

ci/ci-tests.sh

+8-8
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ export RUST_BACKTRACE=1
3333
echo -e "\n\nChecking the full workspace."
3434
cargo check --verbose --color always
3535

36+
# When the workspace members change, make sure to update the list here as well
37+
# as in `Cargo.toml`.
3638
WORKSPACE_MEMBERS=(
3739
lightning
3840
lightning-types
@@ -100,38 +102,36 @@ grep '^max_level_' lightning/Cargo.toml | awk '{ print $1 }'| while read -r FEAT
100102
RUSTFLAGS="$RUSTFLAGS -A unused_variables -A unused_macros -A unused_imports -A dead_code" cargo check -p lightning --verbose --color always --features "$FEATURE"
101103
done
102104

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

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

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

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

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

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

134-
echo -e "\n\nTesting no-std build on a downstream no-std crate"
134+
echo -e "\n\nTesting no_std build on a downstream no-std crate"
135135
# check no-std compatibility across dependencies
136136
pushd no-std-check
137137
cargo check --verbose --color always --features lightning-transaction-sync

fuzz/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ libfuzzer_fuzz = ["libfuzzer-sys"]
1818
stdin_fuzz = []
1919

2020
[dependencies]
21-
lightning = { path = "../lightning", features = ["regex", "hashbrown", "_test_utils"] }
21+
lightning = { path = "../lightning", features = ["regex", "_test_utils"] }
2222
lightning-invoice = { path = "../lightning-invoice" }
2323
lightning-rapid-gossip-sync = { path = "../lightning-rapid-gossip-sync" }
2424
bech32 = "0.9.1"

lightning-background-processor/src/lib.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
//! Utilities that take care of tasks that (1) need to happen periodically to keep Rust-Lightning
2-
//! running properly, and (2) either can or should be run in the background. See docs for
3-
//! [`BackgroundProcessor`] for more details on the nitty-gritty.
4-
2+
//! running properly, and (2) either can or should be run in the background.
3+
#![cfg_attr(feature = "std", doc = "See docs for [`BackgroundProcessor`] for more details.")]
54
#![deny(rustdoc::broken_intra_doc_links)]
65
#![deny(rustdoc::private_intra_doc_links)]
76
#![deny(missing_docs)]

lightning-rapid-gossip-sync/src/lib.rs

+20-6
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,15 @@
3535
//! Note that the first ever rapid sync should use `0` for `last_sync_timestamp`.
3636
//!
3737
//! After the gossip data snapshot has been downloaded, one of the client's graph processing
38-
//! functions needs to be called. In this example, we process the update by reading its contents
39-
//! from disk, which we do by calling [`RapidGossipSync::update_network_graph`]:
38+
//! functions needs to be called.
39+
#![cfg_attr(
40+
feature = "std",
41+
doc = "In this example, we process the update by reading its contents from disk, which we do by calling [`RapidGossipSync::update_network_graph`]:"
42+
)]
43+
#![cfg_attr(
44+
not(feature = "std"),
45+
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`]:"
46+
)]
4047
//!
4148
//! ```
4249
//! use bitcoin::constants::genesis_block;
@@ -54,10 +61,17 @@
5461
//! let network_graph = NetworkGraph::new(Network::Bitcoin, &logger);
5562
//! let rapid_sync = RapidGossipSync::new(&network_graph, &logger);
5663
//! let snapshot_contents: &[u8] = &[0; 0];
57-
//! // In no-std you need to provide the current time in unix epoch seconds
58-
//! // otherwise you can use update_network_graph
59-
//! let current_time_unix = 0;
60-
//! let new_last_sync_timestamp_result = rapid_sync.update_network_graph_no_std(snapshot_contents, Some(current_time_unix));
64+
//! // In non-`std` environments you need to provide the current time in unix epoch seconds
65+
//! // otherwise you can use `update_network_graph`:
66+
#![cfg_attr(
67+
feature = "std",
68+
doc = "let new_last_sync_timestamp_result = rapid_sync.update_network_graph(snapshot_contents);"
69+
)]
70+
#![cfg_attr(not(feature = "std"), doc = "let current_time_unix = 0;")]
71+
#![cfg_attr(
72+
not(feature = "std"),
73+
doc = "let new_last_sync_timestamp_result = rapid_sync.update_network_graph_no_std(snapshot_contents, Some(current_time_unix));"
74+
)]
6175
//! ```
6276
6377
#![cfg_attr(all(not(feature = "std"), not(test)), no_std)]

lightning/Cargo.toml

+3-4
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ max_level_trace = []
2929
# This is unsafe to use in production because it may result in the counterparty publishing taking our funds.
3030
unsafe_revoked_tx_signing = []
3131

32-
no-std = ["hashbrown", "possiblyrandom", "libm"]
3332
std = []
3433

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

47-
hashbrown = { version = "0.13", optional = true, default-features = false }
48-
possiblyrandom = { version = "0.2", path = "../possiblyrandom", optional = true, default-features = false }
46+
hashbrown = { version = "0.13", default-features = false }
47+
possiblyrandom = { version = "0.2", path = "../possiblyrandom", default-features = false }
4948
regex = { version = "1.5.6", optional = true }
5049
backtrace = { version = "0.3", optional = true }
5150

52-
libm = { version = "0.2", optional = true, default-features = false }
51+
libm = { version = "0.2", default-features = false }
5352

5453
[dev-dependencies]
5554
regex = "1.5.6"

lightning/src/events/mod.rs

+6-5
Original file line numberDiff line numberDiff line change
@@ -543,12 +543,13 @@ pub enum PaymentFailureReason {
543543
///
544544
/// [`ChannelManager::abandon_payment`]: crate::ln::channelmanager::ChannelManager::abandon_payment
545545
UserAbandoned,
546-
/// We exhausted all of our retry attempts while trying to send the payment, or we
547-
/// exhausted the [`Retry::Timeout`] if the user set one. If at any point a retry
548-
/// attempt failed while being forwarded along the path, an [`Event::PaymentPathFailed`] will
546+
#[cfg_attr(feature = "std", doc = "We exhausted all of our retry attempts while trying to send the payment, or we")]
547+
#[cfg_attr(feature = "std", doc = "exhausted the [`Retry::Timeout`] if the user set one.")]
548+
#[cfg_attr(not(feature = "std"), doc = "We exhausted all of our retry attempts while trying to send the payment.")]
549+
/// If at any point a retry attempt failed while being forwarded along the path, an [`Event::PaymentPathFailed`] will
549550
/// have come before this.
550-
///
551-
/// [`Retry::Timeout`]: crate::ln::channelmanager::Retry::Timeout
551+
#[cfg_attr(feature = "std", doc = "")]
552+
#[cfg_attr(feature = "std", doc = "[`Retry::Timeout`]: crate::ln::channelmanager::Retry::Timeout")]
552553
RetriesExhausted,
553554
/// The payment expired while retrying, based on the provided
554555
/// [`PaymentParameters::expiry_time`].

lightning/src/lib.rs

-4
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
//!
2929
//! * `std`
3030
//! * `grind_signatures`
31-
//! * `no-std ` - exposes write trait implementations from the `core2` crate (at least one of `no-std` or `std` are required)
3231
//! * Skip logging of messages at levels below the given log level:
3332
//! * `max_level_off`
3433
//! * `max_level_error`
@@ -53,9 +52,6 @@
5352

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

56-
#[cfg(not(any(feature = "std", feature = "no-std")))]
57-
compile_error!("at least one of the `std` or `no-std` features must be enabled");
58-
5955
#[cfg(all(fuzzing, test))]
6056
compile_error!("Tests will always fail with cfg=fuzzing");
6157

lightning/src/ln/channelmanager.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -6042,7 +6042,7 @@ where
60426042
/// * Forgetting about stale outbound payments, either those that have already been fulfilled
60436043
/// or those awaiting an invoice that hasn't been delivered in the necessary amount of time.
60446044
/// The latter is determined using the system clock in `std` and the highest seen block time
6045-
/// minus two hours in `no-std`.
6045+
/// minus two hours in non-`std`.
60466046
///
60476047
/// Note that this may cause reentrancy through [`chain::Watch::update_channel`] calls or feerate
60486048
/// estimate fetches.
@@ -9064,7 +9064,7 @@ macro_rules! create_refund_builder { ($self: ident, $builder: ty) => {
90649064
/// See [Avoiding Duplicate Payments] for other requirements once the payment has been sent.
90659065
///
90669066
/// The builder will have the provided expiration set. Any changes to the expiration on the
9067-
/// returned builder will not be honored by [`ChannelManager`]. For `no-std`, the highest seen
9067+
/// returned builder will not be honored by [`ChannelManager`]. For non-`std`, the highest seen
90689068
/// block time minus two hours is used for the current time when determining if the refund has
90699069
/// expired.
90709070
///

lightning/src/ln/invoice_utils.rs

+16-12
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,8 @@ use core::iter::Iterator;
6161
/// [`ChannelManager::create_inbound_payment_for_hash`]: crate::ln::channelmanager::ChannelManager::create_inbound_payment_for_hash
6262
/// [`PhantomRouteHints::channels`]: crate::ln::channelmanager::PhantomRouteHints::channels
6363
/// [`MIN_FINAL_CLTV_EXPIRY_DETLA`]: crate::ln::channelmanager::MIN_FINAL_CLTV_EXPIRY_DELTA
64-
///
65-
/// This can be used in a `no_std` environment, where [`std::time::SystemTime`] is not
66-
/// available and the current time is supplied by the caller.
64+
#[cfg_attr(feature = "std", doc = "")]
65+
#[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.")]
6766
pub fn create_phantom_invoice<ES: Deref, NS: Deref, L: Deref>(
6867
amt_msat: Option<u64>, payment_hash: Option<PaymentHash>, description: String,
6968
invoice_expiry_delta_secs: u32, phantom_route_hints: Vec<PhantomRouteHints>, entropy_source: ES,
@@ -117,9 +116,8 @@ where
117116
/// [`ChannelManager::create_inbound_payment`]: crate::ln::channelmanager::ChannelManager::create_inbound_payment
118117
/// [`ChannelManager::create_inbound_payment_for_hash`]: crate::ln::channelmanager::ChannelManager::create_inbound_payment_for_hash
119118
/// [`PhantomRouteHints::channels`]: crate::ln::channelmanager::PhantomRouteHints::channels
120-
///
121-
/// This can be used in a `no_std` environment, where [`std::time::SystemTime`] is not
122-
/// available and the current time is supplied by the caller.
119+
#[cfg_attr(feature = "std", doc = "")]
120+
#[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.")]
123121
pub fn create_phantom_invoice_with_description_hash<ES: Deref, NS: Deref, L: Deref>(
124122
amt_msat: Option<u64>, payment_hash: Option<PaymentHash>, invoice_expiry_delta_secs: u32,
125123
description_hash: Sha256, phantom_route_hints: Vec<PhantomRouteHints>, entropy_source: ES,
@@ -399,9 +397,12 @@ where
399397
)
400398
}
401399

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

427-
/// See [`create_invoice_from_channelmanager`]
428-
/// This version can be used in a `no_std` environment, where [`std::time::SystemTime`] is not
429-
/// available and the current time is supplied by the caller.
428+
/// Utility to construct an invoice. Generally, unless you want to do something like a custom
429+
/// `cltv_expiry`, this is what you should be using to create an invoice.
430+
#[cfg_attr(feature = "std", doc = "")]
431+
#[cfg_attr(feature = "std", doc = "See [`create_invoice_from_channelmanager`] for more information.")]
432+
#[cfg_attr(feature = "std", doc = "")]
433+
#[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.")]
430434
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>(
431435
channelmanager: &ChannelManager<M, T, ES, NS, SP, F, R, L>, node_signer: NS, logger: L,
432436
network: Currency, amt_msat: Option<u64>, description: String, duration_since_epoch: Duration,

lightning/src/ln/msgs.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ pub enum DecodeError {
8787
ShortRead,
8888
/// A length descriptor in the packet didn't describe the later data correctly.
8989
BadLengthDescriptor,
90-
/// Error from [`std::io`].
90+
/// Error from [`crate::io`].
9191
Io(io::ErrorKind),
9292
/// The message included zlib-compressed values, which we don't support.
9393
UnsupportedCompression,

lightning/src/ln/outbound_payment.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -438,8 +438,9 @@ impl_writeable_tlv_based_enum_legacy!(StaleExpiration,
438438
/// [`Event::PaymentFailed`]: crate::events::Event::PaymentFailed
439439
#[derive(Clone, Debug, PartialEq, Eq)]
440440
pub enum RetryableSendFailure {
441-
/// The provided [`PaymentParameters::expiry_time`] indicated that the payment has expired. Note
442-
/// that this error is *not* caused by [`Retry::Timeout`].
441+
/// The provided [`PaymentParameters::expiry_time`] indicated that the payment has expired.
442+
#[cfg_attr(feature = "std", doc = "")]
443+
#[cfg_attr(feature = "std", doc = "Note that this error is *not* caused by [`Retry::Timeout`].")]
443444
///
444445
/// [`PaymentParameters::expiry_time`]: crate::routing::router::PaymentParameters::expiry_time
445446
PaymentExpired,

lightning/src/offers/invoice_macros.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ macro_rules! invoice_builder_methods_common { (
1616
#[doc = concat!("Sets the [`", stringify!($invoice_type), "::relative_expiry`]")]
1717
#[doc = concat!("as seconds since [`", stringify!($invoice_type), "::created_at`].")]
1818
#[doc = "Any expiry that has already passed is valid and can be checked for using"]
19-
#[doc = concat!("[`", stringify!($invoice_type), "::is_expired`].")]
19+
#[cfg_attr(feature = "std", doc = concat!("[`", stringify!($invoice_type), "::is_expired`]."))]
2020
///
2121
/// Successive calls to this method will override the previous setting.
2222
pub fn relative_expiry($($self_mut)* $self: $self_type, relative_expiry_secs: u32) -> $return_type {

0 commit comments

Comments
 (0)