Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
103 commits
Select commit Hold shift + click to select a range
81d2237
Draft of new sessions
gavofyork Jun 5, 2019
4fc86da
Reintroduce tuple impls
gavofyork Jun 5, 2019
d24568a
Merge remote-tracking branch 'origin/master' into gav-new-sessions
gavofyork Jun 5, 2019
84f1f1c
Move staking module to new session API
gavofyork Jun 5, 2019
5c67469
More work on staking and grandpa.
gavofyork Jun 5, 2019
5acfa04
Use iterator to avoid cloning and tuple macro
gavofyork Jun 5, 2019
fde708d
Make runtime build again
gavofyork Jun 6, 2019
b9b7d42
Polish the OpaqueKeys devex
gavofyork Jun 6, 2019
445df61
Move consensus logic into system & aura.
gavofyork Jun 6, 2019
4db0062
Fix up system module
gavofyork Jun 6, 2019
6696c55
Get build mostly going. Stuck at service.rs
gavofyork Jun 6, 2019
dc9e8c6
Building again
gavofyork Jun 6, 2019
7da4b04
Update srml/staking/src/lib.rs
gavofyork Jun 7, 2019
e2a0f2e
Refactoring out Consensus module, AuthorityIdOf, &c.
gavofyork Jun 7, 2019
6440ca8
Merge remote-tracking branch 'origin/gav-new-sessions' into gav-new-s…
gavofyork Jun 7, 2019
cfea92a
Refactored out DigestItem::AuthoritiesChanged. Building.
gavofyork Jun 7, 2019
d3de475
Remove tentative code
gavofyork Jun 7, 2019
a061fd7
Remove invalid comment
gavofyork Jun 7, 2019
7f303f9
Make Seal opaque and introduce nice methods for handling opaque items.
gavofyork Jun 7, 2019
a38084d
Merge remote-tracking branch 'origin/master' into gav-new-sessions
gavofyork Jun 7, 2019
f8b24e0
Start to use proper digest for Aura authorities tracking.
gavofyork Jun 8, 2019
fa47974
Fix up grandpa, remove system::Raw/Log
gavofyork Jun 8, 2019
dd93267
Refactor Grandpa to use new logging infrastructure.
gavofyork Jun 8, 2019
7a2b935
Building again
gavofyork Jun 8, 2019
4f9a5a3
Tidy up some AuthorityIds
gavofyork Jun 9, 2019
4871529
Expunge most of the rest of the AuthorityKey confusion.
gavofyork Jun 9, 2019
afeed88
Remove cruft
gavofyork Jun 9, 2019
d1d25e7
Untangle last of the `AuthorityId`s.
gavofyork Jun 9, 2019
bf081a5
Sort out finality_tracker
gavofyork Jun 9, 2019
77ec1ff
Refactor median getting
gavofyork Jun 9, 2019
a02de97
Apply suggestions from code review
Demi-Marie Jun 10, 2019
1cca243
Session tests works
gavofyork Jun 10, 2019
3bbd5ab
Merge remote-tracking branch 'origin/gav-new-sessions' into gav-new-s…
gavofyork Jun 10, 2019
6101aae
Update core/sr-primitives/src/generic/digest.rs
gavofyork Jun 10, 2019
5827ab5
Session tests works
gavofyork Jun 10, 2019
f8fa160
Merge remote-tracking branch 'origin/gav-new-sessions' into gav-new-s…
gavofyork Jun 10, 2019
8a9a4a5
Fix for staking from @dvc94ch
gavofyork Jun 10, 2019
9b4f1a4
log an error
gavofyork Jun 10, 2019
f650fe8
fix test runtime build
gavofyork Jun 10, 2019
ca4dda3
Some test fixes
gavofyork Jun 11, 2019
7b339ef
Fix build.
dvc94ch Jun 11, 2019
730b805
Move OpaqueKeys to primitives.
dvc94ch Jun 11, 2019
8203a7e
Staking mock update to new session api.
dvc94ch Jun 7, 2019
807c284
Use on_initialize instead of check_rotate_session.
dvc94ch Jun 11, 2019
ba4721f
Update tests to new staking api.
dvc94ch Jun 11, 2019
979f3b5
fixup mock
dvc94ch Jun 11, 2019
6e0cf27
Fix bond_extra_and_withdraw_unbonded_works.
dvc94ch Jun 11, 2019
4cafd87
Fix bond_with_little_staked_value_bounded_by_slot_stake.
dvc94ch Jun 11, 2019
4b5bd6b
Fix bond_with_no_staked_value.
dvc94ch Jun 11, 2019
48b0238
Fix change_controller_works.
dvc94ch Jun 11, 2019
379ddc9
Fix less_than_needed_candidates_works.
dvc94ch Jun 11, 2019
7990ce5
Fix multi_era_reward_should_work.
dvc94ch Jun 11, 2019
f3e7f97
Fix nominating_and_rewards_should_work.
dvc94ch Jun 11, 2019
94e58de
Fix nominators_also_get_slashed.
dvc94ch Jun 11, 2019
5404cbf
Fix phragmen_large_scale_test.
dvc94ch Jun 11, 2019
ff246dd
Fix phragmen_poc_works.
dvc94ch Jun 11, 2019
93843f9
Fix phragmen_score_should_be_accurate_on_large_stakes.
dvc94ch Jun 11, 2019
5cc1c44
Fix phragmen_should_not_overflow.
dvc94ch Jun 11, 2019
cfa5237
Fix reward_destination_works.
dvc94ch Jun 11, 2019
d90ffdc
Fix rewards_should_work.
dvc94ch Jun 11, 2019
8692b16
Fix sessions_and_eras_should_work.
dvc94ch Jun 11, 2019
5f1ad03
Fix slot_stake_is_least_staked_validator.
dvc94ch Jun 11, 2019
82946f5
Fix too_many_unbond_calls_should_not_work.
dvc94ch Jun 11, 2019
6b6acd5
Fix wrong_vote_is_null.
dvc94ch Jun 11, 2019
1822167
Fix runtime.
dvc94ch Jun 11, 2019
e87be9d
Fix wasm runtime build.
dvc94ch Jun 11, 2019
5f110d8
Update Cargo.lock
dvc94ch Jun 11, 2019
a5866a6
Fix warnings.
dvc94ch Jun 11, 2019
0378cff
Fix grandpa tests.
dvc94ch Jun 11, 2019
3f4b234
Fix test-runtime build.
dvc94ch Jun 11, 2019
71014e3
Fix template node build.
dvc94ch Jun 11, 2019
a97f98d
Fix stuff.
dvc94ch Jun 11, 2019
a75d3ad
Update Cargo.lock to fix CI
Demi-Marie Jun 11, 2019
3fb729b
Merge branch 'master' into gav-new-sessions
Demi-Marie Jun 12, 2019
cbd8437
Re-add missing AuRa logs
Demi-Marie Jun 12, 2019
99e58a7
Merge remote-tracking branch 'origin/master' into gav-new-sessions
gavofyork Jun 12, 2019
b8f6500
Update core/consensus/babe/src/digest.rs
gavofyork Jun 12, 2019
8c15101
Kill log trait and all that jazz.
gavofyork Jun 12, 2019
24d175c
Merge remote-tracking branch 'origin/gav-new-sessions' into gav-new-s…
gavofyork Jun 12, 2019
aa0956a
Refactor staking tests.
dvc94ch Jun 12, 2019
f788794
Fix ci runtime wasm check.
dvc94ch Jun 12, 2019
91a0495
Line length 120.
dvc94ch Jun 12, 2019
0399856
Make tests build again
gavofyork Jun 12, 2019
6ef0cb9
Merge remote-tracking branch 'origin/gav-new-sessions' into gav-new-s…
gavofyork Jun 12, 2019
b777ba9
Remove trailing commas in function declarations
Demi-Marie Jun 12, 2019
df313e0
Fix type error
Demi-Marie Jun 12, 2019
26f4a2d
Merge remote-tracking branch 'origin/master' into gav-new-sessions
Demi-Marie Jun 12, 2019
988e94d
Fix compilation errors
Demi-Marie Jun 12, 2019
ae7cc46
Fix a test
gavofyork Jun 13, 2019
f82c155
Another couple of fixes
gavofyork Jun 13, 2019
f8af78d
Fix another test
gavofyork Jun 13, 2019
ea77d7d
More test fixes
gavofyork Jun 13, 2019
b6a5548
Another test fix
gavofyork Jun 13, 2019
bb19f0b
Merge branch 'master' into gav-new-sessions
gavofyork Jun 13, 2019
3fcb3a7
Bump runtime.
gavofyork Jun 13, 2019
03249cd
Wrap long line
gavofyork Jun 13, 2019
56f5ac1
Fix build, remove redundant code.
gavofyork Jun 13, 2019
db47886
Issue to track TODO
gavofyork Jun 13, 2019
6b44e5f
Leave the benchmark code alone.
gavofyork Jun 13, 2019
2e8c85f
Merge remote-tracking branch 'origin/master' into gav-new-sessions
gavofyork Jun 13, 2019
5beee4b
Fix missing `std::time::{Instant, Duration}`
Demi-Marie Jun 13, 2019
3ee9625
Indentation
gavofyork Jun 14, 2019
0ad33b9
Aura ConsensusLog as enum
gavofyork Jun 14, 2019
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
Prev Previous commit
Next Next commit
Fix up grandpa, remove system::Raw/Log
  • Loading branch information
