Skip to content

Commit 9a63cb6

Browse files
committed
Add new wire messaging and events but don't handle them
1 parent 8b2d9ff commit 9a63cb6

File tree

9 files changed

+480
-4
lines changed

9 files changed

+480
-4
lines changed

lightning-net-tokio/src/lib.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -529,6 +529,17 @@ mod tests {
529529
fn handle_update_fee(&self, _their_node_id: &PublicKey, _msg: &UpdateFee) {}
530530
fn handle_announcement_signatures(&self, _their_node_id: &PublicKey, _msg: &AnnouncementSignatures) {}
531531
fn handle_channel_update(&self, _their_node_id: &PublicKey, _msg: &ChannelUpdate) {}
532+
fn handle_open_channel_v2(&self, _their_node_id: &PublicKey, _msg: &OpenChannelV2) {}
533+
fn handle_accept_channel_v2(&self, _their_node_id: &PublicKey, _msg: &AcceptChannelV2) {}
534+
fn handle_tx_add_input(&self, _their_node_id: &PublicKey, _msg: &TxAddInput) {}
535+
fn handle_tx_add_output(&self, _their_node_id: &PublicKey, _msg: &TxAddOutput) {}
536+
fn handle_tx_remove_input(&self, _their_node_id: &PublicKey, _msg: &TxRemoveInput) {}
537+
fn handle_tx_remove_output(&self, _their_node_id: &PublicKey, _msg: &TxRemoveOutput) {}
538+
fn handle_tx_complete(&self, _their_node_id: &PublicKey, _msg: &TxComplete) {}
539+
fn handle_tx_signatures(&self, _their_node_id: &PublicKey, _msg: &TxSignatures) {}
540+
fn handle_tx_init_rbf(&self, _their_node_id: &PublicKey, _msg: &TxInitRbf) {}
541+
fn handle_tx_ack_rbf(&self, _their_node_id: &PublicKey, _msg: &TxAckRbf) {}
542+
fn handle_tx_abort(&self, _their_node_id: &PublicKey, _msg: &TxAbort) {}
532543
fn peer_disconnected(&self, their_node_id: &PublicKey) {
533544
if *their_node_id == self.expected_pubkey {
534545
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
@@ -1436,6 +1436,14 @@ pub enum MessageSendEvent {
14361436
/// The message which should be sent.
14371437
msg: msgs::AcceptChannel,
14381438
},
1439+
/// Used to indicate that we've accepted a V2 channel open and should send the accept_channel2
1440+
/// message provided to the given peer.
1441+
SendAcceptChannelV2 {
1442+
/// The node_id of the node which should receive this message
1443+
node_id: PublicKey,
1444+
/// The message which should be sent.
1445+
msg: msgs::AcceptChannelV2,
1446+
},
14391447
/// Used to indicate that we've initiated a channel open and should send the open_channel
14401448
/// message provided to the given peer.
14411449
SendOpenChannel {
@@ -1444,6 +1452,14 @@ pub enum MessageSendEvent {
14441452
/// The message which should be sent.
14451453
msg: msgs::OpenChannel,
14461454
},
1455+
/// Used to indicate that we've initiated a V2 channel open and should send the open_channel2
1456+
/// message provided to the given peer.
1457+
SendOpenChannelV2 {
1458+
/// The node_id of the node which should receive this message
1459+
node_id: PublicKey,
1460+
/// The message which should be sent.
1461+
msg: msgs::OpenChannelV2,
1462+
},
14471463
/// Used to indicate that a funding_created message should be sent to the peer with the given node_id.
14481464
SendFundingCreated {
14491465
/// The node_id of the node which should receive this message
@@ -1458,6 +1474,69 @@ pub enum MessageSendEvent {
14581474
/// The message which should be sent.
14591475
msg: msgs::FundingSigned,
14601476
},
1477+
/// Used to indicate that a tx_add_input message should be sent to the peer with the given node_id.
1478+
SendTxAddInput {
1479+
/// The node_id of the node which should receive this message
1480+
node_id: PublicKey,
1481+
/// The message which should be sent.
1482+
msg: msgs::TxAddInput,
1483+
},
1484+
/// Used to indicate that a tx_add_output message should be sent to the peer with the given node_id.
1485+
SendTxAddOutput {
1486+
/// The node_id of the node which should receive this message
1487+
node_id: PublicKey,
1488+
/// The message which should be sent.
1489+
msg: msgs::TxAddOutput,
1490+
},
1491+
/// Used to indicate that a tx_remove_input message should be sent to the peer with the given node_id.
1492+
SendTxRemoveInput {
1493+
/// The node_id of the node which should receive this message
1494+
node_id: PublicKey,
1495+
/// The message which should be sent.
1496+
msg: msgs::TxRemoveInput,
1497+
},
1498+
/// Used to indicate that a tx_remove_output message should be sent to the peer with the given node_id.
1499+
SendTxRemoveOutput {
1500+
/// The node_id of the node which should receive this message
1501+
node_id: PublicKey,
1502+
/// The message which should be sent.
1503+
msg: msgs::TxRemoveOutput,
1504+
},
1505+
/// Used to indicate that a tx_complete message should be sent to the peer with the given node_id.
1506+
SendTxComplete {
1507+
/// The node_id of the node which should receive this message
1508+
node_id: PublicKey,
1509+
/// The message which should be sent.
1510+
msg: msgs::TxComplete,
1511+
},
1512+
/// Used to indicate that a tx_signatures message should be sent to the peer with the given node_id.
1513+
SendTxSignatures {
1514+
/// The node_id of the node which should receive this message
1515+
node_id: PublicKey,
1516+
/// The message which should be sent.
1517+
msg: msgs::TxSignatures,
1518+
},
1519+
/// Used to indicate that a tx_init_rbf message should be sent to the peer with the given node_id.
1520+
SendTxInitRbf {
1521+
/// The node_id of the node which should receive this message
1522+
node_id: PublicKey,
1523+
/// The message which should be sent.
1524+
msg: msgs::TxInitRbf,
1525+
},
1526+
/// Used to indicate that a tx_ack_rbf message should be sent to the peer with the given node_id.
1527+
SendTxAckRbf {
1528+
/// The node_id of the node which should receive this message
1529+
node_id: PublicKey,
1530+
/// The message which should be sent.
1531+
msg: msgs::TxAckRbf,
1532+
},
1533+
/// Used to indicate that a tx_abort message should be sent to the peer with the given node_id.
1534+
SendTxAbort {
1535+
/// The node_id of the node which should receive this message
1536+
node_id: PublicKey,
1537+
/// The message which should be sent.
1538+
msg: msgs::TxAddInput,
1539+
},
14611540
/// Used to indicate that a channel_ready message should be sent to the peer with the given node_id.
14621541
SendChannelReady {
14631542
/// The node_id of the node which should receive these message(s)

lightning/src/ln/channel.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5695,8 +5695,9 @@ impl<Signer: WriteableEcdsaChannelSigner> Channel<Signer> {
56955695
next_remote_commitment_number: INITIAL_COMMITMENT_NUMBER - self.cur_counterparty_commitment_transaction_number - 1,
56965696
your_last_per_commitment_secret: remote_last_secret,
56975697
my_current_per_commitment_point: dummy_pubkey,
5698-
// TODO(dual_funding): If we've sent `commtiment_signed` for an interactive transaction construction but have not received `tx_signatures`
5699-
// we MUST set `next_funding_txid` to the txid of that interactive transaction, else we MUST NOT set it.
5698+
// TODO(dual_funding): If we've sent `commtiment_signed` for an interactive transaction
5699+
// construction but have not received `tx_signatures` we MUST set `next_funding_txid` to the
5700+
// txid of that interactive transaction, else we MUST NOT set it.
57005701
next_funding_txid: None,
57015702
}
57025703
}

lightning/src/ln/channelmanager.rs

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

6390+
fn handle_open_channel_v2(&self, counterparty_node_id: &PublicKey, msg: &msgs::OpenChannelV2) {
6391+
let _: Result<(), _> = handle_error!(self, Err(MsgHandleErrInternal::send_err_msg_no_close(
6392+
"Dual-funded channels not supported".to_owned(),
6393+
msg.temporary_channel_id.clone())), *counterparty_node_id);
6394+
}
6395+
63906396
fn handle_accept_channel(&self, counterparty_node_id: &PublicKey, msg: &msgs::AcceptChannel) {
63916397
let _persistence_guard = PersistenceNotifierGuard::notify_on_drop(&self.total_consistency_lock, &self.persistence_notifier);
63926398
let _ = handle_error!(self, self.internal_accept_channel(counterparty_node_id, msg), *counterparty_node_id);
63936399
}
63946400

6401+
fn handle_accept_channel_v2(&self, counterparty_node_id: &PublicKey, msg: &msgs::AcceptChannelV2) {
6402+
let _: Result<(), _> = handle_error!(self, Err(MsgHandleErrInternal::send_err_msg_no_close(
6403+
"Dual-funded channels not supported".to_owned(),
6404+
msg.temporary_channel_id.clone())), *counterparty_node_id);
6405+
}
6406+
63956407
fn handle_funding_created(&self, counterparty_node_id: &PublicKey, msg: &msgs::FundingCreated) {
63966408
let _persistence_guard = PersistenceNotifierGuard::notify_on_drop(&self.total_consistency_lock, &self.persistence_notifier);
63976409
let _ = handle_error!(self, self.internal_funding_created(counterparty_node_id, msg), *counterparty_node_id);
@@ -6494,23 +6506,40 @@ where
64946506
});
64956507
pending_msg_events.retain(|msg| {
64966508
match msg {
6509+
// V1 Channel Establishment
64976510
&events::MessageSendEvent::SendAcceptChannel { .. } => false,
64986511
&events::MessageSendEvent::SendOpenChannel { .. } => false,
64996512
&events::MessageSendEvent::SendFundingCreated { .. } => false,
65006513
&events::MessageSendEvent::SendFundingSigned { .. } => false,
6514+
// V2 Channel Establishment
6515+
&events::MessageSendEvent::SendAcceptChannelV2 { .. } => false,
6516+
&events::MessageSendEvent::SendOpenChannelV2 { .. } => false,
6517+
// Common Channel Establishment
65016518
&events::MessageSendEvent::SendChannelReady { .. } => false,
65026519
&events::MessageSendEvent::SendAnnouncementSignatures { .. } => false,
6520+
// Interactive Transaction Construction
6521+
&events::MessageSendEvent::SendTxAddInput { .. } => false,
6522+
&events::MessageSendEvent::SendTxAddOutput { .. } => false,
6523+
&events::MessageSendEvent::SendTxRemoveInput { .. } => false,
6524+
&events::MessageSendEvent::SendTxRemoveOutput { .. } => false,
6525+
&events::MessageSendEvent::SendTxComplete { .. } => false,
6526+
&events::MessageSendEvent::SendTxSignatures { .. } => false,
6527+
&events::MessageSendEvent::SendTxInitRbf { .. } => false,
6528+
&events::MessageSendEvent::SendTxAckRbf { .. } => false,
6529+
&events::MessageSendEvent::SendTxAbort { .. } => false,
6530+
// Channel Operations
65036531
&events::MessageSendEvent::UpdateHTLCs { .. } => false,
65046532
&events::MessageSendEvent::SendRevokeAndACK { .. } => false,
65056533
&events::MessageSendEvent::SendClosingSigned { .. } => false,
65066534
&events::MessageSendEvent::SendShutdown { .. } => false,
65076535
&events::MessageSendEvent::SendChannelReestablish { .. } => false,
6536+
&events::MessageSendEvent::HandleError { .. } => false,
6537+
// Gossip
65086538
&events::MessageSendEvent::SendChannelAnnouncement { .. } => false,
65096539
&events::MessageSendEvent::BroadcastChannelAnnouncement { .. } => true,
65106540
&events::MessageSendEvent::BroadcastChannelUpdate { .. } => true,
65116541
&events::MessageSendEvent::BroadcastNodeAnnouncement { .. } => true,
65126542
&events::MessageSendEvent::SendChannelUpdate { .. } => false,
6513-
&events::MessageSendEvent::HandleError { .. } => false,
65146543
&events::MessageSendEvent::SendChannelRangeQuery { .. } => false,
65156544
&events::MessageSendEvent::SendShortIdsQuery { .. } => false,
65166545
&events::MessageSendEvent::SendReplyChannelRange { .. } => false,
@@ -6667,6 +6696,60 @@ where
66676696
fn provided_init_features(&self, _their_init_features: &PublicKey) -> InitFeatures {
66686697
provided_init_features(&self.default_configuration)
66696698
}
6699+
6700+
fn handle_tx_add_input(&self, counterparty_node_id: &PublicKey, msg: &msgs::TxAddInput) {
6701+
let _: Result<(), _> = handle_error!(self, Err(MsgHandleErrInternal::send_err_msg_no_close(
6702+
"Dual-funded channels not supported".to_owned(),
6703+
msg.channel_id.clone())), *counterparty_node_id);
6704+
}
6705+
6706+
fn handle_tx_add_output(&self, counterparty_node_id: &PublicKey, msg: &msgs::TxAddOutput) {
6707+
let _: Result<(), _> = handle_error!(self, Err(MsgHandleErrInternal::send_err_msg_no_close(
6708+
"Dual-funded channels not supported".to_owned(),
6709+
msg.channel_id.clone())), *counterparty_node_id);
6710+
}
6711+
6712+
fn handle_tx_remove_input(&self, counterparty_node_id: &PublicKey, msg: &msgs::TxRemoveInput) {
6713+
let _: Result<(), _> = handle_error!(self, Err(MsgHandleErrInternal::send_err_msg_no_close(
6714+
"Dual-funded channels not supported".to_owned(),
6715+
msg.channel_id.clone())), *counterparty_node_id);
6716+
}
6717+
6718+
fn handle_tx_remove_output(&self, counterparty_node_id: &PublicKey, msg: &msgs::TxRemoveOutput) {
6719+
let _: Result<(), _> = handle_error!(self, Err(MsgHandleErrInternal::send_err_msg_no_close(
6720+
"Dual-funded channels not supported".to_owned(),
6721+
msg.channel_id.clone())), *counterparty_node_id);
6722+
}
6723+
6724+
fn handle_tx_complete(&self, counterparty_node_id: &PublicKey, msg: &msgs::TxComplete) {
6725+
let _: Result<(), _> = handle_error!(self, Err(MsgHandleErrInternal::send_err_msg_no_close(
6726+
"Dual-funded channels not supported".to_owned(),
6727+
msg.channel_id.clone())), *counterparty_node_id);
6728+
}
6729+
6730+
fn handle_tx_signatures(&self, counterparty_node_id: &PublicKey, msg: &msgs::TxSignatures) {
6731+
let _: Result<(), _> = handle_error!(self, Err(MsgHandleErrInternal::send_err_msg_no_close(
6732+
"Dual-funded channels not supported".to_owned(),
6733+
msg.channel_id.clone())), *counterparty_node_id);
6734+
}
6735+
6736+
fn handle_tx_init_rbf(&self, counterparty_node_id: &PublicKey, msg: &msgs::TxInitRbf) {
6737+
let _: Result<(), _> = handle_error!(self, Err(MsgHandleErrInternal::send_err_msg_no_close(
6738+
"Dual-funded channels not supported".to_owned(),
6739+
msg.channel_id.clone())), *counterparty_node_id);
6740+
}
6741+
6742+
fn handle_tx_ack_rbf(&self, counterparty_node_id: &PublicKey, msg: &msgs::TxAckRbf) {
6743+
let _: Result<(), _> = handle_error!(self, Err(MsgHandleErrInternal::send_err_msg_no_close(
6744+
"Dual-funded channels not supported".to_owned(),
6745+
msg.channel_id.clone())), *counterparty_node_id);
6746+
}
6747+
6748+
fn handle_tx_abort(&self, counterparty_node_id: &PublicKey, msg: &msgs::TxAbort) {
6749+
let _: Result<(), _> = handle_error!(self, Err(MsgHandleErrInternal::send_err_msg_no_close(
6750+
"Dual-funded channels not supported".to_owned(),
6751+
msg.channel_id.clone())), *counterparty_node_id);
6752+
}
66706753
}
66716754

66726755
/// 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
@@ -1198,8 +1198,12 @@ pub trait ChannelMessageHandler : MessageSendEventsProvider {
11981198
// Channel init:
11991199
/// Handle an incoming `open_channel` message from the given peer.
12001200
fn handle_open_channel(&self, their_node_id: &PublicKey, msg: &OpenChannel);
1201+
/// Handle an incoming `open_channel2` message from the given peer.
1202+
fn handle_open_channel_v2(&self, their_node_id: &PublicKey, msg: &OpenChannelV2);
12011203
/// Handle an incoming `accept_channel` message from the given peer.
12021204
fn handle_accept_channel(&self, their_node_id: &PublicKey, msg: &AcceptChannel);
1205+
/// Handle an incoming `accept_channel2` message from the given peer.
1206+
fn handle_accept_channel_v2(&self, their_node_id: &PublicKey, msg: &AcceptChannelV2);
12031207
/// Handle an incoming `funding_created` message from the given peer.
12041208
fn handle_funding_created(&self, their_node_id: &PublicKey, msg: &FundingCreated);
12051209
/// Handle an incoming `funding_signed` message from the given peer.
@@ -1213,6 +1217,26 @@ pub trait ChannelMessageHandler : MessageSendEventsProvider {
12131217
/// Handle an incoming `closing_signed` message from the given peer.
12141218
fn handle_closing_signed(&self, their_node_id: &PublicKey, msg: &ClosingSigned);
12151219

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

0 commit comments

Comments
 (0)