X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=blobdiff_plain;f=lightning%2Fsrc%2Frouting%2Fgossip.rs;h=e265c6322ec56ad1cb3aee3bae696596d5ff02a5;hb=990e34679828ed4eca7bc8e179869f497b5dcc98;hp=28067838f7828ae1eeaad9a9584657ab1d98c959;hpb=c57bb42204a569fce5fb90d7f1b1367320124ae1;p=rust-lightning diff --git a/lightning/src/routing/gossip.rs b/lightning/src/routing/gossip.rs index 28067838..e265c632 100644 --- a/lightning/src/routing/gossip.rs +++ b/lightning/src/routing/gossip.rs @@ -22,7 +22,7 @@ use bitcoin::hash_types::BlockHash; use chain; use chain::Access; use ln::chan_utils::make_funding_redeemscript; -use ln::features::{ChannelFeatures, NodeFeatures}; +use ln::features::{ChannelFeatures, NodeFeatures, InitFeatures}; use ln::msgs::{DecodeError, ErrorAction, Init, LightningError, RoutingMessageHandler, NetAddress, MAX_VALUE_MSAT}; use ln::msgs::{ChannelAnnouncement, ChannelUpdate, NodeAnnouncement, GossipTimestampFilter}; use ln::msgs::{QueryChannelRange, ReplyChannelRange, QueryShortChannelIds, ReplyShortChannelIdsEnd}; @@ -197,6 +197,7 @@ where C::Target: chain::Access, L::Target: Logger { network_graph: G, chain_access: Option, + #[cfg(feature = "std")] full_syncs_requested: AtomicUsize, pending_events: Mutex>, logger: L, @@ -213,6 +214,7 @@ where C::Target: chain::Access, L::Target: Logger pub fn new(network_graph: G, chain_access: Option, logger: L) -> Self { P2PGossipSync { network_graph, + #[cfg(feature = "std")] full_syncs_requested: AtomicUsize::new(0), chain_access, pending_events: Mutex::new(vec![]), @@ -235,6 +237,7 @@ where C::Target: chain::Access, L::Target: Logger &self.network_graph } + #[cfg(feature = "std")] /// Returns true when a full routing table sync should be performed with a peer. fn should_request_full_sync(&self, _node_id: &PublicKey) -> bool { //TODO: Determine whether to request a full sync based on the network map. @@ -421,13 +424,12 @@ where C::Target: chain::Access, L::Target: Logger // `gossip_timestamp_filter`, with the filter time set either two weeks ago or an hour ago. // // For no-std builds, we bury our head in the sand and do a full sync on each connection. - let should_request_full_sync = self.should_request_full_sync(&their_node_id); #[allow(unused_mut, unused_assignments)] let mut gossip_start_time = 0; #[cfg(feature = "std")] { gossip_start_time = SystemTime::now().duration_since(UNIX_EPOCH).expect("Time must be > 1970").as_secs(); - if should_request_full_sync { + if self.should_request_full_sync(&their_node_id) { gossip_start_time -= 60 * 60 * 24 * 7 * 2; // 2 weeks ago } else { gossip_start_time -= 60 * 60; // an hour ago @@ -570,6 +572,18 @@ where C::Target: chain::Access, L::Target: Logger action: ErrorAction::IgnoreError, }) } + + fn provided_node_features(&self) -> NodeFeatures { + let mut features = NodeFeatures::empty(); + features.set_gossip_queries_optional(); + features + } + + fn provided_init_features(&self, _their_node_id: &PublicKey) -> InitFeatures { + let mut features = InitFeatures::empty(); + features.set_gossip_queries_optional(); + features + } } impl>, C: Deref, L: Deref> MessageSendEventsProvider for P2PGossipSync @@ -1856,7 +1870,7 @@ mod tests { use ln::PaymentHash; use ln::features::{ChannelFeatures, InitFeatures, NodeFeatures}; use routing::gossip::{P2PGossipSync, NetworkGraph, NetworkUpdate, NodeAlias, MAX_EXCESS_BYTES_FOR_RELAY, NodeId, RoutingFees, ChannelUpdateInfo, ChannelInfo, NodeAnnouncementInfo, NodeInfo}; - use ln::msgs::{Init, RoutingMessageHandler, UnsignedNodeAnnouncement, NodeAnnouncement, + use ln::msgs::{RoutingMessageHandler, UnsignedNodeAnnouncement, NodeAnnouncement, UnsignedChannelAnnouncement, ChannelAnnouncement, UnsignedChannelUpdate, ChannelUpdate, ReplyChannelRange, QueryChannelRange, QueryShortChannelIds, MAX_VALUE_MSAT}; use util::test_utils; @@ -1900,6 +1914,7 @@ mod tests { } #[test] + #[cfg(feature = "std")] fn request_full_sync_finite_times() { let network_graph = create_network_graph(); let (secp_ctx, gossip_sync) = create_gossip_sync(&network_graph); @@ -2587,6 +2602,7 @@ mod tests { #[cfg(feature = "std")] fn calling_sync_routing_table() { use std::time::{SystemTime, UNIX_EPOCH}; + use ln::msgs::Init; let network_graph = create_network_graph(); let (secp_ctx, gossip_sync) = create_gossip_sync(&network_graph);