-
Notifications
You must be signed in to change notification settings - Fork 399
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
Use hashbrown replacements for std equivalents #947
Conversation
lightning/Cargo.toml
Outdated
@@ -29,6 +29,7 @@ unstable = [] | |||
[dependencies] | |||
bitcoin = "0.26" | |||
|
|||
hashbrown = { version = "0.9" } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Current hashbrown
is 0.11.2
, can bump to 0.11
, if MSRV 1.49
is OK
Can also feature-gate inside the prelude module, too.
Can we make this optional instead with a "hashbrown" feature (even an implicit one where you just make "hashbrown" an optional dependency)? Then we can make no-std depend on it. |
5c10136
to
d9ca4ea
Compare
Codecov Report
@@ Coverage Diff @@
## main #947 +/- ##
==========================================
+ Coverage 90.56% 90.58% +0.01%
==========================================
Files 60 60
Lines 30423 30423
==========================================
+ Hits 27553 27559 +6
+ Misses 2870 2864 -6
Continue to review full report at Codecov.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ACK other than nits
lightning/src/lib.rs
Outdated
#[cfg(feature = "no_std")] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should directly check for the hashbrown
feature. Ideally we'd be able to use hashbrown
with std
or no_std
, but require it for no_std
. Specifically, I'd like to use hashbrown
with std
in the fuzzers, as I can disable the default randomization of keys while fuzzing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hrm, I tried directly naming a hashbrown
feature, but I think it collides with the dependency name. Maybe I'm doing something wrong?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Huh, I thought if you don't even write out the feature and just make the dependency optional you can use it as a feature in cfg.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, maybe that's what I was doing wrong. I tried writing out hashbrown = ["hashbrown"]
as a feature. Will try what you described.
@@ -6,3 +6,4 @@ cargo check | |||
cargo doc | |||
cargo doc --document-private-items | |||
cd fuzz && cargo check --features=stdin_fuzz | |||
cd ../lightning && cargo check --no-default-features --features=no_std |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In .github/workflows/build.yml
can you also add a cd lightning && cargo test --verbose --color always --features hashbrown
to run the test suite with hashbrown + std?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Which builds should that run under, or do you want a new build target?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Uhhmmmmm, yes? I don't think it matters too much, maybe in the existing ones is simplest, given it's ~one line?
lightning/src/routing/router.rs
Outdated
pub(super) fn random_init_seed() -> u64 { | ||
// Because the default HashMap in std pulls OS randomness, we can use it as a (bad) RNG. | ||
use core::hash::{BuildHasher, Hasher}; | ||
let seed = std::collections::hash_map::RandomState::new().build_hasher().finish(); | ||
println!("Using seed of {}", seed); | ||
seed | ||
} | ||
#[cfg(not(feature = "no_std"))] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: indentation with tabs.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
agh! yeah, my editor defaults to indenting with spaces. Would you be open to adding a commit hook to automatically format?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If there's an easy way to just swap spaces for tabs, sure (I don't think there is, though?), but we've tried rustfmt a few times and it makes tons of code completely unreadable. It's desire to lay out all your code completely vertically means you lose a ton of context when reviewing more often than not. There's a few issues open upstream to make it more sensible, but I don't believe there's been much progress on any of them.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, I won't worry about it then. Thought there might be a simple fix.
75b8a14
to
9bac852
Compare
.github/workflows/build.yml
Outdated
@@ -56,6 +56,8 @@ jobs: | |||
cargo build --verbose --color always --features rpc-client | |||
cargo build --verbose --color always --features rpc-client,rest-client | |||
cargo build --verbose --color always --features rpc-client,rest-client,tokio | |||
cd ../lightning | |||
cargo build --verbose --color always --features hashbrown |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should also test with hashbrown
in the "! matrix.build-net-tokio" block immediately above this one.
.github/workflows/build.yml
Outdated
@@ -92,6 +98,8 @@ jobs: | |||
RUSTFLAGS="-C link-dead-code" cargo test --verbose --color always --features rpc-client | |||
RUSTFLAGS="-C link-dead-code" cargo test --verbose --color always --features rpc-client,rest-client | |||
RUSTFLAGS="-C link-dead-code" cargo test --verbose --color always --features rpc-client,rest-client,tokio | |||
cd ../lightning | |||
RUSTFLAGS="-C link-dead-code" cargo test --verbose --color always --features hashbrown |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I dunno if we want the last test we run in "matrix.coverage" (ie the binaries which we generate coverage reports from) to be hashbrown ones - maybe move this up above (or as the first command in) "Test on Rust ${{ matrix.toolchain }} with net-tokio and full code-linking for coverage generation"?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
SGTM, wasn't sure, so just added it after the other tests.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hrm, seems like this causes build failure:
error[E0658]: use of unstable library feature 'ptr_cast'
--> /home/runner/.cargo/registry/src/github.com-1ecc6299db9ec823/hashbrown-0.11.2/src/raw/mod.rs:504:57
|
504 | NonNull::new_unchecked(self.table.ctrl.as_ptr().cast())
| ^^^^
|
= note: for more information, see https://github.com/rust-lang/rust/issues/60602
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Might only make sense to use hashbrown
in later versions of Rust, per rust-lang/rust#60602
MSRV of hashbrown 0.11.2
is rust 1.49
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right, it needs to only run on non-1.36 versions of rust. Maybe add this:
- name: Test no_std builds Rust ${{ matrix.toolchain }}
if: "matrix.build-net-tokio"
run: cargo test --verbose --color always --features hashbrown
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
MSRV of hashbrown 0.11.2 is rust 1.49
Oh, I missed this comment, I guess we need the if there to just be something new that matches on stable instaed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Try:
diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml
index 231db705..2f14a4c2 100644
--- a/.github/workflows/build.yml
+++ b/.github/workflows/build.yml
@@ -14,18 +14,27 @@ jobs:
# 1.41.0 is Debian stable
1.41.0,
# 1.45.2 is MSRV for lightning-net-tokio, lightning-block-sync, and coverage generation
- 1.45.2]
+ 1.45.2,
+ # 1.49 is MSRV for no_std
+ 1.49.0]
include:
- toolchain: stable
build-net-tokio: true
+ build-no-std: true
- toolchain: stable
platform: macos-latest
build-net-tokio: true
+ build-no-std: true
- toolchain: stable
platform: windows-latest
build-net-tokio: true
+ build-no-std: true
- toolchain: beta
build-net-tokio: true
+ build-no-std: true
+ - toolchain: 1.45.2
+ build-net-tokio: true
+ build-no-std: true
- toolchain: 1.45.2
build-net-tokio: true
coverage: true
@@ -76,6 +85,9 @@ jobs:
cd ../lightning
RUSTFLAGS="-C link-dead-code" cargo build --verbose --color always --features hashbrown
cd ..
+ - name: Test no_std builds Rust ${{ matrix.toolchain }}
+ if: "matrix.build-no-std"
+ run: cargo test --verbose --color always --features hashbrown
- name: Test on Rust ${{ matrix.toolchain }} with net-tokio
if: "matrix.build-net-tokio && !matrix.coverage"
run: cargo test --verbose --color always
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added a check build-no-std
, and a 1.49.0
to the toolchain. It took a little experimentation, but I think I understand the CI build scripts better now.
The fuzz build seems to be failing for other reasons...
0b09ee8
to
e76a37f
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good, only diff since devrandom's ack at d9ca4ea are CI and comment addressing, fuzz test failure is due to a libsecp bump that exists on current HEAD anyway, so shouldn't hold this up.
No description provided.