mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-05-31 20:21:03 +00:00
Genesis map.
- fix warning - remove more bare string ids
This commit is contained in:
@@ -23,6 +23,7 @@ use runtime_support::Hashable;
|
||||
use primitives::Block;
|
||||
use demo_primitives::{BlockNumber, AccountId};
|
||||
use runtime::staking::Balance;
|
||||
use runtime::{staking, session, consensus, system, democracy, council, council_vote};
|
||||
|
||||
/// Configuration of a general Substrate Demo genesis block.
|
||||
pub struct GenesisConfig {
|
||||
@@ -33,7 +34,20 @@ pub struct GenesisConfig {
|
||||
pub session_length: BlockNumber,
|
||||
pub sessions_per_era: BlockNumber,
|
||||
pub bonding_duration: BlockNumber,
|
||||
pub approval_ratio: u32,
|
||||
pub launch_period: BlockNumber,
|
||||
pub voting_period: BlockNumber,
|
||||
pub minimum_deposit: Balance,
|
||||
pub candidacy_bond: Balance,
|
||||
pub voter_bond: Balance,
|
||||
pub present_slash_per_voter: Balance,
|
||||
pub carry_count: u32,
|
||||
pub presentation_duration: BlockNumber,
|
||||
pub council_election_voting_period: BlockNumber,
|
||||
pub council_term_duration: BlockNumber,
|
||||
pub desired_seats: u32,
|
||||
pub inactive_grace_period: BlockNumber,
|
||||
pub cooloff_period: BlockNumber,
|
||||
pub council_proposal_voting_period: BlockNumber,
|
||||
}
|
||||
|
||||
impl GenesisConfig {
|
||||
@@ -42,43 +56,69 @@ impl GenesisConfig {
|
||||
validators: authorities_validators.clone(),
|
||||
authorities: authorities_validators.clone(),
|
||||
balances: authorities_validators.iter().map(|v| (v.clone(), balance)).collect(),
|
||||
block_time: 5, // 5 second block time.
|
||||
session_length: 720, // that's 1 hour per session.
|
||||
block_time: 30, // 30 second block time.
|
||||
session_length: 120, // that's 1 hour per session.
|
||||
sessions_per_era: 24, // 24 hours per era.
|
||||
bonding_duration: 90, // 90 days per bond.
|
||||
approval_ratio: 667, // 66.7% approvals required for legislation.
|
||||
launch_period: 120 * 24 * 14, // 2 weeks per public referendum
|
||||
voting_period: 120 * 24 * 28, // 4 weeks to discuss & vote on an active referendum
|
||||
minimum_deposit: 1000, // 1000 as the minimum deposit for a referendum
|
||||
candidacy_bond: 1000, // 1000 to become a council candidate
|
||||
voter_bond: 100, // 100 down to vote for a candidate
|
||||
present_slash_per_voter: 1, // slash by 1 per voter for an invalid presentation.
|
||||
carry_count: 24, // carry over the 24 runners-up to the next council election
|
||||
presentation_duration: 120 * 24, // one day for presenting winners.
|
||||
council_election_voting_period: 7 * 120 * 24, // one week period between possible council elections.
|
||||
council_term_duration: 180 * 120 * 24, // 180 day term duration for the council.
|
||||
desired_seats: 0, // start with no council: we'll raise this once the stake has been dispersed a bit.
|
||||
inactive_grace_period: 1, // one addition vote should go by before an inactive voter can be reaped.
|
||||
cooloff_period: 90 * 120 * 24, // 90 day cooling off period if council member vetoes a proposal.
|
||||
council_proposal_voting_period: 7 * 120 * 24, // 7 day voting period for council members.
|
||||
}
|
||||
}
|
||||
|
||||
pub fn genesis_map(&self) -> HashMap<Vec<u8>, Vec<u8>> {
|
||||
let wasm_runtime = include_bytes!("../wasm/genesis.wasm").to_vec();
|
||||
vec![
|
||||
(&b"gov:apr"[..], vec![].and(&self.approval_ratio)),
|
||||
(&b"ses:len"[..], vec![].and(&self.session_length)),
|
||||
(&b"ses:val:len"[..], vec![].and(&(self.validators.len() as u32))),
|
||||
(&b"sta:wil:len"[..], vec![].and(&0u32)),
|
||||
(&b"sta:spe"[..], vec![].and(&self.sessions_per_era)),
|
||||
(&b"sta:vac"[..], vec![].and(&(self.validators.len() as u32))),
|
||||
(&b"sta:era"[..], vec![].and(&0u64)),
|
||||
(&session::SESSION_LENGTH[..], vec![].and(&self.session_length)),
|
||||
(&session::VALIDATOR_COUNT[..], vec![].and(&(self.validators.len() as u32))),
|
||||
|
||||
(&staking::INTENTION_COUNT[..], vec![].and(&0u32)),
|
||||
(&staking::SESSIONS_PER_ERA[..], vec![].and(&self.sessions_per_era)),
|
||||
(&staking::CURRENT_ERA[..], vec![].and(&0u64)),
|
||||
|
||||
(&democracy::LAUNCH_PERIOD[..], vec![].and(&self.launch_period)),
|
||||
(&democracy::VOTING_PERIOD[..], vec![].and(&self.voting_period)),
|
||||
(&democracy::MINIMUM_DEPOSIT[..], vec![].and(&self.minimum_deposit)),
|
||||
|
||||
(&council::CANDIDACY_BOND[..], vec![].and(&self.candidacy_bond)),
|
||||
(&council::VOTING_BOND[..], vec![].and(&self.voter_bond)),
|
||||
(&council::PRESENT_SLASH_PER_VOTER[..], vec![].and(&self.present_slash_per_voter)),
|
||||
(&council::CARRY_COUNT[..], vec![].and(&self.carry_count)),
|
||||
(&council::PRESENTATION_DURATION[..], vec![].and(&self.presentation_duration)),
|
||||
(&council::VOTING_PERIOD[..], vec![].and(&self.council_election_voting_period)),
|
||||
(&council::TERM_DURATION[..], vec![].and(&self.council_term_duration)),
|
||||
(&council::DESIRED_SEATS[..], vec![].and(&self.desired_seats)),
|
||||
(&council::INACTIVE_GRACE_PERIOD[..], vec![].and(&self.inactive_grace_period)),
|
||||
|
||||
(&council_vote::COOLOFF_PERIOD[..], vec![].and(&self.cooloff_period)),
|
||||
(&council_vote::VOTING_PERIOD[..], vec![].and(&self.council_proposal_voting_period))
|
||||
].into_iter()
|
||||
.map(|(k, v)| (k.into(), v))
|
||||
.chain(self.validators.iter()
|
||||
.enumerate()
|
||||
.map(|(i, account)| ((i as u32).to_keyed_vec(b"ses:val:"), vec![].and(account)))
|
||||
).chain(self.authorities.iter()
|
||||
.enumerate()
|
||||
.map(|(i, account)| ((i as u32).to_keyed_vec(b":auth:"), vec![].and(account)))
|
||||
.map(|(i, account)| ((i as u32).to_keyed_vec(session::VALIDATOR_AT), vec![].and(account)))
|
||||
).chain(self.balances.iter()
|
||||
.map(|&(account, balance)| (account.to_keyed_vec(b"sta:bal:"), vec![].and(&balance)))
|
||||
.map(|&(account, balance)| (account.to_keyed_vec(staking::BALANCE_OF), vec![].and(&balance)))
|
||||
)
|
||||
.map(|(k, v)| (twox_128(&k[..])[..].to_vec(), v.to_vec()))
|
||||
.chain(vec![
|
||||
(b":code"[..].into(), wasm_runtime),
|
||||
(b":auth:len"[..].into(), vec![].and(&(self.authorities.len() as u32))),
|
||||
(system::CODE[..].into(), wasm_runtime),
|
||||
(consensus::AUTHORITY_COUNT[..].into(), vec![].and(&(self.authorities.len() as u32))),
|
||||
].into_iter())
|
||||
.chain(self.authorities.iter()
|
||||
.enumerate()
|
||||
.map(|(i, account)| ((i as u32).to_keyed_vec(b":auth:"), vec![].and(account)))
|
||||
.map(|(i, account)| ((i as u32).to_keyed_vec(consensus::AUTHORITY_AT), vec![].and(account)))
|
||||
)
|
||||
.collect()
|
||||
}
|
||||
@@ -87,6 +127,6 @@ impl GenesisConfig {
|
||||
pub fn additional_storage_with_genesis(genesis_block: &Block) -> HashMap<Vec<u8>, Vec<u8>> {
|
||||
use codec::Slicable;
|
||||
map![
|
||||
twox_128(&0u64.to_keyed_vec(b"sys:old:")).to_vec() => genesis_block.header.blake2_256().encode()
|
||||
twox_128(&0u64.to_keyed_vec(system::BLOCK_HASH_AT)).to_vec() => genesis_block.header.blake2_256().encode()
|
||||
]
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user