Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

grandpa: report equivocations #3868

Merged
merged 102 commits into from
May 6, 2020
Merged
Show file tree
Hide file tree
Changes from 61 commits
Commits
Show all changes
102 commits
Select commit Hold shift + click to select a range
df8a6d4
session: runtime api for generating session membership proofs
andresilva Aug 17, 2019
a94834e
grandpa: add runtime api for creating equivocation report txs
andresilva Aug 17, 2019
30213e4
grandpa: submit signed equivocation report transactions
andresilva Oct 18, 2019
071b3f4
grandpa: use proper equivocation report type
andresilva Oct 18, 2019
6d98987
grandpa: report equivocations
andresilva Oct 19, 2019
9df0d4d
grandpa: validate equivocation proof
andresilva Oct 21, 2019
e4435d7
grandpa: update to finality-grandpa 0.9.1
andresilva Oct 21, 2019
0497a8a
grandpa: fix encoding of session membership proof
andresilva Oct 22, 2019
b8c1c99
grandpa: initialize set id session mapping for genesis session
andresilva Oct 22, 2019
18b0d9d
grandpa: fix bug in set_id session validation
andresilva Oct 22, 2019
4848cc3
Merge branch 'master' into andre/report-grandpa-equivocations
andresilva Nov 27, 2019
c0d5453
fix compilation
andresilva Nov 27, 2019
97770a5
cleanup from merge conflicts
andresilva Nov 27, 2019
d395ff6
cleanup crate tomls
andresilva Nov 27, 2019
3962bb0
Merge branch 'master' into andre/report-grandpa-equivocations
andresilva Nov 27, 2019
a31208c
grandpa: refactor equivocation handling to separate trait
andresilva Nov 28, 2019
3d3ef58
Merge branch 'master' into andre/report-grandpa-equivocations
andresilva Dec 10, 2019
4d0b227
node-template: fix compilation
andresilva Dec 10, 2019
8e0cbf6
fix test compilation
andresilva Dec 10, 2019
2cc3d7f
bump finality-grandpa to v0.10.2
andresilva Dec 10, 2019
beb09d5
rpc: fix runtime version test
andresilva Dec 11, 2019
b9c1651
Merge branch 'master' into andre/report-grandpa-equivocations
andresilva Dec 11, 2019
d2f0a7f
CHERRY-PICK #4200: Add documentation to SubmitSignedTransaction and a…
andresilva Dec 11, 2019
044c7f0
grandpa: skip block initialization on report submission method
andresilva Dec 11, 2019
17af714
primitives: allow transaction pool access by default for offchain calls
andresilva Dec 11, 2019
29e4f94
grandpa: unused parameters
andresilva Dec 11, 2019
e69c86e
grandpa: remove unused method
andresilva Dec 11, 2019
856087d
grandpa: enable equivocation reporting
andresilva Dec 11, 2019
4e4a27b
grandpa: add workaround for parameter encoding
andresilva Dec 11, 2019
47aab63
grandpa: fix localized_payload calls in tests
andresilva Dec 11, 2019
8fc3cd3
Merge branch 'master' into andre/report-grandpa-equivocations
andresilva Dec 12, 2019
da9d216
Merge branch 'master' into andre/report-grandpa-equivocations
andresilva Dec 16, 2019
721baad
Merge branch 'master' into andre/report-grandpa-equivocations
andresilva Jan 27, 2020
44b3fde
Merge branch 'master' into andre/report-grandpa-equivocations
andresilva Jan 27, 2020
9e1586e
fix submit_report_equivocation_extrinsic in runtimes
andresilva Jan 28, 2020
a3c62ea
node: fix submit transaction test compilation
andresilva Jan 28, 2020
bd814e7
node: bump spec_version
andresilva Jan 28, 2020
9ac2c45
rpc: fix api version test
andresilva Jan 29, 2020
2059062
Merge branch 'master' into andre/report-grandpa-equivocations
andresilva Jan 31, 2020
ec2c737
Merge branch 'master' into andre/report-grandpa-equivocations
andresilva Feb 14, 2020
ee3f6b0
grandpa: allow custom equivocation offence type
andresilva Feb 24, 2020
45d2550
grandpa: add test for authorities::next_change_height
andresilva Feb 25, 2020
3b4c910
grandpa: cleanup report_equivocation function
andresilva Feb 25, 2020
aced659
node: move reporting app crypto to node-primitives
andresilva Feb 25, 2020
1c3d8a0
grandpa: move equivocation traits to own module
andresilva Feb 25, 2020
45d6d9d
grandpa: rename app-crypto crate import
andresilva Feb 25, 2020
a04d98c
Merge branch 'master' into andre/report-grandpa-equivocations
andresilva Feb 26, 2020
34a89c2
grandpa: export equivocation types
andresilva Feb 26, 2020
bcc0497
node: bump spec_version
andresilva Feb 26, 2020
2c8e808
grandpa: rename EquivocationReport to EquivocationProof
andresilva Feb 26, 2020
bea38e7
grandpa: add missing docs to primitives
andresilva Feb 26, 2020
c182781
grandpa: add missing docs to equivocation
andresilva Feb 26, 2020
0ee7249
node: fix compilation
andresilva Feb 26, 2020
18ad970
Merge branch 'master' into andre/report-grandpa-equivocations
andresilva Feb 26, 2020
237f516
grandpa: add missing docs to pallet
andresilva Feb 26, 2020
a99bea6
node: bump spec_version
andresilva Feb 26, 2020
443856b
fix whitespace
andresilva Mar 2, 2020
f8459bc
Merge branch 'master' into andre/report-grandpa-equivocations
andresilva Mar 13, 2020
6372736
grandpa: return error on offence reporting
andresilva Mar 13, 2020
2f05c6d
Merge branch 'master' into andre/report-grandpa-equivocations
andresilva Mar 25, 2020
6828d57
Merge branch 'master' into andre/report-grandpa-equivocations
andresilva Mar 30, 2020
18eb560
grandpa: expose session and validator count in proofs through traits
andresilva Apr 1, 2020
9a04120
grandpa: use strong key in module KeyOwnerProofSystem
andresilva Apr 1, 2020
5be01ef
grandpa: move key ownership proof to grandpa runtime api
andresilva Apr 1, 2020
5a24915
Merge branch 'master' into andre/report-grandpa-equivocations
andresilva Apr 1, 2020
d3304fe
grandpa: remove unnecessary cloning when checking equivocation proof
andresilva Apr 2, 2020
71d60de
grandpa: make report_equivocation a method in Environment
andresilva Apr 2, 2020
bd4c74f
support: implement KeyOwnerProofSystem for ()
andresilva Apr 8, 2020
668363f
grandpa: move KeyOwnerProofSystem to module trait
andresilva Apr 8, 2020
7658f31
test-utils: fix runtime compilation
andresilva Apr 8, 2020
97d8fb8
grandpa: fix test compilation
andresilva Apr 8, 2020
7926ab9
Merge branch 'master' into andre/report-grandpa-equivocations
andresilva Apr 8, 2020
712c78d
grandpa: fix test compilation after merge
andresilva Apr 8, 2020
ae2f6bf
grandpa: simplify transaction submission types
andresilva Apr 8, 2020
b6ef6e3
grandpa: validate equivocation report in signed extension
andresilva Apr 8, 2020
7d3cfd7
client: fix test
andresilva Apr 8, 2020
a15f483
node: use ValidateEquivocationReport signed extension
andresilva Apr 8, 2020
dca1a80
grandpa: expose key ownership proof under opaque type
andresilva Apr 8, 2020
f686072
grandpa: better docs on key ownership proofs
andresilva Apr 9, 2020
a91c2eb
grandpa: add note about signed extension
andresilva Apr 9, 2020
a3e8314
Merge branch 'master' into andre/report-grandpa-equivocations
andresilva Apr 9, 2020
88d4f32
Merge branch 'master' into andre/report-grandpa-equivocations
andresilva Apr 14, 2020
837ebbf
Merge branch 'master' into andre/report-grandpa-equivocations
andresilva Apr 17, 2020
ca43f21
grandpa: add ValidateEquivocationReport::new
andresilva Apr 17, 2020
75ec8e8
grandpa: remove skip_initialize_block from runtime api
andresilva Apr 20, 2020
e787d7f
Merge branch 'master' into andre/report-grandpa-equivocations
andresilva Apr 27, 2020
ea73e51
grandpa: use new offchain transaction submission API
andresilva Apr 27, 2020
4468c00
grandpa: take set_id in generate_key_ownership_proof
andresilva Apr 27, 2020
e8981b7
Merge branch 'master' into andre/report-grandpa-equivocations
andresilva May 5, 2020
873fe19
grandpa: update to finality-grandpa v0.12.2
andresilva May 5, 2020
207e0dc
grandpa: cleanup usages of AuthoritySet::current
andresilva May 5, 2020
94990ce
Merge branch 'master' into andre/report-grandpa-equivocations
andresilva May 5, 2020
a237061
grandpa: fix test
andresilva May 5, 2020
769d1d5
grandpa: add mocking utilities for equivocation reporting
andresilva May 5, 2020
f66ba8b
grandpa: add test for equivocation reporting
andresilva May 5, 2020
76eeee1
grandpa: move SetIdSession initialization
andresilva May 5, 2020
34e4040
grandpa: add more tests
andresilva May 5, 2020
b34ebde
node: enable historical session manager
andresilva May 5, 2020
999b671
node: bump spec_version
andresilva May 5, 2020
7f08cc1
node: use strong key types in KeyOwnerProofSystem definitions
andresilva May 6, 2020
ee614f1
Merge branch 'master' into andre/report-grandpa-equivocations
andresilva May 6, 2020
d390b74
grandpa: export GrandpaEquivocationOffence type
andresilva May 6, 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
11 changes: 11 additions & 0 deletions Cargo.lock

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

