Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.
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
27 changes: 24 additions & 3 deletions node/core/dispute-coordinator/src/initialized.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
17 changes: 12 additions & 5 deletions node/core/dispute-coordinator/src/scraping/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};

Expand Down Expand Up @@ -67,7 +67,7 @@ const LRU_OBSERVED_BLOCKS_CAPACITY: NonZeroUsize = match NonZeroUsize::new(20) {
pub struct ScrapedUpdates {
pub on_chain_votes: Vec<ScrapedOnChainVotes>,
pub included_receipts: Vec<CandidateReceipt>,
pub unapplied_slashes: Vec<(SessionIndex, CandidateHash, vstaging::slashing::PendingSlashes)>,
pub unapplied_slashes: Vec<(SessionIndex, CandidateHash, PendingSlashes)>,
}

impl ScrapedUpdates {
Expand Down Expand Up @@ -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,
Expand Down
29 changes: 13 additions & 16 deletions node/subsystem-types/src/messages.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -607,21 +607,18 @@ pub enum RuntimeApiRequest {
/// Returns all on-chain disputes at given block number. Available in `v3`.
Disputes(RuntimeApiSender<Vec<(SessionIndex, CandidateHash, DisputeState<BlockNumber>)>>),
/// Returns a list of validators that lost a past session dispute and need to be slashed.
/// `VStaging`
/// `V5`
UnappliedSlashes(
RuntimeApiSender<Vec<(SessionIndex, CandidateHash, vstaging::slashing::PendingSlashes)>>,
RuntimeApiSender<Vec<(SessionIndex, CandidateHash, slashing::PendingSlashes)>>,
),
/// Returns a merkle proof of a validator session key.
/// `VStaging`
KeyOwnershipProof(
ValidatorId,
RuntimeApiSender<Option<vstaging::slashing::OpaqueKeyOwnershipProof>>,
),
/// `V5`
KeyOwnershipProof(ValidatorId, RuntimeApiSender<Option<slashing::OpaqueKeyOwnershipProof>>),
/// 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<Option<()>>,
),
}
Expand All @@ -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.
Expand Down
12 changes: 6 additions & 6 deletions node/subsystem-util/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand All @@ -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,
Expand Down Expand Up @@ -212,9 +212,9 @@ specialize_requests! {
-> Option<ValidationCodeHash>; ValidationCodeHash;
fn request_on_chain_votes() -> Option<ScrapedOnChainVotes>; FetchOnChainVotes;
fn request_session_executor_params(session_index: SessionIndex) -> Option<ExecutorParams>;SessionExecutorParams;
fn request_unapplied_slashes() -> Vec<(SessionIndex, CandidateHash, vstaging::slashing::PendingSlashes)>; UnappliedSlashes;
fn request_key_ownership_proof(validator_id: ValidatorId) -> Option<vstaging::slashing::OpaqueKeyOwnershipProof>; 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<slashing::OpaqueKeyOwnershipProof>; 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
Expand Down
28 changes: 14 additions & 14 deletions primitives/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
Expand All @@ -60,4 +60,4 @@ pub use v4::{
};

#[cfg(feature = "std")]
pub use v4::{AssignmentPair, CollatorPair, ValidatorPair};
pub use v5::{AssignmentPair, CollatorPair, ValidatorPair};
8 changes: 4 additions & 4 deletions primitives/src/runtime_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<H: Encode + Decode = pcp::v2::Hash, N: Encode + Decode = pcp::v2::BlockNumber> {
/// Get the current validators.
fn validators() -> Vec<ValidatorId>;
Expand Down Expand Up @@ -220,18 +220,18 @@ sp_api::decl_runtime_apis! {
fn session_executor_params(session_index: SessionIndex) -> Option<ExecutorParams>;

/// 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.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not ideal loosing version information when bumping base but it is what it is :(

fn key_ownership_proof(
validator_id: ValidatorId,
) -> Option<vstaging::slashing::OpaqueKeyOwnershipProof>;

/// 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,
Expand Down
2 changes: 2 additions & 0 deletions primitives/src/v4/mod.rs → primitives/src/v5/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down
4 changes: 2 additions & 2 deletions primitives/src/vstaging/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand All @@ -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
Expand Down
30 changes: 28 additions & 2 deletions runtime/kusama/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
};
Expand Down Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion runtime/parachains/src/runtime_api_impl/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Loading