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

Add genesis config to Glutton pallet #14188

Merged
merged 9 commits into from
May 23, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions bin/node/cli/src/chain_spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@
use grandpa_primitives::AuthorityId as GrandpaId;
use kitchensink_runtime::{
constants::currency::*, wasm_binary_unwrap, AuthorityDiscoveryConfig, BabeConfig,
BalancesConfig, Block, CouncilConfig, DemocracyConfig, ElectionsConfig, GrandpaConfig,
ImOnlineConfig, IndicesConfig, MaxNominations, NominationPoolsConfig, SessionConfig,
SessionKeys, SocietyConfig, StakerStatus, StakingConfig, SudoConfig, SystemConfig,
TechnicalCommitteeConfig,
BalancesConfig, Block, CouncilConfig, DemocracyConfig, ElectionsConfig, GluttonConfig,
GrandpaConfig, ImOnlineConfig, IndicesConfig, MaxNominations, NominationPoolsConfig,
SessionConfig, SessionKeys, SocietyConfig, StakerStatus, StakingConfig, SudoConfig,
SystemConfig, TechnicalCommitteeConfig,
};
use pallet_im_online::sr25519::AuthorityId as ImOnlineId;
use sc_chain_spec::ChainSpecExtension;
Expand Down Expand Up @@ -372,6 +372,11 @@ pub fn testnet_genesis(
min_join_bond: 1 * DOLLARS,
..Default::default()
},
glutton: GluttonConfig {
compute: Default::default(),
storage: Default::default(),
trash_data_count: Default::default(),
},
}
}

Expand Down
9 changes: 7 additions & 2 deletions bin/node/testing/src/genesis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
use crate::keyring::*;
use kitchensink_runtime::{
constants::currency::*, wasm_binary_unwrap, AccountId, AssetsConfig, BabeConfig,
BalancesConfig, GenesisConfig, GrandpaConfig, IndicesConfig, SessionConfig, SocietyConfig,
StakerStatus, StakingConfig, SystemConfig, BABE_GENESIS_EPOCH_CONFIG,
BalancesConfig, GenesisConfig, GluttonConfig, GrandpaConfig, IndicesConfig, SessionConfig,
SocietyConfig, StakerStatus, StakingConfig, SystemConfig, BABE_GENESIS_EPOCH_CONFIG,
};
use sp_keyring::{Ed25519Keyring, Sr25519Keyring};
use sp_runtime::Perbill;
Expand Down Expand Up @@ -94,5 +94,10 @@ pub fn config_endowed(code: Option<&[u8]>, extra_endowed: Vec<AccountId>) -> Gen
alliance: Default::default(),
alliance_motion: Default::default(),
nomination_pools: Default::default(),
glutton: GluttonConfig {
compute: Default::default(),
storage: Default::default(),
trash_data_count: Default::default(),
},
}
}
31 changes: 31 additions & 0 deletions frame/glutton/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,37 @@ pub mod pallet {
#[pallet::storage]
pub(crate) type TrashDataCount<T: Config> = StorageValue<_, u32, ValueQuery>;

#[pallet::genesis_config]
pub struct GenesisConfig {
pub compute: Perbill,
pub storage: Perbill,
pub trash_data_count: u32,
}

impl Default for GenesisConfig {
fn default() -> Self {
Self {
compute: Default::default(),
storage: Default::default(),
trash_data_count: Default::default(),
gilescope marked this conversation as resolved.
Show resolved Hide resolved
}
}
}

#[pallet::genesis_build]
impl<T: Config> GenesisBuild<T> for GenesisConfig {
fn build(&self) {
<Compute<T>>::put(self.compute);
<Storage<T>>::put(self.storage);

if self.trash_data_count <= 65_000 {
NachoPal marked this conversation as resolved.
Show resolved Hide resolved
(0..self.trash_data_count).for_each(|i| TrashData::<T>::insert(i, [i as u8; 1024]));
}

TrashDataCount::<T>::set(self.trash_data_count);
}
}

#[pallet::hooks]
impl<T: Config> Hooks<BlockNumberFor<T>> for Pallet<T> {
fn integrity_test() {
Expand Down