Skip to content

Commit bdd1975

Browse files
committed
Handle splice_locked message
1 parent 5fc20b7 commit bdd1975

File tree

2 files changed

+90
-3
lines changed

2 files changed

+90
-3
lines changed

lightning/src/ln/channel.rs

+35
Original file line numberDiff line numberDiff line change
@@ -8998,6 +8998,41 @@ impl<SP: Deref> FundedChannel<SP> where
89988998
Ok(())
89998999
}
90009000

9001+
#[cfg(splicing)]
9002+
pub fn splice_locked<NS: Deref, L: Deref>(
9003+
&mut self, msg: &msgs::SpliceLocked, node_signer: &NS, chain_hash: ChainHash,
9004+
user_config: &UserConfig, best_block: &BestBlock, logger: &L,
9005+
) -> Result<Option<msgs::AnnouncementSignatures>, ChannelError>
9006+
where
9007+
NS::Target: NodeSigner,
9008+
L::Target: Logger
9009+
{
9010+
let pending_splice = match self.pending_splice.as_mut() {
9011+
Some(pending_splice) => pending_splice,
9012+
None => {
9013+
return Err(ChannelError::Warn(format!("Channel is not in pending splice")));
9014+
},
9015+
};
9016+
9017+
if let Some(sent_funding_txid) = pending_splice.sent_funding_txid {
9018+
if sent_funding_txid == msg.splice_txid {
9019+
if let Some(funding) = self.pending_funding
9020+
.iter_mut()
9021+
.find(|funding| funding.get_funding_txid() == Some(sent_funding_txid))
9022+
{
9023+
promote_splice_funding!(self, funding);
9024+
return Ok(self.get_announcement_sigs(node_signer, chain_hash, user_config, best_block.height, logger));
9025+
}
9026+
9027+
// TODO: Close channel?
9028+
return Ok(None);
9029+
}
9030+
}
9031+
9032+
pending_splice.received_funding_txid = Some(msg.splice_txid);
9033+
Ok(None)
9034+
}
9035+
90019036
// Send stuff to our remote peers:
90029037

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

lightning/src/ln/channelmanager.rs

+55-3
Original file line numberDiff line numberDiff line change
@@ -9610,6 +9610,51 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
96109610
Err(MsgHandleErrInternal::send_err_msg_no_close("TODO(splicing): Splicing is not implemented (splice_ack)".to_owned(), msg.channel_id))
96119611
}
96129612

9613+
#[cfg(splicing)]
9614+
fn internal_splice_locked(&self, counterparty_node_id: &PublicKey, msg: &msgs::SpliceLocked) -> Result<(), MsgHandleErrInternal> {
9615+
let per_peer_state = self.per_peer_state.read().unwrap();
9616+
let peer_state_mutex = per_peer_state.get(counterparty_node_id)
9617+
.ok_or_else(|| {
9618+
debug_assert!(false);
9619+
MsgHandleErrInternal::send_err_msg_no_close(format!("Can't find a peer matching the passed counterparty node_id {}", counterparty_node_id), msg.channel_id)
9620+
})?;
9621+
let mut peer_state_lock = peer_state_mutex.lock().unwrap();
9622+
let peer_state = &mut *peer_state_lock;
9623+
9624+
// Look for the channel
9625+
match peer_state.channel_by_id.entry(msg.channel_id) {
9626+
hash_map::Entry::Vacant(_) => return Err(MsgHandleErrInternal::send_err_msg_no_close(format!(
9627+
"Got a message for a channel from the wrong node! No such channel for the passed counterparty_node_id {}",
9628+
counterparty_node_id
9629+
), msg.channel_id)),
9630+
hash_map::Entry::Occupied(mut chan_entry) => {
9631+
if let Some(chan) = chan_entry.get_mut().as_funded_mut() {
9632+
let logger = WithChannelContext::from(&self.logger, &chan.context, None);
9633+
let announcement_sigs_opt = try_channel_entry!(
9634+
self, peer_state, chan.splice_locked(
9635+
msg, &self.node_signer, self.chain_hash, &self.default_configuration,
9636+
&self.best_block.read().unwrap(), &&logger,
9637+
), chan_entry
9638+
);
9639+
if let Some(announcement_sigs) = announcement_sigs_opt {
9640+
let mut short_to_chan_info = self.short_to_chan_info.write().unwrap();
9641+
insert_short_channel_id!(short_to_chan_info, chan);
9642+
9643+
log_trace!(logger, "Sending announcement_signatures for channel {}", chan.context.channel_id());
9644+
peer_state.pending_msg_events.push(MessageSendEvent::SendAnnouncementSignatures {
9645+
node_id: counterparty_node_id.clone(),
9646+
msg: announcement_sigs,
9647+
});
9648+
}
9649+
} else {
9650+
return Err(MsgHandleErrInternal::send_err_msg_no_close("Channel is not funded, cannot splice".to_owned(), msg.channel_id));
9651+
}
9652+
},
9653+
};
9654+
9655+
Err(MsgHandleErrInternal::send_err_msg_no_close("TODO(splicing): Splicing is not implemented (splice_locked)".to_owned(), msg.channel_id))
9656+
}
9657+
96139658
/// Process pending events from the [`chain::Watch`], returning whether any events were processed.
96149659
fn process_pending_monitor_events(&self) -> bool {
96159660
debug_assert!(self.total_consistency_lock.try_write().is_err()); // Caller holds read lock
@@ -12123,9 +12168,16 @@ where
1212312168

1212412169
#[cfg(splicing)]
1212512170
fn handle_splice_locked(&self, counterparty_node_id: PublicKey, msg: &msgs::SpliceLocked) {
12126-
let _: Result<(), _> = handle_error!(self, Err(MsgHandleErrInternal::send_err_msg_no_close(
12127-
"Splicing not supported (splice_locked)".to_owned(),
12128-
msg.channel_id)), counterparty_node_id);
12171+
let _persistence_guard = PersistenceNotifierGuard::optionally_notify(self, || {
12172+
let res = self.internal_splice_locked(&counterparty_node_id, msg);
12173+
let persist = match &res {
12174+
Err(e) if e.closes_channel() => NotifyOption::DoPersist,
12175+
Err(_) => NotifyOption::SkipPersistHandleEvents,
12176+
Ok(()) => NotifyOption::SkipPersistHandleEvents,
12177+
};
12178+
let _ = handle_error!(self, res, counterparty_node_id);
12179+
persist
12180+
});
1212912181
}
1213012182

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

0 commit comments

Comments
 (0)