Use #[pallet::unbounded] tag in FRAME System (#11946)

* use unbounded in system

* update ui tests
This commit is contained in:
Shawn Tabrizi
2022-08-10 14:58:52 +01:00
committed by GitHub
parent e41b90910e
commit 043b1697c7
5 changed files with 20 additions and 15 deletions
+6 -6
View File
@@ -44,7 +44,6 @@ pub mod logger {
#[pallet::pallet]
#[pallet::generate_store(pub(super) trait Store)]
#[pallet::without_storage_info]
pub struct Pallet<T>(PhantomData<T>);
#[pallet::call]
@@ -57,7 +56,7 @@ pub mod logger {
) -> DispatchResultWithPostInfo {
// Ensure that the `origin` is `Root`.
ensure_root(origin)?;
<I32Log<T>>::append(i);
<I32Log<T>>::try_append(i).map_err(|_| "could not append")?;
Self::deposit_event(Event::AppendI32 { value: i, weight });
Ok(().into())
}
@@ -70,8 +69,8 @@ pub mod logger {
) -> DispatchResultWithPostInfo {
// Ensure that the `origin` is some signed account.
let sender = ensure_signed(origin)?;
<I32Log<T>>::append(i);
<AccountLog<T>>::append(sender.clone());
<I32Log<T>>::try_append(i).map_err(|_| "could not append")?;
<AccountLog<T>>::try_append(sender.clone()).map_err(|_| "could not append")?;
Self::deposit_event(Event::AppendI32AndAccount { sender, value: i, weight });
Ok(().into())
}
@@ -86,11 +85,12 @@ pub mod logger {
#[pallet::storage]
#[pallet::getter(fn account_log)]
pub(super) type AccountLog<T: Config> = StorageValue<_, Vec<T::AccountId>, ValueQuery>;
pub(super) type AccountLog<T: Config> =
StorageValue<_, BoundedVec<T::AccountId, ConstU32<1_000>>, ValueQuery>;
#[pallet::storage]
#[pallet::getter(fn i32_log)]
pub(super) type I32Log<T> = StorageValue<_, Vec<i32>, ValueQuery>;
pub(super) type I32Log<T> = StorageValue<_, BoundedVec<i32, ConstU32<1_000>>, ValueQuery>;
}
type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic<Test>;
+2 -2
View File
@@ -128,7 +128,7 @@ use crate::{
dispatch::{DispatchError, DispatchErrorWithPostInfo, DispatchResultWithPostInfo},
traits::Get,
};
use codec::{Decode, Encode};
use codec::{Decode, Encode, MaxEncodedLen};
use scale_info::TypeInfo;
#[cfg(feature = "std")]
use serde::{Deserialize, Serialize};
@@ -676,7 +676,7 @@ where
}
/// A struct holding value for each `DispatchClass`.
#[derive(Clone, Eq, PartialEq, Default, RuntimeDebug, Encode, Decode, TypeInfo)]
#[derive(Clone, Eq, PartialEq, Default, RuntimeDebug, Encode, Decode, TypeInfo, MaxEncodedLen)]
pub struct PerDispatchClass<T> {
/// Value for `Normal` extrinsics.
normal: T,
@@ -13,5 +13,5 @@ error[E0277]: the trait bound `Bar: MaxEncodedLen` is not satisfied
(TupleElement0, TupleElement1, TupleElement2, TupleElement3, TupleElement4, TupleElement5)
(TupleElement0, TupleElement1, TupleElement2, TupleElement3, TupleElement4, TupleElement5, TupleElement6)
(TupleElement0, TupleElement1, TupleElement2, TupleElement3, TupleElement4, TupleElement5, TupleElement6, TupleElement7)
and 72 others
and 75 others
= note: required because of the requirements on the impl of `StorageInfoTrait` for `frame_support::pallet_prelude::StorageValue<_GeneratedPrefixForStorageFoo<T>, Bar>`
@@ -13,6 +13,6 @@ error[E0277]: the trait bound `Bar: MaxEncodedLen` is not satisfied
(TupleElement0, TupleElement1, TupleElement2, TupleElement3, TupleElement4, TupleElement5)
(TupleElement0, TupleElement1, TupleElement2, TupleElement3, TupleElement4, TupleElement5, TupleElement6)
(TupleElement0, TupleElement1, TupleElement2, TupleElement3, TupleElement4, TupleElement5, TupleElement6, TupleElement7)
and 72 others
and 75 others
= note: required because of the requirements on the impl of `KeyGeneratorMaxEncodedLen` for `Key<frame_support::Twox64Concat, Bar>`
= note: required because of the requirements on the impl of `StorageInfoTrait` for `frame_support::pallet_prelude::StorageNMap<_GeneratedPrefixForStorageFoo<T>, Key<frame_support::Twox64Concat, Bar>, u32>`
+10 -5
View File
@@ -233,7 +233,8 @@ pub mod pallet {
+ Default
+ MaybeDisplay
+ AtLeast32Bit
+ Copy;
+ Copy
+ MaxEncodedLen;
/// The block number type used by the runtime.
type BlockNumber: Parameter
@@ -320,7 +321,7 @@ pub mod pallet {
/// Data to be associated with an account (other than nonce/transaction counter, which this
/// pallet does regardless).
type AccountData: Member + FullCodec + Clone + Default + TypeInfo;
type AccountData: Member + FullCodec + Clone + Default + TypeInfo + MaxEncodedLen;
/// Handler for when a new account has just been created.
type OnNewAccount: OnNewAccount<Self::AccountId>;
@@ -355,7 +356,6 @@ pub mod pallet {
#[pallet::pallet]
#[pallet::generate_store(pub (super) trait Store)]
#[pallet::without_storage_info]
pub struct Pallet<T>(_);
#[pallet::hooks]
@@ -578,6 +578,7 @@ pub mod pallet {
/// Extrinsics data for the current block (maps an extrinsic's index to its data).
#[pallet::storage]
#[pallet::getter(fn extrinsic_data)]
#[pallet::unbounded]
pub(super) type ExtrinsicData<T: Config> =
StorageMap<_, Twox64Concat, u32, Vec<u8>, ValueQuery>;
@@ -593,6 +594,7 @@ pub mod pallet {
/// Digest of the current block, also part of the block header.
#[pallet::storage]
#[pallet::unbounded]
#[pallet::getter(fn digest)]
pub(super) type Digest<T: Config> = StorageValue<_, generic::Digest, ValueQuery>;
@@ -604,6 +606,7 @@ pub mod pallet {
/// Events have a large in-memory size. Box the events to not go out-of-memory
/// just in case someone still reads them from within the runtime.
#[pallet::storage]
#[pallet::unbounded]
pub(super) type Events<T: Config> =
StorageValue<_, Vec<Box<EventRecord<T::Event, T::Hash>>>, ValueQuery>;
@@ -623,12 +626,14 @@ pub mod pallet {
/// the `EventIndex` then in case if the topic has the same contents on the next block
/// no notification will be triggered thus the event might be lost.
#[pallet::storage]
#[pallet::unbounded]
#[pallet::getter(fn event_topics)]
pub(super) type EventTopics<T: Config> =
StorageMap<_, Blake2_128Concat, T::Hash, Vec<(T::BlockNumber, EventIndex)>, ValueQuery>;
/// Stores the `spec_version` and `spec_name` of when the last runtime upgrade happened.
#[pallet::storage]
#[pallet::unbounded]
pub type LastRuntimeUpgrade<T: Config> = StorageValue<_, LastRuntimeUpgradeInfo>;
/// True if we have upgraded so that `type RefCount` is `u32`. False (default) if not.
@@ -690,7 +695,7 @@ pub type Key = Vec<u8>;
pub type KeyValue = (Vec<u8>, Vec<u8>);
/// A phase of a block's execution.
#[derive(Encode, Decode, RuntimeDebug, TypeInfo)]
#[derive(Encode, Decode, RuntimeDebug, TypeInfo, MaxEncodedLen)]
#[cfg_attr(feature = "std", derive(Serialize, PartialEq, Eq, Clone))]
pub enum Phase {
/// Applying an extrinsic.
@@ -738,7 +743,7 @@ type EventIndex = u32;
pub type RefCount = u32;
/// Information of an account.
#[derive(Clone, Eq, PartialEq, Default, RuntimeDebug, Encode, Decode, TypeInfo)]
#[derive(Clone, Eq, PartialEq, Default, RuntimeDebug, Encode, Decode, TypeInfo, MaxEncodedLen)]
pub struct AccountInfo<Index, AccountData> {
/// The number of transactions this account has sent.
pub nonce: Index,