From: Matt Corallo Date: Fri, 9 Sep 2022 19:41:58 +0000 (+0000) Subject: Fix several compile warnings when testing in no-std mode X-Git-Tag: v0.0.111~4^2 X-Git-Url: http://git.bitcoin.ninja/?a=commitdiff_plain;h=0cc3572719966c61b6dd767fbfce95ac3efc9cb5;p=rust-lightning Fix several compile warnings when testing in no-std mode --- diff --git a/lightning/src/routing/gossip.rs b/lightning/src/routing/gossip.rs index 92a0e479a..cd366f92a 100644 --- a/lightning/src/routing/gossip.rs +++ b/lightning/src/routing/gossip.rs @@ -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 @@ -1862,7 +1864,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; @@ -1906,6 +1908,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); @@ -2593,6 +2596,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); diff --git a/lightning/src/util/test_utils.rs b/lightning/src/util/test_utils.rs index 7c7aeb5d4..2892af41c 100644 --- a/lightning/src/util/test_utils.rs +++ b/lightning/src/util/test_utils.rs @@ -287,9 +287,9 @@ impl TestChannelMessageHandler { impl Drop for TestChannelMessageHandler { fn drop(&mut self) { - let l = self.expected_recv_msgs.lock().unwrap(); #[cfg(feature = "std")] { + let l = self.expected_recv_msgs.lock().unwrap(); if !std::thread::panicking() { assert!(l.is_none() || l.as_ref().unwrap().is_empty()); } @@ -470,14 +470,12 @@ impl msgs::RoutingMessageHandler for TestRoutingMessageHandler { return (); } - let should_request_full_sync = self.request_full_sync.load(Ordering::Acquire); - #[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.request_full_sync.load(Ordering::Acquire) { gossip_start_time -= 60 * 60 * 24 * 7 * 2; // 2 weeks ago } else { gossip_start_time -= 60 * 60; // an hour ago diff --git a/lightning/src/util/wakers.rs b/lightning/src/util/wakers.rs index 01012fff7..e49c832ef 100644 --- a/lightning/src/util/wakers.rs +++ b/lightning/src/util/wakers.rs @@ -15,13 +15,12 @@ use alloc::sync::Arc; use core::mem; -use core::time::Duration; use sync::{Condvar, Mutex}; use prelude::*; #[cfg(any(test, feature = "std"))] -use std::time::Instant; +use std::time::{Duration, Instant}; use core::future::Future as StdFuture; use core::task::{Context, Poll};