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:
Bastian Köcher
2019-06-25 21:08:56 +02:00
committed by GitHub
parent 23432bb043
commit 9004fb3f97
11 changed files with 55 additions and 74 deletions
@@ -18,9 +18,7 @@
#![no_std]
#![feature(
alloc, core_intrinsics, lang_items, core_panic_info, alloc_error_handler
)]
#![feature(core_intrinsics, lang_items, core_panic_info, alloc_error_handler)]
#[global_allocator]
static ALLOC: dlmalloc::GlobalDlmalloc = dlmalloc::GlobalDlmalloc;
@@ -40,30 +38,30 @@ pub fn panic(_info: &panic::PanicInfo) -> ! {
#[alloc_error_handler]
#[no_mangle]
pub fn oom(_: ::core::alloc::Layout) -> ! {
pub fn oom(_: core::alloc::Layout) -> ! {
unsafe {
intrinsics::abort();
}
}
#[no_mangle]
pub extern fn validate(offset: usize, len: usize) -> usize {
let params = unsafe { ::parachain::wasm_api::load_params(offset, len) };
pub extern fn validate_block(params: *const u8, len: usize) -> usize {
let params = unsafe { parachain::wasm_api::load_params(params, len) };
let parent_head = HeadData::decode(&mut &params.parent_head[..])
.expect("invalid parent head format.");
let block_data = BlockData::decode(&mut &params.block_data[..])
.expect("invalid block data format.");
let parent_hash = ::tiny_keccak::keccak256(&params.parent_head[..]);
let parent_hash = tiny_keccak::keccak256(&params.parent_head[..]);
// we also add based on incoming data from messages. ignoring unknown message
// kinds.
let from_messages = ::adder::process_messages(
let from_messages = adder::process_messages(
params.ingress.iter().map(|incoming| &incoming.data[..])
);
match ::adder::execute(parent_hash, parent_head, &block_data, from_messages) {
match adder::execute(parent_hash, parent_head, &block_data, from_messages) {
Ok(new_head) => parachain::wasm_api::write_result(
ValidationResult { head_data: new_head.encode() }
),