Skip to content

Commit 7ae3a50

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 055a5b5 commit 7ae3a50

File tree

17 files changed

+31
-105
lines changed

17 files changed

+31
-105
lines changed

.github/workflows/build.yml

Lines changed: 0 additions & 7 deletions
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,13 +194,11 @@ 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
209202
cargo check --no-default-features --features=futures,std --release
210203
cargo doc --release
211204
env:

README.md

Lines changed: 1 addition & 1 deletion
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

Lines changed: 0 additions & 3 deletions
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

Lines changed: 0 additions & 3 deletions
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/ci-tests.sh

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -100,38 +100,36 @@ grep '^max_level_' lightning/Cargo.toml | awk '{ print $1 }'| while read -r FEAT
100100
RUSTFLAGS="$RUSTFLAGS -A unused_variables -A unused_macros -A unused_imports -A dead_code" cargo check -p lightning --verbose --color always --features "$FEATURE"
101101
done
102102

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

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
108+
cargo test -p lightning --verbose --color always --no-default-features
111109

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

117115
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
116+
# check if there is a conflict between no_std and the c_bindings cfg
119117
RUSTFLAGS="$RUSTFLAGS --cfg=c_bindings" cargo test -p $DIR --verbose --color always --no-default-features
120118
done
121119

122120
# Note that because `$RUSTFLAGS` is not passed through to doctest builds we cannot selectively
123121
# disable doctests in `c_bindings` so we skip doctests entirely here.
124122
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
123+
RUSTFLAGS="$RUSTFLAGS --cfg=c_bindings" cargo test -p lightning --verbose --color always --no-default-features --lib --bins --tests
126124

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

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

fuzz/Cargo.toml

Lines changed: 1 addition & 1 deletion
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-rapid-gossip-sync/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,8 @@
5454
//! let network_graph = NetworkGraph::new(Network::Bitcoin, &logger);
5555
//! let rapid_sync = RapidGossipSync::new(&network_graph, &logger);
5656
//! 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
57+
//! // In non-`std` environments you need to provide the current time in unix epoch seconds
58+
//! // otherwise you can use `update_network_graph`
5959
//! let current_time_unix = 0;
6060
//! let new_last_sync_timestamp_result = rapid_sync.update_network_graph_no_std(snapshot_contents, Some(current_time_unix));
6161
//! ```

lightning/Cargo.toml

Lines changed: 3 additions & 4 deletions
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/lib.rs

