From: 志宇 Date: Thu, 23 Jan 2025 02:33:43 +0000 (+1100) Subject: refactor(chain): Make private fields in `CanonicalIter` concise. X-Git-Tag: core-0.5.0~2^2~2 X-Git-Url: http://internal-gitweb-vhost/script/%22https:/database/scripts/enum.FromScriptError.html?a=commitdiff_plain;h=58fcf3287be09d28a34243cf7aa02b8de1012148;p=bdk refactor(chain): Make private fields in `CanonicalIter` concise. --- diff --git a/crates/chain/src/canonical_iter.rs b/crates/chain/src/canonical_iter.rs index 3e3cd6a4..837af4c9 100644 --- a/crates/chain/src/canonical_iter.rs +++ b/crates/chain/src/canonical_iter.rs @@ -17,10 +17,10 @@ pub struct CanonicalIter<'g, A, C> { chain: &'g C, chain_tip: BlockId, - unprocessed_txs_with_anchors: + unprocessed_anchored_txs: Box, &'g BTreeSet)> + 'g>, - unprocessed_txs_with_last_seens: Box, u64)> + 'g>, - unprocessed_txs_left_over: VecDeque<(Txid, Arc, u32)>, + unprocessed_seen_txs: Box, u64)> + 'g>, + unprocessed_leftover_txs: VecDeque<(Txid, Arc, u32)>, canonical: CanonicalMap, not_canonical: NotCanonicalSet, @@ -32,12 +32,12 @@ impl<'g, A: Anchor, C: ChainOracle> CanonicalIter<'g, A, C> { /// Constructs [`CanonicalIter`]. pub fn new(tx_graph: &'g TxGraph, chain: &'g C, chain_tip: BlockId) -> Self { let anchors = tx_graph.all_anchors(); - let pending_anchored = Box::new( + let unprocessed_anchored_txs = Box::new( tx_graph .txids_by_descending_anchor_height() .filter_map(|(_, txid)| Some((txid, tx_graph.get_tx(txid)?, anchors.get(&txid)?))), ); - let pending_last_seen = Box::new( + let unprocessed_seen_txs = Box::new( tx_graph .txids_by_descending_last_seen() .filter_map(|(last_seen, txid)| Some((txid, tx_graph.get_tx(txid)?, last_seen))), @@ -46,9 +46,9 @@ impl<'g, A: Anchor, C: ChainOracle> CanonicalIter<'g, A, C> { tx_graph, chain, chain_tip, - unprocessed_txs_with_anchors: pending_anchored, - unprocessed_txs_with_last_seens: pending_last_seen, - unprocessed_txs_left_over: VecDeque::new(), + unprocessed_anchored_txs, + unprocessed_seen_txs, + unprocessed_leftover_txs: VecDeque::new(), canonical: HashMap::new(), not_canonical: HashSet::new(), queue: VecDeque::new(), @@ -77,7 +77,7 @@ impl<'g, A: Anchor, C: ChainOracle> CanonicalIter<'g, A, C> { } } // cannot determine - self.unprocessed_txs_left_over.push_back(( + self.unprocessed_leftover_txs.push_back(( txid, tx, anchors @@ -190,7 +190,7 @@ impl Iterator for CanonicalIter<'_, A, C> { return Some(Ok((txid, tx, reason))); } - if let Some((txid, tx, anchors)) = self.unprocessed_txs_with_anchors.next() { + if let Some((txid, tx, anchors)) = self.unprocessed_anchored_txs.next() { if !self.is_canonicalized(txid) { if let Err(err) = self.scan_anchors(txid, tx, anchors) { return Some(Err(err)); @@ -199,7 +199,7 @@ impl Iterator for CanonicalIter<'_, A, C> { continue; } - if let Some((txid, tx, last_seen)) = self.unprocessed_txs_with_last_seens.next() { + if let Some((txid, tx, last_seen)) = self.unprocessed_seen_txs.next() { if !self.is_canonicalized(txid) { let observed_in = ObservedIn::Mempool(last_seen); self.mark_canonical(txid, tx, CanonicalReason::from_observed_in(observed_in)); @@ -207,7 +207,7 @@ impl Iterator for CanonicalIter<'_, A, C> { continue; } - if let Some((txid, tx, height)) = self.unprocessed_txs_left_over.pop_front() { + if let Some((txid, tx, height)) = self.unprocessed_leftover_txs.pop_front() { if !self.is_canonicalized(txid) { let observed_in = ObservedIn::Block(height); self.mark_canonical(txid, tx, CanonicalReason::from_observed_in(observed_in));