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
33 commits
Select commit Hold shift + click to select a range
527e971
slots: create primitives crate for consensus slots
andresilva Jun 3, 2020
4ffdc8a
offences: add method to check if an offence is unknown
andresilva Jun 8, 2020
94084aa
babe: initial equivocation reporting implementation
andresilva Jun 8, 2020
8759f02
babe: organize imports
andresilva Jun 8, 2020
54ceef3
babe: working equivocation reporting
andresilva Jun 11, 2020
af2e58b
babe: add slot number to equivocation proof
andresilva Jun 15, 2020
4b573fb
session: move duplicate traits to session primitives
andresilva Jun 15, 2020
f20c07f
babe: move equivocation stuff to its own file
andresilva Jun 15, 2020
1215653
offences: fix test
andresilva Jun 15, 2020
03f5b71
session: don't have primitives depend on frame_support
andresilva Jun 15, 2020
17ea089
babe: use opaque type for key owner proof
andresilva Jun 15, 2020
d243323
babe: cleanup client equivocation reporting
andresilva Jun 15, 2020
237689e
babe: cleanup equivocation code in pallet
andresilva Jun 15, 2020
760996a
babe: allow sending signed equivocation reports
andresilva Jun 15, 2020
5464a0a
node: fix compilation
andresilva Jun 16, 2020
585f80b
fix test compilation
andresilva Jun 16, 2020
26bfb4f
Merge branch 'master' into andre/report-babe-equivocations
andresilva Jun 16, 2020
0f22701
babe: return bool on check_equivocation_proof
andresilva Jun 22, 2020
81ce38f
Merge branch 'master' into andre/report-babe-equivocations
andresilva Jun 22, 2020
95b29be
Merge branch 'master' into andre/report-babe-equivocations
andresilva Jun 24, 2020
e8467c4
babe: add test for equivocation reporting
andresilva Jun 30, 2020
187008a
babe: add more tests
andresilva Jun 30, 2020
ae68282
babe: add test for validate unsigned
andresilva Jun 30, 2020
db83144
Merge branch 'master' into andre/report-babe-equivocations
andresilva Jun 30, 2020
17a0141
babe: take slot number in generate_key_ownership_proof API
andresilva Jun 30, 2020
27dc893
Merge branch 'master' into andre/report-babe-equivocations
andresilva Jul 1, 2020
a1db90c
babe: add benchmark for equivocation proof checking
andresilva Jul 1, 2020
f88e5e6
session: add benchmark for membership proof checking
andresilva Jul 1, 2020
15b1000
offences: fix babe benchmark
andresilva Jul 1, 2020
8a5e0bc
babe: add weights based on benchmark results
andresilva Jul 1, 2020
d53a277
babe: adjust weights after benchmarking on reference hardware
andresilva Jul 2, 2020
4b1b2ce
Merge branch 'master' into andre/report-babe-equivocations
andresilva Jul 2, 2020
dbc9ee2
babe: reorder checks in check_and_report_equivocation
andresilva Jul 3, 2020
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
Next Next commit
slots: create primitives crate for consensus slots
  • Loading branch information
andresilva committed Jun 14, 2020
commit 527e9718e067b32b83eb31b9d11a6a16c9c06984
9 changes: 9 additions & 0 deletions Cargo.lock

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

4 changes: 2 additions & 2 deletions client/consensus/babe/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -842,8 +842,8 @@ impl<Block, Client> Verifier<Block> for BabeVerifier<Block, Client> where
"Slot author {:?} is equivocating at slot {} with headers {:?} and {:?}",
author,
babe_pre_digest.slot_number(),
equivocation_proof.fst_header().hash(),
equivocation_proof.snd_header().hash(),
equivocation_proof.first_header.hash(),
equivocation_proof.second_header.hash(),
);
}

Expand Down
1 change: 1 addition & 0 deletions client/consensus/slots/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ sc-client-api = { version = "2.0.0-rc3", path = "../../api" }
sp-core = { version = "2.0.0-rc3", path = "../../../primitives/core" }
sp-application-crypto = { version = "2.0.0-rc3", path = "../../../primitives/application-crypto" }
sp-blockchain = { version = "2.0.0-rc3", path = "../../../primitives/blockchain" }
sp-consensus-slots = { version = "0.8.0-rc3", path = "../../../primitives/consensus/slots" }
sp-runtime = { version = "2.0.0-rc3", path = "../../../primitives/runtime" }
sp-state-machine = { version = "0.8.0-rc3", path = "../../../primitives/state-machine" }
sp-api = { version = "2.0.0-rc3", path = "../../../primitives/api" }
Expand Down
30 changes: 3 additions & 27 deletions client/consensus/slots/src/aux_schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
use codec::{Encode, Decode};
use sc_client_api::backend::AuxStore;
use sp_blockchain::{Result as ClientResult, Error as ClientError};
use sp_consensus_slots::EquivocationProof;
use sp_runtime::traits::Header;

