Skip to content

Commit 98763ef

Browse files
committed
f - remove fallback from ChannelManager
1 parent 12e1821 commit 98763ef

File tree

1 file changed

+21
-46
lines changed

1 file changed

+21
-46
lines changed

lightning/src/ln/channelmanager.rs

+21-46
Original file line numberDiff line numberDiff line change
@@ -7658,7 +7658,9 @@ where
76587658

76597659
match self.create_inbound_payment(Some(amount_msats), relative_expiry, None) {
76607660
Ok((payment_hash, payment_secret)) => {
7661-
let payment_paths = self.create_blinded_payment_paths(amount_msats, payment_secret);
7661+
let payment_paths = self.create_blinded_payment_paths(amount_msats, payment_secret)
7662+
.map_err(|_| Bolt12SemanticError::MissingPaths)?;
7663+
76627664
#[cfg(not(feature = "no-std"))]
76637665
let builder = refund.respond_using_derived_keys(
76647666
payment_paths, payment_hash, expanded_key, entropy
@@ -7819,49 +7821,9 @@ where
78197821
.and_then(|paths| paths.into_iter().next().ok_or(()))
78207822
}
78217823

7822-
/// Creates multi-hop blinded payment paths for the given `amount_msats` by delegating to
7823-
/// [`Router::create_blinded_payment_paths`]. If the router returns an error or no paths,
7824-
/// creates a one-hop blinded payment path instead.
7825-
fn create_blinded_payment_paths(
7826-
&self, amount_msats: u64, payment_secret: PaymentSecret
7827-
) -> Vec<(BlindedPayInfo, BlindedPath)> {
7828-
self.create_multi_hop_blinded_payment_paths(amount_msats, payment_secret)
7829-
.ok()
7830-
.and_then(|paths| (!paths.is_empty()).then(|| paths))
7831-
.unwrap_or_else(|| vec![self.create_one_hop_blinded_payment_path(payment_secret)])
7832-
}
7833-
7834-
/// Creates a one-hop blinded payment path with [`ChannelManager::get_our_node_id`] as the
7835-
/// introduction node.
7836-
fn create_one_hop_blinded_payment_path(
7837-
&self, payment_secret: PaymentSecret
7838-
) -> (BlindedPayInfo, BlindedPath) {
7839-
let entropy_source = self.entropy_source.deref();
7840-
let secp_ctx = &self.secp_ctx;
7841-
7842-
let payee_node_id = self.get_our_node_id();
7843-
let max_cltv_expiry = self.best_block.read().unwrap().height() + LATENCY_GRACE_PERIOD_BLOCKS;
7844-
let payee_tlvs = ReceiveTlvs {
7845-
payment_secret,
7846-
payment_constraints: PaymentConstraints {
7847-
max_cltv_expiry,
7848-
htlc_minimum_msat: 1,
7849-
},
7850-
};
7851-
// TODO: Err for overflow?
7852-
BlindedPath::one_hop_for_payment(
7853-
payee_node_id, payee_tlvs, entropy_source, secp_ctx
7854-
).unwrap()
7855-
}
7856-
78577824
/// Creates multi-hop blinded payment paths for the given `amount_msats` by delegating to
78587825
/// [`Router::create_blinded_payment_paths`].
7859-
///
7860-
/// May return no paths if no peers [support route blinding] or whose channels don't have enough
7861-
/// inbound liquidity.
7862-
///
7863-
/// [support route blinding]: crate::ln::features::InitFeatures::supports_route_blinding
7864-
fn create_multi_hop_blinded_payment_paths(
7826+
fn create_blinded_payment_paths(
78657827
&self, amount_msats: u64, payment_secret: PaymentSecret
78667828
) -> Result<Vec<(BlindedPayInfo, BlindedPath)>, ()> {
78677829
let entropy_source = self.entropy_source.deref();
@@ -9133,9 +9095,15 @@ where
91339095

91349096
match self.create_inbound_payment(Some(amount_msats), relative_expiry, None) {
91359097
Ok((payment_hash, payment_secret)) if invoice_request.keys.is_some() => {
9136-
let payment_paths = self.create_blinded_payment_paths(
9098+
let payment_paths = match self.create_blinded_payment_paths(
91379099
amount_msats, payment_secret
9138-
);
9100+
) {
9101+
Ok(payment_paths) => payment_paths,
9102+
Err(()) => {
9103+
let error = Bolt12SemanticError::MissingPaths;
9104+
return Some(OffersMessage::InvoiceError(error.into()));
9105+
},
9106+
};
91399107
#[cfg(not(feature = "no-std"))]
91409108
let builder = invoice_request.respond_using_derived_keys(
91419109
payment_paths, payment_hash
@@ -9154,9 +9122,16 @@ where
91549122
}
91559123
},
91569124
Ok((payment_hash, payment_secret)) => {
9157-
let payment_paths = self.create_blinded_payment_paths(
9125+
let payment_paths = match self.create_blinded_payment_paths(
91589126
amount_msats, payment_secret
9159-
);
9127+
) {
9128+
Ok(payment_paths) => payment_paths,
9129+
Err(()) => {
9130+
let error = Bolt12SemanticError::MissingPaths;
9131+
return Some(OffersMessage::InvoiceError(error.into()));
9132+
},
9133+
};
9134+
91609135
#[cfg(not(feature = "no-std"))]
91619136
let builder = invoice_request.respond_with(payment_paths, payment_hash);
91629137
#[cfg(feature = "no-std")]

0 commit comments

Comments
 (0)