Skip to content

Commit f26e854

Browse files
authored
Merge pull request #1627 from dunxen/2022-07-reusevalidatepowblockhash
Reuse `BlockHash` from `validate_pow()`
2 parents 834fe63 + e256b34 commit f26e854

File tree

1 file changed

+4
-6
lines changed

1 file changed

+4
-6
lines changed

lightning-block-sync/src/poll.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -59,12 +59,11 @@ impl Validate for BlockHeaderData {
5959
type T = ValidatedBlockHeader;
6060

6161
fn validate(self, block_hash: BlockHash) -> BlockSourceResult<Self::T> {
62-
self.header
62+
let pow_valid_block_hash = self.header
6363
.validate_pow(&self.header.target())
6464
.or_else(|e| Err(BlockSourceError::persistent(e)))?;
6565

66-
// TODO: Use the result of validate_pow instead of recomputing the block hash once upstream.
67-
if self.header.block_hash() != block_hash {
66+
if pow_valid_block_hash != block_hash {
6867
return Err(BlockSourceError::persistent("invalid block hash"));
6968
}
7069

@@ -76,12 +75,11 @@ impl Validate for Block {
7675
type T = ValidatedBlock;
7776

7877
fn validate(self, block_hash: BlockHash) -> BlockSourceResult<Self::T> {
79-
self.header
78+
let pow_valid_block_hash = self.header
8079
.validate_pow(&self.header.target())
8180
.or_else(|e| Err(BlockSourceError::persistent(e)))?;
8281

83-
// TODO: Use the result of validate_pow instead of recomputing the block hash once upstream.
84-
if self.block_hash() != block_hash {
82+
if pow_valid_block_hash != block_hash {
8583
return Err(BlockSourceError::persistent("invalid block hash"));
8684
}
8785

0 commit comments

Comments
 (0)