Skip to content

Comments

Replace rand with getrandom and KeysManager entropy in non-test…#800

Open
TheBlueMatt wants to merge 1 commit intolightningdevkit:mainfrom
TheBlueMatt:2026-02-no-rand
Open

Replace rand with getrandom and KeysManager entropy in non-test…#800
TheBlueMatt wants to merge 1 commit intolightningdevkit:mainfrom
TheBlueMatt:2026-02-no-rand

Conversation

@TheBlueMatt
Copy link
Contributor

… code

rand is basically just a way to wrap getrandom with a chacha stream plus a bag of unrelated random utilities. Given we already have a way to wrap getrandom with a chacha stream, there's no point in relying on rand for it, so we simply drop it here.

Authored-By: Claude Opus 4.6 (1M context) noreply@anthropic.com

… code

`rand` is basically just a way to wrap `getrandom` with a chacha
stream plus a bag of unrelated random utilities. Given we already
have a way to wrap `getrandom` with a chacha stream, there's no
point in relying on `rand` for it, so we simply drop it here.

Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@ldk-reviews-bot
Copy link

👋 Hi! Please choose at least one reviewer by assigning them on the right bar.
If no reviewers are assigned within 10 minutes, I'll automatically assign one.
Once the first reviewer has submitted a review, a second will be assigned if required.

Copy link
Collaborator

@tnull tnull left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, so I'm not entirely convinced this change is worth the loss of convenience, as it won't allow us to drop rand/rand_core from our dependency tree anyways (as crates like bip39 etc are using it anyways).

So not sure if we gain much by restricting ourselves, and ofc. we risk messing something up?

@TheBlueMatt
Copy link
Contributor Author

IMO in the long-term we should move towards getrandom over rand, if only to reduce total code size given we already have a RNG expander in the form of the LDK EntropySource. We also want to remove it from rust-secp (rust-bitcoin/rust-secp256k1#881) and IMO should remove it from bip39 as well (there we probably don't need chacha - fetching randomness for root key generation shouldn't need to be stretched using chacha).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants