Follow-up on #1068 (#1567)

* BestParaHead small changes

Signed-off-by: Serban Iorga <serban@parity.io>

* Renamings

Signed-off-by: Serban Iorga <serban@parity.io>

* Use ParaInfo in parachains loop

Signed-off-by: Serban Iorga <serban@parity.io>

* Define StorageMapKeyProvider

Signed-off-by: Serban Iorga <serban@parity.io>

* CR fixes

Signed-off-by: Serban Iorga <serban@parity.io>
This commit is contained in:
Serban Iorga
2022-09-05 13:13:31 +03:00
committed by Bastian Köcher
parent 1c94fbeafc
commit ad38cdb873
6 changed files with 190 additions and 113 deletions
+18 -1
View File
@@ -29,7 +29,7 @@ use crate::{
use async_std::sync::{Arc, Mutex};
use async_trait::async_trait;
use bp_runtime::{HeaderIdProvider, StorageDoubleMapKeyProvider};
use bp_runtime::{HeaderIdProvider, StorageDoubleMapKeyProvider, StorageMapKeyProvider};
use codec::{Decode, Encode};
use frame_system::AccountInfo;
use futures::{SinkExt, StreamExt};
@@ -320,6 +320,23 @@ impl<C: Chain> Client<C> {
.transpose()
}
/// Read `MapStorage` value from runtime storage.
pub async fn storage_map_value<T: StorageMapKeyProvider>(
&self,
pallet_prefix: &str,
key: &T::Key,
block_hash: Option<C::Hash>,
) -> Result<Option<T::Value>> {
let storage_key = T::final_key(pallet_prefix, key);
self.raw_storage_value(storage_key, block_hash)
.await?
.map(|encoded_value| {
T::Value::decode(&mut &encoded_value.0[..]).map_err(Error::ResponseParseFailed)
})
.transpose()
}
/// Read `DoubleMapStorage` value from runtime storage.
pub async fn storage_double_map_value<T: StorageDoubleMapKeyProvider>(
&self,
@@ -24,9 +24,7 @@ use crate::{
};
use async_trait::async_trait;
use bp_parachains::{
best_parachain_head_hash_storage_key_at_target, BestParaHeadHash, ImportedParaHeadsKeyProvider,
};
use bp_parachains::{BestParaHeadHash, ImportedParaHeadsKeyProvider, ParasInfoKeyProvider};
use bp_polkadot_core::parachains::{ParaHash, ParaHeadsProof, ParaId};
use bp_runtime::HeaderIdProvider;
use codec::Decode;
@@ -122,12 +120,16 @@ where
metrics: Option<&ParachainsLoopMetrics>,
para_id: ParaId,
) -> Result<Option<BestParaHeadHash>, Self::Error> {
let best_para_head_hash_key = best_parachain_head_hash_storage_key_at_target(
P::SourceRelayChain::PARACHAINS_FINALITY_PALLET_NAME,
para_id,
);
let best_para_head_hash: Option<BestParaHeadHash> =
self.client.storage_value(best_para_head_hash_key, Some(at_block.1)).await?;
let best_para_head_hash: Option<BestParaHeadHash> = self
.client
.storage_map_value::<ParasInfoKeyProvider>(
P::SourceRelayChain::PARACHAINS_FINALITY_PALLET_NAME,
&para_id,
Some(at_block.1),
)
.await?
.map(|para_info| para_info.best_head_hash);
if let (Some(metrics), &Some(ref best_para_head_hash)) = (metrics, &best_para_head_hash) {
let imported_para_head = self
.client