Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
0eb8b9d
Implement ValidateUnsigned for Aura equivocation report
seerscode Jun 17, 2019
37c46ac
Add transaction pool to check_header in Aura
seerscode Jun 18, 2019
6d82c3f
Add constructor api to Aura
seerscode Jun 18, 2019
a7536b1
Submit report from Aura
seerscode Jun 18, 2019
f6055b9
Add Grandpa constructor calls
seerscode Jun 19, 2019
157320c
Submit grandpa reports, need to fix tests
seerscode Jun 19, 2019
1b1e516
Fix Grandpa Test
seerscode Jun 19, 2019
808fdb8
Aura construct call
seerscode Jun 19, 2019
86f4793
Add types Prevote/Precommit Equivocation
seerscode Jun 20, 2019
d52f8ab
Add handlers for grandpa reports
seerscode Jun 20, 2019
129fb1c
Fix test-runtime
seerscode Jun 20, 2019
e65252a
Add Babe ValidateUnsigned
seerscode Jun 20, 2019
4b558b5
Fix test
seerscode Jun 20, 2019
1a4b980
Remove unused imports
seerscode Jun 20, 2019
e4a5cc1
Add test for check_header submiting in aura
seerscode Jun 21, 2019
1ad7ce5
Add test for srml aura
seerscode Jun 21, 2019
5b95415
Add test for Grandpa srml
seerscode Jun 21, 2019
9a3a560
Merge master
seerscode Jun 21, 2019
1d1d3f3
Fix fg test
seerscode Jun 21, 2019
d3ddf6b
Add new GrandpaApi version
seerscode Jun 21, 2019
755bf45
Remove unwrap
seerscode Jun 21, 2019
cc01912
Remove bunch of warnings
seerscode Jun 21, 2019
6a293c0
Refactor submitters
seerscode Jun 22, 2019
e1c025e
Refactor aura report
seerscode Jun 24, 2019
042ee9b
Merge master
seerscode Jun 24, 2019
529d4b5
Rename accountable safety
seerscode Jun 24, 2019
9f80e81
Remove mock for tx pool
seerscode Jun 24, 2019
5c2a007
Fix some nits
seerscode Jun 24, 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
54 changes: 50 additions & 4 deletions Cargo.lock

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

16 changes: 16 additions & 0 deletions core/consensus/accountable-safety/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
[package]
name = "substrate-consensus-accountable-safety"
version = "2.0.0"
authors = ["Parity Technologies <admin@parity.io>"]
description = "Common utilities for accountable safety"
edition = "2018"

[dependencies]
client = { package = "substrate-client", path = "../../client" }
transaction_pool = { package = "substrate-transaction-pool", path = "../../transaction-pool" }
node-runtime = { path = "../../../node/runtime" }
runtime_primitives = { package = "sr-primitives", path = "../../sr-primitives" }
substrate-primitives = { path = "../../primitives" }
grandpa = { package = "finality-grandpa", git = "https://github.com/paritytech/finality-grandpa/", branch = "mod-equivocation-reports", features = ["derive-codec"] }
parity-codec = "3.5.1"
log = "0.4"
9 changes: 9 additions & 0 deletions core/consensus/accountable-safety/primitives/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[package]
name = "substrate-consensus-accountable-safety-primitives"
version = "2.0.0"
authors = ["Parity Technologies <admin@parity.io>"]
description = "Primitives for Accountable Safety"
edition = "2018"

[dependencies]
runtime_primitives = { package = "sr-primitives", path = "../../../sr-primitives", default-features = false }
41 changes: 41 additions & 0 deletions core/consensus/accountable-safety/primitives/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// Copyright 2019 Parity Technologies (UK) Ltd.
// This file is part of Substrate.

// Substrate is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.

// Substrate is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.

// You should have received a copy of the GNU General Public License
// along with Substrate. If not, see <http://www.gnu.org/licenses/>.

//! Common utilities for accountable safety in Substrate.

#![cfg_attr(not(feature = "std"), no_std)]

pub trait AuthorshipEquivocationProof<H, S> {
/// Create an equivocation proof for AuRa or Babe.
fn new(
first_header: H,
second_header: H,
first_signature: S,
second_signature: S,
) -> Self;

/// Get the first header involved in the equivocation.
fn first_header(&self) -> &H;

/// Get the second header involved in the equivocation.
fn second_header(&self) -> &H;

/// Get signature for the first header involved in the equivocation.
fn first_signature(&self) -> &S;

/// Get signature for the second header involved in the equivocation.
fn second_signature(&self) -> &S;
}
52 changes: 52 additions & 0 deletions core/consensus/accountable-safety/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
// Copyright 2019 Parity Technologies (UK) Ltd.
// This file is part of Substrate.

// Substrate is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.

// Substrate is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.

// You should have received a copy of the GNU General Public License
// along with Substrate. If not, see <http://www.gnu.org/licenses/>.

//! Common utilities for accountable safety in Substrate.

#![forbid(missing_docs, unsafe_code)]

use client;
use transaction_pool::txpool::{self, PoolApi};
use parity_codec::{Encode, Decode};
use runtime_primitives::traits::{Block as BlockT};
use runtime_primitives::generic::BlockId;
use log::info;
use client::blockchain::HeaderBackend;

/// Trait to submit report calls to the transaction pool.
pub trait SubmitReport<C, Block> {
/// Submit report call to the transaction pool.
fn submit_report_call(&self, client: &C, extrinsic: &[u8]);
}

