From: Duncan Dean Date: Tue, 1 Nov 2022 14:12:06 +0000 (+0200) Subject: Add new wire messaging and events but don't handle them X-Git-Tag: v0.0.116-alpha1~48^2~1 X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=commitdiff_plain;h=4e9a358baad21496734334e723db5a6645e6a205;p=rust-lightning Add new wire messaging and events but don't handle them --- diff --git a/lightning-net-tokio/src/lib.rs b/lightning-net-tokio/src/lib.rs index 2a93ca433..2f0c96396 100644 --- a/lightning-net-tokio/src/lib.rs +++ b/lightning-net-tokio/src/lib.rs @@ -529,6 +529,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, _msg: &OpenChannelV2) {} + fn handle_accept_channel_v2(&self, _their_node_id: &PublicKey, _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) { if *their_node_id == self.expected_pubkey { self.disconnected_flag.store(true, Ordering::SeqCst); diff --git a/lightning/src/events/mod.rs b/lightning/src/events/mod.rs index 4d8b8cee9..7c7152dda 100644 --- a/lightning/src/events/mod.rs +++ b/lightning/src/events/mod.rs @@ -1436,6 +1436,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 { @@ -1444,6 +1452,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 @@ -1458,6 +1474,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/ln/channel.rs b/lightning/src/ln/channel.rs index 3a324e6f4..8956ed270 100644 --- a/lightning/src/ln/channel.rs +++ b/lightning/src/ln/channel.rs @@ -5695,8 +5695,9 @@ impl Channel { next_remote_commitment_number: INITIAL_COMMITMENT_NUMBER - self.cur_counterparty_commitment_transaction_number - 1, your_last_per_commitment_secret: remote_last_secret, my_current_per_commitment_point: dummy_pubkey, - // TODO(dual_funding): If we've sent `commtiment_signed` for an interactive transaction construction but have not received `tx_signatures` - // we MUST set `next_funding_txid` to the txid of that interactive transaction, else we MUST NOT set it. + // TODO(dual_funding): If we've sent `commtiment_signed` for an interactive transaction + // construction but have not received `tx_signatures` we MUST set `next_funding_txid` to the + // txid of that interactive transaction, else we MUST NOT set it. next_funding_txid: None, } } diff --git a/lightning/src/ln/channelmanager.rs b/lightning/src/ln/channelmanager.rs index bf863797a..42cda1456 100644 --- a/lightning/src/ln/channelmanager.rs +++ b/lightning/src/ln/channelmanager.rs @@ -6387,11 +6387,23 @@ where let _ = handle_error!(self, self.internal_open_channel(counterparty_node_id, msg), *counterparty_node_id); } + fn handle_open_channel_v2(&self, counterparty_node_id: &PublicKey, msg: &msgs::OpenChannelV2) { + let _: Result<(), _> = handle_error!(self, Err(MsgHandleErrInternal::send_err_msg_no_close( + "Dual-funded channels not supported".to_owned(), + msg.temporary_channel_id.clone())), *counterparty_node_id); + } + fn handle_accept_channel(&self, counterparty_node_id: &PublicKey, 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, msg), *counterparty_node_id); } + fn handle_accept_channel_v2(&self, counterparty_node_id: &PublicKey, msg: &msgs::AcceptChannelV2) { + let _: Result<(), _> = handle_error!(self, Err(MsgHandleErrInternal::send_err_msg_no_close( + "Dual-funded channels not supported".to_owned(), + msg.temporary_channel_id.clone())), *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); @@ -6494,23 +6506,40 @@ where }); pending_msg_events.retain(|msg| { match msg { + // V1 Channel Establishment &events::MessageSendEvent::SendAcceptChannel { .. } => false, &events::MessageSendEvent::SendOpenChannel { .. } => false, &events::MessageSendEvent::SendFundingCreated { .. } => false, &events::MessageSendEvent::SendFundingSigned { .. } => false, + // V2 Channel Establishment + &events::MessageSendEvent::SendAcceptChannelV2 { .. } => false, + &events::MessageSendEvent::SendOpenChannelV2 { .. } => false, + // Common Channel Establishment &events::MessageSendEvent::SendChannelReady { .. } => false, &events::MessageSendEvent::SendAnnouncementSignatures { .. } => false, + // Interactive Transaction Construction + &events::MessageSendEvent::SendTxAddInput { .. } => false, + &events::MessageSendEvent::SendTxAddOutput { .. } => false, + &events::MessageSendEvent::SendTxRemoveInput { .. } => false, + &events::MessageSendEvent::SendTxRemoveOutput { .. } => false, + &events::MessageSendEvent::SendTxComplete { .. } => false, + &events::MessageSendEvent::SendTxSignatures { .. } => false, + &events::MessageSendEvent::SendTxInitRbf { .. } => false, + &events::MessageSendEvent::SendTxAckRbf { .. } => false, + &events::MessageSendEvent::SendTxAbort { .. } => false, + // Channel Operations &events::MessageSendEvent::UpdateHTLCs { .. } => false, &events::MessageSendEvent::SendRevokeAndACK { .. } => false, &events::MessageSendEvent::SendClosingSigned { .. } => false, &events::MessageSendEvent::SendShutdown { .. } => false, &events::MessageSendEvent::SendChannelReestablish { .. } => false, + &events::MessageSendEvent::HandleError { .. } => false, + // Gossip &events::MessageSendEvent::SendChannelAnnouncement { .. } => false, &events::MessageSendEvent::BroadcastChannelAnnouncement { .. } => true, &events::MessageSendEvent::BroadcastChannelUpdate { .. } => true, &events::MessageSendEvent::BroadcastNodeAnnouncement { .. } => true, &events::MessageSendEvent::SendChannelUpdate { .. } => false, - &events::MessageSendEvent::HandleError { .. } => false, &events::MessageSendEvent::SendChannelRangeQuery { .. } => false, &events::MessageSendEvent::SendShortIdsQuery { .. } => false, &events::MessageSendEvent::SendReplyChannelRange { .. } => false, @@ -6667,6 +6696,60 @@ where fn provided_init_features(&self, _their_init_features: &PublicKey) -> InitFeatures { provided_init_features(&self.default_configuration) } + + fn handle_tx_add_input(&self, counterparty_node_id: &PublicKey, msg: &msgs::TxAddInput) { + let _: Result<(), _> = handle_error!(self, Err(MsgHandleErrInternal::send_err_msg_no_close( + "Dual-funded channels not supported".to_owned(), + msg.channel_id.clone())), *counterparty_node_id); + } + + fn handle_tx_add_output(&self, counterparty_node_id: &PublicKey, msg: &msgs::TxAddOutput) { + let _: Result<(), _> = handle_error!(self, Err(MsgHandleErrInternal::send_err_msg_no_close( + "Dual-funded channels not supported".to_owned(), + msg.channel_id.clone())), *counterparty_node_id); + } + + fn handle_tx_remove_input(&self, counterparty_node_id: &PublicKey, msg: &msgs::TxRemoveInput) { + let _: Result<(), _> = handle_error!(self, Err(MsgHandleErrInternal::send_err_msg_no_close( + "Dual-funded channels not supported".to_owned(), + msg.channel_id.clone())), *counterparty_node_id); + } + + fn handle_tx_remove_output(&self, counterparty_node_id: &PublicKey, msg: &msgs::TxRemoveOutput) { + let _: Result<(), _> = handle_error!(self, Err(MsgHandleErrInternal::send_err_msg_no_close( + "Dual-funded channels not supported".to_owned(), + msg.channel_id.clone())), *counterparty_node_id); + } + + fn handle_tx_complete(&self, counterparty_node_id: &PublicKey, msg: &msgs::TxComplete) { + let _: Result<(), _> = handle_error!(self, Err(MsgHandleErrInternal::send_err_msg_no_close( + "Dual-funded channels not supported".to_owned(), + msg.channel_id.clone())), *counterparty_node_id); + } + + fn handle_tx_signatures(&self, counterparty_node_id: &PublicKey, msg: &msgs::TxSignatures) { + let _: Result<(), _> = handle_error!(self, Err(MsgHandleErrInternal::send_err_msg_no_close( + "Dual-funded channels not supported".to_owned(), + msg.channel_id.clone())), *counterparty_node_id); + } + + fn handle_tx_init_rbf(&self, counterparty_node_id: &PublicKey, msg: &msgs::TxInitRbf) { + let _: Result<(), _> = handle_error!(self, Err(MsgHandleErrInternal::send_err_msg_no_close( + "Dual-funded channels not supported".to_owned(), + msg.channel_id.clone())), *counterparty_node_id); + } + + fn handle_tx_ack_rbf(&self, counterparty_node_id: &PublicKey, msg: &msgs::TxAckRbf) { + let _: Result<(), _> = handle_error!(self, Err(MsgHandleErrInternal::send_err_msg_no_close( + "Dual-funded channels not supported".to_owned(), + msg.channel_id.clone())), *counterparty_node_id); + } + + fn handle_tx_abort(&self, counterparty_node_id: &PublicKey, msg: &msgs::TxAbort) { + let _: Result<(), _> = handle_error!(self, Err(MsgHandleErrInternal::send_err_msg_no_close( + "Dual-funded channels not supported".to_owned(), + msg.channel_id.clone())), *counterparty_node_id); + } } /// Fetches the set of [`NodeFeatures`] flags which are provided by or required by diff --git a/lightning/src/ln/functional_test_utils.rs b/lightning/src/ln/functional_test_utils.rs index 47df7c30e..766fad2d7 100644 --- a/lightning/src/ln/functional_test_utils.rs +++ b/lightning/src/ln/functional_test_utils.rs @@ -724,6 +724,39 @@ pub fn remove_first_msg_event_to_node(msg_node_id: &PublicKey, msg_events: &mut MessageSendEvent::SendGossipTimestampFilter { node_id, .. } => { node_id == msg_node_id }, + MessageSendEvent::SendAcceptChannelV2 { node_id, .. } => { + node_id == msg_node_id + }, + MessageSendEvent::SendOpenChannelV2 { node_id, .. } => { + node_id == msg_node_id + }, + MessageSendEvent::SendTxAddInput { node_id, .. } => { + node_id == msg_node_id + }, + MessageSendEvent::SendTxAddOutput { node_id, .. } => { + node_id == msg_node_id + }, + MessageSendEvent::SendTxRemoveInput { node_id, .. } => { + node_id == msg_node_id + }, + MessageSendEvent::SendTxRemoveOutput { node_id, .. } => { + node_id == msg_node_id + }, + MessageSendEvent::SendTxComplete { node_id, .. } => { + node_id == msg_node_id + }, + MessageSendEvent::SendTxSignatures { node_id, .. } => { + node_id == msg_node_id + }, + MessageSendEvent::SendTxInitRbf { node_id, .. } => { + node_id == msg_node_id + }, + MessageSendEvent::SendTxAckRbf { node_id, .. } => { + node_id == msg_node_id + }, + MessageSendEvent::SendTxAbort { node_id, .. } => { + node_id == msg_node_id + }, }}); if ev_index.is_some() { msg_events.remove(ev_index.unwrap()) diff --git a/lightning/src/ln/msgs.rs b/lightning/src/ln/msgs.rs index 2124d9055..27f8544e3 100644 --- a/lightning/src/ln/msgs.rs +++ b/lightning/src/ln/msgs.rs @@ -1237,8 +1237,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, msg: &OpenChannel); + /// Handle an incoming `open_channel2` message from the given peer. + fn handle_open_channel_v2(&self, their_node_id: &PublicKey, msg: &OpenChannelV2); /// Handle an incoming `accept_channel` message from the given peer. fn handle_accept_channel(&self, their_node_id: &PublicKey, msg: &AcceptChannel); + /// Handle an incoming `accept_channel2` message from the given peer. + fn handle_accept_channel_v2(&self, their_node_id: &PublicKey, 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. @@ -1252,6 +1256,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 046bbad92..0659412f7 100644 --- a/lightning/src/ln/peer_handler.rs +++ b/lightning/src/ln/peer_handler.rs @@ -252,7 +252,52 @@ impl ChannelMessageHandler for ErroringMessageHandler { features.set_zero_conf_optional(); features } + + fn handle_open_channel_v2(&self, their_node_id: &PublicKey, msg: &msgs::OpenChannelV2) { + ErroringMessageHandler::push_error(self, their_node_id, msg.temporary_channel_id); + } + + fn handle_accept_channel_v2(&self, their_node_id: &PublicKey, 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; fn deref(&self) -> &Self { self } @@ -1497,9 +1542,15 @@ impl { self.message_handler.chan_handler.handle_open_channel(&their_node_id, &msg); }, + wire::Message::OpenChannelV2(msg) => { + self.message_handler.chan_handler.handle_open_channel_v2(&their_node_id, &msg); + }, wire::Message::AcceptChannel(msg) => { self.message_handler.chan_handler.handle_accept_channel(&their_node_id, &msg); }, + wire::Message::AcceptChannelV2(msg) => { + self.message_handler.chan_handler.handle_accept_channel_v2(&their_node_id, &msg); + }, wire::Message::FundingCreated(msg) => { self.message_handler.chan_handler.handle_funding_created(&their_node_id, &msg); @@ -1511,6 +1562,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, &msg); }, @@ -1776,12 +1856,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), @@ -1803,6 +1895,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 32447e897..1a01e3382 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/test_utils.rs b/lightning/src/util/test_utils.rs index 658876fe3..ee5180be7 100644 --- a/lightning/src/util/test_utils.rs +++ b/lightning/src/util/test_utils.rs @@ -469,6 +469,50 @@ impl msgs::ChannelMessageHandler for TestChannelMessageHandler { fn provided_init_features(&self, _their_init_features: &PublicKey) -> InitFeatures { channelmanager::provided_init_features(&UserConfig::default()) } + + fn handle_open_channel_v2(&self, _their_node_id: &PublicKey, msg: &msgs::OpenChannelV2) { + self.received_msg(wire::Message::OpenChannelV2(msg.clone())); + } + + fn handle_accept_channel_v2(&self, _their_node_id: &PublicKey, 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 {