Skip to content

Commit 09c528c

Browse files
committed
Add new wire messaging and events but don't handle them
1 parent 955bb1d commit 09c528c

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
@@ -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
@@ -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
@@ -5686,8 +5686,9 @@ impl<Signer: WriteableEcdsaChannelSigner> Channel<Signer> {
56865686
// overflow here.
56875687
next_remote_commitment_number: INITIAL_COMMITMENT_NUMBER - self.cur_counterparty_commitment_transaction_number - 1,
56885688
data_loss_protect,
5689-
// TODO: If we've sent `commtiment_signed` for an interactive transaction construction but have not received `tx_signatures`
5690-
// we MUST set `next_funding_txid` to the txid of that interactive transaction, else we MUST NOT set it.
5689+
// TODO(dual_funding): If we've sent `commtiment_signed` for an interactive transaction
5690+
// construction but have not received `tx_signatures` we MUST set `next_funding_txid` to the
5691+
// txid of that interactive transaction, else we MUST NOT set it.
56915692
next_funding_txid: None,
56925693
}
56935694
}

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
@@ -723,6 +723,39 @@ pub fn remove_first_msg_event_to_node(msg_node_id: &PublicKey, msg_events: &mut
723723
MessageSendEvent::SendGossipTimestampFilter { node_id, .. } => {
724724
node_id == msg_node_id
725725
},
726+
MessageSendEvent::SendAcceptChannelV2 { node_id, .. } => {
727+
node_id == msg_node_id
728+
},
729+
MessageSendEvent::SendOpenChannelV2 { node_id, .. } => {
730+
node_id == msg_node_id
731+
},
732+
MessageSendEvent::SendTxAddInput { node_id, .. } => {
733+
node_id == msg_node_id
734+
},
735+
MessageSendEvent::SendTxAddOutput { node_id, .. } => {
736+
node_id == msg_node_id
737+
},
738+
MessageSendEvent::SendTxRemoveInput { node_id, .. } => {
739+
node_id == msg_node_id
740+
},
741+
MessageSendEvent::SendTxRemoveOutput { node_id, .. } => {
742+
node_id == msg_node_id
743+
},
744+
MessageSendEvent::SendTxComplete { node_id, .. } => {
745+
node_id == msg_node_id
746+
},
747+
MessageSendEvent::SendTxSignatures { node_id, .. } => {
748+
node_id == msg_node_id
749+
},
750+
MessageSendEvent::SendTxInitRbf { node_id, .. } => {
751+
node_id == msg_node_id
752+
},
753+
MessageSendEvent::SendTxAckRbf { node_id, .. } => {
754+
node_id == msg_node_id
755+
},
756+
MessageSendEvent::SendTxAbort { node_id, .. } => {
757+
node_id == msg_node_id
758+
},
726759
}});
727760
if ev_index.is_some() {
728761
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
@@ -1223,8 +1223,12 @@ pub trait ChannelMessageHandler : MessageSendEventsProvider {
12231223
// Channel init:
12241224
/// Handle an incoming `open_channel` message from the given peer.
12251225
fn handle_open_channel(&self, their_node_id: &PublicKey, msg: &OpenChannel);
1226+
/// Handle an incoming `open_channel2` message from the given peer.
1227+
fn handle_open_channel_v2(&self, their_node_id: &PublicKey, msg: &OpenChannelV2);
12261228
/// Handle an incoming `accept_channel` message from the given peer.
12271229
fn handle_accept_channel(&self, their_node_id: &PublicKey, msg: &AcceptChannel);
1230+
/// Handle an incoming `accept_channel2` message from the given peer.
1231+
fn handle_accept_channel_v2(&self, their_node_id: &PublicKey, msg: &AcceptChannelV2);
12281232
/// Handle an incoming `funding_created` message from the given peer.
12291233
fn handle_funding_created(&self, their_node_id: &PublicKey, msg: &FundingCreated);
12301234
/// Handle an incoming `funding_signed` message from the given peer.
@@ -1238,6 +1242,26 @@ pub trait ChannelMessageHandler : MessageSendEventsProvider {
12381242
/// Handle an incoming `closing_signed` message from the given peer.
12391243
fn handle_closing_signed(&self, their_node_id: &PublicKey, msg: &ClosingSigned);
12401244

1245+
// Interactive channel construction
1246+
/// Handle an incoming `tx_add_input message` from the given peer.
1247+
fn handle_tx_add_input(&self, their_node_id: &PublicKey, msg: &TxAddInput);
1248+
/// Handle an incoming `tx_add_output` message from the given peer.
1249+
fn handle_tx_add_output(&self, their_node_id: &PublicKey, msg: &TxAddOutput);
1250+
/// Handle an incoming `tx_remove_input` message from the given peer.
1251+
fn handle_tx_remove_input(&self, their_node_id: &PublicKey, msg: &TxRemoveInput);
1252+
/// Handle an incoming `tx_remove_output` message from the given peer.
1253+
fn handle_tx_remove_output(&self, their_node_id: &PublicKey, msg: &TxRemoveOutput);
1254+
/// Handle an incoming `tx_complete message` from the given peer.
1255+
fn handle_tx_complete(&self, their_node_id: &PublicKey, msg: &TxComplete);
1256+
/// Handle an incoming `tx_signatures` message from the given peer.
1257+
fn handle_tx_signatures(&self, their_node_id: &PublicKey, msg: &TxSignatures);
1258+
/// Handle an incoming `tx_init_rbf` message from the given peer.
1259+
fn handle_tx_init_rbf(&self, their_node_id: &PublicKey, msg: &TxInitRbf);
1260+
/// Handle an incoming `tx_ack_rbf` message from the given peer.
1261+
fn handle_tx_ack_rbf(&self, their_node_id: &PublicKey, msg: &TxAckRbf);
1262+
/// Handle an incoming `tx_abort message` from the given peer.
1263+
fn handle_tx_abort(&self, their_node_id: &PublicKey, msg: &TxAbort);
1264+
12411265
// HTLC handling:
12421266
/// Handle an incoming `update_add_htlc` message from the given peer.
12431267
fn handle_update_add_htlc(&self, their_node_id: &PublicKey, msg: &UpdateAddHTLC);

0 commit comments

Comments
 (0)