mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-05-30 18:41:03 +00:00
Make polkadot-parachain call validate_block instead of validate (#297)
* Make `polkadot-parachain` call `validate_block` instead of `validate` Also switch to rust 2018 in the crate * Use `rstd` * Make `load_params` a pointer
This commit is contained in:
@@ -43,29 +43,7 @@
|
||||
#![cfg_attr(not(feature = "std"), no_std)]
|
||||
|
||||
/// Re-export of parity-codec.
|
||||
pub extern crate parity_codec as codec;
|
||||
|
||||
#[macro_use]
|
||||
extern crate parity_codec_derive;
|
||||
|
||||
#[cfg(not(feature = "std"))]
|
||||
extern crate alloc;
|
||||
|
||||
#[cfg(feature = "std")]
|
||||
extern crate core;
|
||||
|
||||
#[cfg(feature = "std")]
|
||||
extern crate wasmi;
|
||||
|
||||
#[cfg(feature = "std")]
|
||||
extern crate serde;
|
||||
|
||||
#[cfg(feature = "std")]
|
||||
#[macro_use]
|
||||
extern crate serde_derive;
|
||||
|
||||
#[cfg(not(feature = "std"))]
|
||||
use alloc::vec::Vec;
|
||||
pub use codec;
|
||||
|
||||
#[cfg(feature = "std")]
|
||||
pub mod wasm_executor;
|
||||
@@ -75,6 +53,8 @@ pub mod wasm_api;
|
||||
|
||||
use codec::{Encode, Decode};
|
||||
|
||||
use rstd::vec::Vec;
|
||||
|
||||
struct TrailingZeroInput<'a>(&'a [u8]);
|
||||
impl<'a> codec::Input for TrailingZeroInput<'a> {
|
||||
fn read(&mut self, into: &mut [u8]) -> usize {
|
||||
@@ -112,7 +92,7 @@ pub struct ValidationResult {
|
||||
|
||||
/// Unique identifier of a parachain.
|
||||
#[derive(PartialEq, Eq, PartialOrd, Ord, Hash, Default, Clone, Copy, Encode, Decode)]
|
||||
#[cfg_attr(feature = "std", derive(Serialize, Deserialize, Debug))]
|
||||
#[cfg_attr(feature = "std", derive(serde::Serialize, serde::Deserialize, Debug))]
|
||||
pub struct Id(u32);
|
||||
|
||||
impl codec::CompactAs for Id {
|
||||
@@ -207,7 +187,7 @@ pub enum ParachainDispatchOrigin {
|
||||
Parachain,
|
||||
}
|
||||
|
||||
impl core::convert::TryFrom<u8> for ParachainDispatchOrigin {
|
||||
impl rstd::convert::TryFrom<u8> for ParachainDispatchOrigin {
|
||||
type Error = ();
|
||||
fn try_from(x: u8) -> core::result::Result<ParachainDispatchOrigin, ()> {
|
||||
const SIGNED: u8 = ParachainDispatchOrigin::Signed as u8;
|
||||
|
||||
@@ -17,9 +17,7 @@
|
||||
//! Utilities for writing parachain WASM.
|
||||
|
||||
use codec::{Encode, Decode};
|
||||
use super::{
|
||||
ValidationParams, ValidationResult, MessageRef, UpwardMessageRef, ParachainDispatchOrigin
|
||||
};
|
||||
use super::{ValidationParams, ValidationResult, MessageRef, UpwardMessageRef};
|
||||
|
||||
mod ll {
|
||||
extern "C" {
|
||||
@@ -32,8 +30,8 @@ mod ll {
|
||||
///
|
||||
/// Offset and length must have been provided by the validation
|
||||
/// function's entry point.
|
||||
pub unsafe fn load_params(offset: usize, len: usize) -> ValidationParams {
|
||||
let mut slice = ::core::slice::from_raw_parts(offset as *const u8, len);
|
||||
pub unsafe fn load_params(params: *const u8, len: usize) -> ValidationParams {
|
||||
let mut slice = rstd::slice::from_raw_parts(params, len);
|
||||
|
||||
ValidationParams::decode(&mut slice).expect("Invalid input data")
|
||||
}
|
||||
@@ -53,7 +51,7 @@ pub fn write_result(result: ValidationResult) -> usize {
|
||||
let end_ptr = &encoded[len] as *const u8 as usize;
|
||||
|
||||
// leak so it doesn't get zeroed.
|
||||
::core::mem::forget(encoded);
|
||||
rstd::mem::forget(encoded);
|
||||
end_ptr
|
||||
}
|
||||
|
||||
@@ -67,8 +65,8 @@ pub fn post_message(message: MessageRef) {
|
||||
|
||||
/// Post a message to this parachain's relay chain.
|
||||
pub fn post_upward_message(message: UpwardMessageRef) {
|
||||
let data_ptr = message.as_ptr();
|
||||
let data_len = message.len();
|
||||
let data_ptr = message.data.as_ptr();
|
||||
let data_len = message.data.len();
|
||||
|
||||
unsafe { ll::ext_post_upward_message(message.origin as u8 as u32, data_ptr, data_len as u32) }
|
||||
unsafe { ll::ext_post_upward_message(u32::from(message.origin as u8), data_ptr, data_len as u32) }
|
||||
}
|
||||
|
||||
@@ -21,7 +21,7 @@
|
||||
//! a WASM VM for re-execution of a parachain candidate.
|
||||
|
||||
use std::{cell::RefCell, fmt, convert::TryInto};
|
||||
use codec::{Decode, Encode};
|
||||
use crate::codec::{Decode, Encode};
|
||||
use wasmi::{
|
||||
self, Module, ModuleInstance, Trap, MemoryInstance, MemoryDescriptor, MemoryRef,
|
||||
ModuleImportResolver, RuntimeValue, Externals, Error as WasmError, ValueType,
|
||||
@@ -306,16 +306,15 @@ pub fn validate_candidate<E: Externalities>(
|
||||
};
|
||||
|
||||
let output = module.invoke_export(
|
||||
"validate",
|
||||
"validate_block",
|
||||
&[RuntimeValue::I32(offset as i32), RuntimeValue::I32(len as i32)],
|
||||
&mut externals,
|
||||
)
|
||||
.map_err(|e| -> Error {
|
||||
e.as_host_error()
|
||||
.and_then(|he| he.downcast_ref::<ExternalitiesError>())
|
||||
.map(|ee| Error::Externalities(ee.clone()))
|
||||
.unwrap_or_else(move || e.into())
|
||||
})?;
|
||||
).map_err(|e| -> Error {
|
||||
e.as_host_error()
|
||||
.and_then(|he| he.downcast_ref::<ExternalitiesError>())
|
||||
.map(|ee| Error::Externalities(ee.clone()))
|
||||
.unwrap_or_else(move || e.into())
|
||||
})?;
|
||||
|
||||
match output {
|
||||
Some(RuntimeValue::I32(len_offset)) => {
|
||||
@@ -344,6 +343,6 @@ pub fn validate_candidate<E: Externalities>(
|
||||
.map_err(Into::into)
|
||||
})
|
||||
}
|
||||
_ => return Err(Error::BadReturn),
|
||||
_ => Err(Error::BadReturn),
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user