Do not use Option to wrap GenesisConfig fields (#8275)

Currently we wrap every `GenesisConfig` field in an `Option`, while
we require `Default` being implemented for all pallet genesisconfigs.
Passing `None` also results in the genesis not being initialized, which
is a bug as seen from the perspective of a pallet developer?

This pr changes the fields of the `GenesisConfig` to non `Option` types.
This commit is contained in:
Bastian Köcher
2021-03-06 14:42:21 +01:00
committed by GitHub
parent 1680422f1f
commit b0ebf6498f
10 changed files with 111 additions and 113 deletions
@@ -134,24 +134,24 @@ fn testnet_genesis(
_enable_println: bool,
) -> GenesisConfig {
GenesisConfig {
frame_system: Some(SystemConfig {
frame_system: SystemConfig {
// Add Wasm runtime to storage.
code: wasm_binary.to_vec(),
changes_trie_config: Default::default(),
}),
pallet_balances: Some(BalancesConfig {
},
pallet_balances: BalancesConfig {
// Configure endowed accounts with initial balance of 1 << 60.
balances: endowed_accounts.iter().cloned().map(|k|(k, 1 << 60)).collect(),
}),
pallet_aura: Some(AuraConfig {
},
pallet_aura: AuraConfig {
authorities: initial_authorities.iter().map(|x| (x.0.clone())).collect(),
}),
pallet_grandpa: Some(GrandpaConfig {
},
pallet_grandpa: GrandpaConfig {
authorities: initial_authorities.iter().map(|x| (x.1.clone(), 1)).collect(),
}),
pallet_sudo: Some(SudoConfig {
},
pallet_sudo: SudoConfig {
// Assign network admin rights.
key: root_key,
}),
},
}
}
+34 -34
View File
@@ -246,19 +246,19 @@ pub fn testnet_genesis(
const STASH: Balance = ENDOWMENT / 1000;
GenesisConfig {
frame_system: Some(SystemConfig {
frame_system: SystemConfig {
code: wasm_binary_unwrap().to_vec(),
changes_trie_config: Default::default(),
}),
pallet_balances: Some(BalancesConfig {
},
pallet_balances: BalancesConfig {
balances: endowed_accounts.iter().cloned()
.map(|x| (x, ENDOWMENT))
.collect()
}),
pallet_indices: Some(IndicesConfig {
},
pallet_indices: IndicesConfig {
indices: vec![],
}),
pallet_session: Some(SessionConfig {
},
pallet_session: SessionConfig {
keys: initial_authorities.iter().map(|x| {
(x.0.clone(), x.0.clone(), session_keys(
x.2.clone(),
@@ -267,8 +267,8 @@ pub fn testnet_genesis(
x.5.clone(),
))
}).collect::<Vec<_>>(),
}),
pallet_staking: Some(StakingConfig {
},
pallet_staking: StakingConfig {
validator_count: initial_authorities.len() as u32 * 2,
minimum_validator_count: initial_authorities.len() as u32,
stakers: initial_authorities.iter().map(|x| {
@@ -277,56 +277,56 @@ pub fn testnet_genesis(
invulnerables: initial_authorities.iter().map(|x| x.0.clone()).collect(),
slash_reward_fraction: Perbill::from_percent(10),
.. Default::default()
}),
pallet_democracy: Some(DemocracyConfig::default()),
pallet_elections_phragmen: Some(ElectionsConfig {
},
pallet_democracy: DemocracyConfig::default(),
pallet_elections_phragmen: ElectionsConfig {
members: endowed_accounts.iter()
.take((num_endowed_accounts + 1) / 2)
.cloned()
.map(|member| (member, STASH))
.collect(),
}),
pallet_collective_Instance1: Some(CouncilConfig::default()),
pallet_collective_Instance2: Some(TechnicalCommitteeConfig {
},
pallet_collective_Instance1: CouncilConfig::default(),
pallet_collective_Instance2: TechnicalCommitteeConfig {
members: endowed_accounts.iter()
.take((num_endowed_accounts + 1) / 2)
.cloned()
.collect(),
phantom: Default::default(),
}),
pallet_contracts: Some(ContractsConfig {
},
pallet_contracts: ContractsConfig {
current_schedule: pallet_contracts::Schedule {
enable_println, // this should only be enabled on development chains
..Default::default()
},
}),
pallet_sudo: Some(SudoConfig {
},
pallet_sudo: SudoConfig {
key: root_key,
}),
pallet_babe: Some(BabeConfig {
},
pallet_babe: BabeConfig {
authorities: vec![],
}),
pallet_im_online: Some(ImOnlineConfig {
},
pallet_im_online: ImOnlineConfig {
keys: vec![],
}),
pallet_authority_discovery: Some(AuthorityDiscoveryConfig {
},
pallet_authority_discovery: AuthorityDiscoveryConfig {
keys: vec![],
}),
pallet_grandpa: Some(GrandpaConfig {
},
pallet_grandpa: GrandpaConfig {
authorities: vec![],
}),
pallet_membership_Instance1: Some(Default::default()),
pallet_treasury: Some(Default::default()),
pallet_society: Some(SocietyConfig {
},
pallet_membership_Instance1: Default::default(),
pallet_treasury: Default::default(),
pallet_society: SocietyConfig {
members: endowed_accounts.iter()
.take((num_endowed_accounts + 1) / 2)
.cloned()
.collect(),
pot: 0,
max_members: 999,
}),
pallet_vesting: Some(Default::default()),
pallet_gilt: Some(Default::default()),
},
pallet_vesting: Default::default(),
pallet_gilt: Default::default(),
}
}
+28 -28
View File
@@ -56,20 +56,20 @@ pub fn config_endowed(
);
GenesisConfig {
frame_system: Some(SystemConfig {
frame_system: SystemConfig {
changes_trie_config: if support_changes_trie { Some(ChangesTrieConfiguration {
digest_interval: 2,
digest_levels: 2,
}) } else { None },
code: code.map(|x| x.to_vec()).unwrap_or_else(|| wasm_binary_unwrap().to_vec()),
}),
pallet_indices: Some(IndicesConfig {
},
pallet_indices: IndicesConfig {
indices: vec![],
}),
pallet_balances: Some(BalancesConfig {
},
pallet_balances: BalancesConfig {
balances: endowed,
}),
pallet_session: Some(SessionConfig {
},
pallet_session: SessionConfig {
keys: vec![
(dave(), alice(), to_session_keys(
&Ed25519Keyring::Alice,
@@ -84,8 +84,8 @@ pub fn config_endowed(
&Sr25519Keyring::Charlie,
)),
]
}),
pallet_staking: Some(StakingConfig {
},
pallet_staking: StakingConfig {
stakers: vec![
(dave(), alice(), 111 * DOLLARS, StakerStatus::Validator),
(eve(), bob(), 100 * DOLLARS, StakerStatus::Validator),
@@ -96,29 +96,29 @@ pub fn config_endowed(
slash_reward_fraction: Perbill::from_percent(10),
invulnerables: vec![alice(), bob(), charlie()],
.. Default::default()
}),
pallet_contracts: Some(ContractsConfig {
},
pallet_contracts: ContractsConfig {
current_schedule: Default::default(),
}),
pallet_babe: Some(Default::default()),
pallet_grandpa: Some(GrandpaConfig {
},
pallet_babe: Default::default(),
pallet_grandpa: GrandpaConfig {
authorities: vec![],
}),
pallet_im_online: Some(Default::default()),
pallet_authority_discovery: Some(Default::default()),
pallet_democracy: Some(Default::default()),
pallet_collective_Instance1: Some(Default::default()),
pallet_collective_Instance2: Some(Default::default()),
pallet_membership_Instance1: Some(Default::default()),
pallet_elections_phragmen: Some(Default::default()),
pallet_sudo: Some(Default::default()),
pallet_treasury: Some(Default::default()),
pallet_society: Some(SocietyConfig {
},
pallet_im_online: Default::default(),
pallet_authority_discovery: Default::default(),
pallet_democracy: Default::default(),
pallet_collective_Instance1: Default::default(),
pallet_collective_Instance2: Default::default(),
pallet_membership_Instance1: Default::default(),
pallet_elections_phragmen: Default::default(),
pallet_sudo: Default::default(),
pallet_treasury: Default::default(),
pallet_society: SocietyConfig {
members: vec![alice(), bob()],
pot: 0,
max_members: 999,
}),
pallet_vesting: Some(Default::default()),
pallet_gilt: Some(Default::default()),
},
pallet_vesting: Default::default(),
pallet_gilt: Default::default(),
}
}