From 4527f24735447b2ad80bc71ce9af2deb289db1d0 Mon Sep 17 00:00:00 2001 From: eskimor Date: Mon, 12 Jun 2023 13:15:37 +0200 Subject: [PATCH] Move vstaging to production (#7341) * Move vstaging to production (and thus past session slashing). WIP: test-runtime still needs to be fixed. * Fix test-runtime. --------- Co-authored-by: eskimor --- .../dispute-coordinator/src/initialized.rs | 27 +++++++- .../dispute-coordinator/src/scraping/mod.rs | 17 +++-- polkadot/node/subsystem-types/src/messages.rs | 29 ++++----- polkadot/node/subsystem-util/src/lib.rs | 12 ++-- polkadot/primitives/src/lib.rs | 28 ++++---- polkadot/primitives/src/runtime_api.rs | 8 +-- .../src/{v4 => v5}/executor_params.rs | 0 polkadot/primitives/src/{v4 => v5}/metrics.rs | 0 polkadot/primitives/src/{v4 => v5}/mod.rs | 2 + polkadot/primitives/src/{v4 => v5}/signed.rs | 0 .../src/{vstaging => v5}/slashing.rs | 2 +- polkadot/primitives/src/vstaging/mod.rs | 4 +- polkadot/runtime/kusama/src/lib.rs | 30 ++++++++- .../parachains/src/runtime_api_impl/mod.rs | 2 +- .../src/runtime_api_impl/{v4.rs => v5.rs} | 33 ++++++++-- .../src/runtime_api_impl/vstaging.rs | 29 --------- polkadot/runtime/parachains/src/ump_tests.rs | 2 +- polkadot/runtime/polkadot/src/lib.rs | 30 ++++++++- polkadot/runtime/rococo/src/lib.rs | 18 ++--- polkadot/runtime/test-runtime/src/lib.rs | 65 ++++++++++++++++--- polkadot/runtime/westend/src/lib.rs | 20 +++--- 21 files changed, 236 insertions(+), 122 deletions(-) rename polkadot/primitives/src/{v4 => v5}/executor_params.rs (100%) rename polkadot/primitives/src/{v4 => v5}/metrics.rs (100%) rename polkadot/primitives/src/{v4 => v5}/mod.rs (99%) rename polkadot/primitives/src/{v4 => v5}/signed.rs (100%) rename polkadot/primitives/src/{vstaging => v5}/slashing.rs (98%) rename polkadot/runtime/parachains/src/runtime_api_impl/{v4.rs => v5.rs} (93%) diff --git a/polkadot/node/core/dispute-coordinator/src/initialized.rs b/polkadot/node/core/dispute-coordinator/src/initialized.rs index 25bbcde6ee..7d64c91fb6 100644 --- a/polkadot/node/core/dispute-coordinator/src/initialized.rs +++ b/polkadot/node/core/dispute-coordinator/src/initialized.rs @@ -37,10 +37,10 @@ use polkadot_node_subsystem::{ ApprovalVotingMessage, BlockDescription, ChainSelectionMessage, DisputeCoordinatorMessage, DisputeDistributionMessage, ImportStatementsResult, }, - overseer, ActivatedLeaf, ActiveLeavesUpdate, FromOrchestra, OverseerSignal, + overseer, ActivatedLeaf, ActiveLeavesUpdate, FromOrchestra, OverseerSignal, RuntimeApiError, }; use polkadot_node_subsystem_util::runtime::{ - key_ownership_proof, submit_report_dispute_lost, RuntimeInfo, + self, key_ownership_proof, submit_report_dispute_lost, RuntimeInfo, }; use polkadot_primitives::{ vstaging, BlockNumber, CandidateHash, CandidateReceipt, CompactStatement, DisputeStatement, @@ -424,8 +424,19 @@ impl Initialized { dispute_proofs.push(dispute_proof); }, Ok(None) => {}, - Err(error) => { + Err(runtime::Error::RuntimeRequest(RuntimeApiError::NotSupported { + .. + })) => { gum::debug!( + target: LOG_TARGET, + ?session_index, + ?candidate_hash, + ?validator_id, + "Key ownership proof not yet supported.", + ); + }, + Err(error) => { + gum::warn!( target: LOG_TARGET, ?error, ?session_index, @@ -480,6 +491,16 @@ impl Initialized { .await; match res { + Err(runtime::Error::RuntimeRequest(RuntimeApiError::NotSupported { + .. + })) => { + gum::debug!( + target: LOG_TARGET, + ?session_index, + ?candidate_hash, + "Reporting pending slash not yet supported", + ); + }, Err(error) => { gum::warn!( target: LOG_TARGET, diff --git a/polkadot/node/core/dispute-coordinator/src/scraping/mod.rs b/polkadot/node/core/dispute-coordinator/src/scraping/mod.rs index 3ec03dd18b..01240a7e8b 100644 --- a/polkadot/node/core/dispute-coordinator/src/scraping/mod.rs +++ b/polkadot/node/core/dispute-coordinator/src/scraping/mod.rs @@ -25,13 +25,13 @@ use lru::LruCache; use polkadot_node_primitives::{DISPUTE_CANDIDATE_LIFETIME_AFTER_FINALIZATION, MAX_FINALITY_LAG}; use polkadot_node_subsystem::{ messages::ChainApiMessage, overseer, ActivatedLeaf, ActiveLeavesUpdate, ChainApiError, - SubsystemSender, + RuntimeApiError, SubsystemSender, }; use polkadot_node_subsystem_util::runtime::{ - get_candidate_events, get_on_chain_votes, get_unapplied_slashes, + self, get_candidate_events, get_on_chain_votes, get_unapplied_slashes, }; use polkadot_primitives::{ - vstaging, BlockNumber, CandidateEvent, CandidateHash, CandidateReceipt, Hash, + slashing::PendingSlashes, BlockNumber, CandidateEvent, CandidateHash, CandidateReceipt, Hash, ScrapedOnChainVotes, SessionIndex, }; @@ -67,7 +67,7 @@ const LRU_OBSERVED_BLOCKS_CAPACITY: NonZeroUsize = match NonZeroUsize::new(20) { pub struct ScrapedUpdates { pub on_chain_votes: Vec, pub included_receipts: Vec, - pub unapplied_slashes: Vec<(SessionIndex, CandidateHash, vstaging::slashing::PendingSlashes)>, + pub unapplied_slashes: Vec<(SessionIndex, CandidateHash, PendingSlashes)>, } impl ScrapedUpdates { @@ -270,8 +270,15 @@ impl ChainScraper { Ok(unapplied_slashes) => { scraped_updates.unapplied_slashes = unapplied_slashes; }, - Err(error) => { + Err(runtime::Error::RuntimeRequest(RuntimeApiError::NotSupported { .. })) => { gum::debug!( + target: LOG_TARGET, + block_hash = ?activated.hash, + "Fetching unapplied slashes not yet supported.", + ); + }, + Err(error) => { + gum::warn!( target: LOG_TARGET, block_hash = ?activated.hash, ?error, diff --git a/polkadot/node/subsystem-types/src/messages.rs b/polkadot/node/subsystem-types/src/messages.rs index cd61236e67..d190e33f5e 100644 --- a/polkadot/node/subsystem-types/src/messages.rs +++ b/polkadot/node/subsystem-types/src/messages.rs @@ -39,7 +39,7 @@ use polkadot_node_primitives::{ SignedDisputeStatement, SignedFullStatement, ValidationResult, }; use polkadot_primitives::{ - vstaging, AuthorityDiscoveryId, BackedCandidate, BlockNumber, CandidateEvent, CandidateHash, + slashing, AuthorityDiscoveryId, BackedCandidate, BlockNumber, CandidateEvent, CandidateHash, CandidateIndex, CandidateReceipt, CollatorId, CommittedCandidateReceipt, CoreState, DisputeState, ExecutorParams, GroupIndex, GroupRotationInfo, Hash, Header as BlockHeader, Id as ParaId, InboundDownwardMessage, InboundHrmpMessage, MultiDisputeStatementSet, @@ -607,21 +607,18 @@ pub enum RuntimeApiRequest { /// Returns all on-chain disputes at given block number. Available in `v3`. Disputes(RuntimeApiSender)>>), /// Returns a list of validators that lost a past session dispute and need to be slashed. - /// `VStaging` + /// `V5` UnappliedSlashes( - RuntimeApiSender>, + RuntimeApiSender>, ), /// Returns a merkle proof of a validator session key. - /// `VStaging` - KeyOwnershipProof( - ValidatorId, - RuntimeApiSender>, - ), + /// `V5` + KeyOwnershipProof(ValidatorId, RuntimeApiSender>), /// Submits an unsigned extrinsic to slash validator who lost a past session dispute. - /// `VStaging` + /// `V5` SubmitReportDisputeLost( - vstaging::slashing::DisputeProof, - vstaging::slashing::OpaqueKeyOwnershipProof, + slashing::DisputeProof, + slashing::OpaqueKeyOwnershipProof, RuntimeApiSender>, ), } @@ -632,17 +629,17 @@ impl RuntimeApiRequest { /// `Disputes` pub const DISPUTES_RUNTIME_REQUIREMENT: u32 = 3; - /// `UnappliedSlashes` - pub const UNAPPLIED_SLASHES_RUNTIME_REQUIREMENT: u32 = 4; - /// `ExecutorParams` pub const EXECUTOR_PARAMS_RUNTIME_REQUIREMENT: u32 = 4; + /// `UnappliedSlashes` + pub const UNAPPLIED_SLASHES_RUNTIME_REQUIREMENT: u32 = 5; + /// `KeyOwnershipProof` - pub const KEY_OWNERSHIP_PROOF_RUNTIME_REQUIREMENT: u32 = 4; + pub const KEY_OWNERSHIP_PROOF_RUNTIME_REQUIREMENT: u32 = 5; /// `SubmitReportDisputeLost` - pub const SUBMIT_REPORT_DISPUTE_LOST_RUNTIME_REQUIREMENT: u32 = 4; + pub const SUBMIT_REPORT_DISPUTE_LOST_RUNTIME_REQUIREMENT: u32 = 5; } /// A message to the Runtime API subsystem. diff --git a/polkadot/node/subsystem-util/src/lib.rs b/polkadot/node/subsystem-util/src/lib.rs index f523d7e04e..d6984d697a 100644 --- a/polkadot/node/subsystem-util/src/lib.rs +++ b/polkadot/node/subsystem-util/src/lib.rs @@ -29,7 +29,7 @@ use polkadot_node_subsystem::{ messages::{RuntimeApiMessage, RuntimeApiRequest, RuntimeApiSender}, overseer, SubsystemSender, }; -use polkadot_primitives::ExecutorParams; +use polkadot_primitives::{slashing, ExecutorParams}; pub use overseer::{ gen::{OrchestraError as OverseerError, Timeout}, @@ -42,8 +42,8 @@ use futures::channel::{mpsc, oneshot}; use parity_scale_codec::Encode; use polkadot_primitives::{ - vstaging, AuthorityDiscoveryId, CandidateEvent, CandidateHash, CommittedCandidateReceipt, - CoreState, EncodeAs, GroupIndex, GroupRotationInfo, Hash, Id as ParaId, OccupiedCoreAssumption, + AuthorityDiscoveryId, CandidateEvent, CandidateHash, CommittedCandidateReceipt, CoreState, + EncodeAs, GroupIndex, GroupRotationInfo, Hash, Id as ParaId, OccupiedCoreAssumption, PersistedValidationData, ScrapedOnChainVotes, SessionIndex, SessionInfo, Signed, SigningContext, ValidationCode, ValidationCodeHash, ValidatorId, ValidatorIndex, ValidatorSignature, @@ -212,9 +212,9 @@ specialize_requests! { -> Option; ValidationCodeHash; fn request_on_chain_votes() -> Option; FetchOnChainVotes; fn request_session_executor_params(session_index: SessionIndex) -> Option;SessionExecutorParams; - fn request_unapplied_slashes() -> Vec<(SessionIndex, CandidateHash, vstaging::slashing::PendingSlashes)>; UnappliedSlashes; - fn request_key_ownership_proof(validator_id: ValidatorId) -> Option; KeyOwnershipProof; - fn request_submit_report_dispute_lost(dp: vstaging::slashing::DisputeProof, okop: vstaging::slashing::OpaqueKeyOwnershipProof) -> Option<()>; SubmitReportDisputeLost; + fn request_unapplied_slashes() -> Vec<(SessionIndex, CandidateHash, slashing::PendingSlashes)>; UnappliedSlashes; + fn request_key_ownership_proof(validator_id: ValidatorId) -> Option; KeyOwnershipProof; + fn request_submit_report_dispute_lost(dp: slashing::DisputeProof, okop: slashing::OpaqueKeyOwnershipProof) -> Option<()>; SubmitReportDisputeLost; } /// Requests executor parameters from the runtime effective at given relay-parent. First obtains diff --git a/polkadot/primitives/src/lib.rs b/polkadot/primitives/src/lib.rs index 9cd1de8b47..1c8ef1eae7 100644 --- a/polkadot/primitives/src/lib.rs +++ b/polkadot/primitives/src/lib.rs @@ -19,8 +19,8 @@ #![warn(missing_docs)] #![cfg_attr(not(feature = "std"), no_std)] -// `v4` is currently the latest stable version of the runtime API. -pub mod v4; +// `v5` is currently the latest stable version of the runtime API. +pub mod v5; // The 'staging' version is special - it contains primitives which are // still in development. Once they are considered stable, they will be @@ -33,18 +33,18 @@ pub mod runtime_api; // Current primitives not requiring versioning are exported here. // Primitives requiring versioning must not be exported and must be referred by an exact version. -pub use v4::{ +pub use v5::{ byzantine_threshold, check_candidate_backing, collator_signature_payload, metric_definitions, - supermajority_threshold, well_known_keys, AbridgedHostConfiguration, AbridgedHrmpChannel, - AccountId, AccountIndex, AccountPublic, ApprovalVote, AssignmentId, AuthorityDiscoveryId, - AvailabilityBitfield, BackedCandidate, Balance, BlakeTwo256, Block, BlockId, BlockNumber, - CandidateCommitments, CandidateDescriptor, CandidateEvent, CandidateHash, CandidateIndex, - CandidateReceipt, CheckedDisputeStatementSet, CheckedMultiDisputeStatementSet, CollatorId, - CollatorSignature, CommittedCandidateReceipt, CompactStatement, ConsensusLog, CoreIndex, - CoreOccupied, CoreState, DisputeState, DisputeStatement, DisputeStatementSet, DownwardMessage, - EncodeAs, ExecutorParam, ExecutorParams, ExecutorParamsHash, ExplicitDisputeStatement, - GroupIndex, GroupRotationInfo, Hash, HashT, HeadData, Header, HrmpChannelId, Id, - InboundDownwardMessage, InboundHrmpMessage, IndexedVec, InherentData, + slashing, supermajority_threshold, well_known_keys, AbridgedHostConfiguration, + AbridgedHrmpChannel, AccountId, AccountIndex, AccountPublic, ApprovalVote, AssignmentId, + AuthorityDiscoveryId, AvailabilityBitfield, BackedCandidate, Balance, BlakeTwo256, Block, + BlockId, BlockNumber, CandidateCommitments, CandidateDescriptor, CandidateEvent, CandidateHash, + CandidateIndex, CandidateReceipt, CheckedDisputeStatementSet, CheckedMultiDisputeStatementSet, + CollatorId, CollatorSignature, CommittedCandidateReceipt, CompactStatement, ConsensusLog, + CoreIndex, CoreOccupied, CoreState, DisputeState, DisputeStatement, DisputeStatementSet, + DownwardMessage, EncodeAs, ExecutorParam, ExecutorParams, ExecutorParamsHash, + ExplicitDisputeStatement, GroupIndex, GroupRotationInfo, Hash, HashT, HeadData, Header, + HrmpChannelId, Id, InboundDownwardMessage, InboundHrmpMessage, IndexedVec, InherentData, InvalidDisputeStatementKind, Moment, MultiDisputeStatementSet, Nonce, OccupiedCore, OccupiedCoreAssumption, OutboundHrmpMessage, ParathreadClaim, ParathreadEntry, PersistedValidationData, PvfCheckStatement, PvfExecTimeoutKind, PvfPrepTimeoutKind, @@ -60,4 +60,4 @@ pub use v4::{ }; #[cfg(feature = "std")] -pub use v4::{AssignmentPair, CollatorPair, ValidatorPair}; +pub use v5::{AssignmentPair, CollatorPair, ValidatorPair}; diff --git a/polkadot/primitives/src/runtime_api.rs b/polkadot/primitives/src/runtime_api.rs index c60ec8c922..aea069db76 100644 --- a/polkadot/primitives/src/runtime_api.rs +++ b/polkadot/primitives/src/runtime_api.rs @@ -123,7 +123,7 @@ use sp_std::{collections::btree_map::BTreeMap, prelude::*}; sp_api::decl_runtime_apis! { /// The API for querying the state of parachains on-chain. - #[api_version(4)] + #[api_version(5)] pub trait ParachainHost { /// Get the current validators. fn validators() -> Vec; @@ -220,18 +220,18 @@ sp_api::decl_runtime_apis! { fn session_executor_params(session_index: SessionIndex) -> Option; /// Returns a list of validators that lost a past session dispute and need to be slashed. - #[api_version(5)] + /// NOTE: This function is only available since parachain host version 5. fn unapplied_slashes() -> Vec<(SessionIndex, CandidateHash, vstaging::slashing::PendingSlashes)>; /// Returns a merkle proof of a validator session key. - #[api_version(5)] + /// NOTE: This function is only available since parachain host version 5. fn key_ownership_proof( validator_id: ValidatorId, ) -> Option; /// Submit an unsigned extrinsic to slash validators who lost a dispute about /// a candidate of a past session. - #[api_version(5)] + /// NOTE: This function is only available since parachain host version 5. fn submit_report_dispute_lost( dispute_proof: vstaging::slashing::DisputeProof, key_ownership_proof: vstaging::slashing::OpaqueKeyOwnershipProof, diff --git a/polkadot/primitives/src/v4/executor_params.rs b/polkadot/primitives/src/v5/executor_params.rs similarity index 100% rename from polkadot/primitives/src/v4/executor_params.rs rename to polkadot/primitives/src/v5/executor_params.rs diff --git a/polkadot/primitives/src/v4/metrics.rs b/polkadot/primitives/src/v5/metrics.rs similarity index 100% rename from polkadot/primitives/src/v4/metrics.rs rename to polkadot/primitives/src/v5/metrics.rs diff --git a/polkadot/primitives/src/v4/mod.rs b/polkadot/primitives/src/v5/mod.rs similarity index 99% rename from polkadot/primitives/src/v4/mod.rs rename to polkadot/primitives/src/v5/mod.rs index 4f4c9aa5f8..6c6258b2b8 100644 --- a/polkadot/primitives/src/v4/mod.rs +++ b/polkadot/primitives/src/v5/mod.rs @@ -57,6 +57,8 @@ pub use sp_staking::SessionIndex; mod signed; pub use signed::{EncodeAs, Signed, UncheckedSigned}; +pub mod slashing; + mod metrics; pub use metrics::{ metric_definitions, RuntimeMetricLabel, RuntimeMetricLabelValue, RuntimeMetricLabelValues, diff --git a/polkadot/primitives/src/v4/signed.rs b/polkadot/primitives/src/v5/signed.rs similarity index 100% rename from polkadot/primitives/src/v4/signed.rs rename to polkadot/primitives/src/v5/signed.rs diff --git a/polkadot/primitives/src/vstaging/slashing.rs b/polkadot/primitives/src/v5/slashing.rs similarity index 98% rename from polkadot/primitives/src/vstaging/slashing.rs rename to polkadot/primitives/src/v5/slashing.rs index 41bb0e22d6..34424a00d2 100644 --- a/polkadot/primitives/src/vstaging/slashing.rs +++ b/polkadot/primitives/src/v5/slashing.rs @@ -16,7 +16,7 @@ //! Primitives types used for dispute slashing. -use crate::v4::{CandidateHash, SessionIndex, ValidatorId, ValidatorIndex}; +use crate::{CandidateHash, SessionIndex, ValidatorId, ValidatorIndex}; use parity_scale_codec::{Decode, Encode}; use scale_info::TypeInfo; use sp_std::{collections::btree_map::BTreeMap, vec::Vec}; diff --git a/polkadot/primitives/src/vstaging/mod.rs b/polkadot/primitives/src/vstaging/mod.rs index 9b6291ffbf..0dbfa8c34c 100644 --- a/polkadot/primitives/src/vstaging/mod.rs +++ b/polkadot/primitives/src/vstaging/mod.rs @@ -17,8 +17,7 @@ //! Staging Primitives. // Put any primitives used by staging APIs functions here -pub use crate::v4::*; -pub mod slashing; +pub use crate::v5::*; use sp_std::prelude::*; use parity_scale_codec::{Decode, Encode}; @@ -37,6 +36,7 @@ use scale_info::TypeInfo; serde::Serialize, serde::Deserialize, )] + pub struct AsyncBackingParams { /// The maximum number of para blocks between the para head in a relay parent /// and a new candidate. Restricts nodes from building arbitrary long chains diff --git a/polkadot/runtime/kusama/src/lib.rs b/polkadot/runtime/kusama/src/lib.rs index aebc53fbec..16f2e7927b 100644 --- a/polkadot/runtime/kusama/src/lib.rs +++ b/polkadot/runtime/kusama/src/lib.rs @@ -23,11 +23,12 @@ use pallet_nis::WithMaximumOf; use parity_scale_codec::{Decode, Encode, MaxEncodedLen}; use primitives::{ - AccountId, AccountIndex, Balance, BlockNumber, CandidateEvent, CandidateHash, + slashing, AccountId, AccountIndex, Balance, BlockNumber, CandidateEvent, CandidateHash, CommittedCandidateReceipt, CoreState, DisputeState, ExecutorParams, GroupRotationInfo, Hash, Id as ParaId, InboundDownwardMessage, InboundHrmpMessage, Moment, Nonce, OccupiedCoreAssumption, PersistedValidationData, ScrapedOnChainVotes, SessionInfo, Signature, ValidationCode, ValidationCodeHash, ValidatorId, ValidatorIndex, LOWEST_PUBLIC_ID, + PARACHAIN_KEY_TYPE_ID, }; use runtime_common::{ auctions, claims, crowdloan, impl_runtime_weights, impls::DealWithFees, paras_registrar, @@ -44,7 +45,7 @@ use runtime_parachains::{ inclusion::{AggregateMessageOrigin, UmpQueueId}, initializer as parachains_initializer, origin as parachains_origin, paras as parachains_paras, paras_inherent as parachains_paras_inherent, reward_points as parachains_reward_points, - runtime_api_impl::v4 as parachains_runtime_api_impl, + runtime_api_impl::v5 as parachains_runtime_api_impl, scheduler as parachains_scheduler, session_info as parachains_session_info, shared as parachains_shared, }; @@ -1822,6 +1823,31 @@ sp_api::impl_runtime_apis! { fn disputes() -> Vec<(SessionIndex, CandidateHash, DisputeState)> { parachains_runtime_api_impl::get_session_disputes::() } + + fn unapplied_slashes( + ) -> Vec<(SessionIndex, CandidateHash, slashing::PendingSlashes)> { + parachains_runtime_api_impl::unapplied_slashes::() + } + + fn key_ownership_proof( + validator_id: ValidatorId, + ) -> Option { + use parity_scale_codec::Encode; + + Historical::prove((PARACHAIN_KEY_TYPE_ID, validator_id)) + .map(|p| p.encode()) + .map(slashing::OpaqueKeyOwnershipProof::new) + } + + fn submit_report_dispute_lost( + dispute_proof: slashing::DisputeProof, + key_ownership_proof: slashing::OpaqueKeyOwnershipProof, + ) -> Option<()> { + parachains_runtime_api_impl::submit_unsigned_slashing_report::( + dispute_proof, + key_ownership_proof, + ) + } } impl beefy_primitives::BeefyApi for Runtime { diff --git a/polkadot/runtime/parachains/src/runtime_api_impl/mod.rs b/polkadot/runtime/parachains/src/runtime_api_impl/mod.rs index 6f0ee54f6f..e22ef82585 100644 --- a/polkadot/runtime/parachains/src/runtime_api_impl/mod.rs +++ b/polkadot/runtime/parachains/src/runtime_api_impl/mod.rs @@ -26,5 +26,5 @@ //! 2. Move methods from `vstaging` to `v3`. The new stable version should include //! all methods from `vstaging` tagged with the new version number (e.g. all //! `v3` methods). -pub mod v4; +pub mod v5; pub mod vstaging; diff --git a/polkadot/runtime/parachains/src/runtime_api_impl/v4.rs b/polkadot/runtime/parachains/src/runtime_api_impl/v5.rs similarity index 93% rename from polkadot/runtime/parachains/src/runtime_api_impl/v4.rs rename to polkadot/runtime/parachains/src/runtime_api_impl/v5.rs index 20f62f520a..72425995b4 100644 --- a/polkadot/runtime/parachains/src/runtime_api_impl/v4.rs +++ b/polkadot/runtime/parachains/src/runtime_api_impl/v5.rs @@ -11,7 +11,7 @@ // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. -//! A module exporting runtime API implementation functions for all runtime APIs using v2 +//! A module exporting runtime API implementation functions for all runtime APIs using v5 //! primitives. //! //! Runtimes implementing the v2 runtime API are recommended to forward directly to these @@ -22,12 +22,12 @@ use crate::{ session_info, shared, }; use primitives::{ - AuthorityDiscoveryId, CandidateEvent, CandidateHash, CommittedCandidateReceipt, CoreIndex, - CoreOccupied, CoreState, DisputeState, ExecutorParams, GroupIndex, GroupRotationInfo, Hash, - Id as ParaId, InboundDownwardMessage, InboundHrmpMessage, OccupiedCore, OccupiedCoreAssumption, - PersistedValidationData, PvfCheckStatement, ScheduledCore, ScrapedOnChainVotes, SessionIndex, - SessionInfo, ValidationCode, ValidationCodeHash, ValidatorId, ValidatorIndex, - ValidatorSignature, + slashing, AuthorityDiscoveryId, CandidateEvent, CandidateHash, CommittedCandidateReceipt, + CoreIndex, CoreOccupied, CoreState, DisputeState, ExecutorParams, GroupIndex, + GroupRotationInfo, Hash, Id as ParaId, InboundDownwardMessage, InboundHrmpMessage, + OccupiedCore, OccupiedCoreAssumption, PersistedValidationData, PvfCheckStatement, + ScheduledCore, ScrapedOnChainVotes, SessionIndex, SessionInfo, ValidationCode, + ValidationCodeHash, ValidatorId, ValidatorIndex, ValidatorSignature, }; use sp_runtime::traits::One; use sp_std::{collections::btree_map::BTreeMap, prelude::*}; @@ -425,3 +425,22 @@ pub fn session_executor_params( None => Some(ExecutorParams::default()), } } + +/// Implementation of `unapplied_slashes` runtime API +pub fn unapplied_slashes( +) -> Vec<(SessionIndex, CandidateHash, slashing::PendingSlashes)> { + >::unapplied_slashes() +} + +/// Implementation of `submit_report_dispute_lost` runtime API +pub fn submit_unsigned_slashing_report( + dispute_proof: slashing::DisputeProof, + key_ownership_proof: slashing::OpaqueKeyOwnershipProof, +) -> Option<()> { + let key_ownership_proof = key_ownership_proof.decode()?; + + >::submit_unsigned_slashing_report( + dispute_proof, + key_ownership_proof, + ) +} diff --git a/polkadot/runtime/parachains/src/runtime_api_impl/vstaging.rs b/polkadot/runtime/parachains/src/runtime_api_impl/vstaging.rs index be7c58e3f2..d01b543630 100644 --- a/polkadot/runtime/parachains/src/runtime_api_impl/vstaging.rs +++ b/polkadot/runtime/parachains/src/runtime_api_impl/vstaging.rs @@ -15,32 +15,3 @@ // along with Polkadot. If not, see . //! Put implementations of functions from staging APIs here. - -use crate::disputes; -use primitives::{vstaging, CandidateHash, DisputeState, SessionIndex}; -use sp_std::prelude::*; - -/// Implementation for `get_session_disputes` function from the runtime API -pub fn get_session_disputes( -) -> Vec<(SessionIndex, CandidateHash, DisputeState)> { - >::disputes() -} - -/// Implementation of `unapplied_slashes` runtime API -pub fn unapplied_slashes( -) -> Vec<(SessionIndex, CandidateHash, vstaging::slashing::PendingSlashes)> { - >::unapplied_slashes() -} - -/// Implementation of `submit_report_dispute_lost` runtime API -pub fn submit_unsigned_slashing_report( - dispute_proof: vstaging::slashing::DisputeProof, - key_ownership_proof: vstaging::slashing::OpaqueKeyOwnershipProof, -) -> Option<()> { - let key_ownership_proof = key_ownership_proof.decode()?; - - >::submit_unsigned_slashing_report( - dispute_proof, - key_ownership_proof, - ) -} diff --git a/polkadot/runtime/parachains/src/ump_tests.rs b/polkadot/runtime/parachains/src/ump_tests.rs index 40b764fa4d..100d3f248a 100644 --- a/polkadot/runtime/parachains/src/ump_tests.rs +++ b/polkadot/runtime/parachains/src/ump_tests.rs @@ -30,7 +30,7 @@ use frame_support::{ traits::{EnqueueMessage, ExecuteOverweightError, ServiceQueues}, weights::Weight, }; -use primitives::v4::{well_known_keys, Id as ParaId, UpwardMessage}; +use primitives::{well_known_keys, Id as ParaId, UpwardMessage}; use sp_core::twox_64; use sp_io::hashing::blake2_256; use sp_runtime::traits::Bounded; diff --git a/polkadot/runtime/polkadot/src/lib.rs b/polkadot/runtime/polkadot/src/lib.rs index 0ec33b2a41..3349cfd321 100644 --- a/polkadot/runtime/polkadot/src/lib.rs +++ b/polkadot/runtime/polkadot/src/lib.rs @@ -33,7 +33,7 @@ use runtime_parachains::{ inclusion::{AggregateMessageOrigin, UmpQueueId}, initializer as parachains_initializer, origin as parachains_origin, paras as parachains_paras, paras_inherent as parachains_paras_inherent, reward_points as parachains_reward_points, - runtime_api_impl::v4 as parachains_runtime_api_impl, + runtime_api_impl::v5 as parachains_runtime_api_impl, scheduler as parachains_scheduler, session_info as parachains_session_info, shared as parachains_shared, }; @@ -57,11 +57,12 @@ use pallet_session::historical as session_historical; use pallet_transaction_payment::{FeeDetails, RuntimeDispatchInfo}; use parity_scale_codec::{Decode, Encode, MaxEncodedLen}; use primitives::{ - AccountId, AccountIndex, Balance, BlockNumber, CandidateEvent, CandidateHash, + slashing, AccountId, AccountIndex, Balance, BlockNumber, CandidateEvent, CandidateHash, CommittedCandidateReceipt, CoreState, DisputeState, ExecutorParams, GroupRotationInfo, Hash, Id as ParaId, InboundDownwardMessage, InboundHrmpMessage, Moment, Nonce, OccupiedCoreAssumption, PersistedValidationData, ScrapedOnChainVotes, SessionInfo, Signature, ValidationCode, ValidationCodeHash, ValidatorId, ValidatorIndex, LOWEST_PUBLIC_ID, + PARACHAIN_KEY_TYPE_ID, }; use sp_core::OpaqueMetadata; use sp_mmr_primitives as mmr; @@ -1835,6 +1836,31 @@ sp_api::impl_runtime_apis! { fn disputes() -> Vec<(SessionIndex, CandidateHash, DisputeState)> { parachains_runtime_api_impl::get_session_disputes::() } + + fn unapplied_slashes( + ) -> Vec<(SessionIndex, CandidateHash, slashing::PendingSlashes)> { + parachains_runtime_api_impl::unapplied_slashes::() + } + + fn key_ownership_proof( + validator_id: ValidatorId, + ) -> Option { + use parity_scale_codec::Encode; + + Historical::prove((PARACHAIN_KEY_TYPE_ID, validator_id)) + .map(|p| p.encode()) + .map(slashing::OpaqueKeyOwnershipProof::new) + } + + fn submit_report_dispute_lost( + dispute_proof: slashing::DisputeProof, + key_ownership_proof: slashing::OpaqueKeyOwnershipProof, + ) -> Option<()> { + parachains_runtime_api_impl::submit_unsigned_slashing_report::( + dispute_proof, + key_ownership_proof, + ) + } } impl beefy_primitives::BeefyApi for Runtime { diff --git a/polkadot/runtime/rococo/src/lib.rs b/polkadot/runtime/rococo/src/lib.rs index e096a6642b..694d6f54fa 100644 --- a/polkadot/runtime/rococo/src/lib.rs +++ b/polkadot/runtime/rococo/src/lib.rs @@ -23,7 +23,7 @@ use pallet_nis::WithMaximumOf; use parity_scale_codec::{Decode, Encode, MaxEncodedLen}; use primitives::{ - vstaging, AccountId, AccountIndex, Balance, BlockNumber, CandidateEvent, CandidateHash, + slashing, AccountId, AccountIndex, Balance, BlockNumber, CandidateEvent, CandidateHash, CommittedCandidateReceipt, CoreState, DisputeState, ExecutorParams, GroupRotationInfo, Hash, Id as ParaId, InboundDownwardMessage, InboundHrmpMessage, Moment, Nonce, OccupiedCoreAssumption, PersistedValidationData, ScrapedOnChainVotes, SessionInfo, Signature, @@ -44,7 +44,7 @@ use runtime_parachains::{ inclusion::{AggregateMessageOrigin, UmpQueueId}, initializer as parachains_initializer, origin as parachains_origin, paras as parachains_paras, paras_inherent as parachains_paras_inherent, - runtime_api_impl::v4 as parachains_runtime_api_impl, + runtime_api_impl::v5 as parachains_runtime_api_impl, scheduler as parachains_scheduler, session_info as parachains_session_info, shared as parachains_shared, }; @@ -1915,25 +1915,25 @@ sp_api::impl_runtime_apis! { } fn unapplied_slashes( - ) -> Vec<(SessionIndex, CandidateHash, vstaging::slashing::PendingSlashes)> { - runtime_parachains::runtime_api_impl::vstaging::unapplied_slashes::() + ) -> Vec<(SessionIndex, CandidateHash, slashing::PendingSlashes)> { + parachains_runtime_api_impl::unapplied_slashes::() } fn key_ownership_proof( validator_id: ValidatorId, - ) -> Option { + ) -> Option { use parity_scale_codec::Encode; Historical::prove((PARACHAIN_KEY_TYPE_ID, validator_id)) .map(|p| p.encode()) - .map(vstaging::slashing::OpaqueKeyOwnershipProof::new) + .map(slashing::OpaqueKeyOwnershipProof::new) } fn submit_report_dispute_lost( - dispute_proof: vstaging::slashing::DisputeProof, - key_ownership_proof: vstaging::slashing::OpaqueKeyOwnershipProof, + dispute_proof: slashing::DisputeProof, + key_ownership_proof: slashing::OpaqueKeyOwnershipProof, ) -> Option<()> { - runtime_parachains::runtime_api_impl::vstaging::submit_unsigned_slashing_report::( + parachains_runtime_api_impl::submit_unsigned_slashing_report::( dispute_proof, key_ownership_proof, ) diff --git a/polkadot/runtime/test-runtime/src/lib.rs b/polkadot/runtime/test-runtime/src/lib.rs index a361a2a6ec..132b8897d8 100644 --- a/polkadot/runtime/test-runtime/src/lib.rs +++ b/polkadot/runtime/test-runtime/src/lib.rs @@ -26,9 +26,10 @@ use sp_std::{collections::btree_map::BTreeMap, prelude::*}; use polkadot_runtime_parachains::{ configuration as parachains_configuration, disputes as parachains_disputes, - dmp as parachains_dmp, hrmp as parachains_hrmp, inclusion as parachains_inclusion, - initializer as parachains_initializer, origin as parachains_origin, paras as parachains_paras, - paras_inherent as parachains_paras_inherent, runtime_api_impl::v4 as runtime_impl, + disputes::slashing as parachains_slashing, dmp as parachains_dmp, hrmp as parachains_hrmp, + inclusion as parachains_inclusion, initializer as parachains_initializer, + origin as parachains_origin, paras as parachains_paras, + paras_inherent as parachains_paras_inherent, runtime_api_impl::v5 as runtime_impl, scheduler as parachains_scheduler, session_info as parachains_session_info, shared as parachains_shared, }; @@ -38,19 +39,19 @@ use beefy_primitives::crypto::{AuthorityId as BeefyId, Signature as BeefySignatu use frame_election_provider_support::{onchain, SequentialPhragmen}; use frame_support::{ construct_runtime, parameter_types, - traits::{Everything, WithdrawReasons}, + traits::{Everything, KeyOwnerProofSystem, WithdrawReasons}, }; use pallet_grandpa::{fg_primitives, AuthorityId as GrandpaId}; use pallet_session::historical as session_historical; use pallet_transaction_payment::{FeeDetails, RuntimeDispatchInfo}; use polkadot_runtime_parachains::reward_points::RewardValidatorsWithEraPoints; use primitives::{ - AccountId, AccountIndex, Balance, BlockNumber, CandidateEvent, CandidateHash, + slashing, AccountId, AccountIndex, Balance, BlockNumber, CandidateEvent, CandidateHash, CommittedCandidateReceipt, CoreState, DisputeState, ExecutorParams, GroupRotationInfo, Hash as HashT, Id as ParaId, InboundDownwardMessage, InboundHrmpMessage, Moment, Nonce, OccupiedCoreAssumption, PersistedValidationData, ScrapedOnChainVotes, SessionInfo as SessionInfoData, Signature, ValidationCode, ValidationCodeHash, ValidatorId, - ValidatorIndex, + ValidatorIndex, PARACHAIN_KEY_TYPE_ID, }; use runtime_common::{ claims, impl_runtime_weights, paras_sudo_wrapper, BlockHashCount, BlockLength, @@ -67,7 +68,7 @@ use sp_runtime::{ SaturatedConversion, StaticLookup, Verify, }, transaction_validity::{TransactionPriority, TransactionSource, TransactionValidity}, - ApplyExtrinsicResult, Perbill, + ApplyExtrinsicResult, KeyTypeId, Perbill, }; use sp_staking::SessionIndex; #[cfg(any(feature = "std", test))] @@ -170,6 +171,8 @@ where parameter_types! { pub storage EpochDuration: u64 = EPOCH_DURATION_IN_SLOTS as u64; pub storage ExpectedBlockTime: Moment = MILLISECS_PER_BLOCK; + pub ReportLongevity: u64 = + BondingDuration::get() as u64 * SessionsPerEra::get() as u64 * EpochDuration::get(); } impl pallet_babe::Config for Runtime { @@ -185,7 +188,8 @@ impl pallet_babe::Config for Runtime { type MaxAuthorities = MaxAuthorities; - type KeyOwnerProof = sp_core::Void; + type KeyOwnerProof = + >::Proof; type EquivocationReportSystem = (); } @@ -484,10 +488,27 @@ impl parachains_inclusion::Config for Runtime { impl parachains_disputes::Config for Runtime { type RuntimeEvent = RuntimeEvent; type RewardValidators = (); - type SlashingHandler = (); + type SlashingHandler = parachains_slashing::SlashValidatorsForDisputes; type WeightInfo = parachains_disputes::TestWeightInfo; } +impl parachains_slashing::Config for Runtime { + type KeyOwnerProofSystem = Historical; + type KeyOwnerProof = + >::Proof; + type KeyOwnerIdentification = >::IdentificationTuple; + type HandleReports = parachains_slashing::SlashingReportHandler< + Self::KeyOwnerIdentification, + Offences, + ReportLongevity, + >; + type WeightInfo = parachains_disputes::slashing::TestWeightInfo; + type BenchmarkingConfig = parachains_slashing::BenchConfig<1000>; +} + impl parachains_paras_inherent::Config for Runtime { type WeightInfo = parachains_paras_inherent::TestWeightInfo; } @@ -671,6 +692,7 @@ construct_runtime! { Dmp: parachains_dmp::{Pallet, Storage}, Xcm: pallet_xcm::{Pallet, Call, Event, Origin}, ParasDisputes: parachains_disputes::{Pallet, Storage, Event}, + ParasSlashing: parachains_slashing::{Pallet, Call, Storage, ValidateUnsigned}, Sudo: pallet_sudo::{Pallet, Call, Storage, Config, Event}, @@ -891,6 +913,31 @@ sp_api::impl_runtime_apis! { fn disputes() -> Vec<(SessionIndex, CandidateHash, DisputeState)> { runtime_impl::get_session_disputes::() } + + fn unapplied_slashes( + ) -> Vec<(SessionIndex, CandidateHash, slashing::PendingSlashes)> { + runtime_impl::unapplied_slashes::() + } + + fn key_ownership_proof( + validator_id: ValidatorId, + ) -> Option { + use parity_scale_codec::Encode; + + Historical::prove((PARACHAIN_KEY_TYPE_ID, validator_id)) + .map(|p| p.encode()) + .map(slashing::OpaqueKeyOwnershipProof::new) + } + + fn submit_report_dispute_lost( + dispute_proof: slashing::DisputeProof, + key_ownership_proof: slashing::OpaqueKeyOwnershipProof, + ) -> Option<()> { + runtime_impl::submit_unsigned_slashing_report::( + dispute_proof, + key_ownership_proof, + ) + } } impl beefy_primitives::BeefyApi for Runtime { diff --git a/polkadot/runtime/westend/src/lib.rs b/polkadot/runtime/westend/src/lib.rs index d7850dcdd2..592d552bfe 100644 --- a/polkadot/runtime/westend/src/lib.rs +++ b/polkadot/runtime/westend/src/lib.rs @@ -39,7 +39,7 @@ use pallet_session::historical as session_historical; use pallet_transaction_payment::{CurrencyAdapter, FeeDetails, RuntimeDispatchInfo}; use parity_scale_codec::{Decode, Encode, MaxEncodedLen}; use primitives::{ - vstaging, AccountId, AccountIndex, Balance, BlockNumber, CandidateEvent, CandidateHash, + slashing, AccountId, AccountIndex, Balance, BlockNumber, CandidateEvent, CandidateHash, CommittedCandidateReceipt, CoreState, DisputeState, ExecutorParams, GroupRotationInfo, Hash, Id as ParaId, InboundDownwardMessage, InboundHrmpMessage, Moment, Nonce, OccupiedCoreAssumption, PersistedValidationData, PvfCheckStatement, ScrapedOnChainVotes, @@ -58,9 +58,7 @@ use runtime_parachains::{ inclusion::{AggregateMessageOrigin, UmpQueueId}, initializer as parachains_initializer, origin as parachains_origin, paras as parachains_paras, paras_inherent as parachains_paras_inherent, reward_points as parachains_reward_points, - runtime_api_impl::{ - v4 as parachains_runtime_api_impl, vstaging as parachains_runtime_api_impl_staging, - }, + runtime_api_impl::v5 as parachains_runtime_api_impl, scheduler as parachains_scheduler, session_info as parachains_session_info, shared as parachains_shared, }; @@ -1582,25 +1580,25 @@ sp_api::impl_runtime_apis! { } fn unapplied_slashes( - ) -> Vec<(SessionIndex, CandidateHash, vstaging::slashing::PendingSlashes)> { - parachains_runtime_api_impl_staging::unapplied_slashes::() + ) -> Vec<(SessionIndex, CandidateHash, slashing::PendingSlashes)> { + parachains_runtime_api_impl::unapplied_slashes::() } fn key_ownership_proof( validator_id: ValidatorId, - ) -> Option { + ) -> Option { use parity_scale_codec::Encode; Historical::prove((PARACHAIN_KEY_TYPE_ID, validator_id)) .map(|p| p.encode()) - .map(vstaging::slashing::OpaqueKeyOwnershipProof::new) + .map(slashing::OpaqueKeyOwnershipProof::new) } fn submit_report_dispute_lost( - dispute_proof: vstaging::slashing::DisputeProof, - key_ownership_proof: vstaging::slashing::OpaqueKeyOwnershipProof, + dispute_proof: slashing::DisputeProof, + key_ownership_proof: slashing::OpaqueKeyOwnershipProof, ) -> Option<()> { - parachains_runtime_api_impl_staging::submit_unsigned_slashing_report::( + parachains_runtime_api_impl::submit_unsigned_slashing_report::( dispute_proof, key_ownership_proof, )