Skip to content

Commit

Permalink
Reuse block hash from validate_pow()
Browse files Browse the repository at this point in the history
The validate_pow() method now returns the BlockHash since rust-bitcoin
v0.26.2 thanks to jkczyz's PR (rust-bitcoin/rust-bitcoin/pull/572).
  • Loading branch information
dunxen committed Jul 22, 2022
1 parent 834fe63 commit 8cd8df3
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 8cd8df3

Please sign in to comment.