Replace ValidationData with PersistedValidationData (#291)

* Replace ValidationData with PersistedValidationData

* Update polkadot
This commit is contained in:
Sergei Shulepov
2021-01-19 15:20:12 +01:00
committed by GitHub
parent ae9b659969
commit 3fd6ec6bf1
9 changed files with 541 additions and 507 deletions
+491 -446
View File
File diff suppressed because it is too large Load Diff
+7 -7
View File
@@ -20,7 +20,7 @@ use cumulus_network::WaitToAnnounce;
use cumulus_primitives::{ use cumulus_primitives::{
inherents::{self, VALIDATION_DATA_IDENTIFIER}, inherents::{self, VALIDATION_DATA_IDENTIFIER},
well_known_keys, InboundDownwardMessage, InboundHrmpMessage, OutboundHrmpMessage, well_known_keys, InboundDownwardMessage, InboundHrmpMessage, OutboundHrmpMessage,
ValidationData, relay_chain, PersistedValidationData, relay_chain,
}; };
use cumulus_runtime::ParachainBlockData; use cumulus_runtime::ParachainBlockData;
@@ -271,7 +271,7 @@ where
/// Get the inherent data with validation function parameters injected /// Get the inherent data with validation function parameters injected
fn inherent_data( fn inherent_data(
&mut self, &mut self,
validation_data: &ValidationData, validation_data: &PersistedValidationData,
relay_parent: PHash, relay_parent: PHash,
) -> Option<InherentData> { ) -> Option<InherentData> {
let mut inherent_data = self let mut inherent_data = self
@@ -472,12 +472,12 @@ where
async fn produce_candidate( async fn produce_candidate(
mut self, mut self,
relay_parent: PHash, relay_parent: PHash,
validation_data: ValidationData, validation_data: PersistedValidationData,
) -> Option<Collation> { ) -> Option<Collation> {
trace!(target: "cumulus-collator", "Producing candidate"); trace!(target: "cumulus-collator", "Producing candidate");
let last_head = let last_head =
match Block::Header::decode(&mut &validation_data.persisted.parent_head.0[..]) { match Block::Header::decode(&mut &validation_data.parent_head.0[..]) {
Ok(x) => x, Ok(x) => x,
Err(e) => { Err(e) => {
error!(target: "cumulus-collator", "Could not decode the head data: {:?}", e); error!(target: "cumulus-collator", "Could not decode the head data: {:?}", e);
@@ -582,7 +582,7 @@ where
); );
let collation = let collation =
self.build_collation(b, block_hash, validation_data.persisted.block_number)?; self.build_collation(b, block_hash, validation_data.block_number)?;
let pov_hash = collation.proof_of_validity.hash(); let pov_hash = collation.proof_of_validity.hash();
self.wait_to_announce self.wait_to_announce
@@ -842,8 +842,8 @@ mod tests {
CollationGenerationMessage::Initialize(config) => config, CollationGenerationMessage::Initialize(config) => config,
}; };
let mut validation_data = ValidationData::default(); let mut validation_data = PersistedValidationData::default();
validation_data.persisted.parent_head = header.encode().into(); validation_data.parent_head = header.encode().into();
let collation = block_on((config.collator)(relay_parent, &validation_data)) let collation = block_on((config.collator)(relay_parent, &validation_data))
.expect("Collation is build"); .expect("Collation is build");
+1 -5
View File
@@ -23,7 +23,7 @@ use polkadot_primitives::v1::{
CommittedCandidateReceipt, CoreState, GroupRotationInfo, Hash as PHash, HeadData, Id as ParaId, CommittedCandidateReceipt, CoreState, GroupRotationInfo, Hash as PHash, HeadData, Id as ParaId,
InboundDownwardMessage, InboundHrmpMessage, OccupiedCoreAssumption, ParachainHost, InboundDownwardMessage, InboundHrmpMessage, OccupiedCoreAssumption, ParachainHost,
PersistedValidationData, SessionIndex, SessionInfo, SigningContext, ValidationCode, PersistedValidationData, SessionIndex, SessionInfo, SigningContext, ValidationCode,
ValidationData, ValidatorId, ValidatorIndex, ValidatorId, ValidatorIndex,
}; };
use polkadot_test_client::{ use polkadot_test_client::{
Client as PClient, ClientBlockImportExt, DefaultTestClientBuilderExt, FullBackend as PBackend, Client as PClient, ClientBlockImportExt, DefaultTestClientBuilderExt, FullBackend as PBackend,
@@ -400,10 +400,6 @@ sp_api::mock_impl_runtime_apis! {
Vec::new() Vec::new()
} }
fn full_validation_data(&self, _: ParaId, _: OccupiedCoreAssumption) -> Option<ValidationData<BlockNumber>> {
None
}
fn persisted_validation_data(&self, _: ParaId, _: OccupiedCoreAssumption) -> Option<PersistedValidationData<BlockNumber>> { fn persisted_validation_data(&self, _: ParaId, _: OccupiedCoreAssumption) -> Option<PersistedValidationData<BlockNumber>> {
Some(PersistedValidationData { Some(PersistedValidationData {
parent_head: HeadData(default_header().encode()), parent_head: HeadData(default_header().encode()),
+12 -17
View File
@@ -32,7 +32,7 @@
use cumulus_primitives::{ use cumulus_primitives::{
inherents::{ValidationDataType, VALIDATION_DATA_IDENTIFIER as INHERENT_IDENTIFIER}, inherents::{ValidationDataType, VALIDATION_DATA_IDENTIFIER as INHERENT_IDENTIFIER},
well_known_keys::{NEW_VALIDATION_CODE, VALIDATION_DATA}, AbridgedHostConfiguration, well_known_keys::{NEW_VALIDATION_CODE, VALIDATION_DATA}, AbridgedHostConfiguration,
OnValidationData, ValidationData, ParaId, relay_chain, OnValidationData, PersistedValidationData, ParaId, relay_chain,
}; };
use frame_support::{ use frame_support::{
decl_error, decl_event, decl_module, decl_storage, ensure, storage, decl_error, decl_event, decl_module, decl_storage, ensure, storage,
@@ -143,18 +143,18 @@ decl_module! {
// which means we can put the initialization logic here to remove the // which means we can put the initialization logic here to remove the
// sequencing problem. // sequencing problem.
if let Some((apply_block, validation_function)) = PendingValidationFunction::get() { if let Some((apply_block, validation_function)) = PendingValidationFunction::get() {
if vfp.persisted.block_number >= apply_block { if vfp.block_number >= apply_block {
PendingValidationFunction::kill(); PendingValidationFunction::kill();
LastUpgrade::put(&apply_block); LastUpgrade::put(&apply_block);
Self::put_parachain_code(&validation_function); Self::put_parachain_code(&validation_function);
Self::deposit_event(Event::ValidationFunctionApplied(vfp.persisted.block_number)); Self::deposit_event(Event::ValidationFunctionApplied(vfp.block_number));
} }
} }
let (host_config, relevant_messaging_state) = let (host_config, relevant_messaging_state) =
relay_state_snapshot::extract_from_proof( relay_state_snapshot::extract_from_proof(
T::SelfParaId::get(), T::SelfParaId::get(),
vfp.persisted.relay_storage_root, vfp.relay_storage_root,
relay_chain_state relay_chain_state
) )
.map_err(|err| { .map_err(|err| {
@@ -196,7 +196,7 @@ impl<T: Config> Module<T> {
/// Get validation data. /// Get validation data.
/// ///
/// Returns `Some(_)` after the inherent set the data for the current block. /// Returns `Some(_)` after the inherent set the data for the current block.
pub fn validation_data() -> Option<ValidationData> { pub fn validation_data() -> Option<PersistedValidationData> {
storage::unhashed::get(VALIDATION_DATA) storage::unhashed::get(VALIDATION_DATA)
} }
@@ -224,7 +224,7 @@ impl<T: Config> Module<T> {
/// Returns if a PVF/runtime upgrade could be signalled at the current block, and if so /// Returns if a PVF/runtime upgrade could be signalled at the current block, and if so
/// when the new code will take the effect. /// when the new code will take the effect.
fn code_upgrade_allowed( fn code_upgrade_allowed(
vfp: &ValidationData, vfp: &PersistedValidationData,
cfg: &AbridgedHostConfiguration, cfg: &AbridgedHostConfiguration,
) -> Option<relay_chain::BlockNumber> { ) -> Option<relay_chain::BlockNumber> {
if PendingValidationFunction::get().is_some() { if PendingValidationFunction::get().is_some() {
@@ -233,7 +233,6 @@ impl<T: Config> Module<T> {
} }
let relay_blocks_since_last_upgrade = vfp let relay_blocks_since_last_upgrade = vfp
.persisted
.block_number .block_number
.saturating_sub(LastUpgrade::get()); .saturating_sub(LastUpgrade::get());
@@ -242,7 +241,7 @@ impl<T: Config> Module<T> {
return None; return None;
} }
Some(vfp.persisted.block_number + cfg.validation_upgrade_delay) Some(vfp.block_number + cfg.validation_upgrade_delay)
} }
/// The implementation of the runtime upgrade scheduling. /// The implementation of the runtime upgrade scheduling.
@@ -325,7 +324,7 @@ mod tests {
use super::*; use super::*;
use codec::Encode; use codec::Encode;
use cumulus_primitives::{PersistedValidationData, TransientValidationData}; use cumulus_primitives::PersistedValidationData;
use cumulus_test_relay_sproof_builder::RelayStateSproofBuilder; use cumulus_test_relay_sproof_builder::RelayStateSproofBuilder;
use frame_support::{ use frame_support::{
assert_ok, assert_ok,
@@ -543,13 +542,10 @@ mod tests {
} }
let (relay_storage_root, relay_chain_state) = let (relay_storage_root, relay_chain_state) =
sproof_builder.into_state_root_and_proof(); sproof_builder.into_state_root_and_proof();
let vfp = ValidationData { let vfp = PersistedValidationData {
persisted: PersistedValidationData { block_number: *n as RelayChainBlockNumber,
block_number: *n as RelayChainBlockNumber, relay_storage_root,
relay_storage_root, ..Default::default()
..Default::default()
},
transient: TransientValidationData::default(),
}; };
storage::unhashed::put(VALIDATION_DATA, &vfp); storage::unhashed::put(VALIDATION_DATA, &vfp);
@@ -582,7 +578,6 @@ mod tests {
if self.pending_upgrade.is_some() { if self.pending_upgrade.is_some() {
panic!("attempted to set validation code while upgrade was pending"); panic!("attempted to set validation code while upgrade was pending");
} }
self.pending_upgrade = vfp.transient.code_upgrade_allowed;
} }
// clean up // clean up
+3 -4
View File
@@ -21,8 +21,7 @@
pub use polkadot_core_primitives::InboundDownwardMessage; pub use polkadot_core_primitives::InboundDownwardMessage;
pub use polkadot_parachain::primitives::{Id as ParaId, UpwardMessage, ValidationParams}; pub use polkadot_parachain::primitives::{Id as ParaId, UpwardMessage, ValidationParams};
pub use polkadot_primitives::v1::{ pub use polkadot_primitives::v1::{
PersistedValidationData, TransientValidationData, ValidationData, AbridgedHostConfiguration, PersistedValidationData, AbridgedHostConfiguration, AbridgedHrmpChannel,
AbridgedHrmpChannel,
}; };
#[cfg(feature = "std")] #[cfg(feature = "std")]
@@ -66,7 +65,7 @@ pub mod inherents {
/// The type of the inherent. /// The type of the inherent.
#[derive(codec::Encode, codec::Decode, sp_core::RuntimeDebug, Clone, PartialEq)] #[derive(codec::Encode, codec::Decode, sp_core::RuntimeDebug, Clone, PartialEq)]
pub struct ValidationDataType { pub struct ValidationDataType {
pub validation_data: crate::ValidationData, pub validation_data: crate::PersistedValidationData,
/// A storage proof of a predefined set of keys from the relay-chain. /// A storage proof of a predefined set of keys from the relay-chain.
/// ///
/// Specifically this witness contains the data for: /// Specifically this witness contains the data for:
@@ -139,5 +138,5 @@ pub trait HrmpMessageSender {
/// A trait which is called when the validation data is set. /// A trait which is called when the validation data is set.
#[impl_trait_for_tuples::impl_for_tuples(30)] #[impl_trait_for_tuples::impl_for_tuples(30)]
pub trait OnValidationData { pub trait OnValidationData {
fn on_validation_data(data: ValidationData); fn on_validation_data(data: PersistedValidationData);
} }
@@ -32,7 +32,7 @@ use cumulus_primitives::{
HRMP_OUTBOUND_MESSAGES, HRMP_WATERMARK, NEW_VALIDATION_CODE, PROCESSED_DOWNWARD_MESSAGES, HRMP_OUTBOUND_MESSAGES, HRMP_WATERMARK, NEW_VALIDATION_CODE, PROCESSED_DOWNWARD_MESSAGES,
UPWARD_MESSAGES, VALIDATION_DATA, UPWARD_MESSAGES, VALIDATION_DATA,
}, },
OutboundHrmpMessage, UpwardMessage, ValidationData, OutboundHrmpMessage, UpwardMessage, PersistedValidationData,
}; };
use sp_core::storage::{ChildInfo, TrackedStorageKey}; use sp_core::storage::{ChildInfo, TrackedStorageKey};
use sp_externalities::{ use sp_externalities::{
@@ -164,11 +164,11 @@ pub fn validate_block<B: BlockT, E: ExecuteBlock<B>>(params: ValidationParams) -
}) })
.unwrap_or_default(); .unwrap_or_default();
let validation_data: ValidationData = overlay let validation_data: PersistedValidationData = overlay
.storage(VALIDATION_DATA) .storage(VALIDATION_DATA)
.flatten() .flatten()
.and_then(|v| Decode::decode(&mut &v[..]).ok()) .and_then(|v| Decode::decode(&mut &v[..]).ok())
.expect("`ValidationData` is required to be placed into the storage!"); .expect("`PersistedValidationData` is required to be placed into the storage!");
let horizontal_messages = match overlay.storage(HRMP_OUTBOUND_MESSAGES).flatten() { let horizontal_messages = match overlay.storage(HRMP_OUTBOUND_MESSAGES).flatten() {
Some(encoded) => Vec::<OutboundHrmpMessage>::decode(&mut &encoded[..]) Some(encoded) => Vec::<OutboundHrmpMessage>::decode(&mut &encoded[..])
@@ -180,7 +180,7 @@ pub fn validate_block<B: BlockT, E: ExecuteBlock<B>>(params: ValidationParams) -
.storage(HRMP_WATERMARK) .storage(HRMP_WATERMARK)
.flatten() .flatten()
.map(|v| Decode::decode(&mut &v[..]).expect("HRMP watermark is not encoded correctly")) .map(|v| Decode::decode(&mut &v[..]).expect("HRMP watermark is not encoded correctly"))
.unwrap_or(validation_data.persisted.block_number); .unwrap_or(validation_data.block_number);
ValidationResult { ValidationResult {
head_data, head_data,
@@ -200,32 +200,33 @@ struct WitnessExt<'a, B: BlockT> {
} }
impl<'a, B: BlockT> WitnessExt<'a, B> { impl<'a, B: BlockT> WitnessExt<'a, B> {
/// Checks that the encoded `ValidationData` in `data` is correct. /// Checks that the encoded `PersistedValidationData` in `data` is correct.
/// ///
/// Should be removed with: https://github.com/paritytech/cumulus/issues/217 /// Should be removed with: https://github.com/paritytech/cumulus/issues/217
/// When removed `WitnessExt` could also be removed. /// When removed `WitnessExt` could also be removed.
fn check_validation_data(&self, mut data: &[u8]) { fn check_validation_data(&self, mut data: &[u8]) {
let validation_data = ValidationData::decode(&mut data).expect("Invalid `ValidationData`"); let validation_data = PersistedValidationData::decode(&mut data)
.expect("Invalid `PersistedValidationData`");
assert_eq!( assert_eq!(
self.params.parent_head, self.params.parent_head,
validation_data.persisted.parent_head validation_data.parent_head
); );
assert_eq!( assert_eq!(
self.params.relay_chain_height, self.params.relay_chain_height,
validation_data.persisted.block_number validation_data.block_number
); );
assert_eq!( assert_eq!(
self.params.hrmp_mqc_heads, self.params.hrmp_mqc_heads,
validation_data.persisted.hrmp_mqc_heads validation_data.hrmp_mqc_heads
); );
assert_eq!( assert_eq!(
self.params.dmq_mqc_head, self.params.dmq_mqc_head,
validation_data.persisted.dmq_mqc_head, validation_data.dmq_mqc_head,
); );
assert_eq!( assert_eq!(
self.params.relay_storage_root, self.params.relay_storage_root,
validation_data.persisted.relay_storage_root, validation_data.relay_storage_root,
); );
} }
} }
+4 -7
View File
@@ -16,7 +16,7 @@
use crate::ParachainBlockData; use crate::ParachainBlockData;
use cumulus_primitives::{PersistedValidationData, ValidationData}; use cumulus_primitives::PersistedValidationData;
use cumulus_test_client::{ use cumulus_test_client::{
runtime::{Block, Hash, Header, UncheckedExtrinsic, WASM_BINARY}, runtime::{Block, Hash, Header, UncheckedExtrinsic, WASM_BINARY},
transfer, Client, DefaultTestClientBuilderExt, InitBlockBuilder, LongestChain, transfer, Client, DefaultTestClientBuilderExt, InitBlockBuilder, LongestChain,
@@ -100,12 +100,9 @@ fn build_block_with_witness(
let block_id = BlockId::Hash(client.info().best_hash); let block_id = BlockId::Hash(client.info().best_hash);
let mut builder = client.init_block_builder_at( let mut builder = client.init_block_builder_at(
&block_id, &block_id,
Some(ValidationData { Some(PersistedValidationData {
persisted: PersistedValidationData { block_number: 1,
block_number: 1, parent_head: parent_head.encode().into(),
parent_head: parent_head.encode().into(),
..Default::default()
},
..Default::default() ..Default::default()
}), }),
sproof_builder, sproof_builder,
+7 -8
View File
@@ -16,8 +16,7 @@
use crate::{Backend, Client}; use crate::{Backend, Client};
use cumulus_primitives::{ use cumulus_primitives::{
inherents::{ValidationDataType, VALIDATION_DATA_IDENTIFIER}, inherents::{ValidationDataType, VALIDATION_DATA_IDENTIFIER}, PersistedValidationData,
ValidationData,
}; };
use cumulus_test_runtime::{Block, GetLastTimestamp}; use cumulus_test_runtime::{Block, GetLastTimestamp};
use cumulus_test_relay_sproof_builder::RelayStateSproofBuilder; use cumulus_test_relay_sproof_builder::RelayStateSproofBuilder;
@@ -37,7 +36,7 @@ pub trait InitBlockBuilder {
/// just use a default one. /// just use a default one.
fn init_block_builder( fn init_block_builder(
&self, &self,
validation_data: Option<ValidationData<PBlockNumber>>, validation_data: Option<PersistedValidationData<PBlockNumber>>,
relay_sproof_builder: RelayStateSproofBuilder, relay_sproof_builder: RelayStateSproofBuilder,
) -> sc_block_builder::BlockBuilder<Block, Client, Backend>; ) -> sc_block_builder::BlockBuilder<Block, Client, Backend>;
@@ -48,7 +47,7 @@ pub trait InitBlockBuilder {
fn init_block_builder_at( fn init_block_builder_at(
&self, &self,
at: &BlockId<Block>, at: &BlockId<Block>,
validation_data: Option<ValidationData<PBlockNumber>>, validation_data: Option<PersistedValidationData<PBlockNumber>>,
relay_sproof_builder: RelayStateSproofBuilder, relay_sproof_builder: RelayStateSproofBuilder,
) -> sc_block_builder::BlockBuilder<Block, Client, Backend>; ) -> sc_block_builder::BlockBuilder<Block, Client, Backend>;
} }
@@ -56,7 +55,7 @@ pub trait InitBlockBuilder {
impl InitBlockBuilder for Client { impl InitBlockBuilder for Client {
fn init_block_builder( fn init_block_builder(
&self, &self,
validation_data: Option<ValidationData<PBlockNumber>>, validation_data: Option<PersistedValidationData<PBlockNumber>>,
relay_sproof_builder: RelayStateSproofBuilder, relay_sproof_builder: RelayStateSproofBuilder,
) -> BlockBuilder<Block, Client, Backend> { ) -> BlockBuilder<Block, Client, Backend> {
let chain_info = self.chain_info(); let chain_info = self.chain_info();
@@ -70,7 +69,7 @@ impl InitBlockBuilder for Client {
fn init_block_builder_at( fn init_block_builder_at(
&self, &self,
at: &BlockId<Block>, at: &BlockId<Block>,
validation_data: Option<ValidationData<PBlockNumber>>, validation_data: Option<PersistedValidationData<PBlockNumber>>,
relay_sproof_builder: RelayStateSproofBuilder, relay_sproof_builder: RelayStateSproofBuilder,
) -> BlockBuilder<Block, Client, Backend> { ) -> BlockBuilder<Block, Client, Backend> {
let mut block_builder = self let mut block_builder = self
@@ -94,11 +93,11 @@ impl InitBlockBuilder for Client {
let mut validation_data = validation_data.unwrap_or_default(); let mut validation_data = validation_data.unwrap_or_default();
assert_eq!( assert_eq!(
validation_data.persisted.relay_storage_root, validation_data.relay_storage_root,
Default::default(), Default::default(),
"Overriding the relay storage root is not implemented", "Overriding the relay storage root is not implemented",
); );
validation_data.persisted.relay_storage_root = relay_storage_root; validation_data.relay_storage_root = relay_storage_root;
inherent_data inherent_data
.put_data( .put_data(
+4 -2
View File
@@ -40,7 +40,7 @@ use sc_network::{config::TransportConfig, multiaddr, NetworkService};
use sc_service::{ use sc_service::{
config::{ config::{
DatabaseConfig, KeystoreConfig, MultiaddrWithPeerId, NetworkConfiguration, DatabaseConfig, KeystoreConfig, MultiaddrWithPeerId, NetworkConfiguration,
OffchainWorkerConfig, PruningMode, WasmExecutionMethod, OffchainWorkerConfig, KeepBlocks, TransactionStorageMode, PruningMode, WasmExecutionMethod,
}, },
BasePath, ChainSpec, Configuration, Error as ServiceError, PartialComponents, Role, BasePath, ChainSpec, Configuration, Error as ServiceError, PartialComponents, Role,
RpcHandlers, TFullBackend, TFullClient, TaskExecutor, TaskManager, RpcHandlers, TFullBackend, TFullClient, TaskExecutor, TaskManager,
@@ -395,7 +395,9 @@ pub fn node_config(
}, },
state_cache_size: 67108864, state_cache_size: 67108864,
state_cache_child_ratio: None, state_cache_child_ratio: None,
pruning: PruningMode::ArchiveAll, state_pruning: PruningMode::ArchiveAll,
keep_blocks: KeepBlocks::All,
transaction_storage: TransactionStorageMode::BlockBody,
chain_spec: spec, chain_spec: spec,
wasm_method: WasmExecutionMethod::Interpreted, wasm_method: WasmExecutionMethod::Interpreted,
// NOTE: we enforce the use of the native runtime to make the errors more debuggable // NOTE: we enforce the use of the native runtime to make the errors more debuggable