Skip to content
This repository has been archived by the owner on Nov 1, 2023. It is now read-only.

Commit

Permalink
Use #[pallet::unbounded] tag in FRAME System (paritytech#11946)
Browse files Browse the repository at this point in the history
* use unbounded in system

* update ui tests
  • Loading branch information
shawntabrizi authored and DaviRain-Su committed Aug 23, 2022
1 parent 6dde063 commit 806c8b5
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 15 deletions.
12 changes: 6 additions & 6 deletions frame/sudo/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -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())
}
Expand All @@ -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())
}
Expand All @@ -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>;
Expand Down
4 changes: 2 additions & 2 deletions frame/support/src/weights.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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>`
Original file line number Diff line number Diff line change
Expand Up @@ -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>`
15 changes: 10 additions & 5 deletions frame/system/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,8 @@ pub mod pallet {
+ Default
+ MaybeDisplay
+ AtLeast32Bit
+ Copy;
+ Copy
+ MaxEncodedLen;

/// The block number type used by the runtime.
type BlockNumber: Parameter
Expand Down Expand Up @@ -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>;
Expand Down Expand Up @@ -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]
Expand Down Expand Up @@ -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>;

Expand All @@ -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>;

Expand All @@ -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>;

Expand All @@ -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.
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 806c8b5

Please sign in to comment.