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

Generalize pallet-babe to be independent of BABE primitives #5655

Closed
wants to merge 16 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
64 changes: 33 additions & 31 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ members = [
"frame/aura",
"frame/authority-discovery",
"frame/authorship",
"frame/babe",
"frame/epoch-vrf",
"frame/balances",
"frame/benchmarking",
"frame/benchmark",
Expand Down Expand Up @@ -122,7 +122,7 @@ members = [
"primitives/consensus/babe",
"primitives/consensus/common",
"primitives/consensus/pow",
"primitives/consensus/vrf",
"primitives/consensus/epoch-vrf",
"primitives/core",
"primitives/chain-spec",
"primitives/database",
Expand Down
2 changes: 1 addition & 1 deletion bin/node/cli/src/chain_spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ pub fn testnet_genesis(
pallet_sudo: Some(SudoConfig {
key: root_key,
}),
pallet_babe: Some(BabeConfig {
pallet_epoch_vrf: Some(BabeConfig {
authorities: vec![],
}),
pallet_im_online: Some(ImOnlineConfig {
Expand Down
4 changes: 2 additions & 2 deletions bin/node/runtime/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ frame-system-benchmarking = { version = "2.0.0-dev", default-features = false, p
frame-system-rpc-runtime-api = { version = "2.0.0-dev", default-features = false, path = "../../../frame/system/rpc/runtime-api/" }
pallet-authority-discovery = { version = "2.0.0-dev", default-features = false, path = "../../../frame/authority-discovery" }
pallet-authorship = { version = "2.0.0-dev", default-features = false, path = "../../../frame/authorship" }
pallet-babe = { version = "2.0.0-dev", default-features = false, path = "../../../frame/babe" }
pallet-epoch-vrf = { version = "2.0.0-dev", default-features = false, path = "../../../frame/epoch-vrf" }
pallet-balances = { version = "2.0.0-dev", default-features = false, path = "../../../frame/balances" }
pallet-collective = { version = "2.0.0-dev", default-features = false, path = "../../../frame/collective" }
pallet-contracts = { version = "2.0.0-dev", default-features = false, path = "../../../frame/contracts" }
Expand Down Expand Up @@ -89,7 +89,7 @@ std = [
"pallet-authority-discovery/std",
"pallet-authorship/std",
"sp-consensus-babe/std",
"pallet-babe/std",
"pallet-epoch-vrf/std",
"pallet-balances/std",
"sp-block-builder/std",
"codec/std",
Expand Down
10 changes: 5 additions & 5 deletions bin/node/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
// and set impl_version to 0. If only runtime
// implementation changes and behavior does not, then leave spec_version as
// is and increment impl_version.
spec_version: 247,
spec_version: 248,
impl_version: 0,
apis: RUNTIME_API_VERSIONS,
transaction_version: 1,
Expand Down Expand Up @@ -190,10 +190,10 @@ parameter_types! {
pub const ExpectedBlockTime: Moment = MILLISECS_PER_BLOCK;
}

impl pallet_babe::Trait for Runtime {
impl pallet_epoch_vrf::babe::BabeTrait for Runtime {
type EpochDuration = EpochDuration;
type ExpectedBlockTime = ExpectedBlockTime;
type EpochChangeTrigger = pallet_babe::ExternalTrigger;
type EpochChangeTrigger = pallet_epoch_vrf::ExternalTrigger;
}

parameter_types! {
Expand Down Expand Up @@ -251,7 +251,7 @@ parameter_types! {
}

impl pallet_authorship::Trait for Runtime {
type FindAuthor = pallet_session::FindAccountFromAuthorIndex<Self, Babe>;
type FindAuthor = pallet_session::FindAccountFromAuthorIndex<Self, pallet_epoch_vrf::babe::BabeFindAuthor<Self>>;
type UncleGenerations = UncleGenerations;
type FilterUncle = ();
type EventHandler = (Staking, ImOnline);
Expand Down Expand Up @@ -695,7 +695,7 @@ construct_runtime!(
{
System: frame_system::{Module, Call, Config, Storage, Event<T>},
Utility: pallet_utility::{Module, Call, Storage, Event<T>},
Babe: pallet_babe::{Module, Call, Storage, Config, Inherent(Timestamp)},
Babe: pallet_epoch_vrf::{Module, Call, Storage, Config<T>, Inherent(Timestamp)},
Timestamp: pallet_timestamp::{Module, Call, Storage, Inherent},
Authorship: pallet_authorship::{Module, Call, Storage, Inherent},
Indices: pallet_indices::{Module, Call, Storage, Config<T>, Event<T>},
Expand Down
2 changes: 1 addition & 1 deletion bin/node/testing/src/genesis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ pub fn config_endowed(
pallet_contracts: Some(ContractsConfig {
current_schedule: Default::default(),
}),
pallet_babe: Some(Default::default()),
pallet_epoch_vrf: Some(Default::default()),
pallet_grandpa: Some(GrandpaConfig {
authorities: vec![],
}),
Expand Down
2 changes: 1 addition & 1 deletion client/consensus/babe/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ sp-api = { version = "2.0.0-dev", path = "../../../primitives/api" }
sp-block-builder = { version = "2.0.0-dev", path = "../../../primitives/block-builder" }
sp-blockchain = { version = "2.0.0-dev", path = "../../../primitives/blockchain" }
sp-consensus = { version = "0.8.0-dev", path = "../../../primitives/consensus/common" }
sp-consensus-vrf = { version = "0.8.0-dev", path = "../../../primitives/consensus/vrf" }
sp-consensus-epoch-vrf = { version = "0.8.0-dev", path = "../../../primitives/consensus/epoch-vrf" }
sc-consensus-uncles = { version = "0.8.0-dev", path = "../uncles" }
sc-consensus-slots = { version = "0.8.0-dev", path = "../slots" }
sp-runtime = { version = "2.0.0-dev", path = "../../../primitives/runtime" }
Expand Down
2 changes: 1 addition & 1 deletion client/consensus/babe/src/authorship.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ use sp_consensus_babe::{
use sp_consensus_babe::digests::{
PreDigest, PrimaryPreDigest, SecondaryPlainPreDigest, SecondaryVRFPreDigest,
};
use sp_consensus_vrf::schnorrkel::{VRFOutput, VRFProof};
use sp_consensus_epoch_vrf::schnorrkel::{VRFOutput, VRFProof};
use sp_core::{U256, blake2_256};
use codec::Encode;
use schnorrkel::vrf::VRFInOut;
Expand Down
10 changes: 5 additions & 5 deletions client/consensus/babe/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ use sp_consensus::{
ForkChoiceStrategy, BlockImportParams, BlockOrigin, Error as ConsensusError,
SelectChain, SlotData,
};
use sp_consensus_babe::inherents::BabeInherentData;
use sp_consensus_epoch_vrf::inherents::SlotInherentData;
use sp_timestamp::{TimestampInherentData, InherentType as TimestampInherent};
use sp_consensus::import_queue::{Verifier, BasicQueue, CacheKeyId};
use sc_client_api::{
Expand Down Expand Up @@ -672,7 +672,7 @@ impl SlotCompatible for TimeSource {
) -> Result<(TimestampInherent, u64, std::time::Duration), sp_consensus::Error> {
trace!(target: "babe", "extract timestamp");
data.timestamp_inherent_data()
.and_then(|t| data.babe_inherent_data().map(|a| (t, a)))
.and_then(|t| data.slot_inherent_data().map(|a| (t, a)))
.map_err(Into::into)
.map_err(sp_consensus::Error::InherentData)
.map(|(x, y)| (x, y, self.0.lock().0.take().unwrap_or_default()))
Expand Down Expand Up @@ -831,7 +831,7 @@ impl<Block, Client> Verifier<Block> for BabeVerifier<Block, Client> where
// to check that the internally-set timestamp in the inherents
// actually matches the slot set in the seal.
if let Some(inner_body) = body.take() {
inherent_data.babe_replace_inherent_data(slot_number);
inherent_data.slot_replace_inherent_data(slot_number);
let block = Block::new(pre_header.clone(), inner_body);

self.check_inherents(
Expand Down Expand Up @@ -882,9 +882,9 @@ fn register_babe_inherent_data_provider(
slot_duration: u64,
) -> Result<(), sp_consensus::Error> {
debug!(target: "babe", "Registering");
if !inherent_data_providers.has_provider(&sp_consensus_babe::inherents::INHERENT_IDENTIFIER) {
if !inherent_data_providers.has_provider(&sp_consensus_epoch_vrf::inherents::INHERENT_IDENTIFIER) {
inherent_data_providers
.register_provider(sp_consensus_babe::inherents::InherentDataProvider::new(slot_duration))
.register_provider(sp_consensus_epoch_vrf::inherents::InherentDataProvider::new(slot_duration))
.map_err(Into::into)
.map_err(sp_consensus::Error::InherentData)
} else {
Expand Down
8 changes: 4 additions & 4 deletions frame/babe/Cargo.toml → frame/epoch-vrf/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
[package]
name = "pallet-babe"
name = "pallet-epoch-vrf"
version = "2.0.0-dev"
authors = ["Parity Technologies <admin@parity.io>"]
edition = "2018"
license = "GPL-3.0"
homepage = "https://substrate.dev"
repository = "https://github.com/paritytech/substrate/"
description = "Consensus extension module for BABE consensus. Collects on-chain randomness from VRF outputs and manages epoch transitions."
description = "Consensus extension module for VRF-based consensus. Collects on-chain randomness from VRF outputs and manages epoch transitions."

[package.metadata.docs.rs]
targets = ["x86_64-unknown-linux-gnu"]
Expand All @@ -25,7 +25,7 @@ pallet-timestamp = { version = "2.0.0-dev", default-features = false, path = "..
sp-timestamp = { version = "2.0.0-dev", default-features = false, path = "../../primitives/timestamp" }
pallet-session = { version = "2.0.0-dev", default-features = false, path = "../session" }
sp-consensus-babe = { version = "0.8.0-dev", default-features = false, path = "../../primitives/consensus/babe" }
sp-consensus-vrf = { version = "0.8.0-dev", default-features = false, path = "../../primitives/consensus/vrf" }
sp-consensus-epoch-vrf = { version = "0.8.0-dev", default-features = false, path = "../../primitives/consensus/epoch-vrf" }
sp-io = { path = "../../primitives/io", default-features = false , version = "2.0.0-dev"}

[dev-dependencies]
Expand All @@ -46,7 +46,7 @@ std = [
"sp-timestamp/std",
"sp-inherents/std",
"sp-consensus-babe/std",
"sp-consensus-vrf/std",
"sp-consensus-epoch-vrf/std",
"pallet-session/std",
"sp-io/std",
]
Loading