Merge bitcoindevkit/bdk#2000: `FilterIter` API redesign
6aa81fe2ff5737add0be0664347a786573060706 test(bitcoind): Test 6-block reorg to `filter_iter_detects_reorgs` test (志宇)
4b295eec7728fec008a9d83f3d56c28109bdfb8e docs(bip158): Update `FilterIter` documentation (valued mammal)
2181c4babf94e541ca695103619ef8eecfb731d2 feat(rpc)!: `FilterIter` API redesign (valued mammal)
Pull request description:
Previously `FilterIter` did not detect or handle reorgs between `next` calls, meaning that if a reorg occurred, we might process blocks from a stale fork potentially resulting in an invalid wallet state. This PR aims to fix that by adding logic to explicitly check for and respond to a reorg on every call to `next`.
### Notes to the reviewers
The old implementation required storing block IDs of scanned blocks before creating a checkpoint update, but because the interface was split across different methods, it introduced a timing risk between method calls which, when we consider the possibility of reorgs, made the implementation somewhat brittle.
To address this, we make sure that 1) Finding the start block and 2) Updating the internal checkpoint are directly tied to the logic of `next`. Since the checkpoint in practice is derived from a clone of the local chain, this ensures that the checkpoint returned by `next` can always find a connection point with the receiver. Additionally we now emit a checkpoint at every height to ensure that any "must-include" heights are not missing.
For example usage see `examples/filter_iter.rs`
fixes #1848
### Changelog notice
Fixed
- `FilterIter` now handles reorgs to ensure consistency of the header chain.
Changed
- `Event` is now a struct instead of enum
Added
- `FilterIter::new` constructor that takes as input a reference to the RPC client, checkpoint, and a list of SPKs.
- `Error::ReorgDepthExceeded` variant
- `Error::TryFromInt` variant
Removed
- `FilterIter::new_with_height`
- `FilterIter::new_with_checkpoint`
- `EventInner` type
- `FilterIter::get_tip`
- `FilterIter::chain_update`
- `Error::NoScripts` variant
### Checklists
#### All Submissions:
* [x] I followed the [contribution guidelines](https://github.com/bitcoindevkit/bdk/blob/master/CONTRIBUTING.md)
#### New Features:
* [x] I've added tests for the new feature
* [x] I've added docs for the new feature
#### Bugfixes:
* [x] This pull request breaks the existing API
* [x] I've added tests to reproduce the issue which are now passing
* [x] I'm linking the issue being fixed by this PR
ACKs for top commit:
ValuedMammal:
ACK
6aa81fe2ff5737add0be0664347a786573060706
evanlinjin:
ACK
6aa81fe2ff5737add0be0664347a786573060706
oleonardolima:
tACK
6aa81fe2ff5737add0be0664347a786573060706
LagginTimes:
ACK
6aa81fe2ff5737add0be0664347a786573060706
Tree-SHA512: 4aebec0184f9cb0ba601811409cf782ab3ad1536bb2dd1f177b2263df5fe99739a675734aa00b28af1dd1bce77071ac18ac7f2c3e849cbd876a3639981af390a