const SLOT_HEADER_MAP_KEY: &[u8] = b"slot_header_map";
Expand All @@ -44,31 +45,6 @@ fn load_decode<C, T>(backend: &C, key: &[u8]) -> ClientResult<Option<T>>
}
}

/// Represents an equivocation proof.
#[derive(Debug, Clone)]
pub struct EquivocationProof<H> {
slot: u64,
fst_header: H,
snd_header: H,
}

impl<H> EquivocationProof<H> {
/// Get the slot number where the equivocation happened.
pub fn slot(&self) -> u64 {
self.slot
}

/// Get the first header involved in the equivocation.
pub fn fst_header(&self) -> &H {
&self.fst_header
}

/// Get the second header involved in the equivocation.
pub fn snd_header(&self) -> &H {
&self.snd_header
}
}

/// 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.
Expand Down Expand Up @@ -115,8 +91,8 @@ pub fn check_equivocation<C, H, P>(
if header.hash() != prev_header.hash() {
return Ok(Some(EquivocationProof {
slot, // 3) and mentioning the same slot.
fst_header: prev_header.clone(),
snd_header: header.clone(),
first_header: prev_header.clone(),
second_header: header.clone(),
}));
} else {
// We don't need to continue in case of duplicated header,
Expand Down
2 changes: 2 additions & 0 deletions primitives/consensus/babe/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ merlin = { version = "2.0", default-features = false }
sp-std = { version = "2.0.0-rc3", default-features = false, path = "../../std" }
sp-api = { version = "2.0.0-rc3", default-features = false, path = "../../api" }
sp-consensus = { version = "0.8.0-rc3", optional = true, path = "../common" }
sp-consensus-slots = { version = "0.8.0-rc3", default-features = false, path = "../slots" }
sp-consensus-vrf = { version = "0.8.0-rc3", path = "../vrf", default-features = false }
sp-inherents = { version = "2.0.0-rc3", default-features = false, path = "../../inherents" }
sp-runtime = { version = "2.0.0-rc3", default-features = false, path = "../../runtime" }
Expand All @@ -32,6 +33,7 @@ std = [
"sp-std/std",
"sp-api/std",
"sp-consensus",
"sp-consensus-slots/std",
"sp-consensus-vrf/std",
"sp-inherents/std",
"sp-runtime/std",
Expand Down
5 changes: 4 additions & 1 deletion primitives/consensus/babe/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,10 @@ pub const MEDIAN_ALGORITHM_CARDINALITY: usize = 1200; // arbitrary suggestion by
pub type AuthorityIndex = u32;

/// A slot number.
pub type SlotNumber = u64;
pub use sp_consensus_slots::SlotNumber;

/// An equivocation proof for multiple block authorships on the same slot (i.e. double vote).
pub use sp_consensus_slots::EquivocationProof;

/// The weight of an authority.
// NOTE: we use a unique name for the weight to avoid conflicts with other
Expand Down
21 changes: 21 additions & 0 deletions primitives/consensus/slots/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
[package]
name = "sp-consensus-slots"
version = "0.8.0-rc3"
authors = ["Parity Technologies <[email protected]>"]
description = "Primitives for slots-based consensus"
edition = "2018"
license = "Apache-2.0"
homepage = "https://substrate.dev"
repository = "https://github.com/paritytech/substrate/"

[package.metadata.docs.rs]
targets = ["x86_64-unknown-linux-gnu"]

[dependencies]
codec = { package = "parity-scale-codec", version = "1.3.0", default-features = false, features = ["derive"] }

[features]
default = ["std"]
std = [
"codec/std",
]
39 changes: 39 additions & 0 deletions primitives/consensus/slots/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// This file is part of Substrate.

// Copyright (C) 2020 Parity Technologies (UK) Ltd.
// SPDX-License-Identifier: Apache-2.0

// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

//! Primitives for slots-based consensus engines.

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

use codec::{Decode, Encode};

/// A slot number.
pub type SlotNumber = u64;

/// Represents an equivocation proof. An equivocation happens when a validator
/// produces more than one block on the same slot. The proof of equivocation
/// are the given distinct headers that were signed by the validator and which
/// include the slot number.
#[derive(Clone, Debug, Decode, Encode)]
pub struct EquivocationProof<H> {
/// The slot number at which the equivocation happened.
pub slot: SlotNumber,
/// The first header involved in the equivocation.
pub first_header: H,
/// The second header involved in the equivocation.
pub second_header: H,
}