Skip to content

Commit 4e976e3

Browse files
committed
Set initial_routing_sync in InitFeatures
The initial_routing_sync feature is set by peer_handler whenever a full sync of the network graph is desired. It is not explicitly set when creating features with InitFeatures::supported(). An upcoming refactor will change supported() to known(), which will return all features known by the implementation. Thus, the initial_routing_sync flag will need to be set by default. This commit makes the behavior change ahead of the refactor.
1 parent c1db30d commit 4e976e3

File tree

2 files changed

+13
-15
lines changed

2 files changed

+13
-15
lines changed

lightning/src/ln/features.rs

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ impl InitFeatures {
8181
/// Create a Features with the features we support
8282
pub fn supported() -> InitFeatures {
8383
InitFeatures {
84-
flags: vec![2 | 1 << 5, 1 << (9-8) | 1 << (15 - 8), 1 << (17 - 8*2)],
84+
flags: vec![2 | 1 << 3 | 1 << 5, 1 << (9-8) | 1 << (15 - 8), 1 << (17 - 8*2)],
8585
mark: PhantomData,
8686
}
8787
}
@@ -286,11 +286,9 @@ impl<T: sealed::InitialRoutingSync> Features<T> {
286286
pub(crate) fn initial_routing_sync(&self) -> bool {
287287
self.flags.len() > 0 && (self.flags[0] & (1 << 3)) != 0
288288
}
289-
pub(crate) fn set_initial_routing_sync(&mut self) {
290-
if self.flags.len() == 0 {
291-
self.flags.resize(1, 1 << 3);
292-
} else {
293-
self.flags[0] |= 1 << 3;
289+
pub(crate) fn clear_initial_routing_sync(&mut self) {
290+
if self.flags.len() > 0 {
291+
self.flags[0] &= !(1 << 3);
294292
}
295293
}
296294
}
@@ -364,9 +362,9 @@ mod tests {
364362
assert!(NodeFeatures::supported().supports_basic_mpp());
365363

366364
let mut init_features = InitFeatures::supported();
367-
init_features.set_initial_routing_sync();
368-
assert!(!init_features.requires_unknown_bits());
369-
assert!(!init_features.supports_unknown_bits());
365+
assert!(init_features.initial_routing_sync());
366+
init_features.clear_initial_routing_sync();
367+
assert!(!init_features.initial_routing_sync());
370368
}
371369

372370
#[test]
@@ -381,8 +379,8 @@ mod tests {
381379
#[test]
382380
fn test_node_with_known_relevant_init_flags() {
383381
// Create an InitFeatures with initial_routing_sync supported.
384-
let mut init_features = InitFeatures::supported();
385-
init_features.set_initial_routing_sync();
382+
let init_features = InitFeatures::supported();
383+
assert!(init_features.initial_routing_sync());
386384

387385
// Attempt to pull out non-node-context feature flags from these InitFeatures.
388386
let res = NodeFeatures::with_known_relevant_init_flags(&init_features);

lightning/src/ln/peer_handler.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -549,8 +549,8 @@ impl<Descriptor: SocketDescriptor, CM: Deref> PeerManager<Descriptor, CM> where
549549
peer.their_node_id = Some(their_node_id);
550550
insert_node_id!();
551551
let mut features = InitFeatures::supported();
552-
if self.message_handler.route_handler.should_request_full_sync(&peer.their_node_id.unwrap()) {
553-
features.set_initial_routing_sync();
552+
if !self.message_handler.route_handler.should_request_full_sync(&peer.their_node_id.unwrap()) {
553+
features.clear_initial_routing_sync();
554554
}
555555

556556
let resp = msgs::Init { features };
@@ -643,8 +643,8 @@ impl<Descriptor: SocketDescriptor, CM: Deref> PeerManager<Descriptor, CM> where
643643

644644
if !peer.outbound {
645645
let mut features = InitFeatures::supported();
646-
if self.message_handler.route_handler.should_request_full_sync(&peer.their_node_id.unwrap()) {
647-
features.set_initial_routing_sync();
646+
if !self.message_handler.route_handler.should_request_full_sync(&peer.their_node_id.unwrap()) {
647+
features.clear_initial_routing_sync();
648648
}
649649

650650
let resp = msgs::Init { features };

0 commit comments

Comments
 (0)