X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=blobdiff_plain;f=lightning-block-sync%2Fsrc%2Fpoll.rs;h=4c6cb0c0600725e9cf3552045865e8b5be472199;hb=6b1ec5c738c4a925a3092a794ef2c7e794ccc061;hp=b32d2239f69fd4b37513afc6a90076f768679a58;hpb=a3832b029c151e2afd910f5372d1aadcd4e394bc;p=rust-lightning diff --git a/lightning-block-sync/src/poll.rs b/lightning-block-sync/src/poll.rs index b32d2239..4c6cb0c0 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")); } @@ -170,12 +168,12 @@ mod sealed { /// /// Other `Poll` implementations should be built using `ChainPoller` as it provides the simplest way /// of validating chain data and checking consistency. -pub struct ChainPoller + Sized, T: BlockSource> { +pub struct ChainPoller + Sized + Send + Sync, T: BlockSource + ?Sized> { block_source: B, network: Network, } -impl + Sized, T: BlockSource> ChainPoller { +impl + Sized + Send + Sync, T: BlockSource + ?Sized> ChainPoller { /// Creates a new poller for the given block source. /// /// If the `network` parameter is mainnet, then the difficulty between blocks is checked for @@ -185,7 +183,7 @@ impl + Sized, T: BlockSource> ChainPoller { } } -impl + Sized + Send + Sync, T: BlockSource> Poll for ChainPoller { +impl + Sized + Send + Sync, T: BlockSource + ?Sized> Poll for ChainPoller { fn poll_chain_tip<'a>(&'a self, best_known_chain_tip: ValidatedBlockHeader) -> AsyncBlockSourceResult<'a, ChainTip> {