Skip to content

Commit

Permalink
f check for required features
Browse files Browse the repository at this point in the history
  • Loading branch information
valentinewallace committed Aug 15, 2023
1 parent ea039ed commit cf50f76
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
1 change: 1 addition & 0 deletions lightning/src/blinded_path/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ impl BlindedPath {
/// * [`BlindedPayInfo`] calculation results in an integer overflow
/// * the list of [`BlindedPaymentTlvs`] does not consist of 0 or more
/// `BlindedPaymentTlvs::Forward` followed by 1 `BlindedPaymentTlvs::Receive`
/// * any unknown features are required in the provided [`BlindedPaymentTlvs`]
// TODO: make all payloads the same size with padding + add dummy hops
pub fn new_for_payment<ES: EntropySource, T: secp256k1::Signing + secp256k1::Verification>(
path: &[(PublicKey, BlindedPaymentTlvs)], entropy_source: &ES, secp_ctx: &Secp256k1<T>
Expand Down
8 changes: 7 additions & 1 deletion lightning/src/blinded_path/payment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,11 @@ impl BlindedPaymentTlvs {
payment_constraints.htlc_minimum_msat,
}
}
fn features(&self) -> &BlindedHopFeatures {
match self {
Self::Forward { features, .. } | Self::Receive { features, .. } => &features
}
}
}

/// Parameters for relaying over a given [`BlindedHop`].
Expand Down Expand Up @@ -174,6 +179,8 @@ pub(super) fn compute_payinfo(
let mut curr_base_fee: u32 = 0;
let mut curr_prop_mil: u32 = 0;
for (_, payment_tlvs) in path.iter().rev().skip(1) {
if payment_tlvs.features().requires_unknown_bits() { return Err(()) }

let next_base_fee = payment_tlvs.fee_base_msat();
let next_prop_mil = payment_tlvs.fee_proportional_millionths();
// Use integer arithmetic to compute `ceil(a/b)` as `(a+b-1)/b`
Expand All @@ -200,7 +207,6 @@ pub(super) fn compute_payinfo(
htlc_minimum_msat: path.iter().map(|(_, tlvs)| tlvs.htlc_minimum_msat()).max().unwrap_or(0),
// TODO: this field isn't present in route blinding encrypted data
htlc_maximum_msat: 21_000_000 * 100_000_000 * 1_000, // Total bitcoin supply
// TODO: when there are blinded hop features, take the intersection of them here
features: BlindedHopFeatures::empty(),
})
}
Expand Down

0 comments on commit cf50f76

Please sign in to comment.