]> git.bitcoin.ninja Git - rust-lightning/commitdiff
`rustfmt`: Reformat `lightning-transaction-sync/src/esplora.rs`
authorElias Rohrer <dev@tnull.de>
Thu, 6 Jun 2024 07:25:18 +0000 (09:25 +0200)
committerElias Rohrer <dev@tnull.de>
Fri, 7 Jun 2024 09:35:15 +0000 (11:35 +0200)
lightning-transaction-sync/src/esplora.rs
rustfmt_excluded_files

index 82c49b9f9d2e8dfda23ea941ae41f5d5e3ebf943..f176d535124e67681cfabe7575e7eccad5edd0f4 100644 (file)
@@ -1,21 +1,21 @@
-use crate::error::{TxSyncError, InternalError};
-use crate::common::{SyncState, FilterQueue, ConfirmedTx};
+use crate::common::{ConfirmedTx, FilterQueue, SyncState};
+use crate::error::{InternalError, TxSyncError};
 
-use lightning::util::logger::Logger;
-use lightning::{log_error, log_debug, log_trace};
 use lightning::chain::WatchedOutput;
 use lightning::chain::{Confirm, Filter};
+use lightning::util::logger::Logger;
+use lightning::{log_debug, log_error, log_trace};
 
 use bitcoin::{BlockHash, Script, Txid};
 
-use esplora_client::Builder;
-#[cfg(feature = "async-interface")]
-use esplora_client::r#async::AsyncClient;
 #[cfg(not(feature = "async-interface"))]
 use esplora_client::blocking::BlockingClient;
+#[cfg(feature = "async-interface")]
+use esplora_client::r#async::AsyncClient;
+use esplora_client::Builder;
 
-use std::collections::HashSet;
 use core::ops::Deref;
+use std::collections::HashSet;
 
 /// Synchronizes LDK with a given [`Esplora`] server.
 ///
@@ -64,12 +64,7 @@ where
        pub fn from_client(client: EsploraClientType, logger: L) -> Self {
                let sync_state = MutexType::new(SyncState::new());
                let queue = std::sync::Mutex::new(FilterQueue::new());
-               Self {
-                       sync_state,
-                       queue,
-                       client,
-                       logger,
-               }
+               Self { sync_state, queue, client, logger }
        }
 
        /// Synchronizes the given `confirmables` via their [`Confirm`] interface implementations. This
@@ -85,7 +80,8 @@ where
        /// [`Filter`]: lightning::chain::Filter
        #[maybe_async]
        pub fn sync<C: Deref>(&self, confirmables: Vec<C>) -> Result<(), TxSyncError>
-               where C::Target: Confirm
+       where
+               C::Target: Confirm,
        {
                // This lock makes sure we're syncing once at a time.
                #[cfg(not(feature = "async-interface"))]
@@ -130,9 +126,9 @@ where
                                                                        num_unconfirmed += unconfirmed_txs.len();
                                                                        sync_state.sync_unconfirmed_transactions(
                                                                                &confirmables,
-                                                                               unconfirmed_txs
+                                                                               unconfirmed_txs,
                                                                        );
-                                                               }
+                                                               },
                                                                Err(err) => {
                                                                        // (Semi-)permanent failure, retry later.
                                                                        log_error!(self.logger,
@@ -142,7 +138,7 @@ where
                                                                                );
                                                                        sync_state.pending_sync = true;
                                                                        return Err(TxSyncError::from(err));
-                                                               }
+                                                               },
                                                        }
                                                },
                                                Err(err) => {
@@ -154,17 +150,24 @@ where
                                                        );
                                                        sync_state.pending_sync = true;
                                                        return Err(TxSyncError::from(err));
-                                               }
+                                               },
                                        }
 
