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 <eskimor@no-such-url.com>
This commit is contained in:
eskimor
2023-06-12 13:15:37 +02:00
committed by GitHub
parent d90173e438
commit 4527f24735
21 changed files with 236 additions and 122 deletions
+28 -2
View File
@@ -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<BlockNumber>)> {
parachains_runtime_api_impl::get_session_disputes::<Runtime>()
}
fn unapplied_slashes(
) -> Vec<(SessionIndex, CandidateHash, slashing::PendingSlashes)> {
parachains_runtime_api_impl::unapplied_slashes::<Runtime>()
}
fn key_ownership_proof(
validator_id: ValidatorId,
) -> Option<slashing::OpaqueKeyOwnershipProof> {
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::<Runtime>(
dispute_proof,
key_ownership_proof,
)
}
}
impl beefy_primitives::BeefyApi<Block> for Runtime {
@@ -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;
@@ -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<T: session_info::Config>(
None => Some(ExecutorParams::default()),
}
}
/// Implementation of `unapplied_slashes` runtime API
pub fn unapplied_slashes<T: disputes::slashing::Config>(
) -> Vec<(SessionIndex, CandidateHash, slashing::PendingSlashes)> {
<disputes::slashing::Pallet<T>>::unapplied_slashes()
}
/// Implementation of `submit_report_dispute_lost` runtime API
pub fn submit_unsigned_slashing_report<T: disputes::slashing::Config>(
dispute_proof: slashing::DisputeProof,
key_ownership_proof: slashing::OpaqueKeyOwnershipProof,
) -> Option<()> {
let key_ownership_proof = key_ownership_proof.decode()?;
<disputes::slashing::Pallet<T>>::submit_unsigned_slashing_report(
dispute_proof,
key_ownership_proof,
)
}
@@ -15,32 +15,3 @@
// along with Polkadot. If not, see <http://www.gnu.org/licenses/>.
//! 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<T: disputes::Config>(
) -> Vec<(SessionIndex, CandidateHash, DisputeState<T::BlockNumber>)> {
<disputes::Pallet<T>>::disputes()
}
/// Implementation of `unapplied_slashes` runtime API
pub fn unapplied_slashes<T: disputes::slashing::Config>(
) -> Vec<(SessionIndex, CandidateHash, vstaging::slashing::PendingSlashes)> {
<disputes::slashing::Pallet<T>>::unapplied_slashes()
}
/// Implementation of `submit_report_dispute_lost` runtime API
pub fn submit_unsigned_slashing_report<T: disputes::slashing::Config>(
dispute_proof: vstaging::slashing::DisputeProof,
key_ownership_proof: vstaging::slashing::OpaqueKeyOwnershipProof,
) -> Option<()> {
let key_ownership_proof = key_ownership_proof.decode()?;
<disputes::slashing::Pallet<T>>::submit_unsigned_slashing_report(
dispute_proof,
key_ownership_proof,
)
}
+1 -1
View File
@@ -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;
+28 -2
View File
@@ -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<BlockNumber>)> {
parachains_runtime_api_impl::get_session_disputes::<Runtime>()
}
fn unapplied_slashes(
) -> Vec<(SessionIndex, CandidateHash, slashing::PendingSlashes)> {
parachains_runtime_api_impl::unapplied_slashes::<Runtime>()
}
fn key_ownership_proof(
validator_id: ValidatorId,
) -> Option<slashing::OpaqueKeyOwnershipProof> {
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::<Runtime>(
dispute_proof,
key_ownership_proof,
)
}
}
impl beefy_primitives::BeefyApi<Block> for Runtime {
+9 -9
View File
@@ -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::<Runtime>()
) -> Vec<(SessionIndex, CandidateHash, slashing::PendingSlashes)> {
parachains_runtime_api_impl::unapplied_slashes::<Runtime>()
}
fn key_ownership_proof(
validator_id: ValidatorId,
) -> Option<vstaging::slashing::OpaqueKeyOwnershipProof> {
) -> Option<slashing::OpaqueKeyOwnershipProof> {
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::<Runtime>(
parachains_runtime_api_impl::submit_unsigned_slashing_report::<Runtime>(
dispute_proof,
key_ownership_proof,
)
+56 -9
View File
@@ -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 =
<Historical as KeyOwnerProofSystem<(KeyTypeId, pallet_babe::AuthorityId)>>::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<ParasSlashing>;
type WeightInfo = parachains_disputes::TestWeightInfo;
}
impl parachains_slashing::Config for Runtime {
type KeyOwnerProofSystem = Historical;
type KeyOwnerProof =
<Self::KeyOwnerProofSystem as KeyOwnerProofSystem<(KeyTypeId, ValidatorId)>>::Proof;
type KeyOwnerIdentification = <Self::KeyOwnerProofSystem as KeyOwnerProofSystem<(
KeyTypeId,
ValidatorId,
)>>::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<T>, Origin},
ParasDisputes: parachains_disputes::{Pallet, Storage, Event<T>},
ParasSlashing: parachains_slashing::{Pallet, Call, Storage, ValidateUnsigned},
Sudo: pallet_sudo::{Pallet, Call, Storage, Config<T>, Event<T>},
@@ -891,6 +913,31 @@ sp_api::impl_runtime_apis! {
fn disputes() -> Vec<(SessionIndex, CandidateHash, DisputeState<BlockNumber>)> {
runtime_impl::get_session_disputes::<Runtime>()
}
fn unapplied_slashes(
) -> Vec<(SessionIndex, CandidateHash, slashing::PendingSlashes)> {
runtime_impl::unapplied_slashes::<Runtime>()
}
fn key_ownership_proof(
validator_id: ValidatorId,
) -> Option<slashing::OpaqueKeyOwnershipProof> {
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::<Runtime>(
dispute_proof,
key_ownership_proof,
)
}
}
impl beefy_primitives::BeefyApi<Block> for Runtime {
+9 -11
View File
@@ -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::<Runtime>()
) -> Vec<(SessionIndex, CandidateHash, slashing::PendingSlashes)> {
parachains_runtime_api_impl::unapplied_slashes::<Runtime>()
}
fn key_ownership_proof(
validator_id: ValidatorId,
) -> Option<vstaging::slashing::OpaqueKeyOwnershipProof> {
) -> Option<slashing::OpaqueKeyOwnershipProof> {
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::<Runtime>(
parachains_runtime_api_impl::submit_unsigned_slashing_report::<Runtime>(
dispute_proof,
key_ownership_proof,
)