9898 }
9999
100100 match maybe_await ! ( self . get_confirmed_transactions( ) ) {
101- Ok ( ( confirmed_txs, unconfirmed_registered_txs , unspent_registered_outputs ) ) => {
101+ Ok ( ( confirmed_txs, spent_outputs ) ) => {
102102 // Double-check tip hash. If something changed, restart last-minute.
103103 let check_tip_hash = maybe_await ! ( self . client. get_tip_hash( ) ) ?;
104104 if check_tip_hash != tip_hash {
@@ -109,8 +109,7 @@ where
109109 self . sync_confirmed_transactions (
110110 & confirmables,
111111 confirmed_txs,
112- unconfirmed_registered_txs,
113- unspent_registered_outputs,
112+ spent_outputs,
114113 ) ;
115114 }
116115 Err ( TxSyncError :: Inconsistency ) => {
@@ -206,9 +205,9 @@ where
206205
207206 fn sync_confirmed_transactions (
208207 & self , confirmables : & Vec < & ( dyn Confirm + Sync + Send ) > , confirmed_txs : Vec < ConfirmedTx > ,
209- unconfirmed_registered_txs : HashSet < Txid > ,
210- unspent_registered_outputs : HashSet < WatchedOutput > ,
208+ spent_outputs : HashSet < WatchedOutput > ,
211209 ) {
210+ let mut locked_watched_transactions = self . watched_transactions . lock ( ) . unwrap ( ) ;
212211 for ctx in confirmed_txs {
213212 for c in confirmables {
214213 c. transactions_confirmed (
@@ -217,16 +216,18 @@ where
217216 ctx. block_height ,
218217 ) ;
219218 }
219+
220+ locked_watched_transactions. remove ( & ctx. tx . txid ( ) ) ;
220221 }
221222
222- * self . watched_transactions . lock ( ) . unwrap ( ) = unconfirmed_registered_txs ;
223- * self . watched_outputs . lock ( ) . unwrap ( ) = unspent_registered_outputs ;
223+ let mut locked_watched_outputs = self . watched_outputs . lock ( ) . unwrap ( ) ;
224+ * locked_watched_outputs = & * locked_watched_outputs - & spent_outputs ;
224225 }
225226
226227 #[ maybe_async]
227228 fn get_confirmed_transactions (
228229 & self ,
229- ) -> Result < ( Vec < ConfirmedTx > , HashSet < Txid > , HashSet < WatchedOutput > ) , TxSyncError > {
230+ ) -> Result < ( Vec < ConfirmedTx > , HashSet < WatchedOutput > ) , TxSyncError > {
230231
231232 // First, check the confirmation status of registered transactions as well as the
232233 // status of dependent transactions of registered outputs.
@@ -237,22 +238,17 @@ where
237238 // previous iterations.
238239 let registered_txs = self . watched_transactions . lock ( ) . unwrap ( ) . clone ( ) ;
239240
240- // Remember all registered but unconfirmed transactions for future processing.
241- let mut unconfirmed_registered_txs = HashSet :: new ( ) ;
242-
243241 for txid in registered_txs {
244242 if let Some ( confirmed_tx) = maybe_await ! ( self . get_confirmed_tx( & txid, None , None ) ) ? {
245243 confirmed_txs. push ( confirmed_tx) ;
246- } else {
247- unconfirmed_registered_txs. insert ( txid) ;
248244 }
249245 }
250246
251247 // Check all registered outputs for dependent spending transactions.
252248 let registered_outputs = self . watched_outputs . lock ( ) . unwrap ( ) . clone ( ) ;
253249
254- // Remember all registered outputs that haven't been spent for future processing .
255- let mut unspent_registered_outputs = HashSet :: new ( ) ;
250+ // Remember all registered outputs that have been spent.
251+ let mut spent_outputs = HashSet :: new ( ) ;
256252
257253 for output in registered_outputs {
258254 if let Some ( output_status) = maybe_await ! ( self . client
@@ -268,12 +264,12 @@ where
268264 ) ) ?
269265 {
270266 confirmed_txs. push ( confirmed_tx) ;
267+ spent_outputs. insert ( output) ;
271268 continue ;
272269 }
273270 }
274271 }
275272 }
276- unspent_registered_outputs. insert ( output) ;
277273 }
278274
279275 // Sort all confirmed transactions first by block height, then by in-block
@@ -282,7 +278,7 @@ where
282278 tx1. block_height . cmp ( & tx2. block_height ) . then_with ( || tx1. pos . cmp ( & tx2. pos ) )
283279 } ) ;
284280
285- Ok ( ( confirmed_txs, unconfirmed_registered_txs , unspent_registered_outputs ) )
281+ Ok ( ( confirmed_txs, spent_outputs ) )
286282 }
287283
288284 #[ maybe_async]
@@ -336,7 +332,6 @@ where
336332 . flat_map ( |c| c. get_relevant_txids ( ) )
337333 . collect :: < HashSet < ( Txid , Option < BlockHash > ) > > ( ) ;
338334
339- let mut locked_watched_transactions = self . watched_transactions . lock ( ) . unwrap ( ) ;
340335 for ( txid, block_hash_opt) in relevant_txids {
341336 if let Some ( block_hash) = block_hash_opt {
342337 let block_status = maybe_await ! ( self . client. get_block_status( & block_hash) ) ?;
@@ -350,7 +345,7 @@ where
350345 c. transaction_unconfirmed ( & txid) ;
351346 }
352347
353- locked_watched_transactions . insert ( txid) ;
348+ self . watched_transactions . lock ( ) . unwrap ( ) . insert ( txid) ;
354349 }
355350
356351 Ok ( ( ) )
0 commit comments