Skip to content

Commit 25761b9

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 d49c71d commit 25761b9

File tree

3 files changed

+39
-0
lines changed

3 files changed

+39
-0
lines changed

lightning/src/ln/channelmanager.rs

+4
Original file line numberDiff line numberDiff line change
@@ -7895,6 +7895,10 @@ where
78957895
let amount_msats = refund.amount_msats();
78967896
let relative_expiry = DEFAULT_RELATIVE_EXPIRY.as_secs() as u32;
78977897

7898+
if refund.chain() != self.chain_hash {
7899+
return Err(Bolt12SemanticError::UnsupportedChain);
7900+
}
7901+
78987902
match self.create_inbound_payment(Some(amount_msats), relative_expiry, None) {
78997903
Ok((payment_hash, payment_secret)) => {
79007904
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)