@@ -14,8 +14,6 @@ use bitcoin::{Transaction, Txid};
1414pub struct CanonicalizationRequest < A > {
1515 /// The anchors to check.
1616 pub anchors : Vec < A > ,
17- /// The chain tip to check against.
18- pub chain_tip : BlockId ,
1917}
2018
2119/// Response containing the best confirmed anchor, if any.
@@ -30,7 +28,6 @@ type NotCanonicalSet = HashSet<Txid>;
3028/// Manages the canonicalization process without direct I/O operations.
3129pub struct CanonicalizationTask < ' g , A > {
3230 tx_graph : & ' g TxGraph < A > ,
33- chain_tip : BlockId ,
3431
3532 unprocessed_assumed_txs : Box < dyn Iterator < Item = ( Txid , Arc < Transaction > ) > + ' g > ,
3633 unprocessed_anchored_txs :
@@ -52,13 +49,10 @@ pub struct CanonicalizationTask<'g, A> {
5249
5350impl < ' g , A : Anchor > CanonicalizationTask < ' g , A > {
5451 /// Creates a new canonicalization task.
55- ///
56- /// Returns the task and an optional initial request.
5752 pub fn new (
5853 tx_graph : & ' g TxGraph < A > ,
59- chain_tip : BlockId ,
6054 params : CanonicalizationParams ,
61- ) -> ( Self , Option < CanonicalizationRequest < A > > ) {
55+ ) -> Self {
6256 let anchors = tx_graph. all_anchors ( ) ;
6357 let unprocessed_assumed_txs = Box :: new (
6458 params
@@ -80,7 +74,6 @@ impl<'g, A: Anchor> CanonicalizationTask<'g, A> {
8074
8175 let mut task = Self {
8276 tx_graph,
83- chain_tip,
8477
8578 unprocessed_assumed_txs,
8679 unprocessed_anchored_txs,
@@ -96,22 +89,18 @@ impl<'g, A: Anchor> CanonicalizationTask<'g, A> {
9689 confirmed_anchors : HashMap :: new ( ) ,
9790 } ;
9891
99- // Process assumed transactions first (they don't need queries)
92+ // process assumed transactions first (they don't need queries)
10093 task. process_assumed_txs ( ) ;
10194
102- // Process anchored transactions and get the first request if needed
103- let initial_request = task. process_anchored_txs ( ) ;
104-
105- ( task, initial_request)
95+ task
10696 }
10797
10898 /// Returns the next query needed, if any.
10999 pub fn next_query ( & mut self ) -> Option < CanonicalizationRequest < A > > {
110100 // Check if we have pending anchor checks
111101 if let Some ( ( _, _, anchors) ) = self . pending_anchor_checks . front ( ) {
112102 return Some ( CanonicalizationRequest {
113- anchors : anchors. clone ( ) ,
114- chain_tip : self . chain_tip ,
103+ anchors : anchors. clone ( )
115104 } ) ;
116105 }
117106
@@ -152,7 +141,7 @@ impl<'g, A: Anchor> CanonicalizationTask<'g, A> {
152141 }
153142
154143 /// Completes the canonicalization and returns a CanonicalView.
155- pub fn finish ( mut self ) -> CanonicalView < A > {
144+ pub fn finish ( mut self , chain_tip : BlockId ) -> CanonicalView < A > {
156145 // Process remaining transactions (seen and leftover)
157146 self . process_seen_txs ( ) ;
158147 self . process_leftover_txs ( ) ;
@@ -232,7 +221,7 @@ impl<'g, A: Anchor> CanonicalizationTask<'g, A> {
232221 }
233222 }
234223
235- CanonicalView :: from_parts ( self . chain_tip , view_order, view_txs, view_spends)
224+ CanonicalView :: new ( chain_tip, view_order, view_txs, view_spends)
236225 }
237226
238227 fn is_canonicalized ( & self , txid : Txid ) -> bool {
@@ -426,23 +415,10 @@ mod tests {
426415 } ;
427416 let _ = tx_graph. insert_anchor ( txid, anchor) ;
428417
429- // Create canonicalization task
418+ // Create canonicalization task and canonicalize using the chain
430419 let params = CanonicalizationParams :: default ( ) ;
431- let ( mut task, initial_request) = CanonicalizationTask :: new ( & tx_graph, chain_tip, params) ;
432-
433- // Process requests
434- if let Some ( request) = initial_request {
435- let response = chain. handle_canonicalization_request ( & request) . unwrap ( ) ;
436- task. resolve_query ( response) ;
437- }
438-
439- while let Some ( request) = task. next_query ( ) {
440- let response = chain. handle_canonicalization_request ( & request) . unwrap ( ) ;
441- task. resolve_query ( response) ;
442- }
443-
444- // Get canonical view
445- let canonical_view = task. finish ( ) ;
420+ let task = CanonicalizationTask :: new ( & tx_graph, params) ;
421+ let canonical_view = chain. canonicalize ( task) . unwrap ( ) ;
446422
447423 // Should have one canonical transaction
448424 assert_eq ! ( canonical_view. txs( ) . len( ) , 1 ) ;
0 commit comments