Commit 9613fd2
committed
Merge #2000:
6aa81fe test(bitcoind): Test 6-block reorg to `filter_iter_detects_reorgs` test (志宇)
4b295ee docs(bip158): Update `FilterIter` documentation (valued mammal)
2181c4b 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 6aa81fe
evanlinjin:
ACK 6aa81fe
oleonardolima:
tACK 6aa81fe
LagginTimes:
ACK 6aa81fe
Tree-SHA512: 4aebec0184f9cb0ba601811409cf782ab3ad1536bb2dd1f177b2263df5fe99739a675734aa00b28af1dd1bce77071ac18ac7f2c3e849cbd876a3639981af390aFilterIter API redesignFile tree
3 files changed
+284
-356
lines changed- crates/bitcoind_rpc
- examples
- src
- tests
3 files changed
+284
-356
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | | - | |
| 1 | + | |
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
5 | | - | |
| 5 | + | |
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
10 | 10 | | |
11 | 11 | | |
12 | | - | |
13 | 12 | | |
14 | 13 | | |
15 | 14 | | |
16 | 15 | | |
17 | 16 | | |
18 | 17 | | |
19 | 18 | | |
20 | | - | |
21 | | - | |
| 19 | + | |
| 20 | + | |
22 | 21 | | |
23 | 22 | | |
24 | 23 | | |
25 | | - | |
26 | | - | |
| 24 | + | |
| 25 | + | |
27 | 26 | | |
28 | 27 | | |
29 | 28 | | |
| |||
52 | 51 | | |
53 | 52 | | |
54 | 53 | | |
55 | | - | |
56 | | - | |
57 | | - | |
58 | | - | |
| 54 | + | |
| 55 | + | |
59 | 56 | | |
60 | | - | |
61 | | - | |
| 57 | + | |
62 | 58 | | |
| 59 | + | |
63 | 60 | | |
64 | 61 | | |
65 | 62 | | |
66 | | - | |
67 | | - | |
68 | | - | |
69 | | - | |
70 | | - | |
71 | | - | |
72 | | - | |
73 | | - | |
74 | | - | |
75 | | - | |
76 | | - | |
77 | | - | |
78 | | - | |
79 | | - | |
80 | | - | |
81 | | - | |
82 | | - | |
83 | | - | |
84 | | - | |
85 | | - | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
86 | 70 | | |
87 | 71 | | |
88 | 72 | | |
| |||
105 | 89 | | |
106 | 90 | | |
107 | 91 | | |
108 | | - | |
109 | | - | |
110 | | - | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
111 | 104 | | |
112 | 105 | | |
113 | 106 | | |
0 commit comments