@@ -14,7 +14,7 @@ type NotCanonicalSet = HashSet<Txid>;
14
14
/// Modifies the canonicalization algorithm.
15
15
#[ derive( Debug , Default , Clone ) ]
16
16
pub struct CanonicalizationParams {
17
- /// Transactions that will supercede all other transactions.
17
+ /// Transactions that will supersede all other transactions.
18
18
///
19
19
/// In case of conflicting transactions within `assume_canonical`, transactions that appear
20
20
/// later in the list (have higher index) have precedence.
@@ -108,7 +108,7 @@ impl<'g, A: Anchor, C: ChainOracle> CanonicalIter<'g, A, C> {
108
108
. iter ( )
109
109
. last ( )
110
110
. expect (
111
- "tx taken from `unprocessed_txs_with_anchors` so it must atleast have an anchor" ,
111
+ "tx taken from `unprocessed_txs_with_anchors` so it must at least have an anchor" ,
112
112
)
113
113
. confirmation_height_upper_bound ( ) ,
114
114
) ) ;
@@ -142,8 +142,9 @@ impl<'g, A: Anchor, C: ChainOracle> CanonicalIter<'g, A, C> {
142
142
let staged_queue = TxAncestors :: new_include_root (
143
143
self . tx_graph ,
144
144
tx,
145
- |_ : usize , tx : Arc < Transaction > | -> Option < Txid > {
145
+ |depth : usize , tx : Arc < Transaction > | -> Option < Txid > {
146
146
let this_txid = tx. compute_txid ( ) ;
147
+ println ! ( "[canonical_iter] depth: {:?} ; txid: {:?}" , depth, this_txid) ;
147
148
let this_reason = if is_starting_tx {
148
149
is_starting_tx = false ;
149
150
reason. clone ( )
@@ -158,6 +159,8 @@ impl<'g, A: Anchor, C: ChainOracle> CanonicalIter<'g, A, C> {
158
159
Entry :: Vacant ( entry) => entry,
159
160
} ;
160
161
162
+ // TODO: should we also check that it's already been visited by the `self.not_canonical` ?
163
+
161
164
// Any conflicts with a canonical tx can be added to `not_canonical`. Descendants
162
165
// of `not_canonical` txs can also be added to `not_canonical`.
163
166
for ( _, conflict_txid) in self . tx_graph . direct_conflicts ( & tx) {
@@ -166,8 +169,8 @@ impl<'g, A: Anchor, C: ChainOracle> CanonicalIter<'g, A, C> {
166
169
conflict_txid,
167
170
|_: usize , txid : Txid | -> Option < ( ) > {
168
171
if self . not_canonical . insert ( txid) {
169
- undo_not_canonical. push ( txid) ;
170
- Some ( ( ) )
172
+ undo_not_canonical. push ( txid) ;
173
+ Some ( ( ) )
171
174
} else {
172
175
None
173
176
}
@@ -181,7 +184,8 @@ impl<'g, A: Anchor, C: ChainOracle> CanonicalIter<'g, A, C> {
181
184
detected_self_double_spend = true ;
182
185
return None ;
183
186
}
184
- canonical_entry. insert ( ( tx, this_reason) ) ;
187
+ canonical_entry. insert ( ( tx. clone ( ) , this_reason) ) ;
188
+ println ! ( "mark_canonical: {:?}" , tx. clone( ) . compute_txid( ) ) ;
185
189
Some ( this_txid)
186
190
} ,
187
191
)
@@ -196,6 +200,7 @@ impl<'g, A: Anchor, C: ChainOracle> CanonicalIter<'g, A, C> {
196
200
}
197
201
} else {
198
202
self . queue . extend ( staged_queue) ;
203
+ println ! ( "staged_queue: {:?}" , self . queue) ;
199
204
}
200
205
}
201
206
}
@@ -205,7 +210,7 @@ impl<A: Anchor, C: ChainOracle> Iterator for CanonicalIter<'_, A, C> {
205
210
206
211
fn next ( & mut self ) -> Option < Self :: Item > {
207
212
loop {
208
- if let Some ( txid) = self . queue . pop_front ( ) {
213
+ if let Some ( txid) = self . queue . pop_back ( ) {
209
214
let ( tx, reason) = self
210
215
. canonical
211
216
. get ( & txid)
@@ -222,6 +227,7 @@ impl<A: Anchor, C: ChainOracle> Iterator for CanonicalIter<'_, A, C> {
222
227
223
228
if let Some ( ( txid, tx, anchors) ) = self . unprocessed_anchored_txs . next ( ) {
224
229
if !self . is_canonicalized ( txid) {
230
+ println ! ( "{:?}" , txid) ;
225
231
if let Err ( err) = self . scan_anchors ( txid, tx, anchors) {
226
232
return Some ( Err ( err) ) ;
227
233
}
@@ -266,7 +272,7 @@ pub enum ObservedIn {
266
272
/// The reason why a transaction is canonical.
267
273
#[ derive( Debug , Clone , PartialEq , Eq ) ]
268
274
pub enum CanonicalReason < A > {
269
- /// This transaction is explicitly assumed to be canonical by the caller, superceding all other
275
+ /// This transaction is explicitly assumed to be canonical by the caller, superseding all other
270
276
/// canonicalization rules.
271
277
Assumed {
272
278
/// Whether it is a descendant that is assumed to be canonical.
@@ -312,7 +318,7 @@ impl<A: Clone> CanonicalReason<A> {
312
318
}
313
319
}
314
320
315
- /// Contruct a new [`CanonicalReason`] from the original which is transitive to `descendant`.
321
+ /// Construct a new [`CanonicalReason`] from the original which is transitive to `descendant`.
316
322
///
317
323
/// This signals that either the [`ObservedIn`] or [`Anchor`] value belongs to the transaction's
318
324
/// descendant, but is transitively relevant.
0 commit comments