diff --git a/polkadot/node/collation-generation/src/lib.rs b/polkadot/node/collation-generation/src/lib.rs index 21b7f4f7ae..7702e2efef 100644 --- a/polkadot/node/collation-generation/src/lib.rs +++ b/polkadot/node/collation-generation/src/lib.rs @@ -731,7 +731,7 @@ mod tests { // correct descriptor let expect_pov_hash = test_collation().proof_of_validity.hash(); let expect_validation_data_hash - = PersistedValidationData::::default().hash(); + = PersistedValidationData::::default().hash(); let expect_relay_parent = Hash::repeat_byte(4); let expect_payload = collator_signature_payload( &expect_relay_parent, diff --git a/polkadot/node/core/proposer/src/lib.rs b/polkadot/node/core/proposer/src/lib.rs index 822f38f8a8..1a8fd5c28a 100644 --- a/polkadot/node/core/proposer/src/lib.rs +++ b/polkadot/node/core/proposer/src/lib.rs @@ -26,7 +26,7 @@ use polkadot_node_subsystem::{ }; use polkadot_overseer::OverseerHandler; use polkadot_primitives::v1::{ - Block, Hash, Header, + Block, Hash, Header, InherentData as ParachainsInherentData, }; use sc_block_builder::{BlockBuilderApi, BlockBuilderProvider}; use sc_telemetry::TelemetryHandle; @@ -206,24 +206,29 @@ where let span = jaeger::Span::new(self.parent_header_hash, "propose"); let _span = span.child("get-provisioner"); - let provisioner_data = match self.get_provisioner_data().await { - Ok(pd) => pd, + let parachains_inherent_data = match self.get_provisioner_data().await { + Ok(pd) => ParachainsInherentData { + bitfields: pd.bitfields, + backed_candidates: pd.backed_candidates, + disputes: pd.disputes, + parent_header: self.parent_header, + }, Err(err) => { tracing::warn!(err = ?err, "could not get provisioner inherent data; injecting default data"); - Default::default() + ParachainsInherentData { + bitfields: Vec::new(), + backed_candidates: Vec::new(), + disputes: Vec::new(), + parent_header: self.parent_header, + } } }; drop(_span); - let inclusion_inherent_data = ( - provisioner_data.0, - provisioner_data.1, - self.parent_header, - ); inherent_data.put_data( - polkadot_primitives::v1::INCLUSION_INHERENT_IDENTIFIER, - &inclusion_inherent_data, + polkadot_primitives::v1::PARACHAINS_INHERENT_IDENTIFIER, + ¶chains_inherent_data, )?; let _span = span.child("authorship-propose"); diff --git a/polkadot/node/core/provisioner/src/lib.rs b/polkadot/node/core/provisioner/src/lib.rs index 82a0033c52..5320fb931d 100644 --- a/polkadot/node/core/provisioner/src/lib.rs +++ b/polkadot/node/core/provisioner/src/lib.rs @@ -296,12 +296,16 @@ async fn send_inherent_data( candidates, relay_parent, from_job, - ) - .await?; + ).await?; + + let inherent_data = ProvisionerInherentData { + bitfields, + backed_candidates: candidates, + disputes: Vec::new(), // until disputes are implemented. + }; - let res = (bitfields, candidates); for return_sender in return_senders { - return_sender.send(res.clone()).map_err(|_data| Error::InherentDataReturnChannel)?; + return_sender.send(inherent_data.clone()).map_err(|_data| Error::InherentDataReturnChannel)?; } Ok(()) diff --git a/polkadot/node/core/provisioner/src/tests.rs b/polkadot/node/core/provisioner/src/tests.rs index 9b9409fbf5..1842b67559 100644 --- a/polkadot/node/core/provisioner/src/tests.rs +++ b/polkadot/node/core/provisioner/src/tests.rs @@ -342,7 +342,7 @@ mod select_candidates { let mock_cores = mock_availability_cores(); let n_cores = mock_cores.len(); - let empty_hash = PersistedValidationData::::default().hash(); + let empty_hash = PersistedValidationData::::default().hash(); let candidate_template = CandidateReceipt { descriptor: CandidateDescriptor { @@ -415,7 +415,7 @@ mod select_candidates { let mock_cores = mock_availability_cores(); let n_cores = mock_cores.len(); - let empty_hash = PersistedValidationData::::default().hash(); + let empty_hash = PersistedValidationData::::default().hash(); // why those particular indices? see the comments on mock_availability_cores() // the first candidate with code is included out of [1, 4, 7, 8, 10]. diff --git a/polkadot/node/subsystem/src/messages.rs b/polkadot/node/subsystem/src/messages.rs index d9a17bb3da..f80cd77a4c 100644 --- a/polkadot/node/subsystem/src/messages.rs +++ b/polkadot/node/subsystem/src/messages.rs @@ -44,7 +44,7 @@ use polkadot_primitives::v1::{ PersistedValidationData, SessionIndex, SignedAvailabilityBitfield, ValidationCode, ValidatorId, CandidateHash, ValidatorIndex, ValidatorSignature, InboundDownwardMessage, InboundHrmpMessage, - CandidateIndex, GroupIndex, + CandidateIndex, GroupIndex, MultiDisputeStatementSet, SignedAvailabilityBitfields, }; use polkadot_statement_table::v1::Misbehavior; use polkadot_procmacro_subsystem_dispatch_gen::subsystem_dispatch_gen; @@ -550,10 +550,16 @@ pub enum ProvisionableData { Dispute(Hash, ValidatorSignature), } -/// This data needs to make its way from the provisioner into the InherentData. -/// -/// There, it is used to construct the ParaInherent. -pub type ProvisionerInherentData = (Vec, Vec); +/// Inherent data returned by the provisioner +#[derive(Debug, Clone)] +pub struct ProvisionerInherentData { + /// Signed bitfields. + pub bitfields: SignedAvailabilityBitfields, + /// Backed candidates. + pub backed_candidates: Vec, + /// Dispute statement sets. + pub disputes: MultiDisputeStatementSet, +} /// Message to the Provisioner. /// diff --git a/polkadot/node/test/client/src/block_builder.rs b/polkadot/node/test/client/src/block_builder.rs index 85a1873934..00ca965dff 100644 --- a/polkadot/node/test/client/src/block_builder.rs +++ b/polkadot/node/test/client/src/block_builder.rs @@ -16,7 +16,7 @@ use crate::{Client, FullBackend}; use polkadot_test_runtime::{GetLastTimestamp, UncheckedExtrinsic}; -use polkadot_primitives::v1::Block; +use polkadot_primitives::v1::{Block, InherentData as ParachainsInherentData}; use sp_runtime::{generic::BlockId, Digest, DigestItem}; use sp_api::ProvideRuntimeApi; use sp_consensus_babe::{BABE_ENGINE_ID, digests::{PreDigest, SecondaryPlainPreDigest}}; @@ -100,18 +100,20 @@ impl InitPolkadotBlockBuilder for Client { let parent_header = self.header(at) .expect("Get the parent block header") .expect("The target block header must exist"); - let provisioner_data = polkadot_node_subsystem::messages::ProvisionerInherentData::default(); - let inclusion_inherent_data = ( - provisioner_data.0, - provisioner_data.1, - parent_header, - ); + + let parachains_inherent_data = ParachainsInherentData { + bitfields: Vec::new(), + backed_candidates: Vec::new(), + disputes: Vec::new(), + parent_header: parent_header, + }; + inherent_data .put_data( - polkadot_primitives::v1::INCLUSION_INHERENT_IDENTIFIER, - &inclusion_inherent_data, + polkadot_primitives::v1::PARACHAINS_INHERENT_IDENTIFIER, + ¶chains_inherent_data, ) - .expect("Put inclusion inherent data"); + .expect("Put parachains inherent data"); let inherents = block_builder.create_inherents(inherent_data).expect("Creates inherents"); diff --git a/polkadot/primitives/src/v1.rs b/polkadot/primitives/src/v1.rs index 4cb8a09b81..ab0d4357a2 100644 --- a/polkadot/primitives/src/v1.rs +++ b/polkadot/primitives/src/v1.rs @@ -22,7 +22,7 @@ use parity_scale_codec::{Encode, Decode}; use bitvec::vec::BitVec; use primitives::RuntimeDebug; -use runtime_primitives::traits::AppVerify; +use runtime_primitives::traits::{AppVerify, Header as HeaderT}; use inherents::InherentIdentifier; use sp_arithmetic::traits::{BaseArithmetic, Saturating}; use application_crypto::KeyTypeId; @@ -169,8 +169,8 @@ pub mod well_known_keys { } } -/// Unique identifier for the Inclusion Inherent -pub const INCLUSION_INHERENT_IDENTIFIER: InherentIdentifier = *b"inclusn0"; +/// Unique identifier for the Parachains Inherent +pub const PARACHAINS_INHERENT_IDENTIFIER: InherentIdentifier = *b"parachn0"; /// The key type ID for parachain assignment key. pub const ASSIGNMENT_KEY_TYPE_ID: KeyTypeId = KeyTypeId(*b"asgn"); @@ -316,7 +316,7 @@ pub struct FullCandidateReceipt { /// point. The hash of the persisted validation data should /// match the `persisted_validation_data_hash` in the descriptor /// of the receipt. - pub validation_data: PersistedValidationData, + pub validation_data: PersistedValidationData, } /// A candidate-receipt with commitments directly included. @@ -395,18 +395,18 @@ impl Ord for CommittedCandidateReceipt { /// during inclusion for each candidate and therefore lies on the critical path of inclusion. #[derive(PartialEq, Eq, Clone, Encode, Decode)] #[cfg_attr(feature = "std", derive(Debug, Default, MallocSizeOf))] -pub struct PersistedValidationData { +pub struct PersistedValidationData { /// The parent head-data. pub parent_head: HeadData, /// The relay-chain block number this is in the context of. pub relay_parent_number: N, /// The relay-chain block storage root this is in the context of. - pub relay_parent_storage_root: Hash, + pub relay_parent_storage_root: H, /// The maximum legal size of a POV block, in bytes. pub max_pov_size: u32, } -impl PersistedValidationData { +impl PersistedValidationData { /// Compute the blake2-256 hash of the persisted validation data. pub fn hash(&self) -> Hash { BlakeTwo256::hash_of(self) @@ -820,7 +820,7 @@ sp_api::decl_runtime_apis! { /// and the para already occupies a core. #[skip_initialize_block] fn persisted_validation_data(para_id: Id, assumption: OccupiedCoreAssumption) - -> Option>; + -> Option>; /// Checks if the given validation outputs pass the acceptance criteria. #[skip_initialize_block] @@ -991,6 +991,95 @@ impl From for runtime_primitives::DigestItem { } } +/// A statement about a candidate, to be used within the dispute resolution process. +/// +/// Statements are either in favor of the candidate's validity or against it. +#[derive(Encode, Decode, Clone, PartialEq, RuntimeDebug)] +pub enum DisputeStatement { + /// A valid statement, of the given kind. + #[codec(index = 0)] + Valid(ValidDisputeStatementKind), + /// An invalid statement, of the given kind. + #[codec(index = 1)] + Invalid(InvalidDisputeStatementKind), +} + +/// Different kinds of statements of validity on a candidate. +#[derive(Encode, Decode, Clone, PartialEq, RuntimeDebug)] +pub enum ValidDisputeStatementKind { + /// An explicit statement issued as part of a dispute. + #[codec(index = 0)] + Explicit, + /// A seconded statement on a candidate from the backing phase. + #[codec(index = 1)] + BackingSeconded, + /// A valid statement on a candidate from the backing phase. + #[codec(index = 2)] + BackingValid, + /// An approval vote from the approval checking phase. + #[codec(index = 3)] + ApprovalChecking, +} + +/// Different kinds of statements of invalidity on a candidate. +#[derive(Encode, Decode, Clone, PartialEq, RuntimeDebug)] +pub enum InvalidDisputeStatementKind { + /// An explicit statement issued as part of a dispute. + #[codec(index = 0)] + Explicit, +} + +/// An explicit statement on a candidate issued as part of a dispute. +#[derive(Encode, Decode, Clone, PartialEq, RuntimeDebug)] +pub struct ExplicitDisputeStatement { + /// Whether the candidate is valid + pub valid: bool, + /// The candidate hash. + pub candidate_hash: CandidateHash, + /// The session index of the candidate. + pub session: SessionIndex, +} + +/// A set of statements about a specific candidate. +#[derive(Encode, Decode, Clone, PartialEq, RuntimeDebug)] +pub struct DisputeStatementSet { + /// The candidate referenced by this set. + pub candidate_hash: CandidateHash, + /// The session index of the candidate. + pub session: SessionIndex, + /// Statements about the candidate. + pub statements: Vec<(DisputeStatement, ValidatorIndex, ValidatorSignature)>, +} + +/// A set of dispute statements. +pub type MultiDisputeStatementSet = Vec; + +/// The entire state of a dispute. +#[derive(Encode, Decode, Clone, RuntimeDebug)] +pub struct DisputeState { + /// A bitfield indicating all validators for the candidate. + pub validators_for: BitVec, // one bit per validator. + /// A bitfield indicating all validators against the candidate. + pub validators_against: BitVec, // one bit per validator. + /// The block number at which the dispute started on-chain. + pub start: N, + /// The block number at which the dispute concluded on-chain. + pub concluded_at: Option, +} + +/// Parachains inherent-data passed into the runtime by a block author +#[derive(Encode, Decode, Clone, PartialEq, RuntimeDebug)] +pub struct InherentData { + /// Signed bitfields by validators about availability. + pub bitfields: SignedAvailabilityBitfields, + /// Backed candidates for inclusion in the block. + pub backed_candidates: Vec>, + /// Sets of dispute votes for inclusion, + pub disputes: MultiDisputeStatementSet, + /// The parent block header. Used for checking state proofs. + pub parent_header: HDR, +} + #[cfg(test)] mod tests { use super::*; diff --git a/polkadot/runtime/kusama/src/lib.rs b/polkadot/runtime/kusama/src/lib.rs index 0d18f4d9ce..3b2bdea6f1 100644 --- a/polkadot/runtime/kusama/src/lib.rs +++ b/polkadot/runtime/kusama/src/lib.rs @@ -1173,7 +1173,7 @@ sp_api::impl_runtime_apis! { } fn persisted_validation_data(_: Id, _: OccupiedCoreAssumption) - -> Option> { + -> Option> { None } fn check_validation_outputs( diff --git a/polkadot/runtime/parachains/src/inclusion.rs b/polkadot/runtime/parachains/src/inclusion.rs index 495ded3720..a1ae846a91 100644 --- a/polkadot/runtime/parachains/src/inclusion.rs +++ b/polkadot/runtime/parachains/src/inclusion.rs @@ -25,7 +25,7 @@ use primitives::v1::{ CandidateCommitments, CandidateDescriptor, ValidatorIndex, Id as ParaId, AvailabilityBitfield as AvailabilityBitfield, SignedAvailabilityBitfields, SigningContext, BackedCandidate, CoreIndex, GroupIndex, CommittedCandidateReceipt, - CandidateReceipt, HeadData, CandidateHash, Hash, + CandidateReceipt, HeadData, CandidateHash, }; use frame_support::{ decl_storage, decl_module, decl_error, decl_event, ensure, dispatch::DispatchResult, IterableStorageMap, @@ -378,7 +378,7 @@ impl Module { /// Both should be sorted ascending by core index, and the candidates should be a subset of /// scheduled cores. If these conditions are not met, the execution of the function fails. pub(crate) fn process_candidates( - parent_storage_root: Hash, + parent_storage_root: T::Hash, candidates: Vec>, scheduled: Vec, group_validators: impl Fn(GroupIndex) -> Option>, diff --git a/polkadot/runtime/parachains/src/lib.rs b/polkadot/runtime/parachains/src/lib.rs index 9e140d5f58..b486d82958 100644 --- a/polkadot/runtime/parachains/src/lib.rs +++ b/polkadot/runtime/parachains/src/lib.rs @@ -25,9 +25,9 @@ pub mod configuration; pub mod shared; pub mod inclusion; -pub mod inclusion_inherent; pub mod initializer; pub mod paras; +pub mod paras_inherent; pub mod scheduler; pub mod session_info; pub mod origin; diff --git a/polkadot/runtime/parachains/src/mock.rs b/polkadot/runtime/parachains/src/mock.rs index 25ef134651..68a4771873 100644 --- a/polkadot/runtime/parachains/src/mock.rs +++ b/polkadot/runtime/parachains/src/mock.rs @@ -134,7 +134,7 @@ impl crate::inclusion::Config for Test { type RewardValidators = TestRewardValidators; } -impl crate::inclusion_inherent::Config for Test { } +impl crate::paras_inherent::Config for Test { } impl crate::session_info::Config for Test { } diff --git a/polkadot/runtime/parachains/src/inclusion_inherent.rs b/polkadot/runtime/parachains/src/paras_inherent.rs similarity index 81% rename from polkadot/runtime/parachains/src/inclusion_inherent.rs rename to polkadot/runtime/parachains/src/paras_inherent.rs index 364ab2d0a0..c44352089b 100644 --- a/polkadot/runtime/parachains/src/inclusion_inherent.rs +++ b/polkadot/runtime/parachains/src/paras_inherent.rs @@ -22,8 +22,9 @@ //! this module. use sp_std::prelude::*; +use sp_runtime::traits::Header as HeaderT; use primitives::v1::{ - BackedCandidate, SignedAvailabilityBitfields, INCLUSION_INHERENT_IDENTIFIER, Header, + BackedCandidate, PARACHAINS_INHERENT_IDENTIFIER, InherentData as ParachainsInherentData, }; use frame_support::{ decl_error, decl_module, decl_storage, ensure, @@ -43,14 +44,14 @@ const LOG_TARGET: &str = "runtime::inclusion-inherent"; // In the future, we should benchmark these consts; these are all untested assumptions for now. const BACKED_CANDIDATE_WEIGHT: Weight = 100_000; const INCLUSION_INHERENT_CLAIMED_WEIGHT: Weight = 1_000_000_000; -// we assume that 75% of an inclusion inherent's weight is used processing backed candidates +// we assume that 75% of an paras inherent's weight is used processing backed candidates const MINIMAL_INCLUSION_INHERENT_WEIGHT: Weight = INCLUSION_INHERENT_CLAIMED_WEIGHT / 4; pub trait Config: inclusion::Config + scheduler::Config {} decl_storage! { - trait Store for Module as ParaInclusionInherent { - /// Whether the inclusion inherent was included within this block. + trait Store for Module as ParaInherent { + /// Whether the paras inherent was included within this block. /// /// The `Option<()>` is effectively a bool, but it never hits storage in the `None` variant /// due to the guarantees of FRAME's storage APIs. @@ -71,7 +72,7 @@ decl_error! { } decl_module! { - /// The inclusion inherent module. + /// The paras inherent module. pub struct Module for enum Call where origin: ::Origin { type Error = Error; @@ -85,17 +86,22 @@ decl_module! { } } - /// Include backed candidates and bitfields. + /// Enter the paras inherent. This will process bitfields and backed candidates. #[weight = ( - MINIMAL_INCLUSION_INHERENT_WEIGHT + backed_candidates.len() as Weight * BACKED_CANDIDATE_WEIGHT, + MINIMAL_INCLUSION_INHERENT_WEIGHT + data.backed_candidates.len() as Weight * BACKED_CANDIDATE_WEIGHT, DispatchClass::Mandatory, )] - pub fn inclusion( + pub fn enter( origin, - signed_bitfields: SignedAvailabilityBitfields, - backed_candidates: Vec>, - parent_header: Header, + data: ParachainsInherentData, ) -> DispatchResultWithPostInfo { + let ParachainsInherentData { + bitfields: signed_bitfields, + backed_candidates, + parent_header, + disputes: _, + } = data; + ensure_none(origin)?; ensure!(!::exists(), Error::::TooManyInclusionInherents); @@ -137,7 +143,7 @@ decl_module! { let backed_candidates_len = backed_candidates.len() as Weight; // Process backed candidates according to scheduled cores. - let parent_storage_root = parent_header.state_root; + let parent_storage_root = parent_header.state_root().clone(); let occupied = >::process_candidates( parent_storage_root, backed_candidates, @@ -195,7 +201,7 @@ fn limit_backed_candidates( }); } - // the weight of the inclusion inherent is already included in the current block weight, + // the weight of the paras inherent is already included in the current block weight, // so our operation is simple: if the block is currently overloaded, make this intrinsic smaller if frame_system::Pallet::::block_weight().total() > ::BlockWeights::get().max_block { Vec::new() @@ -207,39 +213,49 @@ fn limit_backed_candidates( impl ProvideInherent for Module { type Call = Call; type Error = MakeFatalError<()>; - const INHERENT_IDENTIFIER: InherentIdentifier = INCLUSION_INHERENT_IDENTIFIER; + const INHERENT_IDENTIFIER: InherentIdentifier = PARACHAINS_INHERENT_IDENTIFIER; fn create_inherent(data: &InherentData) -> Option { - data.get_data(&Self::INHERENT_IDENTIFIER) - .expect("inclusion inherent data failed to decode") - .map( - |(signed_bitfields, backed_candidates, parent_header): ( - SignedAvailabilityBitfields, - Vec>, - Header, - )| { - // Sanity check: session changes can invalidate an inherent, and we _really_ don't want that to happen. - // See github.com/paritytech/polkadot/issues/1327 - let (signed_bitfields, backed_candidates) = match Self::inclusion( - frame_system::RawOrigin::None.into(), - signed_bitfields.clone(), - backed_candidates.clone(), - parent_header.clone(), - ) { - Ok(_) => (signed_bitfields, backed_candidates), - Err(err) => { - log::warn!( - target: LOG_TARGET, - "dropping signed_bitfields and backed_candidates because they produced \ - an invalid inclusion inherent: {:?}", - err, - ); - (Vec::new().into(), Vec::new()) - } - }; - Call::inclusion(signed_bitfields, backed_candidates, parent_header) + let inherent_data: ParachainsInherentData + = match data.get_data(&Self::INHERENT_IDENTIFIER) + { + Ok(Some(d)) => d, + Ok(None) => return None, + Err(_) => { + log::warn!( + target: LOG_TARGET, + "ParachainsInherentData failed to decode", + ); + + return None; + } + }; + + // Sanity check: session changes can invalidate an inherent, and we _really_ don't want that to happen. + // See github.com/paritytech/polkadot/issues/1327 + let inherent_data = match Self::enter( + frame_system::RawOrigin::None.into(), + inherent_data.clone(), + ) { + Ok(_) => inherent_data, + Err(err) => { + log::warn!( + target: LOG_TARGET, + "dropping signed_bitfields and backed_candidates because they produced \ + an invalid paras inherent: {:?}", + err, + ); + + ParachainsInherentData { + bitfields: Vec::new(), + backed_candidates: Vec::new(), + disputes: Vec::new(), + parent_header: inherent_data.parent_header, } - ) + } + }; + + Some(Call::enter(inherent_data)) } } @@ -307,12 +323,13 @@ mod tests { } } - mod inclusion_inherent_weight { + mod paras_inherent_weight { use super::*; use crate::mock::{ new_test_ext, System, MockGenesisConfig, Test }; + use primitives::v1::Header; use frame_support::traits::UnfilteredDispatchable; @@ -326,7 +343,7 @@ mod tests { } } - /// We expect the weight of the inclusion inherent not to change when no truncation occurs: + /// We expect the weight of the paras inherent not to change when no truncation occurs: /// its weight is dynamically computed from the size of the backed candidates list, and is /// already incorporated into the current block weight when it is selected by the provisioner. #[test] @@ -336,7 +353,7 @@ mod tests { System::set_block_number(1); System::set_parent_hash(header.hash()); - // number of bitfields doesn't affect the inclusion inherent weight, so we can mock it with an empty one + // number of bitfields doesn't affect the paras inherent weight, so we can mock it with an empty one let signed_bitfields = Vec::new(); // backed candidates must not be empty, so we can demonstrate that the weight has not changed let backed_candidates = vec![BackedCandidate::default(); 10]; @@ -350,8 +367,13 @@ mod tests { let used_block_weight = max_block_weight / 2; System::set_block_consumed_resources(used_block_weight, 0); - // execute the inclusion inherent - let post_info = Call::::inclusion(signed_bitfields, backed_candidates, default_header()) + // execute the paras inherent + let post_info = Call::::enter(ParachainsInherentData { + bitfields: signed_bitfields, + backed_candidates, + disputes: Vec::new(), + parent_header: default_header(), + }) .dispatch_bypass_filter(None.into()).unwrap_err().post_info; // we don't directly check the block's weight post-call. Instead, we check that the @@ -367,7 +389,7 @@ mod tests { }); } - /// We expect the weight of the inclusion inherent to change when truncation occurs: its + /// We expect the weight of the paras inherent to change when truncation occurs: its /// weight was initially dynamically computed from the size of the backed candidates list, /// but was reduced by truncation. #[test] @@ -377,7 +399,7 @@ mod tests { System::set_block_number(1); System::set_parent_hash(header.hash()); - // number of bitfields doesn't affect the inclusion inherent weight, so we can mock it with an empty one + // number of bitfields doesn't affect the paras inherent weight, so we can mock it with an empty one let signed_bitfields = Vec::new(); // backed candidates must not be empty, so we can demonstrate that the weight has not changed let backed_candidates = vec![BackedCandidate::default(); 10]; @@ -390,8 +412,13 @@ mod tests { let used_block_weight = max_block_weight + 1; System::set_block_consumed_resources(used_block_weight, 0); - // execute the inclusion inherent - let post_info = Call::::inclusion(signed_bitfields, backed_candidates, header) + // execute the paras inherent + let post_info = Call::::enter(ParachainsInherentData { + bitfields: signed_bitfields, + backed_candidates, + disputes: Vec::new(), + parent_header: header, + }) .dispatch_bypass_filter(None.into()).unwrap(); // we don't directly check the block's weight post-call. Instead, we check that the diff --git a/polkadot/runtime/parachains/src/runtime_api_impl/v1.rs b/polkadot/runtime/parachains/src/runtime_api_impl/v1.rs index aecc059c56..4b2c0f9599 100644 --- a/polkadot/runtime/parachains/src/runtime_api_impl/v1.rs +++ b/polkadot/runtime/parachains/src/runtime_api_impl/v1.rs @@ -25,7 +25,7 @@ use primitives::v1::{ Id as ParaId, OccupiedCoreAssumption, SessionIndex, ValidationCode, CommittedCandidateReceipt, ScheduledCore, OccupiedCore, CoreOccupied, CoreIndex, GroupIndex, CandidateEvent, PersistedValidationData, SessionInfo, - InboundDownwardMessage, InboundHrmpMessage, Hash, AuthorityDiscoveryId + InboundDownwardMessage, InboundHrmpMessage, AuthorityDiscoveryId }; use crate::{initializer, inclusion, scheduler, configuration, paras, session_info, dmp, hrmp, shared}; @@ -200,10 +200,10 @@ fn with_assumption( pub fn persisted_validation_data( para_id: ParaId, assumption: OccupiedCoreAssumption, -) -> Option> { +) -> Option> { use parity_scale_codec::Decode as _; let relay_parent_number = >::block_number(); - let relay_parent_storage_root = Hash::decode(&mut &sp_io::storage::root()[..]) + let relay_parent_storage_root = T::Hash::decode(&mut &sp_io::storage::root()[..]) .expect("storage root must decode to the Hash type; qed"); with_assumption::(para_id, assumption, || { crate::util::make_persisted_validation_data::( diff --git a/polkadot/runtime/parachains/src/util.rs b/polkadot/runtime/parachains/src/util.rs index 8721d3ed9c..6cada4dd65 100644 --- a/polkadot/runtime/parachains/src/util.rs +++ b/polkadot/runtime/parachains/src/util.rs @@ -17,7 +17,7 @@ //! Utilities that don't belong to any particular module but may draw //! on all modules. -use primitives::v1::{Id as ParaId, PersistedValidationData, Hash, ValidatorIndex}; +use primitives::v1::{Id as ParaId, PersistedValidationData, ValidatorIndex}; use sp_std::vec::Vec; use crate::{configuration, paras, hrmp}; @@ -29,8 +29,8 @@ use crate::{configuration, paras, hrmp}; pub fn make_persisted_validation_data( para_id: ParaId, relay_parent_number: T::BlockNumber, - relay_parent_storage_root: Hash, -) -> Option> { + relay_parent_storage_root: T::Hash, +) -> Option> { let config = >::config(); Some(PersistedValidationData { diff --git a/polkadot/runtime/polkadot/src/lib.rs b/polkadot/runtime/polkadot/src/lib.rs index 7ad16c7084..739e560f00 100644 --- a/polkadot/runtime/polkadot/src/lib.rs +++ b/polkadot/runtime/polkadot/src/lib.rs @@ -1200,7 +1200,7 @@ sp_api::impl_runtime_apis! { } fn persisted_validation_data(_: Id, _: OccupiedCoreAssumption) - -> Option> { + -> Option> { None } diff --git a/polkadot/runtime/rococo/src/lib.rs b/polkadot/runtime/rococo/src/lib.rs index 7a487e6432..96937fdd62 100644 --- a/polkadot/runtime/rococo/src/lib.rs +++ b/polkadot/runtime/rococo/src/lib.rs @@ -68,7 +68,7 @@ use runtime_parachains::origin as parachains_origin; use runtime_parachains::configuration as parachains_configuration; use runtime_parachains::shared as parachains_shared; use runtime_parachains::inclusion as parachains_inclusion; -use runtime_parachains::inclusion_inherent as parachains_inclusion_inherent; +use runtime_parachains::paras_inherent as parachains_paras_inherent; use runtime_parachains::initializer as parachains_initializer; use runtime_parachains::session_info as parachains_session_info; use runtime_parachains::paras as parachains_paras; @@ -247,7 +247,7 @@ construct_runtime! { ParachainsConfiguration: parachains_configuration::{Pallet, Call, Storage, Config}, Shared: parachains_shared::{Pallet, Call, Storage}, Inclusion: parachains_inclusion::{Pallet, Call, Storage, Event}, - InclusionInherent: parachains_inclusion_inherent::{Pallet, Call, Storage, Inherent}, + ParasInherent: parachains_paras_inherent::{Pallet, Call, Storage, Inherent}, Scheduler: parachains_scheduler::{Pallet, Call, Storage}, Paras: parachains_paras::{Pallet, Call, Storage, Event}, Initializer: parachains_initializer::{Pallet, Call, Storage}, @@ -641,7 +641,7 @@ impl parachains_hrmp::Config for Runtime { type Currency = Balances; } -impl parachains_inclusion_inherent::Config for Runtime {} +impl parachains_paras_inherent::Config for Runtime {} impl parachains_scheduler::Config for Runtime {} @@ -897,7 +897,7 @@ sp_api::impl_runtime_apis! { } fn persisted_validation_data(para_id: Id, assumption: OccupiedCoreAssumption) - -> Option> { + -> Option> { runtime_api_impl::persisted_validation_data::(para_id, assumption) } diff --git a/polkadot/runtime/test-runtime/src/lib.rs b/polkadot/runtime/test-runtime/src/lib.rs index b8f839e72d..57f5afd779 100644 --- a/polkadot/runtime/test-runtime/src/lib.rs +++ b/polkadot/runtime/test-runtime/src/lib.rs @@ -28,7 +28,7 @@ use parity_scale_codec::Encode; use polkadot_runtime_parachains::configuration as parachains_configuration; use polkadot_runtime_parachains::shared as parachains_shared; use polkadot_runtime_parachains::inclusion as parachains_inclusion; -use polkadot_runtime_parachains::inclusion_inherent as parachains_inclusion_inherent; +use polkadot_runtime_parachains::paras_inherent as parachains_paras_inherent; use polkadot_runtime_parachains::initializer as parachains_initializer; use polkadot_runtime_parachains::session_info as parachains_session_info; use polkadot_runtime_parachains::paras as parachains_paras; @@ -458,7 +458,7 @@ impl parachains_inclusion::Config for Runtime { type RewardValidators = RewardValidatorsWithEraPoints; } -impl parachains_inclusion_inherent::Config for Runtime {} +impl parachains_paras_inherent::Config for Runtime {} impl parachains_initializer::Config for Runtime { type Randomness = pallet_babe::RandomnessFromOneEpochAgo; @@ -524,7 +524,7 @@ construct_runtime! { // Parachains runtime modules ParachainsConfiguration: parachains_configuration::{Pallet, Call, Storage, Config}, Inclusion: parachains_inclusion::{Pallet, Call, Storage, Event}, - InclusionInherent: parachains_inclusion_inherent::{Pallet, Call, Storage, Inherent}, + ParasInherent: parachains_paras_inherent::{Pallet, Call, Storage, Inherent}, Initializer: parachains_initializer::{Pallet, Call, Storage}, Paras: parachains_paras::{Pallet, Call, Storage, Origin, Event}, Scheduler: parachains_scheduler::{Pallet, Call, Storage}, @@ -649,7 +649,7 @@ sp_api::impl_runtime_apis! { } fn persisted_validation_data(para_id: ParaId, assumption: OccupiedCoreAssumption) - -> Option> + -> Option> { runtime_impl::persisted_validation_data::(para_id, assumption) } diff --git a/polkadot/runtime/westend/src/lib.rs b/polkadot/runtime/westend/src/lib.rs index a7e0dad07a..fc3afc6874 100644 --- a/polkadot/runtime/westend/src/lib.rs +++ b/polkadot/runtime/westend/src/lib.rs @@ -937,7 +937,7 @@ sp_api::impl_runtime_apis! { } fn persisted_validation_data(_: Id, _: OccupiedCoreAssumption) - -> Option> { + -> Option> { None }