Skip to content

Commit 35b1dc8

Browse files
Set htlc_maximum_msat in BlindedPayInfo on blinded path construction
1 parent d3a508d commit 35b1dc8

File tree

2 files changed

+19
-9
lines changed

2 files changed

+19
-9
lines changed

lightning/src/blinded_path/mod.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,12 +89,13 @@ impl BlindedPath {
8989
// TODO: make all payloads the same size with padding + add dummy hops
9090
pub fn new_for_payment<ES: EntropySource, T: secp256k1::Signing + secp256k1::Verification>(
9191
intermediate_nodes: &[(PublicKey, payment::ForwardTlvs)], payee_node_id: PublicKey,
92-
payee_tlvs: payment::ReceiveTlvs, entropy_source: &ES, secp_ctx: &Secp256k1<T>
92+
payee_tlvs: payment::ReceiveTlvs, htlc_maximum_msat: u64, entropy_source: &ES,
93+
secp_ctx: &Secp256k1<T>
9394
) -> Result<(BlindedPayInfo, Self), ()> {
9495
let blinding_secret_bytes = entropy_source.get_secure_random_bytes();
9596
let blinding_secret = SecretKey::from_slice(&blinding_secret_bytes[..]).expect("RNG is busted");
9697

97-
let blinded_payinfo = payment::compute_payinfo(intermediate_nodes, &payee_tlvs)?;
98+
let blinded_payinfo = payment::compute_payinfo(intermediate_nodes, &payee_tlvs, htlc_maximum_msat)?;
9899
Ok((blinded_payinfo, BlindedPath {
99100
introduction_node_id: intermediate_nodes.first().map_or(payee_node_id, |n| n.0),
100101
blinding_point: PublicKey::from_secret_key(secp_ctx, &blinding_secret),

lightning/src/blinded_path/payment.rs

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ pub(super) fn blinded_hops<T: secp256k1::Signing + secp256k1::Verification>(
154154
}
155155

156156
pub(super) fn compute_payinfo(
157-
intermediate_nodes: &[(PublicKey, ForwardTlvs)], payee_tlvs: &ReceiveTlvs
157+
intermediate_nodes: &[(PublicKey, ForwardTlvs)], payee_tlvs: &ReceiveTlvs, htlc_maximum_msat: u64
158158
) -> Result<BlindedPayInfo, ()> {
159159
let mut curr_base_fee: u64 = 0;
160160
let mut curr_prop_mil: u64 = 0;
@@ -211,12 +211,13 @@ pub(super) fn compute_payinfo(
211211
htlc_minimum_msat =
212212
core::cmp::max(payee_tlvs.payment_constraints.htlc_minimum_msat as u128, htlc_minimum_msat);
213213

214+
if (htlc_maximum_msat as u128) < htlc_minimum_msat { return Err(()) }
214215
Ok(BlindedPayInfo {
215216
fee_base_msat: u32::try_from(curr_base_fee).map_err(|_| ())?,
216217
fee_proportional_millionths: u32::try_from(curr_prop_mil).map_err(|_| ())?,
217218
cltv_expiry_delta,
218219
htlc_minimum_msat: u64::try_from(htlc_minimum_msat).map_err(|_| ())?,
219-
htlc_maximum_msat: 21_000_000 * 100_000_000 * 1_000, // TODO
220+
htlc_maximum_msat,
220221
features: BlindedHopFeatures::empty(),
221222
})
222223
}
@@ -276,11 +277,13 @@ mod tests {
276277
htlc_minimum_msat: 1,
277278
},
278279
};
279-
let blinded_payinfo = super::compute_payinfo(&intermediate_nodes[..], &recv_tlvs).unwrap();
280+
let htlc_maximum_msat = 100_000;
281+
let blinded_payinfo = super::compute_payinfo(&intermediate_nodes[..], &recv_tlvs, htlc_maximum_msat).unwrap();
280282
assert_eq!(blinded_payinfo.fee_base_msat, 201);
281283
assert_eq!(blinded_payinfo.fee_proportional_millionths, 1001);
282284
assert_eq!(blinded_payinfo.cltv_expiry_delta, 288);
283285
assert_eq!(blinded_payinfo.htlc_minimum_msat, 900);
286+
assert_eq!(blinded_payinfo.htlc_maximum_msat, htlc_maximum_msat);
284287
}
285288

286289
#[test]
@@ -292,11 +295,12 @@ mod tests {
292295
htlc_minimum_msat: 1,
293296
},
294297
};
295-
let blinded_payinfo = super::compute_payinfo(&[], &recv_tlvs).unwrap();
298+
let blinded_payinfo = super::compute_payinfo(&[], &recv_tlvs, 4242).unwrap();
296299
assert_eq!(blinded_payinfo.fee_base_msat, 0);
297300
assert_eq!(blinded_payinfo.fee_proportional_millionths, 0);
298301
assert_eq!(blinded_payinfo.cltv_expiry_delta, 0);
299302
assert_eq!(blinded_payinfo.htlc_minimum_msat, 1);
303+
assert_eq!(blinded_payinfo.htlc_maximum_msat, 4242);
300304
}
301305

302306
#[test]
@@ -336,7 +340,8 @@ mod tests {
336340
htlc_minimum_msat: 3,
337341
},
338342
};
339-
let blinded_payinfo = super::compute_payinfo(&intermediate_nodes[..], &recv_tlvs).unwrap();
343+
let htlc_maximum_msat = 100_000;
344+
let blinded_payinfo = super::compute_payinfo(&intermediate_nodes[..], &recv_tlvs, htlc_maximum_msat).unwrap();
340345
assert_eq!(blinded_payinfo.htlc_minimum_msat, 2_000);
341346
}
342347

@@ -377,8 +382,12 @@ mod tests {
377382
htlc_minimum_msat: 1,
378383
},
379384
};
385+
let htlc_minimum_msat = 3797;
386+
assert!(super::compute_payinfo(&intermediate_nodes[..], &recv_tlvs, htlc_minimum_msat - 1).is_err());
380387

381-
let blinded_payinfo = super::compute_payinfo(&intermediate_nodes[..], &recv_tlvs).unwrap();
382-
assert_eq!(blinded_payinfo.htlc_minimum_msat, 3797);
388+
let htlc_maximum_msat = htlc_minimum_msat + 1;
389+
let blinded_payinfo = super::compute_payinfo(&intermediate_nodes[..], &recv_tlvs, htlc_maximum_msat).unwrap();
390+
assert_eq!(blinded_payinfo.htlc_minimum_msat, htlc_minimum_msat);
391+
assert_eq!(blinded_payinfo.htlc_maximum_msat, htlc_maximum_msat);
383392
}
384393
}

0 commit comments

Comments
 (0)