-                                       match maybe_await!(self.sync_best_block_updated(&confirmables, &mut sync_state, &tip_hash)) {
-                                               Ok(()) => {}
+                                       match maybe_await!(self.sync_best_block_updated(
+                                               &confirmables,
+                                               &mut sync_state,
+                                               &tip_hash
+                                       )) {
+                                               Ok(()) => {},
                                                Err(InternalError::Inconsistency) => {
                                                        // Immediately restart syncing when we encounter any inconsistencies.
-                                                       log_debug!(self.logger, "Encountered inconsistency during transaction sync, restarting.");
+                                                       log_debug!(
+                                                               self.logger,
+                                                               "Encountered inconsistency during transaction sync, restarting."
+                                                       );
                                                        sync_state.pending_sync = true;
                                                        continue;
-                                               }
+                                               },
                                                Err(err) => {
                                                        // (Semi-)permanent failure, retry later.
                                                        log_error!(self.logger,
@@ -174,7 +177,7 @@ where
                                                        );
                                                        sync_state.pending_sync = true;
                                                        return Err(TxSyncError::from(err));
-                                               }
+                                               },
                                        }
                                }
 
@@ -193,11 +196,9 @@ where
                                                                        continue;
                                                                }
                                                                num_confirmed += confirmed_txs.len();
-                                                               sync_state.sync_confirmed_transactions(
-                                                                       &confirmables,
-                                                                       confirmed_txs
-                                                               );
-                                                       }
+                                                               sync_state
+                                                                       .sync_confirmed_transactions(&confirmables, confirmed_txs);
+                                                       },
                                                        Err(err) => {
                                                                // (Semi-)permanent failure, retry later.
                                                                log_error!(self.logger,
@@ -207,15 +208,18 @@ where
                                                                );
                                                                sync_state.pending_sync = true;
                                                                return Err(TxSyncError::from(err));
-                                                       }
+                                                       },
                                                }
-                                       }
+                                       },
                                        Err(InternalError::Inconsistency) => {
                                                // Immediately restart syncing when we encounter any inconsistencies.
-                                               log_debug!(self.logger, "Encountered inconsistency during transaction sync, restarting.");
+                                               log_debug!(
+                                                       self.logger,
+                                                       "Encountered inconsistency during transaction sync, restarting."
+                                               );
                                                sync_state.pending_sync = true;
                                                continue;
-                                       }
+                                       },
                                        Err(err) => {
                                                // (Semi-)permanent failure, retry later.
                                                log_error!(self.logger,
@@ -225,18 +229,29 @@ where
                                                );
                                                sync_state.pending_sync = true;
                                                return Err(TxSyncError::from(err));
-                                       }
+                                       },
                                }
                                sync_state.last_sync_hash = Some(tip_hash);
                                sync_state.pending_sync = false;
                        }
                }
                #[cfg(feature = "time")]
-               log_debug!(self.logger, "Finished transaction sync at tip {} in {}ms: {} confirmed, {} unconfirmed.",
-                               tip_hash, start_time.elapsed().as_millis(), num_confirmed, num_unconfirmed);
+               log_debug!(
+                       self.logger,
+                       "Finished transaction sync at tip {} in {}ms: {} confirmed, {} unconfirmed.",
+                       tip_hash,
+                       start_time.elapsed().as_millis(),
+                       num_confirmed,
+                       num_unconfirmed
+               );
                #[cfg(not(feature = "time"))]
-               log_debug!(self.logger, "Finished transaction sync at tip {}: {} confirmed, {} unconfirmed.",
-                               tip_hash, num_confirmed, num_unconfirmed);
+               log_debug!(
+                       self.logger,
+                       "Finished transaction sync at tip {}: {} confirmed, {} unconfirmed.",
+                       tip_hash,
+                       num_confirmed,
+                       num_unconfirmed
+               );
                Ok(())
        }
 
@@ -244,7 +259,8 @@ where
        fn sync_best_block_updated<C: Deref>(
                &self, confirmables: &Vec<C>, sync_state: &mut SyncState, tip_hash: &BlockHash,
        ) -> Result<(), InternalError>
