Skip to content

Run rustfmt on lightning-rapid-gossip-sync #3135

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 4 commits into from
Jun 20, 2024
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
39 changes: 20 additions & 19 deletions lightning-rapid-gossip-sync/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#![deny(rustdoc::broken_intra_doc_links)]
#![deny(rustdoc::private_intra_doc_links)]

#![deny(missing_docs)]
#![deny(unsafe_code)]
#![deny(non_upper_case_globals)]
Expand Down Expand Up @@ -63,15 +62,16 @@

#![cfg_attr(all(not(feature = "std"), not(test)), no_std)]

#[cfg(ldk_bench)] extern crate criterion;
#[cfg(ldk_bench)]
extern crate criterion;

#[cfg(not(feature = "std"))]
extern crate alloc;

#[cfg(feature = "std")]
use std::fs::File;
use core::ops::Deref;
use core::sync::atomic::{AtomicBool, Ordering};
#[cfg(feature = "std")]
use std::fs::File;

use lightning::io;
use lightning::ln::msgs::{DecodeError, LightningError};
Expand Down Expand Up @@ -121,21 +121,22 @@ impl From<LightningError> for GraphSyncError {
/// See [crate-level documentation] for usage.
///
/// [crate-level documentation]: crate
pub struct RapidGossipSync<NG: Deref<Target=NetworkGraph<L>>, L: Deref>
where L::Target: Logger {
pub struct RapidGossipSync<NG: Deref<Target = NetworkGraph<L>>, L: Deref>
where
L::Target: Logger,
{
network_graph: NG,
logger: L,
is_initial_sync_complete: AtomicBool
is_initial_sync_complete: AtomicBool,
}

impl<NG: Deref<Target=NetworkGraph<L>>, L: Deref> RapidGossipSync<NG, L> where L::Target: Logger {
impl<NG: Deref<Target = NetworkGraph<L>>, L: Deref> RapidGossipSync<NG, L>
where
L::Target: Logger,
{
/// Instantiate a new [`RapidGossipSync`] instance.
pub fn new(network_graph: NG, logger: L) -> Self {
Self {
network_graph,
logger,
is_initial_sync_complete: AtomicBool::new(false)
}
Self { network_graph, logger, is_initial_sync_complete: AtomicBool::new(false) }
}

/// Sync gossip data from a file.
Expand All @@ -147,8 +148,7 @@ impl<NG: Deref<Target=NetworkGraph<L>>, L: Deref> RapidGossipSync<NG, L> where L
///
#[cfg(feature = "std")]
pub fn sync_network_graph_with_file_path(
&self,
sync_path: &str,
&self, sync_path: &str,
) -> Result<u32, GraphSyncError> {
let mut file = File::open(sync_path)?;
self.update_network_graph_from_byte_stream(&mut file)
Expand All @@ -169,7 +169,9 @@ impl<NG: Deref<Target=NetworkGraph<L>>, L: Deref> RapidGossipSync<NG, L> where L
///
/// `update_data`: `&[u8]` binary stream that comprises the update data
/// `current_time_unix`: `Option<u64>` optional current timestamp to verify data age
pub fn update_network_graph_no_std(&self, update_data: &[u8], current_time_unix: Option<u64>) -> Result<u32, GraphSyncError> {
pub fn update_network_graph_no_std(
&self, update_data: &[u8], current_time_unix: Option<u64>,
) -> Result<u32, GraphSyncError> {
let mut read_cursor = io::Cursor::new(update_data);
self.update_network_graph_from_byte_stream_no_std(&mut read_cursor, current_time_unix)
}
Expand All @@ -195,10 +197,10 @@ mod tests {

use bitcoin::Network;

use crate::{GraphSyncError, RapidGossipSync};
use lightning::ln::msgs::DecodeError;
use lightning::routing::gossip::NetworkGraph;
use lightning::util::test_utils::TestLogger;
use crate::{GraphSyncError, RapidGossipSync};

#[test]
fn test_sync_from_file() {
Expand Down Expand Up @@ -294,8 +296,7 @@ mod tests {

let rapid_sync = RapidGossipSync::new(&network_graph, &logger);
let start = std::time::Instant::now();
let sync_result = rapid_sync
.sync_network_graph_with_file_path("./res/full_graph.lngossip");
let sync_result = rapid_sync.sync_network_graph_with_file_path("./res/full_graph.lngossip");
if let Err(GraphSyncError::DecodeError(DecodeError::Io(io_error))) = &sync_result {
let error_string = format!("Input file lightning-rapid-gossip-sync/res/full_graph.lngossip is missing! Download it from https://bitcoin.ninja/ldk-compressed_graph-285cb27df79-2022-07-21.bin\n\n{:?}", io_error);
#[cfg(not(require_route_graph_test))]
Expand Down
Loading
Loading