Skip to content
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
1,504 changes: 713 additions & 791 deletions Cargo.lock

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions bin/node/cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ sc-keystore = { version = "4.0.0-dev", path = "../../../client/keystore" }
sc-client-db = { version = "0.10.0-dev", path = "../../../client/db" }
sc-consensus = { version = "0.10.0-dev", path = "../../../client/consensus/common" }
sc-consensus-babe = { version = "0.10.0-dev", path = "../../../client/consensus/babe" }
sc-consensus-epochs = { version = "0.10.0-dev", path = "../../../client/consensus/epochs" }
sc-consensus-sessions = { version = "0.10.0-dev", path = "../../../client/consensus/epochs" }
sc-service-test = { version = "2.0.0", path = "../../../client/service/test" }
sc-block-builder = { version = "0.10.0-dev", path = "../../../client/block-builder" }
sp-tracing = { version = "5.0.0", path = "../../../primitives/tracing" }
Expand All @@ -128,7 +128,7 @@ platforms = "2.0"
async-std = { version = "1.11.0", features = ["attributes"] }
soketto = "0.7.1"
criterion = { version = "0.3.5", features = ["async_tokio"] }
tokio = { version = "1.17.0", features = ["macros", "time", "parking_lot"] }
tokio = { version = "1.18.1", features = ["macros", "time", "parking_lot"] }
wait-timeout = "0.2"
remote-externalities = { path = "../../../utils/frame/remote-externalities" }
pallet-timestamp = { version = "4.0.0-dev", path = "../../../frame/timestamp" }
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 @@ -342,7 +342,7 @@ pub fn testnet_genesis(
sudo: SudoConfig { key: Some(root_key) },
babe: BabeConfig {
authorities: vec![],
epoch_config: Some(node_runtime::BABE_GENESIS_EPOCH_CONFIG),
session_config: Some(node_runtime::BABE_GENESIS_SESSION_CONFIG),
},
im_online: ImOnlineConfig { keys: vec![] },
authority_discovery: AuthorityDiscoveryConfig { keys: vec![] },
Expand Down
28 changes: 14 additions & 14 deletions bin/node/cli/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ pub fn new_partial(
);

let babe_config = babe_link.config().clone();
let shared_epoch_changes = babe_link.epoch_changes().clone();
let shared_session_changes = babe_link.session_changes().clone();

let client = client.clone();
let pool = transaction_pool.clone();
Expand All @@ -262,7 +262,7 @@ pub fn new_partial(
deny_unsafe,
babe: node_rpc::BabeDeps {
babe_config: babe_config.clone(),
shared_epoch_changes: shared_epoch_changes.clone(),
shared_session_changes: shared_session_changes.clone(),
keystore: keystore.clone(),
},
grandpa: node_rpc::GrandpaDeps {
Expand Down Expand Up @@ -573,7 +573,7 @@ mod tests {
use sc_client_api::BlockBackend;
use sc_consensus::{BlockImport, BlockImportParams, ForkChoiceStrategy};
use sc_consensus_babe::{BabeIntermediate, CompatibleDigestItem, INTERMEDIATE_KEY};
use sc_consensus_epochs::descendent_query;
use sc_consensus_sessions::descendent_query;
use sc_keystore::LocalKeystore;
use sc_service_test::TestNetNode;
use sc_transaction_pool_api::{ChainEvent, MaintainedTransactionPool};
Expand Down Expand Up @@ -662,11 +662,11 @@ mod tests {

// even though there's only one authority some slots might be empty,
// so we must keep trying the next slots until we can claim one.
let (babe_pre_digest, epoch_descriptor) = loop {
let epoch_descriptor = babe_link
.epoch_changes()
let (babe_pre_digest, session_descriptor) = loop {
let session_descriptor = babe_link
.session_changes()
.shared_data()
.epoch_descriptor_for_child_of(
.session_descriptor_for_child_of(
descendent_query(&*service.client()),
&parent_hash,
parent_number,
Expand All @@ -675,22 +675,22 @@ mod tests {
.unwrap()
.unwrap();

let epoch = babe_link
.epoch_changes()
let session = babe_link
.session_changes()
.shared_data()
.epoch_data(&epoch_descriptor, |slot| {
sc_consensus_babe::Epoch::genesis(
.session_data(&session_descriptor, |slot| {
sc_consensus_babe::Session::genesis(
babe_link.config().genesis_config(),
slot,
)
})
.unwrap();

if let Some(babe_pre_digest) =
sc_consensus_babe::authorship::claim_slot(slot.into(), &epoch, &keystore)
sc_consensus_babe::authorship::claim_slot(slot.into(), &session, &keystore)
.map(|(digest, _)| digest)
{
break (babe_pre_digest, epoch_descriptor)
break (babe_pre_digest, session_descriptor)
}

slot += 1;
Expand Down Expand Up @@ -740,7 +740,7 @@ mod tests {
params.body = Some(new_body);
params.intermediates.insert(
Cow::from(INTERMEDIATE_KEY),
Box::new(BabeIntermediate::<Block> { epoch_descriptor }) as Box<_>,
Box::new(BabeIntermediate::<Block> { session_descriptor }) as Box<_>,
);
params.fork_choice = Some(ForkChoiceStrategy::LongestChain);

Expand Down
2 changes: 1 addition & 1 deletion bin/node/rpc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ pallet-transaction-payment-rpc = { version = "4.0.0-dev", path = "../../../frame
sc-client-api = { version = "4.0.0-dev", path = "../../../client/api" }
sc-consensus-babe = { version = "0.10.0-dev", path = "../../../client/consensus/babe" }
sc-consensus-babe-rpc = { version = "0.10.0-dev", path = "../../../client/consensus/babe/rpc" }
sc-consensus-epochs = { version = "0.10.0-dev", path = "../../../client/consensus/epochs" }
sc-consensus-sessions = { version = "0.10.0-dev", path = "../../../client/consensus/epochs" }
sc-chain-spec = { version = "4.0.0-dev", path = "../../../client/chain-spec" }
sc-finality-grandpa = { version = "0.10.0-dev", path = "../../../client/finality-grandpa" }
sc-finality-grandpa-rpc = { version = "0.10.0-dev", path = "../../../client/finality-grandpa/rpc" }
Expand Down
14 changes: 7 additions & 7 deletions bin/node/rpc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ use std::sync::Arc;

use node_primitives::{AccountId, Balance, Block, BlockNumber, Hash, Index};
use sc_client_api::AuxStore;
use sc_consensus_babe::{Config, Epoch};
use sc_consensus_babe::{Config, Session};
use sc_consensus_babe_rpc::BabeRpcHandler;
use sc_consensus_epochs::SharedEpochChanges;
use sc_consensus_sessions::SharedSessionChanges;
use sc_finality_grandpa::{
FinalityProofProvider, GrandpaJustificationStream, SharedAuthoritySet, SharedVoterState,
};
Expand All @@ -55,8 +55,8 @@ use sp_keystore::SyncCryptoStorePtr;
pub struct BabeDeps {
/// BABE protocol config.
pub babe_config: Config,
/// BABE pending epoch changes.
pub shared_epoch_changes: SharedEpochChanges<Block, Epoch>,
/// BABE pending session changes.
pub shared_session_changes: SharedSessionChanges<Block, Session>,
/// The keystore that manages the keys of the node.
pub keystore: SyncCryptoStorePtr,
}
Expand Down Expand Up @@ -130,7 +130,7 @@ where
let mut io = jsonrpc_core::IoHandler::default();
let FullDeps { client, pool, select_chain, chain_spec, deny_unsafe, babe, grandpa } = deps;

let BabeDeps { keystore, babe_config, shared_epoch_changes } = babe;
let BabeDeps { keystore, babe_config, shared_session_changes } = babe;
let GrandpaDeps {
shared_voter_state,
shared_authority_set,
Expand All @@ -148,7 +148,7 @@ where
io.extend_with(TransactionPaymentApi::to_delegate(TransactionPayment::new(client.clone())));
io.extend_with(sc_consensus_babe_rpc::BabeApi::to_delegate(BabeRpcHandler::new(
client.clone(),
shared_epoch_changes.clone(),
shared_session_changes.clone(),
keystore,
babe_config,
select_chain,
Expand All @@ -169,7 +169,7 @@ where
chain_spec,
client.clone(),
shared_authority_set,
shared_epoch_changes,
shared_session_changes,
)?,
));
io.extend_with(DevApi::to_delegate(Dev::new(client, deny_unsafe)));
Expand Down
8 changes: 4 additions & 4 deletions bin/node/runtime/src/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,13 @@ pub mod time {
// 1 in 4 blocks (on average, not counting collisions) will be primary BABE blocks.
pub const PRIMARY_PROBABILITY: (u64, u64) = (1, 4);

// NOTE: Currently it is not possible to change the epoch duration after the chain has started.
// NOTE: Currently it is not possible to change the session duration after the chain has started.
// Attempting to do so will brick block production.
pub const EPOCH_DURATION_IN_BLOCKS: BlockNumber = 10 * MINUTES;
pub const EPOCH_DURATION_IN_SLOTS: u64 = {
pub const SESSION_DURATION_IN_BLOCKS: BlockNumber = 10 * MINUTES;
pub const SESSION_DURATION_IN_SLOTS: u64 = {
const SLOT_FILL_RATE: f64 = MILLISECS_PER_BLOCK as f64 / SLOT_DURATION as f64;

(EPOCH_DURATION_IN_BLOCKS as f64 * SLOT_FILL_RATE) as u64
(SESSION_DURATION_IN_BLOCKS as f64 * SLOT_FILL_RATE) as u64
};

// These time units are defined in number of blocks.
Expand Down
38 changes: 19 additions & 19 deletions bin/node/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,9 +129,9 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
state_version: 1,
};

/// The BABE epoch configuration at genesis.
pub const BABE_GENESIS_EPOCH_CONFIG: sp_consensus_babe::BabeEpochConfiguration =
sp_consensus_babe::BabeEpochConfiguration {
/// The BABE session configuration at genesis.
pub const BABE_GENESIS_SESSION_CONFIG: sp_consensus_babe::BabeSessionConfiguration =
sp_consensus_babe::BabeSessionConfiguration {
c: PRIMARY_PROBABILITY,
allowed_slots: sp_consensus_babe::AllowedSlots::PrimaryAndSecondaryPlainSlots,
};
Expand Down Expand Up @@ -369,18 +369,18 @@ impl pallet_preimage::Config for Runtime {
}

parameter_types! {
// NOTE: Currently it is not possible to change the epoch duration after the chain has started.
// NOTE: Currently it is not possible to change the session duration after the chain has started.
// Attempting to do so will brick block production.
pub const EpochDuration: u64 = EPOCH_DURATION_IN_SLOTS;
pub const SessionDuration: u64 = SESSION_DURATION_IN_SLOTS;
pub const ExpectedBlockTime: Moment = MILLISECS_PER_BLOCK;
pub const ReportLongevity: u64 =
BondingDuration::get() as u64 * SessionsPerEra::get() as u64 * EpochDuration::get();
BondingDuration::get() as u64 * SessionsPerEra::get() as u64 * SessionDuration::get();
}

impl pallet_babe::Config for Runtime {
type EpochDuration = EpochDuration;
type SessionDuration = SessionDuration;
type ExpectedBlockTime = ExpectedBlockTime;
type EpochChangeTrigger = pallet_babe::ExternalTrigger;
type SessionChangeTrigger = pallet_babe::ExternalTrigger;
type DisabledValidators = Session;

type KeyOwnerProofSystem = Historical;
Expand Down Expand Up @@ -568,8 +568,8 @@ impl pallet_staking::Config for Runtime {

parameter_types! {
// phase durations. 1/4 of the last session for each.
pub const SignedPhase: u32 = EPOCH_DURATION_IN_BLOCKS / 4;
pub const UnsignedPhase: u32 = EPOCH_DURATION_IN_BLOCKS / 4;
pub const SignedPhase: u32 = SESSION_DURATION_IN_BLOCKS / 4;
pub const UnsignedPhase: u32 = SESSION_DURATION_IN_BLOCKS / 4;

// signed config
pub const SignedRewardBase: Balance = 1 * DOLLARS;
Expand Down Expand Up @@ -1711,24 +1711,24 @@ impl_runtime_apis! {
// <https://research.web3.foundation/en/latest/polkadot/BABE/Babe/#6-practical-results>
sp_consensus_babe::BabeGenesisConfiguration {
slot_duration: Babe::slot_duration(),
epoch_length: EpochDuration::get(),
c: BABE_GENESIS_EPOCH_CONFIG.c,
session_length: SessionDuration::get(),
c: BABE_GENESIS_SESSION_CONFIG.c,
genesis_authorities: Babe::authorities().to_vec(),
randomness: Babe::randomness(),
allowed_slots: BABE_GENESIS_EPOCH_CONFIG.allowed_slots,
allowed_slots: BABE_GENESIS_SESSION_CONFIG.allowed_slots,
}
}

fn current_epoch_start() -> sp_consensus_babe::Slot {
Babe::current_epoch_start()
fn current_session_start() -> sp_consensus_babe::Slot {
Babe::current_session_start()
}

fn current_epoch() -> sp_consensus_babe::Epoch {
Babe::current_epoch()
fn current_session() -> sp_consensus_babe::Session {
Babe::current_session()
}

fn next_epoch() -> sp_consensus_babe::Epoch {
Babe::next_epoch()
fn next_session() -> sp_consensus_babe::Session {
Babe::next_session()
}

fn generate_key_ownership_proof(
Expand Down
4 changes: 2 additions & 2 deletions bin/node/testing/src/genesis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ use crate::keyring::*;
use node_runtime::{
constants::currency::*, wasm_binary_unwrap, AccountId, BabeConfig, BalancesConfig,
GenesisConfig, GrandpaConfig, IndicesConfig, SessionConfig, SocietyConfig, StakerStatus,
StakingConfig, SystemConfig, BABE_GENESIS_EPOCH_CONFIG,
StakingConfig, SystemConfig, BABE_GENESIS_SESSION_CONFIG,
};
use sp_keyring::{Ed25519Keyring, Sr25519Keyring};
use sp_runtime::Perbill;
Expand Down Expand Up @@ -75,7 +75,7 @@ pub fn config_endowed(code: Option<&[u8]>, extra_endowed: Vec<AccountId>) -> Gen
invulnerables: vec![alice(), bob(), charlie()],
..Default::default()
},
babe: BabeConfig { authorities: vec![], epoch_config: Some(BABE_GENESIS_EPOCH_CONFIG) },
babe: BabeConfig { authorities: vec![], session_config: Some(BABE_GENESIS_SESSION_CONFIG) },
grandpa: GrandpaConfig { authorities: vec![] },
im_online: Default::default(),
authority_discovery: Default::default(),
Expand Down
2 changes: 1 addition & 1 deletion client/beefy/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -51,5 +51,5 @@ substrate-test-runtime-client = { version = "2.0.0", path = "../../test-utils/ru

serde = "1.0.136"
strum = { version = "0.23", features = ["derive"] }
tokio = "1.15"
tokio = "1.18"
tempfile = "3.1.0"
2 changes: 1 addition & 1 deletion client/cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ serde = "1.0.136"
serde_json = "1.0.79"
thiserror = "1.0.30"
tiny-bip39 = "0.8.2"
tokio = { version = "1.17.0", features = ["signal", "rt-multi-thread", "parking_lot"] }
tokio = { version = "1.18.1", features = ["signal", "rt-multi-thread", "parking_lot"] }

parity-scale-codec = "3.0.0"
sc-client-api = { version = "4.0.0-dev", path = "../api" }
Expand Down
18 changes: 9 additions & 9 deletions client/consensus/aura/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ pub fn build_aura_worker<P, B, C, PF, I, SO, L, BS, Error>(
SyncOracle = SO,
JustificationSyncLink = L,
Claim = P::Public,
EpochData = Vec<AuthorityId<P>>,
SessionData = Vec<AuthorityId<P>>,
>
where
B: BlockT,
Expand Down Expand Up @@ -337,7 +337,7 @@ where
Pin<Box<dyn Future<Output = Result<E::Proposer, sp_consensus::Error>> + Send + 'static>>;
type Proposer = E::Proposer;
type Claim = P::Public;
type EpochData = Vec<AuthorityId<P>>;
type SessionData = Vec<AuthorityId<P>>;

fn logging_target(&self) -> &'static str {
"aura"
Expand All @@ -347,25 +347,25 @@ where
&mut self.block_import
}

fn epoch_data(
fn session_data(
&self,
header: &B::Header,
_slot: Slot,
) -> Result<Self::EpochData, sp_consensus::Error> {
) -> Result<Self::SessionData, sp_consensus::Error> {
authorities(self.client.as_ref(), &BlockId::Hash(header.hash()))
}

fn authorities_len(&self, epoch_data: &Self::EpochData) -> Option<usize> {
Some(epoch_data.len())
fn authorities_len(&self, session_data: &Self::SessionData) -> Option<usize> {
Some(session_data.len())
}

async fn claim_slot(
&self,
_header: &B::Header,
slot: Slot,
epoch_data: &Self::EpochData,
session_data: &Self::SessionData,
) -> Option<Self::Claim> {
let expected_author = slot_author::<P>(slot, epoch_data);
let expected_author = slot_author::<P>(slot, session_data);
expected_author.and_then(|p| {
if SyncCryptoStore::has_keys(
&*self.keystore,
Expand All @@ -389,7 +389,7 @@ where
body: Vec<B::Extrinsic>,
storage_changes: StorageChanges<<Self::BlockImport as BlockImport<B>>::Transaction, B>,
public: Self::Claim,
_epoch: Self::EpochData,
_session: Self::SessionData,
) -> Result<
sc_consensus::BlockImportParams<B, <Self::BlockImport as BlockImport<B>>::Transaction>,
sp_consensus::Error,
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 @@ -32,7 +32,7 @@ sp-inherents = { version = "4.0.0-dev", path = "../../../primitives/inherents" }
sc-telemetry = { version = "4.0.0-dev", path = "../../telemetry" }
sc-keystore = { version = "4.0.0-dev", path = "../../keystore" }
sc-client-api = { version = "4.0.0-dev", path = "../../api" }
sc-consensus-epochs = { version = "0.10.0-dev", path = "../epochs" }
sc-consensus-sessions = { version = "0.10.0-dev", path = "../epochs" }
sp-api = { version = "4.0.0-dev", path = "../../../primitives/api" }
sp-block-builder = { version = "4.0.0-dev", path = "../../../primitives/block-builder" }
sp-blockchain = { version = "4.0.0-dev", path = "../../../primitives/blockchain" }
Expand Down
12 changes: 6 additions & 6 deletions client/consensus/babe/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ right to produce a block. The proof of the VRF function execution will be
used by other peer to validate the legitimacy of the slot claim.

The engine is also responsible for collecting entropy on-chain which will be
used to seed the given VRF PRNG. An epoch is a contiguous number of slots
under which we will be using the same authority set. During an epoch all VRF
used to seed the given VRF PRNG. An session is a contiguous number of slots
under which we will be using the same authority set. During an session all VRF
outputs produced as a result of block production will be collected on an
on-chain randomness pool. Epoch changes are announced one epoch in advance,
i.e. when ending epoch N, we announce the parameters (randomness,
authorities, etc.) for epoch N+2.
on-chain randomness pool. Session changes are announced one session in advance,
i.e. when ending session N, we announce the parameters (randomness,
authorities, etc.) for session N+2.

Since the slot assignment is randomized, it is possible that a slot is
assigned to multiple validators in which case we will have a temporary fork,
Expand All @@ -31,7 +31,7 @@ authoring the node starts by trying to claim a primary slot and falls back
to a secondary slot claim attempt. The secondary slot assignment is done
by picking the authority at index:

`blake2_256(epoch_randomness ++ slot_number) % authorities_len`.
`blake2_256(session_randomness ++ slot_number) % authorities_len`.

The secondary slots supports either a `SecondaryPlain` or `SecondaryVRF`
variant. Comparing with `SecondaryPlain` variant, the `SecondaryVRF` variant
Expand Down
Loading