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 all commits
Commits
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
2 changes: 2 additions & 0 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion bin/node-template/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,7 @@ impl_runtime_apis! {
Grandpa::grandpa_authorities()
}

fn submit_report_equivocation_extrinsic(
fn submit_report_equivocation_unsigned_extrinsic(
_equivocation_proof: fg_primitives::EquivocationProof<
<Block as BlockT>::Hash,
NumberFor<Block>,
Expand Down
4 changes: 1 addition & 3 deletions bin/node/cli/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -628,7 +628,6 @@ mod tests {
let check_nonce = frame_system::CheckNonce::from(index);
let check_weight = frame_system::CheckWeight::new();
let payment = pallet_transaction_payment::ChargeTransactionPayment::from(0);
let validate_grandpa_equivocation = pallet_grandpa::ValidateEquivocationReport::new();
let extra = (
check_spec_version,
check_tx_version,
Expand All @@ -637,12 +636,11 @@ mod tests {
check_nonce,
check_weight,
payment,
validate_grandpa_equivocation,
);
let raw_payload = SignedPayload::from_raw(
function,
extra,
(spec_version, transaction_version, genesis_hash, genesis_hash, (), (), (), ())
(spec_version, transaction_version, genesis_hash, genesis_hash, (), (), ())
);
let signature = raw_payload.using_encoded(|payload| {
signer.sign(payload)
Expand Down
1 change: 1 addition & 0 deletions bin/node/runtime/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ runtime-benchmarks = [
"pallet-collective/runtime-benchmarks",
"pallet-democracy/runtime-benchmarks",
"pallet-elections-phragmen/runtime-benchmarks",
"pallet-grandpa/runtime-benchmarks",
"pallet-identity/runtime-benchmarks",
"pallet-im-online/runtime-benchmarks",
"pallet-indices/runtime-benchmarks",
Expand Down
17 changes: 6 additions & 11 deletions bin/node/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -671,7 +671,6 @@ impl<LocalCall> frame_system::offchain::CreateSignedTransaction<LocalCall> for R
frame_system::CheckNonce::<Runtime>::from(nonce),
frame_system::CheckWeight::<Runtime>::new(),
pallet_transaction_payment::ChargeTransactionPayment::<Runtime>::from(tip),
pallet_grandpa::ValidateEquivocationReport::<Runtime>::new(),
);
let raw_payload = SignedPayload::new(call, extra).map_err(|e| {
debug::warn!("Unable to create signed payload: {:?}", e);
Expand Down Expand Up @@ -734,12 +733,8 @@ impl pallet_grandpa::Trait for Runtime {
GrandpaId,
)>>::IdentificationTuple;

type HandleEquivocation = pallet_grandpa::EquivocationHandler<
Self::KeyOwnerIdentification,
node_primitives::report::ReporterAppCrypto,
Runtime,
Offences,
>;
type HandleEquivocation =
pallet_grandpa::EquivocationHandler<Self::KeyOwnerIdentification, Offences>;
}

parameter_types! {
Expand Down Expand Up @@ -856,7 +851,7 @@ construct_runtime!(
Elections: pallet_elections_phragmen::{Module, Call, Storage, Event<T>, Config<T>},
TechnicalMembership: pallet_membership::<Instance1>::{Module, Call, Storage, Event<T>, Config<T>},
FinalityTracker: pallet_finality_tracker::{Module, Call, Inherent},
Grandpa: pallet_grandpa::{Module, Call, Storage, Config, Event},
Grandpa: pallet_grandpa::{Module, Call, Storage, Config, Event, ValidateUnsigned},
Treasury: pallet_treasury::{Module, Call, Storage, Config, Event<T>},
Contracts: pallet_contracts::{Module, Call, Config, Storage, Event<T>},
Sudo: pallet_sudo::{Module, Call, Config<T>, Storage, Event<T>},
Expand Down Expand Up @@ -898,7 +893,6 @@ pub type SignedExtra = (
frame_system::CheckNonce<Runtime>,
frame_system::CheckWeight<Runtime>,
pallet_transaction_payment::ChargeTransactionPayment<Runtime>,
pallet_grandpa::ValidateEquivocationReport<Runtime>,
);
/// Unchecked extrinsic type as expected by this runtime.
pub type UncheckedExtrinsic = generic::UncheckedExtrinsic<Address, Call, Signature, SignedExtra>;
Expand Down Expand Up @@ -972,7 +966,7 @@ impl_runtime_apis! {
Grandpa::grandpa_authorities()
}

fn submit_report_equivocation_extrinsic(
fn submit_report_equivocation_unsigned_extrinsic(
equivocation_proof: fg_primitives::EquivocationProof<
<Block as BlockT>::Hash,
NumberFor<Block>,
Expand All @@ -981,7 +975,7 @@ impl_runtime_apis! {
) -> Option<()> {
let key_owner_proof = key_owner_proof.decode()?;

Grandpa::submit_report_equivocation_extrinsic(
Grandpa::submit_unsigned_equivocation_report(
equivocation_proof,
key_owner_proof,
)
Expand Down Expand Up @@ -1161,6 +1155,7 @@ impl_runtime_apis! {
add_benchmark!(params, batches, pallet_collective, Council);
add_benchmark!(params, batches, pallet_democracy, Democracy);
add_benchmark!(params, batches, pallet_elections_phragmen, Elections);
add_benchmark!(params, batches, pallet_grandpa, Grandpa);
add_benchmark!(params, batches, pallet_identity, Identity);
add_benchmark!(params, batches, pallet_im_online, ImOnline);
add_benchmark!(params, batches, pallet_indices, Indices);
Expand Down
1 change: 0 additions & 1 deletion bin/node/testing/src/keyring.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ pub fn signed_extra(nonce: Index, extra_fee: Balance) -> SignedExtra {
frame_system::CheckNonce::from(nonce),
frame_system::CheckWeight::new(),
pallet_transaction_payment::ChargeTransactionPayment::from(extra_fee),
pallet_grandpa::ValidateEquivocationReport::new(),
)
}

Expand Down
2 changes: 0 additions & 2 deletions bin/utils/subkey/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -725,7 +725,6 @@ fn create_extrinsic<C: Crypto>(
frame_system::CheckNonce::<Runtime>::from(i),
frame_system::CheckWeight::<Runtime>::new(),
pallet_transaction_payment::ChargeTransactionPayment::<Runtime>::from(f),
pallet_grandpa::ValidateEquivocationReport::<Runtime>::new(),
)
};
let raw_payload = SignedPayload::from_raw(
Expand All @@ -739,7 +738,6 @@ fn create_extrinsic<C: Crypto>(
(),
(),
(),
(),
),
);
let signature = raw_payload.using_encoded(|payload| signer.sign(payload)).into_runtime();
Expand Down
8 changes: 5 additions & 3 deletions client/finality-grandpa/src/environment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -515,12 +515,14 @@ where
equivocation,
);

self.client.runtime_api()
.submit_report_equivocation_extrinsic(
self.client
.runtime_api()
.submit_report_equivocation_unsigned_extrinsic(
&BlockId::Hash(best_header.hash()),
equivocation_proof,
key_owner_proof,
).map_err(Error::Client)?;
)
.map_err(Error::Client)?;

Ok(())
}
Expand Down
2 changes: 1 addition & 1 deletion client/finality-grandpa/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ sp_api::mock_impl_runtime_apis! {
self.inner.genesis_authorities.clone()
}

fn submit_report_equivocation_extrinsic(
fn submit_report_equivocation_unsigned_extrinsic(
_equivocation_proof: EquivocationProof<Hash, BlockNumber>,
_key_owner_proof: OpaqueKeyOwnershipProof,
) -> Option<()> {
Expand Down
6 changes: 6 additions & 0 deletions frame/grandpa/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,15 @@ sp-session = { version = "2.0.0-rc4", default-features = false, path = "../../pr
sp-std = { version = "2.0.0-rc4", default-features = false, path = "../../primitives/std" }
sp-runtime = { version = "2.0.0-rc4", default-features = false, path = "../../primitives/runtime" }
sp-staking = { version = "2.0.0-rc4", default-features = false, path = "../../primitives/staking" }
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" }
pallet-session = { version = "2.0.0-rc4", default-features = false, path = "../session" }
pallet-finality-tracker = { version = "2.0.0-rc4", default-features = false, path = "../finality-tracker" }

[dev-dependencies]
frame-benchmarking = { version = "2.0.0-rc4", path = "../benchmarking" }
grandpa = { package = "finality-grandpa", version = "0.12.3", features = ["derive-codec"] }
sp-io = { version = "2.0.0-rc4", path = "../../primitives/io" }
sp-keyring = { version = "2.0.0-rc4", path = "../../primitives/keyring" }
Expand All @@ -41,6 +44,7 @@ default = ["std"]
std = [
"serde",
"codec/std",
"frame-benchmarking/std",
"sp-application-crypto/std",
"sp-core/std",
"sp-finality-grandpa/std",
Expand All @@ -50,6 +54,8 @@ std = [
"sp-runtime/std",
"sp-staking/std",
"frame-system/std",
"pallet-authorship/std",
"pallet-session/std",
"pallet-finality-tracker/std",
]
runtime-benchmarks = ["frame-benchmarking"]
106 changes: 106 additions & 0 deletions frame/grandpa/src/benchmarking.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
// 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 GRANDPA pallet.

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

use super::*;
use frame_benchmarking::benchmarks;
use sp_core::H256;

benchmarks! {
_ { }

check_equivocation_proof {
let x in 0 .. 1;

// NOTE: generated with the test below `test_generate_equivocation_report_blob`.
// the output should be deterministic since the keys we use are static.
// with the current benchmark setup it is not possible to generate this
// programatically from the benchmark setup.
const EQUIVOCATION_PROOF_BLOB: [u8; 257] = [
1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 136, 220, 52, 23,
213, 5, 142, 196, 180, 80, 62, 12, 18, 234, 26, 10, 137, 190, 32,
15, 233, 137, 34, 66, 61, 67, 52, 1, 79, 166, 176, 238, 207, 48,
195, 55, 171, 225, 252, 130, 161, 56, 151, 29, 193, 32, 25, 157,
249, 39, 80, 193, 214, 96, 167, 147, 25, 130, 45, 42, 64, 208, 182,
164, 10, 0, 0, 0, 0, 0, 0, 0, 234, 236, 231, 45, 70, 171, 135, 246,
136, 153, 38, 167, 91, 134, 150, 242, 215, 83, 56, 238, 16, 119, 55,
170, 32, 69, 255, 248, 164, 20, 57, 50, 122, 115, 135, 96, 80, 203,
131, 232, 73, 23, 149, 86, 174, 59, 193, 92, 121, 76, 154, 211, 44,
96, 10, 84, 159, 133, 211, 56, 103, 0, 59, 2, 96, 20, 69, 2, 32,
179, 16, 184, 108, 76, 215, 64, 195, 78, 143, 73, 177, 139, 20, 144,
98, 231, 41, 117, 255, 220, 115, 41, 59, 27, 75, 56, 10, 0, 0, 0, 0,
0, 0, 0, 128, 179, 250, 48, 211, 76, 10, 70, 74, 230, 219, 139, 96,
78, 88, 112, 33, 170, 44, 184, 59, 200, 155, 143, 128, 40, 222, 179,
210, 190, 84, 16, 182, 21, 34, 94, 28, 193, 163, 226, 51, 251, 134,
233, 187, 121, 63, 157, 240, 165, 203, 92, 16, 146, 120, 190, 229,
251, 129, 29, 45, 32, 29, 6
];

let equivocation_proof1: sp_finality_grandpa::EquivocationProof<H256, u64> =
Decode::decode(&mut &EQUIVOCATION_PROOF_BLOB[..]).unwrap();

let equivocation_proof2 = equivocation_proof1.clone();
}: {
sp_finality_grandpa::check_equivocation_proof(equivocation_proof1);
} verify {
assert!(sp_finality_grandpa::check_equivocation_proof(equivocation_proof2));
}
}

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

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

#[test]
fn test_generate_equivocation_report_blob() {
let authorities = crate::tests::test_authorities();

let equivocation_authority_index = 0;
let equivocation_key = &authorities[equivocation_authority_index].0;
let equivocation_keyring = extract_keyring(equivocation_key);

new_test_ext_raw_authorities(authorities).execute_with(|| {
start_era(1);

// generate an equivocation proof, with two votes in the same round for
// different block hashes signed by the same key
let equivocation_proof = generate_equivocation_proof(
1,
(1, H256::random(), 10, &equivocation_keyring),
(1, H256::random(), 10, &equivocation_keyring),
);

println!("equivocation_proof: {:?}", equivocation_proof);
println!(
"equivocation_proof.encode(): {:?}",
equivocation_proof.encode()
);
});
}
}
Loading