Skip to content

Commit 5ebb518

Browse files
committed
Add new wire messaging and events but don't handle them
1 parent 97e646e commit 5ebb518

File tree

8 files changed

+477
-2
lines changed

8 files changed

+477
-2
lines changed

lightning-net-tokio/src/lib.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -598,6 +598,17 @@ mod tests {
598598
fn handle_update_fee(&self, _their_node_id: &PublicKey, _msg: &UpdateFee) {}
599599
fn handle_announcement_signatures(&self, _their_node_id: &PublicKey, _msg: &AnnouncementSignatures) {}
600600
fn handle_channel_update(&self, _their_node_id: &PublicKey, _msg: &ChannelUpdate) {}
601+
fn handle_open_channel_v2(&self, _their_node_id: &PublicKey, _msg: &OpenChannelV2) {}
602+
fn handle_accept_channel_v2(&self, _their_node_id: &PublicKey, _msg: &AcceptChannelV2) {}
603+
fn handle_tx_add_input(&self, _their_node_id: &PublicKey, _msg: &TxAddInput) {}
604+
fn handle_tx_add_output(&self, _their_node_id: &PublicKey, _msg: &TxAddOutput) {}
605+
fn handle_tx_remove_input(&self, _their_node_id: &PublicKey, _msg: &TxRemoveInput) {}
606+
fn handle_tx_remove_output(&self, _their_node_id: &PublicKey, _msg: &TxRemoveOutput) {}
607+
fn handle_tx_complete(&self, _their_node_id: &PublicKey, _msg: &TxComplete) {}
608+
fn handle_tx_signatures(&self, _their_node_id: &PublicKey, _msg: &TxSignatures) {}
609+
fn handle_tx_init_rbf(&self, _their_node_id: &PublicKey, _msg: &TxInitRbf) {}
610+
fn handle_tx_ack_rbf(&self, _their_node_id: &PublicKey, _msg: &TxAckRbf) {}
611+
fn handle_tx_abort(&self, _their_node_id: &PublicKey, _msg: &TxAbort) {}
601612
fn peer_disconnected(&self, their_node_id: &PublicKey) {
602613
if *their_node_id == self.expected_pubkey {
603614
self.disconnected_flag.store(true, Ordering::SeqCst);

lightning/src/events/mod.rs

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1437,6 +1437,14 @@ pub enum MessageSendEvent {
14371437
/// The message which should be sent.
14381438
msg: msgs::AcceptChannel,
14391439
},
1440+
/// Used to indicate that we've accepted a V2 channel open and should send the accept_channel2
1441+
/// message provided to the given peer.
1442+
SendAcceptChannelV2 {
1443+
/// The node_id of the node which should receive this message
1444+
node_id: PublicKey,
1445+
/// The message which should be sent.
1446+
msg: msgs::AcceptChannelV2,
1447+
},
14401448
/// Used to indicate that we've initiated a channel open and should send the open_channel
14411449
/// message provided to the given peer.
14421450
SendOpenChannel {
@@ -1445,6 +1453,14 @@ pub enum MessageSendEvent {
14451453
/// The message which should be sent.
14461454
msg: msgs::OpenChannel,
14471455
},
1456+
/// Used to indicate that we've initiated a V2 channel open and should send the open_channel2
1457+
/// message provided to the given peer.
1458+
SendOpenChannelV2 {
1459+
/// The node_id of the node which should receive this message
1460+
node_id: PublicKey,
1461+
/// The message which should be sent.
1462+
msg: msgs::OpenChannelV2,
1463+
},
14481464
/// Used to indicate that a funding_created message should be sent to the peer with the given node_id.
14491465
SendFundingCreated {
14501466
/// The node_id of the node which should receive this message
@@ -1459,6 +1475,69 @@ pub enum MessageSendEvent {
14591475
/// The message which should be sent.
14601476
msg: msgs::FundingSigned,
14611477
},
1478+
/// Used to indicate that a tx_add_input message should be sent to the peer with the given node_id.
1479+
SendTxAddInput {
1480+
/// The node_id of the node which should receive this message
1481+
node_id: PublicKey,
1482+
/// The message which should be sent.
1483+
msg: msgs::TxAddInput,
1484+
},
1485+
/// Used to indicate that a tx_add_output message should be sent to the peer with the given node_id.
1486+
SendTxAddOutput {
1487+
/// The node_id of the node which should receive this message
1488+
node_id: PublicKey,
1489+
/// The message which should be sent.
1490+
msg: msgs::TxAddOutput,
1491+
},
1492+
/// Used to indicate that a tx_remove_input message should be sent to the peer with the given node_id.
1493+
SendTxRemoveInput {
1494+
/// The node_id of the node which should receive this message
1495+
node_id: PublicKey,
1496+
/// The message which should be sent.
1497+
msg: msgs::TxRemoveInput,
1498+
},
1499+
/// Used to indicate that a tx_remove_output message should be sent to the peer with the given node_id.
1500+
SendTxRemoveOutput {
1501+
/// The node_id of the node which should receive this message
1502+
node_id: PublicKey,
1503+
/// The message which should be sent.
1504+
msg: msgs::TxRemoveOutput,
1505+
},
1506+
/// Used to indicate that a tx_complete message should be sent to the peer with the given node_id.
1507+
SendTxComplete {
1508+
/// The node_id of the node which should receive this message
1509+
node_id: PublicKey,
1510+
/// The message which should be sent.
1511+
msg: msgs::TxComplete,
1512+
},
1513+
/// Used to indicate that a tx_signatures message should be sent to the peer with the given node_id.
1514+
SendTxSignatures {
1515+
/// The node_id of the node which should receive this message
1516+
node_id: PublicKey,
1517+
/// The message which should be sent.
1518+
msg: msgs::TxSignatures,
1519+
},
1520+
/// Used to indicate that a tx_init_rbf message should be sent to the peer with the given node_id.
1521+
SendTxInitRbf {
1522+
/// The node_id of the node which should receive this message
1523+
node_id: PublicKey,
1524+
/// The message which should be sent.
1525+
msg: msgs::TxInitRbf,
1526+
},
1527+
/// Used to indicate that a tx_ack_rbf message should be sent to the peer with the given node_id.
1528+
SendTxAckRbf {
1529+
/// The node_id of the node which should receive this message
1530+
node_id: PublicKey,
1531+
/// The message which should be sent.
1532+
msg: msgs::TxAckRbf,
1533+
},
1534+
/// Used to indicate that a tx_abort message should be sent to the peer with the given node_id.
1535+
SendTxAbort {
1536+
/// The node_id of the node which should receive this message
1537+
node_id: PublicKey,
1538+
/// The message which should be sent.
1539+
msg: msgs::TxAddInput,
1540+
},
14621541
/// Used to indicate that a channel_ready message should be sent to the peer with the given node_id.
14631542
SendChannelReady {
14641543
/// The node_id of the node which should receive these message(s)

lightning/src/ln/channelmanager.rs

Lines changed: 84 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6367,11 +6367,23 @@ where
63676367
let _ = handle_error!(self, self.internal_open_channel(counterparty_node_id, msg), *counterparty_node_id);
63686368
}
63696369

6370+
fn handle_open_channel_v2(&self, counterparty_node_id: &PublicKey, msg: &msgs::OpenChannelV2) {
6371+
let _: Result<(), _> = handle_error!(self, Err(MsgHandleErrInternal::send_err_msg_no_close(
6372+
"Dual-funded channels not supported".to_owned(),
6373+
msg.temporary_channel_id.clone())), *counterparty_node_id);
6374+
}
6375+
63706376
fn handle_accept_channel(&self, counterparty_node_id: &PublicKey, msg: &msgs::AcceptChannel) {
63716377
let _persistence_guard = PersistenceNotifierGuard::notify_on_drop(&self.total_consistency_lock, &self.persistence_notifier);
63726378
let _ = handle_error!(self, self.internal_accept_channel(counterparty_node_id, msg), *counterparty_node_id);
63736379
}
63746380

6381+
fn handle_accept_channel_v2(&self, counterparty_node_id: &PublicKey, msg: &msgs::AcceptChannelV2) {
6382+
let _: Result<(), _> = handle_error!(self, Err(MsgHandleErrInternal::send_err_msg_no_close(
6383+
"Dual-funded channels not supported".to_owned(),
6384+
msg.temporary_channel_id.clone())), *counterparty_node_id);
6385+
}
6386+
63756387
fn handle_funding_created(&self, counterparty_node_id: &PublicKey, msg: &msgs::FundingCreated) {
63766388
let _persistence_guard = PersistenceNotifierGuard::notify_on_drop(&self.total_consistency_lock, &self.persistence_notifier);
63776389
let _ = handle_error!(self, self.internal_funding_created(counterparty_node_id, msg), *counterparty_node_id);
@@ -6474,23 +6486,40 @@ where
64746486
});
64756487
pending_msg_events.retain(|msg| {
64766488
match msg {
6489+
// V1 Channel Establishment
64776490
&events::MessageSendEvent::SendAcceptChannel { .. } => false,
64786491
&events::MessageSendEvent::SendOpenChannel { .. } => false,
64796492
&events::MessageSendEvent::SendFundingCreated { .. } => false,
64806493
&events::MessageSendEvent::SendFundingSigned { .. } => false,
6494+
// V2 Channel Establishment
6495+
&events::MessageSendEvent::SendAcceptChannelV2 { .. } => false,
6496+
&events::MessageSendEvent::SendOpenChannelV2 { .. } => false,
6497+
// Common Channel Establishment
64816498
&events::MessageSendEvent::SendChannelReady { .. } => false,
64826499
&events::MessageSendEvent::SendAnnouncementSignatures { .. } => false,
6500+
// Interactive Transaction Construction
6501+
&events::MessageSendEvent::SendTxAddInput { .. } => false,
6502+
&events::MessageSendEvent::SendTxAddOutput { .. } => false,
6503+
&events::MessageSendEvent::SendTxRemoveInput { .. } => false,
6504+
&events::MessageSendEvent::SendTxRemoveOutput { .. } => false,
6505+
&events::MessageSendEvent::SendTxComplete { .. } => false,
6506+
&events::MessageSendEvent::SendTxSignatures { .. } => false,
6507+
&events::MessageSendEvent::SendTxInitRbf { .. } => false,
6508+
&events::MessageSendEvent::SendTxAckRbf { .. } => false,
6509+
&events::MessageSendEvent::SendTxAbort { .. } => false,
6510+
// Channel Operations
64836511
&events::MessageSendEvent::UpdateHTLCs { .. } => false,
64846512
&events::MessageSendEvent::SendRevokeAndACK { .. } => false,
64856513
&events::MessageSendEvent::SendClosingSigned { .. } => false,
64866514
&events::MessageSendEvent::SendShutdown { .. } => false,
64876515
&events::MessageSendEvent::SendChannelReestablish { .. } => false,
6516+
&events::MessageSendEvent::HandleError { .. } => false,
6517+
// Gossip
64886518
&events::MessageSendEvent::SendChannelAnnouncement { .. } => false,
64896519
&events::MessageSendEvent::BroadcastChannelAnnouncement { .. } => true,
64906520
&events::MessageSendEvent::BroadcastChannelUpdate { .. } => true,
64916521
&events::MessageSendEvent::BroadcastNodeAnnouncement { .. } => true,
64926522
&events::MessageSendEvent::SendChannelUpdate { .. } => false,
6493-
&events::MessageSendEvent::HandleError { .. } => false,
64946523
&events::MessageSendEvent::SendChannelRangeQuery { .. } => false,
64956524
&events::MessageSendEvent::SendShortIdsQuery { .. } => false,
64966525
&events::MessageSendEvent::SendReplyChannelRange { .. } => false,
@@ -6647,6 +6676,60 @@ where
66476676
fn provided_init_features(&self, _their_init_features: &PublicKey) -> InitFeatures {
66486677
provided_init_features(&self.default_configuration)
66496678
}
6679+
6680+
fn handle_tx_add_input(&self, counterparty_node_id: &PublicKey, msg: &msgs::TxAddInput) {
6681+
let _: Result<(), _> = handle_error!(self, Err(MsgHandleErrInternal::send_err_msg_no_close(
6682+
"Dual-funded channels not supported".to_owned(),
6683+
msg.channel_id.clone())), *counterparty_node_id);
6684+
}
6685+
6686+
fn handle_tx_add_output(&self, counterparty_node_id: &PublicKey, msg: &msgs::TxAddOutput) {
6687+
let _: Result<(), _> = handle_error!(self, Err(MsgHandleErrInternal::send_err_msg_no_close(
6688+
"Dual-funded channels not supported".to_owned(),
6689+
msg.channel_id.clone())), *counterparty_node_id);
6690+
}
6691+
6692+
fn handle_tx_remove_input(&self, counterparty_node_id: &PublicKey, msg: &msgs::TxRemoveInput) {
6693+
let _: Result<(), _> = handle_error!(self, Err(MsgHandleErrInternal::send_err_msg_no_close(
6694+
"Dual-funded channels not supported".to_owned(),
6695+
msg.channel_id.clone())), *counterparty_node_id);
6696+
}
6697+
6698+
fn handle_tx_remove_output(&self, counterparty_node_id: &PublicKey, msg: &msgs::TxRemoveOutput) {
6699+
let _: Result<(), _> = handle_error!(self, Err(MsgHandleErrInternal::send_err_msg_no_close(
6700+
"Dual-funded channels not supported".to_owned(),
6701+
msg.channel_id.clone())), *counterparty_node_id);
6702+
}
6703+
6704+
fn handle_tx_complete(&self, counterparty_node_id: &PublicKey, msg: &msgs::TxComplete) {
6705+
let _: Result<(), _> = handle_error!(self, Err(MsgHandleErrInternal::send_err_msg_no_close(
6706+
"Dual-funded channels not supported".to_owned(),
6707+
msg.channel_id.clone())), *counterparty_node_id);
6708+
}
6709+
6710+
fn handle_tx_signatures(&self, counterparty_node_id: &PublicKey, msg: &msgs::TxSignatures) {
6711+
let _: Result<(), _> = handle_error!(self, Err(MsgHandleErrInternal::send_err_msg_no_close(
6712+
"Dual-funded channels not supported".to_owned(),
6713+
msg.channel_id.clone())), *counterparty_node_id);
6714+
}
6715+
6716+
fn handle_tx_init_rbf(&self, counterparty_node_id: &PublicKey, msg: &msgs::TxInitRbf) {
6717+
let _: Result<(), _> = handle_error!(self, Err(MsgHandleErrInternal::send_err_msg_no_close(
6718+
"Dual-funded channels not supported".to_owned(),
6719+
msg.channel_id.clone())), *counterparty_node_id);
6720+
}
6721+
6722+
fn handle_tx_ack_rbf(&self, counterparty_node_id: &PublicKey, msg: &msgs::TxAckRbf) {
6723+
let _: Result<(), _> = handle_error!(self, Err(MsgHandleErrInternal::send_err_msg_no_close(
6724+
"Dual-funded channels not supported".to_owned(),
6725+
msg.channel_id.clone())), *counterparty_node_id);
6726+
}
6727+
6728+
fn handle_tx_abort(&self, counterparty_node_id: &PublicKey, msg: &msgs::TxAbort) {
6729+
let _: Result<(), _> = handle_error!(self, Err(MsgHandleErrInternal::send_err_msg_no_close(
6730+
"Dual-funded channels not supported".to_owned(),
6731+
msg.channel_id.clone())), *counterparty_node_id);
6732+
}
66506733
}
66516734

66526735
/// Fetches the set of [`NodeFeatures`] flags which are provided by or required by

lightning/src/ln/functional_test_utils.rs

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -724,6 +724,39 @@ pub fn remove_first_msg_event_to_node(msg_node_id: &PublicKey, msg_events: &mut
724724
MessageSendEvent::SendGossipTimestampFilter { node_id, .. } => {
725725
node_id == msg_node_id
726726
},
727+
MessageSendEvent::SendAcceptChannelV2 { node_id, .. } => {
728+
node_id == msg_node_id
729+
},
730+
MessageSendEvent::SendOpenChannelV2 { node_id, .. } => {
731+
node_id == msg_node_id
732+
},
733+
MessageSendEvent::SendTxAddInput { node_id, .. } => {
734+
node_id == msg_node_id
735+
},
736+
MessageSendEvent::SendTxAddOutput { node_id, .. } => {
737+
node_id == msg_node_id
738+
},
739+
MessageSendEvent::SendTxRemoveInput { node_id, .. } => {
740+
node_id == msg_node_id
741+
},
742+
MessageSendEvent::SendTxRemoveOutput { node_id, .. } => {
743+
node_id == msg_node_id
744+
},
745+
MessageSendEvent::SendTxComplete { node_id, .. } => {
746+
node_id == msg_node_id
747+
},
748+
MessageSendEvent::SendTxSignatures { node_id, .. } => {
749+
node_id == msg_node_id
750+
},
751+
MessageSendEvent::SendTxInitRbf { node_id, .. } => {
752+
node_id == msg_node_id
753+
},
754+
MessageSendEvent::SendTxAckRbf { node_id, .. } => {
755+
node_id == msg_node_id
756+
},
757+
MessageSendEvent::SendTxAbort { node_id, .. } => {
758+
node_id == msg_node_id
759+
},
727760
}});
728761
if ev_index.is_some() {
729762
msg_events.remove(ev_index.unwrap())

lightning/src/ln/msgs.rs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1201,8 +1201,12 @@ pub trait ChannelMessageHandler : MessageSendEventsProvider {
12011201
// Channel init:
12021202
/// Handle an incoming `open_channel` message from the given peer.
12031203
fn handle_open_channel(&self, their_node_id: &PublicKey, msg: &OpenChannel);
1204+
/// Handle an incoming `open_channel2` message from the given peer.
1205+
fn handle_open_channel_v2(&self, their_node_id: &PublicKey, msg: &OpenChannelV2);
12041206
/// Handle an incoming `accept_channel` message from the given peer.
12051207
fn handle_accept_channel(&self, their_node_id: &PublicKey, msg: &AcceptChannel);
1208+
/// Handle an incoming `accept_channel2` message from the given peer.
1209+
fn handle_accept_channel_v2(&self, their_node_id: &PublicKey, msg: &AcceptChannelV2);
12061210
/// Handle an incoming `funding_created` message from the given peer.
12071211
fn handle_funding_created(&self, their_node_id: &PublicKey, msg: &FundingCreated);
12081212
/// Handle an incoming `funding_signed` message from the given peer.
@@ -1216,6 +1220,26 @@ pub trait ChannelMessageHandler : MessageSendEventsProvider {
12161220
/// Handle an incoming `closing_signed` message from the given peer.
12171221
fn handle_closing_signed(&self, their_node_id: &PublicKey, msg: &ClosingSigned);
12181222

1223+
// Interactive channel construction
1224+
/// Handle an incoming `tx_add_input message` from the given peer.
1225+
fn handle_tx_add_input(&self, their_node_id: &PublicKey, msg: &TxAddInput);
1226+
/// Handle an incoming `tx_add_output` message from the given peer.
1227+
fn handle_tx_add_output(&self, their_node_id: &PublicKey, msg: &TxAddOutput);
1228+
/// Handle an incoming `tx_remove_input` message from the given peer.
1229+
fn handle_tx_remove_input(&self, their_node_id: &PublicKey, msg: &TxRemoveInput);
1230+
/// Handle an incoming `tx_remove_output` message from the given peer.
1231+
fn handle_tx_remove_output(&self, their_node_id: &PublicKey, msg: &TxRemoveOutput);
1232+
/// Handle an incoming `tx_complete message` from the given peer.
1233+
fn handle_tx_complete(&self, their_node_id: &PublicKey, msg: &TxComplete);
1234+
/// Handle an incoming `tx_signatures` message from the given peer.
1235+
fn handle_tx_signatures(&self, their_node_id: &PublicKey, msg: &TxSignatures);
1236+
/// Handle an incoming `tx_init_rbf` message from the given peer.
1237+
fn handle_tx_init_rbf(&self, their_node_id: &PublicKey, msg: &TxInitRbf);
1238+
/// Handle an incoming `tx_ack_rbf` message from the given peer.
1239+
fn handle_tx_ack_rbf(&self, their_node_id: &PublicKey, msg: &TxAckRbf);
1240+
/// Handle an incoming `tx_abort message` from the given peer.
1241+
fn handle_tx_abort(&self, their_node_id: &PublicKey, msg: &TxAbort);
1242+
12191243
// HTLC handling:
12201244
/// Handle an incoming `update_add_htlc` message from the given peer.
12211245
fn handle_update_add_htlc(&self, their_node_id: &PublicKey, msg: &UpdateAddHTLC);

0 commit comments

Comments
 (0)