22 changes: 21 additions & 1 deletion bin/node-template/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use sp_runtime::{
transaction_validity::{TransactionValidity, TransactionSource},
};
use sp_runtime::traits::{
BlakeTwo256, Block as BlockT, IdentityLookup, Verify, ConvertInto, IdentifyAccount
BlakeTwo256, Block as BlockT, IdentityLookup, Verify, ConvertInto, IdentifyAccount, NumberFor,
};
use sp_api::impl_runtime_apis;
use sp_consensus_aura::sr25519::AuthorityId as AuraId;
Expand Down Expand Up @@ -175,6 +175,8 @@ impl aura::Trait for Runtime {

impl grandpa::Trait for Runtime {
type Event = Event;
type Call = Call;
type HandleEquivocation = ();
}

parameter_types! {
Expand Down Expand Up @@ -354,9 +356,27 @@ impl_runtime_apis! {
}
}

impl sp_session::SessionMembership<Block> for Runtime {
fn generate_session_membership_proof(
_session_key: (sp_core::crypto::KeyTypeId, Vec<u8>),
) -> Option<sp_session::MembershipProof> {
None
}
}

impl fg_primitives::GrandpaApi<Block> for Runtime {
fn grandpa_authorities() -> GrandpaAuthorityList {
Grandpa::grandpa_authorities()
}

fn submit_report_equivocation_extrinsic(
_equivocation_proof: fg_primitives::EquivocationProof<
<Block as BlockT>::Hash,
NumberFor<Block>,
>,
_key_owner_proof: Vec<u8>,
) -> Option<()> {
None
}
}
}
4 changes: 4 additions & 0 deletions bin/node/primitives/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ homepage = "https://substrate.dev"
repository = "https://github.com/paritytech/substrate/"

