Skip to content

Commit 0b09ee8

Browse files
committed
Use hashbrown replacements for std equivalents
1 parent 4d1c1a3 commit 0b09ee8

17 files changed

+38
-19
lines changed

Diff for: .github/workflows/build.yml

+20-2
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,13 @@ jobs:
4747
run: RUSTFLAGS="-C link-dead-code" cargo build --verbose --color always
4848
- name: Build on Rust ${{ matrix.toolchain }}
4949
if: "! matrix.build-net-tokio"
50-
run: cargo build --verbose --color always -p lightning && cargo build --verbose --color always -p lightning-invoice && cargo build --verbose --color always -p lightning-persister
50+
run: |
51+
cargo build --verbose --color always -p lightning
52+
cargo build --verbose --color always -p lightning-invoice
53+
cargo build --verbose --color always -p lightning-persister
54+
cd lightning
55+
cargo build --verbose --color always --features hashbrown
56+
cd ..
5157
- name: Build Block Sync Clients on Rust ${{ matrix.toolchain }} with features
5258
if: "matrix.build-net-tokio && !matrix.coverage"
5359
run: |
@@ -56,6 +62,8 @@ jobs:
5662
cargo build --verbose --color always --features rpc-client
5763
cargo build --verbose --color always --features rpc-client,rest-client
5864
cargo build --verbose --color always --features rpc-client,rest-client,tokio
65+
cd ../lightning
66+
cargo build --verbose --color always --features hashbrown
5967
cd ..
6068
- name: Build Block Sync Clients on Rust ${{ matrix.toolchain }} with features and full code-linking for coverage generation
6169
if: matrix.coverage
@@ -65,13 +73,21 @@ jobs:
6573
RUSTFLAGS="-C link-dead-code" cargo build --verbose --color always --features rpc-client
6674
RUSTFLAGS="-C link-dead-code" cargo build --verbose --color always --features rpc-client,rest-client
6775
RUSTFLAGS="-C link-dead-code" cargo build --verbose --color always --features rpc-client,rest-client,tokio
76+
cd ../lightning
77+
RUSTFLAGS="-C link-dead-code" cargo build --verbose --color always --features hashbrown
6878
cd ..
6979
- name: Test on Rust ${{ matrix.toolchain }} with net-tokio
7080
if: "matrix.build-net-tokio && !matrix.coverage"
7181
run: cargo test --verbose --color always
7282
- name: Test on Rust ${{ matrix.toolchain }} with net-tokio and full code-linking for coverage generation
7383
if: matrix.coverage
7484
run: RUSTFLAGS="-C link-dead-code" cargo test --verbose --color always
85+
- name: Test on no_std bullds Rust ${{ matrix.toolchain }}
86+
if: "matrix.build-net-tokio && matrix.toolchain != 1.36.0 && matrix.toolchain != 1.41.0 && matrix.toolchain != 1.45.2"
87+
run: |
88+
cd lightning
89+
RUSTFLAGS="-C link-dead-code" cargo test --verbose --color always --features hashbrown
90+
cd ..
7591
- name: Test on Rust ${{ matrix.toolchain }}
7692
if: "! matrix.build-net-tokio"
7793
run: cargo test --verbose --color always -p lightning && cargo test --verbose --color always -p lightning-invoice && cargo build --verbose --color always -p lightning-persister
@@ -83,6 +99,8 @@ jobs:
8399
cargo test --verbose --color always --features rpc-client
84100
cargo test --verbose --color always --features rpc-client,rest-client
85101
cargo test --verbose --color always --features rpc-client,rest-client,tokio
102+
cd ../lightning
103+
cargo test --verbose --color always --features hashbrown
86104
cd ..
87105
- name: Test Block Sync Clients on Rust ${{ matrix.toolchain }} with features and full code-linking for coverage generation
88106
if: matrix.coverage
@@ -92,7 +110,6 @@ jobs:
92110
RUSTFLAGS="-C link-dead-code" cargo test --verbose --color always --features rpc-client
93111
RUSTFLAGS="-C link-dead-code" cargo test --verbose --color always --features rpc-client,rest-client
94112
RUSTFLAGS="-C link-dead-code" cargo test --verbose --color always --features rpc-client,rest-client,tokio
95-
cd ..
96113
- name: Install deps for kcov
97114
if: matrix.coverage
98115
run: |
@@ -157,6 +174,7 @@ jobs:
157174
run: |
158175
cd lightning
159176
RUSTFLAGS="--cfg=require_route_graph_test" cargo test
177+
RUSTFLAGS="--cfg=require_route_graph_test" cargo test --features hashbrown
160178
cd ..
161179
- name: Run benchmarks on Rust ${{ matrix.toolchain }}
162180
run: |

