@@ -2,7 +2,7 @@ use core::fmt;
2
2
use core:: ops:: RangeBounds ;
3
3
4
4
use alloc:: sync:: Arc ;
5
- use bitcoin:: { block:: Header , Block , BlockHash } ;
5
+ use bitcoin:: { block:: Header , BlockHash } ;
6
6
7
7
use crate :: BlockId ;
8
8
@@ -60,8 +60,11 @@ impl<D> Drop for CPInner<D> {
60
60
61
61
/// Trait that converts [`CheckPoint`] `data` to [`BlockHash`].
62
62
///
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.
65
68
pub trait ToBlockHash {
66
69
/// Returns the [`BlockHash`] for the associated [`CheckPoint`] `data` type.
67
70
fn to_blockhash ( & self ) -> BlockHash ;
@@ -79,12 +82,6 @@ impl ToBlockHash for Header {
79
82
}
80
83
}
81
84
82
- impl ToBlockHash for Block {
83
- fn to_blockhash ( & self ) -> BlockHash {
84
- self . block_hash ( )
85
- }
86
- }
87
-
88
85
impl < D > PartialEq for CheckPoint < D > {
89
86
fn eq ( & self , other : & Self ) -> bool {
90
87
let self_cps = self . iter ( ) . map ( |cp| cp. block_id ( ) ) ;
@@ -239,11 +236,11 @@ where
239
236
240
237
/// Inserts `data` at its `height` within the chain.
241
238
///
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`.
247
244
///
248
245
/// # Panics
249
246
///
@@ -258,7 +255,7 @@ where
258
255
return self ;
259
256
}
260
257
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
262
259
// implication invalid.
263
260
tail = vec ! [ ] ;
264
261
break cp. prev ( ) . expect ( "can't be called on genesis block" ) ;
0 commit comments