diff --git a/node/core/pvf/src/executor_intf.rs b/node/core/pvf/src/executor_intf.rs index c3b5e3115466..70ea86ba0c9f 100644 --- a/node/core/pvf/src/executor_intf.rs +++ b/node/core/pvf/src/executor_intf.rs @@ -64,6 +64,7 @@ pub fn execute( let mut extensions = sp_externalities::Extensions::new(); extensions.register(sp_core::traits::TaskExecutorExt::new(spawner)); + extensions.register(sp_core::traits::ReadRuntimeVersionExt::new(ReadRuntimeVersion)); let mut ext = ValidationExternalities(extensions); @@ -244,3 +245,26 @@ impl sp_core::traits::SpawnNamed for TaskExecutor { self.0.spawn_ok(future); } } + +struct ReadRuntimeVersion; + +impl sp_core::traits::ReadRuntimeVersion for ReadRuntimeVersion { + fn read_runtime_version( + &self, + wasm_code: &[u8], + _ext: &mut dyn sp_externalities::Externalities, + ) -> Result, String> { + let blob = RuntimeBlob::uncompress_if_needed(wasm_code) + .map_err(|e| format!("Failed to read the PVF runtime blob: {:?}", e))?; + + match sc_executor::read_embedded_version(&blob) + .map_err(|e| format!("Failed to read the static section from the PVF blob: {:?}", e))? + { + Some(version) => { + use parity_scale_codec::Encode; + Ok(version.encode()) + }, + None => Err(format!("runtime version section is not found")), + } + } +}