mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-05-31 14:31: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
@@ -106,6 +106,9 @@ pub const MAX_AUTHORITIES_COUNT: u32 = 5;
|
||||
/// Maximal SCALE-encoded header size (in bytes) at Rialto.
|
||||
pub const MAX_HEADER_SIZE: u32 = 512;
|
||||
|
||||
/// Maximal SCALE-encoded size of parachains headers that are stored at Rialto `Paras` pallet.
|
||||
pub const MAX_NESTED_PARACHAIN_HEAD_SIZE: u32 = MAX_HEADER_SIZE;
|
||||
|
||||
/// Re-export `time_units` to make usage easier.
|
||||
pub use time_units::*;
|
||||
|
||||
|
||||
@@ -70,6 +70,9 @@ pub const MAX_AUTHORITIES_COUNT: u32 = 100_000;
|
||||
/// some fixed reserve for other things (digest, block hash and number, ...) as well.
|
||||
pub const MAX_HEADER_SIZE: u32 = 4096 + MAX_AUTHORITIES_COUNT * 40;
|
||||
|
||||
/// Maximal SCALE-encoded size of parachains headers that are stored at Westend `Paras` pallet.
|
||||
pub const MAX_NESTED_PARACHAIN_HEAD_SIZE: u32 = MAX_HEADER_SIZE;
|
||||
|
||||
/// Identifier of Westmint parachain at the Westend relay chain.
|
||||
pub const WESTMINT_PARACHAIN_ID: u32 = 2000;
|
||||
|
||||
|
||||
@@ -23,13 +23,13 @@ use bp_polkadot_core::{
|
||||
BlockNumber as RelayBlockNumber,
|
||||
};
|
||||
use bp_runtime::{StorageDoubleMapKeyProvider, StorageMapKeyProvider};
|
||||
use codec::{Decode, Encode};
|
||||
use codec::{Decode, Encode, MaxEncodedLen};
|
||||
use frame_support::{Blake2_128Concat, RuntimeDebug, Twox64Concat};
|
||||
use scale_info::TypeInfo;
|
||||
use sp_core::storage::StorageKey;
|
||||
|
||||
/// Best known parachain head hash.
|
||||
#[derive(Clone, Decode, Encode, PartialEq, RuntimeDebug, TypeInfo)]
|
||||
#[derive(Clone, Decode, Encode, MaxEncodedLen, PartialEq, RuntimeDebug, TypeInfo)]
|
||||
pub struct BestParaHeadHash {
|
||||
/// Number of relay block where this head has been read.
|
||||
///
|
||||
@@ -45,7 +45,7 @@ pub struct BestParaHeadHash {
|
||||
}
|
||||
|
||||
/// Best known parachain head as it is stored in the runtime storage.
|
||||
#[derive(Decode, Encode, PartialEq, RuntimeDebug, TypeInfo)]
|
||||
#[derive(Decode, Encode, MaxEncodedLen, PartialEq, RuntimeDebug, TypeInfo)]
|
||||
pub struct ParaInfo {
|
||||
/// Best known parachain head hash.
|
||||
pub best_head_hash: BestParaHeadHash,
|
||||
|
||||
@@ -40,6 +40,7 @@ pub use storage_proof::{
|
||||
record_all_keys as record_all_trie_keys, Error as StorageProofError,
|
||||
ProofSize as StorageProofSize, StorageProofChecker,
|
||||
};
|
||||
pub use storage_types::BoundedStorageValue;
|
||||
|
||||
#[cfg(feature = "std")]
|
||||
pub use storage_proof::craft_valid_storage_proof;
|
||||
@@ -48,6 +49,7 @@ pub mod messages;
|
||||
|
||||
mod chain;
|
||||
mod storage_proof;
|
||||
mod storage_types;
|
||||
|
||||
// Re-export macro to aviod include paste dependency everywhere
|
||||
pub use sp_runtime::paste;
|
||||
|
||||
@@ -0,0 +1,90 @@
|
||||
// Copyright 2022 Parity Technologies (UK) Ltd.
|
||||
// This file is part of Parity Bridges Common.
|
||||
|
||||
// Parity Bridges Common is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
|
||||
// Parity Bridges Common is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Parity Bridges Common. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
//! Wrapper for a runtime storage value that checks if value exceeds given maximum
|
||||
//! during conversion.
|
||||
|
||||
use codec::{Decode, Encode, MaxEncodedLen};
|
||||
use frame_support::{traits::Get, RuntimeDebug};
|
||||
use scale_info::{Type, TypeInfo};
|
||||
use sp_std::{marker::PhantomData, ops::Deref};
|
||||
|
||||
/// Error that is returned when the value size exceeds maximal configured size.
|
||||
#[derive(RuntimeDebug)]
|
||||
pub struct MaximalSizeExceededError {
|
||||
/// Size of the value.
|
||||
pub value_size: usize,
|
||||
/// Maximal configured size.
|
||||
pub maximal_size: usize,
|
||||
}
|
||||
|
||||
/// A bounded runtime storage value.
|
||||
#[derive(Clone, Decode, Encode, Eq, PartialEq)]
|
||||
pub struct BoundedStorageValue<B, V> {
|
||||
value: V,
|
||||
_phantom: PhantomData<B>,
|
||||
}
|
||||
|
||||
impl<B, V: sp_std::fmt::Debug> sp_std::fmt::Debug for BoundedStorageValue<B, V> {
|
||||
fn fmt(&self, fmt: &mut sp_std::fmt::Formatter) -> sp_std::fmt::Result {
|
||||
self.value.fmt(fmt)
|
||||
}
|
||||
}
|
||||
|
||||
impl<B: Get<u32>, V: Encode> BoundedStorageValue<B, V> {
|
||||
/// Construct `BoundedStorageValue` from the underlying `value` with all required checks.
|
||||
///
|
||||
/// Returns error if value size exceeds given bounds.
|
||||
pub fn try_from_inner(value: V) -> Result<Self, MaximalSizeExceededError> {
|
||||
// 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 `BoundedStorageValue` into
|
||||
// `enum BoundedStorageValue { Decoded(V), Encoded(Vec<u8>) }`)
|
||||
let value_size = value.encoded_size();
|
||||
let maximal_size = B::get() as usize;
|
||||
if value_size > maximal_size {
|
||||
Err(MaximalSizeExceededError { value_size, maximal_size })
|
||||
} else {
|
||||
Ok(BoundedStorageValue { value, _phantom: Default::default() })
|
||||
}
|
||||
}
|
||||
|
||||
/// Convert into the inner type
|
||||
pub fn into_inner(self) -> V {
|
||||
self.value
|
||||
}
|
||||
}
|
||||
|
||||
impl<B, V> Deref for BoundedStorageValue<B, V> {
|
||||
type Target = V;
|
||||
|
||||
fn deref(&self) -> &Self::Target {
|
||||
&self.value
|
||||
}
|
||||
}
|
||||
|
||||
impl<B: 'static, V: TypeInfo + 'static> TypeInfo for BoundedStorageValue<B, V> {
|
||||
type Identity = Self;
|
||||
|
||||
fn type_info() -> Type {
|
||||
V::type_info()
|
||||
}
|
||||
}
|
||||
|
||||
impl<B: Get<u32>, V: Encode> MaxEncodedLen for BoundedStorageValue<B, V> {
|
||||
fn max_encoded_len() -> usize {
|
||||
B::get() as usize
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user