mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-05-31 04:01:02 +00:00
Remove without_storage_info from parachains pallet (#1596)
* remove without_storage_info from pallet-bridge-parachains * fix benchmarks
This commit is contained in:
committed by
Bastian Köcher
parent
f38852f661
commit
be2a13c747
@@ -36,10 +36,12 @@
|
||||
// Runtime-generated enums
|
||||
#![allow(clippy::large_enum_variant)]
|
||||
|
||||
use storage_types::{StoredAuthoritySet, StoredBridgedHeader};
|
||||
use storage_types::StoredAuthoritySet;
|
||||
|
||||
use bp_header_chain::{justification::GrandpaJustification, InitializationData};
|
||||
use bp_runtime::{BlockNumberOf, Chain, HashOf, HasherOf, HeaderOf, OwnedBridgeModule};
|
||||
use bp_runtime::{
|
||||
BlockNumberOf, BoundedStorageValue, Chain, HashOf, HasherOf, HeaderOf, OwnedBridgeModule,
|
||||
};
|
||||
use finality_grandpa::voter_set::VoterSet;
|
||||
use frame_support::{ensure, fail};
|
||||
use frame_system::ensure_signed;
|
||||
@@ -73,6 +75,9 @@ pub type BridgedBlockHash<T, I> = HashOf<<T as Config<I>>::BridgedChain>;
|
||||
pub type BridgedBlockHasher<T, I> = HasherOf<<T as Config<I>>::BridgedChain>;
|
||||
/// Header of the bridged chain.
|
||||
pub type BridgedHeader<T, I> = HeaderOf<<T as Config<I>>::BridgedChain>;
|
||||
/// Stored header of the bridged chain.
|
||||
pub type StoredBridgedHeader<T, I> =
|
||||
BoundedStorageValue<<T as Config<I>>::MaxBridgedHeaderSize, BridgedHeader<T, I>>;
|
||||
|
||||
#[frame_support::pallet]
|
||||
pub mod pallet {
|
||||
@@ -199,8 +204,18 @@ pub mod pallet {
|
||||
|
||||
let is_authorities_change_enacted =
|
||||
try_enact_authority_change::<T, I>(&finality_target, set_id)?;
|
||||
let finality_target =
|
||||
StoredBridgedHeader::<T, I>::try_from_bridged_header(*finality_target)?;
|
||||
let finality_target = StoredBridgedHeader::<T, I>::try_from_inner(*finality_target)
|
||||
.map_err(|e| {
|
||||
log::error!(
|
||||
target: LOG_TARGET,
|
||||
"Size of header {:?} ({}) is larger that the configured value {}",
|
||||
hash,
|
||||
e.value_size,
|
||||
e.maximal_size,
|
||||
);
|
||||
|
||||
Error::<T, I>::TooLargeHeader
|
||||
})?;
|
||||
<RequestCount<T, I>>::mutate(|count| *count += 1);
|
||||
insert_header::<T, I>(finality_target, hash);
|
||||
log::info!(
|
||||
@@ -504,7 +519,8 @@ pub mod pallet {
|
||||
init_params;
|
||||
let authority_set = StoredAuthoritySet::<T, I>::try_new(authority_list, set_id)
|
||||
.map_err(|_| Error::TooManyAuthoritiesInSet)?;
|
||||
let header = StoredBridgedHeader::<T, I>::try_from_bridged_header(*header)?;
|
||||
let header = StoredBridgedHeader::<T, I>::try_from_inner(*header)
|
||||
.map_err(|_| Error::<T, I>::TooLargeHeader)?;
|
||||
|
||||
let initial_hash = header.hash();
|
||||
<InitialHash<T, I>>::put(initial_hash);
|
||||
@@ -538,7 +554,7 @@ pub mod pallet {
|
||||
);
|
||||
let hash = header.hash();
|
||||
insert_header::<T, I>(
|
||||
StoredBridgedHeader::try_from_bridged_header(header)
|
||||
StoredBridgedHeader::<T, I>::try_from_inner(header)
|
||||
.expect("only used from benchmarks; benchmarks are correct; qed"),
|
||||
hash,
|
||||
);
|
||||
@@ -553,7 +569,7 @@ impl<T: Config<I>, I: 'static> Pallet<T, I> {
|
||||
/// if the pallet has not been initialized yet.
|
||||
pub fn best_finalized() -> Option<BridgedHeader<T, I>> {
|
||||
let (_, hash) = <BestFinalized<T, I>>::get()?;
|
||||
<ImportedHeaders<T, I>>::get(hash).map(|h| h.0)
|
||||
<ImportedHeaders<T, I>>::get(hash).map(|h| h.into_inner())
|
||||
}
|
||||
|
||||
/// Check if a particular header is known to the bridge pallet.
|
||||
@@ -1103,7 +1119,7 @@ mod tests {
|
||||
<BestFinalized<TestRuntime>>::put((2, hash));
|
||||
<ImportedHeaders<TestRuntime>>::insert(
|
||||
hash,
|
||||
StoredBridgedHeader::try_from_bridged_header(header).unwrap(),
|
||||
StoredBridgedHeader::<TestRuntime, ()>::try_from_inner(header).unwrap(),
|
||||
);
|
||||
|
||||
assert_ok!(
|
||||
|
||||
@@ -16,12 +16,12 @@
|
||||
|
||||
//! Wrappers for public types that are implementing `MaxEncodedLen`
|
||||
|
||||
use crate::{BridgedHeader, Config, Error};
|
||||
use crate::Config;
|
||||
|
||||
use bp_header_chain::AuthoritySet;
|
||||
use codec::{Decode, Encode, MaxEncodedLen};
|
||||
use frame_support::{traits::Get, BoundedVec, RuntimeDebugNoBound};
|
||||
use scale_info::{Type, TypeInfo};
|
||||
use frame_support::{BoundedVec, RuntimeDebugNoBound};
|
||||
use scale_info::TypeInfo;
|
||||
use sp_finality_grandpa::{AuthorityId, AuthorityList, AuthorityWeight, SetId};
|
||||
|
||||
/// A bounded list of Grandpa authorities with associated weights.
|
||||
@@ -64,43 +64,3 @@ impl<T: Config<I>, I: 'static> From<StoredAuthoritySet<T, I>> for AuthoritySet {
|
||||
AuthoritySet { authorities: t.authorities.into(), set_id: t.set_id }
|
||||
}
|
||||
}
|
||||
|
||||
/// A bounded chain header.
|
||||
#[derive(Clone, Decode, Encode, Eq, PartialEq, RuntimeDebugNoBound)]
|
||||
pub struct StoredBridgedHeader<T: Config<I>, I: 'static>(pub BridgedHeader<T, I>);
|
||||
|
||||
impl<T: Config<I>, I: 'static> StoredBridgedHeader<T, I> {
|
||||
/// Construct `StoredBridgedHeader` from the `BridgedHeader` with all required checks.
|
||||
pub fn try_from_bridged_header(header: BridgedHeader<T, I>) -> Result<Self, Error<T, I>> {
|
||||
// this conversion is heavy (since we do encoding here), so we may want to optimize it later
|
||||
// (e.g. by introducing custom Encode implementation, and turning `StoredBridgedHeader` into
|
||||
// `enum StoredBridgedHeader { Decoded(BridgedHeader), Encoded(Vec<u8>) }`)
|
||||
if header.encoded_size() > T::MaxBridgedHeaderSize::get() as usize {
|
||||
Err(Error::TooLargeHeader)
|
||||
} else {
|
||||
Ok(StoredBridgedHeader(header))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: Config<I>, I: 'static> sp_std::ops::Deref for StoredBridgedHeader<T, I> {
|
||||
type Target = BridgedHeader<T, I>;
|
||||
|
||||
fn deref(&self) -> &Self::Target {
|
||||
&self.0
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: Config<I>, I: 'static> TypeInfo for StoredBridgedHeader<T, I> {
|
||||
type Identity = Self;
|
||||
|
||||
fn type_info() -> Type {
|
||||
BridgedHeader::<T, I>::type_info()
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: Config<I>, I: 'static> MaxEncodedLen for StoredBridgedHeader<T, I> {
|
||||
fn max_encoded_len() -> usize {
|
||||
T::MaxBridgedHeaderSize::get() as usize
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user