From a788fcdf7fd63dd93d7262619e6832ac1cfcdfde Mon Sep 17 00:00:00 2001 From: Duncan Dean Date: Tue, 1 Nov 2022 16:12:06 +0200 Subject: [PATCH] Add new wire messaging and events but don't handle them --- lightning-net-tokio/src/lib.rs | 11 +++ lightning/src/ln/channelmanager.rs | 134 ++++++++++++++++++++++++++ lightning/src/ln/msgs.rs | 24 +++++ lightning/src/ln/peer_handler.rs | 145 +++++++++++++++++++++++++++++ lightning/src/ln/wire.rs | 57 +++++++++++- lightning/src/util/events.rs | 84 ++++++++++++++++- lightning/src/util/test_utils.rs | 44 +++++++++ 7 files changed, 496 insertions(+), 3 deletions(-) diff --git a/lightning-net-tokio/src/lib.rs b/lightning-net-tokio/src/lib.rs index 3fbe6aab949..6dd14e04bd5 100644 --- a/lightning-net-tokio/src/lib.rs +++ b/lightning-net-tokio/src/lib.rs @@ -602,6 +602,17 @@ mod tests { fn handle_update_fee(&self, _their_node_id: &PublicKey, _msg: &UpdateFee) {} fn handle_announcement_signatures(&self, _their_node_id: &PublicKey, _msg: &AnnouncementSignatures) {} fn handle_channel_update(&self, _their_node_id: &PublicKey, _msg: &ChannelUpdate) {} + fn handle_open_channel_v2(&self, _their_node_id: &PublicKey, _their_features: InitFeatures, _msg: &OpenChannelV2) {} + fn handle_accept_channel_v2(&self, _their_node_id: &PublicKey, _their_features: InitFeatures, _msg: &AcceptChannelV2) {} + fn handle_tx_add_input(&self, _their_node_id: &PublicKey, _msg: &TxAddInput) {} + fn handle_tx_add_output(&self, _their_node_id: &PublicKey, _msg: &TxAddOutput) {} + fn handle_tx_remove_input(&self, _their_node_id: &PublicKey, _msg: &TxRemoveInput) {} + fn handle_tx_remove_output(&self, _their_node_id: &PublicKey, _msg: &TxRemoveOutput) {} + fn handle_tx_complete(&self, _their_node_id: &PublicKey, _msg: &TxComplete) {} + fn handle_tx_signatures(&self, _their_node_id: &PublicKey, _msg: &TxSignatures) {} + fn handle_tx_init_rbf(&self, _their_node_id: &PublicKey, _msg: &TxInitRbf) {} + fn handle_tx_ack_rbf(&self, _their_node_id: &PublicKey, _msg: &TxAckRbf) {} + fn handle_tx_abort(&self, _their_node_id: &PublicKey, _msg: &TxAbort) {} fn peer_disconnected(&self, their_node_id: &PublicKey, _no_connection_possible: bool) { if *their_node_id == self.expected_pubkey { self.disconnected_flag.store(true, Ordering::SeqCst); diff --git a/lightning/src/ln/channelmanager.rs b/lightning/src/ln/channelmanager.rs index 358af825dd4..bb11f64f5b5 100644 --- a/lightning/src/ln/channelmanager.rs +++ b/lightning/src/ln/channelmanager.rs @@ -4503,6 +4503,13 @@ impl ChannelManager Result<(), MsgHandleErrInternal> { + // TODO - Actually implement + Err(MsgHandleErrInternal::send_err_msg_no_close("Dual-funded channels not supported".to_owned(), + msg.temporary_channel_id.clone())) + } + fn internal_accept_channel(&self, counterparty_node_id: &PublicKey, their_features: InitFeatures, msg: &msgs::AcceptChannel) -> Result<(), MsgHandleErrInternal> { let (value, output_script, user_id) = { let mut channel_lock = self.channel_state.lock().unwrap(); @@ -4529,6 +4536,13 @@ impl ChannelManager Result<(), MsgHandleErrInternal> { + // TODO - Actually implement + Err(MsgHandleErrInternal::send_err_msg_no_close("Dual-funded channels not supported".to_owned(), + msg.temporary_channel_id.clone())) + } + fn internal_funding_created(&self, counterparty_node_id: &PublicKey, msg: &msgs::FundingCreated) -> Result<(), MsgHandleErrInternal> { let ((funding_msg, monitor, mut channel_ready), mut chan) = { let best_block = *self.best_block.read().unwrap(); @@ -5158,6 +5172,60 @@ impl ChannelManager Result<(), MsgHandleErrInternal> { + // TODO - Actually implement + Err(MsgHandleErrInternal::send_err_msg_no_close("Interactive transaction construction not supported".to_owned(), + msg.channel_id.clone())) + } + + fn internal_tx_add_output(&self, _counterparty_node_id: &PublicKey, msg: &msgs::TxAddOutput) -> Result<(), MsgHandleErrInternal> { + // TODO - Actually implement + Err(MsgHandleErrInternal::send_err_msg_no_close("Interactive transaction construction not supported".to_owned(), + msg.channel_id.clone())) + } + + fn internal_tx_remove_input(&self, _counterparty_node_id: &PublicKey, msg: &msgs::TxRemoveInput) -> Result<(), MsgHandleErrInternal> { + // TODO - Actually implement + Err(MsgHandleErrInternal::send_err_msg_no_close("Interactive transaction construction not supported".to_owned(), + msg.channel_id.clone())) + } + + fn internal_tx_remove_output(&self, _counterparty_node_id: &PublicKey, msg: &msgs::TxRemoveOutput) -> Result<(), MsgHandleErrInternal> { + // TODO - Actually implement + Err(MsgHandleErrInternal::send_err_msg_no_close("Interactive transaction construction not supported".to_owned(), + msg.channel_id.clone())) + } + + fn internal_tx_complete(&self, _counterparty_node_id: &PublicKey, msg: &msgs::TxComplete) -> Result<(), MsgHandleErrInternal> { + // TODO - Actually implement + Err(MsgHandleErrInternal::send_err_msg_no_close("Interactive transaction construction not supported".to_owned(), + msg.channel_id.clone())) + } + + fn internal_tx_signatures(&self, _counterparty_node_id: &PublicKey, msg: &msgs::TxSignatures) -> Result<(), MsgHandleErrInternal> { + // TODO - Actually implement + Err(MsgHandleErrInternal::send_err_msg_no_close("Interactive transaction construction not supported".to_owned(), + msg.channel_id.clone())) + } + + fn internal_tx_init_rbf(&self, _counterparty_node_id: &PublicKey, msg: &msgs::TxInitRbf) -> Result<(), MsgHandleErrInternal> { + // TODO - Actually implement + Err(MsgHandleErrInternal::send_err_msg_no_close("Interactive transaction construction not supported".to_owned(), + msg.channel_id.clone())) + } + + fn internal_tx_ack_rbf(&self, _counterparty_node_id: &PublicKey, msg: &msgs::TxAckRbf) -> Result<(), MsgHandleErrInternal> { + // TODO - Actually implement + Err(MsgHandleErrInternal::send_err_msg_no_close("Interactive transaction construction not supported".to_owned(), + msg.channel_id.clone())) + } + + fn internal_tx_abort(&self, _counterparty_node_id: &PublicKey, msg: &msgs::TxAbort) -> Result<(), MsgHandleErrInternal> { + // TODO - Actually implement + Err(MsgHandleErrInternal::send_err_msg_no_close("Interactive transaction construction not supported".to_owned(), + msg.channel_id.clone())) + } + /// Process pending events from the `chain::Watch`, returning whether any events were processed. fn process_pending_monitor_events(&self) -> bool { let mut failed_channels = Vec::new(); @@ -5964,11 +6032,21 @@ impl let _ = handle_error!(self, self.internal_open_channel(counterparty_node_id, their_features, msg), *counterparty_node_id); } + fn handle_open_channel_v2(&self, counterparty_node_id: &PublicKey, their_features: InitFeatures, msg: &msgs::OpenChannelV2) { + let _persistence_guard = PersistenceNotifierGuard::notify_on_drop(&self.total_consistency_lock, &self.persistence_notifier); + let _ = handle_error!(self, self.internal_open_channel_v2(counterparty_node_id, their_features, msg), *counterparty_node_id); + } + fn handle_accept_channel(&self, counterparty_node_id: &PublicKey, their_features: InitFeatures, msg: &msgs::AcceptChannel) { let _persistence_guard = PersistenceNotifierGuard::notify_on_drop(&self.total_consistency_lock, &self.persistence_notifier); let _ = handle_error!(self, self.internal_accept_channel(counterparty_node_id, their_features, msg), *counterparty_node_id); } + fn handle_accept_channel_v2(&self, counterparty_node_id: &PublicKey, their_features: InitFeatures, msg: &msgs::AcceptChannelV2) { + let _persistence_guard = PersistenceNotifierGuard::notify_on_drop(&self.total_consistency_lock, &self.persistence_notifier); + let _ = handle_error!(self, self.internal_accept_channel_v2(counterparty_node_id, their_features, msg), *counterparty_node_id); + } + fn handle_funding_created(&self, counterparty_node_id: &PublicKey, msg: &msgs::FundingCreated) { let _persistence_guard = PersistenceNotifierGuard::notify_on_drop(&self.total_consistency_lock, &self.persistence_notifier); let _ = handle_error!(self, self.internal_funding_created(counterparty_node_id, msg), *counterparty_node_id); @@ -6076,10 +6154,21 @@ impl pending_msg_events.retain(|msg| { match msg { &events::MessageSendEvent::SendAcceptChannel { ref node_id, .. } => node_id != counterparty_node_id, + &events::MessageSendEvent::SendAcceptChannelV2 { ref node_id, .. } => node_id != counterparty_node_id, &events::MessageSendEvent::SendOpenChannel { ref node_id, .. } => node_id != counterparty_node_id, + &events::MessageSendEvent::SendOpenChannelV2 { ref node_id, .. } => node_id != counterparty_node_id, &events::MessageSendEvent::SendFundingCreated { ref node_id, .. } => node_id != counterparty_node_id, &events::MessageSendEvent::SendFundingSigned { ref node_id, .. } => node_id != counterparty_node_id, &events::MessageSendEvent::SendChannelReady { ref node_id, .. } => node_id != counterparty_node_id, + &events::MessageSendEvent::SendTxAddInput { ref node_id, .. } => node_id != counterparty_node_id, + &events::MessageSendEvent::SendTxAddOutput { ref node_id, .. } => node_id != counterparty_node_id, + &events::MessageSendEvent::SendTxRemoveInput { ref node_id, .. } => node_id != counterparty_node_id, + &events::MessageSendEvent::SendTxRemoveOutput { ref node_id, .. } => node_id != counterparty_node_id, + &events::MessageSendEvent::SendTxComplete { ref node_id, .. } => node_id != counterparty_node_id, + &events::MessageSendEvent::SendTxSignatures { ref node_id, .. } => node_id != counterparty_node_id, + &events::MessageSendEvent::SendTxInitRbf { ref node_id, .. } => node_id != counterparty_node_id, + &events::MessageSendEvent::SendTxAckRbf { ref node_id, .. } => node_id != counterparty_node_id, + &events::MessageSendEvent::SendTxAbort { ref node_id, .. } => node_id != counterparty_node_id, &events::MessageSendEvent::SendAnnouncementSignatures { ref node_id, .. } => node_id != counterparty_node_id, &events::MessageSendEvent::UpdateHTLCs { ref node_id, .. } => node_id != counterparty_node_id, &events::MessageSendEvent::SendRevokeAndACK { ref node_id, .. } => node_id != counterparty_node_id, @@ -6206,6 +6295,51 @@ impl fn provided_init_features(&self, _their_init_features: &PublicKey) -> InitFeatures { provided_init_features() } + + fn handle_tx_add_input(&self, counterparty_node_id: &PublicKey, msg: &msgs::TxAddInput) { + let _persistence_guard = PersistenceNotifierGuard::notify_on_drop(&self.total_consistency_lock, &self.persistence_notifier); + let _ = handle_error!(self, self.internal_tx_add_input(counterparty_node_id, msg), *counterparty_node_id); + } + + fn handle_tx_add_output(&self, counterparty_node_id: &PublicKey, msg: &msgs::TxAddOutput) { + let _persistence_guard = PersistenceNotifierGuard::notify_on_drop(&self.total_consistency_lock, &self.persistence_notifier); + let _ = handle_error!(self, self.internal_tx_add_output(counterparty_node_id, msg), *counterparty_node_id); + } + + fn handle_tx_remove_input(&self, counterparty_node_id: &PublicKey, msg: &msgs::TxRemoveInput) { + let _persistence_guard = PersistenceNotifierGuard::notify_on_drop(&self.total_consistency_lock, &self.persistence_notifier); + let _ = handle_error!(self, self.internal_tx_remove_input(counterparty_node_id, msg), *counterparty_node_id); + } + + fn handle_tx_remove_output(&self, counterparty_node_id: &PublicKey, msg: &msgs::TxRemoveOutput) { + let _persistence_guard = PersistenceNotifierGuard::notify_on_drop(&self.total_consistency_lock, &self.persistence_notifier); + let _ = handle_error!(self, self.internal_tx_remove_output(counterparty_node_id, msg), *counterparty_node_id); + } + + fn handle_tx_complete(&self, counterparty_node_id: &PublicKey, msg: &msgs::TxComplete) { + let _persistence_guard = PersistenceNotifierGuard::notify_on_drop(&self.total_consistency_lock, &self.persistence_notifier); + let _ = handle_error!(self, self.internal_tx_complete(counterparty_node_id, msg), *counterparty_node_id); + } + + fn handle_tx_signatures(&self, counterparty_node_id: &PublicKey, msg: &msgs::TxSignatures) { + let _persistence_guard = PersistenceNotifierGuard::notify_on_drop(&self.total_consistency_lock, &self.persistence_notifier); + let _ = handle_error!(self, self.internal_tx_signatures(counterparty_node_id, msg), *counterparty_node_id); + } + + fn handle_tx_init_rbf(&self, counterparty_node_id: &PublicKey, msg: &msgs::TxInitRbf) { + let _persistence_guard = PersistenceNotifierGuard::notify_on_drop(&self.total_consistency_lock, &self.persistence_notifier); + let _ = handle_error!(self, self.internal_tx_init_rbf(counterparty_node_id, msg), *counterparty_node_id); + } + + fn handle_tx_ack_rbf(&self, counterparty_node_id: &PublicKey, msg: &msgs::TxAckRbf) { + let _persistence_guard = PersistenceNotifierGuard::notify_on_drop(&self.total_consistency_lock, &self.persistence_notifier); + let _ = handle_error!(self, self.internal_tx_ack_rbf(counterparty_node_id, msg), *counterparty_node_id); + } + + fn handle_tx_abort(&self, counterparty_node_id: &PublicKey, msg: &msgs::TxAbort) { + let _persistence_guard = PersistenceNotifierGuard::notify_on_drop(&self.total_consistency_lock, &self.persistence_notifier); + let _ = handle_error!(self, self.internal_tx_abort(counterparty_node_id, msg), *counterparty_node_id); + } } /// Fetches the set of [`NodeFeatures`] flags which are provided by or required by diff --git a/lightning/src/ln/msgs.rs b/lightning/src/ln/msgs.rs index e40bd713f42..f0ada065987 100644 --- a/lightning/src/ln/msgs.rs +++ b/lightning/src/ln/msgs.rs @@ -1052,8 +1052,12 @@ pub trait ChannelMessageHandler : MessageSendEventsProvider { //Channel init: /// Handle an incoming open_channel message from the given peer. fn handle_open_channel(&self, their_node_id: &PublicKey, their_features: InitFeatures, msg: &OpenChannel); + /// Handle an incoming open_channel2 message from the given peer. + fn handle_open_channel_v2(&self, their_node_id: &PublicKey, their_features: InitFeatures, msg: &OpenChannelV2); /// Handle an incoming accept_channel message from the given peer. fn handle_accept_channel(&self, their_node_id: &PublicKey, their_features: InitFeatures, msg: &AcceptChannel); + /// Handle an incoming accept_channel2 message from the given peer. + fn handle_accept_channel_v2(&self, their_node_id: &PublicKey, their_features: InitFeatures, msg: &AcceptChannelV2); /// Handle an incoming funding_created message from the given peer. fn handle_funding_created(&self, their_node_id: &PublicKey, msg: &FundingCreated); /// Handle an incoming funding_signed message from the given peer. @@ -1067,6 +1071,26 @@ pub trait ChannelMessageHandler : MessageSendEventsProvider { /// Handle an incoming closing_signed message from the given peer. fn handle_closing_signed(&self, their_node_id: &PublicKey, msg: &ClosingSigned); + // Interactive channel construction + /// Handle an incoming tx_add_input message from the given peer. + fn handle_tx_add_input(&self, their_node_id: &PublicKey, msg: &TxAddInput); + /// Handle an incoming tx_add_output message from the given peer. + fn handle_tx_add_output(&self, their_node_id: &PublicKey, msg: &TxAddOutput); + /// Handle an incoming tx_remove_input message from the given peer. + fn handle_tx_remove_input(&self, their_node_id: &PublicKey, msg: &TxRemoveInput); + /// Handle an incoming tx_remove_output message from the given peer. + fn handle_tx_remove_output(&self, their_node_id: &PublicKey, msg: &TxRemoveOutput); + /// Handle an incoming tx_complete message from the given peer. + fn handle_tx_complete(&self, their_node_id: &PublicKey, msg: &TxComplete); + /// Handle an incoming tx_signatures message from the given peer. + fn handle_tx_signatures(&self, their_node_id: &PublicKey, msg: &TxSignatures); + /// Handle an incoming tx_init_rbf message from the given peer. + fn handle_tx_init_rbf(&self, their_node_id: &PublicKey, msg: &TxInitRbf); + /// Handle an incoming tx_ack_rbf message from the given peer. + fn handle_tx_ack_rbf(&self, their_node_id: &PublicKey, msg: &TxAckRbf); + /// Handle an incoming tx_abort message from the given peer. + fn handle_tx_abort(&self, their_node_id: &PublicKey, msg: &TxAbort); + // HTLC handling: /// Handle an incoming update_add_htlc message from the given peer. fn handle_update_add_htlc(&self, their_node_id: &PublicKey, msg: &UpdateAddHTLC); diff --git a/lightning/src/ln/peer_handler.rs b/lightning/src/ln/peer_handler.rs index 351f5142604..621b3ea4d4b 100644 --- a/lightning/src/ln/peer_handler.rs +++ b/lightning/src/ln/peer_handler.rs @@ -245,6 +245,50 @@ impl ChannelMessageHandler for ErroringMessageHandler { features.set_zero_conf_optional(); features } + + fn handle_open_channel_v2(&self, their_node_id: &PublicKey, _their_features: InitFeatures, msg: &msgs::OpenChannelV2) { + ErroringMessageHandler::push_error(self, their_node_id, msg.temporary_channel_id); + } + + fn handle_accept_channel_v2(&self, their_node_id: &PublicKey, _their_features: InitFeatures, msg: &msgs::AcceptChannelV2) { + ErroringMessageHandler::push_error(self, their_node_id, msg.temporary_channel_id); + } + + fn handle_tx_add_input(&self, their_node_id: &PublicKey, msg: &msgs::TxAddInput) { + ErroringMessageHandler::push_error(self, their_node_id, msg.channel_id); + } + + fn handle_tx_add_output(&self, their_node_id: &PublicKey, msg: &msgs::TxAddOutput) { + ErroringMessageHandler::push_error(self, their_node_id, msg.channel_id); + } + + fn handle_tx_remove_input(&self, their_node_id: &PublicKey, msg: &msgs::TxRemoveInput) { + ErroringMessageHandler::push_error(self, their_node_id, msg.channel_id); + } + + fn handle_tx_remove_output(&self, their_node_id: &PublicKey, msg: &msgs::TxRemoveOutput) { + ErroringMessageHandler::push_error(self, their_node_id, msg.channel_id); + } + + fn handle_tx_complete(&self, their_node_id: &PublicKey, msg: &msgs::TxComplete) { + ErroringMessageHandler::push_error(self, their_node_id, msg.channel_id); + } + + fn handle_tx_signatures(&self, their_node_id: &PublicKey, msg: &msgs::TxSignatures) { + ErroringMessageHandler::push_error(self, their_node_id, msg.channel_id); + } + + fn handle_tx_init_rbf(&self, their_node_id: &PublicKey, msg: &msgs::TxInitRbf) { + ErroringMessageHandler::push_error(self, their_node_id, msg.channel_id); + } + + fn handle_tx_ack_rbf(&self, their_node_id: &PublicKey, msg: &msgs::TxAckRbf) { + ErroringMessageHandler::push_error(self, their_node_id, msg.channel_id); + } + + fn handle_tx_abort(&self, their_node_id: &PublicKey, msg: &msgs::TxAbort) { + ErroringMessageHandler::push_error(self, their_node_id, msg.channel_id); + } } impl Deref for ErroringMessageHandler { type Target = ErroringMessageHandler; @@ -1342,9 +1386,15 @@ impl { self.message_handler.chan_handler.handle_open_channel(&their_node_id, their_features.clone().unwrap(), &msg); }, + wire::Message::OpenChannelV2(msg) => { + self.message_handler.chan_handler.handle_open_channel_v2(&their_node_id, their_features.clone().unwrap(), &msg); + }, wire::Message::AcceptChannel(msg) => { self.message_handler.chan_handler.handle_accept_channel(&their_node_id, their_features.clone().unwrap(), &msg); }, + wire::Message::AcceptChannelV2(msg) => { + self.message_handler.chan_handler.handle_accept_channel_v2(&their_node_id, their_features.clone().unwrap(), &msg); + }, wire::Message::FundingCreated(msg) => { self.message_handler.chan_handler.handle_funding_created(&their_node_id, &msg); @@ -1356,6 +1406,35 @@ impl { + self.message_handler.chan_handler.handle_tx_add_input(&their_node_id, &msg); + }, + wire::Message::TxAddOutput(msg) => { + self.message_handler.chan_handler.handle_tx_add_output(&their_node_id, &msg); + }, + wire::Message::TxRemoveInput(msg) => { + self.message_handler.chan_handler.handle_tx_remove_input(&their_node_id, &msg); + }, + wire::Message::TxRemoveOutput(msg) => { + self.message_handler.chan_handler.handle_tx_remove_output(&their_node_id, &msg); + }, + wire::Message::TxComplete(msg) => { + self.message_handler.chan_handler.handle_tx_complete(&their_node_id, &msg); + }, + wire::Message::TxSignatures(msg) => { + self.message_handler.chan_handler.handle_tx_signatures(&their_node_id, &msg); + }, + wire::Message::TxInitRbf(msg) => { + self.message_handler.chan_handler.handle_tx_init_rbf(&their_node_id, &msg); + }, + wire::Message::TxAckRbf(msg) => { + self.message_handler.chan_handler.handle_tx_ack_rbf(&their_node_id, &msg); + }, + wire::Message::TxAbort(msg) => { + self.message_handler.chan_handler.handle_tx_abort(&their_node_id, &msg); + } + wire::Message::Shutdown(msg) => { self.message_handler.chan_handler.handle_shutdown(&their_node_id, their_features.as_ref().unwrap(), &msg); }, @@ -1607,12 +1686,24 @@ impl { + log_debug!(self.logger, "Handling SendAcceptChannelV2 event in peer_handler for node {} for channel {}", + log_pubkey!(node_id), + log_bytes!(msg.temporary_channel_id)); + self.enqueue_message(&mut *get_peer_for_forwarding!(node_id), msg); + }, MessageSendEvent::SendOpenChannel { ref node_id, ref msg } => { log_debug!(self.logger, "Handling SendOpenChannel event in peer_handler for node {} for channel {}", log_pubkey!(node_id), log_bytes!(msg.temporary_channel_id)); self.enqueue_message(&mut *get_peer_for_forwarding!(node_id), msg); }, + MessageSendEvent::SendOpenChannelV2 { ref node_id, ref msg } => { + log_debug!(self.logger, "Handling SendOpenChannelV2 event in peer_handler for node {} for channel {}", + log_pubkey!(node_id), + log_bytes!(msg.temporary_channel_id)); + self.enqueue_message(&mut *get_peer_for_forwarding!(node_id), msg); + }, MessageSendEvent::SendFundingCreated { ref node_id, ref msg } => { log_debug!(self.logger, "Handling SendFundingCreated event in peer_handler for node {} for channel {} (which becomes {})", log_pubkey!(node_id), @@ -1634,6 +1725,60 @@ impl { + log_debug!(self.logger, "Handling SendTxAddInput event in peer_handler for node {} for channel {}", + log_pubkey!(node_id), + log_bytes!(msg.channel_id)); + self.enqueue_message(&mut *get_peer_for_forwarding!(node_id), msg); + }, + MessageSendEvent::SendTxAddOutput { ref node_id, ref msg } => { + log_debug!(self.logger, "Handling SendTxAddOutput event in peer_handler for node {} for channel {}", + log_pubkey!(node_id), + log_bytes!(msg.channel_id)); + self.enqueue_message(&mut *get_peer_for_forwarding!(node_id), msg); + }, + MessageSendEvent::SendTxRemoveInput { ref node_id, ref msg } => { + log_debug!(self.logger, "Handling SendTxRemoveInput event in peer_handler for node {} for channel {}", + log_pubkey!(node_id), + log_bytes!(msg.channel_id)); + self.enqueue_message(&mut *get_peer_for_forwarding!(node_id), msg); + }, + MessageSendEvent::SendTxRemoveOutput { ref node_id, ref msg } => { + log_debug!(self.logger, "Handling SendTxRemoveOutput event in peer_handler for node {} for channel {}", + log_pubkey!(node_id), + log_bytes!(msg.channel_id)); + self.enqueue_message(&mut *get_peer_for_forwarding!(node_id), msg); + }, + MessageSendEvent::SendTxComplete { ref node_id, ref msg } => { + log_debug!(self.logger, "Handling SendTxComplete event in peer_handler for node {} for channel {}", + log_pubkey!(node_id), + log_bytes!(msg.channel_id)); + self.enqueue_message(&mut *get_peer_for_forwarding!(node_id), msg); + }, + MessageSendEvent::SendTxSignatures { ref node_id, ref msg } => { + log_debug!(self.logger, "Handling SendTxSignatures event in peer_handler for node {} for channel {}", + log_pubkey!(node_id), + log_bytes!(msg.channel_id)); + self.enqueue_message(&mut *get_peer_for_forwarding!(node_id), msg); + }, + MessageSendEvent::SendTxInitRbf { ref node_id, ref msg } => { + log_debug!(self.logger, "Handling SendTxInitRbf event in peer_handler for node {} for channel {}", + log_pubkey!(node_id), + log_bytes!(msg.channel_id)); + self.enqueue_message(&mut *get_peer_for_forwarding!(node_id), msg); + }, + MessageSendEvent::SendTxAckRbf { ref node_id, ref msg } => { + log_debug!(self.logger, "Handling SendTxAckRbf event in peer_handler for node {} for channel {}", + log_pubkey!(node_id), + log_bytes!(msg.channel_id)); + self.enqueue_message(&mut *get_peer_for_forwarding!(node_id), msg); + }, + MessageSendEvent::SendTxAbort { ref node_id, ref msg } => { + log_debug!(self.logger, "Handling SendTxAbort event in peer_handler for node {} for channel {}", + log_pubkey!(node_id), + log_bytes!(msg.channel_id)); + self.enqueue_message(&mut *get_peer_for_forwarding!(node_id), msg); + }, MessageSendEvent::SendAnnouncementSignatures { ref node_id, ref msg } => { log_debug!(self.logger, "Handling SendAnnouncementSignatures event in peer_handler for node {} for channel {})", log_pubkey!(node_id), diff --git a/lightning/src/ln/wire.rs b/lightning/src/ln/wire.rs index 2e968acc53e..882285ad7f7 100644 --- a/lightning/src/ln/wire.rs +++ b/lightning/src/ln/wire.rs @@ -54,9 +54,20 @@ pub(crate) enum Message where T: core::fmt::Debug + Type + TestEq { Ping(msgs::Ping), Pong(msgs::Pong), OpenChannel(msgs::OpenChannel), + OpenChannelV2(msgs::OpenChannelV2), AcceptChannel(msgs::AcceptChannel), + AcceptChannelV2(msgs::AcceptChannelV2), FundingCreated(msgs::FundingCreated), FundingSigned(msgs::FundingSigned), + TxAddInput(msgs::TxAddInput), + TxAddOutput(msgs::TxAddOutput), + TxRemoveInput(msgs::TxRemoveInput), + TxRemoveOutput(msgs::TxRemoveOutput), + TxComplete(msgs::TxComplete), + TxSignatures(msgs::TxSignatures), + TxInitRbf(msgs::TxInitRbf), + TxAckRbf(msgs::TxAckRbf), + TxAbort(msgs::TxAbort), ChannelReady(msgs::ChannelReady), Shutdown(msgs::Shutdown), ClosingSigned(msgs::ClosingSigned), @@ -95,9 +106,20 @@ impl Message where T: core::fmt::Debug + Type + TestEq { &Message::Ping(ref msg) => msg.type_id(), &Message::Pong(ref msg) => msg.type_id(), &Message::OpenChannel(ref msg) => msg.type_id(), + &Message::OpenChannelV2(ref msg) => msg.type_id(), &Message::AcceptChannel(ref msg) => msg.type_id(), + &Message::AcceptChannelV2(ref msg) => msg.type_id(), &Message::FundingCreated(ref msg) => msg.type_id(), &Message::FundingSigned(ref msg) => msg.type_id(), + &Message::TxAddInput(ref msg) => msg.type_id(), + &Message::TxAddOutput(ref msg) => msg.type_id(), + &Message::TxRemoveInput(ref msg) => msg.type_id(), + &Message::TxRemoveOutput(ref msg) => msg.type_id(), + &Message::TxComplete(ref msg) => msg.type_id(), + &Message::TxSignatures(ref msg) => msg.type_id(), + &Message::TxInitRbf(ref msg) => msg.type_id(), + &Message::TxAckRbf(ref msg) => msg.type_id(), + &Message::TxAbort(ref msg) => msg.type_id(), &Message::ChannelReady(ref msg) => msg.type_id(), &Message::Shutdown(ref msg) => msg.type_id(), &Message::ClosingSigned(ref msg) => msg.type_id(), @@ -135,7 +157,7 @@ impl Message where T: core::fmt::Debug + Type + TestEq { /// /// # Errors /// -/// Returns an error if the message payload code not be decoded as the specified type. +/// Returns an error if the message payload could not be decoded as the specified type. pub(crate) fn read(buffer: &mut R, custom_reader: H) -> Result, (msgs::DecodeError, Option)> where T: core::fmt::Debug + Type + Writeable, @@ -169,15 +191,48 @@ fn do_read(buffer: &mut R, message_type: u1 msgs::OpenChannel::TYPE => { Ok(Message::OpenChannel(Readable::read(buffer)?)) }, + msgs::OpenChannelV2::TYPE => { + Ok(Message::OpenChannelV2(Readable::read(buffer)?)) + }, msgs::AcceptChannel::TYPE => { Ok(Message::AcceptChannel(Readable::read(buffer)?)) }, + msgs::AcceptChannelV2::TYPE => { + Ok(Message::AcceptChannelV2(Readable::read(buffer)?)) + }, msgs::FundingCreated::TYPE => { Ok(Message::FundingCreated(Readable::read(buffer)?)) }, msgs::FundingSigned::TYPE => { Ok(Message::FundingSigned(Readable::read(buffer)?)) }, + msgs::TxAddInput::TYPE => { + Ok(Message::TxAddInput(Readable::read(buffer)?)) + }, + msgs::TxAddOutput::TYPE => { + Ok(Message::TxAddOutput(Readable::read(buffer)?)) + }, + msgs::TxRemoveInput::TYPE => { + Ok(Message::TxRemoveInput(Readable::read(buffer)?)) + }, + msgs::TxRemoveOutput::TYPE => { + Ok(Message::TxRemoveOutput(Readable::read(buffer)?)) + }, + msgs::TxComplete::TYPE => { + Ok(Message::TxComplete(Readable::read(buffer)?)) + }, + msgs::TxSignatures::TYPE => { + Ok(Message::TxSignatures(Readable::read(buffer)?)) + }, + msgs::TxInitRbf::TYPE => { + Ok(Message::TxInitRbf(Readable::read(buffer)?)) + }, + msgs::TxAckRbf::TYPE => { + Ok(Message::TxAckRbf(Readable::read(buffer)?)) + }, + msgs::TxAbort::TYPE => { + Ok(Message::TxAbort(Readable::read(buffer)?)) + }, msgs::ChannelReady::TYPE => { Ok(Message::ChannelReady(Readable::read(buffer)?)) }, diff --git a/lightning/src/util/events.rs b/lightning/src/util/events.rs index 37a146c3dac..31116e0192f 100644 --- a/lightning/src/util/events.rs +++ b/lightning/src/util/events.rs @@ -15,7 +15,8 @@ //! few other things. use crate::chain::keysinterface::SpendableOutputDescriptor; -use crate::ln::chan_utils::HTLCOutputInCommitment; +#[cfg(opt_anchors)] +use crate::chan_utils::HTLCOutputInCommitment; use crate::ln::channelmanager::PaymentId; use crate::ln::channel::FUNDING_CONF_DEADLINE_BLOCKS; use crate::ln::features::ChannelTypeFeatures; @@ -26,7 +27,7 @@ use crate::routing::gossip::NetworkUpdate; use crate::util::ser::{BigSize, FixedLengthReader, Writeable, Writer, MaybeReadable, Readable, VecReadWrapper, VecWriteWrapper}; use crate::routing::router::{RouteHop, RouteParameters}; -use bitcoin::{PackedLockTime, Transaction, OutPoint}; +use bitcoin::{PackedLockTime, Transaction}; use bitcoin::blockdata::script::Script; use bitcoin::hashes::Hash; use bitcoin::hashes::sha256::Hash as Sha256; @@ -1170,6 +1171,14 @@ pub enum MessageSendEvent { /// The message which should be sent. msg: msgs::AcceptChannel, }, + /// Used to indicate that we've accepted a V2 channel open and should send the accept_channel2 + /// message provided to the given peer. + SendAcceptChannelV2 { + /// The node_id of the node which should receive this message + node_id: PublicKey, + /// The message which should be sent. + msg: msgs::AcceptChannelV2, + }, /// Used to indicate that we've initiated a channel open and should send the open_channel /// message provided to the given peer. SendOpenChannel { @@ -1178,6 +1187,14 @@ pub enum MessageSendEvent { /// The message which should be sent. msg: msgs::OpenChannel, }, + /// Used to indicate that we've initiated a V2 channel open and should send the open_channel2 + /// message provided to the given peer. + SendOpenChannelV2 { + /// The node_id of the node which should receive this message + node_id: PublicKey, + /// The message which should be sent. + msg: msgs::OpenChannelV2, + }, /// Used to indicate that a funding_created message should be sent to the peer with the given node_id. SendFundingCreated { /// The node_id of the node which should receive this message @@ -1192,6 +1209,69 @@ pub enum MessageSendEvent { /// The message which should be sent. msg: msgs::FundingSigned, }, + /// Used to indicate that a tx_add_input message should be sent to the peer with the given node_id. + SendTxAddInput { + /// The node_id of the node which should receive this message + node_id: PublicKey, + /// The message which should be sent. + msg: msgs::TxAddInput, + }, + /// Used to indicate that a tx_add_output message should be sent to the peer with the given node_id. + SendTxAddOutput { + /// The node_id of the node which should receive this message + node_id: PublicKey, + /// The message which should be sent. + msg: msgs::TxAddOutput, + }, + /// Used to indicate that a tx_remove_input message should be sent to the peer with the given node_id. + SendTxRemoveInput { + /// The node_id of the node which should receive this message + node_id: PublicKey, + /// The message which should be sent. + msg: msgs::TxRemoveInput, + }, + /// Used to indicate that a tx_remove_output message should be sent to the peer with the given node_id. + SendTxRemoveOutput { + /// The node_id of the node which should receive this message + node_id: PublicKey, + /// The message which should be sent. + msg: msgs::TxRemoveOutput, + }, + /// Used to indicate that a tx_complete message should be sent to the peer with the given node_id. + SendTxComplete { + /// The node_id of the node which should receive this message + node_id: PublicKey, + /// The message which should be sent. + msg: msgs::TxComplete, + }, + /// Used to indicate that a tx_signatures message should be sent to the peer with the given node_id. + SendTxSignatures { + /// The node_id of the node which should receive this message + node_id: PublicKey, + /// The message which should be sent. + msg: msgs::TxSignatures, + }, + /// Used to indicate that a tx_init_rbf message should be sent to the peer with the given node_id. + SendTxInitRbf { + /// The node_id of the node which should receive this message + node_id: PublicKey, + /// The message which should be sent. + msg: msgs::TxInitRbf, + }, + /// Used to indicate that a tx_ack_rbf message should be sent to the peer with the given node_id. + SendTxAckRbf { + /// The node_id of the node which should receive this message + node_id: PublicKey, + /// The message which should be sent. + msg: msgs::TxAckRbf, + }, + /// Used to indicate that a tx_abort message should be sent to the peer with the given node_id. + SendTxAbort { + /// The node_id of the node which should receive this message + node_id: PublicKey, + /// The message which should be sent. + msg: msgs::TxAddInput, + }, /// Used to indicate that a channel_ready message should be sent to the peer with the given node_id. SendChannelReady { /// The node_id of the node which should receive these message(s) diff --git a/lightning/src/util/test_utils.rs b/lightning/src/util/test_utils.rs index 89bf27de280..dd55763c1c0 100644 --- a/lightning/src/util/test_utils.rs +++ b/lightning/src/util/test_utils.rs @@ -365,6 +365,50 @@ impl msgs::ChannelMessageHandler for TestChannelMessageHandler { fn provided_init_features(&self, _their_init_features: &PublicKey) -> InitFeatures { channelmanager::provided_init_features() } + + fn handle_open_channel_v2(&self, _their_node_id: &PublicKey, _their_features: InitFeatures, msg: &msgs::OpenChannelV2) { + self.received_msg(wire::Message::OpenChannelV2(msg.clone())); + } + + fn handle_accept_channel_v2(&self, _their_node_id: &PublicKey, _their_features: InitFeatures, msg: &msgs::AcceptChannelV2) { + self.received_msg(wire::Message::AcceptChannelV2(msg.clone())); + } + + fn handle_tx_add_input(&self, _their_node_id: &PublicKey, msg: &msgs::TxAddInput) { + self.received_msg(wire::Message::TxAddInput(msg.clone())); + } + + fn handle_tx_add_output(&self, _their_node_id: &PublicKey, msg: &msgs::TxAddOutput) { + self.received_msg(wire::Message::TxAddOutput(msg.clone())); + } + + fn handle_tx_remove_input(&self, _their_node_id: &PublicKey, msg: &msgs::TxRemoveInput) { + self.received_msg(wire::Message::TxRemoveInput(msg.clone())); + } + + fn handle_tx_remove_output(&self, _their_node_id: &PublicKey, msg: &msgs::TxRemoveOutput) { + self.received_msg(wire::Message::TxRemoveOutput(msg.clone())); + } + + fn handle_tx_complete(&self, _their_node_id: &PublicKey, msg: &msgs::TxComplete) { + self.received_msg(wire::Message::TxComplete(msg.clone())); + } + + fn handle_tx_signatures(&self, _their_node_id: &PublicKey, msg: &msgs::TxSignatures) { + self.received_msg(wire::Message::TxSignatures(msg.clone())); + } + + fn handle_tx_init_rbf(&self, _their_node_id: &PublicKey, msg: &msgs::TxInitRbf) { + self.received_msg(wire::Message::TxInitRbf(msg.clone())); + } + + fn handle_tx_ack_rbf(&self, _their_node_id: &PublicKey, msg: &msgs::TxAckRbf) { + self.received_msg(wire::Message::TxAckRbf(msg.clone())); + } + + fn handle_tx_abort(&self, _their_node_id: &PublicKey, msg: &msgs::TxAbort) { + self.received_msg(wire::Message::TxAbort(msg.clone())); + } } impl events::MessageSendEventsProvider for TestChannelMessageHandler {