Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.
Merged
Changes from 1 commit
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
Next Next commit
Start
  • Loading branch information
bkchr committed Jun 7, 2021
commit 2a7c7536c3c359c0bc84a275c0c5306553c5219a
25 changes: 19 additions & 6 deletions pallets/parachain-system/src/validate_block/implementation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@

//! The actual implementation of the validate block functionality.

use frame_support::traits::ExecuteBlock;
use sp_runtime::traits::{Block as BlockT, HashFor, Header as HeaderT, NumberFor};
use frame_support::traits::{misc::ExtrinsicCall, ExecuteBlock};
use sp_runtime::traits::{Block as BlockT, HashFor, Header as HeaderT, NumberFor, Extrinsic};

use sp_io::KillChildStorageResult;
use sp_std::prelude::*;
Expand Down Expand Up @@ -47,7 +47,11 @@ fn with_externalities<F: FnOnce(&mut dyn Externalities) -> R, R>(f: F) -> R {
#[doc(hidden)]
pub fn validate_block<B: BlockT, E: ExecuteBlock<B>, PSC: crate::Config>(
params: ValidationParams,
) -> ValidationResult {
) -> ValidationResult
where
B::Exrinsic: ExtrinsicCall,
<B::Extrinisc as Extrinsic>::Call: IsSubType<crate::Call>,
{
let block_data =
cumulus_primitives_core::ParachainBlockData::<B>::decode(&mut &params.block_data.0[..])
.expect("Invalid parachain block data");
Expand All @@ -71,9 +75,6 @@ pub fn validate_block<B: BlockT, E: ExecuteBlock<B>, PSC: crate::Config>(
panic!("Witness data does not contain given storage root.");
}
let backend = sp_state_machine::TrieBackend::new(db, root);
let mut overlay = sp_state_machine::OverlayedChanges::default();
let mut cache = Default::default();
let mut ext = Ext::<B>::new(&mut overlay, &mut cache, &backend);

let _guard = (
// Replace storage calls with our own implementations
Expand Down Expand Up @@ -115,6 +116,18 @@ pub fn validate_block<B: BlockT, E: ExecuteBlock<B>, PSC: crate::Config>(
sp_io::offchain_index::host_clear.replace_implementation(host_offchain_index_clear),
);

let validation_data = block
.extrinsics()
.filter_map(|e| e.is_sub_type())
.find_map(|c| match c.call() {
crate::Call::set_validation_data(validation_data) => Some(validation_data.clone()),
_ => None,
}).expect("Could not find `set_validation_data` inherent");

let mut overlay = sp_state_machine::OverlayedChanges::default();
let mut cache = Default::default();
let mut ext = Ext::<B>::new(&mut overlay, &mut cache, &backend);

set_and_run_with_externalities(&mut ext, || {
super::set_and_run_with_validation_params(params, || {
E::execute_block(block);
Expand Down