Skip to content

Commit 0fb0ef1

Browse files
committed
Handle splice_locked message
1 parent 2d110b9 commit 0fb0ef1

File tree

2 files changed

+90
-3
lines changed

2 files changed

+90
-3
lines changed

lightning/src/ln/channel.rs

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9150,6 +9150,41 @@ impl<SP: Deref> FundedChannel<SP> where
91509150
Ok(())
91519151
}
91529152

9153+
#[cfg(splicing)]
9154+
pub fn splice_locked<NS: Deref, L: Deref>(
9155+
&mut self, msg: &msgs::SpliceLocked, node_signer: &NS, chain_hash: ChainHash,
9156+
user_config: &UserConfig, best_block: &BestBlock, logger: &L,
9157+
) -> Result<Option<msgs::AnnouncementSignatures>, ChannelError>
9158+
where
9159+
NS::Target: NodeSigner,
9160+
L::Target: Logger
9161+
{
9162+
let pending_splice = match self.pending_splice.as_mut() {
9163+
Some(pending_splice) => pending_splice,
9164+
None => {
9165+
return Err(ChannelError::Ignore(format!("Channel is not in pending splice")));
9166+
},
9167+
};
9168+
9169+
if let Some(sent_funding_txid) = pending_splice.sent_funding_txid {
9170+
if sent_funding_txid == msg.splice_txid {
9171+
if let Some(funding) = self.pending_funding
9172+
.iter_mut()
9173+
.find(|funding| funding.get_funding_txid() == Some(sent_funding_txid))
9174+
{
9175+
promote_splice_funding!(self, funding);
9176+
return Ok(self.get_announcement_sigs(node_signer, chain_hash, user_config, best_block.height, logger));
9177+
}
9178+
9179+
// TODO: Close channel?
9180+
return Ok(None);
9181+
}
9182+
}
9183+
9184+
pending_splice.received_funding_txid = Some(msg.splice_txid);
9185+
Ok(None)
9186+
}
9187+
91539188
// Send stuff to our remote peers:
91549189

91559190
/// Queues up an outbound HTLC to send by placing it in the holding cell. You should call

lightning/src/ln/channelmanager.rs

Lines changed: 55 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9627,6 +9627,51 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
96279627
Err(MsgHandleErrInternal::send_err_msg_no_close("TODO(splicing): Splicing is not implemented (splice_ack)".to_owned(), msg.channel_id))
96289628
}
96299629

9630+
#[cfg(splicing)]
9631+
fn internal_splice_locked(&self, counterparty_node_id: &PublicKey, msg: &msgs::SpliceLocked) -> Result<(), MsgHandleErrInternal> {
9632+
let per_peer_state = self.per_peer_state.read().unwrap();
9633+
let peer_state_mutex = per_peer_state.get(counterparty_node_id)
9634+
.ok_or_else(|| {
9635+
debug_assert!(false);
9636+
MsgHandleErrInternal::send_err_msg_no_close(format!("Can't find a peer matching the passed counterparty node_id {}", counterparty_node_id), msg.channel_id)
9637+
})?;
9638+
let mut peer_state_lock = peer_state_mutex.lock().unwrap();
9639+
let peer_state = &mut *peer_state_lock;
9640+
9641+
// Look for the channel
9642+
match peer_state.channel_by_id.entry(msg.channel_id) {
9643+
hash_map::Entry::Vacant(_) => return Err(MsgHandleErrInternal::send_err_msg_no_close(format!(
9644+
"Got a message for a channel from the wrong node! No such channel for the passed counterparty_node_id {}",
9645+
counterparty_node_id
9646+
), msg.channel_id)),
9647+
hash_map::Entry::Occupied(mut chan_entry) => {
9648+
if let Some(chan) = chan_entry.get_mut().as_funded_mut() {
9649+
let logger = WithChannelContext::from(&self.logger, &chan.context, None);
9650+
let announcement_sigs_opt = try_channel_entry!(
9651+
self, peer_state, chan.splice_locked(
9652+
msg, &self.node_signer, self.chain_hash, &self.default_configuration,
9653+
&self.best_block.read().unwrap(), &&logger,
9654+
), chan_entry
9655+
);
9656+
if let Some(announcement_sigs) = announcement_sigs_opt {
9657+
let mut short_to_chan_info = self.short_to_chan_info.write().unwrap();
9658+
insert_short_channel_id!(short_to_chan_info, chan);
9659+
9660+
log_trace!(logger, "Sending announcement_signatures for channel {}", chan.context.channel_id());
9661+
peer_state.pending_msg_events.push(MessageSendEvent::SendAnnouncementSignatures {
9662+
node_id: counterparty_node_id.clone(),
9663+
msg: announcement_sigs,
9664+
});
9665+
}
9666+
} else {
9667+
return Err(MsgHandleErrInternal::send_err_msg_no_close("Channel is not funded, cannot splice".to_owned(), msg.channel_id));
9668+
}
9669+
},
9670+
};
9671+
9672+
Err(MsgHandleErrInternal::send_err_msg_no_close("TODO(splicing): Splicing is not implemented (splice_locked)".to_owned(), msg.channel_id))
9673+
}
9674+
96309675
/// Process pending events from the [`chain::Watch`], returning whether any events were processed.
96319676
fn process_pending_monitor_events(&self) -> bool {
96329677
debug_assert!(self.total_consistency_lock.try_write().is_err()); // Caller holds read lock
@@ -12144,9 +12189,16 @@ where
1214412189

1214512190
#[cfg(splicing)]
1214612191
fn handle_splice_locked(&self, counterparty_node_id: PublicKey, msg: &msgs::SpliceLocked) {
12147-
let _: Result<(), _> = handle_error!(self, Err(MsgHandleErrInternal::send_err_msg_no_close(
12148-
"Splicing not supported (splice_locked)".to_owned(),
12149-
msg.channel_id)), counterparty_node_id);
12192+
let _persistence_guard = PersistenceNotifierGuard::optionally_notify(self, || {
12193+
let res = self.internal_splice_locked(&counterparty_node_id, msg);
12194+
let persist = match &res {
12195+
Err(e) if e.closes_channel() => NotifyOption::DoPersist,
12196+
Err(_) => NotifyOption::SkipPersistHandleEvents,
12197+
Ok(()) => NotifyOption::DoPersist,
12198+
};
12199+
let _ = handle_error!(self, res, counterparty_node_id);
12200+
persist
12201+
});
1215012202
}
1215112203

1215212204
fn handle_shutdown(&self, counterparty_node_id: PublicKey, msg: &msgs::Shutdown) {

0 commit comments

Comments
 (0)