Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Commit

Permalink
Release parachain host API v4 (#6885)
Browse files Browse the repository at this point in the history
  • Loading branch information
s0me0ne-unkn0wn authored Mar 15, 2023
1 parent 40ab88b commit c717dbb
Show file tree
Hide file tree
Showing 30 changed files with 129 additions and 120 deletions.
2 changes: 1 addition & 1 deletion node/core/candidate-validation/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ use polkadot_node_subsystem::{
use polkadot_node_subsystem_util::executor_params_at_relay_parent;
use polkadot_parachain::primitives::{ValidationParams, ValidationResult as WasmValidationResult};
use polkadot_primitives::{
vstaging::ExecutorParams, CandidateCommitments, CandidateDescriptor, CandidateReceipt, Hash,
CandidateCommitments, CandidateDescriptor, CandidateReceipt, ExecutorParams, Hash,
OccupiedCoreAssumption, PersistedValidationData, PvfExecTimeoutKind, PvfPrepTimeoutKind,
ValidationCode, ValidationCodeHash,
};
Expand Down
4 changes: 2 additions & 2 deletions node/core/pvf/src/artifacts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
use crate::{error::PrepareError, host::PrepareResultSender, prepare::PrepareStats};
use always_assert::always;
use polkadot_parachain::primitives::ValidationCodeHash;
use polkadot_primitives::vstaging::ExecutorParamsHash;
use polkadot_primitives::ExecutorParamsHash;
use std::{
collections::HashMap,
path::{Path, PathBuf},
Expand Down Expand Up @@ -219,7 +219,7 @@ impl Artifacts {
#[cfg(test)]
mod tests {
use super::{ArtifactId, Artifacts};
use polkadot_primitives::vstaging::ExecutorParamsHash;
use polkadot_primitives::ExecutorParamsHash;
use sp_core::H256;
use std::{path::Path, str::FromStr};

Expand Down
2 changes: 1 addition & 1 deletion node/core/pvf/src/execute/queue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ use futures::{
stream::{FuturesUnordered, StreamExt as _},
Future, FutureExt,
};
use polkadot_primitives::vstaging::{ExecutorParams, ExecutorParamsHash};
use polkadot_primitives::{ExecutorParams, ExecutorParamsHash};
use slotmap::HopSlotMap;
use std::{
collections::VecDeque,
Expand Down
2 changes: 1 addition & 1 deletion node/core/pvf/src/execute/worker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ use futures_timer::Delay;
use parity_scale_codec::{Decode, Encode};

use polkadot_parachain::primitives::ValidationResult;
use polkadot_primitives::vstaging::ExecutorParams;
use polkadot_primitives::ExecutorParams;
use std::{
path::{Path, PathBuf},
sync::{mpsc::channel, Arc},
Expand Down
2 changes: 1 addition & 1 deletion node/core/pvf/src/executor_intf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

//! Interface to the Substrate Executor

use polkadot_primitives::vstaging::executor_params::{ExecutorParam, ExecutorParams};
use polkadot_primitives::{ExecutorParam, ExecutorParams};
use sc_executor_common::{
runtime_blob::RuntimeBlob,
wasm_runtime::{HeapAllocStrategy, InvokeMethod, WasmModule as _},
Expand Down
2 changes: 1 addition & 1 deletion node/core/pvf/src/host.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ use futures::{
Future, FutureExt, SinkExt, StreamExt,
};
use polkadot_parachain::primitives::ValidationResult;
use polkadot_primitives::vstaging::ExecutorParams;
use polkadot_primitives::ExecutorParams;
use std::{
collections::HashMap,
path::{Path, PathBuf},
Expand Down
2 changes: 1 addition & 1 deletion node/core/pvf/src/pvf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
use crate::artifacts::ArtifactId;
use parity_scale_codec::{Decode, Encode};
use polkadot_parachain::primitives::ValidationCodeHash;
use polkadot_primitives::vstaging::ExecutorParams;
use polkadot_primitives::ExecutorParams;
use sp_core::blake2_256;
use std::{
cmp::{Eq, PartialEq},
Expand Down
2 changes: 1 addition & 1 deletion node/core/pvf/src/testing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
//! N.B. This is not guarded with some feature flag. Overexposing items here may affect the final
//! artifact even for production builds.

use polkadot_primitives::vstaging::ExecutorParams;
use polkadot_primitives::ExecutorParams;

pub mod worker_common {
pub use crate::worker_common::{spawn_with_program_path, SpawnErr};
Expand Down
2 changes: 1 addition & 1 deletion node/core/pvf/tests/it/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ use polkadot_node_core_pvf::{
JOB_TIMEOUT_WALL_CLOCK_FACTOR,
};
use polkadot_parachain::primitives::{BlockData, ValidationParams, ValidationResult};
use polkadot_primitives::vstaging::{ExecutorParam, ExecutorParams};
use polkadot_primitives::{ExecutorParam, ExecutorParams};
use std::time::Duration;
use tokio::sync::Mutex;

Expand Down
11 changes: 5 additions & 6 deletions node/core/runtime-api/src/cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,11 @@ use lru::LruCache;
use sp_consensus_babe::Epoch;

use polkadot_primitives::{
vstaging::ExecutorParams, AuthorityDiscoveryId, BlockNumber, CandidateCommitments,
CandidateEvent, CandidateHash, CommittedCandidateReceipt, CoreState, DisputeState,
GroupRotationInfo, Hash, Id as ParaId, InboundDownwardMessage, InboundHrmpMessage,
OccupiedCoreAssumption, PersistedValidationData, PvfCheckStatement, ScrapedOnChainVotes,
SessionIndex, SessionInfo, ValidationCode, ValidationCodeHash, ValidatorId, ValidatorIndex,
ValidatorSignature,
AuthorityDiscoveryId, BlockNumber, CandidateCommitments, CandidateEvent, CandidateHash,
CommittedCandidateReceipt, CoreState, DisputeState, ExecutorParams, GroupRotationInfo, Hash,
Id as ParaId, InboundDownwardMessage, InboundHrmpMessage, OccupiedCoreAssumption,
PersistedValidationData, PvfCheckStatement, ScrapedOnChainVotes, SessionIndex, SessionInfo,
ValidationCode, ValidationCodeHash, ValidatorId, ValidatorIndex, ValidatorSignature,
};

/// For consistency we have the same capacity for all caches. We use 128 as we'll only need that
Expand Down
6 changes: 3 additions & 3 deletions node/subsystem-types/src/messages.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ use polkadot_node_primitives::{
SignedDisputeStatement, SignedFullStatement, ValidationResult,
};
use polkadot_primitives::{
vstaging::ExecutorParams, AuthorityDiscoveryId, BackedCandidate, BlockNumber, CandidateEvent,
CandidateHash, CandidateIndex, CandidateReceipt, CollatorId, CommittedCandidateReceipt,
CoreState, DisputeState, GroupIndex, GroupRotationInfo, Hash, Header as BlockHeader,
AuthorityDiscoveryId, BackedCandidate, BlockNumber, CandidateEvent, CandidateHash,
CandidateIndex, CandidateReceipt, CollatorId, CommittedCandidateReceipt, CoreState,
DisputeState, ExecutorParams, GroupIndex, GroupRotationInfo, Hash, Header as BlockHeader,
Id as ParaId, InboundDownwardMessage, InboundHrmpMessage, MultiDisputeStatementSet,
OccupiedCoreAssumption, PersistedValidationData, PvfCheckStatement, PvfExecTimeoutKind,
SessionIndex, SessionInfo, SignedAvailabilityBitfield, SignedAvailabilityBitfields,
Expand Down
4 changes: 2 additions & 2 deletions node/subsystem-types/src/runtime_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@

use async_trait::async_trait;
use polkadot_primitives::{
runtime_api::ParachainHost, vstaging::ExecutorParams, Block, BlockNumber, CandidateCommitments,
CandidateEvent, CandidateHash, CommittedCandidateReceipt, CoreState, DisputeState,
runtime_api::ParachainHost, Block, BlockNumber, CandidateCommitments, CandidateEvent,
CandidateHash, CommittedCandidateReceipt, CoreState, DisputeState, ExecutorParams,
GroupRotationInfo, Hash, Id, InboundDownwardMessage, InboundHrmpMessage,
OccupiedCoreAssumption, PersistedValidationData, PvfCheckStatement, ScrapedOnChainVotes,
SessionIndex, SessionInfo, ValidationCode, ValidationCodeHash, ValidatorId, ValidatorIndex,
Expand Down
2 changes: 1 addition & 1 deletion 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::vstaging::ExecutorParams;
use polkadot_primitives::ExecutorParams;

pub use overseer::{
gen::{OrchestraError as OverseerError, Timeout},
Expand Down
2 changes: 1 addition & 1 deletion node/test/performance-test/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

use polkadot_erasure_coding::{obtain_chunks, reconstruct};
use polkadot_node_core_pvf::{sc_executor_common, sp_maybe_compressed_blob};
use polkadot_primitives::vstaging::ExecutorParams;
use polkadot_primitives::ExecutorParams;
use std::time::{Duration, Instant};

mod constants;
Expand Down
17 changes: 9 additions & 8 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)]

// `v2` is currently the latest stable version of the runtime API.
pub mod v2;
// `v4` is currently the latest stable version of the runtime API.
pub mod v4;

// The 'staging' version is special - it contains primitives which are
// still in development. Once they are considered stable, they will be
Expand All @@ -33,7 +33,7 @@ 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 v2::{
pub use v4::{
byzantine_threshold, check_candidate_backing, collator_signature_payload, metric_definitions,
supermajority_threshold, well_known_keys, AbridgedHostConfiguration, AbridgedHrmpChannel,
AccountId, AccountIndex, AccountPublic, ApprovalVote, AssignmentId, AuthorityDiscoveryId,
Expand All @@ -42,10 +42,11 @@ pub use v2::{
CandidateReceipt, CheckedDisputeStatementSet, CheckedMultiDisputeStatementSet, CollatorId,
CollatorSignature, CommittedCandidateReceipt, CompactStatement, ConsensusLog, CoreIndex,
CoreOccupied, CoreState, DisputeState, DisputeStatement, DisputeStatementSet, DownwardMessage,
EncodeAs, ExplicitDisputeStatement, GroupIndex, GroupRotationInfo, Hash, HashT, HeadData,
Header, HrmpChannelId, Id, InboundDownwardMessage, InboundHrmpMessage, IndexedVec,
InherentData, InvalidDisputeStatementKind, Moment, MultiDisputeStatementSet, Nonce,
OccupiedCore, OccupiedCoreAssumption, OutboundHrmpMessage, ParathreadClaim, ParathreadEntry,
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,
RuntimeMetricLabel, RuntimeMetricLabelValue, RuntimeMetricLabelValues, RuntimeMetricLabels,
RuntimeMetricOp, RuntimeMetricUpdate, ScheduledCore, ScrapedOnChainVotes, SessionIndex,
Expand All @@ -59,4 +60,4 @@ pub use v2::{
};

#[cfg(feature = "std")]
pub use v2::{AssignmentPair, CollatorPair, ValidatorPair};
pub use v4::{AssignmentPair, CollatorPair, ValidatorPair};
12 changes: 4 additions & 8 deletions primitives/src/runtime_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,8 @@
//! from the stable primitives.

use crate::{
vstaging, BlockNumber, CandidateCommitments, CandidateEvent, CandidateHash,
CommittedCandidateReceipt, CoreState, DisputeState, GroupRotationInfo, OccupiedCoreAssumption,
BlockNumber, CandidateCommitments, CandidateEvent, CandidateHash, CommittedCandidateReceipt,
CoreState, DisputeState, ExecutorParams, GroupRotationInfo, OccupiedCoreAssumption,
PersistedValidationData, PvfCheckStatement, ScrapedOnChainVotes, SessionIndex, SessionInfo,
ValidatorId, ValidatorIndex, ValidatorSignature,
};
Expand All @@ -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(2)]
#[api_version(4)]
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 @@ -213,14 +213,10 @@ sp_api::decl_runtime_apis! {
fn validation_code_hash(para_id: ppp::Id, assumption: OccupiedCoreAssumption)
-> Option<ppp::ValidationCodeHash>;

/***** STAGING *****/

/// Returns all onchain disputes.
#[api_version(3)]
fn disputes() -> Vec<(SessionIndex, CandidateHash, DisputeState<BlockNumber>)>;

/// Returns execution parameters for the session.
#[api_version(4)]
fn session_executor_params(session_index: SessionIndex) -> Option<vstaging::ExecutorParams>;
fn session_executor_params(session_index: SessionIndex) -> Option<ExecutorParams>;
}
}
File renamed without changes.
3 changes: 3 additions & 0 deletions primitives/src/v2/mod.rs → primitives/src/v4/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1716,6 +1716,9 @@ pub enum PvfExecTimeoutKind {
Approval,
}

pub mod executor_params;
pub use executor_params::{ExecutorParam, ExecutorParams, ExecutorParamsHash};

#[cfg(test)]
mod tests {
use super::*;
Expand Down
File renamed without changes.
3 changes: 0 additions & 3 deletions primitives/src/vstaging/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,3 @@
//! Staging Primitives.

// Put any primitives used by staging APIs functions here

pub mod executor_params;
pub use executor_params::{ExecutorParam, ExecutorParams, ExecutorParamsHash};
20 changes: 14 additions & 6 deletions runtime/kusama/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@
use pallet_nis::WithMaximumOf;
use parity_scale_codec::{Decode, Encode, MaxEncodedLen};
use primitives::{
AccountId, AccountIndex, Balance, BlockNumber, CandidateEvent, CommittedCandidateReceipt,
CoreState, GroupRotationInfo, Hash, Id as ParaId, InboundDownwardMessage, InboundHrmpMessage,
Moment, Nonce, OccupiedCoreAssumption, PersistedValidationData, ScrapedOnChainVotes,
SessionInfo, Signature, ValidationCode, ValidationCodeHash, ValidatorId, ValidatorIndex,
LOWEST_PUBLIC_ID,
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,
};
use runtime_common::{
auctions, claims, crowdloan, impl_runtime_weights, impls::DealWithFees, paras_registrar,
Expand All @@ -41,7 +41,7 @@ use runtime_parachains::{
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, reward_points as parachains_reward_points,
runtime_api_impl::v2 as parachains_runtime_api_impl, scheduler as parachains_scheduler,
runtime_api_impl::v4 as parachains_runtime_api_impl, scheduler as parachains_scheduler,
session_info as parachains_session_info, shared as parachains_shared, ump as parachains_ump,
};

Expand Down Expand Up @@ -1678,6 +1678,10 @@ sp_api::impl_runtime_apis! {
parachains_runtime_api_impl::session_info::<Runtime>(index)
}

fn session_executor_params(session_index: SessionIndex) -> Option<ExecutorParams> {
parachains_runtime_api_impl::session_executor_params::<Runtime>(session_index)
}

fn dmq_contents(recipient: ParaId) -> Vec<InboundDownwardMessage<BlockNumber>> {
parachains_runtime_api_impl::dmq_contents::<Runtime>(recipient)
}
Expand Down Expand Up @@ -1712,6 +1716,10 @@ sp_api::impl_runtime_apis! {
{
parachains_runtime_api_impl::validation_code_hash::<Runtime>(para_id, assumption)
}

fn disputes() -> Vec<(SessionIndex, CandidateHash, DisputeState<BlockNumber>)> {
parachains_runtime_api_impl::get_session_disputes::<Runtime>()
}
}

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 v2;
pub mod v4;
pub mod vstaging;
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,16 @@
//! functions.

use crate::{
configuration, dmp, hrmp, inclusion, initializer, paras, paras_inherent, scheduler,
configuration, disputes, dmp, hrmp, inclusion, initializer, paras, paras_inherent, scheduler,
session_info, shared,
};
use primitives::{
AuthorityDiscoveryId, CandidateEvent, CommittedCandidateReceipt, CoreIndex, CoreOccupied,
CoreState, GroupIndex, GroupRotationInfo, Hash, Id as ParaId, InboundDownwardMessage,
InboundHrmpMessage, OccupiedCore, OccupiedCoreAssumption, PersistedValidationData,
PvfCheckStatement, ScheduledCore, ScrapedOnChainVotes, SessionIndex, SessionInfo,
ValidationCode, ValidationCodeHash, ValidatorId, ValidatorIndex, ValidatorSignature,
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::*};
Expand Down Expand Up @@ -399,3 +400,24 @@ where
<paras::Pallet<T>>::current_code_hash(&para_id)
})
}

/// 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()
}

/// Get session executor parameter set
pub fn session_executor_params<T: session_info::Config>(
session_index: SessionIndex,
) -> Option<ExecutorParams> {
// This is to bootstrap the storage working around the runtime migration issue:
// https://github.com/paritytech/substrate/issues/9997
// After the bootstrap is complete (no less than 7 session passed with the runtime)
// this code should be replaced with a pure
// <session_info::Pallet<T>>::session_executor_params(session_index) call.
match <session_info::Pallet<T>>::session_executor_params(session_index) {
Some(ep) => Some(ep),
None => Some(ExecutorParams::default()),
}
}
25 changes: 0 additions & 25 deletions runtime/parachains/src/runtime_api_impl/vstaging.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,28 +15,3 @@
// along with Polkadot. If not, see <http://www.gnu.org/licenses/>.

//! Put implementations of functions from staging APIs here.

use crate::{disputes, session_info};
use primitives::{vstaging::ExecutorParams, 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()
}

/// Get session executor parameter set
pub fn session_executor_params<T: session_info::Config>(
session_index: SessionIndex,
) -> Option<ExecutorParams> {
// This is to bootstrap the storage working around the runtime migration issue:
// https://github.com/paritytech/substrate/issues/9997
// After the bootstrap is complete (no less than 7 session passed with the runtime)
// this code should be replaced with a pure
// <session_info::Pallet<T>>::session_executor_params(session_index) call.
match <session_info::Pallet<T>>::session_executor_params(session_index) {
Some(ep) => Some(ep),
None => Some(ExecutorParams::default()),
}
}
3 changes: 1 addition & 2 deletions runtime/parachains/src/session_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@ use frame_support::{
traits::{OneSessionHandler, ValidatorSet, ValidatorSetWithIdentification},
};
use primitives::{
vstaging::{ExecutorParam, ExecutorParams},
AssignmentId, AuthorityDiscoveryId, SessionIndex, SessionInfo,
AssignmentId, AuthorityDiscoveryId, ExecutorParam, ExecutorParams, SessionIndex, SessionInfo,
};
use sp_std::vec::Vec;

Expand Down
Loading

0 comments on commit c717dbb

Please sign in to comment.