From 1f013c9cc21dcde1b7581c9b5b2e32ba7dc2cf7f Mon Sep 17 00:00:00 2001 From: Matt Corallo Date: Wed, 28 Jul 2021 21:06:49 +0000 Subject: [PATCH] Macroize feature printing to ensure we don't miss new flags --- lightning/src/ln/features.rs | 23 +++++++++++++++++++++++ lightning/src/ln/peer_handler.rs | 10 +--------- 2 files changed, 24 insertions(+), 9 deletions(-) diff --git a/lightning/src/ln/features.rs b/lightning/src/ln/features.rs index eb0100db6..b90748aa8 100644 --- a/lightning/src/ln/features.rs +++ b/lightning/src/ln/features.rs @@ -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" })) + } + } }; } @@ -566,6 +588,7 @@ impl Features { pub(crate) fn requires_data_loss_protect(&self) -> bool { ::requires_feature(&self.flags) } + #[cfg(test)] pub(crate) fn supports_data_loss_protect(&self) -> bool { ::supports_feature(&self.flags) } diff --git a/lightning/src/ln/peer_handler.rs b/lightning/src/ln/peer_handler.rs index 0ec24fbf8..ec7500190 100644 --- a/lightning/src/ln/peer_handler.rs +++ b/lightning/src/ln/peer_handler.rs @@ -888,15 +888,7 @@ impl PeerManager