Skip to content

Reuse BlockHash from validate_pow() #1627

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 4 additions & 6 deletions lightning-block-sync/src/poll.rs
Original file line number Diff line number Diff line change
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