Commit 86420a2
committed
c486ba7 docs: address review feedback on `prev_blockhash` validation (志宇)
031b30f docs(core): address review feedback on docs and tests (志宇)
ef35b19 fix(chain)!: make genesis immutable in `merge_chains` (志宇)
d8cb41f test(core): address review feedback on checkpoint tests (志宇)
9c0453c docs(core): Add module-level docs for `checkpoint_entry` (志宇)
3ef6ed8 feat(chain)!: Add `ApplyBlockError` for `prev_blockhash` validation (志宇)
bf6541b feat(chain)!: Relax the generic parameter for `LocalChain<D>` (志宇)
19b9006 test(core): add tests for CheckPoint::push and insert methods (志宇)
9971fda test(chain): Test `apply_update` with a single `CheckPoint<Header>` (valued mammal)
3df0609 test(chain): make `TestLocalChain` generic and add `prev_blockhash` test (志宇)
c314b25 fix(chain): `merge_chains` now takes account of `prev_blockhash`es (志宇)
f10ba0e fix(core): `Checkpoint::insert` now evicts on `prev_blockhash` mismatch (志宇)
046a771 fix(core): `push` now errors on `prev_blockhash` mismatch (志宇)
68d1ef4 feat(core): Initial work on `CheckPointEntry` (志宇)
d4bdff0 feat(core): Add `prev_blockhash` method to `ToBlockHash` trait (志宇)
Pull request description:
Closes #2021
Related to #2076
Replaces #2024
Replaces #2091
### Description
This PR adds `prev_blockhash` awareness to `CheckPoint`, enabling proper chain validation when merging checkpoint chains that store block headers or similar data with previous block hash information.
### Notes to the reviewers
This PR replaces some prior attempts:
* #2024 - where we made the `CheckPoint::data` optional - however this resulted in internal complexity and an API with annoying edge cases. The tests from this PR were still useful.
* #2091 - This second attempt had some good ideas, but was distracted from the goal of #2021. I mostly reused the `CheckPoint::insert` implementation of that PR.
### Changelog notice
```md
Added:
- `ToBlockHash::prev_blockhash()` - optional method to expose previous block hash
- `CheckPointEntry` - new type for iterating with `prev_blockhash` awareness, yielding "placeholder" entries for heights inferred from `prev_blockhash`
- `ApplyBlockError` - this is a new error type with two variants; `MissingGenesis` and `PrevBlockhashMismatch`. The second variant is a new error case introduced by `prev_blockhash` awareness.
Changed:
- `CheckPoint::push` - now errors when `prev_blockhash` conflicts with current tip (contiguous heights)
- `CheckPoint::insert` - now evicts/displaces checkpoints on `prev_blockhash` conflict
- `merge_chains` - now validates `prev_blockhash` consistency when merging
- `LocalChain<D>` generic parameter - relaxed constraint to `D: Clone` instead of `D: Copy`.
Fixed:
- `merge_chains` no longer replaces the genesis block.
```
### 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
ACKs for top commit:
evanlinjin:
self-ACK c486ba7
Tree-SHA512: 5622a8a418034443931c8b5938e708c2222c42c05efbdac71d47a4e0ce1b4f4b0b7bcd2e1e14e2f295cc056e12c03e5750b40b1a1313cdbdf59a009d81d0b8a1
6 files changed
Lines changed: 1230 additions & 99 deletions
File tree
- crates
- chain
- src
- tests
- core
- src
- tests
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
9 | | - | |
10 | 9 | | |
| 10 | + | |
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
15 | 15 | | |
16 | 16 | | |
17 | 17 | | |
18 | | - | |
| 18 | + | |
19 | 19 | | |
20 | | - | |
| 20 | + | |
21 | 21 | | |
22 | 22 | | |
23 | 23 | | |
| |||
34 | 34 | | |
35 | 35 | | |
36 | 36 | | |
37 | | - | |
| 37 | + | |
38 | 38 | | |
39 | 39 | | |
40 | | - | |
| 40 | + | |
41 | 41 | | |
42 | 42 | | |
43 | 43 | | |
| |||
48 | 48 | | |
49 | 49 | | |
50 | 50 | | |
51 | | - | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
52 | 56 | | |
53 | 57 | | |
54 | 58 | | |
| |||
234 | 238 | | |
235 | 239 | | |
236 | 240 | | |
237 | | - | |
| 241 | + | |
238 | 242 | | |
239 | 243 | | |
240 | 244 | | |
| |||
251 | 255 | | |
252 | 256 | | |
253 | 257 | | |
254 | | - | |
| 258 | + | |
255 | 259 | | |
256 | | - | |
| 260 | + | |
257 | 261 | | |
258 | 262 | | |
259 | | - | |
260 | | - | |
261 | | - | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
262 | 271 | | |
263 | 272 | | |
264 | 273 | | |
265 | | - | |
266 | | - | |
| 274 | + | |
| 275 | + | |
267 | 276 | | |
268 | 277 | | |
269 | | - | |
| 278 | + | |
270 | 279 | | |
271 | 280 | | |
272 | 281 | | |
| |||
310 | 319 | | |
311 | 320 | | |
312 | 321 | | |
313 | | - | |
| 322 | + | |
314 | 323 | | |
315 | 324 | | |
316 | 325 | | |
| |||
412 | 421 | | |
413 | 422 | | |
414 | 423 | | |
415 | | - | |
| 424 | + | |
416 | 425 | | |
417 | 426 | | |
418 | 427 | | |
| |||
485 | 494 | | |
486 | 495 | | |
487 | 496 | | |
| 497 | + | |
| 498 | + | |
| 499 | + | |
| 500 | + | |
| 501 | + | |
| 502 | + | |
| 503 | + | |
| 504 | + | |
| 505 | + | |
| 506 | + | |
| 507 | + | |
| 508 | + | |
| 509 | + | |
| 510 | + | |
| 511 | + | |
| 512 | + | |
| 513 | + | |
| 514 | + | |
| 515 | + | |
| 516 | + | |
| 517 | + | |
| 518 | + | |
| 519 | + | |
| 520 | + | |
| 521 | + | |
| 522 | + | |
| 523 | + | |
| 524 | + | |
| 525 | + | |
488 | 526 | | |
489 | 527 | | |
490 | 528 | | |
| |||
590 | 628 | | |
591 | 629 | | |
592 | 630 | | |
593 | | - | |
| 631 | + | |
594 | 632 | | |
| 633 | + | |
| 634 | + | |
| 635 | + | |
| 636 | + | |
| 637 | + | |
| 638 | + | |
| 639 | + | |
| 640 | + | |
| 641 | + | |
| 642 | + | |
| 643 | + | |
| 644 | + | |
| 645 | + | |
| 646 | + | |
| 647 | + | |
| 648 | + | |
| 649 | + | |
| 650 | + | |
| 651 | + | |
| 652 | + | |
| 653 | + | |
| 654 | + | |
| 655 | + | |
| 656 | + | |
| 657 | + | |
| 658 | + | |
| 659 | + | |
| 660 | + | |
| 661 | + | |
| 662 | + | |
| 663 | + | |
| 664 | + | |
595 | 665 | | |
596 | 666 | | |
597 | | - | |
598 | | - | |
| 667 | + | |
| 668 | + | |
599 | 669 | | |
600 | 670 | | |
601 | 671 | | |
602 | 672 | | |
603 | | - | |
604 | | - | |
| 673 | + | |
| 674 | + | |
605 | 675 | | |
606 | 676 | | |
607 | 677 | | |
| |||
630 | 700 | | |
631 | 701 | | |
632 | 702 | | |
633 | | - | |
| 703 | + | |
| 704 | + | |
| 705 | + | |
| 706 | + | |
634 | 707 | | |
635 | 708 | | |
636 | 709 | | |
637 | 710 | | |
638 | | - | |
639 | | - | |
| 711 | + | |
| 712 | + | |
| 713 | + | |
| 714 | + | |
640 | 715 | | |
641 | 716 | | |
642 | 717 | | |
| |||
667 | 742 | | |
668 | 743 | | |
669 | 744 | | |
670 | | - | |
| 745 | + | |
671 | 746 | | |
672 | 747 | | |
673 | 748 | | |
674 | | - | |
675 | | - | |
676 | | - | |
677 | | - | |
678 | | - | |
| 749 | + | |
| 750 | + | |
| 751 | + | |
| 752 | + | |
| 753 | + | |
| 754 | + | |
| 755 | + | |
679 | 756 | | |
680 | 757 | | |
681 | 758 | | |
| 759 | + | |
| 760 | + | |
| 761 | + | |
| 762 | + | |
| 763 | + | |
| 764 | + | |
| 765 | + | |
682 | 766 | | |
683 | 767 | | |
684 | | - | |
| 768 | + | |
| 769 | + | |
| 770 | + | |
| 771 | + | |
| 772 | + | |
| 773 | + | |
| 774 | + | |
685 | 775 | | |
686 | 776 | | |
687 | 777 | | |
| |||
710 | 800 | | |
711 | 801 | | |
712 | 802 | | |
713 | | - | |
714 | | - | |
715 | | - | |
716 | | - | |
717 | | - | |
718 | | - | |
| 803 | + | |
719 | 804 | | |
0 commit comments