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 Nov 3, 2022
1 parent 70bfd3d commit a788fcd
Show file tree
Hide file tree
Showing 7 changed files with 496 additions and 3 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 @@ -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);
Expand Down
134 changes: 134 additions & 0 deletions lightning/src/ln/channelmanager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4503,6 +4503,13 @@ impl<M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelManager<M, T, K, F
Ok(())
}

fn internal_open_channel_v2(&self, _counterparty_node_id: &PublicKey, _their_features: InitFeatures,
msg: &msgs::OpenChannelV2) -> 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();
Expand All @@ -4529,6 +4536,13 @@ impl<M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelManager<M, T, K, F
Ok(())
}

fn internal_accept_channel_v2(&self, _counterparty_node_id: &PublicKey, _their_features: InitFeatures,
msg: &msgs::AcceptChannelV2) -> 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();
Expand Down Expand Up @@ -5158,6 +5172,60 @@ impl<M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelManager<M, T, K, F
Ok(())
}

fn internal_tx_add_input(&self, _counterparty_node_id: &PublicKey, msg: &msgs::TxAddInput) -> 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();
Expand Down Expand Up @@ -5964,11 +6032,21 @@ impl<M: Deref , T: Deref , K: Deref , F: Deref , L: Deref >
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);
Expand Down Expand Up @@ -6076,10 +6154,21 @@ impl<M: Deref , T: Deref , K: Deref , F: Deref , L: Deref >
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,
Expand Down Expand Up @@ -6206,6 +6295,51 @@ impl<M: Deref , T: Deref , K: Deref , F: Deref , L: Deref >
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
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 @@ -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.
Expand All @@ -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);
Expand Down
Loading

0 comments on commit a788fcd

Please sign in to comment.