]> Untitled Git - bdk/commitdiff
refactor(chain)!: remove `Anchor::confirmation_height`
author志宇 <hello@evanlinjin.me>
Thu, 15 Oct 2026 02:45:25 +0000 (02:45 +0000)
committer志宇 <hello@evanlinjin.me>
Thu, 15 Oct 2026 02:45:25 +0000 (02:45 +0000)
An anchor names the confirming block, so the confirmation height is
always `anchor_block().height`. An overridable method could only
diverge from that, so callers use `anchor_block().height` directly.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
crates/chain/src/canonical_task.rs
crates/chain/src/chain_data.rs
crates/chain/src/tx_data_traits.rs
crates/chain/src/tx_graph.rs

index e36df4d2a17e25d5d67e3af5d43c2d97a5a9aec2..ff1d68970b8baa59b50ec8fdf6863c691963c08b 100644 (file)
@@ -178,7 +178,8 @@ impl<'g, A: Anchor> ChainQuery for CanonicalTask<'g, A> {
                                     .expect(
                                         "tx taken from `unprocessed_anchored_txs` so it must have at least one anchor",
                                     )
-                                    .confirmation_height(),
+                                    .anchor_block()
+                                    .height,
                             ))
                         }
                     }
index 2bfe591343e400451aa8203d8743a2732707492e..34b7bb38c8b6c213e3e571b9af14ad1d6ca5582b 100644 (file)
@@ -81,7 +81,7 @@ impl<A: Anchor> ChainPosition<A> {
     /// descendant, so the chain data may be confirmed in an earlier block.
     pub fn confirmation_height_upper_bound(&self) -> Option<u32> {
         match self {
-            ChainPosition::Confirmed { anchor, .. } => Some(anchor.confirmation_height()),
+            ChainPosition::Confirmed { anchor, .. } => Some(anchor.anchor_block().height),
             ChainPosition::Unconfirmed { .. } => None,
         }
     }
index 998937434122e302a03e2d1e492a54caa858851a..c09aa0005365554635dd674a9f1e1c6f4327f784 100644 (file)
@@ -65,23 +65,12 @@ use crate::{BlockId, ConfirmationBlockTime};
 pub trait Anchor: core::fmt::Debug + Clone + Eq + PartialOrd + Ord + core::hash::Hash {
     /// Returns the [`BlockId`] that the associated blockchain data is "anchored" in.
     fn anchor_block(&self) -> BlockId;
-
-    /// Get the height of the block that confirmed the associated chain data.
-    ///
-    /// This is the height of [`anchor_block`](Anchor::anchor_block).
-    fn confirmation_height(&self) -> u32 {
-        self.anchor_block().height
-    }
 }
 
 impl<A: Anchor> Anchor for &A {
     fn anchor_block(&self) -> BlockId {
         <A as Anchor>::anchor_block(self)
     }
-
-    fn confirmation_height(&self) -> u32 {
-        <A as Anchor>::confirmation_height(self)
-    }
 }
 
 impl Anchor for BlockId {
index 44a2f81af5f4d420e15fb6c5f11af0534bd64f63..3c6ab69e59a5b7d8584a7007b467e5e1038408f9 100644 (file)
@@ -766,11 +766,11 @@ impl<A: Anchor> TxGraph<A> {
         // `txs_by_highest_conf_heights`.
         // We want to remove `(old_top_h?, txid)` and insert `(new_top_h?, txid)`.
         let mut old_top_h = None;
-        let mut new_top_h = anchor.confirmation_height();
+        let mut new_top_h = anchor.anchor_block().height;
 
         let is_changed = match self.anchors.entry(txid) {
             hash_map::Entry::Occupied(mut e) => {
-                old_top_h = e.get().iter().last().map(Anchor::confirmation_height);
+                old_top_h = e.get().iter().last().map(|a| a.anchor_block().height);
                 if let Some(old_top_h) = old_top_h {
                     if old_top_h > new_top_h {
                         new_top_h = old_top_h;