Add Storage Info to Various Pallets (#10810)

* atomic swap

* bounties

* bounties fmt

* gilt

* indices

* nicks

* randomness-collective-flip

* recovery

* reuse maxapprovals

* Update tests.rs

* Update frame/randomness-collective-flip/src/lib.rs

Co-authored-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* use the correct bound

* complete recovery

* use `bounded_vec` macro

* Update tests.rs

* transaction payment

* uniques

* mmr

* example offchain worker

* beefy-mmr

* Update frame/recovery/src/lib.rs

Co-authored-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Use BoundedVec instead of a type-parameterized BoundedString

* cargo fmt

* Update frame/atomic-swap/src/lib.rs

* use config const

* Update lib.rs

* update mel_bound

* fmt

Co-authored-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>
Co-authored-by: Keith Yeung <kungfukeith11@gmail.com>
This commit is contained in:
Shawn Tabrizi
2022-02-08 15:10:35 +01:00
committed by GitHub
parent d14e1c641e
commit f6f82d876b
25 changed files with 165 additions and 115 deletions
@@ -154,11 +154,14 @@ pub mod pallet {
/// multiple pallets send unsigned transactions.
#[pallet::constant]
type UnsignedPriority: Get<TransactionPriority>;
/// Maximum number of prices.
#[pallet::constant]
type MaxPrices: Get<u32>;
}
#[pallet::pallet]
#[pallet::generate_store(pub(super) trait Store)]
#[pallet::without_storage_info]
pub struct Pallet<T>(_);
#[pallet::hooks]
@@ -330,7 +333,7 @@ pub mod pallet {
/// This is used to calculate average price, should have bounded size.
#[pallet::storage]
#[pallet::getter(fn prices)]
pub(super) type Prices<T: Config> = StorageValue<_, Vec<u32>, ValueQuery>;
pub(super) type Prices<T: Config> = StorageValue<_, BoundedVec<u32, T::MaxPrices>, ValueQuery>;
/// Defines the block when next unsigned transaction will be accepted.
///
@@ -645,12 +648,8 @@ impl<T: Config> Pallet<T> {
fn add_price(maybe_who: Option<T::AccountId>, price: u32) {
log::info!("Adding to the average: {}", price);
<Prices<T>>::mutate(|prices| {
const MAX_LEN: usize = 64;
if prices.len() < MAX_LEN {
prices.push(price);
} else {
prices[price as usize % MAX_LEN] = price;
if prices.try_push(price).is_err() {
prices[(price % T::MaxPrices::get()) as usize] = price;
}
});
@@ -123,6 +123,7 @@ impl Config for Test {
type GracePeriod = ConstU64<5>;
type UnsignedInterval = ConstU64<128>;
type UnsignedPriority = UnsignedPriority;
type MaxPrices = ConstU32<64>;
}
fn test_pub() -> sp_core::sr25519::Public {