Skip to content

Commit 50b036c

Browse files
committed
fix(docs): merge_chains documentation
- it's a small fix for `merge_chains` docs, reported on audit. - adds an `Errors` section to cover what scenarios it can fail.
1 parent ea150b4 commit 50b036c

File tree

1 file changed

+18
-4
lines changed

1 file changed

+18
-4
lines changed

crates/chain/src/local_chain.rs

+18-4
Original file line numberDiff line numberDiff line change
@@ -545,31 +545,45 @@ 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 we were unable to invalidate heights of the original chain.
556+
/// - A point of agreement is found but we failed to apply the changeset to `CheckPoint`.
557+
///
550558
fn merge_chains(
551559
original_tip: CheckPoint,
552560
update_tip: CheckPoint,
553561
) -> Result<(CheckPoint, ChangeSet), CannotConnectError> {
554562
let mut changeset = ChangeSet::default();
563+
555564
let mut orig = original_tip.iter();
556565
let mut update = update_tip.iter();
566+
557567
let mut curr_orig = None;
558568
let mut curr_update = None;
569+
559570
let mut prev_orig: Option<CheckPoint> = None;
560571
let mut prev_update: Option<CheckPoint> = None;
572+
561573
let mut point_of_agreement_found = false;
574+
562575
let mut prev_orig_was_invalidated = false;
576+
563577
let mut potentially_invalidated_heights = vec![];
564578

565579
// If we can, we want to return the update tip as the new tip because this allows checkpoints
566580
// 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
581+
// other using this function. We can do this as long as the update contains every
568582
// block's height of the original chain.
569583
let mut is_update_height_superset_of_original = true;
570584

571585
// 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
586+
// from the tip backwards in tandem. We are always dealing with the highest one from either chain
573587
// first and move to the next highest. The crucial logic is applied when they have blocks at the
574588
// same height.
575589
loop {

0 commit comments

Comments
 (0)