Skip to content

Commit 27f7731

Browse files
committed
Fail request_refund_payment for unsupported chain
If a Refund has an unsupported chain, ChannelManager should not send an invoice as it can't be paid on that chain. Instead, return an error when calling ChannelManager::request_refund_payment for such refunds.
1 parent 34e19e5 commit 27f7731

File tree

3 files changed

+43
-2
lines changed

3 files changed

+43
-2
lines changed

lightning/src/ln/channelmanager.rs

+8-2
Original file line numberDiff line numberDiff line change
@@ -7884,8 +7884,10 @@ where
78847884
///
78857885
/// # Errors
78867886
///
7887-
/// Errors if the parameterized [`Router`] is unable to create a blinded payment path or reply
7888-
/// path for the invoice.
7887+
/// Errors if:
7888+
/// - the refund is for an unsupported chain, or
7889+
/// - the parameterized [`Router`] is unable to create a blinded payment path or reply path for
7890+
/// the invoice.
78897891
///
78907892
/// [`Bolt12Invoice`]: crate::offers::invoice::Bolt12Invoice
78917893
pub fn request_refund_payment(&self, refund: &Refund) -> Result<(), Bolt12SemanticError> {
@@ -7896,6 +7898,10 @@ where
78967898
let amount_msats = refund.amount_msats();
78977899
let relative_expiry = DEFAULT_RELATIVE_EXPIRY.as_secs() as u32;
78987900

7901+
if refund.chain() != self.chain_hash {
7902+
return Err(Bolt12SemanticError::UnsupportedChain);
7903+
}
7904+
78997905
match self.create_inbound_payment(Some(amount_msats), relative_expiry, None) {
79007906
Ok((payment_hash, payment_secret)) => {
79017907
let payment_paths = self.create_blinded_payment_paths(amount_msats, payment_secret)

lightning/src/ln/offers_tests.rs

+30
Original file line numberDiff line numberDiff line change
@@ -694,6 +694,36 @@ fn fails_creating_invoice_request_for_unsupported_chain() {
694694
}
695695
}
696696

697+
/// Fails requesting a payment when the refund contains an unsupported chain.
698+
#[test]
699+
fn fails_sending_invoice_with_unsupported_chain_for_refund() {
700+
let chanmon_cfgs = create_chanmon_cfgs(2);
701+
let node_cfgs = create_node_cfgs(2, &chanmon_cfgs);
702+
let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[None, None]);
703+
let nodes = create_network(2, &node_cfgs, &node_chanmgrs);
704+
705+
create_announced_chan_between_nodes_with_value(&nodes, 0, 1, 10_000_000, 1_000_000_000);
706+
707+
let alice = &nodes[0];
708+
let bob = &nodes[1];
709+
710+
let absolute_expiry = Duration::from_secs(u64::MAX);
711+
let payment_id = PaymentId([1; 32]);
712+
let refund = bob.node
713+
.create_refund_builder(
714+
"refund".to_string(), 10_000_000, absolute_expiry, payment_id, Retry::Attempts(0), None
715+
)
716+
.unwrap()
717+
.clear_chain()
718+
.chain(Network::Signet)
719+
.build().unwrap();
720+
721+
match alice.node.request_refund_payment(&refund) {
722+
Ok(_) => panic!("Expected error"),
723+
Err(e) => assert_eq!(e, Bolt12SemanticError::UnsupportedChain),
724+
}
725+
}
726+
697727
/// Fails creating an invoice request when a blinded reply path cannot be created without exposing
698728
/// the node's id.
699729
#[test]

lightning/src/offers/refund.rs

+5
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,11 @@ impl<'a, T: secp256k1::Signing> RefundBuilder<'a, T> {
302302
self
303303
}
304304

305+
pub(crate) fn clear_chain(mut self) -> Self {
306+
self.refund.chain = None;
307+
self
308+
}
309+
305310
fn features_unchecked(mut self, features: InvoiceRequestFeatures) -> Self {
306311
self.refund.features = features;
307312
self

0 commit comments

Comments
 (0)