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

Gav keep session vars #144

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
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
7 changes: 4 additions & 3 deletions demo/cli/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,10 @@ pub mod error;
use std::sync::Arc;
use client::genesis;
use codec::Slicable;
use demo_runtime::{GenesisConfig, ConsensusConfig, CouncilConfig, DemocracyConfig,
use demo_runtime::{GenesisConfig, SystemConfig, ConsensusConfig, CouncilConfig, DemocracyConfig,
SessionConfig, StakingConfig, BuildExternalities};
use futures::{Future, Sink, Stream};


struct DummyPool;
impl substrate_rpc::author::AuthorApi for DummyPool {
fn submit_extrinsic(&self, _: primitives::block::Extrinsic) -> substrate_rpc::author::error::Result<()> {
Expand Down Expand Up @@ -90,7 +89,9 @@ pub fn run<I, T>(args: I) -> error::Result<()> where
code: vec![], // TODO
authorities: vec![god_key.clone()],
}),
system: None,
system: Some(SystemConfig {
number: 0,
}),
// block_time: 5, // 5 second block time.
session: Some(SessionConfig {
validators: vec![god_key.clone()],
Expand Down
4 changes: 2 additions & 2 deletions demo/executor/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ mod tests {
construct_block(
1,
[69u8; 32].into(),
hex!("a63d59c6a7347cd7a1dc1ec139723b531f0ac450e39b1c532d5ca69ff74ad811").into(),
hex!("cb24b6108728b696d72a3a7801a98710bb868fb9bced92931a4dc9d581a506eb").into(),
vec![Extrinsic {
signed: Alice.into(),
index: 0,
Expand All @@ -210,7 +210,7 @@ mod tests {
construct_block(
2,
block1().1,
hex!("1c3623b2e3f7e43752debb9015bace4f6931593579b5af34457b931315f5e2ab").into(),
hex!("8f0cac66464e9c0006e72335cd185dccdfb5beaf21d474aff904694c79cf18e4").into(),
vec![
Extrinsic {
signed: Bob.into(),
Expand Down
Binary file modified demo/runtime/wasm/genesis.wasm
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified polkadot/runtime/wasm/genesis.wasm
Binary file not shown.
Binary file not shown.
Binary file not shown.
8 changes: 5 additions & 3 deletions polkadot/service/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ use substrate_executor::NativeExecutor;
use polkadot_executor::Executor as LocalDispatch;
use keystore::Store as Keystore;
use polkadot_api::PolkadotApi;
use polkadot_runtime::{GenesisConfig, ConsensusConfig, CouncilConfig, DemocracyConfig,
SessionConfig, StakingConfig, BuildExternalities};
use polkadot_runtime::{GenesisConfig, ConsensusConfig, SystemConfig, CouncilConfig,
DemocracyConfig, SessionConfig, StakingConfig, BuildExternalities};
use client::{genesis, BlockchainEvents};
use network::ManageNetwork;
use exit_future::Signal;
Expand Down Expand Up @@ -204,7 +204,9 @@ fn testnet_config(initial_authorities: Vec<AuthorityId>) -> ChainConfig {
code: include_bytes!("../../runtime/wasm/target/wasm32-unknown-unknown/release/polkadot_runtime.compact.wasm").to_vec(),
authorities: initial_authorities.clone(),
}),
system: None,
system: Some(SystemConfig {
number: 0,
}),
session: Some(SessionConfig {
validators: initial_authorities.clone(),
session_length: 10,
Expand Down
4 changes: 2 additions & 2 deletions substrate/runtime/executive/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ mod tests {
header: Header {
parent_hash: [69u8; 32].into(),
number: 1,
state_root: hex!("aa0cff04242e55fc780861b890aa8deba555f6ed95bd8fa575dfd80864f3b93e").into(),
state_root: hex!("0b88a6c6c26a6223eb44a1bb54bc2d43af3384bead8e58e5780c7ec7ad383e0a").into(),
extrinsics_root: hex!("56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421").into(),
digest: Digest { logs: vec![], },
},
Expand Down Expand Up @@ -273,7 +273,7 @@ mod tests {
header: Header {
parent_hash: [69u8; 32].into(),
number: 1,
state_root: hex!("aa0cff04242e55fc780861b890aa8deba555f6ed95bd8fa575dfd80864f3b93e").into(),
state_root: hex!("0b88a6c6c26a6223eb44a1bb54bc2d43af3384bead8e58e5780c7ec7ad383e0a").into(),
extrinsics_root: [0u8; 32].into(),
digest: Digest { logs: vec![], },
},
Expand Down
38 changes: 23 additions & 15 deletions substrate/runtime/system/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,11 +102,8 @@ impl<T: Trait> Module<T> {

/// Remove temporary "environment" entries in storage.
pub fn finalise() -> T::Header {
<RandomSeed<T>>::kill();
<ExtrinsicIndex<T>>::kill();

let number = <Number<T>>::take();
let parent_hash = <ParentHash<T>>::take();
let number = <Number<T>>::get();
let parent_hash = <ParentHash<T>>::get();
let digest = <Digest<T>>::take();
let extrinsics_root = <ExtrinsicsRoot<T>>::take();
let storage_root = T::Hashing::storage_root();
Expand Down Expand Up @@ -184,12 +181,15 @@ impl<T: Trait> Module<T> {
}

#[cfg(any(feature = "std", test))]
pub struct GenesisConfig<T: Trait>(PhantomData<T>);
pub struct GenesisConfig<T: Trait> {
pub number: T::BlockNumber,
}

#[cfg(any(feature = "std", test))]
impl<T: Trait> Default for GenesisConfig<T> {
fn default() -> Self {
GenesisConfig(PhantomData)
use primitives::traits::As;
GenesisConfig { number: T::BlockNumber::sa(1), }
}
}

Expand All @@ -199,13 +199,21 @@ impl<T: Trait> primitives::BuildExternalities for GenesisConfig<T>
fn build_externalities(self) -> runtime_io::TestExternalities {
use runtime_io::twox_128;
use codec::Slicable;

map![
twox_128(&<BlockHash<T>>::key_for(T::BlockNumber::zero())).to_vec() => [69u8; 32].encode(),
twox_128(<Number<T>>::key()).to_vec() => 1u64.encode(),
twox_128(<ParentHash<T>>::key()).to_vec() => [69u8; 32].encode(),
twox_128(<RandomSeed<T>>::key()).to_vec() => [0u8; 32].encode(),
twox_128(<ExtrinsicIndex<T>>::key()).to_vec() => [0u8; 4].encode()
]
use primitives::traits::As;

if self.number == T::BlockNumber::sa(0) {
map![
twox_128(<Number<T>>::key()).to_vec() => self.number.encode(),
twox_128(<RandomSeed<T>>::key()).to_vec() => T::Hash::default().encode()
]
} else {
map![
twox_128(<Number<T>>::key()).to_vec() => self.number.encode(),
twox_128(<RandomSeed<T>>::key()).to_vec() => T::Hash::default().encode(),
twox_128(&<BlockHash<T>>::key_for(T::BlockNumber::zero())).to_vec() => [69u8; 32].encode(),
twox_128(<ParentHash<T>>::key()).to_vec() => [69u8; 32].encode(),
twox_128(<ExtrinsicIndex<T>>::key()).to_vec() => 0u32.encode()
]
}
}
}
Binary file not shown.
Binary file not shown.