Skip to content

Commit 34f82ba

Browse files
f check for required features
1 parent 1bbf8b9 commit 34f82ba

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

lightning/src/blinded_path/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ impl BlindedPath {
8686
/// * [`BlindedPayInfo`] calculation results in an integer overflow
8787
/// * the list of [`BlindedPaymentTlvs`] does not consist of 0 or more
8888
/// `BlindedPaymentTlvs::Forward` followed by 1 `BlindedPaymentTlvs::Receive`
89+
/// * any unknown features are required in the provided [`BlindedPaymentTlvs`]
8990
// TODO: make all payloads the same size with padding + add dummy hops
9091
pub fn new_for_payment<ES: EntropySource, T: secp256k1::Signing + secp256k1::Verification>(
9192
path: &[(PublicKey, BlindedPaymentTlvs)], entropy_source: &ES, secp_ctx: &Secp256k1<T>

lightning/src/blinded_path/payment.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,12 @@ impl BlindedPaymentTlvs {
6868
payment_constraints.htlc_minimum_msat,
6969
}
7070
}
71+
fn features(&self) -> Option<&BlindedHopFeatures> {
72+
match self {
73+
Self::Forward { features, .. } => Some(&features),
74+
Self::Receive { .. } => None,
75+
}
76+
}
7177
}
7278

7379
/// Parameters for relaying over a given [`BlindedHop`].
@@ -167,6 +173,10 @@ pub(super) fn compute_payinfo(
167173
let mut curr_base_fee: u32 = 0;
168174
let mut curr_prop_mil: u32 = 0;
169175
for (_, payment_tlvs) in path.iter().rev().skip(1) {
176+
// In the future, we'll want to take the intersection of all supported features for the
177+
// `BlindedPayInfo`, but there are no features in that context right now.
178+
if payment_tlvs.features().map_or(false, |f| f.requires_unknown_bits()) { return Err(()) }
179+
170180
let next_base_fee = payment_tlvs.fee_base_msat();
171181
let next_prop_mil = payment_tlvs.fee_proportional_millionths();
172182
// Use integer arithmetic to compute `ceil(a/b)` as `(a+b-1)/b`
@@ -193,7 +203,6 @@ pub(super) fn compute_payinfo(
193203
htlc_minimum_msat: path.iter().map(|(_, tlvs)| tlvs.htlc_minimum_msat()).max().unwrap_or(0),
194204
// TODO: this field isn't present in route blinding encrypted data
195205
htlc_maximum_msat: 21_000_000 * 100_000_000 * 1_000, // Total bitcoin supply
196-
// TODO: when there are blinded hop features, take the intersection of them here
197206
features: BlindedHopFeatures::empty(),
198207
})
199208
}

0 commit comments

Comments
 (0)