mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-05-30 14:01:02 +00:00
Parachain execution yields messages to send (#96)
* read head-data directly out of WASM memory * implement ext_post_message for parachain WASM * further refactoring of the parachain module * add externalities error type * accumulate posted messages when validating parachain candidate * define Extrinsic type in primitives * availability-store: store extrinsic data * compute extrinsic and check against candidate * add some egress queue tests * grumbles & substrate update * ensure everything builds
This commit is contained in:
committed by
Gav Wood
parent
152bb30889
commit
fe6351ca65
@@ -37,8 +37,8 @@
|
||||
//! ^~~returned pointer
|
||||
//! ```
|
||||
//!
|
||||
//! The `load_params` and `write_result` functions provide utilities for setting up
|
||||
//! a parachain WASM module in Rust.
|
||||
//! The `wasm_api` module (enabled only with the wasm-api feature) provides utilities
|
||||
//! for setting up a parachain WASM module in Rust.
|
||||
|
||||
#![cfg_attr(not(feature = "std"), no_std)]
|
||||
#![cfg_attr(not(feature = "std"), feature(alloc))]
|
||||
@@ -64,15 +64,17 @@ extern crate error_chain;
|
||||
|
||||
#[cfg(not(feature = "std"))]
|
||||
use alloc::vec::Vec;
|
||||
use codec::{Encode, Decode};
|
||||
|
||||
#[cfg(feature = "std")]
|
||||
pub mod wasm;
|
||||
pub mod wasm_executor;
|
||||
|
||||
#[cfg(feature = "wasm-api")]
|
||||
pub mod wasm_api;
|
||||
|
||||
/// Validation parameters for evaluating the parachain validity function.
|
||||
// TODO: consolidated ingress and balance downloads
|
||||
#[derive(PartialEq, Eq, Encode, Decode)]
|
||||
#[cfg_attr(feature = "std", derive(Debug))]
|
||||
#[derive(PartialEq, Eq, Decode)]
|
||||
#[cfg_attr(feature = "std", derive(Debug, Encode))]
|
||||
pub struct ValidationParams {
|
||||
/// The collation body.
|
||||
pub block_data: Vec<u8>,
|
||||
@@ -82,38 +84,19 @@ pub struct ValidationParams {
|
||||
|
||||
/// The result of parachain validation.
|
||||
// TODO: egress and balance uploads
|
||||
#[derive(PartialEq, Eq, Encode, Decode)]
|
||||
#[cfg_attr(feature = "std", derive(Debug))]
|
||||
#[derive(PartialEq, Eq, Encode)]
|
||||
#[cfg_attr(feature = "std", derive(Debug, Decode))]
|
||||
pub struct ValidationResult {
|
||||
/// New head data that should be included in the relay chain state.
|
||||
pub head_data: Vec<u8>,
|
||||
}
|
||||
|
||||
/// Load the validation params from memory when implementing a Rust parachain.
|
||||
///
|
||||
/// 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);
|
||||
|
||||
ValidationParams::decode(&mut slice).expect("Invalid input data")
|
||||
/// A reference to a message.
|
||||
#[cfg(feature = "std")]
|
||||
pub struct MessageRef<'a> {
|
||||
/// The target parachain.
|
||||
pub target: u32,
|
||||
/// Underlying data of the message.
|
||||
pub data: &'a [u8],
|
||||
}
|
||||
|
||||
/// Allocate the validation result in memory, getting the return-pointer back.
|
||||
///
|
||||
/// As described in the crate docs, this is a pointer to the appended length
|
||||
/// of the vector.
|
||||
pub fn write_result(result: ValidationResult) -> usize {
|
||||
let mut encoded = result.encode();
|
||||
let len = encoded.len();
|
||||
|
||||
assert!(len <= u32::max_value() as usize, "Len too large for parachain-WASM abi");
|
||||
(len as u32).using_encoded(|s| encoded.extend(s));
|
||||
|
||||
// do not alter `encoded` beyond this point. may reallocate.
|
||||
let end_ptr = &encoded[len] as *const u8 as usize;
|
||||
|
||||
// leak so it doesn't get zeroed.
|
||||
::core::mem::forget(encoded);
|
||||
end_ptr
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user