Support multi trie in genesis generation (#958)

* Support multi trie in genesis generation

* Fix merge issues
This commit is contained in:
Wei Tang
2018-11-01 16:30:03 +08:00
committed by Gav Wood
parent ac4a188e15
commit b21de8a0b5
45 changed files with 292 additions and 213 deletions
+1 -1
View File
@@ -186,7 +186,7 @@ mod tests {
// This function basically just builds a genesis storage key/value store according to
// our desired mockup.
fn new_test_ext() -> runtime_io::TestExternalities<Blake2Hasher> {
system::GenesisConfig::<Test>::default().build_storage().unwrap().into()
system::GenesisConfig::<Test>::default().build_storage().unwrap().0.into()
}
#[test]
+1 -1
View File
@@ -260,7 +260,7 @@ decl_storage! {
}
add_extra_genesis {
config(balances): Vec<(T::AccountId, T::Balance)>;
build(|storage: &mut primitives::StorageMap, config: &GenesisConfig<T>| {
build(|storage: &mut primitives::StorageMap, _: &mut primitives::ChildrenStorageMap, config: &GenesisConfig<T>| {
let ids: Vec<_> = config.balances.iter().map(|x| x.0.clone()).collect();
for i in 0..(ids.len() + ENUM_SET_SIZE - 1) / ENUM_SET_SIZE {
storage.insert(GenesisConfig::<T>::hash(&<EnumSet<T>>::key_for(T::AccountIndex::sa(i))).to_vec(),
+2 -2
View File
@@ -85,7 +85,7 @@ impl ExtBuilder {
self
}
pub fn build(self) -> runtime_io::TestExternalities<Blake2Hasher> {
let mut t = system::GenesisConfig::<Runtime>::default().build_storage().unwrap();
let mut t = system::GenesisConfig::<Runtime>::default().build_storage().unwrap().0;
let balance_factor = if self.existential_deposit > 0 {
256
} else {
@@ -103,7 +103,7 @@ impl ExtBuilder {
transfer_fee: self.transfer_fee,
creation_fee: self.creation_fee,
reclaim_rebate: 0,
}.build_storage().unwrap());
}.build_storage().unwrap().0);
t.into()
}
}
+1 -1
View File
@@ -130,7 +130,7 @@ decl_storage! {
#[serde(with = "substrate_primitives::bytes")]
config(code): Vec<u8>;
build(|storage: &mut primitives::StorageMap, config: &GenesisConfig<T>| {
build(|storage: &mut primitives::StorageMap, _: &mut primitives::ChildrenStorageMap, config: &GenesisConfig<T>| {
use codec::{Encode, KeyedVec};
let auth_count = config.authorities.len() as u32;
+2 -2
View File
@@ -50,11 +50,11 @@ impl system::Trait for Test {
}
pub fn new_test_ext(authorities: Vec<u64>) -> runtime_io::TestExternalities<Blake2Hasher> {
let mut t = system::GenesisConfig::<Test>::default().build_storage().unwrap();
let mut t = system::GenesisConfig::<Test>::default().build_storage().unwrap().0;
t.extend(GenesisConfig::<Test>{
code: vec![],
authorities,
}.build_storage().unwrap());
}.build_storage().unwrap().0);
t.into()
}
+3 -3
View File
@@ -121,7 +121,7 @@ impl ExtBuilder {
fn build(self) -> runtime_io::TestExternalities<Blake2Hasher> {
let mut t = system::GenesisConfig::<Test>::default()
.build_storage()
.unwrap();
.unwrap().0;
t.extend(
balances::GenesisConfig::<Test> {
balances: vec![],
@@ -132,7 +132,7 @@ impl ExtBuilder {
creation_fee: self.creation_fee,
reclaim_rebate: 0,
}.build_storage()
.unwrap(),
.unwrap().0,
);
t.extend(
GenesisConfig::<Test> {
@@ -143,7 +143,7 @@ impl ExtBuilder {
max_depth: 100,
block_gas_limit: self.block_gas_limit,
}.build_storage()
.unwrap(),
.unwrap().0,
);
runtime_io::TestExternalities::new(t)
}
+5 -5
View File
@@ -117,7 +117,7 @@ mod tests {
}
pub fn new_test_ext(with_council: bool) -> runtime_io::TestExternalities<Blake2Hasher> {
let mut t = system::GenesisConfig::<Test>::default().build_storage().unwrap();
let mut t = system::GenesisConfig::<Test>::default().build_storage().unwrap().0;
t.extend(balances::GenesisConfig::<Test>{
balances: vec![(1, 10), (2, 20), (3, 30), (4, 40), (5, 50), (6, 60)],
transaction_base_fee: 0,
@@ -126,12 +126,12 @@ mod tests {
transfer_fee: 0,
creation_fee: 0,
reclaim_rebate: 0,
}.build_storage().unwrap());
}.build_storage().unwrap().0);
t.extend(democracy::GenesisConfig::<Test>{
launch_period: 1,
voting_period: 3,
minimum_deposit: 1,
}.build_storage().unwrap());
}.build_storage().unwrap().0);
t.extend(seats::GenesisConfig::<Test> {
candidacy_bond: 9,
voter_bond: 3,
@@ -147,11 +147,11 @@ mod tests {
presentation_duration: 2,
desired_seats: 2,
term_duration: 5,
}.build_storage().unwrap());
}.build_storage().unwrap().0);
t.extend(voting::GenesisConfig::<Test> {
cooloff_period: 2,
voting_period: 1,
}.build_storage().unwrap());
}.build_storage().unwrap().0);
runtime_io::TestExternalities::new(t)
}
+1 -1
View File
@@ -174,7 +174,7 @@ decl_storage! {
}
add_extra_genesis {
config(_marker): ::std::marker::PhantomData<T>;
build(|_, _| {});
build(|_, _, _| {});
}
}
+3 -3
View File
@@ -353,7 +353,7 @@ mod tests {
}
fn new_test_ext() -> runtime_io::TestExternalities<Blake2Hasher> {
let mut t = system::GenesisConfig::<Test>::default().build_storage().unwrap();
let mut t = system::GenesisConfig::<Test>::default().build_storage().unwrap().0;
t.extend(balances::GenesisConfig::<Test>{
balances: vec![(1, 10), (2, 20), (3, 30), (4, 40), (5, 50), (6, 60)],
transaction_base_fee: 0,
@@ -362,12 +362,12 @@ mod tests {
transfer_fee: 0,
creation_fee: 0,
reclaim_rebate: 0,
}.build_storage().unwrap());
}.build_storage().unwrap().0);
t.extend(GenesisConfig::<Test>{
launch_period: 1,
voting_period: 1,
minimum_deposit: 1,
}.build_storage().unwrap());
}.build_storage().unwrap().0);
runtime_io::TestExternalities::new(t)
}
+3 -3
View File
@@ -314,13 +314,13 @@ mod tests {
// This function basically just builds a genesis storage key/value store according to
// our desired mockup.
fn new_test_ext() -> sr_io::TestExternalities<Blake2Hasher> {
let mut t = system::GenesisConfig::<Test>::default().build_storage().unwrap();
let mut t = system::GenesisConfig::<Test>::default().build_storage().unwrap().0;
// We use default for brevity, but you can configure as desired if needed.
t.extend(balances::GenesisConfig::<Test>::default().build_storage().unwrap());
t.extend(balances::GenesisConfig::<Test>::default().build_storage().unwrap().0);
t.extend(GenesisConfig::<Test>{
dummy: 42,
foo: 24,
}.build_storage().unwrap());
}.build_storage().unwrap().0);
t.into()
}
+4 -4
View File
@@ -322,7 +322,7 @@ mod tests {
#[test]
fn balance_transfer_dispatch_works() {
let mut t = system::GenesisConfig::<Runtime>::default().build_storage().unwrap();
let mut t = system::GenesisConfig::<Runtime>::default().build_storage().unwrap().0;
t.extend(balances::GenesisConfig::<Runtime> {
balances: vec![(1, 111)],
transaction_base_fee: 10,
@@ -331,7 +331,7 @@ mod tests {
transfer_fee: 0,
creation_fee: 0,
reclaim_rebate: 0,
}.build_storage().unwrap());
}.build_storage().unwrap().0);
let xt = primitives::testing::TestXt(Some(1), 0, Call::transfer(2.into(), 69.into()));
let mut t = runtime_io::TestExternalities::<Blake2Hasher>::new(t);
with_externalities(&mut t, || {
@@ -344,8 +344,8 @@ mod tests {
}
fn new_test_ext() -> runtime_io::TestExternalities<Blake2Hasher> {
let mut t = system::GenesisConfig::<Runtime>::default().build_storage().unwrap();
t.extend(balances::GenesisConfig::<Runtime>::default().build_storage().unwrap());
let mut t = system::GenesisConfig::<Runtime>::default().build_storage().unwrap().0;
t.extend(balances::GenesisConfig::<Runtime>::default().build_storage().unwrap().0);
t.into()
}
+4 -4
View File
@@ -270,18 +270,18 @@ mod tests {
type Session = Module<Test>;
fn new_test_ext() -> runtime_io::TestExternalities<Blake2Hasher> {
let mut t = system::GenesisConfig::<Test>::default().build_storage().unwrap();
let mut t = system::GenesisConfig::<Test>::default().build_storage().unwrap().0;
t.extend(consensus::GenesisConfig::<Test>{
code: vec![],
authorities: vec![1, 2, 3],
}.build_storage().unwrap());
}.build_storage().unwrap().0);
t.extend(timestamp::GenesisConfig::<Test>{
period: 5,
}.build_storage().unwrap());
}.build_storage().unwrap().0);
t.extend(GenesisConfig::<Test>{
session_length: 2,
validators: vec![1, 2, 3],
}.build_storage().unwrap());
}.build_storage().unwrap().0);
runtime_io::TestExternalities::new(t)
}
+6 -6
View File
@@ -79,7 +79,7 @@ pub fn new_test_ext(
monied: bool,
reward: u64
) -> runtime_io::TestExternalities<Blake2Hasher> {
let mut t = system::GenesisConfig::<Test>::default().build_storage().unwrap();
let mut t = system::GenesisConfig::<Test>::default().build_storage().unwrap().0;
let balance_factor = if ext_deposit > 0 {
256
} else {
@@ -88,11 +88,11 @@ pub fn new_test_ext(
t.extend(consensus::GenesisConfig::<Test>{
code: vec![],
authorities: vec![],
}.build_storage().unwrap());
}.build_storage().unwrap().0);
t.extend(session::GenesisConfig::<Test>{
session_length,
validators: vec![10, 20],
}.build_storage().unwrap());
}.build_storage().unwrap().0);
t.extend(balances::GenesisConfig::<Test>{
balances: if monied {
if reward > 0 {
@@ -109,7 +109,7 @@ pub fn new_test_ext(
transfer_fee: 0,
creation_fee: 0,
reclaim_rebate: 0,
}.build_storage().unwrap());
}.build_storage().unwrap().0);
t.extend(GenesisConfig::<Test>{
sessions_per_era,
current_era,
@@ -122,10 +122,10 @@ pub fn new_test_ext(
current_session_reward: reward,
current_offline_slash: 20,
offline_slash_grace: 0,
}.build_storage().unwrap());
}.build_storage().unwrap().0);
t.extend(timestamp::GenesisConfig::<Test>{
period: 5
}.build_storage().unwrap());
}.build_storage().unwrap().0);
runtime_io::TestExternalities::new(t)
}
+1 -1
View File
@@ -189,7 +189,7 @@ mod tests {
}
add_extra_genesis {
config(_marker) : ::std::marker::PhantomData<T>;
build(|_, _| {});
build(|_, _, _| {});
}
}
}
@@ -644,8 +644,9 @@ macro_rules! __generate_genesis_config {
#[cfg(feature = "std")]
impl<$traitinstance: $traittype> $crate::runtime_primitives::BuildStorage for GenesisConfig<$traitinstance>
{
fn build_storage(self) -> ::std::result::Result<$crate::runtime_primitives::StorageMap, String> {
fn build_storage(self) -> ::std::result::Result<($crate::runtime_primitives::StorageMap, $crate::runtime_primitives::ChildrenStorageMap), String> {
let mut r: $crate::runtime_primitives::StorageMap = Default::default();
let mut c: $crate::runtime_primitives::ChildrenStorageMap = Default::default();
// normal getters
$({
@@ -664,9 +665,9 @@ macro_rules! __generate_genesis_config {
})*
// extra call
$call(&mut r, &self);
$call(&mut r, &mut c, &self);
Ok(r)
Ok((r, c))
}
}
};
@@ -718,7 +719,7 @@ macro_rules! decl_storage {
__impl_store_fns!($traitinstance $($t)*);
__impl_store_metadata!($cratename; $($t)*);
}
__decl_genesis_config_items!([$traittype $traitinstance] [] [] [] [] [|_, _|{}] $($t)*);
__decl_genesis_config_items!([$traittype $traitinstance] [] [] [] [] [|_, _, _|{}] $($t)*);
};
}
@@ -1961,7 +1962,7 @@ mod tests {
}
add_extra_genesis {
config(_marker) : ::std::marker::PhantomData<T>;
build(|_, _| {});
build(|_, _, _| {});
}
}
@@ -2168,7 +2169,7 @@ mod test2 {
add_extra_genesis {
config(_marker) : ::std::marker::PhantomData<T>;
config(extra_field) : u32 = 32;
build(|_, _| {});
build(|_, _, _| {});
}
}
+2 -2
View File
@@ -206,7 +206,7 @@ decl_storage! {
config(changes_trie_config): Option<ChangesTrieConfiguration>;
config(_phantom): ::std::marker::PhantomData<T>;
build(|storage: &mut primitives::StorageMap, config: &GenesisConfig<T>| {
build(|storage: &mut primitives::StorageMap, _: &mut primitives::ChildrenStorageMap, config: &GenesisConfig<T>| {
use codec::Encode;
storage.insert(well_known_keys::EXTRINSIC_INDEX.to_vec(), 0u32.encode());
@@ -467,7 +467,7 @@ mod tests {
type System = Module<Test>;
fn new_test_ext() -> runtime_io::TestExternalities<Blake2Hasher> {
GenesisConfig::<Test>::default().build_storage().unwrap().into()
GenesisConfig::<Test>::default().build_storage().unwrap().0.into()
}
#[test]
+6 -6
View File
@@ -215,8 +215,8 @@ mod tests {
#[test]
fn timestamp_works() {
let mut t = system::GenesisConfig::<Test>::default().build_storage().unwrap();
t.extend(GenesisConfig::<Test> { period: 0 }.build_storage().unwrap());
let mut t = system::GenesisConfig::<Test>::default().build_storage().unwrap().0;
t.extend(GenesisConfig::<Test> { period: 0 }.build_storage().unwrap().0);
with_externalities(&mut TestExternalities::new(t), || {
Timestamp::set_timestamp(42);
@@ -228,8 +228,8 @@ mod tests {
#[test]
#[should_panic(expected = "Timestamp must be updated only once in the block")]
fn double_timestamp_should_fail() {
let mut t = system::GenesisConfig::<Test>::default().build_storage().unwrap();
t.extend(GenesisConfig::<Test> { period: 5 }.build_storage().unwrap());
let mut t = system::GenesisConfig::<Test>::default().build_storage().unwrap().0;
t.extend(GenesisConfig::<Test> { period: 5 }.build_storage().unwrap().0);
with_externalities(&mut TestExternalities::new(t), || {
Timestamp::set_timestamp(42);
@@ -241,8 +241,8 @@ mod tests {
#[test]
#[should_panic(expected = "Timestamp must increment by at least <BlockPeriod> between sequential blocks")]
fn block_period_is_enforced() {
let mut t = system::GenesisConfig::<Test>::default().build_storage().unwrap();
t.extend(GenesisConfig::<Test> { period: 5 }.build_storage().unwrap());
let mut t = system::GenesisConfig::<Test>::default().build_storage().unwrap().0;
t.extend(GenesisConfig::<Test> { period: 5 }.build_storage().unwrap().0);
with_externalities(&mut TestExternalities::new(t), || {
Timestamp::set_timestamp(42);
+3 -3
View File
@@ -325,7 +325,7 @@ mod tests {
type Treasury = Module<Test>;
fn new_test_ext() -> runtime_io::TestExternalities<Blake2Hasher> {
let mut t = system::GenesisConfig::<Test>::default().build_storage().unwrap();
let mut t = system::GenesisConfig::<Test>::default().build_storage().unwrap().0;
t.extend(balances::GenesisConfig::<Test>{
balances: vec![(0, 100), (1, 99), (2, 1)],
transaction_base_fee: 0,
@@ -334,13 +334,13 @@ mod tests {
creation_fee: 0,
existential_deposit: 0,
reclaim_rebate: 0,
}.build_storage().unwrap());
}.build_storage().unwrap().0);
t.extend(GenesisConfig::<Test>{
proposal_bond: Permill::from_percent(5),
proposal_bond_minimum: 1,
spend_period: 2,
burn: Permill::from_percent(50),
}.build_storage().unwrap());
}.build_storage().unwrap().0);
t.into()
}