Diff for: ci/check-compiles.sh

+1
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@ cargo check
66
cargo doc
77
cargo doc --document-private-items
88
cd fuzz && cargo check --features=stdin_fuzz
9+
cd ../lightning && cargo check --no-default-features --features=no_std

Diff for: lightning/Cargo.toml

+2
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,12 @@ max_level_debug = []
2525
# This is unsafe to use in production because it may result in the counterparty publishing taking our funds.
2626
unsafe_revoked_tx_signing = []
2727
unstable = []
28+
no_std = ["hashbrown"]
2829

2930
[dependencies]
3031
bitcoin = "0.26"
3132

33+
hashbrown = { version = "0.11", optional = true }
3234
hex = { version = "0.3", optional = true }
3335
regex = { version = "0.1.80", optional = true }
3436

Diff for: lightning/src/chain/chainmonitor.rs

-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ use util::events;
3838
use util::events::EventHandler;
3939

4040
use prelude::*;
41-
use std::collections::{HashMap, hash_map};
4241
use std::sync::RwLock;
4342
use core::ops::Deref;
4443

Diff for: lightning/src/chain/channelmonitor.rs

-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@ use util::byte_utils;
5252
use util::events::Event;
5353

5454
use prelude::*;
55-
use std::collections::{HashMap, HashSet};
5655
use core::{cmp, mem};
5756
use std::io::Error;
5857
use core::ops::Deref;

Diff for: lightning/src/chain/keysinterface.rs

-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ use ln::chan_utils::{HTLCOutputInCommitment, make_funding_redeemscript, ChannelP
3838
use ln::msgs::UnsignedChannelAnnouncement;
3939

4040
use prelude::*;
41-
use std::collections::HashSet;
4241
use core::sync::atomic::{AtomicUsize, Ordering};
4342
use std::io::Error;
4443
use ln::msgs::{DecodeError, MAX_VALUE_MSAT};

Diff for: lightning/src/chain/onchaintx.rs

-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ use util::byte_utils;
3434

3535
use prelude::*;
3636
use alloc::collections::BTreeMap;
37-
use std::collections::HashMap;
3837
use core::cmp;
3938
use core::ops::Deref;
4039
use core::mem::replace;

Diff for: lightning/src/lib.rs

+9-2
Original file line numberDiff line numberDiff line change
@@ -44,5 +44,12 @@ pub mod ln;
4444
pub mod routing;
4545

4646
mod prelude {
47-
pub use alloc::{vec, vec::Vec, string::String};
48-
}
47+
#[cfg(feature = "hashbrown")]
48+
extern crate hashbrown;
49+
50+
pub use alloc::{vec, vec::Vec, string::String, collections::VecDeque};
51+
#[cfg(not(feature = "hashbrown"))]
52+
pub use std::collections::{HashMap, HashSet, hash_map};
53+
#[cfg(feature = "hashbrown")]
54+
pub use self::hashbrown::{HashMap, HashSet, hash_map};
55+
}

Diff for: lightning/src/ln/chanmon_update_fail_tests.rs

-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ use ln::functional_test_utils::*;
4141
use util::test_utils;
4242

4343
use prelude::*;
44-
use std::collections::HashMap;
4544
use std::sync::{Arc, Mutex};
4645

4746
// If persister_fail is true, we have the persister return a PermanentFailure

Diff for: lightning/src/ln/channelmanager.rs

-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,6 @@ use util::errors::APIError;
6464
use prelude::*;
6565
use core::{cmp, mem};
6666
use core::cell::RefCell;
67-
use std::collections::{HashMap, hash_map, HashSet};
6867
use std::io::{Cursor, Read};
6968
use std::sync::{Arc, Condvar, Mutex, MutexGuard, RwLock, RwLockReadGuard};
7069
use core::sync::atomic::{AtomicUsize, Ordering};

Diff for: lightning/src/ln/functional_test_utils.rs