Lines changed: 0 additions & 4 deletions
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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5920,7 +5920,7 @@ where
59205920
/// * Forgetting about stale outbound payments, either those that have already been fulfilled
59215921
/// or those awaiting an invoice that hasn't been delivered in the necessary amount of time.
59225922
/// The latter is determined using the system clock in `std` and the highest seen block time
5923-
/// minus two hours in `no-std`.
5923+
/// minus two hours in non-`std`.
59245924
///
59255925
/// Note that this may cause reentrancy through [`chain::Watch::update_channel`] calls or feerate
59265926
/// estimate fetches.
@@ -8942,7 +8942,7 @@ macro_rules! create_refund_builder { ($self: ident, $builder: ty) => {
89428942
/// See [Avoiding Duplicate Payments] for other requirements once the payment has been sent.
89438943
///
89448944
/// The builder will have the provided expiration set. Any changes to the expiration on the
8945-
/// returned builder will not be honored by [`ChannelManager`]. For `no-std`, the highest seen
8945+
/// returned builder will not be honored by [`ChannelManager`]. For non-`std`, the highest seen
89468946
/// block time minus two hours is used for the current time when determining if the refund has
89478947
/// expired.
89488948
///

lightning/src/offers/invoice_request.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -719,7 +719,7 @@ macro_rules! invoice_request_respond_with_explicit_signing_pubkey_methods { (
719719
/// Creates an [`InvoiceBuilder`] for the request with the given required fields.
720720
///
721721
/// Unless [`InvoiceBuilder::relative_expiry`] is set, the invoice will expire two hours after
722-
/// `created_at`, which is used to set [`Bolt12Invoice::created_at`]. Useful for `no-std` builds
722+
/// `created_at`, which is used to set [`Bolt12Invoice::created_at`]. Useful for non-`std` builds
723723
/// where [`std::time::SystemTime`] is not available.
724724
///
725725
/// The caller is expected to remember the preimage of `payment_hash` in order to claim a payment

lightning/src/offers/refund.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -545,7 +545,7 @@ macro_rules! respond_with_explicit_signing_pubkey_methods { ($self: ident, $buil
545545
/// Creates an [`InvoiceBuilder`] for the refund with the given required fields.
546546
///
547547
/// Unless [`InvoiceBuilder::relative_expiry`] is set, the invoice will expire two hours after
548-
/// `created_at`, which is used to set [`Bolt12Invoice::created_at`]. Useful for `no-std` builds
548+
/// `created_at`, which is used to set [`Bolt12Invoice::created_at`]. Useful for non-`std` builds
549549
/// where [`std::time::SystemTime`] is not available.
550550
///
551551
/// The caller is expected to remember the preimage of `payment_hash` in order to

lightning/src/routing/gossip.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ pub struct NetworkGraph<L: Deref> where L::Target: Logger {
183183
//
184184
// NOTE: In the following `removed_*` maps, we use seconds since UNIX epoch to track time instead
185185
// of `std::time::Instant`s for a few reasons:
186-
// * We want it to be possible to do tracking in no-std environments where we can compare
186+
// * We want it to be possible to do tracking in non-`std` environments where we can compare
187187
// a provided current UNIX timestamp with the time at which we started tracking.
188188
// * In the future, if we decide to persist these maps, they will already be serializable.
189189
// * Although we lose out on the platform's monotonic clock, the system clock in a std
@@ -612,7 +612,7 @@ where U::Target: UtxoLookup, L::Target: Logger
612612
// our peers and never receiving gossip from peers at all, we send all of our peers a
613613
// `gossip_timestamp_filter`, with the filter time set either two weeks ago or an hour ago.
614614
//
615-
// For no-std builds, we bury our head in the sand and do a full sync on each connection.
615+
// For non-`std` builds, we bury our head in the sand and do a full sync on each connection.
616616
#[allow(unused_mut, unused_assignments)]
617617
let mut gossip_start_time = 0;
618618
#[allow(unused)]
@@ -934,7 +934,7 @@ pub struct ChannelInfo {
934934
/// Not stored if contains excess data to prevent DoS.
935935
pub announcement_message: Option<ChannelAnnouncement>,
936936
/// The timestamp when we received the announcement, if we are running with feature = "std"
937-
/// (which we can probably assume we are - no-std environments probably won't have a full
937+
/// (which we can probably assume we are - non-`std` environments probably won't have a full
938938
/// network graph in memory!).
939939
announcement_received_time: u64,
940940
}
@@ -2105,7 +2105,7 @@ impl<L: Deref> NetworkGraph<L> where L::Target: Logger {
21052105
/// in the map for a while so that these can be resynced from gossip in the future.
21062106
///
21072107
/// This method is only available with the `std` feature. See
2108-
/// [`NetworkGraph::remove_stale_channels_and_tracking_with_time`] for `no-std` use.
2108+
/// [`NetworkGraph::remove_stale_channels_and_tracking_with_time`] for non-`std` use.
21092109
pub fn remove_stale_channels_and_tracking(&self) {
21102110
let time = SystemTime::now().duration_since(UNIX_EPOCH).expect("Time must be > 1970").as_secs();
21112111
self.remove_stale_channels_and_tracking_with_time(time);
@@ -2169,7 +2169,7 @@ impl<L: Deref> NetworkGraph<L> where L::Target: Logger {
21692169
if let Some(time) = time {
21702170
current_time_unix.saturating_sub(*time) < REMOVED_ENTRIES_TRACKING_AGE_LIMIT_SECS
21712171
} else {
2172-
// NOTE: In the case of no-std, we won't have access to the current UNIX time at the time of removal,
2172+
// NOTE: In the case of non-`std`, we won't have access to the current UNIX time at the time of removal,
21732173
// so we'll just set the removal time here to the current UNIX time on the very next invocation
21742174
// of this function.
21752175
#[cfg(not(feature = "std"))]
@@ -2193,7 +2193,7 @@ impl<L: Deref> NetworkGraph<L> where L::Target: Logger {
21932193
/// [`RoutingMessageHandler`] implementation to call it indirectly. This may be useful to accept
21942194
/// routing messages from a source using a protocol other than the lightning P2P protocol.
21952195
///
2196-
/// If built with `no-std`, any updates with a timestamp more than two weeks in the past or
2196+
/// If not built with `std`, any updates with a timestamp more than two weeks in the past or
21972197
/// materially in the future will be rejected.
21982198
pub fn update_channel(&self, msg: &msgs::ChannelUpdate) -> Result<(), LightningError> {
21992199
self.update_channel_internal(&msg.contents, Some(&msg), Some(&msg.signature), false)
@@ -2203,7 +2203,7 @@ impl<L: Deref> NetworkGraph<L> where L::Target: Logger {
22032203
/// of the channel without verifying the associated signatures. Because we aren't given the
22042204
/// associated signatures here we cannot relay the channel update to any of our peers.
22052205
///
2206-
/// If built with `no-std`, any updates with a timestamp more than two weeks in the past or
2206+
/// If not built with `std`, any updates with a timestamp more than two weeks in the past or
22072207
/// materially in the future will be rejected.
22082208
pub fn update_channel_unsigned(&self, msg: &msgs::UnsignedChannelUpdate) -> Result<(), LightningError> {
22092209
self.update_channel_internal(msg, None, None, false)
@@ -2213,7 +2213,7 @@ impl<L: Deref> NetworkGraph<L> where L::Target: Logger {
22132213
///
22142214
/// This checks whether the update currently is applicable by [`Self::update_channel`].
22152215
///
2216-
/// If built with `no-std`, any updates with a timestamp more than two weeks in the past or
2216+
/// If not built with `std`, any updates with a timestamp more than two weeks in the past or
22172217
/// materially in the future will be rejected.
22182218
pub fn verify_channel_update(&self, msg: &msgs::ChannelUpdate) -> Result<(), LightningError> {
22192219
self.update_channel_internal(&msg.contents, Some(&msg), Some(&msg.signature), true)

lightning/src/routing/scoring.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -749,7 +749,7 @@ pub struct ProbabilisticScoringDecayParameters {
749749
///
750750
/// # Note
751751
///
752-
/// When built with the `no-std` feature, time will never elapse. Therefore, the channel
752+
/// When not built with the `std` feature, time will never elapse. Therefore, the channel
753753
/// liquidity knowledge will never decay except when the bounds cross.
754754
pub liquidity_offset_half_life: Duration,
755755
}

lightning/src/util/hash_tables.rs

Lines changed: 3 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -1,67 +1,13 @@
1-
//! Generally LDK uses `std`'s `HashMap`s, however when building for no-std, LDK uses `hashbrown`'s
2-
//! `HashMap`s with the `std` `SipHasher` and uses `getrandom` to opportunistically randomize it,
3-
//! if randomization is available.
1+
//! Generally LDK uses `hashbrown`'s `HashMap`s with the `std` `SipHasher` and uses `getrandom` to
2+
//! opportunistically randomize it, if randomization is available.
43
//!
54
//! This module simply re-exports the `HashMap` used in LDK for public consumption.
65
7-
#[cfg(feature = "hashbrown")]
86
extern crate hashbrown;
9-
#[cfg(feature = "possiblyrandom")]
107
extern crate possiblyrandom;
118

12-
// For no-std builds, we need to use hashbrown, however, by default, it doesn't randomize the
13-
// hashing and is vulnerable to HashDoS attacks. Thus, we use the core SipHasher when not using
14-
// std, but use `getrandom` to randomize it if its available.
15-
16-
#[cfg(not(feature = "hashbrown"))]
17-
mod std_hashtables {
18-
pub use std::collections::hash_map::RandomState;
19-
pub use std::collections::HashMap;
20-
21-
pub(crate) use std::collections::{hash_map, HashSet};
22-
23-
pub(crate) type OccupiedHashMapEntry<'a, K, V> =
24-
std::collections::hash_map::OccupiedEntry<'a, K, V>;
25-
pub(crate) type VacantHashMapEntry<'a, K, V> =
26-
std::collections::hash_map::VacantEntry<'a, K, V>;
27-
28-
/// Builds a new [`HashMap`].
29-
pub fn new_hash_map<K, V>() -> HashMap<K, V> {
30-
HashMap::new()
31-
}
32-
/// Builds a new [`HashMap`] with the given capacity.
33-
pub fn hash_map_with_capacity<K, V>(cap: usize) -> HashMap<K, V> {
34-
HashMap::with_capacity(cap)
35-
}
36-
pub(crate) fn hash_map_from_iter<
37-
K: core::hash::Hash + Eq,
38-
V,
39-
I: IntoIterator<Item = (K, V)>,
40-
>(
41-
iter: I,
42-
) -> HashMap<K, V> {
43-
HashMap::from_iter(iter)
44-
}
45-
46-
pub(crate) fn new_hash_set<K>() -> HashSet<K> {
47-
HashSet::new()
48-
}
49-
pub(crate) fn hash_set_with_capacity<K>(cap: usize) -> HashSet<K> {
50-
HashSet::with_capacity(cap)
51-
}
52-
pub(crate) fn hash_set_from_iter<K: core::hash::Hash + Eq, I: IntoIterator<Item = K>>(
53-
iter: I,
54-
) -> HashSet<K> {
55-
HashSet::from_iter(iter)
56-
}
57-
}
58-
#[cfg(not(feature = "hashbrown"))]
59-
pub use std_hashtables::*;
60-
61-
#[cfg(feature = "hashbrown")]
629
pub(crate) use self::hashbrown::hash_map;
6310

64-
#[cfg(feature = "hashbrown")]
6511
mod hashbrown_tables {
6612
#[cfg(feature = "std")]
6713
mod hasher {
@@ -170,5 +116,5 @@ mod hashbrown_tables {
170116
res
171117
}
172118
}
173-
#[cfg(feature = "hashbrown")]
119+
174120
pub use hashbrown_tables::*;

lightning/src/util/test_utils.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1053,7 +1053,7 @@ impl msgs::RoutingMessageHandler for TestRoutingMessageHandler {
10531053

10541054
#[allow(unused_mut, unused_assignments)]
10551055
let mut gossip_start_time = 0;
1056-
#[cfg(not(feature = "no-std"))]
1056+
#[cfg(feature = "std")]
10571057
{
10581058
use std::time::{SystemTime, UNIX_EPOCH};
10591059
gossip_start_time = SystemTime::now().duration_since(UNIX_EPOCH).expect("Time must be > 1970").as_secs();

no-std-check/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ version = "0.1.0"
44
edition = "2021"
55

66
[features]
7-
default = ["lightning/no-std"]
7+
default = []
88

99
[dependencies]
1010
lightning = { path = "../lightning", default-features = false }

0 commit comments

Comments
 (0)