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
Prev Previous commit
Next Next commit
babe: add benchmark for equivocation proof checking
  • Loading branch information
andresilva committed Jul 1, 2020
commit a1db90cf3a4196c08c63f06fe09de34188e39f5b
1 change: 1 addition & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions bin/node/runtime/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ runtime-benchmarks = [
"frame-support/runtime-benchmarks",
"frame-system/runtime-benchmarks",
"sp-runtime/runtime-benchmarks",
"pallet-babe/runtime-benchmarks",
"pallet-balances/runtime-benchmarks",
"pallet-collective/runtime-benchmarks",
"pallet-democracy/runtime-benchmarks",
Expand Down
1 change: 1 addition & 0 deletions bin/node/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1134,6 +1134,7 @@ impl_runtime_apis! {
let mut batches = Vec::<BenchmarkBatch>::new();
let params = (&pallet, &benchmark, &lowest_range_values, &highest_range_values, &steps, repeat, &whitelist);

add_benchmark!(params, batches, b"babe", Babe);
add_benchmark!(params, batches, b"balances", Balances);
add_benchmark!(params, batches, b"collective", Council);
add_benchmark!(params, batches, b"democracy", Democracy);
Expand Down
4 changes: 4 additions & 0 deletions frame/babe/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ targets = ["x86_64-unknown-linux-gnu"]

[dependencies]
codec = { package = "parity-scale-codec", version = "1.3.1", default-features = false, features = ["derive"] }
frame-benchmarking = { version = "2.0.0-rc4", default-features = false, path = "../benchmarking", optional = true }
frame-support = { version = "2.0.0-rc4", default-features = false, path = "../support" }
frame-system = { version = "2.0.0-rc4", default-features = false, path = "../system" }
pallet-authorship = { version = "2.0.0-rc4", default-features = false, path = "../authorship" }
Expand All @@ -31,6 +32,7 @@ sp-std = { version = "2.0.0-rc4", default-features = false, path = "../../primit
sp-timestamp = { version = "2.0.0-rc4", default-features = false, path = "../../primitives/timestamp" }

[dev-dependencies]
frame-benchmarking = { version = "2.0.0-rc4", path = "../benchmarking" }
pallet-balances = { version = "2.0.0-rc4", path = "../balances" }
pallet-offences = { version = "2.0.0-rc4", path = "../offences" }
pallet-staking = { version = "2.0.0-rc4", path = "../staking" }
Expand All @@ -41,6 +43,7 @@ sp-core = { version = "2.0.0-rc4", path = "../../primitives/core" }
default = ["std"]
std = [
"codec/std",
"frame-benchmarking/std",
"frame-support/std",
"frame-system/std",
"pallet-authorship/std",
Expand All @@ -58,3 +61,4 @@ std = [
"sp-std/std",
"sp-timestamp/std",
]
runtime-benchmarks = ["frame-benchmarking"]
108 changes: 108 additions & 0 deletions frame/babe/src/benchmarking.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
// 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.

//! Benchmarks for the BABE Pallet.

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

use super::*;
use frame_benchmarking::benchmarks;

type Header = sp_runtime::generic::Header<u64, sp_runtime::traits::BlakeTwo256>;

benchmarks! {
_ { }

check_equivocation_proof {
let x in 0 .. 1;

// NOTE: generated with the test below `test_generate_equivocation_report_blob`.
// the output is not deterministic since keys are generated randomly (and therefore
// signature content changes). it should not affect the benchmark.
// with the current benchmark setup it is not possible to generate this programatically
// from the benchmark setup.
const EQUIVOCATION_PROOF_BLOB: [u8; 416] = [
222, 241, 46, 66, 243, 228, 135, 233, 177, 64, 149, 170, 141, 92, 193, 106, 51, 73, 31,
27, 80, 218, 220, 248, 129, 29, 20, 128, 243, 250, 134, 39, 11, 0, 0, 0, 0, 0, 0, 0,
158, 4, 7, 240, 67, 153, 134, 190, 251, 196, 229, 95, 136, 165, 234, 228, 255, 18, 2,
187, 76, 125, 108, 50, 67, 33, 196, 108, 38, 115, 179, 86, 40, 36, 27, 5, 105, 58, 228,
94, 198, 65, 212, 218, 213, 61, 170, 21, 51, 249, 182, 121, 101, 91, 204, 25, 31, 87,
219, 208, 43, 119, 211, 185, 128, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 8, 6, 66, 65, 66, 69, 52, 2, 0, 0, 0, 0, 11,
0, 0, 0, 0, 0, 0, 0, 5, 66, 65, 66, 69, 1, 1, 188, 192, 217, 91, 138, 78, 217, 80, 8,
29, 140, 55, 242, 210, 170, 184, 73, 98, 135, 212, 236, 209, 115, 52, 200, 79, 175,
172, 242, 161, 199, 47, 236, 93, 101, 95, 43, 34, 141, 16, 247, 220, 33, 59, 31, 197,
27, 7, 196, 62, 12, 238, 236, 124, 136, 191, 29, 36, 22, 238, 242, 202, 57, 139, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 40, 23, 175, 153, 83, 6, 33, 65, 123, 51, 80, 223, 126, 186, 226, 225, 240, 105, 28,
169, 9, 54, 11, 138, 46, 194, 201, 250, 48, 242, 125, 117, 116, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 8, 6, 66, 65,
66, 69, 52, 2, 0, 0, 0, 0, 11, 0, 0, 0, 0, 0, 0, 0, 5, 66, 65, 66, 69, 1, 1, 142, 12,
124, 11, 167, 227, 103, 88, 78, 23, 228, 33, 96, 41, 207, 183, 227, 189, 114, 70, 254,
30, 128, 243, 233, 83, 214, 45, 74, 182, 120, 119, 64, 243, 219, 119, 63, 240, 205,
123, 231, 82, 205, 174, 143, 70, 2, 86, 182, 20, 16, 141, 145, 91, 116, 195, 58, 223,
175, 145, 255, 7, 121, 133
];

let equivocation_proof1: sp_consensus_babe::EquivocationProof<Header> =
Decode::decode(&mut &EQUIVOCATION_PROOF_BLOB[..]).unwrap();

let equivocation_proof2 = equivocation_proof1.clone();
}: {
sp_consensus_babe::check_equivocation_proof::<Header>(equivocation_proof1);
} verify {
assert!(sp_consensus_babe::check_equivocation_proof::<Header>(equivocation_proof2));
}
}

#[cfg(test)]
mod tests {
use super::*;
use crate::mock::*;
use frame_support::assert_ok;

#[test]
fn test_benchmarks() {
new_test_ext(3).execute_with(|| {
assert_ok!(test_benchmark_check_equivocation_proof::<Test>());
})
}

#[test]
fn test_generate_equivocation_report_blob() {
let (pairs, mut ext) = new_test_ext_with_pairs(3);

let offending_authority_index = 0;
let offending_authority_pair = &pairs[0];

ext.execute_with(|| {
start_era(1);

let equivocation_proof = generate_equivocation_proof(
offending_authority_index,
offending_authority_pair,
CurrentSlot::get() + 1,
);

println!("equivocation_proof: {:?}", equivocation_proof);
println!(
"equivocation_proof.encode(): {:?}",
equivocation_proof.encode()
);
});
}
}
3 changes: 3 additions & 0 deletions frame/babe/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ use sp_inherents::{InherentData, InherentIdentifier, MakeFatalError, ProvideInhe
pub use sp_consensus_babe::{AuthorityId, PUBLIC_KEY_LENGTH, RANDOMNESS_LENGTH, VRF_OUTPUT_LENGTH};

mod equivocation;

#[cfg(any(feature = "runtime-benchmarks", test))]
mod benchmarking;
#[cfg(all(feature = "std", test))]
mod mock;
#[cfg(all(feature = "std", test))]
Expand Down