Skip to content

Commit c24dd6a

Browse files
committed
docs(chain): update CheckPoint and LocalChain docs
1 parent 46bd424 commit c24dd6a

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

crates/chain/src/local_chain.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -648,6 +648,9 @@ where
648648
match (curr_orig.as_ref(), curr_update.as_ref()) {
649649
// Update block that doesn't exist in the original chain
650650
(o, Some(u)) if Some(u.height()) > o.map(|o| o.height()) => {
651+
// Only append to `ChangeSet` when the update has complete data. Entries where
652+
// `data` does not exist that are created via `prev_blockhash` should not alter the
653+
// `ChangeSet`.
651654
if let Some(data) = u.data() {
652655
changeset.blocks.insert(u.height(), Some(data));
653656
}

crates/core/src/checkpoint.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,11 @@ where
217217
{
218218
/// Construct a new base [`CheckPoint`] from given `height` and `data` at the front of a linked
219219
/// list.
220+
///
221+
/// If `data` contains previous block via [`ToBlockHash::prev_blockhash`], this will also create
222+
/// a placeholder checkpoint at `height - 1` with that hash and with `data: None`, and link the
223+
/// new checkpoint to it. The placeholder can be materialized later by inserting data at its
224+
/// height.
220225
pub fn new(height: u32, data: D) -> Self {
221226
// If `data` has a `prev_blockhash`, create a placeholder checkpoint one height below.
222227
let prev = if height > 0 {
@@ -276,8 +281,10 @@ where
276281
/// The effect of `insert` depends on whether a height already exists. If it doesn't, the data
277282
/// we inserted and all pre-existing entries higher than it will be re-inserted after it. If the
278283
/// height already existed and has a conflicting block hash then it will be purged along with
279-
/// all entries following it. The returned chain will have a tip of the data passed in. Of
280-
/// course, if the data was already present then this just returns `self`.
284+
/// all entries following it. If the existing checkpoint at height is a placeholder where
285+
/// `data: None` with the same hash, then the `data` is inserted to make a complete checkpoint.
286+
/// The returned chain will have a tip of the data passed in. If the data was already present
287+
/// then this just returns `self`. This method does not create new placeholders.
281288
///
282289
/// # Panics
283290
///

0 commit comments

Comments
 (0)