Skip to content

Commit e4c0566

Browse files
committed
Handle splice_locked message
1 parent 71e27a4 commit e4c0566

File tree

2 files changed

+87
-3
lines changed

2 files changed

+87
-3
lines changed

lightning/src/ln/channel.rs

+35
Original file line numberDiff line numberDiff line change
@@ -8922,6 +8922,41 @@ impl<SP: Deref> FundedChannel<SP> where
89228922
Ok(())
89238923
}
89248924

8925+
#[cfg(splicing)]
8926+
pub fn splice_locked<NS: Deref, L: Deref>(
8927+
&mut self, msg: &msgs::SpliceLocked, node_signer: &NS, chain_hash: ChainHash,
8928+
user_config: &UserConfig, best_block: &BestBlock, logger: &L,
8929+
) -> Result<Option<msgs::AnnouncementSignatures>, ChannelError>
8930+
where
8931+
NS::Target: NodeSigner,
8932+
L::Target: Logger
8933+
{
8934+
let pending_splice = match self.pending_splice.as_mut() {
8935+
Some(pending_splice) => pending_splice,
8936+
None => {
8937+
return Err(ChannelError::Warn(format!("Channel is not in pending splice")));
8938+
},
8939+
};
8940+
8941+
if let Some(sent_funding_txid) = pending_splice.sent_funding_txid {
8942+
if sent_funding_txid == msg.splice_txid {
8943+
if let Some(funding) = self.pending_funding
8944+
.iter_mut()
8945+
.find(|funding| funding.get_funding_txo().map(|txo| txo.txid) == Some(sent_funding_txid))
8946+
{
8947+
promote_splice_funding!(self, funding);
8948+
return Ok(self.get_announcement_sigs(node_signer, chain_hash, user_config, best_block.height, logger));
8949+
}
8950+
8951+
// TODO: Close channel?
8952+
return Ok(None);
8953+
}
8954+
}
8955+
8956+
pending_splice.received_funding_txid = Some(msg.splice_txid);
8957+
Ok(None)
8958+
}
8959+
89258960
// Send stuff to our remote peers:
89268961

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

lightning/src/ln/channelmanager.rs

+52-3
Original file line numberDiff line numberDiff line change
@@ -9603,6 +9603,48 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
96039603
Err(MsgHandleErrInternal::send_err_msg_no_close("TODO(splicing): Splicing is not implemented (splice_ack)".to_owned(), msg.channel_id))
96049604
}
96059605

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

1211212154
#[cfg(splicing)]
1211312155
fn handle_splice_locked(&self, counterparty_node_id: PublicKey, msg: &msgs::SpliceLocked) {
12114-
let _: Result<(), _> = handle_error!(self, Err(MsgHandleErrInternal::send_err_msg_no_close(
12115-
"Splicing not supported (splice_locked)".to_owned(),
12116-
msg.channel_id)), counterparty_node_id);
12156+
let _persistence_guard = PersistenceNotifierGuard::optionally_notify(self, || {
12157+
let res = self.internal_splice_locked(&counterparty_node_id, msg);
12158+
let persist = match &res {
12159+
Err(e) if e.closes_channel() => NotifyOption::DoPersist,
12160+
Err(_) => NotifyOption::SkipPersistHandleEvents,
12161+
Ok(()) => NotifyOption::SkipPersistHandleEvents,
12162+
};
12163+
let _ = handle_error!(self, res, counterparty_node_id);
12164+
persist
12165+
});
1211712166
}
1211812167

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

0 commit comments

Comments
 (0)