[dependencies]
codec = { package = "parity-scale-codec", version = "1.3.0", default-features = false, features = ["derive"] }
sp-application-crypto = { version = "2.0.0-alpha.5", default-features = false, path = "../../../primitives/application-crypto" }
sp-core = { version = "2.0.0-alpha.5", default-features = false, path = "../../../primitives/core" }
sp-runtime = { version = "2.0.0-alpha.5", default-features = false, path = "../../../primitives/runtime" }

Expand All @@ -18,6 +20,8 @@ pretty_assertions = "0.6.1"
[features]
default = ["std"]
std = [
"codec/std",
"sp-application-crypto/std",
"sp-core/std",
"sp-runtime/std",
]
Expand Down
29 changes: 29 additions & 0 deletions bin/node/primitives/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,3 +62,32 @@ pub type Header = generic::Header<BlockNumber, BlakeTwo256>;
pub type Block = generic::Block<Header, OpaqueExtrinsic>;
/// Block ID.
pub type BlockId = generic::BlockId<Block>;

/// App-specific crypto used for reporting equivocation/misbehavior in BABE and
/// GRANDPA. The crypto used is sr25519 and the account must be minimally funded
/// in order to pay for transaction fees. Any rewards for misbehavior reporting
/// will be paid out to this account.
pub mod report {
use sp_core::crypto::KeyTypeId;

/// Key type for the reporting module. Used for reporting BABE and GRANDPA
/// equivocations.
pub const KEY_TYPE: KeyTypeId = KeyTypeId(*b"fish");
kianenigma marked this conversation as resolved.
Show resolved Hide resolved
andresilva marked this conversation as resolved.
Show resolved Hide resolved

mod app {
use sp_application_crypto::{app_crypto, sr25519};

app_crypto!(sr25519, super::KEY_TYPE);

impl sp_runtime::traits::IdentifyAccount for Public {
type AccountId = sp_runtime::AccountId32;

fn into_account(self) -> Self::AccountId {
sp_runtime::MultiSigner::from(self.0).into_account()
}
}
}

/// Identity of the equivocation/misbehavior reporter.
pub type ReporterId = app::Public;
}
36 changes: 35 additions & 1 deletion bin/node/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ use sp_runtime::curve::PiecewiseLinear;
use sp_runtime::transaction_validity::{TransactionValidity, TransactionSource};
use sp_runtime::traits::{
self, BlakeTwo256, Block as BlockT, StaticLookup, SaturatedConversion,
ConvertInto, OpaqueKeys,
ConvertInto, OpaqueKeys, NumberFor,
};
use sp_version::RuntimeVersion;
#[cfg(any(feature = "std", test))]
Expand All @@ -50,6 +50,7 @@ use pallet_im_online::sr25519::{AuthorityId as ImOnlineId};
use sp_authority_discovery::AuthorityId as AuthorityDiscoveryId;
use pallet_transaction_payment_rpc_runtime_api::RuntimeDispatchInfo;
use pallet_contracts_rpc_runtime_api::ContractExecResult;
use pallet_session::{historical as pallet_session_historical};
use frame_system::offchain::TransactionSubmitter;
use sp_inherents::{InherentData, CheckInherentsResult};

