1- use crate :: error :: { TxSyncError , InternalError } ;
2- use crate :: common :: { SyncState , FilterQueue , ConfirmedTx } ;
1+ use crate :: common :: { ConfirmedTx , FilterQueue , SyncState } ;
2+ use crate :: error :: { InternalError , TxSyncError } ;
33
4- use lightning:: util:: logger:: Logger ;
5- use lightning:: { log_error, log_debug, log_trace} ;
64use lightning:: chain:: WatchedOutput ;
75use lightning:: chain:: { Confirm , Filter } ;
6+ use lightning:: util:: logger:: Logger ;
7+ use lightning:: { log_debug, log_error, log_trace} ;
88
99use bitcoin:: { BlockHash , Script , Txid } ;
1010
11- use esplora_client:: Builder ;
12- #[ cfg( feature = "async-interface" ) ]
13- use esplora_client:: r#async:: AsyncClient ;
1411#[ cfg( not( feature = "async-interface" ) ) ]
1512use esplora_client:: blocking:: BlockingClient ;
13+ #[ cfg( feature = "async-interface" ) ]
14+ use esplora_client:: r#async:: AsyncClient ;
15+ use esplora_client:: Builder ;
1616
17- use std:: collections:: HashSet ;
1817use core:: ops:: Deref ;
18+ use std:: collections:: HashSet ;
1919
2020/// Synchronizes LDK with a given [`Esplora`] server.
2121///
6464 pub fn from_client ( client : EsploraClientType , logger : L ) -> Self {
6565 let sync_state = MutexType :: new ( SyncState :: new ( ) ) ;
6666 let queue = std:: sync:: Mutex :: new ( FilterQueue :: new ( ) ) ;
67- Self {
68- sync_state,
69- queue,
70- client,
71- logger,
72- }
67+ Self { sync_state, queue, client, logger }
7368 }
7469
7570 /// Synchronizes the given `confirmables` via their [`Confirm`] interface implementations. This
8580 /// [`Filter`]: lightning::chain::Filter
8681 #[ maybe_async]
8782 pub fn sync < C : Deref > ( & self , confirmables : Vec < C > ) -> Result < ( ) , TxSyncError >
88- where C :: Target : Confirm
83+ where
84+ C :: Target : Confirm ,
8985 {
9086 // This lock makes sure we're syncing once at a time.
9187 #[ cfg( not( feature = "async-interface" ) ) ]
@@ -130,9 +126,9 @@ where
130126 num_unconfirmed += unconfirmed_txs. len ( ) ;
131127 sync_state. sync_unconfirmed_transactions (
132128 & confirmables,
133- unconfirmed_txs
129+ unconfirmed_txs,
134130 ) ;
135- }
131+ } ,
136132 Err ( err) => {
137133 // (Semi-)permanent failure, retry later.
138134 log_error ! ( self . logger,
@@ -142,7 +138,7 @@ where
142138 ) ;
143139 sync_state. pending_sync = true ;
144140 return Err ( TxSyncError :: from ( err) ) ;
145- }
141+ } ,
146142 }
147143 } ,
148144 Err ( err) => {
@@ -154,17 +150,24 @@ where
154150 ) ;
155151 sync_state. pending_sync = true ;
156152 return Err ( TxSyncError :: from ( err) ) ;
157- }
153+ } ,
158154 }
159155
160- match maybe_await ! ( self . sync_best_block_updated( & confirmables, & mut sync_state, & tip_hash) ) {
161- Ok ( ( ) ) => { }
156+ match maybe_await ! ( self . sync_best_block_updated(
157+ & confirmables,
158+ & mut sync_state,
159+ & tip_hash
160+ ) ) {
161+ Ok ( ( ) ) => { } ,
162162 Err ( InternalError :: Inconsistency ) => {
163163 // Immediately restart syncing when we encounter any inconsistencies.
164- log_debug ! ( self . logger, "Encountered inconsistency during transaction sync, restarting." ) ;
164+ log_debug ! (
165+ self . logger,
166+ "Encountered inconsistency during transaction sync, restarting."
167+ ) ;
165168 sync_state. pending_sync = true ;
166169 continue ;
167- }
170+ } ,
168171 Err ( err) => {
169172 // (Semi-)permanent failure, retry later.
170173 log_error ! ( self . logger,
@@ -174,7 +177,7 @@ where
174177 ) ;
175178 sync_state. pending_sync = true ;
176179 return Err ( TxSyncError :: from ( err) ) ;
177- }
180+ } ,
178181 }
179182 }
180183
@@ -193,11 +196,9 @@ where
193196 continue ;
194197 }
195198 num_confirmed += confirmed_txs. len ( ) ;
196- sync_state. sync_confirmed_transactions (
197- & confirmables,
198- confirmed_txs
199- ) ;
200- }
199+ sync_state
200+ . sync_confirmed_transactions ( & confirmables, confirmed_txs) ;
201+ } ,
201202 Err ( err) => {
202203 // (Semi-)permanent failure, retry later.
203204 log_error ! ( self . logger,
@@ -207,15 +208,18 @@ where
207208 ) ;
208209 sync_state. pending_sync = true ;
209210 return Err ( TxSyncError :: from ( err) ) ;
210- }
211+ } ,
211212 }
212- }
213+ } ,
213214 Err ( InternalError :: Inconsistency ) => {
214215 // Immediately restart syncing when we encounter any inconsistencies.
215- log_debug ! ( self . logger, "Encountered inconsistency during transaction sync, restarting." ) ;
216+ log_debug ! (
217+ self . logger,
218+ "Encountered inconsistency during transaction sync, restarting."
219+ ) ;
216220 sync_state. pending_sync = true ;
217221 continue ;
218- }
222+ } ,
219223 Err ( err) => {
220224 // (Semi-)permanent failure, retry later.
221225 log_error ! ( self . logger,
@@ -225,26 +229,38 @@ where
225229 ) ;
226230 sync_state. pending_sync = true ;
227231 return Err ( TxSyncError :: from ( err) ) ;
228- }
232+ } ,
229233 }
230234 sync_state. last_sync_hash = Some ( tip_hash) ;
231235 sync_state. pending_sync = false ;
232236 }
233237 }
234238 #[ cfg( feature = "time" ) ]
235- log_debug ! ( self . logger, "Finished transaction sync at tip {} in {}ms: {} confirmed, {} unconfirmed." ,
236- tip_hash, start_time. elapsed( ) . as_millis( ) , num_confirmed, num_unconfirmed) ;
239+ log_debug ! (
240+ self . logger,
241+ "Finished transaction sync at tip {} in {}ms: {} confirmed, {} unconfirmed." ,
242+ tip_hash,
243+ start_time. elapsed( ) . as_millis( ) ,
244+ num_confirmed,
245+ num_unconfirmed
246+ ) ;
237247 #[ cfg( not( feature = "time" ) ) ]
238- log_debug ! ( self . logger, "Finished transaction sync at tip {}: {} confirmed, {} unconfirmed." ,
239- tip_hash, num_confirmed, num_unconfirmed) ;
248+ log_debug ! (
249+ self . logger,
250+ "Finished transaction sync at tip {}: {} confirmed, {} unconfirmed." ,
251+ tip_hash,
252+ num_confirmed,
253+ num_unconfirmed
254+ ) ;
240255 Ok ( ( ) )
241256 }
242257
243258 #[ maybe_async]
244259 fn sync_best_block_updated < C : Deref > (
245260 & self , confirmables : & Vec < C > , sync_state : & mut SyncState , tip_hash : & BlockHash ,
246261 ) -> Result < ( ) , InternalError >
247- where C :: Target : Confirm
262+ where
263+ C :: Target : Confirm ,
248264 {
249265 // Inform the interface of the new block.
250266 let tip_header = maybe_await ! ( self . client. get_header_by_hash( tip_hash) ) ?;
@@ -268,7 +284,6 @@ where
268284 fn get_confirmed_transactions (
269285 & self , sync_state : & SyncState ,
270286 ) -> Result < Vec < ConfirmedTx > , InternalError > {
271-
272287 // First, check the confirmation status of registered transactions as well as the
273288 // status of dependent transactions of registered outputs.
274289
@@ -284,7 +299,8 @@ where
284299 }
285300
286301 for ( _, output) in & sync_state. watched_outputs {
287- if let Some ( output_status) = maybe_await ! ( self . client
302+ if let Some ( output_status) = maybe_await ! ( self
303+ . client
288304 . get_output_status( & output. outpoint. txid, output. outpoint. index as u64 ) ) ?
289305 {
290306 if let Some ( spending_txid) = output_status. txid {
@@ -299,13 +315,11 @@ where
299315 }
300316 }
301317
302- if let Some ( confirmed_tx) = maybe_await ! ( self
303- . get_confirmed_tx(
304- spending_txid,
305- spending_tx_status. block_hash,
306- spending_tx_status. block_height,
307- ) ) ?
308- {
318+ if let Some ( confirmed_tx) = maybe_await ! ( self . get_confirmed_tx(
319+ spending_txid,
320+ spending_tx_status. block_hash,
321+ spending_tx_status. block_height,
322+ ) ) ? {
309323 confirmed_txs. push ( confirmed_tx) ;
310324 }
311325 }
@@ -331,7 +345,13 @@ where
331345 let block_hash = block_header. block_hash ( ) ;
332346 if let Some ( expected_block_hash) = expected_block_hash {
333347 if expected_block_hash != block_hash {
334- log_trace ! ( self . logger, "Inconsistency: Tx {} expected in block {}, but is confirmed in {}" , txid, expected_block_hash, block_hash) ;
348+ log_trace ! (
349+ self . logger,
350+ "Inconsistency: Tx {} expected in block {}, but is confirmed in {}" ,
351+ txid,
352+ expected_block_hash,
353+ block_hash
354+ ) ;
335355 return Err ( InternalError :: Inconsistency ) ;
336356 }
337357 }
@@ -363,7 +383,11 @@ where
363383 } else {
364384 // If any previously-confirmed block suddenly is no longer confirmed, we found
365385 // an inconsistency and should start over.
366- log_trace ! ( self . logger, "Inconsistency: Tx {} was unconfirmed during syncing." , txid) ;
386+ log_trace ! (
387+ self . logger,
388+ "Inconsistency: Tx {} was unconfirmed during syncing." ,
389+ txid
390+ ) ;
367391 return Err ( InternalError :: Inconsistency ) ;
368392 }
369393 }
@@ -375,7 +399,8 @@ where
375399 fn get_unconfirmed_transactions < C : Deref > (
376400 & self , confirmables : & Vec < C > ,
377401 ) -> Result < Vec < Txid > , InternalError >
378- where C :: Target : Confirm
402+ where
403+ C :: Target : Confirm ,
379404 {
380405 // Query the interface for relevant txids and check whether the relevant blocks are still
381406 // in the best chain, mark them unconfirmed otherwise
@@ -422,7 +447,6 @@ type EsploraClientType = AsyncClient;
422447#[ cfg( not( feature = "async-interface" ) ) ]
423448type EsploraClientType = BlockingClient ;
424449
425-
426450impl < L : Deref > Filter for EsploraSyncClient < L >
427451where
428452 L :: Target : Logger ,
0 commit comments