mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-05-30 07:01:03 +00:00
grandpa: report equivocations on all runtimes (#1000)
* grandpa: report equivocations on all runtimes * runtime: fix test-runtime compilation * runtime: enable historical session manager on all runtimes * runtime: fix indentation * runtime: use strong key types in KeyOwnerProofSystem definitions * update substrate * bump spec_version of runtimes
This commit is contained in:
@@ -83,7 +83,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
|
||||
spec_name: create_runtime_str!("kusama"),
|
||||
impl_name: create_runtime_str!("parity-kusama"),
|
||||
authoring_version: 2,
|
||||
spec_version: 1062,
|
||||
spec_version: 1063,
|
||||
impl_version: 0,
|
||||
apis: RUNTIME_API_VERSIONS,
|
||||
transaction_version: 1,
|
||||
@@ -267,7 +267,7 @@ impl session::Trait for Runtime {
|
||||
type ValidatorIdOf = staking::StashOf<Self>;
|
||||
type ShouldEndSession = Babe;
|
||||
type NextSessionRotation = Babe;
|
||||
type SessionManager = Staking;
|
||||
type SessionManager = session::historical::NoteHistoricalRoot<Self, Staking>;
|
||||
type SessionHandler = <SessionKeys as OpaqueKeys>::KeyTypeIdProviders;
|
||||
type Keys = SessionKeys;
|
||||
type DisabledValidatorsThreshold = DisabledValidatorsThreshold;
|
||||
@@ -490,6 +490,24 @@ impl im_online::Trait for Runtime {
|
||||
|
||||
impl grandpa::Trait for Runtime {
|
||||
type Event = Event;
|
||||
type Call = Call;
|
||||
|
||||
type KeyOwnerProofSystem = Historical;
|
||||
|
||||
type KeyOwnerProof =
|
||||
<Self::KeyOwnerProofSystem as KeyOwnerProofSystem<(KeyTypeId, GrandpaId)>>::Proof;
|
||||
|
||||
type KeyOwnerIdentification = <Self::KeyOwnerProofSystem as KeyOwnerProofSystem<(
|
||||
KeyTypeId,
|
||||
GrandpaId,
|
||||
)>>::IdentificationTuple;
|
||||
|
||||
type HandleEquivocation = grandpa::EquivocationHandler<
|
||||
Self::KeyOwnerIdentification,
|
||||
primitives::fisherman::FishermanAppCrypto,
|
||||
Runtime,
|
||||
Offences,
|
||||
>;
|
||||
}
|
||||
|
||||
parameter_types! {
|
||||
@@ -522,7 +540,7 @@ parameter_types! {
|
||||
}
|
||||
|
||||
impl parachains::Trait for Runtime {
|
||||
type AuthorityId = parachains::FishermanAuthorityId;
|
||||
type AuthorityId = primitives::fisherman::FishermanAppCrypto;
|
||||
type Origin = Origin;
|
||||
type Call = Call;
|
||||
type ParachainCurrency = Balances;
|
||||
@@ -537,13 +555,15 @@ impl parachains::Trait for Runtime {
|
||||
type ValidationUpgradeDelay = ValidationUpgradeDelay;
|
||||
type SlashPeriod = SlashPeriod;
|
||||
|
||||
type Proof = session::historical::Proof;
|
||||
type Proof = sp_session::MembershipProof;
|
||||
type KeyOwnerProofSystem = session::historical::Module<Self>;
|
||||
type IdentificationTuple = <Self::KeyOwnerProofSystem as KeyOwnerProofSystem<(KeyTypeId, Vec<u8>)>>::IdentificationTuple;
|
||||
type ReportOffence = Offences;
|
||||
type BlockHashConversion = sp_runtime::traits::Identity;
|
||||
}
|
||||
|
||||
/// Submits transaction with the node's public and signature type. Adheres to the signed extension
|
||||
/// format of the chain.
|
||||
impl<LocalCall> system::offchain::CreateSignedTransaction<LocalCall> for Runtime where
|
||||
Call: From<LocalCall>,
|
||||
{
|
||||
@@ -553,6 +573,7 @@ impl<LocalCall> system::offchain::CreateSignedTransaction<LocalCall> for Runtime
|
||||
account: AccountId,
|
||||
nonce: <Runtime as system::Trait>::Index,
|
||||
) -> Option<(Call, <UncheckedExtrinsic as ExtrinsicT>::SignaturePayload)> {
|
||||
// take the biggest period possible.
|
||||
let period = BlockHashCount::get()
|
||||
.checked_next_power_of_two()
|
||||
.map(|c| c / 2)
|
||||
@@ -560,6 +581,8 @@ impl<LocalCall> system::offchain::CreateSignedTransaction<LocalCall> for Runtime
|
||||
|
||||
let current_block = System::block_number()
|
||||
.saturated_into::<u64>()
|
||||
// The `System::block_number` is initialized with `n+1`,
|
||||
// so the actual block number is `n`.
|
||||
.saturating_sub(1);
|
||||
let tip = 0;
|
||||
let extra: SignedExtra = (
|
||||
@@ -572,6 +595,7 @@ impl<LocalCall> system::offchain::CreateSignedTransaction<LocalCall> for Runtime
|
||||
transaction_payment::ChargeTransactionPayment::<Runtime>::from(tip),
|
||||
registrar::LimitParathreadCommits::<Runtime>::new(),
|
||||
parachains::ValidateDoubleVoteReports::<Runtime>::new(),
|
||||
grandpa::ValidateEquivocationReport::<Runtime>::new(),
|
||||
);
|
||||
let raw_payload = SignedPayload::new(call, extra).map_err(|e| {
|
||||
debug::warn!("Unable to create signed payload: {:?}", e);
|
||||
@@ -818,9 +842,10 @@ pub type SignedExtra = (
|
||||
system::CheckEra<Runtime>,
|
||||
system::CheckNonce<Runtime>,
|
||||
system::CheckWeight<Runtime>,
|
||||
transaction_payment::ChargeTransactionPayment::<Runtime>,
|
||||
transaction_payment::ChargeTransactionPayment<Runtime>,
|
||||
registrar::LimitParathreadCommits<Runtime>,
|
||||
parachains::ValidateDoubleVoteReports<Runtime>,
|
||||
grandpa::ValidateEquivocationReport<Runtime>,
|
||||
);
|
||||
/// Unchecked extrinsic type as expected by this runtime.
|
||||
pub type UncheckedExtrinsic = generic::UncheckedExtrinsic<Address, Call, Signature, SignedExtra>;
|
||||
@@ -935,6 +960,32 @@ sp_api::impl_runtime_apis! {
|
||||
fn grandpa_authorities() -> Vec<(GrandpaId, u64)> {
|
||||
Grandpa::grandpa_authorities()
|
||||
}
|
||||
|
||||
fn submit_report_equivocation_extrinsic(
|
||||
equivocation_proof: fg_primitives::EquivocationProof<
|
||||
<Block as BlockT>::Hash,
|
||||
sp_runtime::traits::NumberFor<Block>,
|
||||
>,
|
||||
key_owner_proof: fg_primitives::OpaqueKeyOwnershipProof,
|
||||
) -> Option<()> {
|
||||
let key_owner_proof = key_owner_proof.decode()?;
|
||||
|
||||
Grandpa::submit_report_equivocation_extrinsic(
|
||||
equivocation_proof,
|
||||
key_owner_proof,
|
||||
)
|
||||
}
|
||||
|
||||
fn generate_key_ownership_proof(
|
||||
_set_id: fg_primitives::SetId,
|
||||
authority_id: fg_primitives::AuthorityId,
|
||||
) -> Option<fg_primitives::OpaqueKeyOwnershipProof> {
|
||||
use codec::Encode;
|
||||
|
||||
Historical::prove((fg_primitives::KEY_TYPE, authority_id))
|
||||
.map(|p| p.encode())
|
||||
.map(fg_primitives::OpaqueKeyOwnershipProof::new)
|
||||
}
|
||||
}
|
||||
|
||||
impl babe_primitives::BabeApi<Block> for Runtime {
|
||||
|
||||
Reference in New Issue
Block a user