Skip to content

Commit

Permalink
Merge pull request #1627 from dunxen/2022-07-reusevalidatepowblockhash
Browse files Browse the repository at this point in the history
Reuse `BlockHash` from `validate_pow()`
  • Loading branch information
TheBlueMatt committed Jul 22, 2022
2 parents 834fe63 + e256b34 commit f26e854
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions lightning-block-sync/src/poll.rs
Expand Up @@ -59,12 +59,11 @@ impl Validate for BlockHeaderData {
type T = ValidatedBlockHeader;

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

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

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

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

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

Expand Down

0 comments on commit f26e854

Please sign in to comment.