Skip to content

Commit 8e36a2e

Browse files
committed
[bdk_chain_redesign] Remove incomplete logic
`ObservedAs::ConfirmedImplicit` is incomplete, remove for now. `local_chain::ChangeSet` does not need to be a single-element tuple struct.
1 parent 81436fc commit 8e36a2e

4 files changed

Lines changed: 15 additions & 55 deletions

File tree

crates/chain/src/chain_data.rs

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,6 @@ use crate::{
1212
pub enum ObservedAs<A> {
1313
/// The chain data is seen as confirmed, and in anchored by `A`.
1414
Confirmed(A),
15-
/// The chain data is assumed to be confirmed, because a transaction that spends it is anchored
16-
/// by `A`.
17-
ConfirmedImplicit(A),
1815
/// The chain data is seen in mempool at this given timestamp.
1916
Unconfirmed(u64),
2017
}
@@ -23,7 +20,6 @@ impl<A: Clone> ObservedAs<&A> {
2320
pub fn cloned(self) -> ObservedAs<A> {
2421
match self {
2522
ObservedAs::Confirmed(a) => ObservedAs::Confirmed(a.clone()),
26-
ObservedAs::ConfirmedImplicit(a) => ObservedAs::ConfirmedImplicit(a.clone()),
2723
ObservedAs::Unconfirmed(last_seen) => ObservedAs::Unconfirmed(last_seen),
2824
}
2925
}
@@ -259,9 +255,6 @@ impl<A: Anchor + ConfirmationHeight> FullTxOut<ObservedAs<A>> {
259255

260256
let tx_height = match &self.chain_position {
261257
ObservedAs::Confirmed(anchor) => anchor.confirmation_height(),
262-
// although we do not know the exact confirm height, the returned height here is the
263-
// "upper bound" so only false-negatives are possible
264-
ObservedAs::ConfirmedImplicit(anchor) => anchor.confirmation_height(),
265258
ObservedAs::Unconfirmed(_) => {
266259
debug_assert!(false, "coinbase tx can never be unconfirmed");
267260
return false;
@@ -291,9 +284,6 @@ impl<A: Anchor + ConfirmationHeight> FullTxOut<ObservedAs<A>> {
291284

292285
let confirmation_height = match &self.chain_position {
293286
ObservedAs::Confirmed(anchor) => anchor.confirmation_height(),
294-
// although we do not know the exact confirm height, the returned height here is the
295-
// "upper bound" so only false-negatives are possible
296-
ObservedAs::ConfirmedImplicit(anchor) => anchor.confirmation_height(),
297287
ObservedAs::Unconfirmed(_) => return false,
298288
};
299289
if confirmation_height > tip {

crates/chain/src/indexed_tx_graph.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ impl<A: Anchor + ConfirmationHeight, I: OwnedIndexer> IndexedTxGraph<A, I> {
251251
let txout = res?;
252252

253253
match &txout.chain_position {
254-
ObservedAs::Confirmed(_) | ObservedAs::ConfirmedImplicit(_) => {
254+
ObservedAs::Confirmed(_) => {
255255
if txout.is_on_coinbase {
256256
if txout.is_observed_as_mature(tip) {
257257
confirmed += txout.txout.value;

crates/chain/src/local_chain.rs

Lines changed: 14 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,23 @@
1-
use core::{convert::Infallible, ops::Deref};
1+
use core::convert::Infallible;
22

33
use alloc::collections::{BTreeMap, BTreeSet};
44
use bitcoin::BlockHash;
55

66
use crate::{Append, BlockId, ChainOracle};
77

8+
/// This is a local implementation of [`ChainOracle`].
9+
///
10+
/// TODO: We need a cache/snapshot thing for chain oracle.
11+
/// * Minimize calls to remotes.
12+
/// * Can we cache it forever? Should we drop stuff?
13+
/// * Assume anything deeper than (i.e. 10) blocks won't be reorged.
14+
/// * Is this a cache on txs or block? or both?
15+
/// TODO: Parents of children are confirmed if children are confirmed.
816
#[derive(Debug, Default, Clone, PartialEq, Eq, PartialOrd, Ord)]
917
pub struct LocalChain {
1018
blocks: BTreeMap<u32, BlockHash>,
1119
}
1220

13-
// [TODO] We need a cache/snapshot thing for chain oracle.
14-
// * Minimize calls to remotes.
15-
// * Can we cache it forever? Should we drop stuff?
16-
// * Assume anything deeper than (i.e. 10) blocks won't be reorged.
17-
// * Is this a cache on txs or block? or both?
18-
// [TODO] Parents of children are confirmed if children are confirmed.
1921
impl ChainOracle for LocalChain {
2022
type Error = Infallible;
2123

@@ -114,12 +116,12 @@ impl LocalChain {
114116
changeset.insert(*height, *new_hash);
115117
}
116118
}
117-
Ok(ChangeSet(changeset))
119+
Ok(changeset)
118120
}
119121

120122
/// Applies the given `changeset`.
121123
pub fn apply_changeset(&mut self, mut changeset: ChangeSet) {
122-
self.blocks.append(&mut changeset.0)
124+
self.blocks.append(&mut changeset)
123125
}
124126

125127
/// Updates [`LocalChain`] with an update [`LocalChain`].
@@ -135,7 +137,7 @@ impl LocalChain {
135137
}
136138

137139
pub fn initial_changeset(&self) -> ChangeSet {
138-
ChangeSet(self.blocks.clone())
140+
self.blocks.clone()
139141
}
140142

141143
pub fn heights(&self) -> BTreeSet<u32> {
@@ -146,25 +148,11 @@ impl LocalChain {
146148
/// This is the return value of [`determine_changeset`] and represents changes to [`LocalChain`].
147149
///
148150
/// [`determine_changeset`]: LocalChain::determine_changeset
149-
#[derive(Debug, Default, Clone, PartialEq)]
150-
#[cfg_attr(
151-
feature = "serde",
152-
derive(serde::Deserialize, serde::Serialize),
153-
serde(crate = "serde_crate")
154-
)]
155-
pub struct ChangeSet(pub(crate) BTreeMap<u32, BlockHash>);
156-
157-
impl Deref for ChangeSet {
158-
type Target = BTreeMap<u32, BlockHash>;
159-
160-
fn deref(&self) -> &Self::Target {
161-
&self.0
162-
}
163-
}
151+
type ChangeSet = BTreeMap<u32, BlockHash>;
164152

165153
impl Append for ChangeSet {
166154
fn append(&mut self, mut other: Self) {
167-
BTreeMap::append(&mut self.0, &mut other.0)
155+
BTreeMap::append(self, &mut other)
168156
}
169157
}
170158

crates/chain/src/tx_graph.rs

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -644,24 +644,6 @@ impl<A: Anchor> TxGraph<A> {
644644
}
645645
}
646646

647-
// If we cannot determine whether tx is in best chain, we can check whether a spending tx is
648-
// confirmed and in best chain, and if so, it is guaranteed that this tx is in the best
649-
// chain.
650-
//
651-
// [TODO] This logic is incomplete as we do not check spends of spends.
652-
let spending_anchors = self
653-
.spends
654-
.range(OutPoint::new(txid, u32::MIN)..=OutPoint::new(txid, u32::MAX))
655-
.flat_map(|(_, spending_txids)| spending_txids)
656-
.filter_map(|spending_txid| self.txs.get(spending_txid))
657-
.flat_map(|(_, spending_anchors, _)| spending_anchors);
658-
for spending_anchor in spending_anchors {
659-
match chain.is_block_in_chain(spending_anchor.anchor_block(), chain_tip)? {
660-
Some(true) => return Ok(Some(ObservedAs::ConfirmedImplicit(spending_anchor))),
661-
_ => continue,
662-
}
663-
}
664-
665647
// The tx is not anchored to a block which is in the best chain, let's check whether we can
666648
// ignore it by checking conflicts!
667649
let tx = match tx_node {

0 commit comments

Comments
 (0)