gavofyork committed Jun 8, 2019
commit fa47974be925288c7e651f7f5d762970733684ab
16 changes: 7 additions & 9 deletions core/consensus/babe/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ pub use digest::{BabePreDigest, BABE_VRF_PREFIX};
pub use babe_primitives::*;
pub use consensus_common::SyncOracle;
use consensus_common::{ExtraVerification, well_known_cache_keys::Id as CacheKeyId};
use runtime_primitives::{generic, generic::BlockId, Justification};
use runtime_primitives::{generic, generic::{BlockId, OpaqueDigestItemId}, Justification};
use runtime_primitives::traits::{
Block, Header, Digest, DigestItemFor, DigestItem, ProvideRuntimeApi,
SimpleBitOps,
Expand Down Expand Up @@ -645,14 +645,12 @@ impl<B: Block, C, E> Verifier<B> for BabeVerifier<C, E> where

extra_verification.into_future().wait()?;

let maybe_keys = None;
/* TODO: make this work:
pre_header.digest()
.log(DigestItem::as_authorities_change)
.map(|digest| digest.to_vec())
.map(Encode::encode)
.map(|blob| vec![(well_known_cache_keys::AUTHORITIES, blob)]);
*/
// `Consensus` is the Babe-specific authorities change log.
// It's an encoded `Vec<AuthorityId>`, the same format as is stored in the cache,
// so no need to decode/re-encode.
let maybe_keys = pre_header.digest()
.log(|l| l.try_as_raw(OpaqueDigestItemId::Consensus(&BABE_ENGINE_ID)))
.map(|blob| vec![(well_known_cache_keys::AUTHORITIES, blob.to_vec())]);

let import_block = ImportBlock {
origin,
Expand Down
5 changes: 2 additions & 3 deletions node-template/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,6 @@ impl system::Trait for Runtime {

impl aura::Trait for Runtime {
type HandleReport = ();
type Log = Log;
}

impl indices::Trait for Runtime {
Expand Down Expand Up @@ -187,9 +186,9 @@ construct_runtime!(
NodeBlock = opaque::Block,
UncheckedExtrinsic = UncheckedExtrinsic
{
System: system::{default, Log(ChangesTrieRoot)},
System: system::{default, Config<T>},
Timestamp: timestamp::{Module, Call, Storage, Config<T>, Inherent},
Aura: aura::{Module, Config<T>, Inherent(Timestamp), Log(PreRuntime)},
Aura: aura::{Module, Config<T>, Inherent(Timestamp)},
Indices: indices::{default, Config<T>},
Balances: balances,
Sudo: sudo,
Expand Down
7 changes: 2 additions & 5 deletions node/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,6 @@ impl system::Trait for Runtime {

impl aura::Trait for Runtime {
type HandleReport = aura::StakingSlasher<Runtime>;
type Log = Log;
}

impl indices::Trait for Runtime {
Expand Down Expand Up @@ -254,8 +253,8 @@ construct_runtime!(
NodeBlock = node_primitives::Block,
UncheckedExtrinsic = UncheckedExtrinsic
{
System: system::{default, Config<T>, Log(ChangesTrieRoot)},
Aura: aura::{Module, Config<T>, Inherent(Timestamp), Log(PreRuntime)},
System: system::{default, Config<T>},
Aura: aura::{Module, Config<T>, Inherent(Timestamp)},
Timestamp: timestamp::{Module, Call, Storage, Config<T>, Inherent},
Indices: indices,
Balances: balances,
Expand Down Expand Up @@ -351,7 +350,6 @@ impl_runtime_apis! {
{
for log in digest.logs.iter().filter_map(|l| match l {
Log(InternalLog::grandpa(grandpa_signal)) => Some(grandpa_signal),
_ => None
}) {
if let Some(change) = Grandpa::scrape_digest_change(log) {
return Some(change);
Expand All @@ -365,7 +363,6 @@ impl_runtime_apis! {
{
for log in digest.logs.iter().filter_map(|l| match l {
Log(InternalLog::grandpa(grandpa_signal)) => Some(grandpa_signal),
_ => None
}) {
if let Some(change) = Grandpa::scrape_digest_forced_change(log) {
return Some(change);
Expand Down
52 changes: 7 additions & 45 deletions srml/aura/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ use rstd::{result, prelude::*};
use parity_codec::{Encode, Decode};
use srml_support::storage::StorageValue;
use srml_support::{decl_storage, decl_module};
use primitives::traits::{SaturatedConversion, Saturating, Zero, One};
use primitives::{traits::{SaturatedConversion, Saturating, Zero, One, Digest}, generic::DigestItem};
use timestamp::OnTimestampSet;
use rstd::marker::PhantomData;
#[cfg(feature = "std")]
Expand All @@ -65,6 +65,7 @@ use inherents::{InherentDataProviders, ProvideInherentData};
#[cfg(feature = "std")]
use serde::Serialize;
pub use substrate_consensus_aura_primitives::AuthorityId;
use substrate_consensus_aura_primitives::AURA_ENGINE_ID;

mod mock;
mod tests;
Expand Down Expand Up @@ -94,45 +95,6 @@ impl AuraInherentData for InherentData {
}
}

/// Logs in this module.
pub type Log<T> = RawLog<T>;

/// Logs in this module.
///
/// The type parameter distinguishes logs belonging to two different runtimes,
/// which should not be mixed.
#[cfg_attr(feature = "std", derive(Serialize, Debug))]
#[derive(Encode, Decode, PartialEq, Eq, Clone)]
pub enum RawLog<T> {
/// AuRa inherent digests
PreRuntime([u8; 4], Vec<u8>, PhantomData<T>),
/// Authorities set has been changed. Contains the new set of authorities.
AuthoritiesChange(Vec<AuthorityId>),
}

impl<T> RawLog<T> {
/// Try to cast the log entry as AuthoritiesChange log entry.
pub fn as_authorities_change(&self) -> Option<&[AuthorityId]> {
match *self {
RawLog::AuthoritiesChange(ref item) => Some(item),
_ => None,
}
}
}

// Implementation for tests outside of this crate.
#[cfg(any(feature = "std", test))]
impl<N> From<RawLog<N>> for primitives::testing::DigestItem where N: Into<AuthorityId> {
fn from(log: RawLog<N>) -> primitives::testing::DigestItem {
match log {
RawLog::AuthoritiesChange(authorities) =>
primitives::generic::DigestItem::Consensus(*b"aura", authorities.encode()),
RawLog::PreRuntime(id, v, _) =>
primitives::generic::DigestItem::PreRuntime(id, v),
}
}
}

/// Provides the slot duration inherent data for `Aura`.
#[cfg(feature = "std")]
pub struct InherentDataProvider {
Expand Down Expand Up @@ -190,9 +152,6 @@ impl HandleReport for () {
}

pub trait Trait: timestamp::Trait {
/// Type for all log entries of this module.
type Log: From<Log<Self>> + Into<system::DigestItemOf<Self>>;

/// The logic for handling reports.
type HandleReport: HandleReport;
}
Expand All @@ -215,11 +174,14 @@ impl<T: Trait> Module<T> {
fn change_authorities(new: Vec<AuthorityId>) {
<Authorities<T>>::put(&new);

let log: DigestItem<T::Hash> = DigestItem::Consensus(AURA_ENGINE_ID, new.encode());
//Self::deposit_log();
<system::Module<T>>::deposit_log(log.into());
}

/// Deposit one of this module's logs.
fn deposit_log(log: Log<T>) {
<system::Module<T>>::deposit_log(<T as Trait>::Log::from(log).into());
fn deposit_log<L>(log: L) where <<T as system::Trait>::Digest as Digest>::Item: From<L> {
<system::Module<T>>::deposit_log(log.into());
}
}

Expand Down
22 changes: 10 additions & 12 deletions srml/grandpa/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,15 @@ pub use substrate_finality_grandpa_primitives as fg_primitives;
#[cfg(feature = "std")]
use serde::Serialize;
use rstd::prelude::*;
use parity_codec as codec;
use codec::{Encode, Decode};
use fg_primitives::ScheduledChange;
use srml_support::{Parameter, decl_event, decl_storage, decl_module};
use srml_support::{dispatch::Result};
use srml_support::storage::StorageValue;
use srml_support::storage::unhashed::StorageVec;
use primitives::traits::CurrentHeight;
use parity_codec::{self as codec, Encode, Decode};
use substrate_primitives::ed25519;
use srml_support::{
Parameter, decl_event, decl_storage, decl_module, dispatch::Result,
storage::{StorageValue, unhashed::StorageVec}
};
use primitives::traits::{self, CurrentHeight, MaybeSerializeDebug};
use fg_primitives::ScheduledChange;
use system::ensure_signed;
use primitives::traits::MaybeSerializeDebug;

// TODO: switch to import from aura primitives.
use ed25519::Public as AuthorityId;
Expand Down Expand Up @@ -127,10 +125,10 @@ impl<N, SessionKey> GrandpaChangeSignal<N> for RawLog<N, SessionKey>
}

pub trait Trait: system::Trait {
/// Type for all log entries of this module.
type Log: From<Log<Self>> + Into<system::DigestItemOf<Self>>;
/// Overarching log type that can convert from/into log entries of this module.
type Log: traits::DigestItem<Hash=Self::Hash> + Into<<Self as system::Trait>::Log> + From<Log<Self>>;

/// The session key type used by authorities.
/// The key type used by Grandpa authorities to sign grandpa stuff.
type SessionKey: Parameter + Default + MaybeSerializeDebug;

/// The event type of this module.
Expand Down
46 changes: 7 additions & 39 deletions srml/system/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,10 @@ use serde::Serialize;
use rstd::prelude::*;
#[cfg(any(feature = "std", test))]
use rstd::map;
use primitives::traits::{self, CheckEqual, SimpleArithmetic, SimpleBitOps, One, Bounded, Lookup,
use primitives::{generic::DigestItem, traits::{self, CheckEqual, SimpleArithmetic, SimpleBitOps,
Hash, Member, MaybeDisplay, EnsureOrigin, Digest as DigestT, CurrentHeight, BlockNumberToHash,
MaybeSerializeDebugButNotDeserialize, MaybeSerializeDebug, StaticLookup
};
MaybeSerializeDebugButNotDeserialize, MaybeSerializeDebug, StaticLookup, One, Bounded, Lookup,
}};
#[cfg(any(feature = "std", test))]
use primitives::traits::Zero;
use substrate_primitives::storage::well_known_keys;
Expand Down Expand Up @@ -168,7 +168,7 @@ pub trait Trait: 'static + Eq + Clone {

/// Collection of (light-client-relevant) logs for a block to be included verbatim in the block header.
type Digest:
Parameter + Member + MaybeSerializeDebugButNotDeserialize + Default + traits::Digest<Hash = Self::Hash>;
Parameter + Member + MaybeSerializeDebugButNotDeserialize + Default + traits::Digest<Hash=Self::Hash, Item=Self::Log>;

/// The user account identifier type for the runtime.
type AccountId: Parameter + Member + MaybeSerializeDebug + MaybeDisplay + Ord + Default;
Expand All @@ -191,7 +191,7 @@ pub trait Trait: 'static + Eq + Clone {
type Event: Parameter + Member + From<Event>;

/// A piece of information that can be part of the digest (as a digest item).
type Log: From<Log<Self>> + Into<DigestItemOf<Self>>;
type Log: traits::DigestItem<Hash=Self::Hash> + From<DigestItem<Self::Hash>>;
}

pub type DigestItemOf<T> = <<T as Trait>::Digest as traits::Digest>::Item;
Expand Down Expand Up @@ -295,38 +295,6 @@ impl<AccountId> From<Option<AccountId>> for RawOrigin<AccountId> {
/// Exposed trait-generic origin type.
pub type Origin<T> = RawOrigin<<T as Trait>::AccountId>;

pub type Log<T> = RawLog<
<T as Trait>::Hash,
>;

/// A log in this module.
#[cfg_attr(feature = "std", derive(Serialize, Debug))]
#[derive(Encode, Decode, PartialEq, Eq, Clone)]
pub enum RawLog<Hash> {
/// Changes trie has been computed for this block. Contains the root of
/// changes trie.
ChangesTrieRoot(Hash),
}

impl<Hash: Member> RawLog<Hash> {
/// Try to cast the log entry as ChangesTrieRoot log entry.
pub fn as_changes_trie_root(&self) -> Option<&Hash> {
match *self {
RawLog::ChangesTrieRoot(ref item) => Some(item),
}
}
}

// Implementation for tests outside of this crate.
#[cfg(any(feature = "std", test))]
impl From<RawLog<substrate_primitives::H256>> for primitives::testing::DigestItem {
fn from(log: RawLog<substrate_primitives::H256>) -> primitives::testing::DigestItem {
match log {
RawLog::ChangesTrieRoot(root) => primitives::generic::DigestItem::ChangesTrieRoot(root),
}
}
}

// Create a Hash with 69 for each byte,
// only used to build genesis config.
#[cfg(feature = "std")]
Expand Down Expand Up @@ -611,8 +579,8 @@ impl<T: Trait> Module<T> {
// we can't compute changes trie root earlier && put it to the Digest
// because it will include all currently existing temporaries.
if let Some(storage_changes_root) = storage_changes_root {
let item = RawLog::ChangesTrieRoot(storage_changes_root);
let item = <T as Trait>::Log::from(item).into();
let item = DigestItem::ChangesTrieRoot(storage_changes_root);
let item = <T as Trait>::Log::from(item);
digest.push(item);
}

Expand Down