fuzz: simplify get_payment_secret_hash return type
What changed, and why it matters
This is a small code cleanup inside a fuzz testing harness. It removes an unnecessary retry loop and changes a helper function to return a plain value instead of an optional value. It does not change production Lightning code, user-facing behavior, or security-sensitive logic.
No security action required. Treat as normal refactoring of test code.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The commit refactors get_payment_secret_hash in fuzz/src/chanmon_consistency.rs. Previously the function returned Option<(PaymentSecret, PaymentHash)> and looped up to 256 times because create_inbound_payment_for_hash could fail on duplicate payment hashes. The new version increments a counter, computes a fresh payment hash, and calls create_inbound_payment_for_hash with min_value_msat=None and min_final_cltv_expiry=None, which the commit message states cannot fail. The Option return type and retry loop are removed, and callers are simplified. This is a test-only change in fuzzing infrastructure.
Changed components
fuzz/src/chanmon_consistency.rsInspect captured patch +9 / −26
diff --git a/fuzz/src/chanmon_consistency.rs b/fuzz/src/chanmon_consistency.rs
index e5783b3..d3d38a9 100644
--- a/fuzz/src/chanmon_consistency.rs
+++ b/fuzz/src/chanmon_consistency.rs
@@ -538,20 +538,13 @@ type ChanMan<'a> = ChannelManager<
>;
#[inline]
-fn get_payment_secret_hash(
- dest: &ChanMan, payment_ctr: &mut u64,
-) -> Option<(PaymentSecret, PaymentHash)> {
- let mut payment_hash;
- for _ in 0..256 {
- *payment_ctr += 1;
- payment_hash = PaymentHash(Sha256::hash(&[*payment_ctr as u8]).to_byte_array());
- if let Ok(payment_secret) =
- dest.create_inbound_payment_for_hash(payment_hash, None, 3600, None)
- {
- return Some((payment_secret, payment_hash));
- }
- }
- None
+fn get_payment_secret_hash(dest: &ChanMan, payment_ctr: &mut u64) -> (PaymentSecret, PaymentHash) {
+ *payment_ctr += 1;
+ let payment_hash = PaymentHash(Sha256::hash(&[*payment_ctr as u8]).to_byte_array());
+ let payment_secret = dest
+ .create_inbound_payment_for_hash(payment_hash, None, 3600, None)
+ .expect("create_inbound_payment_for_hash failed");
+ (payment_secret, payment_hash)
}
#[inline]
@@ -565,12 +558,7 @@ fn send_noret(
fn send_payment(
source: &ChanMan, dest: &ChanMan, dest_chan_id: u64, amt: u64, payment_ctr: &mut u64,
) -> bool {
- let (payment_secret, payment_hash) =
- if let Some((secret, hash)) = get_payment_secret_hash(dest, payment_ctr) {
- (secret, hash)
- } else {
- return true;
- };
+ let (payment_secret, payment_hash) = get_payment_secret_hash(dest, payment_ctr);
let mut payment_id = [0; 32];
payment_id[0..8].copy_from_slice(&payment_ctr.to_ne_bytes());
let (min_value_sendable, max_value_sendable) = source
@@ -627,12 +615,7 @@ fn send_hop_payment(
source: &ChanMan, middle: &ChanMan, middle_chan_id: u64, dest: &ChanMan, dest_chan_id: u64,
amt: u64, payment_ctr: &mut u64,
) -> bool {
- let (payment_secret, payment_hash) =
- if let Some((secret, hash)) = get_payment_secret_hash(dest, payment_ctr) {
- (secret, hash)
- } else {
- return true;
- };
+ let (payment_secret, payment_hash) = get_payment_secret_hash(dest, payment_ctr);
let mut payment_id = [0; 32];
payment_id[0..8].copy_from_slice(&payment_ctr.to_ne_bytes());
let (min_value_sendable, max_value_sendable) = source
Why this scored 15/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.