@@ -13,9 +13,10 @@ pub struct CanonicalIter<'g, A, C> {
13
13
chain : & ' g C ,
14
14
chain_tip : BlockId ,
15
15
16
- pending_anchored : Box < dyn Iterator < Item = ( Txid , Arc < Transaction > , & ' g BTreeSet < A > ) > + ' g > ,
17
- pending_last_seen : Box < dyn Iterator < Item = ( Txid , Arc < Transaction > , u64 ) > + ' g > ,
18
- pending_remaining : VecDeque < ( Txid , Arc < Transaction > , u32 ) > ,
16
+ unprocessed_txs_with_anchors :
17
+ Box < dyn Iterator < Item = ( Txid , Arc < Transaction > , & ' g BTreeSet < A > ) > + ' g > ,
18
+ unprocessed_txs_with_last_seens : Box < dyn Iterator < Item = ( Txid , Arc < Transaction > , u64 ) > + ' g > ,
19
+ unprocessed_txs_left_over : VecDeque < ( Txid , Arc < Transaction > , u32 ) > ,
19
20
20
21
canonical : HashMap < Txid , ( Arc < Transaction > , CanonicalReason < A > ) > ,
21
22
not_canonical : HashSet < Txid > ,
@@ -41,9 +42,9 @@ impl<'g, A: Anchor, C: ChainOracle> CanonicalIter<'g, A, C> {
41
42
tx_graph,
42
43
chain,
43
44
chain_tip,
44
- pending_anchored,
45
- pending_last_seen,
46
- pending_remaining : VecDeque :: new ( ) ,
45
+ unprocessed_txs_with_anchors : pending_anchored,
46
+ unprocessed_txs_with_last_seens : pending_last_seen,
47
+ unprocessed_txs_left_over : VecDeque :: new ( ) ,
47
48
canonical : HashMap :: new ( ) ,
48
49
not_canonical : HashSet :: new ( ) ,
49
50
queue : VecDeque :: new ( ) ,
@@ -67,27 +68,29 @@ impl<'g, A: Anchor, C: ChainOracle> CanonicalIter<'g, A, C> {
67
68
. chain
68
69
. is_block_in_chain ( anchor. anchor_block ( ) , self . chain_tip ) ?;
69
70
if in_chain_opt == Some ( true ) {
70
- self . mark_canonical ( tx, CanonicalReason :: from_anchor ( anchor. clone ( ) ) ) ;
71
+ self . mark_canonical ( txid , tx, CanonicalReason :: from_anchor ( anchor. clone ( ) ) ) ;
71
72
return Ok ( ( ) ) ;
72
73
}
73
74
}
74
75
// cannot determine
75
- self . pending_remaining . push_back ( (
76
+ self . unprocessed_txs_left_over . push_back ( (
76
77
txid,
77
78
tx,
78
79
anchors
79
80
. iter ( )
80
81
. last ( )
81
- . unwrap ( )
82
+ . expect (
83
+ "tx taken from `unprocessed_txs_with_anchors` so it must atleast have an anchor" ,
84
+ )
82
85
. confirmation_height_upper_bound ( ) ,
83
86
) ) ;
84
87
Ok ( ( ) )
85
88
}
86
89
87
90
/// Marks a transaction and it's ancestors as canoncial. Mark all conflicts of these as
88
91
/// `not_canonical`.
89
- fn mark_canonical ( & mut self , tx : Arc < Transaction > , reason : CanonicalReason < A > ) {
90
- let starting_txid = tx . compute_txid ( ) ;
92
+ fn mark_canonical ( & mut self , txid : Txid , tx : Arc < Transaction > , reason : CanonicalReason < A > ) {
93
+ let starting_txid = txid ;
91
94
let mut is_root = true ;
92
95
TxAncestors :: new_include_root (
93
96
self . tx_graph ,
@@ -126,11 +129,11 @@ impl<'g, A: Anchor, C: ChainOracle> CanonicalIter<'g, A, C> {
126
129
Some ( ( ) )
127
130
} ,
128
131
)
129
- . for_each ( |_| { } )
132
+ . run_until_finished ( )
130
133
}
131
134
}
132
135
133
- impl < ' g , A : Anchor , C : ChainOracle > Iterator for CanonicalIter < ' g , A , C > {
136
+ impl < A : Anchor , C : ChainOracle > Iterator for CanonicalIter < ' _ , A , C > {
134
137
type Item = Result < ( Txid , Arc < Transaction > , CanonicalReason < A > ) , C :: Error > ;
135
138
136
139
fn next ( & mut self ) -> Option < Self :: Item > {
@@ -144,7 +147,7 @@ impl<'g, A: Anchor, C: ChainOracle> Iterator for CanonicalIter<'g, A, C> {
144
147
return Some ( Ok ( ( txid, tx, reason) ) ) ;
145
148
}
146
149
147
- if let Some ( ( txid, tx, anchors) ) = self . pending_anchored . next ( ) {
150
+ if let Some ( ( txid, tx, anchors) ) = self . unprocessed_txs_with_anchors . next ( ) {
148
151
if !self . is_canonicalized ( txid) {
149
152
if let Err ( err) = self . scan_anchors ( txid, tx, anchors) {
150
153
return Some ( Err ( err) ) ;
@@ -153,18 +156,18 @@ impl<'g, A: Anchor, C: ChainOracle> Iterator for CanonicalIter<'g, A, C> {
153
156
continue ;
154
157
}
155
158
156
- if let Some ( ( txid, tx, last_seen) ) = self . pending_last_seen . next ( ) {
159
+ if let Some ( ( txid, tx, last_seen) ) = self . unprocessed_txs_with_last_seens . next ( ) {
157
160
if !self . is_canonicalized ( txid) {
158
161
let observed_in = ObservedIn :: Mempool ( last_seen) ;
159
- self . mark_canonical ( tx, CanonicalReason :: from_observed_in ( observed_in) ) ;
162
+ self . mark_canonical ( txid , tx, CanonicalReason :: from_observed_in ( observed_in) ) ;
160
163
}
161
164
continue ;
162
165
}
163
166
164
- if let Some ( ( txid, tx, height) ) = self . pending_remaining . pop_front ( ) {
167
+ if let Some ( ( txid, tx, height) ) = self . unprocessed_txs_left_over . pop_front ( ) {
165
168
if !self . is_canonicalized ( txid) {
166
169
let observed_in = ObservedIn :: Block ( height) ;
167
- self . mark_canonical ( tx, CanonicalReason :: from_observed_in ( observed_in) ) ;
170
+ self . mark_canonical ( txid , tx, CanonicalReason :: from_observed_in ( observed_in) ) ;
168
171
}
169
172
continue ;
170
173
}
@@ -212,7 +215,7 @@ impl<A: Clone> CanonicalReason<A> {
212
215
}
213
216
}
214
217
215
- /// Constructs a [`CanonicalReason`] from a `last_seen ` value.
218
+ /// Constructs a [`CanonicalReason`] from an `observed_in ` value.
216
219
pub fn from_observed_in ( observed_in : ObservedIn ) -> Self {
217
220
Self :: ObservedIn {
218
221
observed_in,
@@ -230,11 +233,8 @@ impl<A: Clone> CanonicalReason<A> {
230
233
anchor : anchor. clone ( ) ,
231
234
descendant : Some ( descendant) ,
232
235
} ,
233
- CanonicalReason :: ObservedIn {
234
- observed_in : last_seen,
235
- ..
236
- } => Self :: ObservedIn {
237
- observed_in : * last_seen,
236
+ CanonicalReason :: ObservedIn { observed_in, .. } => Self :: ObservedIn {
237
+ observed_in : * observed_in,
238
238
descendant : Some ( descendant) ,
239
239
} ,
240
240
}
0 commit comments