Skip to content

Commit

Permalink
Merge pull request #1020 from TheBlueMatt/2021-07-log-features-more
Browse files Browse the repository at this point in the history
Macroize feature printing to ensure we don't miss new flags
  • Loading branch information
TheBlueMatt authored Jul 28, 2021
2 parents 1bb9e64 + 1f013c9 commit f3b63e4
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 9 deletions.
23 changes: 23 additions & 0 deletions lightning/src/ln/features.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,28 @@ mod sealed {
)*
];
}

impl alloc::fmt::Display for Features<$context> {
fn fmt(&self, fmt: &mut alloc::fmt::Formatter) -> Result<(), alloc::fmt::Error> {
$(
$(
fmt.write_fmt(format_args!("{}: {}, ", stringify!($required_feature),
if <$context as $required_feature>::requires_feature(&self.flags) { "required" }
else if <$context as $required_feature>::supports_feature(&self.flags) { "supported" }
else { "not supported" }))?;
)*
$(
fmt.write_fmt(format_args!("{}: {}, ", stringify!($optional_feature),
if <$context as $optional_feature>::requires_feature(&self.flags) { "required" }
else if <$context as $optional_feature>::supports_feature(&self.flags) { "supported" }
else { "not supported" }))?;
)*
)*
fmt.write_fmt(format_args!("unknown flags: {}",
if self.requires_unknown_bits() { "required" }
else if self.supports_unknown_bits() { "supported" } else { "none" }))
}
}
};
}

Expand Down Expand Up @@ -566,6 +588,7 @@ impl<T: sealed::DataLossProtect> Features<T> {
pub(crate) fn requires_data_loss_protect(&self) -> bool {
<T as sealed::DataLossProtect>::requires_feature(&self.flags)
}
#[cfg(test)]
pub(crate) fn supports_data_loss_protect(&self) -> bool {
<T as sealed::DataLossProtect>::supports_feature(&self.flags)
}
Expand Down
10 changes: 1 addition & 9 deletions lightning/src/ln/peer_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -888,15 +888,7 @@ impl<Descriptor: SocketDescriptor, CM: Deref, RM: Deref, L: Deref> PeerManager<D
return Err(PeerHandleError{ no_connection_possible: false }.into());
}

log_info!(
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): {}",
if msg.features.supports_data_loss_protect() { "supported" } else { "not supported"},
if msg.features.initial_routing_sync() { "requested" } else { "not requested" },
if msg.features.supports_upfront_shutdown_script() { "supported" } else { "not supported"},
if msg.features.supports_gossip_queries() { "supported" } else { "not supported" },
if msg.features.supports_static_remote_key() { "supported" } else { "not supported"},
if msg.features.supports_unknown_bits() { "present" } else { "none" }
);
log_info!(self.logger, "Received peer Init message: {}", msg.features);

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

0 comments on commit f3b63e4

Please sign in to comment.