Skip to content

Commit a0d0bb4

Browse files
committed
Move MessageSendEvent to ln::msgs from events
`MessageSendEvent` got placed in the `events` module next to `Event` but it really doesn't make a whole lot of sense to be there (despite the superficially similar name). `MessageSendEvent`s aren't really "events" so much as simply queued messages, handled by the `PeerManager` rather than the user. Further, they're used entirely by structs implementing the traits in `ln::msgs` and basically define an enum over `ln::msgs` structs. Thus, it only really makes sense to have them in `ln::msgs`, which we do here.
1 parent 5da1d73 commit a0d0bb4

29 files changed

+507
-511
lines changed

fuzz/src/chanmon_consistency.rs

+37-38
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,8 @@ use lightning::ln::channelmanager::{
5252
use lightning::ln::functional_test_utils::*;
5353
use lightning::ln::inbound_payment::ExpandedKey;
5454
use lightning::ln::msgs::{
55-
BaseMessageHandler, ChannelMessageHandler, CommitmentUpdate, Init, UpdateAddHTLC,
55+
BaseMessageHandler, ChannelMessageHandler, CommitmentUpdate, Init, MessageSendEvent,
56+
UpdateAddHTLC,
5657
};
5758
use lightning::ln::script::ShutdownScript;
5859
use lightning::ln::types::ChannelId;
@@ -769,7 +770,7 @@ pub fn do_test<Out: Output>(data: &[u8], underlying_out: Out, anchors: bool) {
769770
let open_channel = {
770771
let events = $source.get_and_clear_pending_msg_events();
771772
assert_eq!(events.len(), 1);
772-
if let events::MessageSendEvent::SendOpenChannel { ref msg, .. } = events[0] {
773+
if let MessageSendEvent::SendOpenChannel { ref msg, .. } = events[0] {
773774
msg.clone()
774775
} else {
775776
panic!("Wrong event type");
@@ -805,7 +806,7 @@ pub fn do_test<Out: Output>(data: &[u8], underlying_out: Out, anchors: bool) {
805806
}
806807
let events = $dest.get_and_clear_pending_msg_events();
807808
assert_eq!(events.len(), 1);
808-
if let events::MessageSendEvent::SendAcceptChannel { ref msg, .. } = events[0] {
809+
if let MessageSendEvent::SendAcceptChannel { ref msg, .. } = events[0] {
809810
msg.clone()
810811
} else {
811812
panic!("Wrong event type");
@@ -848,7 +849,7 @@ pub fn do_test<Out: Output>(data: &[u8], underlying_out: Out, anchors: bool) {
848849
let funding_created = {
849850
let events = $source.get_and_clear_pending_msg_events();
850851
assert_eq!(events.len(), 1);
851-
if let events::MessageSendEvent::SendFundingCreated { ref msg, .. } = events[0] {
852+
if let MessageSendEvent::SendFundingCreated { ref msg, .. } = events[0] {
852853
msg.clone()
853854
} else {
854855
panic!("Wrong event type");
@@ -859,7 +860,7 @@ pub fn do_test<Out: Output>(data: &[u8], underlying_out: Out, anchors: bool) {
859860
let funding_signed = {
860861
let events = $dest.get_and_clear_pending_msg_events();
861862
assert_eq!(events.len(), 1);
862-
if let events::MessageSendEvent::SendFundingSigned { ref msg, .. } = events[0] {
863+
if let MessageSendEvent::SendFundingSigned { ref msg, .. } = events[0] {
863864
msg.clone()
864865
} else {
865866
panic!("Wrong event type");
@@ -914,9 +915,7 @@ pub fn do_test<Out: Output>(data: &[u8], underlying_out: Out, anchors: bool) {
914915
}
915916
for (idx, node_event) in node_events.iter().enumerate() {
916917
for event in node_event {
917-
if let events::MessageSendEvent::SendChannelReady { ref node_id, ref msg } =
918-
event
919-
{
918+
if let MessageSendEvent::SendChannelReady { ref node_id, ref msg } = event {
920919
for node in $nodes.iter() {
921920
if node.get_our_node_id() == *node_id {
922921
node.handle_channel_ready($nodes[idx].get_our_node_id(), msg);
@@ -931,7 +930,7 @@ pub fn do_test<Out: Output>(data: &[u8], underlying_out: Out, anchors: bool) {
931930
for node in $nodes.iter() {
932931
let events = node.get_and_clear_pending_msg_events();
933932
for event in events {
934-
if let events::MessageSendEvent::SendAnnouncementSignatures { .. } = event {
933+
if let MessageSendEvent::SendAnnouncementSignatures { .. } = event {
935934
} else {
936935
panic!("Wrong event type");
937936
}
@@ -1016,25 +1015,25 @@ pub fn do_test<Out: Output>(data: &[u8], underlying_out: Out, anchors: bool) {
10161015
let expect_drop_id = if let Some(id) = expect_drop_node { Some(nodes[id].get_our_node_id()) } else { None };
10171016
for event in $excess_events {
10181017
let push_a = match event {
1019-
events::MessageSendEvent::UpdateHTLCs { ref node_id, .. } => {
1018+
MessageSendEvent::UpdateHTLCs { ref node_id, .. } => {
10201019
if Some(*node_id) == expect_drop_id { panic!("peer_disconnected should drop msgs bound for the disconnected peer"); }
10211020
*node_id == a_id
10221021
},
1023-
events::MessageSendEvent::SendRevokeAndACK { ref node_id, .. } => {
1022+
MessageSendEvent::SendRevokeAndACK { ref node_id, .. } => {
10241023
if Some(*node_id) == expect_drop_id { panic!("peer_disconnected should drop msgs bound for the disconnected peer"); }
10251024
*node_id == a_id
10261025
},
1027-
events::MessageSendEvent::SendChannelReestablish { ref node_id, .. } => {
1026+
MessageSendEvent::SendChannelReestablish { ref node_id, .. } => {
10281027
if Some(*node_id) == expect_drop_id { panic!("peer_disconnected should drop msgs bound for the disconnected peer"); }
10291028
*node_id == a_id
10301029
},
1031-
events::MessageSendEvent::SendStfu { ref node_id, .. } => {
1030+
MessageSendEvent::SendStfu { ref node_id, .. } => {
10321031
if Some(*node_id) == expect_drop_id { panic!("peer_disconnected should drop msgs bound for the disconnected peer"); }
10331032
*node_id == a_id
10341033
},
1035-
events::MessageSendEvent::SendChannelReady { .. } => continue,
1036-
events::MessageSendEvent::SendAnnouncementSignatures { .. } => continue,
1037-
events::MessageSendEvent::SendChannelUpdate { ref node_id, ref msg } => {
1034+
MessageSendEvent::SendChannelReady { .. } => continue,
1035+
MessageSendEvent::SendAnnouncementSignatures { .. } => continue,
1036+
MessageSendEvent::SendChannelUpdate { ref node_id, ref msg } => {
10381037
assert_eq!(msg.contents.channel_flags & 2, 0); // The disable bit must never be set!
10391038
if Some(*node_id) == expect_drop_id { panic!("peer_disconnected should drop msgs bound for the disconnected peer"); }
10401039
*node_id == a_id
@@ -1090,7 +1089,7 @@ pub fn do_test<Out: Output>(data: &[u8], underlying_out: Out, anchors: bool) {
10901089
for event in &mut events_iter {
10911090
had_events = true;
10921091
match event {
1093-
events::MessageSendEvent::UpdateHTLCs { node_id, updates: CommitmentUpdate { update_add_htlcs, update_fail_htlcs, update_fulfill_htlcs, update_fail_malformed_htlcs, update_fee, commitment_signed } } => {
1092+
MessageSendEvent::UpdateHTLCs { node_id, updates: CommitmentUpdate { update_add_htlcs, update_fail_htlcs, update_fulfill_htlcs, update_fail_malformed_htlcs, update_fee, commitment_signed } } => {
10941093
for (idx, dest) in nodes.iter().enumerate() {
10951094
if dest.get_our_node_id() == node_id {
10961095
for update_add in update_add_htlcs.iter() {
@@ -1128,7 +1127,7 @@ pub fn do_test<Out: Output>(data: &[u8], underlying_out: Out, anchors: bool) {
11281127
!update_fail_htlcs.is_empty() || !update_fail_malformed_htlcs.is_empty();
11291128
if $limit_events != ProcessMessages::AllMessages && processed_change {
11301129
// If we only want to process some messages, don't deliver the CS until later.
1131-
extra_ev = Some(events::MessageSendEvent::UpdateHTLCs { node_id, updates: CommitmentUpdate {
1130+
extra_ev = Some(MessageSendEvent::UpdateHTLCs { node_id, updates: CommitmentUpdate {
11321131
update_add_htlcs: Vec::new(),
11331132
update_fail_htlcs: Vec::new(),
11341133
update_fulfill_htlcs: Vec::new(),
@@ -1144,37 +1143,37 @@ pub fn do_test<Out: Output>(data: &[u8], underlying_out: Out, anchors: bool) {
11441143
}
11451144
}
11461145
},
1147-
events::MessageSendEvent::SendRevokeAndACK { ref node_id, ref msg } => {
1146+
MessageSendEvent::SendRevokeAndACK { ref node_id, ref msg } => {
11481147
for (idx, dest) in nodes.iter().enumerate() {
11491148
if dest.get_our_node_id() == *node_id {
11501149
out.locked_write(format!("Delivering revoke_and_ack from node {} to node {}.\n", $node, idx).as_bytes());
11511150
dest.handle_revoke_and_ack(nodes[$node].get_our_node_id(), msg);
11521151
}
11531152
}
11541153
},
1155-
events::MessageSendEvent::SendChannelReestablish { ref node_id, ref msg } => {
1154+
MessageSendEvent::SendChannelReestablish { ref node_id, ref msg } => {
11561155
for (idx, dest) in nodes.iter().enumerate() {
11571156
if dest.get_our_node_id() == *node_id {
11581157
out.locked_write(format!("Delivering channel_reestablish from node {} to node {}.\n", $node, idx).as_bytes());
11591158
dest.handle_channel_reestablish(nodes[$node].get_our_node_id(), msg);
11601159
}
11611160
}
11621161
},
1163-
events::MessageSendEvent::SendStfu { ref node_id, ref msg } => {
1162+
MessageSendEvent::SendStfu { ref node_id, ref msg } => {
11641163
for (idx, dest) in nodes.iter().enumerate() {
11651164
if dest.get_our_node_id() == *node_id {
11661165
out.locked_write(format!("Delivering stfu from node {} to node {}.\n", $node, idx).as_bytes());
11671166
dest.handle_stfu(nodes[$node].get_our_node_id(), msg);
11681167
}
11691168
}
11701169
}
1171-
events::MessageSendEvent::SendChannelReady { .. } => {
1170+
MessageSendEvent::SendChannelReady { .. } => {
11721171
// Can be generated as a reestablish response
11731172
},
1174-
events::MessageSendEvent::SendAnnouncementSignatures { .. } => {
1173+
MessageSendEvent::SendAnnouncementSignatures { .. } => {
11751174
// Can be generated as a reestablish response
11761175
},
1177-
events::MessageSendEvent::SendChannelUpdate { ref msg, .. } => {
1176+
MessageSendEvent::SendChannelUpdate { ref msg, .. } => {
11781177
// When we reconnect we will resend a channel_update to make sure our
11791178
// counterparty has the latest parameters for receiving payments
11801179
// through us. We do, however, check that the message does not include
@@ -1217,13 +1216,13 @@ pub fn do_test<Out: Output>(data: &[u8], underlying_out: Out, anchors: bool) {
12171216
if $counterparty_id == 0 {
12181217
for event in nodes[0].get_and_clear_pending_msg_events() {
12191218
match event {
1220-
events::MessageSendEvent::UpdateHTLCs { .. } => {},
1221-
events::MessageSendEvent::SendRevokeAndACK { .. } => {},
1222-
events::MessageSendEvent::SendChannelReestablish { .. } => {},
1223-
events::MessageSendEvent::SendStfu { .. } => {},
1224-
events::MessageSendEvent::SendChannelReady { .. } => {},
1225-
events::MessageSendEvent::SendAnnouncementSignatures { .. } => {},
1226-
events::MessageSendEvent::SendChannelUpdate { ref msg, .. } => {
1219+
MessageSendEvent::UpdateHTLCs { .. } => {},
1220+
MessageSendEvent::SendRevokeAndACK { .. } => {},
1221+
MessageSendEvent::SendChannelReestablish { .. } => {},
1222+
MessageSendEvent::SendStfu { .. } => {},
1223+
MessageSendEvent::SendChannelReady { .. } => {},
1224+
MessageSendEvent::SendAnnouncementSignatures { .. } => {},
1225+
MessageSendEvent::SendChannelUpdate { ref msg, .. } => {
12271226
assert_eq!(msg.contents.channel_flags & 2, 0); // The disable bit must never be set!
12281227
},
12291228
_ => {
@@ -1244,13 +1243,13 @@ pub fn do_test<Out: Output>(data: &[u8], underlying_out: Out, anchors: bool) {
12441243
} else {
12451244
for event in nodes[2].get_and_clear_pending_msg_events() {
12461245
match event {
1247-
events::MessageSendEvent::UpdateHTLCs { .. } => {},
1248-
events::MessageSendEvent::SendRevokeAndACK { .. } => {},
1249-
events::MessageSendEvent::SendChannelReestablish { .. } => {},
1250-
events::MessageSendEvent::SendStfu { .. } => {},
1251-
events::MessageSendEvent::SendChannelReady { .. } => {},
1252-
events::MessageSendEvent::SendAnnouncementSignatures { .. } => {},
1253-
events::MessageSendEvent::SendChannelUpdate { ref msg, .. } => {
1246+
MessageSendEvent::UpdateHTLCs { .. } => {},
1247+
MessageSendEvent::SendRevokeAndACK { .. } => {},
1248+
MessageSendEvent::SendChannelReestablish { .. } => {},
1249+
MessageSendEvent::SendStfu { .. } => {},
1250+
MessageSendEvent::SendChannelReady { .. } => {},
1251+
MessageSendEvent::SendAnnouncementSignatures { .. } => {},
1252+
MessageSendEvent::SendChannelUpdate { ref msg, .. } => {
12541253
assert_eq!(msg.contents.channel_flags & 2, 0); // The disable bit must never be set!
12551254
},
12561255
_ => {

lightning-background-processor/src/lib.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1070,13 +1070,13 @@ mod tests {
10701070
use lightning::chain::channelmonitor::ANTI_REORG_DELAY;
10711071
use lightning::chain::transaction::OutPoint;
10721072
use lightning::chain::{chainmonitor, BestBlock, Confirm, Filter};
1073-
use lightning::events::{Event, MessageSendEvent, PathFailure, ReplayEvent};
1073+
use lightning::events::{Event, PathFailure, ReplayEvent};
10741074
use lightning::ln::channelmanager;
10751075
use lightning::ln::channelmanager::{
10761076
ChainParameters, PaymentId, BREAKDOWN_TIMEOUT, MIN_CLTV_EXPIRY_DELTA,
10771077
};
10781078
use lightning::ln::functional_test_utils::*;
1079-
use lightning::ln::msgs::{BaseMessageHandler, ChannelMessageHandler, Init};
1079+
use lightning::ln::msgs::{BaseMessageHandler, ChannelMessageHandler, Init, MessageSendEvent};
10801080
use lightning::ln::peer_handler::{
10811081
IgnoringMessageHandler, MessageHandler, PeerManager, SocketDescriptor,
10821082
};

lightning-net-tokio/src/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -623,7 +623,6 @@ mod tests {
623623
use bitcoin::constants::ChainHash;
624624
use bitcoin::secp256k1::{PublicKey, Secp256k1, SecretKey};
625625
use bitcoin::Network;
626-
use lightning::events::*;
627626
use lightning::ln::msgs::*;
628627
use lightning::ln::peer_handler::{IgnoringMessageHandler, MessageHandler, PeerManager};
629628
use lightning::routing::gossip::NodeId;

lightning/src/chain/chainmonitor.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -928,9 +928,9 @@ mod tests {
928928
use crate::{get_htlc_update_msgs, get_revoke_commit_msgs};
929929
use crate::chain::{ChannelMonitorUpdateStatus, Watch};
930930
use crate::chain::channelmonitor::ANTI_REORG_DELAY;
931-
use crate::events::{ClosureReason, Event, MessageSendEvent};
931+
use crate::events::{ClosureReason, Event};
932932
use crate::ln::functional_test_utils::*;
933-
use crate::ln::msgs::{BaseMessageHandler, ChannelMessageHandler};
933+
use crate::ln::msgs::{BaseMessageHandler, ChannelMessageHandler, MessageSendEvent};
934934

935935
const CHAINSYNC_MONITOR_PARTITION_FACTOR: u32 = 5;
936936

0 commit comments

Comments
 (0)