Skip to content

Commit

Permalink
Add new wire messaging and events but don't handle them
Browse files Browse the repository at this point in the history
  • Loading branch information
dunxen committed Apr 25, 2023
1 parent 6afd913 commit 3385a25
Show file tree
Hide file tree
Showing 8 changed files with 477 additions and 2 deletions.
11 changes: 11 additions & 0 deletions lightning-net-tokio/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -598,6 +598,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);
Expand Down
79 changes: 79 additions & 0 deletions lightning/src/events/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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
Expand All @@ -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)
Expand Down
85 changes: 84 additions & 1 deletion lightning/src/ln/channelmanager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6367,11 +6367,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);
Expand Down Expand Up @@ -6474,23 +6486,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,
Expand Down Expand Up @@ -6647,6 +6676,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
Expand Down
33 changes: 33 additions & 0 deletions lightning/src/ln/functional_test_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -723,6 +723,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())
Expand Down
24 changes: 24 additions & 0 deletions lightning/src/ln/msgs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1201,8 +1201,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.
Expand All @@ -1216,6 +1220,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);
Expand Down
Loading

0 comments on commit 3385a25

Please sign in to comment.