Skip to content

Commit 6c036fa

Browse files
Set htlc_maximum_msat in BlindedPayInfo on blinded path construction
1 parent 52fb048 commit 6c036fa

File tree

2 files changed

+18
-8
lines changed

2 files changed

+18
-8
lines changed

lightning/src/blinded_path/mod.rs

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

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

lightning/src/blinded_path/payment.rs

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ fn amt_to_forward_msat(inbound_amt_msat: u64, payment_relay: &PaymentRelay) -> O
178178
}
179179

180180
pub(super) fn compute_payinfo(
181-
intermediate_nodes: &[(PublicKey, ForwardTlvs)], payee_tlvs: &ReceiveTlvs
181+
intermediate_nodes: &[(PublicKey, ForwardTlvs)], payee_tlvs: &ReceiveTlvs, htlc_maximum_msat: u64
182182
) -> Result<BlindedPayInfo, ()> {
183183
let mut curr_base_fee: u64 = 0;
184184
let mut curr_prop_mil: u64 = 0;
@@ -220,12 +220,13 @@ pub(super) fn compute_payinfo(
220220
payee_tlvs.payment_constraints.htlc_minimum_msat, htlc_minimum_msat
221221
);
222222

223+
if htlc_maximum_msat < htlc_minimum_msat { return Err(()) }
223224
Ok(BlindedPayInfo {
224225
fee_base_msat: u32::try_from(curr_base_fee).map_err(|_| ())?,
225226
fee_proportional_millionths: u32::try_from(curr_prop_mil).map_err(|_| ())?,
226227
cltv_expiry_delta,
227228
htlc_minimum_msat,
228-
htlc_maximum_msat: 21_000_000 * 100_000_000 * 1_000, // TODO
229+
htlc_maximum_msat,
229230
features: BlindedHopFeatures::empty(),
230231
})
231232
}
@@ -285,11 +286,13 @@ mod tests {
285286
htlc_minimum_msat: 1,
286287
},
287288
};
288-
let blinded_payinfo = super::compute_payinfo(&intermediate_nodes[..], &recv_tlvs).unwrap();
289+
let htlc_maximum_msat = 100_000;
290+
let blinded_payinfo = super::compute_payinfo(&intermediate_nodes[..], &recv_tlvs, htlc_maximum_msat).unwrap();
289291
assert_eq!(blinded_payinfo.fee_base_msat, 201);
290292
assert_eq!(blinded_payinfo.fee_proportional_millionths, 1001);
291293
assert_eq!(blinded_payinfo.cltv_expiry_delta, 288);
292294
assert_eq!(blinded_payinfo.htlc_minimum_msat, 900);
295+
assert_eq!(blinded_payinfo.htlc_maximum_msat, htlc_maximum_msat);
293296
}
294297

295298
#[test]
@@ -301,11 +304,12 @@ mod tests {
301304
htlc_minimum_msat: 1,
302305
},
303306
};
304-
let blinded_payinfo = super::compute_payinfo(&[], &recv_tlvs).unwrap();
307+
let blinded_payinfo = super::compute_payinfo(&[], &recv_tlvs, 4242).unwrap();
305308
assert_eq!(blinded_payinfo.fee_base_msat, 0);
306309
assert_eq!(blinded_payinfo.fee_proportional_millionths, 0);
307310
assert_eq!(blinded_payinfo.cltv_expiry_delta, 0);
308311
assert_eq!(blinded_payinfo.htlc_minimum_msat, 1);
312+
assert_eq!(blinded_payinfo.htlc_maximum_msat, 4242);
309313
}
310314

311315
#[test]
@@ -345,7 +349,8 @@ mod tests {
345349
htlc_minimum_msat: 3,
346350
},
347351
};
348-
let blinded_payinfo = super::compute_payinfo(&intermediate_nodes[..], &recv_tlvs).unwrap();
352+
let htlc_maximum_msat = 100_000;
353+
let blinded_payinfo = super::compute_payinfo(&intermediate_nodes[..], &recv_tlvs, htlc_maximum_msat).unwrap();
349354
assert_eq!(blinded_payinfo.htlc_minimum_msat, 2_000);
350355
}
351356

@@ -387,7 +392,11 @@ mod tests {
387392
},
388393
};
389394
let htlc_minimum_msat = 3798;
390-
let blinded_payinfo = super::compute_payinfo(&intermediate_nodes[..], &recv_tlvs).unwrap();
395+
assert!(super::compute_payinfo(&intermediate_nodes[..], &recv_tlvs, htlc_minimum_msat - 1).is_err());
396+
397+
let htlc_maximum_msat = htlc_minimum_msat + 1;
398+
let blinded_payinfo = super::compute_payinfo(&intermediate_nodes[..], &recv_tlvs, htlc_maximum_msat).unwrap();
391399
assert_eq!(blinded_payinfo.htlc_minimum_msat, htlc_minimum_msat);
400+
assert_eq!(blinded_payinfo.htlc_maximum_msat, htlc_maximum_msat);
392401
}
393402
}

0 commit comments

Comments
 (0)