Expand Down Expand Up @@ -545,6 +546,13 @@ impl pallet_authority_discovery::Trait for Runtime {}

impl pallet_grandpa::Trait for Runtime {
type Event = Event;
type Call = Call;
type HandleEquivocation = pallet_grandpa::EquivocationHandler<
Historical,
TransactionSubmitterOf<node_primitives::report::ReporterId>,
andresilva marked this conversation as resolved.
Show resolved Hide resolved
Offences,
node_primitives::report::ReporterId,
>;
}

parameter_types! {
Expand Down Expand Up @@ -662,6 +670,7 @@ construct_runtime!(
ImOnline: pallet_im_online::{Module, Call, Storage, Event<T>, ValidateUnsigned, Config<T>},
AuthorityDiscovery: pallet_authority_discovery::{Module, Call, Config},
Offences: pallet_offences::{Module, Call, Storage, Event},
Historical: pallet_session_historical::{Module},
RandomnessCollectiveFlip: pallet_randomness_collective_flip::{Module, Call, Storage},
Identity: pallet_identity::{Module, Call, Storage, Event<T>},
Society: pallet_society::{Module, Call, Storage, Event<T>, Config<T>},
Expand Down Expand Up @@ -762,6 +771,21 @@ impl_runtime_apis! {
fn grandpa_authorities() -> GrandpaAuthorityList {
Grandpa::grandpa_authorities()
}

fn submit_report_equivocation_extrinsic(
equivocation_proof: fg_primitives::EquivocationProof<
<Block as BlockT>::Hash,
NumberFor<Block>,
>,
key_owner_proof: Vec<u8>,
) -> Option<()> {
let key_owner_proof = codec::Decode::decode(&mut &key_owner_proof[..]).ok()?;

Grandpa::submit_report_equivocation_extrinsic(
equivocation_proof,
key_owner_proof,
)
}
}

impl sp_consensus_babe::BabeApi<Block> for Runtime {
Expand Down Expand Up @@ -855,6 +879,16 @@ impl_runtime_apis! {
}
}

impl sp_session::SessionMembership<Block> for Runtime {
fn generate_session_membership_proof(
session_key: (sp_core::crypto::KeyTypeId, Vec<u8>),
andresilva marked this conversation as resolved.
Show resolved Hide resolved
) -> Option<sp_session::MembershipProof> {
use frame_support::traits::KeyOwnerProofSystem;

Historical::prove(session_key)
}
}

#[cfg(feature = "runtime-benchmarks")]
impl frame_benchmarking::Benchmark<Block> for Runtime {
fn dispatch_benchmark(
Expand Down
1 change: 1 addition & 0 deletions client/finality-grandpa/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ assert_matches = "1.3.0"
parity-scale-codec = { version = "1.3.0", features = ["derive"] }
sp-arithmetic = { version = "2.0.0-alpha.5", path = "../../primitives/arithmetic" }
sp-runtime = { version = "2.0.0-alpha.5", path = "../../primitives/runtime" }
sp-session = { version = "2.0.0-alpha.5", path = "../../primitives/session" }
sp-consensus = { version = "0.8.0-alpha.5", path = "../../primitives/consensus/common" }
sp-core = { version = "2.0.0-alpha.5", path = "../../primitives/core" }
sp-api = { version = "2.0.0-alpha.5", path = "../../primitives/api" }
Expand Down
Loading