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

Commit

Permalink
enable BABE equivocation reporting on all runtimes
Browse files Browse the repository at this point in the history
  • Loading branch information
andresilva committed Jun 30, 2020
1 parent 17650ce commit b546b55
Show file tree
Hide file tree
Showing 6 changed files with 161 additions and 7 deletions.
10 changes: 8 additions & 2 deletions node/service/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,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,
)?;

Expand All @@ -213,6 +213,7 @@ macro_rules! new_full_start {
Some(Box::new(justification_import)),
None,
client,
select_chain,
inherent_data_providers.clone(),
spawn_task_handle,
registry,
Expand Down Expand Up @@ -516,14 +517,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)
)?;
Expand All @@ -545,6 +550,7 @@ macro_rules! new_light {
None,
Some(Box::new(finality_proof_import)),
client,
select_chain,
inherent_data_providers.clone(),
spawn_task_handle,
registry,
Expand Down
40 changes: 39 additions & 1 deletion runtime/kusama/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,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! {
Expand Down Expand Up @@ -899,7 +914,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>},
Expand Down Expand Up @@ -1152,6 +1167,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 {
Expand Down
40 changes: 39 additions & 1 deletion runtime/polkadot/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,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! {
Expand Down Expand Up @@ -874,7 +889,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>},
Expand Down Expand Up @@ -1115,6 +1130,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 {
Expand Down
28 changes: 28 additions & 0 deletions runtime/test-runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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! {
Expand Down Expand Up @@ -701,6 +715,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 {
Expand Down
40 changes: 39 additions & 1 deletion runtime/westend/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,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! {
Expand Down Expand Up @@ -666,7 +681,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>},
Expand Down Expand Up @@ -900,6 +915,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 {
Expand Down
10 changes: 8 additions & 2 deletions service/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,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,
)?;

Expand All @@ -209,6 +209,7 @@ macro_rules! new_full_start {
Some(Box::new(justification_import)),
None,
client,
select_chain,
inherent_data_providers.clone(),
spawn_task_handle,
registry,
Expand Down Expand Up @@ -572,14 +573,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)
)?;
Expand All @@ -601,6 +606,7 @@ macro_rules! new_light {
None,
Some(Box::new(finality_proof_import)),
client,
select_chain,
inherent_data_providers.clone(),
spawn_task_handle,
registry,
Expand Down

0 comments on commit b546b55

Please sign in to comment.