BlockId removal: refactor: BlockBackend::block|block_status (#13014)

* BlockId removal: refactor: BlockBackend::block|block_status

It changes the arguments of:
-  `BlockBackend::block`
-  `BlockBackend::block_status`

method from: `BlockId<Block>` to: `Block::Hash`

This PR is part of BlockId::Number refactoring analysis (paritytech/substrate#11292)

* non-obvious reworks

* doc fix

* Apply suggestions from code review

Co-authored-by: Bastian Köcher <git@kchr.de>

Co-authored-by: Bastian Köcher <git@kchr.de>
Co-authored-by: parity-processbot <>
This commit is contained in:
Michal Kucharczyk
2023-01-02 10:42:05 +01:00
committed by GitHub
parent 66cfd01f17
commit 9c69fc1b32
12 changed files with 75 additions and 101 deletions
+4 -7
View File
@@ -86,7 +86,6 @@ use sp_consensus::{
BlockOrigin, BlockStatus,
};
use sp_runtime::{
generic::BlockId,
traits::{
Block as BlockT, CheckedSub, Hash, HashFor, Header as HeaderT, NumberFor, One,
SaturatedConversion, Zero,
@@ -1865,8 +1864,7 @@ where
self.best_queued_number = info.best_number;
if self.mode == SyncMode::Full &&
self.client.block_status(&BlockId::hash(info.best_hash))? !=
BlockStatus::InChainWithState
self.client.block_status(info.best_hash)? != BlockStatus::InChainWithState
{
self.import_existing = true;
// Latest state is missing, start with the last finalized state or genesis instead.
@@ -1898,7 +1896,7 @@ where
if self.queue_blocks.contains(hash) {
return Ok(BlockStatus::Queued)
}
self.client.block_status(&BlockId::Hash(*hash))
self.client.block_status(*hash)
}
/// Is the block corresponding to the given hash known?
@@ -2455,9 +2453,7 @@ where
if queue.contains(hash) {
BlockStatus::Queued
} else {
client
.block_status(&BlockId::Hash(*hash))
.unwrap_or(BlockStatus::Unknown)
client.block_status(*hash).unwrap_or(BlockStatus::Unknown)
}
},
) {
@@ -3202,6 +3198,7 @@ mod test {
};
use sp_blockchain::HeaderBackend;
use sp_consensus::block_validation::DefaultBlockAnnounceValidator;
use sp_runtime::generic::BlockId;
use substrate_test_runtime_client::{
runtime::{Block, Hash, Header},
BlockBuilderExt, ClientBlockImportExt, ClientExt, DefaultTestClientBuilderExt, TestClient,