Skip to content

Commit 9d481d1

Browse files
Set htlc_maximum_msat in BlindedPayInfo on route construction
1 parent dc4f471 commit 9d481d1

File tree

2 files changed

+14
-11
lines changed

2 files changed

+14
-11
lines changed

lightning/src/blinded_path/mod.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,8 @@ impl BlindedPath {
8989
/// * any unknown features are required in the provided [`BlindedPaymentTlvs`]
9090
// TODO: make all payloads the same size with padding + add dummy hops
9191
pub fn new_for_payment<ES: EntropySource, T: secp256k1::Signing + secp256k1::Verification>(
92-
path: &[(PublicKey, BlindedPaymentTlvs)], entropy_source: &ES, secp_ctx: &Secp256k1<T>
92+
path: &[(PublicKey, BlindedPaymentTlvs)], htlc_maximum_msat: u64, entropy_source: &ES,
93+
secp_ctx: &Secp256k1<T>
9394
) -> Result<(BlindedPayInfo, Self), ()> {
9495
if path.len() < 1 { return Err(()) }
9596
let mut found_recv_payload = false;
@@ -104,7 +105,7 @@ impl BlindedPath {
104105
let blinding_secret_bytes = entropy_source.get_secure_random_bytes();
105106
let blinding_secret = SecretKey::from_slice(&blinding_secret_bytes[..]).expect("RNG is busted");
106107

107-
let blinded_payinfo = payment::compute_payinfo(path)?;
108+
let blinded_payinfo = payment::compute_payinfo(path, htlc_maximum_msat)?;
108109
Ok((blinded_payinfo, BlindedPath {
109110
introduction_node_id: path[0].0,
110111
blinding_point: PublicKey::from_secret_key(secp_ctx, &blinding_secret),

lightning/src/blinded_path/payment.rs

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ pub(super) fn blinded_hops<T: secp256k1::Signing + secp256k1::Verification>(
168168
}
169169

170170
pub(super) fn compute_payinfo(
171-
path: &[(PublicKey, BlindedPaymentTlvs)]
171+
path: &[(PublicKey, BlindedPaymentTlvs)], htlc_maximum_msat: u64,
172172
) -> Result<BlindedPayInfo, ()> {
173173
let mut curr_base_fee: u32 = 0;
174174
let mut curr_prop_mil: u32 = 0;
@@ -195,14 +195,15 @@ pub(super) fn compute_payinfo(
195195
.map(|f| f / 1_000_000)
196196
.ok_or(())?;
197197
}
198+
let htlc_minimum_msat = path.iter().map(|(_, tlvs)| tlvs.htlc_minimum_msat()).max().unwrap_or(0);
199+
if htlc_maximum_msat < htlc_minimum_msat { return Err(()) }
198200
Ok(BlindedPayInfo {
199201
fee_base_msat: curr_base_fee,
200202
fee_proportional_millionths: curr_prop_mil,
201203
cltv_expiry_delta: path.iter().map(|(_, tlvs)| tlvs.cltv_expiry_delta())
202204
.try_fold(0u16, |acc, delta| acc.checked_add(delta)).ok_or(())?,
203-
htlc_minimum_msat: path.iter().map(|(_, tlvs)| tlvs.htlc_minimum_msat()).max().unwrap_or(0),
204-
// TODO: this field isn't present in route blinding encrypted data
205-
htlc_maximum_msat: 21_000_000 * 100_000_000 * 1_000, // Total bitcoin supply
205+
htlc_minimum_msat,
206+
htlc_maximum_msat,
206207
features: BlindedHopFeatures::empty(),
207208
})
208209
}
@@ -264,11 +265,12 @@ mod tests {
264265
htlc_minimum_msat: 1,
265266
},
266267
})];
267-
let blinded_payinfo = super::compute_payinfo(&path[..]).unwrap();
268+
let blinded_payinfo = super::compute_payinfo(&path[..], 4242).unwrap();
268269
assert_eq!(blinded_payinfo.fee_base_msat, 201);
269270
assert_eq!(blinded_payinfo.fee_proportional_millionths, 1001);
270271
assert_eq!(blinded_payinfo.cltv_expiry_delta, 288);
271272
assert_eq!(blinded_payinfo.htlc_minimum_msat, 1_000);
273+
assert_eq!(blinded_payinfo.htlc_maximum_msat, 4242);
272274
}
273275

274276
#[test]
@@ -281,7 +283,7 @@ mod tests {
281283
htlc_minimum_msat: 1,
282284
},
283285
})];
284-
let blinded_payinfo = super::compute_payinfo(&path[..]).unwrap();
286+
let blinded_payinfo = super::compute_payinfo(&path[..], 42).unwrap();
285287
assert_eq!(blinded_payinfo.fee_base_msat, 0);
286288
assert_eq!(blinded_payinfo.fee_proportional_millionths, 0);
287289
assert_eq!(blinded_payinfo.cltv_expiry_delta, 0);
@@ -313,7 +315,7 @@ mod tests {
313315
},
314316
features: BlindedHopFeatures::empty(),
315317
})];
316-
assert!(BlindedPath::new_for_payment(&out_of_order_payloads_path[..], &keys_manager, &secp_ctx).is_err());
318+
assert!(BlindedPath::new_for_payment(&out_of_order_payloads_path[..], 1_000_000, &keys_manager, &secp_ctx).is_err());
317319

318320
let multiple_recv_payloads_path = vec![(dummy_pk, BlindedPaymentTlvs::Receive {
319321
payment_secret: PaymentSecret([0; 32]),
@@ -328,7 +330,7 @@ mod tests {
328330
htlc_minimum_msat: 1,
329331
},
330332
})];
331-
assert!(BlindedPath::new_for_payment(&multiple_recv_payloads_path[..], &keys_manager, &secp_ctx).is_err());
333+
assert!(BlindedPath::new_for_payment(&multiple_recv_payloads_path[..], 1_000_000, &keys_manager, &secp_ctx).is_err());
332334

333335
let missing_recv_payload_path = vec![(dummy_pk, BlindedPaymentTlvs::Forward {
334336
short_channel_id: 0,
@@ -343,6 +345,6 @@ mod tests {
343345
},
344346
features: BlindedHopFeatures::empty(),
345347
})];
346-
assert!(BlindedPath::new_for_payment(&missing_recv_payload_path[..], &keys_manager, &secp_ctx).is_err());
348+
assert!(BlindedPath::new_for_payment(&missing_recv_payload_path[..], 1_000_000, &keys_manager, &secp_ctx).is_err());
347349
}
348350
}

0 commit comments

Comments
 (0)