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

Commit

Permalink
Fix extensions handling for Parachain validation (#1015)
Browse files Browse the repository at this point in the history
The `TaskExecutor` extension is now required by Substrate to batch verify signatures.

Co-authored-by: NikVolf <nikvolf@gmail.com>
  • Loading branch information
bkchr and NikVolf authored Apr 21, 2020
1 parent 87f080e commit a8e9240
Showing 1 changed file with 16 additions and 12 deletions.
28 changes: 16 additions & 12 deletions parachain/src/wasm_executor/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ use codec::{Decode, Encode};
use sp_core::storage::ChildInfo;
use sp_core::traits::CallInWasm;
use sp_wasm_interface::HostFunctions as _;
use sp_externalities::Extensions;

#[cfg(not(target_os = "unknown"))]
pub use validation_host::{run_worker, ValidationPool, EXECUTION_TIMEOUT_SEC};
Expand Down Expand Up @@ -171,7 +172,11 @@ pub fn validate_candidate_internal<E: Externalities + 'static>(
encoded_call_data: &[u8],
externalities: E,
) -> Result<ValidationResult, Error> {
let mut ext = ValidationExternalities(ParachainExt::new(externalities));
let mut extensions = Extensions::new();
extensions.register(ParachainExt::new(externalities));
extensions.register(sp_core::traits::TaskExecutorExt(sp_core::tasks::executor()));

let mut ext = ValidationExternalities(extensions);

let executor = sc_executor::WasmExecutor::new(
sc_executor::WasmExecutionMethod::Interpreted,
Expand All @@ -194,7 +199,7 @@ pub fn validate_candidate_internal<E: Externalities + 'static>(

/// The validation externalities that will panic on any storage related access. They just provide
/// access to the parachain extension.
struct ValidationExternalities(ParachainExt);
struct ValidationExternalities(Extensions);

impl sp_externalities::Externalities for ValidationExternalities {
fn storage(&self, _: &[u8]) -> Option<Vec<u8>> {
Expand Down Expand Up @@ -268,25 +273,24 @@ impl sp_externalities::Externalities for ValidationExternalities {

impl sp_externalities::ExtensionStore for ValidationExternalities {
fn extension_by_type_id(&mut self, type_id: TypeId) -> Option<&mut dyn Any> {
if type_id == TypeId::of::<ParachainExt>() {
Some(&mut self.0)
} else {
None
}
self.0.get_mut(type_id)
}

fn register_extension_with_type_id(
&mut self,
_type_id: TypeId,
_extension: Box<dyn sp_externalities::Extension>,
type_id: TypeId,
extension: Box<dyn sp_externalities::Extension>,
) -> Result<(), sp_externalities::Error> {
panic!("register_extension_with_type_id: unsupported feature for parachain validation")
self.0.register_with_type_id(type_id, extension)
}

fn deregister_extension_by_type_id(
&mut self,
_type_id: TypeId,
type_id: TypeId,
) -> Result<(), sp_externalities::Error> {
panic!("deregister_extension_by_type_id: unsupported feature for parachain validation")
match self.0.deregister(type_id) {
Some(_) => Ok(()),
None => Err(sp_externalities::Error::ExtensionIsNotRegistered(type_id))
}
}
}

0 comments on commit a8e9240

Please sign in to comment.