From 3b9c38d7de2e6e4856f3325a8395f11f62a9cb46 Mon Sep 17 00:00:00 2001 From: Marcio Diaz Date: Tue, 6 Aug 2019 23:56:09 +0200 Subject: [PATCH] Fix signature and public tmp --- Cargo.lock | 2 + .../babe/primitives/src/equivocation.rs | 102 ------------------ core/consensus/babe/primitives/src/lib.rs | 10 +- core/consensus/babe/src/lib.rs | 2 +- core/consensus/common/primitives/Cargo.toml | 1 + core/consensus/common/primitives/src/lib.rs | 6 +- core/consensus/slots/Cargo.toml | 1 + core/consensus/slots/src/aux_schema.rs | 7 +- core/primitives/src/sr25519.rs | 14 +++ srml/session/src/historical.rs | 4 +- 10 files changed, 39 insertions(+), 110 deletions(-) delete mode 100644 core/consensus/babe/primitives/src/equivocation.rs diff --git a/Cargo.lock b/Cargo.lock index fdb00f194df3d..b260c58660227 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4459,6 +4459,7 @@ dependencies = [ "serde 1.0.97 (registry+https://github.com/rust-lang/crates.io-index)", "sr-primitives 2.0.0", "sr-std 2.0.0", + "srml-session 2.0.0", "substrate-client 2.0.0", "substrate-primitives 2.0.0", ] @@ -4497,6 +4498,7 @@ dependencies = [ "parity-codec 4.1.3 (registry+https://github.com/rust-lang/crates.io-index)", "parking_lot 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", "sr-primitives 2.0.0", + "srml-session 2.0.0", "substrate-client 2.0.0", "substrate-consensus-common 2.0.0", "substrate-consensus-common-primitives 2.0.0", diff --git a/core/consensus/babe/primitives/src/equivocation.rs b/core/consensus/babe/primitives/src/equivocation.rs deleted file mode 100644 index dfdcb946532c2..0000000000000 --- a/core/consensus/babe/primitives/src/equivocation.rs +++ /dev/null @@ -1,102 +0,0 @@ -// 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 . - -//! Primitives for BABE equivocations. - -use parity_codec::{Encode, Decode, Codec}; -use sr_primitives::{ConsensusEngineId, traits::{Block as BlockT, Header, Verify}}; -use safety_primitives::AuthorshipEquivocationProof; -use srml_session::historical::Proof; -use crate::digest::find_pre_digest; - -/// Represents a Babe equivocation proof. -#[cfg_attr(feature = "std", derive(Serialize, Debug))] -#[derive(Clone, Encode, Decode, PartialEq, Eq)] -pub struct BabeEquivocationProof { - identity: AuthorityId, - slot: u64, - identity_proof: Proof, - first_header: H, - second_header: H, - first_signature: AuthoritySignature, - second_signature: AuthoritySignature, -} - -impl AuthorshipEquivocationProof for BabeEquivocationProof -where - H: Header, -{ - type Header = H; - type Signature = AuthoritySignature; - type Identity = AuthorityId; - type InclusionProof = Proof; - - /// Create a new Babe equivocation proof. - fn new( - identity: AuthorityId, - identity_proof: Proof, - slot: u64, - first_header: H, - second_header: H, - first_signature: AuthoritySignature, - second_signature: AuthoritySignature, - ) -> Self { - BabeEquivocationProof { - identity, - identity_proof, - slot, - first_header, - second_header, - first_signature, - second_signature, - } - } - - /// Return the slot where the equivocation happened. - fn slot(&self) -> u64 { - self.slot - } - - /// Get the identity of the suspect of equivocating. - fn identity(&self) -> &I { - &self.identity - } - - /// Get the identity proof. - fn identity_proof(&self) -> Option<&P> { - self.identity_proof.as_ref() - } - - /// Get the first header involved in the equivocation. - fn first_header(&self) -> &H { - &self.first_header - } - - /// Get the second header involved in the equivocation. - fn second_header(&self) -> &H { - &self.second_header - } - - /// Get the first signature involved in the equivocation. - fn first_signature(&self) -> &S { - &self.first_signature - } - - /// Get the second signature involved in the equivocation. - fn second_signature(&self) -> &S { - &self.second_signature - } -} \ No newline at end of file diff --git a/core/consensus/babe/primitives/src/lib.rs b/core/consensus/babe/primitives/src/lib.rs index 36ea7af22cd27..c20ab19315154 100644 --- a/core/consensus/babe/primitives/src/lib.rs +++ b/core/consensus/babe/primitives/src/lib.rs @@ -139,9 +139,10 @@ impl slots::SlotData for BabeConfiguration { } /// Represents an Babe equivocation proof. -#[derive(Clone, Encode, Decode, PartialEq)] +#[derive(Debug, Clone, Encode, Decode, PartialEq)] pub struct BabeEquivocationProof { identity: AuthorityId, + identity_proof: Proof, slot: u64, first_header: H, second_header: H, @@ -160,6 +161,7 @@ where /// Create a new Babe equivocation proof. fn new( identity: Self::Identity, + identity_proof: Proof, slot: u64, first_header: H, second_header: H, @@ -168,6 +170,7 @@ where ) -> Self { BabeEquivocationProof { identity, + identity_proof, slot, first_header, second_header, @@ -186,6 +189,11 @@ where &self.identity } + /// Get the identity of the suspect of equivocating. + fn identity_proof(&self) -> &Proof { + &self.identity_proof + } + /// Get the first header involved in the equivocation. fn first_header(&self) -> &H { &self.first_header diff --git a/core/consensus/babe/src/lib.rs b/core/consensus/babe/src/lib.rs index 6ec283ab9e551..0b4ad5a5f3392 100644 --- a/core/consensus/babe/src/lib.rs +++ b/core/consensus/babe/src/lib.rs @@ -505,7 +505,7 @@ fn check_header( } if let Some(equivocation_proof) = check_equivocation::< - _, _, BabeEquivocationProof, _, _ + _, _, BabeEquivocationProof, _ >( client, slot_now, diff --git a/core/consensus/common/primitives/Cargo.toml b/core/consensus/common/primitives/Cargo.toml index 29841796ef97c..381b01cff03c2 100644 --- a/core/consensus/common/primitives/Cargo.toml +++ b/core/consensus/common/primitives/Cargo.toml @@ -12,6 +12,7 @@ sr-primitives = { path = "../../../sr-primitives", default-features = false } rstd = { package = "sr-std", path = "../../../sr-std", default-features = false } serde = { version = "1.0", optional = true, features = ["derive"] } primitives = { package = "substrate-primitives", path = "../../../primitives", default-features = false } +srml-session = { path = "../../../../srml/session", default-features = false } [features] default = ["std"] diff --git a/core/consensus/common/primitives/src/lib.rs b/core/consensus/common/primitives/src/lib.rs index 1b6ce61a395e6..3c1032c321d07 100644 --- a/core/consensus/common/primitives/src/lib.rs +++ b/core/consensus/common/primitives/src/lib.rs @@ -24,7 +24,7 @@ use parity_codec::Codec; #[cfg(feature = "std")] use serde::Serialize; use sr_primitives::{traits::{Header, Verify}}; - +use srml_session::historical::Proof; decl_runtime_apis! { /// Common consensus runtime api. @@ -42,6 +42,7 @@ pub trait AuthorshipEquivocationProof { /// Create an equivocation proof for AuRa or Babe. fn new( identity: Self::Identity, + identity_proof: Proof, slot: u64, first_header: Self::Header, second_header: Self::Header, @@ -52,6 +53,9 @@ pub trait AuthorshipEquivocationProof { /// Get the slot where the equivocation happened. fn slot(&self) -> u64; + /// Get the identity proof of the suspect of equivocating. + fn identity_proof(&self) -> &Proof; + /// Get the identity of the suspect of equivocating. fn identity(&self) -> &Self::Identity; diff --git a/core/consensus/slots/Cargo.toml b/core/consensus/slots/Cargo.toml index 2bdd376302180..38c8794244fc5 100644 --- a/core/consensus/slots/Cargo.toml +++ b/core/consensus/slots/Cargo.toml @@ -13,6 +13,7 @@ sr-primitives = { path = "../../sr-primitives" } consensus_common = { package = "substrate-consensus-common", path = "../common" } consensus_common_primitives = { package = "substrate-consensus-common-primitives", path = "../common/primitives" } inherents = { package = "substrate-inherents", path = "../../inherents" } +srml-session = { path = "../../../srml/session", default-features = false } futures-preview = "0.3.0-alpha.17" futures-timer = "0.2.1" parking_lot = "0.8.0" diff --git a/core/consensus/slots/src/aux_schema.rs b/core/consensus/slots/src/aux_schema.rs index bcd26d04262a1..0e40854077fe4 100644 --- a/core/consensus/slots/src/aux_schema.rs +++ b/core/consensus/slots/src/aux_schema.rs @@ -16,12 +16,13 @@ //! Schema for slots in the aux-db. +use std::ops::Deref; use codec::{Encode, Decode, Codec}; use client::backend::AuxStore; use client::error::{Result as ClientResult, Error as ClientError}; use sr_primitives::traits::{Header, Verify}; use consensus_common_primitives::AuthorshipEquivocationProof; -use std::ops::Deref; +use srml_session::historical::Proof; const SLOT_HEADER_MAP_KEY: &[u8] = b"slot_header_map"; const SLOT_HEADER_START: &[u8] = b"slot_header_start"; @@ -57,7 +58,7 @@ pub struct EquivocationProof { /// Checks if the header is an equivocation and returns the proof in that case. /// /// Note: it detects equivocations only when slot_now - slot <= MAX_SLOT_CAPACITY. -pub fn check_equivocation( +pub fn check_equivocation( backend: &C, slot_now: u64, slot: u64, @@ -68,7 +69,6 @@ pub fn check_equivocation( where H: Header, C: AuxStore, - P: Clone + Encode + Decode + PartialEq, V: Verify + Codec + Clone, ::Signer: Clone + Codec + PartialEq, E: AuthorshipEquivocationProof< @@ -106,6 +106,7 @@ pub fn check_equivocation( if header.hash() != prev_header.hash() { return Ok(Some(AuthorshipEquivocationProof::new( signer.clone(), + Proof::default(), slot, prev_header.clone(), header.clone(), diff --git a/core/primitives/src/sr25519.rs b/core/primitives/src/sr25519.rs index e01d989143c6b..df4a0f75abc23 100644 --- a/core/primitives/src/sr25519.rs +++ b/core/primitives/src/sr25519.rs @@ -126,6 +126,20 @@ impl ::std::fmt::Debug for Public { } } +#[cfg(not(feature = "std"))] +impl ::core::fmt::Debug for Public { + fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { + write!(f, "") + } +} + +#[cfg(not(feature = "std"))] +impl ::core::fmt::Debug for Signature { + fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { + write!(f, "") + } +} + #[cfg(feature = "std")] impl Serialize for Public { fn serialize(&self, serializer: S) -> Result where S: Serializer { diff --git a/srml/session/src/historical.rs b/srml/session/src/historical.rs index 3738b120b31c7..2479d050dffcc 100644 --- a/srml/session/src/historical.rs +++ b/srml/session/src/historical.rs @@ -270,8 +270,8 @@ impl ProvingTrie { } /// Proof of ownership of a specific key. -#[cfg_attr(feature = "std", derive(Serialize, Debug))] -#[derive(Encode, Decode, Clone, PartialEq, Eq, Default)] +#[cfg_attr(feature = "std", derive(Serialize))] +#[derive(Encode, Decode, Clone, PartialEq, Eq, Default, Debug)] pub struct Proof { session: SessionIndex, trie_nodes: Vec>,