Unverified Commit 78e6e08e authored by André Silva's avatar André Silva Committed by GitHub
Browse files

babe: enable equivocation reporting on all runtimes (#1330)



* enable BABE equivocation reporting on all runtimes

* runtime: fix parachains mock test runtime

* cargo update -p sp-io
Co-authored-by: Shawn Tabrizi's avatarShawn Tabrizi <shawntabrizi@gmail.com>
parent 21f31f78
Pipeline #99405 passed with stages
in 21 minutes and 19 seconds
This diff is collapsed.
......@@ -196,7 +196,7 @@ macro_rules! new_full_start {
grandpa::block_import_with_authority_set_hard_forks(
client.clone(),
&(client.clone() as Arc<_>),
select_chain,
select_chain.clone(),
grandpa_hard_forks,
)?;
......@@ -214,6 +214,7 @@ macro_rules! new_full_start {
Some(Box::new(justification_import)),
None,
client,
select_chain,
inherent_data_providers.clone(),
spawn_task_handle,
registry,
......@@ -517,14 +518,18 @@ macro_rules! new_light {
client,
backend,
fetcher,
_select_chain,
mut select_chain,
_,
spawn_task_handle,
registry,
| {
let select_chain = select_chain.take()
.ok_or_else(|| service::Error::SelectChainRequired)?;
let fetch_checker = fetcher
.map(|fetcher| fetcher.checker().clone())
.ok_or_else(|| "Trying to start light import queue without active fetch checker")?;
let grandpa_block_import = grandpa::light_block_import(
client.clone(), backend, &(client.clone() as Arc<_>), Arc::new(fetch_checker)
)?;
......@@ -546,6 +551,7 @@ macro_rules! new_light {
None,
Some(Box::new(finality_proof_import)),
client,
select_chain,
inherent_data_providers.clone(),
spawn_task_handle,
registry,
......
......@@ -1834,6 +1834,20 @@ mod tests {
// session module is the trigger
type EpochChangeTrigger = babe::ExternalTrigger;
type KeyOwnerProofSystem = ();
type KeyOwnerProof = <Self::KeyOwnerProofSystem as KeyOwnerProofSystem<(
KeyTypeId,
babe::AuthorityId,
)>>::Proof;
type KeyOwnerIdentification = <Self::KeyOwnerProofSystem as KeyOwnerProofSystem<(
KeyTypeId,
babe::AuthorityId,
)>>::IdentificationTuple;
type HandleEquivocation = ();
}
parameter_types! {
......
......@@ -169,6 +169,21 @@ impl babe::Trait for Runtime {
// session module is the trigger
type EpochChangeTrigger = babe::ExternalTrigger;
type KeyOwnerProofSystem = Historical;
type KeyOwnerProof = <Self::KeyOwnerProofSystem as KeyOwnerProofSystem<(
KeyTypeId,
babe::AuthorityId,
)>>::Proof;
type KeyOwnerIdentification = <Self::KeyOwnerProofSystem as KeyOwnerProofSystem<(
KeyTypeId,
babe::AuthorityId,
)>>::IdentificationTuple;
type HandleEquivocation =
babe::EquivocationHandler<Self::KeyOwnerIdentification, Offences>;
}
parameter_types! {
......@@ -913,7 +928,7 @@ construct_runtime! {
RandomnessCollectiveFlip: randomness_collective_flip::{Module, Storage},
// Must be before session.
Babe: babe::{Module, Call, Storage, Config, Inherent(Timestamp)},
Babe: babe::{Module, Call, Storage, Config, Inherent(Timestamp), ValidateUnsigned},
Timestamp: timestamp::{Module, Call, Storage, Inherent},
Indices: indices::{Module, Call, Storage, Config<T>, Event<T>},
......@@ -1170,6 +1185,29 @@ sp_api::impl_runtime_apis! {
fn current_epoch_start() -> babe_primitives::SlotNumber {
Babe::current_epoch_start()
}
fn generate_key_ownership_proof(
_slot_number: babe_primitives::SlotNumber,
authority_id: babe_primitives::AuthorityId,
) -> Option<babe_primitives::OpaqueKeyOwnershipProof> {
use codec::Encode;
Historical::prove((babe_primitives::KEY_TYPE, authority_id))
.map(|p| p.encode())
.map(babe_primitives::OpaqueKeyOwnershipProof::new)
}
fn submit_report_equivocation_unsigned_extrinsic(
equivocation_proof: babe_primitives::EquivocationProof<<Block as BlockT>::Header>,
key_owner_proof: babe_primitives::OpaqueKeyOwnershipProof,
) -> Option<()> {
let key_owner_proof = key_owner_proof.decode()?;
Babe::submit_unsigned_equivocation_report(
equivocation_proof,
key_owner_proof,
)
}
}
impl authority_discovery_primitives::AuthorityDiscoveryApi<Block> for Runtime {
......
......@@ -200,6 +200,21 @@ impl babe::Trait for Runtime {
// session module is the trigger
type EpochChangeTrigger = babe::ExternalTrigger;
type KeyOwnerProofSystem = Historical;
type KeyOwnerProof = <Self::KeyOwnerProofSystem as KeyOwnerProofSystem<(
KeyTypeId,
babe::AuthorityId,
)>>::Proof;
type KeyOwnerIdentification = <Self::KeyOwnerProofSystem as KeyOwnerProofSystem<(
KeyTypeId,
babe::AuthorityId,
)>>::IdentificationTuple;
type HandleEquivocation =
babe::EquivocationHandler<Self::KeyOwnerIdentification, Offences>;
}
parameter_types! {
......@@ -919,7 +934,7 @@ construct_runtime! {
Scheduler: scheduler::{Module, Call, Storage, Event<T>},
// Must be before session.
Babe: babe::{Module, Call, Storage, Config, Inherent(Timestamp)},
Babe: babe::{Module, Call, Storage, Config, Inherent(Timestamp), ValidateUnsigned},
Timestamp: timestamp::{Module, Call, Storage, Inherent},
Indices: indices::{Module, Call, Storage, Config<T>, Event<T>},
......@@ -1171,6 +1186,29 @@ sp_api::impl_runtime_apis! {
fn current_epoch_start() -> babe_primitives::SlotNumber {
Babe::current_epoch_start()
}
fn generate_key_ownership_proof(
_slot_number: babe_primitives::SlotNumber,
authority_id: babe_primitives::AuthorityId,
) -> Option<babe_primitives::OpaqueKeyOwnershipProof> {
use codec::Encode;
Historical::prove((babe_primitives::KEY_TYPE, authority_id))
.map(|p| p.encode())
.map(babe_primitives::OpaqueKeyOwnershipProof::new)
}
fn submit_report_equivocation_unsigned_extrinsic(
equivocation_proof: babe_primitives::EquivocationProof<<Block as BlockT>::Header>,
key_owner_proof: babe_primitives::OpaqueKeyOwnershipProof,
) -> Option<()> {
let key_owner_proof = key_owner_proof.decode()?;
Babe::submit_unsigned_equivocation_report(
equivocation_proof,
key_owner_proof,
)
}
}
impl authority_discovery_primitives::AuthorityDiscoveryApi<Block> for Runtime {
......
......@@ -175,6 +175,20 @@ impl babe::Trait for Runtime {
// session module is the trigger
type EpochChangeTrigger = babe::ExternalTrigger;
type KeyOwnerProofSystem = ();
type KeyOwnerProof = <Self::KeyOwnerProofSystem as KeyOwnerProofSystem<(
KeyTypeId,
babe::AuthorityId,
)>>::Proof;
type KeyOwnerIdentification = <Self::KeyOwnerProofSystem as KeyOwnerProofSystem<(
KeyTypeId,
babe::AuthorityId,
)>>::IdentificationTuple;
type HandleEquivocation = ();
}
parameter_types! {
......@@ -704,6 +718,20 @@ sp_api::impl_runtime_apis! {
fn current_epoch_start() -> babe_primitives::SlotNumber {
Babe::current_epoch_start()
}
fn generate_key_ownership_proof(
_slot_number: babe_primitives::SlotNumber,
_authority_id: babe_primitives::AuthorityId,
) -> Option<babe_primitives::OpaqueKeyOwnershipProof> {
None
}
fn submit_report_equivocation_unsigned_extrinsic(
_equivocation_proof: babe_primitives::EquivocationProof<<Block as BlockT>::Header>,
_key_owner_proof: babe_primitives::OpaqueKeyOwnershipProof,
) -> Option<()> {
None
}
}
impl sp_session::SessionKeys<Block> for Runtime {
......
......@@ -159,6 +159,21 @@ impl babe::Trait for Runtime {
// session module is the trigger
type EpochChangeTrigger = babe::ExternalTrigger;
type KeyOwnerProofSystem = Historical;
type KeyOwnerProof = <Self::KeyOwnerProofSystem as KeyOwnerProofSystem<(
KeyTypeId,
babe::AuthorityId,
)>>::Proof;
type KeyOwnerIdentification = <Self::KeyOwnerProofSystem as KeyOwnerProofSystem<(
KeyTypeId,
babe::AuthorityId,
)>>::IdentificationTuple;
type HandleEquivocation =
babe::EquivocationHandler<Self::KeyOwnerIdentification, Offences>;
}
parameter_types! {
......@@ -677,7 +692,7 @@ construct_runtime! {
RandomnessCollectiveFlip: randomness_collective_flip::{Module, Storage},
// Must be before session.
Babe: babe::{Module, Call, Storage, Config, Inherent(Timestamp)},
Babe: babe::{Module, Call, Storage, Config, Inherent(Timestamp), ValidateUnsigned},
Timestamp: timestamp::{Module, Call, Storage, Inherent},
Indices: indices::{Module, Call, Storage, Config<T>, Event<T>},
......@@ -915,6 +930,29 @@ sp_api::impl_runtime_apis! {
fn current_epoch_start() -> babe_primitives::SlotNumber {
Babe::current_epoch_start()
}
fn generate_key_ownership_proof(
_slot_number: babe_primitives::SlotNumber,
authority_id: babe_primitives::AuthorityId,
) -> Option<babe_primitives::OpaqueKeyOwnershipProof> {
use codec::Encode;
Historical::prove((babe_primitives::KEY_TYPE, authority_id))
.map(|p| p.encode())
.map(babe_primitives::OpaqueKeyOwnershipProof::new)
}
fn submit_report_equivocation_unsigned_extrinsic(
equivocation_proof: babe_primitives::EquivocationProof<<Block as BlockT>::Header>,
key_owner_proof: babe_primitives::OpaqueKeyOwnershipProof,
) -> Option<()> {
let key_owner_proof = key_owner_proof.decode()?;
Babe::submit_unsigned_equivocation_report(
equivocation_proof,
key_owner_proof,
)
}
}
impl authority_discovery_primitives::AuthorityDiscoveryApi<Block> for Runtime {
......
......@@ -192,7 +192,7 @@ macro_rules! new_full_start {
grandpa::block_import_with_authority_set_hard_forks(
client.clone(),
&(client.clone() as Arc<_>),
select_chain,
select_chain.clone(),
grandpa_hard_forks,
)?;
......@@ -210,6 +210,7 @@ macro_rules! new_full_start {
Some(Box::new(justification_import)),
None,
client,
select_chain,
inherent_data_providers.clone(),
spawn_task_handle,
registry,
......@@ -573,14 +574,18 @@ macro_rules! new_light {
client,
backend,
fetcher,
_select_chain,
mut select_chain,
_,
spawn_task_handle,
registry,
| {
let select_chain = select_chain.take()
.ok_or_else(|| service::Error::SelectChainRequired)?;
let fetch_checker = fetcher
.map(|fetcher| fetcher.checker().clone())
.ok_or_else(|| "Trying to start light import queue without active fetch checker")?;
let grandpa_block_import = grandpa::light_block_import(
client.clone(), backend, &(client.clone() as Arc<_>), Arc::new(fetch_checker)
)?;
......@@ -602,6 +607,7 @@ macro_rules! new_light {
None,
Some(Box::new(finality_proof_import)),
client,
select_chain,
inherent_data_providers.clone(),
spawn_task_handle,
registry,
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment