mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-07-13 23:15:49 +00:00
10cec3b591
* upgrade primitives to allow changing validation function * set up storage schema for old parachains code * fix compilation errors * fix test compilation * add some tests for past code meta * most of the runtime logic for code upgrades * implement old-code pruning * add a couple tests * clean up remaining TODOs * add a whole bunch of tests for runtime functionality * remove unused function * fix runtime compilation * extract some primitives to parachain crate * add validation-code upgrades to validation params and result * extend validation params with code upgrade fields * provide maximums to validation params * port test-parachains * add a code-upgrader test-parachain and tests * fix collator tests * move test-parachains to own folder to work around compilation errors * fix test compilation * update the Cargo.lock * fix parachains tests * remove dbg! invocation * use new pool in code-upgrader * bump lockfile * link TODO to issue
63 lines
2.4 KiB
Rust
63 lines
2.4 KiB
Rust
// Copyright 2019-2020 Parity Technologies (UK) Ltd.
|
|
// This file is part of Polkadot.
|
|
|
|
// Polkadot is free software: you can redistribute it and/or modify
|
|
// it under the terms of the GNU General Public License as published by
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
// (at your option) any later version.
|
|
|
|
// Polkadot is distributed in the hope that it will be useful,
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
// GNU General Public License for more details.
|
|
|
|
// You should have received a copy of the GNU General Public License
|
|
// along with Polkadot. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
//! Utilities for writing parachain WASM.
|
|
|
|
#[cfg(any(feature = "std", all(not(feature = "std"), feature = "wasm-api")))]
|
|
use crate::primitives::UpwardMessage;
|
|
#[cfg(any(feature = "std", all(not(feature = "std"), feature = "wasm-api")))]
|
|
use sp_runtime_interface::runtime_interface;
|
|
#[cfg(feature = "std")]
|
|
use sp_externalities::ExternalitiesExt;
|
|
|
|
/// The parachain api for posting messages.
|
|
// Either activate on `std` to get access to the `HostFunctions` or when `wasm-api` is given and on
|
|
// `no_std`.
|
|
#[cfg(any(feature = "std", all(not(feature = "std"), feature = "wasm-api")))]
|
|
#[runtime_interface]
|
|
pub trait Parachain {
|
|
/// Post a message to this parachain's relay chain.
|
|
#[allow(dead_code)]
|
|
fn post_upward_message(&mut self, msg: UpwardMessage) {
|
|
self.extension::<crate::wasm_executor::ParachainExt>()
|
|
.expect("No `ParachainExt` associated with the current context.")
|
|
.post_upward_message(msg)
|
|
.expect("Failed to post upward message")
|
|
}
|
|
}
|
|
|
|
/// 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.
|
|
#[cfg(not(feature = "std"))]
|
|
pub unsafe fn load_params(params: *const u8, len: usize)
|
|
-> crate::primitives::ValidationParams
|
|
{
|
|
let mut slice = sp_std::slice::from_raw_parts(params, len);
|
|
|
|
codec::Decode::decode(&mut slice).expect("Invalid input data")
|
|
}
|
|
|
|
/// 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.
|
|
#[cfg(not(feature = "std"))]
|
|
pub fn write_result(result: &crate::primitives::ValidationResult) -> u64 {
|
|
sp_core::to_substrate_wasm_fn_return_value(&result)
|
|
}
|