-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ use core::cell::RefCell;
4444
use std::rc::Rc;
4545
use std::sync::{Arc, Mutex};
4646
use core::mem;
47-
use std::collections::HashMap;
4847

4948
pub const CHAN_CONFIRM_DEPTH: u32 = 10;
5049

Diff for: lightning/src/ln/functional_tests.rs

-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@ use regex;
5252

5353
use prelude::*;
5454
use alloc::collections::BTreeSet;
55-
use std::collections::{HashMap, HashSet};
5655
use core::default::Default;
5756
use std::sync::{Arc, Mutex};
5857

Diff for: lightning/src/ln/peer_handler.rs

-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ use routing::network_graph::NetGraphMsgHandler;
3232

3333
use prelude::*;
3434
use alloc::collections::LinkedList;
35-
use std::collections::{HashMap,hash_map,HashSet};
3635
use std::sync::{Arc, Mutex};
3736
use core::sync::atomic::{AtomicUsize, Ordering};
3837
use core::{cmp, hash, fmt, mem};

Diff for: lightning/src/ln/reorg_tests.rs

-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ use bitcoin::blockdata::block::{Block, BlockHeader};
2323
use bitcoin::hash_types::BlockHash;
2424

2525
use prelude::*;
26-
use std::collections::HashMap;
2726
use core::mem;
2827

2928
use ln::functional_test_utils::*;

Diff for: lightning/src/routing/router.rs

+6-3
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ use util::logger::Logger;
2424
use prelude::*;
2525
use alloc::collections::BinaryHeap;
2626
use core::cmp;
27-
use std::collections::HashMap;
2827
use core::ops::Deref;
2928

3029
/// A hop in a route
@@ -3843,16 +3842,19 @@ mod tests {
38433842
}
38443843
}
38453844

3845+
#[cfg(not(feature = "no_std"))]
38463846
pub(super) fn random_init_seed() -> u64 {
38473847
// Because the default HashMap in std pulls OS randomness, we can use it as a (bad) RNG.
38483848
use core::hash::{BuildHasher, Hasher};
38493849
let seed = std::collections::hash_map::RandomState::new().build_hasher().finish();
38503850
println!("Using seed of {}", seed);
38513851
seed
38523852
}
3853+
#[cfg(not(feature = "no_std"))]
38533854
use util::ser::Readable;
38543855

38553856
#[test]
3857+
#[cfg(not(feature = "no_std"))]
38563858
fn generate_routes() {
38573859
let mut d = match super::test_utils::get_route_file() {
38583860
Ok(f) => f,
@@ -3880,6 +3882,7 @@ mod tests {
38803882
}
38813883

38823884
#[test]
3885+
#[cfg(not(feature = "no_std"))]
38833886
fn generate_routes_mpp() {
38843887
let mut d = match super::test_utils::get_route_file() {
38853888
Ok(f) => f,
@@ -3907,7 +3910,7 @@ mod tests {
39073910
}
39083911
}
39093912

3910-
#[cfg(test)]
3913+
#[cfg(all(test, not(feature = "no_std")))]
39113914
pub(crate) mod test_utils {
39123915
use std::fs::File;
39133916
/// Tries to open a network graph file, or panics with a URL to fetch it.
@@ -3934,7 +3937,7 @@ pub(crate) mod test_utils {
39343937
}
39353938
}
39363939

3937-
#[cfg(all(test, feature = "unstable"))]
3940+
#[cfg(all(test, feature = "unstable", not(feature = "no_std")))]
39383941
mod benches {
39393942
use super::*;
39403943
use util::logger::{Logger, Record};

Diff for: lightning/src/util/ser.rs

-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
1313
use prelude::*;
1414
use std::io::{Read, Write};
15-
use std::collections::HashMap;
1615
use core::hash::Hash;
1716
use std::sync::Mutex;
1817
use core::cmp;

Diff for: lightning/src/util/test_utils.rs

-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ use core::time::Duration;
4242
use std::sync::{Mutex, Arc};
4343
use core::sync::atomic::{AtomicBool, AtomicUsize, Ordering};
4444
use core::{cmp, mem};
45-
use std::collections::{HashMap, HashSet, VecDeque};
4645
use chain::keysinterface::InMemorySigner;
4746

4847
pub struct TestVecWriter(pub Vec<u8>);

0 commit comments

Comments
 (0)