BlockId removal: refactor: Backend::body (#12587)

It changes the arguments of `Backend::body` method from: `BlockId<Block>` to: `&Block::Hash`

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

Co-authored-by: parity-processbot <>
This commit is contained in:
Michal Kucharczyk
2022-11-01 17:24:09 +01:00
committed by GitHub
parent c68bd397d8
commit 76bcbd09a5
16 changed files with 93 additions and 74 deletions
+2 -2
View File
@@ -126,8 +126,8 @@ where
Pin<Box<dyn Future<Output = error::Result<TransactionValidity>> + Send>>;
type BodyFuture = Ready<error::Result<Option<Vec<<Self::Block as BlockT>::Extrinsic>>>>;
fn block_body(&self, id: &BlockId<Self::Block>) -> Self::BodyFuture {
ready(self.client.block_body(id).map_err(error::Error::from))
fn block_body(&self, hash: &Block::Hash) -> Self::BodyFuture {
ready(self.client.block_body(hash).map_err(error::Error::from))
}
fn validate_transaction(
@@ -90,8 +90,8 @@ pub trait ChainApi: Send + Sync {
/// Returns hash and encoding length of the extrinsic.
fn hash_and_length(&self, uxt: &ExtrinsicFor<Self>) -> (ExtrinsicHash<Self>, usize);
/// Returns a block body given the block id.
fn block_body(&self, at: &BlockId<Self::Block>) -> Self::BodyFuture;
/// Returns a block body given the block.
fn block_body(&self, at: &<Self::Block as BlockT>::Hash) -> Self::BodyFuture;
/// Returns a block header given the block id.
fn block_header(
+10 -8
View File
@@ -550,12 +550,12 @@ impl<N: Clone + Copy + AtLeast32Bit> RevalidationStatus<N> {
/// Prune the known txs for the given block.
async fn prune_known_txs_for_block<Block: BlockT, Api: graph::ChainApi<Block = Block>>(
block_id: BlockId<Block>,
block_hash: &Block::Hash,
api: &Api,
pool: &graph::Pool<Api>,
) -> Vec<ExtrinsicHash<Api>> {
let extrinsics = api
.block_body(&block_id)
.block_body(&block_hash)
.await
.unwrap_or_else(|e| {
log::warn!("Prune known transactions: error request: {}", e);
@@ -567,19 +567,21 @@ async fn prune_known_txs_for_block<Block: BlockT, Api: graph::ChainApi<Block = B
log::trace!(target: "txpool", "Pruning transactions: {:?}", hashes);
let header = match api.block_header(&block_id) {
let header = match api.block_header(&BlockId::Hash(*block_hash)) {
Ok(Some(h)) => h,
Ok(None) => {
log::debug!(target: "txpool", "Could not find header for {:?}.", block_id);
log::debug!(target: "txpool", "Could not find header for {:?}.", block_hash);
return hashes
},
Err(e) => {
log::debug!(target: "txpool", "Error retrieving header for {:?}: {}", block_id, e);
log::debug!(target: "txpool", "Error retrieving header for {:?}: {}", block_hash, e);
return hashes
},
};
if let Err(e) = pool.prune(&block_id, &BlockId::hash(*header.parent_hash()), &extrinsics).await
if let Err(e) = pool
.prune(&BlockId::Hash(*block_hash), &BlockId::hash(*header.parent_hash()), &extrinsics)
.await
{
log::error!("Cannot prune known in the pool: {}", e);
}
@@ -636,7 +638,7 @@ where
tree_route
.enacted()
.iter()
.map(|h| prune_known_txs_for_block(BlockId::Hash(h.hash), &*api, &*pool)),
.map(|h| prune_known_txs_for_block(&h.hash, &*api, &*pool)),
)
.await
.into_iter()
@@ -654,7 +656,7 @@ where
let hash = retracted.hash;
let block_transactions = api
.block_body(&BlockId::hash(hash))
.block_body(&hash)
.await
.unwrap_or_else(|e| {
log::warn!("Failed to fetch block body: {}", e);
@@ -164,7 +164,7 @@ impl ChainApi for TestApi {
(Hashing::hash(&encoded), len)
}
fn block_body(&self, _id: &BlockId<Self::Block>) -> Self::BodyFuture {
fn block_body(&self, _id: &<Self::Block as BlockT>::Hash) -> Self::BodyFuture {
futures::future::ready(Ok(None))
}