@@ -2,7 +2,7 @@ use core::fmt;
22use core:: ops:: RangeBounds ;
33
44use alloc:: sync:: Arc ;
5- use bitcoin:: { block:: Header , Block , BlockHash } ;
5+ use bitcoin:: { block:: Header , BlockHash } ;
66
77use 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.
6568pub 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-
8885impl < 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" ) ;
0 commit comments