1
- use crate :: TxSyncError ;
1
+ use crate :: error :: { TxSyncError , InternalError } ;
2
2
3
3
use lightning:: util:: logger:: Logger ;
4
4
use lightning:: { log_error, log_given_level, log_info, log_internal, log_debug, log_trace} ;
@@ -88,13 +88,13 @@ where
88
88
// (Semi-)permanent failure, retry later.
89
89
log_error ! ( self . logger, "Failed during transaction sync, aborting." ) ;
90
90
self . pending_sync . store ( true , Ordering :: SeqCst ) ;
91
- return Err ( err) ;
91
+ return Err ( TxSyncError :: from ( err) ) ;
92
92
}
93
93
}
94
94
95
95
match maybe_await ! ( self . sync_best_block_updated( & confirmables, & tip_hash) ) {
96
96
Ok ( ( ) ) => { }
97
- Err ( TxSyncError :: Inconsistency ) => {
97
+ Err ( InternalError :: Inconsistency ) => {
98
98
// Immediately restart syncing when we encounter any inconsistencies.
99
99
log_debug ! ( self . logger, "Encountered inconsistency during transaction sync, restarting." ) ;
100
100
self . pending_sync . store ( true , Ordering :: SeqCst ) ;
@@ -103,7 +103,7 @@ where
103
103
Err ( err) => {
104
104
// (Semi-)permanent failure, retry later.
105
105
self . pending_sync . store ( true , Ordering :: SeqCst ) ;
106
- return Err ( err) ;
106
+ return Err ( TxSyncError :: from ( err) ) ;
107
107
}
108
108
}
109
109
}
@@ -124,7 +124,7 @@ where
124
124
spent_outputs,
125
125
) ;
126
126
}
127
- Err ( TxSyncError :: Inconsistency ) => {
127
+ Err ( InternalError :: Inconsistency ) => {
128
128
// Immediately restart syncing when we encounter any inconsistencies.
129
129
log_debug ! ( self . logger, "Encountered inconsistency during transaction sync, restarting." ) ;
130
130
self . pending_sync . store ( true , Ordering :: SeqCst ) ;
@@ -134,7 +134,7 @@ where
134
134
// (Semi-)permanent failure, retry later.
135
135
log_error ! ( self . logger, "Failed during transaction sync, aborting." ) ;
136
136
self . pending_sync . store ( true , Ordering :: SeqCst ) ;
137
- return Err ( err) ;
137
+ return Err ( TxSyncError :: from ( err) ) ;
138
138
}
139
139
}
140
140
* locked_last_sync_hash = Some ( tip_hash) ;
@@ -209,7 +209,7 @@ where
209
209
#[ maybe_async]
210
210
fn sync_best_block_updated (
211
211
& self , confirmables : & Vec < & ( dyn Confirm + Sync + Send ) > , tip_hash : & BlockHash ,
212
- ) -> Result < ( ) , TxSyncError > {
212
+ ) -> Result < ( ) , InternalError > {
213
213
214
214
// Inform the interface of the new block.
215
215
let tip_header = maybe_await ! ( self . client. get_header_by_hash( tip_hash) ) ?;
@@ -221,7 +221,7 @@ where
221
221
}
222
222
}
223
223
} else {
224
- return Err ( TxSyncError :: Inconsistency ) ;
224
+ return Err ( InternalError :: Inconsistency ) ;
225
225
}
226
226
Ok ( ( ) )
227
227
}
@@ -250,7 +250,7 @@ where
250
250
#[ maybe_async]
251
251
fn get_confirmed_transactions (
252
252
& self ,
253
- ) -> Result < ( Vec < ConfirmedTx > , HashSet < WatchedOutput > ) , TxSyncError > {
253
+ ) -> Result < ( Vec < ConfirmedTx > , HashSet < WatchedOutput > ) , InternalError > {
254
254
255
255
// First, check the confirmation status of registered transactions as well as the
256
256
// status of dependent transactions of registered outputs.
@@ -307,22 +307,22 @@ where
307
307
#[ maybe_async]
308
308
fn get_confirmed_tx (
309
309
& self , txid : & Txid , expected_block_hash : Option < BlockHash > , known_block_height : Option < u32 > ,
310
- ) -> Result < Option < ConfirmedTx > , TxSyncError > {
310
+ ) -> Result < Option < ConfirmedTx > , InternalError > {
311
311
if let Some ( merkle_block) = maybe_await ! ( self . client. get_merkle_block( & txid) ) ? {
312
312
let block_header = merkle_block. header ;
313
313
let block_hash = block_header. block_hash ( ) ;
314
314
if let Some ( expected_block_hash) = expected_block_hash {
315
315
if expected_block_hash != block_hash {
316
316
log_trace ! ( self . logger, "Inconsistency: Tx {} expected in block {}, but is confirmed in {}" , txid, expected_block_hash, block_hash) ;
317
- return Err ( TxSyncError :: Inconsistency ) ;
317
+ return Err ( InternalError :: Inconsistency ) ;
318
318
}
319
319
}
320
320
321
321
let mut matches = vec ! [ * txid] ;
322
322
let mut indexes = Vec :: new ( ) ;
323
323
let _ = merkle_block. txn . extract_matches ( & mut matches, & mut indexes) ;
324
324
debug_assert_eq ! ( indexes. len( ) , 1 ) ;
325
- let pos = * indexes. get ( 0 ) . ok_or ( TxSyncError :: Failed ) ? as usize ;
325
+ let pos = * indexes. get ( 0 ) . ok_or ( InternalError :: Failed ) ? as usize ;
326
326
if let Some ( tx) = maybe_await ! ( self . client. get_tx( & txid) ) ? {
327
327
if let Some ( block_height) = known_block_height {
328
328
// We can take a shortcut here if a previous call already gave us the height.
@@ -336,7 +336,7 @@ where
336
336
// If any previously-confirmed block suddenly is no longer confirmed, we found
337
337
// an inconsistency and should start over.
338
338
log_trace ! ( self . logger, "Inconsistency: Tx {} was unconfirmed during syncing." , txid) ;
339
- return Err ( TxSyncError :: Inconsistency ) ;
339
+ return Err ( InternalError :: Inconsistency ) ;
340
340
}
341
341
}
342
342
}
@@ -346,7 +346,7 @@ where
346
346
#[ maybe_async]
347
347
fn sync_unconfirmed_transactions (
348
348
& self , confirmables : & Vec < & ( dyn Confirm + Sync + Send ) > ,
349
- ) -> Result < ( ) , TxSyncError > {
349
+ ) -> Result < ( ) , InternalError > {
350
350
// Query the interface for relevant txids and check whether the relevant blocks are still
351
351
// in the best chain, mark them unconfirmed otherwise. If the transactions have been
352
352
// reconfirmed in another block, we'll confirm them in the next sync iteration.
0 commit comments