Skip to content

Fix several compile warnings added in some of my recent commits #1710

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Sep 11, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion lightning/src/ln/channelmanager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ use ln::channel::{Channel, ChannelError, ChannelUpdateStatus, UpdateFulfillCommi
use ln::features::{ChannelTypeFeatures, InitFeatures, NodeFeatures};
use routing::router::{PaymentParameters, Route, RouteHop, RoutePath, RouteParameters};
use ln::msgs;
use ln::msgs::NetAddress;
use ln::onion_utils;
use ln::msgs::{ChannelMessageHandler, DecodeError, LightningError, MAX_VALUE_MSAT};
use ln::wire::Encode;
Expand Down
10 changes: 7 additions & 3 deletions lightning/src/routing/gossip.rs
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@ where C::Target: chain::Access, L::Target: Logger
{
network_graph: G,
chain_access: Option<C>,
#[cfg(feature = "std")]
full_syncs_requested: AtomicUsize,
pending_events: Mutex<Vec<MessageSendEvent>>,
logger: L,
Expand All @@ -213,6 +214,7 @@ where C::Target: chain::Access, L::Target: Logger
pub fn new(network_graph: G, chain_access: Option<C>, logger: L) -> Self {
P2PGossipSync {
network_graph,
#[cfg(feature = "std")]
full_syncs_requested: AtomicUsize::new(0),
chain_access,
pending_events: Mutex::new(vec![]),
Expand All @@ -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.
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
6 changes: 2 additions & 4 deletions lightning/src/util/test_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
Expand Down Expand Up @@ -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
Expand Down
8 changes: 3 additions & 5 deletions lightning/src/util/wakers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,17 @@

use alloc::sync::Arc;
use core::mem;
use core::time::Duration;
use sync::{Condvar, Mutex};

use prelude::{Box, Vec};
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};
use core::pin::Pin;

use prelude::*;

/// Used to signal to one of many waiters that the condition they're waiting on has happened.
pub(crate) struct Notifier {
Expand Down Expand Up @@ -294,7 +292,7 @@ mod tests {
// waker, which we do here with a trivial Arc<AtomicBool> data element to track woke-ness.
const WAKER_V_TABLE: RawWakerVTable = RawWakerVTable::new(waker_clone, wake, wake_by_ref, drop);
unsafe fn wake_by_ref(ptr: *const ()) { let p = ptr as *const Arc<AtomicBool>; assert!(!(*p).fetch_or(true, Ordering::SeqCst)); }
unsafe fn drop(ptr: *const ()) { let p = ptr as *mut Arc<AtomicBool>; Box::from_raw(p); }
unsafe fn drop(ptr: *const ()) { let p = ptr as *mut Arc<AtomicBool>; let _freed = Box::from_raw(p); }
unsafe fn wake(ptr: *const ()) { wake_by_ref(ptr); drop(ptr); }
unsafe fn waker_clone(ptr: *const ()) -> RawWaker {
let p = ptr as *const Arc<AtomicBool>;
Expand Down