Repository navigation
Make bdk_bitcoind_rpc emitters support any checkpoint data type - #2105
evanlinjin wants to merge 4 commits into
Conversation
|
This couples nicely with Floresta, since we already keep a chain of headers. Cool idea. |
c989f8f to
cd404c6
Compare
Proposal - Make
|
912d0f7 to
b76cb25
Compare
| /// Trait that converts [`Header`] to subset data. | ||
| pub trait FromBlockHeader { | ||
| /// Returns the subset data from a block `header`. | ||
| fn from_blockheader(header: Header) -> Self; | ||
| } |
There was a problem hiding this comment.
@evanlinjin Can you clarify why the new trait it's really need ? Can't we achieve the same by just implementing ToBlockHash for Header ? (I'll do another round to better understand it)
There was a problem hiding this comment.
We want Header -> checkpoint data. So a chain-source crate can provide the Header, and the checkpoint data can be made from that.
There was a problem hiding this comment.
Instead of a new trait, could the same thing be expressed as a bound?D: From<Header>
Edit: D: for<'a> From<&'a Block>
There was a problem hiding this comment.
Instead of a new trait, could the same thing be expressed as a
bound?D: From<Header>Edit:
D: for<'a> From<&'a Block>
A D: From<Header> / for<'a> From<&'a Block> bound can't replace the trait: the orphan rule stops bdk_core from writing impl From<Header> for BlockHash (foreign trait, foreign types), and BlockHash is the default D. So it needs a local trait (or only closures).
b76cb25 to
4755d8c
Compare
|
Hey @ValuedMammal, re: your proposal to use |
Ah that's a good point. I do think it's unfortunate that |
4755d8c to
25e8feb
Compare
Ok we don't need the ability to "fetch" median time here, because we're already syncing block by block. |
81fbd81 to
8483e7f
Compare
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #2105 +/- ##
==========================================
+ Coverage 80.00% 80.65% +0.64%
==========================================
Files 31 31
Lines 6187 6286 +99
Branches 292 294 +2
==========================================
+ Hits 4950 5070 +120
+ Misses 1167 1146 -21
Partials 70 70
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
This allows us to use any subset of a `Header` to construct checkpoint data. Currently, only `BlockHash` and `Header` implement this. Chain sources can bound the checkpoint data generic to this trait, so all checkpoint data types that implement `FromBlockHeader` is supported by the chain source.
… `Emitter` Store `Fn(Header) -> D` in `FilterIter` and `Fn(&Block) -> D` in `Emitter`, enabling `Iterator` for any `D` without a `FromBlockHeader` bound. Add `new_with` constructors for custom `D` types; `new` delegates to `new_with` for the common `FromBlockHeader` case. Remove `FilterIter::next_with` and `Emitter::next_block_with` — callers should use `new_with` at construction time instead. Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
`FilterIter` now rebuilds each block's `Header` from `getblockheader` and derives checkpoint data from it, so for the default `BlockHash` the hash comes from hashing the rebuilt header instead of the RPC's `nextblockhash`. If the rebuild ever gets a field wrong, every checkpoint would be silently wrong. Add `filter_iter_emits_node_headers`, which runs a `FilterIter<Header>` and compares every emitted header with `getblockheader` for that height. Equal headers mean equal hashes, so this covers the `BlockHash` path too.
8483e7f to
7524b6e
Compare
Description
Make
bdk_bitcoind_rpcemitters support emittingCheckPointupdates with bothBlockHashandHeaderdata. To make this easier to implement, abdk_core::fromBlockHashtrait is introduced.Rationale
I think BDK should move towards making
Headerthe most-used checkpoint data type (so chain-sources should be able to output that!). This allows us to accurately calculate time (MTP), provides the merkle root for verification (maybe anchors in the future can include the merkle proof), and provides theprev_blockhashvalue.However, we cannot force this change as users may want persisted data to be compatible with newer versions of BDK (and retain their
BlockId-based persistence data).Changelog notice
Checklists
All Submissions:
New Features: