Skip to content

Commit 8bc2391

Browse files
LagginTimesevanlinjin
authored andcommitted
docs(chain): update docs for CheckPoint and SyncRequest
1 parent 7cf4e5b commit 8bc2391

File tree

2 files changed

+14
-17
lines changed

2 files changed

+14
-17
lines changed

crates/core/src/checkpoint.rs

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use core::fmt;
22
use core::ops::RangeBounds;
33

44
use alloc::sync::Arc;
5-
use bitcoin::{block::Header, Block, BlockHash};
5+
use bitcoin::{block::Header, BlockHash};
66

77
use crate::BlockId;
88

@@ -60,8 +60,11 @@ impl<D> Drop for CPInner<D> {
6060

6161
/// Trait that converts [`CheckPoint`] `data` to [`BlockHash`].
6262
///
63-
/// Implementations of [`ToBlockHash`] must consist exclusively of the data to be hashed — do not
64-
/// include any extraneous fields.
63+
/// Implementations of [`ToBlockHash`] must always return the block’s consensus-defined hash. If
64+
/// your type contains extra fields (timestamps, metadata, etc.), these must be ignored. For
65+
/// example, [`BlockHash`] trivially returns itself, [`Header`] calls its `block_hash()`, and a
66+
/// wrapper type around a [`Header`] should delegate to the header’s hash rather than derive one
67+
/// from other fields.
6568
pub trait ToBlockHash {
6669
/// Returns the [`BlockHash`] for the associated [`CheckPoint`] `data` type.
6770
fn to_blockhash(&self) -> BlockHash;
@@ -79,12 +82,6 @@ impl ToBlockHash for Header {
7982
}
8083
}
8184

82-
impl ToBlockHash for Block {
83-
fn to_blockhash(&self) -> BlockHash {
84-
self.block_hash()
85-
}
86-
}
87-
8885
impl<D> PartialEq for CheckPoint<D> {
8986
fn eq(&self, other: &Self) -> bool {
9087
let self_cps = self.iter().map(|cp| cp.block_id());
@@ -239,11 +236,11 @@ where
239236

240237
/// Inserts `data` at its `height` within the chain.
241238
///
242-
/// The effect of `insert` depends on whether a height already exists. If it doesn't the
243-
/// `block_id` we inserted and all pre-existing blocks higher than it will be re-inserted after
244-
/// it. If the height already existed and has a conflicting block hash then it will be purged
245-
/// along with all block following it. The returned chain will have a tip of the `block_id`
246-
/// passed in. Of course, if the `block_id` was already present then this just returns `self`.
239+
/// The effect of `insert` depends on whether a height already exists. If it doesn't, the data
240+
/// we inserted and all pre-existing entries higher than it will be re-inserted after it. If the
241+
/// height already existed and has a conflicting block hash then it will be purged along with
242+
/// all entries following it. The returned chain will have a tip of the data passed in. Of
243+
/// course, if the data was already present then this just returns `self`.
247244
///
248245
/// # Panics
249246
///
@@ -258,7 +255,7 @@ where
258255
return self;
259256
}
260257
assert_ne!(cp.height(), 0, "cannot replace genesis block");
261-
// if we have a conflict we just return the inserted block because the tail is by
258+
// If we have a conflict we just return the inserted data because the tail is by
262259
// implication invalid.
263260
tail = vec![];
264261
break cp.prev().expect("can't be called on genesis block");

crates/core/src/spk_client.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -164,8 +164,8 @@ impl<I, D> SyncRequestBuilder<I, D> {
164164
/// .build();
165165
///
166166
/// // Sync all revealed spks in the indexer. This time, spks may be derived from different
167-
/// // keychains. Each spk will be indexed with `(&'static str, u32)` where `&'static str` is
168-
/// // the keychain identifier and `u32` is the derivation index.
167+
/// // keychains. Each spk will be indexed with `(&str, u32)` where `&str` is the keychain
168+
/// // identifier and `u32` is the derivation index.
169169
/// let all_revealed_spks = indexer.revealed_spks(..);
170170
/// let _request: SyncRequest<(&str, u32), BlockHash> = SyncRequest::builder()
171171
/// .spks_with_indexes(all_revealed_spks)

0 commit comments

Comments
 (0)