Skip to content

Commit f3b63e4

Browse files
authored
Merge pull request #1020 from TheBlueMatt/2021-07-log-features-more
Macroize feature printing to ensure we don't miss new flags
2 parents 1bb9e64 + 1f013c9 commit f3b63e4

File tree

2 files changed

+24
-9
lines changed

2 files changed

+24
-9
lines changed

lightning/src/ln/features.rs

+23
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,28 @@ mod sealed {
8989
)*
9090
];
9191
}
92+
93+
impl alloc::fmt::Display for Features<$context> {
94+
fn fmt(&self, fmt: &mut alloc::fmt::Formatter) -> Result<(), alloc::fmt::Error> {
95+
$(
96+
$(
97+
fmt.write_fmt(format_args!("{}: {}, ", stringify!($required_feature),
98+
if <$context as $required_feature>::requires_feature(&self.flags) { "required" }
99+
else if <$context as $required_feature>::supports_feature(&self.flags) { "supported" }
100+
else { "not supported" }))?;
101+
)*
102+
$(
103+
fmt.write_fmt(format_args!("{}: {}, ", stringify!($optional_feature),
104+
if <$context as $optional_feature>::requires_feature(&self.flags) { "required" }
105+
else if <$context as $optional_feature>::supports_feature(&self.flags) { "supported" }
106+
else { "not supported" }))?;
107+
)*
108+
)*
109+
fmt.write_fmt(format_args!("unknown flags: {}",
110+
if self.requires_unknown_bits() { "required" }
111+
else if self.supports_unknown_bits() { "supported" } else { "none" }))
112+
}
113+
}
92114
};
93115
}
94116

@@ -566,6 +588,7 @@ impl<T: sealed::DataLossProtect> Features<T> {
566588
pub(crate) fn requires_data_loss_protect(&self) -> bool {
567589
<T as sealed::DataLossProtect>::requires_feature(&self.flags)
568590
}
591+
#[cfg(test)]
569592
pub(crate) fn supports_data_loss_protect(&self) -> bool {
570593
<T as sealed::DataLossProtect>::supports_feature(&self.flags)
571594
}

lightning/src/ln/peer_handler.rs

+1-9
Original file line numberDiff line numberDiff line change
@@ -888,15 +888,7 @@ impl<Descriptor: SocketDescriptor, CM: Deref, RM: Deref, L: Deref> PeerManager<D
888888
return Err(PeerHandleError{ no_connection_possible: false }.into());
889889
}
890890

891-
log_info!(
892-
self.logger, "Received peer Init message: data_loss_protect: {}, initial_routing_sync: {}, upfront_shutdown_script: {}, gossip_queries: {}, static_remote_key: {}, unknown flags (local and global): {}",
893-
if msg.features.supports_data_loss_protect() { "supported" } else { "not supported"},
894-
if msg.features.initial_routing_sync() { "requested" } else { "not requested" },
895-
if msg.features.supports_upfront_shutdown_script() { "supported" } else { "not supported"},
896-
if msg.features.supports_gossip_queries() { "supported" } else { "not supported" },
897-
if msg.features.supports_static_remote_key() { "supported" } else { "not supported"},
898-
if msg.features.supports_unknown_bits() { "present" } else { "none" }
899-
);
891+
log_info!(self.logger, "Received peer Init message: {}", msg.features);
900892

901893
if msg.features.initial_routing_sync() {
902894
peer.sync_status = InitSyncTracker::ChannelsSyncing(0);

0 commit comments

Comments
 (0)