Skip to content

Commit

Permalink
f - remove fallback from ChannelManager
Browse files Browse the repository at this point in the history
  • Loading branch information
jkczyz committed Dec 15, 2023
1 parent 12e1821 commit 98763ef
Showing 1 changed file with 21 additions and 46 deletions.
67 changes: 21 additions & 46 deletions lightning/src/ln/channelmanager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7658,7 +7658,9 @@ where

match self.create_inbound_payment(Some(amount_msats), relative_expiry, None) {
Ok((payment_hash, payment_secret)) => {
let payment_paths = self.create_blinded_payment_paths(amount_msats, payment_secret);
let payment_paths = self.create_blinded_payment_paths(amount_msats, payment_secret)
.map_err(|_| Bolt12SemanticError::MissingPaths)?;

#[cfg(not(feature = "no-std"))]
let builder = refund.respond_using_derived_keys(
payment_paths, payment_hash, expanded_key, entropy
Expand Down Expand Up @@ -7819,49 +7821,9 @@ where
.and_then(|paths| paths.into_iter().next().ok_or(()))
}

/// Creates multi-hop blinded payment paths for the given `amount_msats` by delegating to
/// [`Router::create_blinded_payment_paths`]. If the router returns an error or no paths,
/// creates a one-hop blinded payment path instead.
fn create_blinded_payment_paths(
&self, amount_msats: u64, payment_secret: PaymentSecret
) -> Vec<(BlindedPayInfo, BlindedPath)> {
self.create_multi_hop_blinded_payment_paths(amount_msats, payment_secret)
.ok()
.and_then(|paths| (!paths.is_empty()).then(|| paths))
.unwrap_or_else(|| vec![self.create_one_hop_blinded_payment_path(payment_secret)])
}

/// Creates a one-hop blinded payment path with [`ChannelManager::get_our_node_id`] as the
/// introduction node.
fn create_one_hop_blinded_payment_path(
&self, payment_secret: PaymentSecret
) -> (BlindedPayInfo, BlindedPath) {
let entropy_source = self.entropy_source.deref();
let secp_ctx = &self.secp_ctx;

let payee_node_id = self.get_our_node_id();
let max_cltv_expiry = self.best_block.read().unwrap().height() + LATENCY_GRACE_PERIOD_BLOCKS;
let payee_tlvs = ReceiveTlvs {
payment_secret,
payment_constraints: PaymentConstraints {
max_cltv_expiry,
htlc_minimum_msat: 1,
},
};
// TODO: Err for overflow?
BlindedPath::one_hop_for_payment(
payee_node_id, payee_tlvs, entropy_source, secp_ctx
).unwrap()
}

/// Creates multi-hop blinded payment paths for the given `amount_msats` by delegating to
/// [`Router::create_blinded_payment_paths`].
///
/// May return no paths if no peers [support route blinding] or whose channels don't have enough
/// inbound liquidity.
///
/// [support route blinding]: crate::ln::features::InitFeatures::supports_route_blinding
fn create_multi_hop_blinded_payment_paths(
fn create_blinded_payment_paths(
&self, amount_msats: u64, payment_secret: PaymentSecret
) -> Result<Vec<(BlindedPayInfo, BlindedPath)>, ()> {
let entropy_source = self.entropy_source.deref();
Expand Down Expand Up @@ -9133,9 +9095,15 @@ where

match self.create_inbound_payment(Some(amount_msats), relative_expiry, None) {
Ok((payment_hash, payment_secret)) if invoice_request.keys.is_some() => {
let payment_paths = self.create_blinded_payment_paths(
let payment_paths = match self.create_blinded_payment_paths(
amount_msats, payment_secret
);
) {
Ok(payment_paths) => payment_paths,
Err(()) => {
let error = Bolt12SemanticError::MissingPaths;
return Some(OffersMessage::InvoiceError(error.into()));
},
};
#[cfg(not(feature = "no-std"))]
let builder = invoice_request.respond_using_derived_keys(
payment_paths, payment_hash
Expand All @@ -9154,9 +9122,16 @@ where
}
},
Ok((payment_hash, payment_secret)) => {
let payment_paths = self.create_blinded_payment_paths(
let payment_paths = match self.create_blinded_payment_paths(
amount_msats, payment_secret
);
) {
Ok(payment_paths) => payment_paths,
Err(()) => {
let error = Bolt12SemanticError::MissingPaths;
return Some(OffersMessage::InvoiceError(error.into()));
},
};

#[cfg(not(feature = "no-std"))]
let builder = invoice_request.respond_with(payment_paths, payment_hash);
#[cfg(feature = "no-std")]
Expand Down

0 comments on commit 98763ef

Please sign in to comment.