Skip to content

Commit 9bac852

Browse files
committed
Use hashbrown replacements for std equivalents
1 parent a8038a8 commit 9bac852

17 files changed

+27
-17
lines changed

.github/workflows/build.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ jobs:
5656
cargo build --verbose --color always --features rpc-client
5757
cargo build --verbose --color always --features rpc-client,rest-client
5858
cargo build --verbose --color always --features rpc-client,rest-client,tokio
59+
cd ../lightning
60+
cargo build --verbose --color always --features hashbrown
5961
cd ..
6062
- name: Build Block Sync Clients on Rust ${{ matrix.toolchain }} with features and full code-linking for coverage generation
6163
if: matrix.coverage
@@ -65,6 +67,8 @@ jobs:
6567
RUSTFLAGS="-C link-dead-code" cargo build --verbose --color always --features rpc-client
6668
RUSTFLAGS="-C link-dead-code" cargo build --verbose --color always --features rpc-client,rest-client
6769
RUSTFLAGS="-C link-dead-code" cargo build --verbose --color always --features rpc-client,rest-client,tokio
70+
cd ../lightning
71+
RUSTFLAGS="-C link-dead-code" cargo build --verbose --color always --features hashbrown
6872
cd ..
6973
- name: Test on Rust ${{ matrix.toolchain }} with net-tokio
7074
if: "matrix.build-net-tokio && !matrix.coverage"
@@ -83,6 +87,8 @@ jobs:
8387
cargo test --verbose --color always --features rpc-client
8488
cargo test --verbose --color always --features rpc-client,rest-client
8589
cargo test --verbose --color always --features rpc-client,rest-client,tokio
90+
cd ../lightning
91+
cargo test --verbose --color always --features hashbrown
8692
cd ..
8793
- name: Test Block Sync Clients on Rust ${{ matrix.toolchain }} with features and full code-linking for coverage generation
8894
if: matrix.coverage
@@ -92,6 +98,8 @@ jobs:
9298
RUSTFLAGS="-C link-dead-code" cargo test --verbose --color always --features rpc-client
9399
RUSTFLAGS="-C link-dead-code" cargo test --verbose --color always --features rpc-client,rest-client
94100
RUSTFLAGS="-C link-dead-code" cargo test --verbose --color always --features rpc-client,rest-client,tokio
101+
cd ../lightning
102+
RUSTFLAGS="-C link-dead-code" cargo test --verbose --color always --features hashbrown
95103
cd ..
96104
- name: Install deps for kcov
97105
if: matrix.coverage
@@ -157,6 +165,7 @@ jobs:
157165
run: |
158166
cd lightning
159167
RUSTFLAGS="--cfg=require_route_graph_test" cargo test
168+
RUSTFLAGS="--cfg=require_route_graph_test" cargo test --features hashbrown
160169
cd ..
161170
- name: Run benchmarks on Rust ${{ matrix.toolchain }}
162171
run: |

ci/check-compiles.sh

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

lightning/Cargo.toml

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

lightning/src/chain/chainmonitor.rs

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

lightning/src/chain/channelmonitor.rs

Lines changed: 0 additions & 1 deletion
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;

lightning/src/chain/keysinterface.rs

Lines changed: 0 additions & 1 deletion
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};

lightning/src/chain/onchaintx.rs

Lines changed: 0 additions & 1 deletion
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;

lightning/src/lib.rs

Lines changed: 9 additions & 2 deletions
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+
}

lightning/src/ln/chanmon_update_fail_tests.rs

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

lightning/src/ln/channelmanager.rs

Lines changed: 0 additions & 1 deletion
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};

0 commit comments

Comments
 (0)