1
- use lightning:: chain:: { Confirm , WatchedOutput } ;
2
- use lightning:: chain:: channelmonitor:: ANTI_REORG_DELAY ;
3
- use bitcoin:: { Txid , BlockHash , Transaction , OutPoint } ;
4
1
use bitcoin:: block:: Header ;
2
+ use bitcoin:: { BlockHash , OutPoint , Transaction , Txid } ;
3
+ use lightning:: chain:: channelmonitor:: ANTI_REORG_DELAY ;
4
+ use lightning:: chain:: { Confirm , WatchedOutput } ;
5
5
6
- use std:: collections:: { HashSet , HashMap } ;
6
+ use std:: collections:: { HashMap , HashSet } ;
7
7
use std:: ops:: Deref ;
8
8
9
-
10
9
// Represents the current state.
11
10
pub ( crate ) struct SyncState {
12
11
// Transactions that were previously processed, but must not be forgotten
@@ -35,10 +34,9 @@ impl SyncState {
35
34
}
36
35
}
37
36
pub fn sync_unconfirmed_transactions < C : Deref > (
38
- & mut self , confirmables : & Vec < C > ,
39
- unconfirmed_txs : Vec < Txid > ,
40
- )
41
- where C :: Target : Confirm ,
37
+ & mut self , confirmables : & Vec < C > , unconfirmed_txs : Vec < Txid > ,
38
+ ) where
39
+ C :: Target : Confirm ,
42
40
{
43
41
for txid in unconfirmed_txs {
44
42
for c in confirmables {
@@ -49,22 +47,23 @@ impl SyncState {
49
47
50
48
// If a previously-confirmed output spend is unconfirmed, re-add the watched output to
51
49
// the tracking map.
52
- self . outputs_spends_pending_threshold_conf . retain ( |( conf_txid, _, prev_outpoint, output) | {
53
- if txid == * conf_txid {
54
- self . watched_outputs . insert ( * prev_outpoint, output. clone ( ) ) ;
55
- false
56
- } else {
57
- true
58
- }
59
- } )
50
+ self . outputs_spends_pending_threshold_conf . retain (
51
+ |( conf_txid, _, prev_outpoint, output) | {
52
+ if txid == * conf_txid {
53
+ self . watched_outputs . insert ( * prev_outpoint, output. clone ( ) ) ;
54
+ false
55
+ } else {
56
+ true
57
+ }
58
+ } ,
59
+ )
60
60
}
61
61
}
62
62
63
63
pub fn sync_confirmed_transactions < C : Deref > (
64
- & mut self , confirmables : & Vec < C > ,
65
- confirmed_txs : Vec < ConfirmedTx >
66
- )
67
- where C :: Target : Confirm ,
64
+ & mut self , confirmables : & Vec < C > , confirmed_txs : Vec < ConfirmedTx > ,
65
+ ) where
66
+ C :: Target : Confirm ,
68
67
{
69
68
for ctx in confirmed_txs {
70
69
for c in confirmables {
@@ -79,20 +78,19 @@ impl SyncState {
79
78
80
79
for input in & ctx. tx . input {
81
80
if let Some ( output) = self . watched_outputs . remove ( & input. previous_output ) {
82
- self . outputs_spends_pending_threshold_conf . push ( ( ctx. tx . txid ( ) , ctx. block_height , input. previous_output , output) ) ;
81
+ let spent = ( ctx. tx . txid ( ) , ctx. block_height , input. previous_output , output) ;
82
+ self . outputs_spends_pending_threshold_conf . push ( spent) ;
83
83
}
84
84
}
85
85
}
86
86
}
87
87
88
88
pub fn prune_output_spends ( & mut self , cur_height : u32 ) {
89
- self . outputs_spends_pending_threshold_conf . retain ( |( _, conf_height, _, _) | {
90
- cur_height < conf_height + ANTI_REORG_DELAY - 1
91
- } ) ;
89
+ self . outputs_spends_pending_threshold_conf
90
+ . retain ( |( _, conf_height, _, _) | cur_height < conf_height + ANTI_REORG_DELAY - 1 ) ;
92
91
}
93
92
}
94
93
95
-
96
94
// A queue that is to be filled by `Filter` and drained during the next syncing round.
97
95
pub ( crate ) struct FilterQueue {
98
96
// Transactions that were registered via the `Filter` interface and have to be processed.
@@ -103,10 +101,7 @@ pub(crate) struct FilterQueue {
103
101
104
102
impl FilterQueue {
105
103
pub fn new ( ) -> Self {
106
- Self {
107
- transactions : HashSet :: new ( ) ,
108
- outputs : HashMap :: new ( ) ,
109
- }
104
+ Self { transactions : HashSet :: new ( ) , outputs : HashMap :: new ( ) }
110
105
}
111
106
112
107
// Processes the transaction and output queues and adds them to the given [`SyncState`].
0 commit comments