mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-05-30 16:21:02 +00:00
* 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:
committed by
Bastian Köcher
parent
1c94fbeafc
commit
ad38cdb873
@@ -22,7 +22,7 @@ use bp_polkadot_core::{
|
||||
parachains::{ParaHash, ParaHead, ParaId},
|
||||
BlockNumber as RelayBlockNumber,
|
||||
};
|
||||
use bp_runtime::StorageDoubleMapKeyProvider;
|
||||
use bp_runtime::{StorageDoubleMapKeyProvider, StorageMapKeyProvider};
|
||||
use codec::{Decode, Encode};
|
||||
use frame_support::{Blake2_128Concat, RuntimeDebug, Twox64Concat};
|
||||
use scale_info::TypeInfo;
|
||||
@@ -44,6 +44,15 @@ pub struct BestParaHeadHash {
|
||||
pub head_hash: ParaHash,
|
||||
}
|
||||
|
||||
/// Best known parachain head as it is stored in the runtime storage.
|
||||
#[derive(Decode, Encode, PartialEq, RuntimeDebug, TypeInfo)]
|
||||
pub struct ParaInfo {
|
||||
/// Best known parachain head hash.
|
||||
pub best_head_hash: BestParaHeadHash,
|
||||
/// Current ring buffer position for this parachain.
|
||||
pub next_imported_hash_position: u32,
|
||||
}
|
||||
|
||||
/// Returns runtime storage key of given parachain head at the source chain.
|
||||
///
|
||||
/// The head is stored by the `paras` pallet in the `Heads` map.
|
||||
@@ -54,18 +63,16 @@ pub fn parachain_head_storage_key_at_source(
|
||||
bp_runtime::storage_map_final_key::<Twox64Concat>(paras_pallet_name, "Heads", ¶_id.encode())
|
||||
}
|
||||
|
||||
/// Returns runtime storage key of best known parachain head at the target chain.
|
||||
/// Can be use to access the runtime storage key of the parachains info at the target chain.
|
||||
///
|
||||
/// The head is stored by the `pallet-bridge-parachains` pallet in the `BestParaHeads` map.
|
||||
pub fn best_parachain_head_hash_storage_key_at_target(
|
||||
bridge_parachains_pallet_name: &str,
|
||||
para_id: ParaId,
|
||||
) -> StorageKey {
|
||||
bp_runtime::storage_map_final_key::<Blake2_128Concat>(
|
||||
bridge_parachains_pallet_name,
|
||||
"BestParaHeads",
|
||||
¶_id.encode(),
|
||||
)
|
||||
/// The info is stored by the `pallet-bridge-parachains` pallet in the `ParasInfo` map.
|
||||
pub struct ParasInfoKeyProvider;
|
||||
impl StorageMapKeyProvider for ParasInfoKeyProvider {
|
||||
const MAP_NAME: &'static str = "ParasInfo";
|
||||
|
||||
type Hasher = Blake2_128Concat;
|
||||
type Key = ParaId;
|
||||
type Value = ParaInfo;
|
||||
}
|
||||
|
||||
/// Can be use to access the runtime storage key of the parachain head at the target chain.
|
||||
|
||||
@@ -285,20 +285,42 @@ pub fn storage_value_key(pallet_prefix: &str, value_name: &str) -> StorageKey {
|
||||
StorageKey(final_key)
|
||||
}
|
||||
|
||||
/// Can be use to access the runtime storage key of a `StorageDoubleMap`.
|
||||
pub trait StorageDoubleMapKeyProvider {
|
||||
// The name of the variable that holds the `StorageDoubleMap`
|
||||
/// Can be use to access the runtime storage key of a `StorageMap`.
|
||||
pub trait StorageMapKeyProvider {
|
||||
/// The name of the variable that holds the `StorageMap`.
|
||||
const MAP_NAME: &'static str;
|
||||
|
||||
// The same as `StorageDoubleMap::Hasher1`
|
||||
/// The same as `StorageMap::Hasher1`.
|
||||
type Hasher: StorageHasher;
|
||||
/// The same as `StorageMap::Key1`.
|
||||
type Key: FullCodec;
|
||||
/// The same as `StorageMap::Value`.
|
||||
type Value: FullCodec;
|
||||
|
||||
/// This is a copy of the
|
||||
/// `frame_support::storage::generator::StorageMap::storage_map_final_key`.
|
||||
///
|
||||
/// We're using it because to call `storage_map_final_key` directly, we need access
|
||||
/// to the runtime and pallet instance, which (sometimes) is impossible.
|
||||
fn final_key(pallet_prefix: &str, key: &Self::Key) -> StorageKey {
|
||||
storage_map_final_key::<Self::Hasher>(pallet_prefix, Self::MAP_NAME, &key.encode())
|
||||
}
|
||||
}
|
||||
|
||||
/// Can be use to access the runtime storage key of a `StorageDoubleMap`.
|
||||
pub trait StorageDoubleMapKeyProvider {
|
||||
/// The name of the variable that holds the `StorageDoubleMap`.
|
||||
const MAP_NAME: &'static str;
|
||||
|
||||
/// The same as `StorageDoubleMap::Hasher1`.
|
||||
type Hasher1: StorageHasher;
|
||||
// The same as `StorageDoubleMap::Key1`
|
||||
/// The same as `StorageDoubleMap::Key1`.
|
||||
type Key1: FullCodec;
|
||||
// The same as `StorageDoubleMap::Hasher2`
|
||||
/// The same as `StorageDoubleMap::Hasher2`.
|
||||
type Hasher2: StorageHasher;
|
||||
// The same as `StorageDoubleMap::Key2`
|
||||
/// The same as `StorageDoubleMap::Key2`.
|
||||
type Key2: FullCodec;
|
||||
// The same as `StorageDoubleMap::Value`
|
||||
/// The same as `StorageDoubleMap::Value`.
|
||||
type Value: FullCodec;
|
||||
|
||||
/// This is a copy of the
|
||||
|
||||
Reference in New Issue
Block a user