impl<C, Block, T: PoolApi + Send + Sync + 'static> SubmitReport<C, Block> for T
where
Block: BlockT + 'static,
<T as PoolApi>::Api: txpool::ChainApi<Block=Block> + 'static,
C: HeaderBackend<Block>,
{
fn submit_report_call(&self, client: &C, mut extrinsic: &[u8]) {
info!(target: "accountable-safety", "Submitting report call to tx pool");
if let Some(uxt) = Decode::decode(&mut extrinsic) {
let block_id = BlockId::<Block>::number(client.info().best_number);
if let Err(e) = self.submit_one(&block_id, uxt) {
info!(target: "accountable-safety", "Error importing misbehavior report: {:?}", e);
}
} else {
info!(target: "accountable-safety", "Error decoding report call");
}
}
}
3 changes: 3 additions & 0 deletions core/consensus/aura/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@ srml-aura = { path = "../../../srml/aura" }
client = { package = "substrate-client", path = "../../client" }
substrate-telemetry = { path = "../../telemetry" }
consensus_common = { package = "substrate-consensus-common", path = "../common" }
consensus_accountable_safety = { package = "substrate-consensus-accountable-safety", path = "../accountable-safety" }
consensus_accountable_safety_primitives = { package = "substrate-consensus-accountable-safety-primitives", path = "../accountable-safety/primitives" }
runtime_primitives = { package = "sr-primitives", path = "../../sr-primitives" }
transaction_pool = { package = "substrate-transaction-pool", path = "../../transaction-pool" }
futures = "0.1.17"
tokio-timer = "0.2.11"
parking_lot = "0.8.0"
Expand Down
1 change: 1 addition & 0 deletions core/consensus/aura/primitives/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ substrate-client = { path = "../../../client", default-features = false }
substrate-primitives = { path = "../../../primitives", default-features = false }
rstd = { package = "sr-std", path = "../../../sr-std", default-features = false }
runtime_primitives = { package = "sr-primitives", path = "../../../sr-primitives", default-features = false }
consensus_accountable_safety_primitives = { package = "substrate-consensus-accountable-safety-primitives", path = "../../accountable-safety/primitives" }

[features]
default = ["std"]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,21 +19,19 @@
//! This implements the digests for AuRa, to allow the private

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting. I almost made the same change for BABE in my on-chain randomness work, but reverted it.

//! `CompatibleDigestItem` trait to appear in public interfaces.

use primitives::Pair;
use aura_primitives::AURA_ENGINE_ID;
use runtime_primitives::generic::{DigestItem, OpaqueDigestItemId};
use runtime_primitives::{
generic::{DigestItem, OpaqueDigestItemId}, traits::Header
};
use parity_codec::{Encode, Codec};
use std::fmt::Debug;

type Signature<P> = <P as Pair>::Signature;
use crate::AURA_ENGINE_ID;

/// A digest item which is usable with aura consensus.
pub trait CompatibleDigestItem<P: Pair>: Sized {
pub trait CompatibleDigestItem<Signature> {
/// Construct a digest item which contains a signature on the hash.
fn aura_seal(signature: Signature<P>) -> Self;
fn aura_seal(signature: Signature) -> Self;

/// If this item is an Aura seal, return the signature.
fn as_aura_seal(&self) -> Option<Signature<P>>;
fn as_aura_seal(&self) -> Option<Signature>;

/// Construct a digest item which contains the slot number
fn aura_pre_digest(slot_num: u64) -> Self;
Expand All @@ -42,16 +40,13 @@ pub trait CompatibleDigestItem<P: Pair>: Sized {
fn as_aura_pre_digest(&self) -> Option<u64>;
}

impl<P, Hash> CompatibleDigestItem<P> for DigestItem<Hash> where
P: Pair,
Signature<P>: Codec,
Hash: Debug + Send + Sync + Eq + Clone + Codec + 'static
impl<Hash, Signature: Codec> CompatibleDigestItem<Signature> for DigestItem<Hash>
{
fn aura_seal(signature: Signature<P>) -> Self {
fn aura_seal(signature: Signature) -> Self {
DigestItem::Seal(AURA_ENGINE_ID, signature.encode())
}

fn as_aura_seal(&self) -> Option<Signature<P>> {
fn as_aura_seal(&self) -> Option<Signature> {
self.try_to(OpaqueDigestItemId::Seal(&AURA_ENGINE_ID))
}

Expand All @@ -63,3 +58,23 @@ impl<P, Hash> CompatibleDigestItem<P> for DigestItem<Hash> where
self.try_to(OpaqueDigestItemId::PreRuntime(&AURA_ENGINE_ID))
}
}

/// Extract the digest item type for a block.
pub type DigestItemForHeader<H> = DigestItem<<H as Header>::Hash>;

/// Find pre digest in Aura header.
pub fn find_pre_digest<H, S>(header: &H) -> Result<u64, &str>
where
H: Header,
DigestItemForHeader<H>: CompatibleDigestItem<S>,
{
let mut pre_digest: Option<u64> = None;
for log in header.digest().logs() {
match (log.as_aura_pre_digest(), pre_digest.is_some()) {
(Some(_), true) => Err("Multiple AuRa pre-runtime headers, rejecting!")?,
(None, _) => {},
(s, false) => pre_digest = s,
}
}
pre_digest.ok_or_else(|| "No AuRa pre-runtime digest found")
}
Loading