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

Commit

Permalink
companion: Babe remove inherent (#2438)
Browse files Browse the repository at this point in the history
  • Loading branch information
gui1117 committed Feb 16, 2021
1 parent cb0570d commit 0409d12
Show file tree
Hide file tree
Showing 8 changed files with 173 additions and 150 deletions.
282 changes: 142 additions & 140 deletions Cargo.lock

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions node/test/client/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ sp-core = { git = "https://github.com/paritytech/substrate", branch = "master" }
sp-api = { git = "https://github.com/paritytech/substrate", branch = "master" }
sp-timestamp = { git = "https://github.com/paritytech/substrate", branch = "master" }
sp-consensus = { git = "https://github.com/paritytech/substrate", branch = "master" }
sp-consensus-babe = { git = "https://github.com/paritytech/substrate", branch = "master" }
sp-state-machine = { git = "https://github.com/paritytech/substrate", branch = "master" }

[dev-dependencies]
Expand Down
30 changes: 25 additions & 5 deletions node/test/client/src/block_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@
use crate::{Client, FullBackend};
use polkadot_test_runtime::{GetLastTimestamp, UncheckedExtrinsic};
use polkadot_primitives::v1::Block;
use sp_runtime::generic::BlockId;
use sp_runtime::{generic::BlockId, Digest, DigestItem};
use sp_api::ProvideRuntimeApi;
use sp_consensus_babe::{BABE_ENGINE_ID, digests::{PreDigest, SecondaryPlainPreDigest}};
use sc_block_builder::{BlockBuilderProvider, BlockBuilder};
use sp_state_machine::BasicExternalities;
use parity_scale_codec::{Encode, Decode};
Expand Down Expand Up @@ -52,10 +53,6 @@ impl InitPolkadotBlockBuilder for Client {
&self,
at: &BlockId<Block>,
) -> BlockBuilder<Block, Client, FullBackend> {
let mut block_builder = self.new_block_at(at, Default::default(), false)
.expect("Creates new block builder for test runtime");

let mut inherent_data = sp_inherents::InherentData::new();
let last_timestamp = self
.runtime_api()
.get_last_timestamp(&at)
Expand All @@ -67,6 +64,29 @@ impl InitPolkadotBlockBuilder for Client {

let timestamp = last_timestamp + minimum_period;

// `SlotDuration` is a storage parameter type that requires externalities to access the value.
let slot_duration = BasicExternalities::new_empty()
.execute_with(|| polkadot_test_runtime::SlotDuration::get());

let slot = (timestamp / slot_duration).into();

let digest = Digest {
logs: vec![
DigestItem::PreRuntime(
BABE_ENGINE_ID,
PreDigest::SecondaryPlain(SecondaryPlainPreDigest {
slot,
authority_index: 42,
}).encode()
),
],
};

let mut block_builder = self.new_block_at(at, digest, false)
.expect("Creates new block builder for test runtime");

let mut inherent_data = sp_inherents::InherentData::new();

inherent_data
.put_data(sp_timestamp::INHERENT_IDENTIFIER, &timestamp)
.expect("Put timestamp inherent data");
Expand Down
2 changes: 1 addition & 1 deletion runtime/kusama/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -980,7 +980,7 @@ construct_runtime! {
RandomnessCollectiveFlip: pallet_randomness_collective_flip::{Module, Storage} = 32,

// Must be before session.
Babe: pallet_babe::{Module, Call, Storage, Config, Inherent, ValidateUnsigned} = 1,
Babe: pallet_babe::{Module, Call, Storage, Config, ValidateUnsigned} = 1,

Timestamp: pallet_timestamp::{Module, Call, Storage, Inherent} = 2,
Indices: pallet_indices::{Module, Call, Storage, Config<T>, Event<T>} = 3,
Expand Down
2 changes: 1 addition & 1 deletion runtime/polkadot/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -985,7 +985,7 @@ construct_runtime! {
Scheduler: pallet_scheduler::{Module, Call, Storage, Event<T>} = 1,

// Must be before session.
Babe: pallet_babe::{Module, Call, Storage, Config, Inherent, ValidateUnsigned} = 2,
Babe: pallet_babe::{Module, Call, Storage, Config, ValidateUnsigned} = 2,

Timestamp: pallet_timestamp::{Module, Call, Storage, Inherent} = 3,
Indices: pallet_indices::{Module, Call, Storage, Config<T>, Event<T>} = 4,
Expand Down
2 changes: 1 addition & 1 deletion runtime/rococo/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ construct_runtime! {
System: frame_system::{Module, Call, Storage, Config, Event<T>},

// Must be before session.
Babe: pallet_babe::{Module, Call, Storage, Config, Inherent, ValidateUnsigned},
Babe: pallet_babe::{Module, Call, Storage, Config, ValidateUnsigned},

Timestamp: pallet_timestamp::{Module, Call, Storage, Inherent},
Indices: pallet_indices::{Module, Call, Storage, Config<T>, Event<T>},
Expand Down
2 changes: 1 addition & 1 deletion runtime/test-runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -491,7 +491,7 @@ construct_runtime! {
RandomnessCollectiveFlip: pallet_randomness_collective_flip::{Module, Storage},

// Must be before session.
Babe: pallet_babe::{Module, Call, Storage, Config, Inherent},
Babe: pallet_babe::{Module, Call, Storage, Config},

Timestamp: pallet_timestamp::{Module, Call, Storage, Inherent},
Indices: pallet_indices::{Module, Call, Storage, Config<T>, Event<T>},
Expand Down
2 changes: 1 addition & 1 deletion runtime/westend/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -690,7 +690,7 @@ construct_runtime! {
RandomnessCollectiveFlip: pallet_randomness_collective_flip::{Module, Storage} = 25,

// Must be before session.
Babe: pallet_babe::{Module, Call, Storage, Config, Inherent, ValidateUnsigned} = 1,
Babe: pallet_babe::{Module, Call, Storage, Config, ValidateUnsigned} = 1,

Timestamp: pallet_timestamp::{Module, Call, Storage, Inherent} = 2,
Indices: pallet_indices::{Module, Call, Storage, Config<T>, Event<T>} = 3,
Expand Down

0 comments on commit 0409d12

Please sign in to comment.