Skip to content

Commit 75ef7c0

Browse files
committed
Merge #1806: fix(docs): merge_chains outdated documentation
5647241 fix(docs): `merge_chains` documentation (Leonardo Lima) Pull request description: <!-- You can erase any parts of this template not applicable to your Pull Request. --> ### Description It's a minor documentation fix, as reported during the audit and referenced in bitcoindevkit/bdk_wallet#59. <!-- Describe the purpose of this PR, what's being adding and/or fixed --> ### Notes to the reviewers I'm unsure if anything else / any other explanation should be included in the documentation. Let me know if you think more context should be added to it. <!-- In this section you can include notes directed to the reviewers, like explaining why some parts of the PR were done in a specific way --> ### Changelog notice - Update `bdk_chain::local_chain::merge_chains` documentation. <!-- Notice the release manager should include in the release tag message changelog --> <!-- See https://keepachangelog.com/en/1.0.0/ for examples --> ### Checklists #### All Submissions: * [x] I've signed all my commits * [x] I followed the [contribution guidelines](https://github.com/bitcoindevkit/bdk/blob/master/CONTRIBUTING.md) * [x] I ran `cargo fmt` and `cargo clippy` before committing ACKs for top commit: evanlinjin: self-ACK 5647241 Tree-SHA512: a70a67eab9c8fa0c60a674efed82ddeb9bc9b69763fefaa38a9058d7a1e67c06045c3e5a31aaf0d48c0a599d03bac0a3a86530cc250acefea9497572c01b8b0e
2 parents b9e4e4c + 5647241 commit 75ef7c0

File tree

1 file changed

+19
-4
lines changed

1 file changed

+19
-4
lines changed

crates/chain/src/local_chain.rs

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -545,31 +545,46 @@ impl std::error::Error for ApplyHeaderError {}
545545

546546
/// Applies `update_tip` onto `original_tip`.
547547
///
548-
/// On success, a tuple is returned `(changeset, can_replace)`. If `can_replace` is true, then the
549-
/// `update_tip` can replace the `original_tip`.
548+
/// On success, a tuple is returned ([`CheckPoint`], [`ChangeSet`]).
549+
///
550+
/// # Errors
551+
///
552+
/// [`CannotConnectError`] occurs when the `original_tip` and `update_tip` chains are disjoint:
553+
///
554+
/// - If no point of agreement is found between the update and original chains.
555+
/// - A point of agreement is found but the update is ambiguous above the point of agreement (a.k.a.
556+
/// the update and original chain both have a block above the point of agreement, but their
557+
/// heights do not overlap).
558+
/// - The update attempts to replace the genesis block of the original chain.
550559
fn merge_chains(
551560
original_tip: CheckPoint,
552561
update_tip: CheckPoint,
553562
) -> Result<(CheckPoint, ChangeSet), CannotConnectError> {
554563
let mut changeset = ChangeSet::default();
564+
555565
let mut orig = original_tip.iter();
556566
let mut update = update_tip.iter();
567+
557568
let mut curr_orig = None;
558569
let mut curr_update = None;
570+
559571
let mut prev_orig: Option<CheckPoint> = None;
560572
let mut prev_update: Option<CheckPoint> = None;
573+
561574
let mut point_of_agreement_found = false;
575+
562576
let mut prev_orig_was_invalidated = false;
577+
563578
let mut potentially_invalidated_heights = vec![];
564579

565580
// If we can, we want to return the update tip as the new tip because this allows checkpoints
566581
// in multiple locations to keep the same `Arc` pointers when they are being updated from each
567-
// other using this function. We can do this as long as long as the update contains every
582+
// other using this function. We can do this as long as the update contains every
568583
// block's height of the original chain.
569584
let mut is_update_height_superset_of_original = true;
570585

571586
// To find the difference between the new chain and the original we iterate over both of them
572-
// from the tip backwards in tandem. We always dealing with the highest one from either chain
587+
// from the tip backwards in tandem. We are always dealing with the highest one from either chain
573588
// first and move to the next highest. The crucial logic is applied when they have blocks at the
574589
// same height.
575590
loop {

0 commit comments

Comments
 (0)