From a92d2135a49ee76fd301655febc77452d4ef131f Mon Sep 17 00:00:00 2001 From: Serban Iorga Date: Thu, 12 Oct 2023 10:08:35 +0300 Subject: [PATCH] Millau, Rialto: accept equivocation reports (#2614) (#2617) --- Cargo.lock | 4 +++ bin/millau/runtime/Cargo.toml | 4 +++ bin/millau/runtime/src/lib.rs | 43 ++++++++++++++++++++++++++++++--- bin/rialto/runtime/Cargo.toml | 4 +++ bin/rialto/runtime/src/lib.rs | 37 +++++++++++++++++++++++++--- relays/client-millau/src/lib.rs | 5 ++-- relays/client-rialto/src/lib.rs | 5 ++-- 7 files changed, 92 insertions(+), 10 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 71c1598c243e4..aeed4ffd7e206 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -6560,6 +6560,7 @@ dependencies = [ "frame-system-rpc-runtime-api", "hex-literal", "pallet-aura", + "pallet-authorship", "pallet-balances", "pallet-beefy", "pallet-beefy-mmr", @@ -6569,6 +6570,7 @@ dependencies = [ "pallet-bridge-relayers", "pallet-grandpa", "pallet-mmr", + "pallet-offences", "pallet-session", "pallet-shift-session-manager", "pallet-sudo", @@ -11061,6 +11063,7 @@ dependencies = [ "frame-system", "frame-system-rpc-runtime-api", "pallet-authority-discovery", + "pallet-authorship", "pallet-babe", "pallet-balances", "pallet-beefy", @@ -11072,6 +11075,7 @@ dependencies = [ "pallet-grandpa", "pallet-message-queue", "pallet-mmr", + "pallet-offences", "pallet-session", "pallet-shift-session-manager", "pallet-sudo", diff --git a/bin/millau/runtime/Cargo.toml b/bin/millau/runtime/Cargo.toml index 57586fb961f7a..861a40120dbc3 100644 --- a/bin/millau/runtime/Cargo.toml +++ b/bin/millau/runtime/Cargo.toml @@ -41,11 +41,13 @@ frame-support = { git = "https://github.com/paritytech/polkadot-sdk", branch = " frame-system = { git = "https://github.com/paritytech/polkadot-sdk", branch = "master", default-features = false } frame-system-rpc-runtime-api = { git = "https://github.com/paritytech/polkadot-sdk", branch = "master", default-features = false } pallet-aura = { git = "https://github.com/paritytech/polkadot-sdk", branch = "master", default-features = false } +pallet-authorship = { git = "https://github.com/paritytech/polkadot-sdk", branch = "master", default-features = false } pallet-balances = { git = "https://github.com/paritytech/polkadot-sdk", branch = "master", default-features = false } pallet-beefy = { git = "https://github.com/paritytech/polkadot-sdk", branch = "master", default-features = false } pallet-beefy-mmr = { git = "https://github.com/paritytech/polkadot-sdk", branch = "master", default-features = false } pallet-grandpa = { git = "https://github.com/paritytech/polkadot-sdk", branch = "master", default-features = false } pallet-mmr = { git = "https://github.com/paritytech/polkadot-sdk", branch = "master", default-features = false } +pallet-offences = { git = "https://github.com/paritytech/polkadot-sdk", branch = "master", default-features = false } pallet-session = { git = "https://github.com/paritytech/polkadot-sdk", branch = "master", default-features = false, features = ["historical"]} pallet-sudo = { git = "https://github.com/paritytech/polkadot-sdk", branch = "master", default-features = false } pallet-timestamp = { git = "https://github.com/paritytech/polkadot-sdk", branch = "master", default-features = false } @@ -100,6 +102,7 @@ std = [ "frame-system-rpc-runtime-api/std", "frame-system/std", "pallet-aura/std", + "pallet-authorship/std", "pallet-balances/std", "pallet-beefy/std", "pallet-beefy-mmr/std", @@ -109,6 +112,7 @@ std = [ "pallet-bridge-relayers/std", "pallet-grandpa/std", "pallet-mmr/std", + "pallet-offences/std", "pallet-session/std", "pallet-shift-session-manager/std", "pallet-sudo/std", diff --git a/bin/millau/runtime/src/lib.rs b/bin/millau/runtime/src/lib.rs index 9abe5ce69c096..cf2b887d1ab44 100644 --- a/bin/millau/runtime/src/lib.rs +++ b/bin/millau/runtime/src/lib.rs @@ -49,7 +49,7 @@ use sp_runtime::{ create_runtime_str, generic, impl_opaque_keys, traits::{Block as BlockT, IdentityLookup, Keccak256, NumberFor, OpaqueKeys}, transaction_validity::{TransactionSource, TransactionValidity}, - ApplyExtrinsicResult, FixedPointNumber, Perquintill, + ApplyExtrinsicResult, FixedPointNumber, KeyTypeId, Perquintill, }; use sp_std::prelude::*; #[cfg(feature = "std")] @@ -249,8 +249,9 @@ impl pallet_grandpa::Config for Runtime { type WeightInfo = (); type MaxAuthorities = ConstU32<10>; type MaxSetIdSessionEntries = ConstU64<0>; - type KeyOwnerProof = sp_core::Void; - type EquivocationReportSystem = (); + type KeyOwnerProof = >::Proof; + type EquivocationReportSystem = + pallet_grandpa::EquivocationReportSystem; type MaxNominators = ConstU32<256>; } @@ -377,6 +378,7 @@ parameter_types! { pub const Period: BlockNumber = bp_millau::SESSION_LENGTH; pub const Offset: BlockNumber = 0; pub const RelayerStakeReserveId: [u8; 8] = *b"brdgrlrs"; + pub ReportLongevity: u64 = Period::get() * 10; } impl pallet_session::Config for Runtime { @@ -392,6 +394,37 @@ impl pallet_session::Config for Runtime { type WeightInfo = (); } +impl frame_system::offchain::SendTransactionTypes for Runtime +where + RuntimeCall: From, +{ + type Extrinsic = UncheckedExtrinsic; + type OverarchingCall = RuntimeCall; +} + +impl pallet_authorship::Config for Runtime { + type FindAuthor = pallet_session::FindAccountFromAuthorIndex; + type EventHandler = (); +} + +pub struct FullIdentificationOf; +impl sp_runtime::traits::Convert> for FullIdentificationOf { + fn convert(_: AccountId) -> Option<()> { + Some(()) + } +} + +impl pallet_session::historical::Config for Runtime { + type FullIdentification = (); + type FullIdentificationOf = FullIdentificationOf; +} + +impl pallet_offences::Config for Runtime { + type RuntimeEvent = RuntimeEvent; + type IdentificationTuple = pallet_session::historical::IdentificationTuple; + type OnOffenceHandler = (); +} + impl pallet_bridge_relayers::Config for Runtime { type RuntimeEvent = RuntimeEvent; type Reward = Balance; @@ -582,6 +615,10 @@ construct_runtime!( TransactionPayment: pallet_transaction_payment::{Pallet, Storage, Event}, // Consensus support. + Authorship: pallet_authorship::{Pallet, Storage}, + Offences: pallet_offences::{Pallet, Storage, Event}, + Historical: pallet_session::historical::{Pallet}, + Session: pallet_session::{Pallet, Call, Storage, Event, Config}, Grandpa: pallet_grandpa::{Pallet, Call, Storage, Config, Event}, ShiftSessionManager: pallet_shift_session_manager::{Pallet}, diff --git a/bin/rialto/runtime/Cargo.toml b/bin/rialto/runtime/Cargo.toml index d8b402d310979..7bd89803cafac 100644 --- a/bin/rialto/runtime/Cargo.toml +++ b/bin/rialto/runtime/Cargo.toml @@ -34,6 +34,7 @@ frame-support = { git = "https://github.com/paritytech/polkadot-sdk", branch = " frame-system = { git = "https://github.com/paritytech/polkadot-sdk", branch = "master", default-features = false } frame-system-rpc-runtime-api = { git = "https://github.com/paritytech/polkadot-sdk", branch = "master", default-features = false } pallet-authority-discovery = { git = "https://github.com/paritytech/polkadot-sdk", branch = "master", default-features = false } +pallet-authorship = { git = "https://github.com/paritytech/polkadot-sdk", branch = "master", default-features = false } pallet-babe = { git = "https://github.com/paritytech/polkadot-sdk", branch = "master", default-features = false } pallet-balances = { git = "https://github.com/paritytech/polkadot-sdk", branch = "master", default-features = false } pallet-beefy = { git = "https://github.com/paritytech/polkadot-sdk", branch = "master", default-features = false } @@ -41,6 +42,7 @@ pallet-beefy-mmr = { git = "https://github.com/paritytech/polkadot-sdk", branch pallet-grandpa = { git = "https://github.com/paritytech/polkadot-sdk", branch = "master", default-features = false } pallet-message-queue = { git = "https://github.com/paritytech/polkadot-sdk", branch = "master", default-features = false } pallet-mmr = { git = "https://github.com/paritytech/polkadot-sdk", branch = "master", default-features = false } +pallet-offences = { git = "https://github.com/paritytech/polkadot-sdk", branch = "master", default-features = false } pallet-session = { git = "https://github.com/paritytech/polkadot-sdk", branch = "master", default-features = false, features = ["historical"]} pallet-sudo = { git = "https://github.com/paritytech/polkadot-sdk", branch = "master", default-features = false } pallet-timestamp = { git = "https://github.com/paritytech/polkadot-sdk", branch = "master", default-features = false } @@ -94,6 +96,7 @@ std = [ "frame-system-rpc-runtime-api/std", "frame-system/std", "pallet-authority-discovery/std", + "pallet-authorship/std", "pallet-babe/std", "pallet-balances/std", "pallet-beefy/std", @@ -105,6 +108,7 @@ std = [ "pallet-grandpa/std", "pallet-message-queue/std", "pallet-mmr/std", + "pallet-offences/std", "pallet-xcm/std", "pallet-session/std", "pallet-shift-session-manager/std", diff --git a/bin/rialto/runtime/src/lib.rs b/bin/rialto/runtime/src/lib.rs index d149421864f6f..c00e32e9f317e 100644 --- a/bin/rialto/runtime/src/lib.rs +++ b/bin/rialto/runtime/src/lib.rs @@ -45,7 +45,7 @@ use sp_runtime::{ create_runtime_str, generic, impl_opaque_keys, traits::{AccountIdLookup, Block as BlockT, Keccak256, NumberFor, OpaqueKeys}, transaction_validity::{TransactionSource, TransactionValidity}, - ApplyExtrinsicResult, FixedPointNumber, Perquintill, + ApplyExtrinsicResult, FixedPointNumber, KeyTypeId, Perquintill, }; use sp_std::{collections::btree_map::BTreeMap, prelude::*}; #[cfg(feature = "std")] @@ -219,6 +219,7 @@ pub const BABE_GENESIS_EPOCH_CONFIG: sp_consensus_babe::BabeEpochConfiguration = parameter_types! { pub const EpochDuration: u64 = bp_rialto::EPOCH_DURATION_IN_SLOTS as u64; pub const ExpectedBlockTime: bp_rialto::Moment = bp_rialto::time_units::MILLISECS_PER_BLOCK; + pub ReportLongevity: u64 = EpochDuration::get() * 10; } impl pallet_babe::Config for Runtime { @@ -257,8 +258,9 @@ impl pallet_grandpa::Config for Runtime { type WeightInfo = (); type MaxAuthorities = ConstU32<10>; type MaxSetIdSessionEntries = ConstU64<0>; - type KeyOwnerProof = sp_core::Void; - type EquivocationReportSystem = (); + type KeyOwnerProof = >::Proof; + type EquivocationReportSystem = + pallet_grandpa::EquivocationReportSystem; type MaxNominators = ConstU32<256>; } @@ -383,6 +385,29 @@ impl pallet_session::Config for Runtime { type WeightInfo = (); } +impl pallet_authorship::Config for Runtime { + type FindAuthor = pallet_session::FindAccountFromAuthorIndex; + type EventHandler = (); +} + +pub struct FullIdentificationOf; +impl sp_runtime::traits::Convert> for FullIdentificationOf { + fn convert(_: AccountId) -> Option<()> { + Some(()) + } +} + +impl pallet_session::historical::Config for Runtime { + type FullIdentification = (); + type FullIdentificationOf = FullIdentificationOf; +} + +impl pallet_offences::Config for Runtime { + type RuntimeEvent = RuntimeEvent; + type IdentificationTuple = pallet_session::historical::IdentificationTuple; + type OnOffenceHandler = (); +} + impl pallet_authority_discovery::Config for Runtime { type MaxAuthorities = ConstU32<10>; } @@ -469,6 +494,12 @@ construct_runtime!( TransactionPayment: pallet_transaction_payment::{Pallet, Storage, Event}, // Consensus support. + // Authorship must be before session in order to note author in the correct session and era + // for im-online. + Authorship: pallet_authorship::{Pallet, Storage}, + Offences: pallet_offences::{Pallet, Storage, Event}, + Historical: pallet_session::historical::{Pallet}, + AuthorityDiscovery: pallet_authority_discovery::{Pallet, Config}, Session: pallet_session::{Pallet, Call, Storage, Event, Config}, Grandpa: pallet_grandpa::{Pallet, Call, Storage, Config, Event}, diff --git a/relays/client-millau/src/lib.rs b/relays/client-millau/src/lib.rs index ffd4a3f1cb8ed..b3101c980c557 100644 --- a/relays/client-millau/src/lib.rs +++ b/relays/client-millau/src/lib.rs @@ -25,8 +25,9 @@ use relay_substrate_client::{ ChainWithTransactions, ChainWithUtilityPallet, Error as SubstrateError, FullRuntimeUtilityPallet, NonceOf, SignParam, UnderlyingChainProvider, UnsignedTransaction, }; -use sp_core::{storage::StorageKey, Pair, Void}; +use sp_core::{storage::StorageKey, Pair}; use sp_runtime::{generic::SignedPayload, traits::IdentifyAccount}; +use sp_session::MembershipProof; use std::time::Duration; /// Millau header id. @@ -70,7 +71,7 @@ impl ChainWithGrandpa for Millau { const SYNCED_HEADERS_GRANDPA_INFO_METHOD: &'static str = MILLAU_SYNCED_HEADERS_GRANDPA_INFO_METHOD; - type KeyOwnerProof = Void; + type KeyOwnerProof = MembershipProof; } impl ChainWithBalances for Millau { diff --git a/relays/client-rialto/src/lib.rs b/relays/client-rialto/src/lib.rs index 94d8c24d95105..cc5371612c346 100644 --- a/relays/client-rialto/src/lib.rs +++ b/relays/client-rialto/src/lib.rs @@ -25,8 +25,9 @@ use relay_substrate_client::{ ChainWithTransactions, Error as SubstrateError, NonceOf, RelayChain, SignParam, UnderlyingChainProvider, UnsignedTransaction, }; -use sp_core::{storage::StorageKey, Pair, Void}; +use sp_core::{storage::StorageKey, Pair}; use sp_runtime::{generic::SignedPayload, traits::IdentifyAccount}; +use sp_session::MembershipProof; use std::time::Duration; /// Rialto header id. @@ -55,7 +56,7 @@ impl ChainWithGrandpa for Rialto { const SYNCED_HEADERS_GRANDPA_INFO_METHOD: &'static str = RIALTO_SYNCED_HEADERS_GRANDPA_INFO_METHOD; - type KeyOwnerProof = Void; + type KeyOwnerProof = MembershipProof; } impl RelayChain for Rialto {