Skip to content

Commit 3660062

Browse files
committed
f - remove fallback from ChannelManager
1 parent a3cfa90 commit 3660062

File tree

1 file changed

+19
-29
lines changed

1 file changed

+19
-29
lines changed

lightning/src/ln/channelmanager.rs

Lines changed: 19 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -7435,15 +7435,20 @@ where
74357435
/// [`InvoiceRequest`]: crate::offers::invoice_request::InvoiceRequest
74367436
pub fn create_offer_builder(
74377437
&self, description: String
7438-
) -> OfferBuilder<DerivedMetadata, secp256k1::All> {
7438+
) -> Result<OfferBuilder<DerivedMetadata, secp256k1::All>, Bolt12SemanticError> {
74397439
let node_id = self.get_our_node_id();
74407440
let expanded_key = &self.inbound_payment_key;
74417441
let entropy = &*self.entropy_source;
74427442
let secp_ctx = &self.secp_ctx;
74437443

7444-
OfferBuilder::deriving_signing_pubkey(description, node_id, expanded_key, entropy, secp_ctx)
7444+
let path = self.create_blinded_path().map_err(|_| Bolt12SemanticError::MissingPaths)?;
7445+
let builder = OfferBuilder::deriving_signing_pubkey(
7446+
description, node_id, expanded_key, entropy, secp_ctx
7447+
)
74457448
.chain_hash(self.chain_hash)
7446-
.path(self.create_blinded_path())
7449+
.path(path);
7450+
7451+
Ok(builder)
74477452
}
74487453

74497454
/// Creates a [`RefundBuilder`] such that the [`Refund`] it builds is recognized by the
@@ -7500,12 +7505,13 @@ where
75007505
let entropy = &*self.entropy_source;
75017506
let secp_ctx = &self.secp_ctx;
75027507

7508+
let path = self.create_blinded_path().map_err(|_| Bolt12SemanticError::MissingPaths)?;
75037509
let builder = RefundBuilder::deriving_payer_id(
75047510
description, node_id, expanded_key, entropy, secp_ctx, amount_msats, payment_id
75057511
)?
75067512
.chain_hash(self.chain_hash)
75077513
.absolute_expiry(absolute_expiry)
7508-
.path(self.create_blinded_path());
7514+
.path(path);
75097515

75107516
let expiration = StaleExpiration::AbsoluteTimeout(absolute_expiry);
75117517
self.pending_outbound_payments
@@ -7592,7 +7598,7 @@ where
75927598
Some(payer_note) => builder.payer_note(payer_note),
75937599
};
75947600
let invoice_request = builder.build_and_sign()?;
7595-
let reply_path = self.create_blinded_path();
7601+
let reply_path = self.create_blinded_path().map_err(|_| Bolt12SemanticError::MissingPaths)?;
75967602

75977603
let expiration = StaleExpiration::TimerTicks(1);
75987604
self.pending_outbound_payments
@@ -7668,7 +7674,8 @@ where
76687674
payment_paths, payment_hash, created_at, expanded_key, entropy
76697675
)?;
76707676
let invoice = builder.allow_mpp().build_and_sign(secp_ctx)?;
7671-
let reply_path = self.create_blinded_path();
7677+
let reply_path = self.create_blinded_path()
7678+
.map_err(|_| Bolt12SemanticError::MissingPaths)?;
76727679

76737680
let mut pending_offers_messages = self.pending_offers_messages.lock().unwrap();
76747681
if refund.paths().is_empty() {
@@ -7795,29 +7802,10 @@ where
77957802
inbound_payment::get_payment_preimage(payment_hash, payment_secret, &self.inbound_payment_key)
77967803
}
77977804

7798-
/// Creates a multi-hop blinded path by delegating to [`MessageRouter::create_blinded_paths`].
7799-
/// If the router returns an error or no paths, creates a one-hop blinded path instead.
7800-
fn create_blinded_path(&self) -> BlindedPath {
7801-
self.create_multi_hop_blinded_paths()
7802-
.ok()
7803-
.and_then(|paths| paths.into_iter().next())
7804-
.unwrap_or_else(|| self.create_one_hop_blinded_path())
7805-
}
7806-
7807-
/// Creates a one-hop blinded path with [`ChannelManager::get_our_node_id`] as the introduction
7808-
/// node.
7809-
fn create_one_hop_blinded_path(&self) -> BlindedPath {
7810-
let entropy_source = self.entropy_source.deref();
7811-
let secp_ctx = &self.secp_ctx;
7812-
BlindedPath::one_hop_for_message(self.get_our_node_id(), entropy_source, secp_ctx).unwrap()
7813-
}
7814-
7815-
/// Creates blinded paths by delegating to [`MessageRouter::create_blinded_paths`].
7816-
///
7817-
/// May return no paths if no peers [support onion messages].
7805+
/// Creates a blinded path by delegating to [`MessageRouter::create_blinded_paths`].
78187806
///
7819-
/// [support onion messages]: crate::ln::features::InitFeatures::supports_onion_messages
7820-
fn create_multi_hop_blinded_paths(&self) -> Result<Vec<BlindedPath>, ()> {
7807+
/// Errors if the `MessageRouter` errors or returns an empty `Vec`.
7808+
fn create_blinded_path(&self) -> Result<BlindedPath, ()> {
78217809
let recipient = self.get_our_node_id();
78227810
let entropy_source = self.entropy_source.deref();
78237811
let secp_ctx = &self.secp_ctx;
@@ -7828,7 +7816,9 @@ where
78287816
.map(|(node_id, _)| *node_id)
78297817
.collect::<Vec<_>>();
78307818

7831-
self.router.create_blinded_paths(recipient, peers, entropy_source, secp_ctx)
7819+
self.router
7820+
.create_blinded_paths(recipient, peers, entropy_source, secp_ctx)
7821+
.and_then(|paths| paths.into_iter().next().ok_or(()))
78327822
}
78337823

78347824
/// Creates a one-hop blinded payment path with [`ChannelManager::get_our_node_id`] as the

0 commit comments

Comments
 (0)