-               where C::Target: Confirm
+       where
+               C::Target: Confirm,
        {
                // Inform the interface of the new block.
                let tip_header = maybe_await!(self.client.get_header_by_hash(tip_hash))?;
@@ -268,7 +284,6 @@ where
        fn get_confirmed_transactions(
                &self, sync_state: &SyncState,
        ) -> Result<Vec<ConfirmedTx>, InternalError> {
-
                // First, check the confirmation status of registered transactions as well as the
                // status of dependent transactions of registered outputs.
 
@@ -284,7 +299,8 @@ where
                }
 
                for (_, output) in &sync_state.watched_outputs {
-                       if let Some(output_status) = maybe_await!(self.client
+                       if let Some(output_status) = maybe_await!(self
+                               .client
                                .get_output_status(&output.outpoint.txid, output.outpoint.index as u64))?
                        {
                                if let Some(spending_txid) = output_status.txid {
@@ -299,13 +315,11 @@ where
                                                        }
                                                }
 
-                                               if let Some(confirmed_tx) = maybe_await!(self
-                                                       .get_confirmed_tx(
-                                                               spending_txid,
-                                                               spending_tx_status.block_hash,
-                                                               spending_tx_status.block_height,
-                                                       ))?
-                                               {
+                                               if let Some(confirmed_tx) = maybe_await!(self.get_confirmed_tx(
+                                                       spending_txid,
+                                                       spending_tx_status.block_hash,
+                                                       spending_tx_status.block_height,
+                                               ))? {
                                                        confirmed_txs.push(confirmed_tx);
                                                }
                                        }
@@ -331,7 +345,13 @@ where
                        let block_hash = block_header.block_hash();
                        if let Some(expected_block_hash) = expected_block_hash {
                                if expected_block_hash != block_hash {
-                                       log_trace!(self.logger, "Inconsistency: Tx {} expected in block {}, but is confirmed in {}", txid, expected_block_hash, block_hash);
+                                       log_trace!(
+                                               self.logger,
+                                               "Inconsistency: Tx {} expected in block {}, but is confirmed in {}",
+                                               txid,
+                                               expected_block_hash,
+                                               block_hash
+                                       );
                                        return Err(InternalError::Inconsistency);
                                }
                        }
@@ -363,7 +383,11 @@ where
                                } else {
                                        // If any previously-confirmed block suddenly is no longer confirmed, we found
                                        // an inconsistency and should start over.
-                                       log_trace!(self.logger, "Inconsistency: Tx {} was unconfirmed during syncing.", txid);
+                                       log_trace!(
+                                               self.logger,
+                                               "Inconsistency: Tx {} was unconfirmed during syncing.",
+                                               txid
+                                       );
                                        return Err(InternalError::Inconsistency);
                                }
                        }
@@ -375,7 +399,8 @@ where
        fn get_unconfirmed_transactions<C: Deref>(
                &self, confirmables: &Vec<C>,
        ) -> Result<Vec<Txid>, InternalError>
-               where C::Target: Confirm
+       where
+               C::Target: Confirm,
        {
                // Query the interface for relevant txids and check whether the relevant blocks are still
                // in the best chain, mark them unconfirmed otherwise
@@ -422,7 +447,6 @@ type EsploraClientType = AsyncClient;
 #[cfg(not(feature = "async-interface"))]
 type EsploraClientType = BlockingClient;
 
-
 impl<L: Deref> Filter for EsploraSyncClient<L>
 where
        L::Target: Logger,
index d3f7dc8d9300419b7c5336e96deec3d09cd3a299..bccaaf4ed43a665f91c8fbe88abe0bc948334ce2 100644 (file)
 ./lightning-rapid-gossip-sync/src/lib.rs
 ./lightning-rapid-gossip-sync/src/processing.rs
 ./lightning-transaction-sync/src/error.rs
-./lightning-transaction-sync/src/esplora.rs
 ./lightning-transaction-sync/src/lib.rs
 ./lightning-transaction-sync/tests/integration_tests.rs
 ./lightning/src/blinded_path/message.rs