Skip to content

Commit 5ca6d5e

Browse files
committed
rustfmt: Run on lightning-block-sync/src/init.rs
1 parent 9985e7c commit 5ca6d5e

File tree

2 files changed

+33
-22
lines changed

2 files changed

+33
-22
lines changed

lightning-block-sync/src/init.rs

Lines changed: 33 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
//! Utilities to assist in the initial sync required to initialize or reload Rust-Lightning objects
22
//! from disk.
33
4-
use crate::{BlockSource, BlockSourceResult, Cache, ChainNotifier};
54
use crate::poll::{ChainPoller, Validate, ValidatedBlockHeader};
5+
use crate::{BlockSource, BlockSourceResult, Cache, ChainNotifier};
66

77
use bitcoin::blockdata::block::Header;
88
use bitcoin::hash_types::BlockHash;
@@ -18,12 +18,14 @@ use std::ops::Deref;
1818
/// start when there are no chain listeners to sync yet.
1919
///
2020
/// [`SpvClient`]: crate::SpvClient
21-
pub async fn validate_best_block_header<B: Deref>(block_source: B) ->
22-
BlockSourceResult<ValidatedBlockHeader> where B::Target: BlockSource {
21+
pub async fn validate_best_block_header<B: Deref>(
22+
block_source: B,
23+
) -> BlockSourceResult<ValidatedBlockHeader>
24+
where
25+
B::Target: BlockSource,
26+
{
2327
let (best_block_hash, best_block_height) = block_source.get_best_block().await?;
24-
block_source
25-
.get_header(&best_block_hash, best_block_height).await?
26-
.validate(best_block_hash)
28+
block_source.get_header(&best_block_hash, best_block_height).await?.validate(best_block_hash)
2729
}
2830

2931
/// Performs a one-time sync of chain listeners using a single *trusted* block source, bringing each
@@ -131,22 +133,27 @@ BlockSourceResult<ValidatedBlockHeader> where B::Target: BlockSource {
131133
/// [`SpvClient`]: crate::SpvClient
132134
/// [`ChannelManager`]: lightning::ln::channelmanager::ChannelManager
133135
/// [`ChannelMonitor`]: lightning::chain::channelmonitor::ChannelMonitor
134-
pub async fn synchronize_listeners<B: Deref + Sized + Send + Sync, C: Cache, L: chain::Listen + ?Sized>(
135-
block_source: B,
136-
network: Network,
137-
header_cache: &mut C,
136+
pub async fn synchronize_listeners<
137+
B: Deref + Sized + Send + Sync,
138+
C: Cache,
139+
L: chain::Listen + ?Sized,
140+
>(
141+
block_source: B, network: Network, header_cache: &mut C,
138142
mut chain_listeners: Vec<(BlockHash, &L)>,
139-
) -> BlockSourceResult<ValidatedBlockHeader> where B::Target: BlockSource {
143+
) -> BlockSourceResult<ValidatedBlockHeader>
144+
where
145+
B::Target: BlockSource,
146+
{
140147
let best_header = validate_best_block_header(&*block_source).await?;
141148

142149
// Fetch the header for the block hash paired with each listener.
143150
let mut chain_listeners_with_old_headers = Vec::new();
144151
for (old_block_hash, chain_listener) in chain_listeners.drain(..) {
145152
let old_header = match header_cache.look_up(&old_block_hash) {
146153
Some(header) => *header,
147-
None => block_source
148-
.get_header(&old_block_hash, None).await?
149-
.validate(old_block_hash)?
154+
None => {
155+
block_source.get_header(&old_block_hash, None).await?.validate(old_block_hash)?
156+
},
150157
};
151158
chain_listeners_with_old_headers.push((old_header, chain_listener))
152159
}
@@ -180,8 +187,10 @@ pub async fn synchronize_listeners<B: Deref + Sized + Send + Sync, C: Cache, L:
180187
if let Some(common_ancestor) = most_common_ancestor {
181188
let chain_listener = &ChainListenerSet(chain_listeners_at_height);
182189
let mut chain_notifier = ChainNotifier { header_cache, chain_listener };
183-
chain_notifier.connect_blocks(common_ancestor, most_connected_blocks, &mut chain_poller)
184-
.await.map_err(|(e, _)| e)?;
190+
chain_notifier
191+
.connect_blocks(common_ancestor, most_connected_blocks, &mut chain_poller)
192+
.await
193+
.map_err(|(e, _)| e)?;
185194
}
186195

187196
Ok(best_header)
@@ -211,7 +220,9 @@ impl<'a, C: Cache> Cache for ReadOnlyCache<'a, C> {
211220
struct DynamicChainListener<'a, L: chain::Listen + ?Sized>(&'a L);
212221

213222
impl<'a, L: chain::Listen + ?Sized> chain::Listen for DynamicChainListener<'a, L> {
214-
fn filtered_block_connected(&self, _header: &Header, _txdata: &chain::transaction::TransactionData, _height: u32) {
223+
fn filtered_block_connected(
224+
&self, _header: &Header, _txdata: &chain::transaction::TransactionData, _height: u32,
225+
) {
215226
unreachable!()
216227
}
217228

@@ -234,7 +245,9 @@ impl<'a, L: chain::Listen + ?Sized> chain::Listen for ChainListenerSet<'a, L> {
234245
}
235246
}
236247

237-
fn filtered_block_connected(&self, header: &Header, txdata: &chain::transaction::TransactionData, height: u32) {
248+
fn filtered_block_connected(
249+
&self, header: &Header, txdata: &chain::transaction::TransactionData, height: u32,
250+
) {
238251
for (starting_height, chain_listener) in self.0.iter() {
239252
if height > *starting_height {
240253
chain_listener.filtered_block_connected(header, txdata, height);
@@ -249,8 +262,8 @@ impl<'a, L: chain::Listen + ?Sized> chain::Listen for ChainListenerSet<'a, L> {
249262

250263
#[cfg(test)]
251264
mod tests {
252-
use crate::test_utils::{Blockchain, MockChainListener};
253265
use super::*;
266+
use crate::test_utils::{Blockchain, MockChainListener};
254267

255268
#[tokio::test]
256269
async fn sync_from_same_chain() {
@@ -263,8 +276,7 @@ mod tests {
263276
let listener_2 = MockChainListener::new()
264277
.expect_block_connected(*chain.at_height(3))
265278
.expect_block_connected(*chain.at_height(4));
266-
let listener_3 = MockChainListener::new()
267-
.expect_block_connected(*chain.at_height(4));
279+
let listener_3 = MockChainListener::new().expect_block_connected(*chain.at_height(4));
268280

269281
let listeners = vec![
270282
(chain.at_height(1).block_hash, &listener_1 as &dyn chain::Listen),

rustfmt_excluded_files

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
./lightning-background-processor/src/lib.rs
2-
./lightning-block-sync/src/init.rs
32
./lightning-block-sync/src/lib.rs
43
./lightning-block-sync/src/poll.rs
54
./lightning-block-sync/src/rest.rs

0 commit comments

Comments
 (0)