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
@@ -19,18 +19,18 @@
use crate::BlockStatus;
use futures::FutureExt as _;
use sp_runtime::{generic::BlockId, traits::Block};
use sp_runtime::traits::Block;
use std::{error::Error, future::Future, pin::Pin, sync::Arc};
/// A type which provides access to chain information.
pub trait Chain<B: Block> {
/// Retrieve the status of the block denoted by the given [`BlockId`].
fn block_status(&self, id: &BlockId<B>) -> Result<BlockStatus, Box<dyn Error + Send>>;
/// Retrieve the status of the block denoted by the given [`Block::Hash`].
fn block_status(&self, hash: B::Hash) -> Result<BlockStatus, Box<dyn Error + Send>>;
}
impl<T: Chain<B>, B: Block> Chain<B> for Arc<T> {
fn block_status(&self, id: &BlockId<B>) -> Result<BlockStatus, Box<dyn Error + Send>> {
(&**self).block_status(id)
fn block_status(&self, hash: B::Hash) -> Result<BlockStatus, Box<dyn Error + Send>> {
(&**self).block_status(hash)
}
}
@@ -60,7 +60,7 @@ pub trait BlockAnnounceValidator<B: Block> {
/// Returning [`Validation::Failure`] will lead to a decrease of the
/// peers reputation as it sent us invalid data.
///
/// The returned future should only resolve to an error iff there was an internal error
/// The returned future should only resolve to an error if there was an internal error
/// validating the block announcement. If the block announcement itself is invalid, this should
/// *always* return [`Validation::Failure`].
fn validate(