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
@@ -8,12 +8,15 @@ edition = "2018"
adder = { path = ".." }
parachain = { package = "polkadot-parachain", path = "../../../parachain", default-features = false, features = ["wasm-api"] }
tiny-keccak = "1.4"
dlmalloc = { version = "0.1.2", features = ["global"] }
dlmalloc = { version = "0.1.3", features = ["global"] }
# We need to make sure the global allocator is disabled until we have support of full substrate externalities
rstd = { package = "sr-std", git = "https://github.com/paritytech/substrate", branch = "polkadot-master", default-features = false, features = [ "no_global_allocator" ] }
[lib]
crate-type = ["cdylib"]
[target.release]
[profile.release]
panic = "abort"
lto = true
@@ -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() }
),
+7 -1
View File
@@ -4,10 +4,16 @@ set -e
# Make LLD produce a binary that imports memory from the outside environment.
export RUSTFLAGS="-C link-arg=--import-memory -C link-arg=--export-table -C panic=abort"
if cargo --version | grep -q "nightly"; then
CARGO_CMD="cargo"
else
CARGO_CMD="cargo +nightly"
fi
for i in adder
do
cd $i/wasm
cargo +nightly build --target=wasm32-unknown-unknown --release --no-default-features --target-dir target "$@"
$CARGO_CMD build --target=wasm32-unknown-unknown --release --no-default-features --target-dir target "$@"
wasm-gc target/wasm32-unknown-unknown/release/$i'_'wasm.wasm target/wasm32-unknown-unknown/release/$i.wasm
cp target/wasm32-unknown-unknown/release/$i.wasm ../../../parachain/tests/res/
rm -rf target