]> Untitled Git - bdk/commit
[bdk_chain_redesign] Fix `Anchor` definition + docs
author志宇 <hello@evanlinjin.me>
Mon, 17 Apr 2023 15:25:57 +0000 (23:25 +0800)
committer志宇 <hello@evanlinjin.me>
Mon, 17 Apr 2023 16:02:14 +0000 (00:02 +0800)
commit81436fcd72a3c45bb10a098be28de0116322d22d
tree261c28f018e68341c555261ce1dabd3df1142273
parent001efdd1cb658f3a2929ffcf9047e6b07e9bd15c
[bdk_chain_redesign] Fix `Anchor` definition + docs

Previously, I have misunderstood the definition of anchor. If a tx is
anchored in a block, it does not necessarily mean it is confirmed in
that block. The tx can be confirmed in an ancestor block of the anchor
block.

With this new definition, we need a new trait `ConfirmationHeight` that
has one method `confirmation_height`. This trait can be used to extend
`Anchor` for those implementations that can give us the exact
conirmation height of a tx (which is useful in most cases).

Another change is to add another variant to the `ObservedAs` enum;
`ObservedAs::ConfirmedImplicit(A)`. If a tx does not have an anchor, but
another tx that spends it has an anchor that in in the best chain, we
can assume that tx is also in the best chain. The logic of
`TxGraph::try_get_chain_position` is also changed to reflect this.

Some methods from `IndexedTxGraph` have been moved to `TxGraph` as they
do not require the `Indexer`. Some `TxGraph` methods have been renamed
for clarity and consistency.

Also more docs are added.
crates/chain/src/chain_data.rs
crates/chain/src/indexed_tx_graph.rs
crates/chain/src/keychain/txout_index.rs
crates/chain/src/sparse_chain.rs
crates/chain/src/spk_txout_index.rs
crates/chain/src/tx_data_traits.rs
crates/chain/src/tx_graph.rs
crates/chain/tests/test_tx_graph.rs