Skip to content

Commit 9488ca4

Browse files
committed
Add detection of feature_static_remotekey support and print
This adds the ability to check for static_remotekey in appropriate feature contexts and prints it at connect time. It is still considered unknown for the purposes of requires_unknown_bits() as we don't yet implement it.
1 parent 3787398 commit 9488ca4

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

lightning/src/ln/features.rs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,10 @@ mod sealed { // You should just use the type aliases instead.
3434
impl VariableLengthOnion for InitContext {}
3535
impl VariableLengthOnion for NodeContext {}
3636

37+
pub trait StaticRemoteKey: Context {}
38+
impl StaticRemoteKey for InitContext {}
39+
impl StaticRemoteKey for NodeContext {}
40+
3741
pub trait PaymentSecret: Context {}
3842
impl PaymentSecret for InitContext {}
3943
impl PaymentSecret for NodeContext {}
@@ -222,8 +226,8 @@ impl<T: sealed::Context> Features<T> {
222226
// unknown, upfront_shutdown_script, initial_routing_sync (is only valid as an
223227
// optional feature), and data_loss_protect:
224228
0 => (byte & 0b11000100),
225-
// payment_secret, unknown, unknown, var_onion_optin:
226-
1 => (byte & 0b00111100),
229+
// payment_secret, static_remotekey, unknown, var_onion_optin:
230+
1 => (byte & 0b00001100),
227231
// unknown, unknown, unknown, basic_mpp:
228232
2 => (byte & 0b11111100),
229233
_ => byte,
@@ -293,6 +297,12 @@ impl<T: sealed::InitialRoutingSync> Features<T> {
293297
}
294298
}
295299

300+
impl<T: sealed::StaticRemoteKey> Features<T> {
301+
pub(crate) fn supports_static_remote_key(&self) -> bool {
302+
self.flags.len() > 1 && (self.flags[1] & (3 << 4)) != 0
303+
}
304+
}
305+
296306
impl<T: sealed::PaymentSecret> Features<T> {
297307
#[allow(dead_code)]
298308
// Note that we never need to test this since what really matters is the invoice - iff the

lightning/src/ln/peer_handler.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -625,10 +625,11 @@ impl<Descriptor: SocketDescriptor, CM: Deref> PeerManager<Descriptor, CM> where
625625
return Err(PeerHandleError{ no_connection_possible: false });
626626
}
627627

628-
log_info!(self, "Received peer Init message: data_loss_protect: {}, initial_routing_sync: {}, upfront_shutdown_script: {}, unkown local flags: {}, unknown global flags: {}",
628+
log_info!(self, "Received peer Init message: data_loss_protect: {}, initial_routing_sync: {}, upfront_shutdown_script: {}, static_remote_key: {}, unkown local flags: {}, unknown global flags: {}",
629629
if msg.features.supports_data_loss_protect() { "supported" } else { "not supported"},
630630
if msg.features.initial_routing_sync() { "requested" } else { "not requested" },
631631
if msg.features.supports_upfront_shutdown_script() { "supported" } else { "not supported"},
632+
if msg.features.supports_static_remote_key() { "supported" } else { "not supported"},
632633
if msg.features.supports_unknown_bits() { "present" } else { "none" },
633634
if msg.features.supports_unknown_bits() { "present" } else { "none" });
634635

0 commit comments

Comments
 (0)