Remove without_storage_info from parachains pallet (#1596)

* remove without_storage_info from pallet-bridge-parachains

* fix benchmarks
This commit is contained in:
Svyatoslav Nikolsky
2022-10-10 15:57:02 +03:00
committed by Bastian Köcher
parent f38852f661
commit be2a13c747
10 changed files with 258 additions and 69 deletions
+24 -8
View File
@@ -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!(