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
Refactored out DigestItem::AuthoritiesChanged. Building.
  • Loading branch information
gavofyork committed Jun 7, 2019
commit cfea92a2f49005552f8f057c978e660bda5e0d75
6 changes: 5 additions & 1 deletion core/consensus/aura/primitives/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
use parity_codec::Codec;
use substrate_client::decl_runtime_apis;
use substrate_primitives::ed25519;
use runtime_primitives::ConsensusEngineId;
use runtime_primitives::{ConsensusEngineId, traits::DigestFor};

/// The `ConsensusEngineId` of AuRa.
pub const AURA_ENGINE_ID: ConsensusEngineId = [b'a', b'u', b'r', b'a'];
Expand All @@ -32,6 +32,10 @@ pub type AuthorityId = ed25519::Public;
decl_runtime_apis! {
/// API necessary for block authorship with aura.
pub trait AuraApi<AuthorityId: Codec> {
/// Returns the new authorities set, if it changed in this block according to the digest.
fn authorities_change(digest: &DigestFor<Block>)
-> Option<Vec<AuthorityId>>;

/// Return the slot duration in seconds for Aura.
/// Currently, only the value provided by this type at genesis
/// will be used.
Expand Down
2 changes: 1 addition & 1 deletion core/consensus/aura/src/digest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ pub trait CompatibleDigestItem<T: Pair>: Sized {
fn as_aura_pre_digest(&self) -> Option<u64>;
}

impl<P, Hash> CompatibleDigestItem<P> for DigestItem<Hash, P::Public, P::Signature>
impl<P, Hash> CompatibleDigestItem<P> for DigestItem<Hash, P::Signature>
where P: Pair, P::Signature: Clone + Encode + Decode,
{
fn aura_seal(signature: Signature<P>) -> Self {
Expand Down
21 changes: 11 additions & 10 deletions core/consensus/aura/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,15 +142,15 @@ pub fn start_aura<B, C, SC, E, I, P, SO, Error, H>(
C: ProvideRuntimeApi + ProvideCache<B> + AuxStore + Send + Sync,
C::Api: AuraApi<B, AuthorityId<P>>,
SC: SelectChain<B>,
generic::DigestItem<B::Hash, P::Public, P::Signature>: DigestItem<Hash=B::Hash>,
generic::DigestItem<B::Hash, P::Signature>: DigestItem<Hash=B::Hash>,
E::Proposer: Proposer<B, Error=Error>,
<<E::Proposer as Proposer<B>>::Create as IntoFuture>::Future: Send + 'static,
P: Pair + Send + Sync + 'static,
P::Public: Hash + Member + Encode + Decode,
P::Signature: Hash + Member + Encode + Decode,
DigestItemFor<B>: CompatibleDigestItem<P> + DigestItem<AuthorityId=AuthorityId<P>>,
DigestItemFor<B>: CompatibleDigestItem<P>,
H: Header<
Digest=generic::Digest<generic::DigestItem<B::Hash, P::Public, P::Signature>>,
Digest=generic::Digest<generic::DigestItem<B::Hash, P::Signature>>,
Hash=B::Hash,
>,
E: Environment<B, Error=Error>,
Expand Down Expand Up @@ -196,15 +196,15 @@ impl<H, B, C, E, I, P, Error, SO> SlotWorker<B> for AuraWorker<C, E, I, P, SO> w
E::Proposer: Proposer<B, Error=Error>,
<<E::Proposer as Proposer<B>>::Create as IntoFuture>::Future: Send + 'static,
H: Header<
Digest=generic::Digest<generic::DigestItem<B::Hash, P::Public, P::Signature>>,
Digest=generic::Digest<generic::DigestItem<B::Hash, P::Signature>>,
Hash=B::Hash,
>,
I: BlockImport<B> + Send + Sync + 'static,
P: Pair + Send + Sync + 'static,
P::Public: Member + Encode + Decode + Hash,
P::Signature: Member + Encode + Decode + Hash + Debug,
SO: SyncOracle + Send + Clone,
DigestItemFor<B>: CompatibleDigestItem<P> + DigestItem<AuthorityId=AuthorityId<P>, Hash=B::Hash>,
DigestItemFor<B>: CompatibleDigestItem<P> + DigestItem<Hash=B::Hash>,
Error: ::std::error::Error + Send + From<::consensus_common::Error> + From<I::Error> + 'static,
{
type OnSlot = Box<dyn Future<Item=(), Error=consensus_common::Error> + Send>;
Expand Down Expand Up @@ -259,7 +259,7 @@ impl<H, B, C, E, I, P, Error, SO> SlotWorker<B> for AuraWorker<C, E, I, P, SO> w
);

// we are the slot author. make a block and sign it.
let proposer = match env.init(&chain_head, &authorities) {
let proposer = match env.init(&chain_head) {
Ok(p) => p,
Err(e) => {
warn!("Unable to author block in slot {:?}: {:?}", slot_num, e);
Expand Down Expand Up @@ -523,7 +523,7 @@ impl<B: Block> ExtraVerification<B> for NothingExtra {
impl<B: Block, C, E, P> Verifier<B> for AuraVerifier<C, E, P> where
C: ProvideRuntimeApi + Send + Sync + client::backend::AuxStore + ProvideCache<B>,
C::Api: BlockBuilderApi<B> + AuraApi<B, AuthorityId<P>>,
DigestItemFor<B>: CompatibleDigestItem<P> + DigestItem<AuthorityId=AuthorityId<P>>,
DigestItemFor<B>: CompatibleDigestItem<P>,
E: ExtraVerification<B>,
P: Pair + Send + Sync + 'static,
P::Public: Send + Sync + Hash + Eq + Clone + Decode + Encode + Debug + AsRef<P::Public> + 'static,
Expand Down Expand Up @@ -591,11 +591,12 @@ impl<B: Block, C, E, P> Verifier<B> for AuraVerifier<C, E, P> where

extra_verification.into_future().wait()?;

let maybe_keys = pre_header.digest()
// TODO: make this work with the Aura-specific authorities change log.
let maybe_keys = None;/*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)]);
.map(|blob| vec![(well_known_cache_keys::AUTHORITIES, blob)]);*/

let import_block = ImportBlock {
origin,
Expand Down Expand Up @@ -703,7 +704,7 @@ pub fn import_queue<B, C, E, P>(
B: Block,
C: 'static + ProvideRuntimeApi + ProvideCache<B> + Send + Sync + AuxStore,
C::Api: BlockBuilderApi<B> + AuraApi<B, AuthorityId<P>>,
DigestItemFor<B>: CompatibleDigestItem<P> + DigestItem<AuthorityId=AuthorityId<P>>,
DigestItemFor<B>: CompatibleDigestItem<P>,
E: 'static + ExtraVerification<B>,
P: Pair + Send + Sync + 'static,
P::Public: Clone + Eq + Send + Sync + Hash + Debug + Encode + Decode + AsRef<P::Public>,
Expand Down
6 changes: 3 additions & 3 deletions core/consensus/babe/src/digest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ pub trait CompatibleDigestItem: Sized {
fn as_babe_seal(&self) -> Option<Signature>;
}

impl<Hash: Debug> CompatibleDigestItem for DigestItem<Hash, Public, Vec<u8>>
impl<Hash: Debug> CompatibleDigestItem for DigestItem<Hash, Vec<u8>>
{
fn babe_pre_digest(digest: BabePreDigest) -> Self {
DigestItem::PreRuntime(BABE_ENGINE_ID, digest.encode())
Expand Down Expand Up @@ -123,7 +123,7 @@ impl<Hash: Debug> CompatibleDigestItem for DigestItem<Hash, Public, Vec<u8>>
}
}

impl<Hash: Debug> CompatibleDigestItem for DigestItem<Hash, Public, Signature>
impl<Hash: Debug> CompatibleDigestItem for DigestItem<Hash, Signature>
{
fn babe_pre_digest(digest: BabePreDigest) -> Self {
DigestItem::PreRuntime(BABE_ENGINE_ID, digest.encode())
Expand All @@ -146,4 +146,4 @@ impl<Hash: Debug> CompatibleDigestItem for DigestItem<Hash, Public, Signature>
_ => None,
}
}
}
}
17 changes: 10 additions & 7 deletions core/consensus/babe/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -183,12 +183,12 @@ pub fn start_babe<B, C, SC, E, I, SO, Error, H>(BabeParams {
C: ProvideRuntimeApi + ProvideCache<B>,
C::Api: BabeApi<B, Public>,
SC: SelectChain<B>,
generic::DigestItem<B::Hash, Public, Signature>: DigestItem<Hash=B::Hash>,
generic::DigestItem<B::Hash, Signature>: DigestItem<Hash=B::Hash>,
E::Proposer: Proposer<B, Error=Error>,
<<E::Proposer as Proposer<B>>::Create as IntoFuture>::Future: Send + 'static,
DigestItemFor<B>: CompatibleDigestItem + DigestItem<AuthorityId=Public>,
DigestItemFor<B>: CompatibleDigestItem,
H: Header<
Digest=generic::Digest<generic::DigestItem<B::Hash, Public, Signature>>,
Digest=generic::Digest<generic::DigestItem<B::Hash, Signature>>,
Hash=B::Hash,
>,
E: Environment<B, Error=Error>,
Expand Down Expand Up @@ -236,7 +236,7 @@ impl<Hash, H, B, C, E, I, Error, SO> SlotWorker<B> for BabeWorker<C, E, I, SO> w
for<'de> Deserialize<'de> + Debug + Default + AsRef<[u8]> + AsMut<[u8]> +
std::hash::Hash + Display + Send + Sync + 'static,
H: Header<
Digest=generic::Digest<generic::DigestItem<B::Hash, Public, Signature>>,
Digest=generic::Digest<generic::DigestItem<B::Hash, Signature>>,
Hash=B::Hash,
>,
I: BlockImport<B> + Send + Sync + 'static,
Expand Down Expand Up @@ -304,7 +304,7 @@ impl<Hash, H, B, C, E, I, Error, SO> SlotWorker<B> for BabeWorker<C, E, I, SO> w
);

// we are the slot author. make a block and sign it.
let proposer = match env.init(&chain_head, &authorities) {
let proposer = match env.init(&chain_head) {
Ok(p) => p,
Err(e) => {
warn!(target: "babe", "Unable to author block in slot {:?}: {:?}", slot_num, e);
Expand Down Expand Up @@ -568,7 +568,7 @@ impl<B: Block> ExtraVerification<B> for NothingExtra {
impl<B: Block, C, E> Verifier<B> for BabeVerifier<C, E> where
C: ProvideRuntimeApi + Send + Sync + AuxStore + ProvideCache<B>,
C::Api: BlockBuilderApi<B> + BabeApi<B, Public>,
DigestItemFor<B>: CompatibleDigestItem + DigestItem<AuthorityId=Public>,
DigestItemFor<B>: CompatibleDigestItem,// + DigestItem<AuthorityId=Public>,
E: ExtraVerification<B>,
{
fn verify(
Expand Down Expand Up @@ -645,11 +645,14 @@ impl<B: Block, C, E> Verifier<B> for BabeVerifier<C, E> where

extra_verification.into_future().wait()?;

let maybe_keys = pre_header.digest()
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)]);
*/

let import_block = ImportBlock {
origin,
Expand Down
15 changes: 9 additions & 6 deletions core/network/src/test/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ use consensus::import_queue::{
Link, SharedBlockImport, SharedJustificationImport, Verifier, SharedFinalityProofImport,
SharedFinalityProofRequestBuilder,
};
use consensus::{Error as ConsensusError};
use consensus::{Error as ConsensusError, well_known_cache_keys::Id as CacheKeyId};
use consensus::{BlockOrigin, ForkChoiceStrategy, ImportBlock, JustificationImport};
use crate::consensus_gossip::{ConsensusGossip, MessageRecipient as GossipMessageRecipient, TopicNotification};
use futures::{prelude::*, sync::{mpsc, oneshot}};
Expand All @@ -47,7 +47,7 @@ use parking_lot::{Mutex, RwLock};
use primitives::{H256, Blake2Hasher};
use crate::protocol::{Context, Protocol, ProtocolConfig, ProtocolStatus, CustomMessageOutcome, NetworkOut};
use runtime_primitives::generic::BlockId;
use runtime_primitives::traits::{Block as BlockT, Digest, DigestItem, Header, NumberFor};
use runtime_primitives::traits::{Block as BlockT, Digest, Header, NumberFor};
use runtime_primitives::{Justification, ConsensusEngineId};
use crate::service::{NetworkLink, NetworkMsg, ProtocolMsg, TransactionPool};
use crate::specialization::NetworkSpecialization;
Expand All @@ -73,9 +73,12 @@ impl<B: BlockT> Verifier<B> for PassThroughVerifier {
header: B::Header,
justification: Option<Justification>,
body: Option<Vec<B::Extrinsic>>
) -> Result<(ImportBlock<B>, Option<Vec<AuthorityId>>), String> {
let new_authorities = header.digest().log(DigestItem::as_authorities_change)
.map(|auth| auth.iter().cloned().collect());
) -> Result<(ImportBlock<B>, Option<Vec<(CacheKeyId, Vec<u8>)>>), String> {
/* let new_authorities = header.digest().log(DigestItem::as_authorities_change)
.map(|auth| auth.iter().cloned().collect());*/
// TODO: should grab the new authorities from the digest (if any) and put in the new cache
// key that the consensus algo expects.
let maybe_keys = None;

Ok((ImportBlock {
origin,
Expand All @@ -86,7 +89,7 @@ impl<B: BlockT> Verifier<B> for PassThroughVerifier {
post_digests: vec![],
auxiliary: Vec::new(),
fork_choice: ForkChoiceStrategy::LongestChain,
}, new_authorities))
}, maybe_keys))
}
}

Expand Down
51 changes: 11 additions & 40 deletions core/sr-primitives/src/generic/digest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,7 @@ impl<Item> traits::Digest for Digest<Item> where
/// provide opaque access to other items.
#[derive(PartialEq, Eq, Clone)]
#[cfg_attr(feature = "std", derive(Debug))]
pub enum DigestItem<Hash, AuthorityId, SealSignature> {
/// System digest item announcing that authorities set has been changed
/// in the block. Contains the new set of authorities.
AuthoritiesChange(Vec<AuthorityId>),
pub enum DigestItem<Hash, SealSignature> {
/// System digest item that contains the root of changes trie at given
/// block. It is created for every block iff runtime supports changes
/// trie creation.
Expand All @@ -89,7 +86,7 @@ pub enum DigestItem<Hash, AuthorityId, SealSignature> {
}

#[cfg(feature = "std")]
impl<Hash: Encode, AuthorityId: Encode, SealSignature: Encode> ::serde::Serialize for DigestItem<Hash, AuthorityId, SealSignature> {
impl<Hash: Encode, SealSignature: Encode> ::serde::Serialize for DigestItem<Hash, SealSignature> {
fn serialize<S>(&self, seq: S) -> Result<S::Ok, S::Error> where S: ::serde::Serializer {
self.using_encoded(|bytes| {
::substrate_primitives::bytes::serialize(bytes, seq)
Expand All @@ -102,9 +99,7 @@ impl<Hash: Encode, AuthorityId: Encode, SealSignature: Encode> ::serde::Serializ
/// final runtime implementations for encoding/decoding its log items.
#[derive(PartialEq, Eq, Clone)]
#[cfg_attr(feature = "std", derive(Debug))]
pub enum DigestItemRef<'a, Hash: 'a, AuthorityId: 'a, SealSignature: 'a> {
/// Reference to `DigestItem::AuthoritiesChange`.
AuthoritiesChange(&'a [AuthorityId]),
pub enum DigestItemRef<'a, Hash: 'a, SealSignature: 'a> {
/// Reference to `DigestItem::ChangesTrieRoot`.
ChangesTrieRoot(&'a Hash),
/// A message from the runtime to the consensus engine. This should *never*
Expand Down Expand Up @@ -133,14 +128,13 @@ pub enum DigestItemRef<'a, Hash: 'a, AuthorityId: 'a, SealSignature: 'a> {
#[derive(Encode, Decode)]
enum DigestItemType {
Other = 0,
AuthoritiesChange = 1,
ChangesTrieRoot = 2,
Consensus = 4,
Seal = 5,
PreRuntime = 6,
}

impl<Hash, AuthorityId, SealSignature> DigestItem<Hash, AuthorityId, SealSignature> {
impl<Hash, SealSignature> DigestItem<Hash, SealSignature> {
/// Returns Some if `self` is a `DigestItem::Other`.
pub fn as_other(&self) -> Option<&Vec<u8>> {
match *self {
Expand All @@ -150,9 +144,8 @@ impl<Hash, AuthorityId, SealSignature> DigestItem<Hash, AuthorityId, SealSignatu
}

/// Returns a 'referencing view' for this digest item.
fn dref<'a>(&'a self) -> DigestItemRef<'a, Hash, AuthorityId, SealSignature> {
fn dref<'a>(&'a self) -> DigestItemRef<'a, Hash, SealSignature> {
match *self {
DigestItem::AuthoritiesChange(ref v) => DigestItemRef::AuthoritiesChange(v),
DigestItem::ChangesTrieRoot(ref v) => DigestItemRef::ChangesTrieRoot(v),
DigestItem::Consensus(ref v, ref s) => DigestItemRef::Consensus(v, s),
DigestItem::Seal(ref v, ref s) => DigestItemRef::Seal(v, s),
Expand All @@ -164,16 +157,10 @@ impl<Hash, AuthorityId, SealSignature> DigestItem<Hash, AuthorityId, SealSignatu

impl<
Hash: Codec + Member,
AuthorityId: Codec + Member + MaybeHash,
SealSignature: Codec + Member,
> traits::DigestItem for DigestItem<Hash, AuthorityId, SealSignature> {
> traits::DigestItem for DigestItem<Hash, SealSignature> {
type Hash = Hash;
/* type AuthorityId = AuthorityId;

fn as_authorities_change(&self) -> Option<&[Self::AuthorityId]> {
self.dref().as_authorities_change()
}
*/
fn as_changes_trie_root(&self) -> Option<&Self::Hash> {
self.dref().as_changes_trie_root()
}
Expand All @@ -183,20 +170,17 @@ impl<
}
}

impl<Hash: Encode, AuthorityId: Encode, SealSignature: Encode> Encode for DigestItem<Hash, AuthorityId, SealSignature> {
impl<Hash: Encode, SealSignature: Encode> Encode for DigestItem<Hash, SealSignature> {
fn encode(&self) -> Vec<u8> {
self.dref().encode()
}
}

impl<Hash: Decode, AuthorityId: Decode, SealSignature: Decode> Decode for DigestItem<Hash, AuthorityId, SealSignature> {
impl<Hash: Decode, SealSignature: Decode> Decode for DigestItem<Hash, SealSignature> {
#[allow(deprecated)]
fn decode<I: Input>(input: &mut I) -> Option<Self> {
let item_type: DigestItemType = Decode::decode(input)?;
match item_type {
DigestItemType::AuthoritiesChange => Some(DigestItem::AuthoritiesChange(
Decode::decode(input)?,
)),
DigestItemType::ChangesTrieRoot => Some(DigestItem::ChangesTrieRoot(
Decode::decode(input)?,
)),
Expand All @@ -219,15 +203,7 @@ impl<Hash: Decode, AuthorityId: Decode, SealSignature: Decode> Decode for Digest
}
}

impl<'a, Hash: Codec + Member, AuthorityId: Codec + Member, SealSignature: Codec + Member> DigestItemRef<'a, Hash, AuthorityId, SealSignature> {
/// Cast this digest item into `AuthoritiesChange`.
pub fn as_authorities_change(&self) -> Option<&'a [AuthorityId]> {
match *self {
DigestItemRef::AuthoritiesChange(ref authorities) => Some(authorities),
_ => None,
}
}

impl<'a, Hash: Codec + Member, SealSignature: Codec + Member> DigestItemRef<'a, Hash, SealSignature> {
/// Cast this digest item into `ChangesTrieRoot`.
pub fn as_changes_trie_root(&self) -> Option<&'a Hash> {
match *self {
Expand All @@ -245,15 +221,11 @@ impl<'a, Hash: Codec + Member, AuthorityId: Codec + Member, SealSignature: Codec
}
}

impl<'a, Hash: Encode, AuthorityId: Encode, SealSignature: Encode> Encode for DigestItemRef<'a, Hash, AuthorityId, SealSignature> {
impl<'a, Hash: Encode, SealSignature: Encode> Encode for DigestItemRef<'a, Hash, SealSignature> {
fn encode(&self) -> Vec<u8> {
let mut v = Vec::new();

match *self {
DigestItemRef::AuthoritiesChange(authorities) => {
DigestItemType::AuthoritiesChange.encode_to(&mut v);
authorities.encode_to(&mut v);
},
DigestItemRef::ChangesTrieRoot(changes_trie_root) => {
DigestItemType::ChangesTrieRoot.encode_to(&mut v);
changes_trie_root.encode_to(&mut v);
Expand Down Expand Up @@ -289,7 +261,6 @@ mod tests {
fn should_serialize_digest() {
let digest = Digest {
logs: vec![
DigestItem::AuthoritiesChange(vec![1]),
DigestItem::ChangesTrieRoot(4),
DigestItem::Other(vec![1, 2, 3]),
DigestItem::Seal(Default::default(), Signature::default())
Expand All @@ -298,7 +269,7 @@ mod tests {

assert_eq!(
::serde_json::to_string(&digest).unwrap(),
"{\"logs\":[\"0x010401000000\",\"0x0204000000\",\"0x000c010203\",\"0x050000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\"]}",
"{\"logs\":[\"0x010401000000\",\"0x000c010203\",\"0x050000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\"]}",
);
}
}
5 changes: 0 additions & 5 deletions core/sr-primitives/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -737,11 +737,6 @@ macro_rules! impl_outer_log {

impl $crate::traits::DigestItem for $name {
type Hash = <$crate::generic::DigestItem<$($genarg),*> as $crate::traits::DigestItem>::Hash;
type AuthorityId = <$crate::generic::DigestItem<$($genarg),*> as $crate::traits::DigestItem>::AuthorityId;

fn as_authorities_change(&self) -> Option<&[Self::AuthorityId]> {
self.dref().and_then(|dref| dref.as_authorities_change())
}

fn as_changes_trie_root(&self) -> Option<&Self::Hash> {
self.dref().and_then(|dref| dref.as_changes_trie_root())
Expand Down
Loading