]> Untitled Git - bdk/commit
[bdk_chain_redesign] Consistent `ChainOracle`
author志宇 <hello@evanlinjin.me>
Mon, 10 Apr 2023 05:03:51 +0000 (13:03 +0800)
committer志宇 <hello@evanlinjin.me>
Mon, 10 Apr 2023 05:03:51 +0000 (13:03 +0800)
commit611d2e3ea2ed9249ddf04e0f9089642160e5c901
tree29781baeafc7e53037f9f529b2d481482030ed20
parentbff80ec378fab29556099f9830bcb42911658710
[bdk_chain_redesign] Consistent `ChainOracle`

The problem with the previous `ChainOracle` interface is that it had no
guarantee for consistency. For example, a block deemed to be part of the
"best chain" can be reorged out. So when `ChainOracle` is called
multiple times for an operation (such as getting the UTXO set), the
returned result may be inconsistent.

This PR changes `ChainOracle::is_block_in_chain` to take in another
input `static_block`, ensuring `block` is an ancestor of `static_block`.
Thus, if `static_block` is consistent across the operation, the result
will be consistent also.

`is_block_in_chain` now returns `Option<bool>`. The `None` case means
that the oracle implementation cannot determine whether block is an
ancestor of static block. `IndexedTxGraph::list_chain_txouts` handles
this case by checking child spends that are in chain, and if so, the
parent tx must be in chain too.
crates/chain/src/chain_data.rs
crates/chain/src/chain_oracle.rs
crates/chain/src/indexed_tx_graph.rs
crates/chain/src/local_chain.rs
crates/chain/src/sparse_chain.rs
crates/chain/src/tx_graph.rs