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

babe: enable equivocation reporting on all runtimes #1330

Merged
merged 6 commits into from
Jul 4, 2020
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
290 changes: 154 additions & 136 deletions Cargo.lock

Large diffs are not rendered by default.

10 changes: 8 additions & 2 deletions node/service/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)?;

Expand All @@ -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,
Expand Down Expand Up @@ -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)
)?;
Expand All @@ -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,
Expand Down
14 changes: 14 additions & 0 deletions runtime/common/src/parachains.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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! {
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 @@ -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! {
Expand Down Expand Up @@ -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>},
Expand Down Expand Up @@ -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 {
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 @@ -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! {
Expand Down Expand Up @@ -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>},
Expand Down Expand Up @@ -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 {
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 @@ -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 {
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 @@ -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! {
Expand Down Expand Up @@ -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>},
Expand Down Expand Up @@ -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 {
Expand Down
10 changes: 8 additions & 2 deletions service/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)?;

Expand All @@ -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,
Expand Down Expand Up @@ -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)
)?;
Expand All @@ -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,
Expand Down