Skip to content

Commit c585275

Browse files
committed
Add SplicePending and SpiceFailed events
LDK introduced similar events with splicing. SplicePending is largely informational like ChannelPending. SpliceFailed indicates the used UTXOs can be reclaimed. This requires UTXO locking, which is not yet implemented.
1 parent ba335eb commit c585275

File tree

2 files changed

+103
-10
lines changed

2 files changed

+103
-10
lines changed

bindings/ldk_node.udl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -395,6 +395,8 @@ interface Event {
395395
ChannelPending(ChannelId channel_id, UserChannelId user_channel_id, ChannelId former_temporary_channel_id, PublicKey counterparty_node_id, OutPoint funding_txo);
396396
ChannelReady(ChannelId channel_id, UserChannelId user_channel_id, PublicKey? counterparty_node_id, OutPoint? funding_txo);
397397
ChannelClosed(ChannelId channel_id, UserChannelId user_channel_id, PublicKey? counterparty_node_id, ClosureReason? reason);
398+
SplicePending(ChannelId channel_id, UserChannelId user_channel_id, PublicKey counterparty_node_id, OutPoint new_funding_txo);
399+
SpliceFailed(ChannelId channel_id, UserChannelId user_channel_id, PublicKey counterparty_node_id, OutPoint? abandoned_funding_txo);
398400
};
399401

400402
enum PaymentFailureReason {

src/event.rs

Lines changed: 101 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,28 @@ pub enum Event {
234234
/// This will be `None` for events serialized by LDK Node v0.2.1 and prior.
235235
reason: Option<ClosureReason>,
236236
},
237+
/// A channel splice is pending confirmation on-chain.
238+
SplicePending {
239+
/// The `channel_id` of the channel.
240+
channel_id: ChannelId,
241+
/// The `user_channel_id` of the channel.
242+
user_channel_id: UserChannelId,
243+
/// The `node_id` of the channel counterparty.
244+
counterparty_node_id: PublicKey,
245+
/// The outpoint of the channel's splice funding transaction.
246+
new_funding_txo: OutPoint,
247+
},
248+
/// A channel splice has failed.
249+
SpliceFailed {
250+
/// The `channel_id` of the channel.
251+
channel_id: ChannelId,
252+
/// The `user_channel_id` of the channel.
253+
user_channel_id: UserChannelId,
254+
/// The `node_id` of the channel counterparty.
255+
counterparty_node_id: PublicKey,
256+
/// The outpoint of the channel's splice funding transaction, if one was created.
257+
abandoned_funding_txo: Option<OutPoint>,
258+
},
237259
}
238260

239261
impl_writeable_tlv_based_enum!(Event,
@@ -291,7 +313,19 @@ impl_writeable_tlv_based_enum!(Event,
291313
(10, skimmed_fee_msat, option),
292314
(12, claim_from_onchain_tx, required),
293315
(14, outbound_amount_forwarded_msat, option),
294-
}
316+
},
317+
(8, SplicePending) => {
318+
(1, channel_id, required),
319+
(3, counterparty_node_id, required),
320+
(5, user_channel_id, required),
321+
(7, new_funding_txo, required),
322+
},
323+
(9, SpliceFailed) => {
324+
(1, channel_id, required),
325+
(3, counterparty_node_id, required),
326+
(5, user_channel_id, required),
327+
(7, abandoned_funding_txo, option),
328+
},
295329
);
296330

297331
pub struct EventQueue<L: Deref>
@@ -1645,17 +1679,74 @@ where
16451679
LdkEvent::FundingTransactionReadyForSigning { .. } => {
16461680
debug_assert!(false, "We currently don't support interactive-tx, so this event should never be emitted.");
16471681
},
1648-
LdkEvent::SplicePending { .. } => {
1649-
debug_assert!(
1650-
false,
1651-
"We currently don't support splicing, so this event should never be emitted."
1682+
LdkEvent::SplicePending {
1683+
channel_id,
1684+
user_channel_id,
1685+
counterparty_node_id,
1686+
new_funding_txo,
1687+
..
1688+
} => {
1689+
log_info!(
1690+
self.logger,
1691+
"Channel {} with counterparty {} pending splice with funding_txo {}",
1692+
channel_id,
1693+
counterparty_node_id,
1694+
new_funding_txo,
16521695
);
1696+
1697+
let event = Event::SplicePending {
1698+
channel_id,
1699+
user_channel_id: UserChannelId(user_channel_id),
1700+
counterparty_node_id,
1701+
new_funding_txo,
1702+
};
1703+
1704+
match self.event_queue.add_event(event).await {
1705+
Ok(_) => {},
1706+
Err(e) => {
1707+
log_error!(self.logger, "Failed to push to event queue: {}", e);
1708+
return Err(ReplayEvent());
1709+
},
1710+
};
16531711
},
1654-
LdkEvent::SpliceFailed { .. } => {
1655-
debug_assert!(
1656-
false,
1657-
"We currently don't support splicing, so this event should never be emitted."
1658-
);
1712+
LdkEvent::SpliceFailed {
1713+
channel_id,
1714+
user_channel_id,
1715+
counterparty_node_id,
1716+
abandoned_funding_txo,
1717+
..
1718+
} => {
1719+
if let Some(funding_txo) = abandoned_funding_txo {
1720+
log_info!(
1721+
self.logger,
1722+
"Channel {} with counterparty {} failed splice with funding_txo {}",
1723+
channel_id,
1724+
counterparty_node_id,
1725+
funding_txo,
1726+
);
1727+
} else {
1728+
log_info!(
1729+
self.logger,
1730+
"Channel {} with counterparty {} failed splice",
1731+
channel_id,
1732+
counterparty_node_id,
1733+
);
1734+
}
1735+
1736+
let event = Event::SpliceFailed {
1737+
channel_id,
1738+
user_channel_id: UserChannelId(user_channel_id),
1739+
counterparty_node_id,
1740+
abandoned_funding_txo,
1741+
};
1742+
1743+
match self.event_queue.add_event(event).await {
1744+
Ok(_) => {},
1745+
Err(e) => {
1746+
log_error!(self.logger, "Failed to push to event queue: {}", e);
1747+
return Err(ReplayEvent());
1748+
},
1749+
};
16591750
},
16601751
}
16611752
Ok(())

0 commit comments

Comments
 (0)