From: Elias Rohrer Date: Thu, 20 Jun 2024 09:07:29 +0000 (+0200) Subject: `rustfmt`: Run on `lightning-block-sync/src/init.rs` X-Git-Tag: v0.0.124-beta~44^2~8 X-Git-Url: http://git.bitcoin.ninja/?a=commitdiff_plain;h=fb57e04057b611486b85e720686e1bc911e50935;p=rust-lightning `rustfmt`: Run on `lightning-block-sync/src/init.rs` --- diff --git a/lightning-block-sync/src/init.rs b/lightning-block-sync/src/init.rs index 38c21f2f9..4e893e11c 100644 --- a/lightning-block-sync/src/init.rs +++ b/lightning-block-sync/src/init.rs @@ -1,8 +1,8 @@ //! Utilities to assist in the initial sync required to initialize or reload Rust-Lightning objects //! from disk. -use crate::{BlockSource, BlockSourceResult, Cache, ChainNotifier}; use crate::poll::{ChainPoller, Validate, ValidatedBlockHeader}; +use crate::{BlockSource, BlockSourceResult, Cache, ChainNotifier}; use bitcoin::blockdata::block::Header; use bitcoin::hash_types::BlockHash; @@ -18,12 +18,14 @@ use std::ops::Deref; /// start when there are no chain listeners to sync yet. /// /// [`SpvClient`]: crate::SpvClient -pub async fn validate_best_block_header(block_source: B) -> -BlockSourceResult where B::Target: BlockSource { +pub async fn validate_best_block_header( + block_source: B, +) -> BlockSourceResult +where + B::Target: BlockSource, +{ let (best_block_hash, best_block_height) = block_source.get_best_block().await?; - block_source - .get_header(&best_block_hash, best_block_height).await? - .validate(best_block_hash) + block_source.get_header(&best_block_hash, best_block_height).await?.validate(best_block_hash) } /// Performs a one-time sync of chain listeners using a single *trusted* block source, bringing each @@ -131,12 +133,17 @@ BlockSourceResult where B::Target: BlockSource { /// [`SpvClient`]: crate::SpvClient /// [`ChannelManager`]: lightning::ln::channelmanager::ChannelManager /// [`ChannelMonitor`]: lightning::chain::channelmonitor::ChannelMonitor -pub async fn synchronize_listeners( - block_source: B, - network: Network, - header_cache: &mut C, +pub async fn synchronize_listeners< + B: Deref + Sized + Send + Sync, + C: Cache, + L: chain::Listen + ?Sized, +>( + block_source: B, network: Network, header_cache: &mut C, mut chain_listeners: Vec<(BlockHash, &L)>, -) -> BlockSourceResult where B::Target: BlockSource { +) -> BlockSourceResult +where + B::Target: BlockSource, +{ let best_header = validate_best_block_header(&*block_source).await?; // Fetch the header for the block hash paired with each listener. @@ -144,9 +151,9 @@ pub async fn synchronize_listeners *header, - None => block_source - .get_header(&old_block_hash, None).await? - .validate(old_block_hash)? + None => { + block_source.get_header(&old_block_hash, None).await?.validate(old_block_hash)? + }, }; chain_listeners_with_old_headers.push((old_header, chain_listener)) } @@ -180,8 +187,10 @@ pub async fn synchronize_listeners Cache for ReadOnlyCache<'a, C> { struct DynamicChainListener<'a, L: chain::Listen + ?Sized>(&'a L); impl<'a, L: chain::Listen + ?Sized> chain::Listen for DynamicChainListener<'a, L> { - fn filtered_block_connected(&self, _header: &Header, _txdata: &chain::transaction::TransactionData, _height: u32) { + fn filtered_block_connected( + &self, _header: &Header, _txdata: &chain::transaction::TransactionData, _height: u32, + ) { unreachable!() } @@ -234,7 +245,9 @@ impl<'a, L: chain::Listen + ?Sized> chain::Listen for ChainListenerSet<'a, L> { } } - fn filtered_block_connected(&self, header: &Header, txdata: &chain::transaction::TransactionData, height: u32) { + fn filtered_block_connected( + &self, header: &Header, txdata: &chain::transaction::TransactionData, height: u32, + ) { for (starting_height, chain_listener) in self.0.iter() { if height > *starting_height { chain_listener.filtered_block_connected(header, txdata, height); @@ -249,8 +262,8 @@ impl<'a, L: chain::Listen + ?Sized> chain::Listen for ChainListenerSet<'a, L> { #[cfg(test)] mod tests { - use crate::test_utils::{Blockchain, MockChainListener}; use super::*; + use crate::test_utils::{Blockchain, MockChainListener}; #[tokio::test] async fn sync_from_same_chain() { @@ -263,8 +276,7 @@ mod tests { let listener_2 = MockChainListener::new() .expect_block_connected(*chain.at_height(3)) .expect_block_connected(*chain.at_height(4)); - let listener_3 = MockChainListener::new() - .expect_block_connected(*chain.at_height(4)); + let listener_3 = MockChainListener::new().expect_block_connected(*chain.at_height(4)); let listeners = vec![ (chain.at_height(1).block_hash, &listener_1 as &dyn chain::Listen), diff --git a/rustfmt_excluded_files b/rustfmt_excluded_files index c8837be8b..74f5eace4 100644 --- a/rustfmt_excluded_files +++ b/rustfmt_excluded_files @@ -1,5 +1,4 @@ ./lightning-background-processor/src/lib.rs -./lightning-block-sync/src/init.rs ./lightning-block-sync/src/lib.rs ./lightning-block-sync/src/poll.rs ./lightning-block-sync/src/rest.rs