From: Duncan Dean Date: Fri, 22 Jul 2022 09:34:25 +0000 (+0200) Subject: Reuse `BlockHash` from `validate_pow()` X-Git-Tag: v0.0.110~7^2 X-Git-Url: http://git.bitcoin.ninja/?a=commitdiff_plain;h=e256b3498ef35192cfa407e5fa6475cf62b37728;p=rust-lightning Reuse `BlockHash` from `validate_pow()` 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). --- diff --git a/lightning-block-sync/src/poll.rs b/lightning-block-sync/src/poll.rs index 6e30d2e86..4c6cb0c06 100644 --- a/lightning-block-sync/src/poll.rs +++ b/lightning-block-sync/src/poll.rs @@ -59,12 +59,11 @@ impl Validate for BlockHeaderData { type T = ValidatedBlockHeader; fn validate(self, block_hash: BlockHash) -> BlockSourceResult { - 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")); } @@ -76,12 +75,11 @@ impl Validate for Block { type T = ValidatedBlock; fn validate(self, block_hash: BlockHash) -> BlockSourceResult { - 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")); }