mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-20 03:31:03 +00:00
Switch to parachain::ValidationParams
This commit is contained in:
Generated
+97
-1340
File diff suppressed because it is too large
Load Diff
@@ -1,6 +1,5 @@
|
|||||||
[workspace]
|
[workspace]
|
||||||
members = [
|
members = [
|
||||||
"collator",
|
|
||||||
"consensus",
|
"consensus",
|
||||||
"runtime",
|
"runtime",
|
||||||
"test/runtime",
|
"test/runtime",
|
||||||
|
|||||||
+9
-1
@@ -5,13 +5,19 @@ authors = ["Parity Technologies <admin@parity.io>"]
|
|||||||
edition = "2018"
|
edition = "2018"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
codec = { package = "parity-codec", version = "3.5.1", default-features = false, features = [ "derive" ] }
|
# Substrate dependencies
|
||||||
rstd = { package = "sr-std", git = "https://github.com/paritytech/substrate", default-features = false, branch = "bkchr-cumulus-branch" }
|
rstd = { package = "sr-std", git = "https://github.com/paritytech/substrate", default-features = false, branch = "bkchr-cumulus-branch" }
|
||||||
runtime-primitives = { package = "sr-primitives", git = "https://github.com/paritytech/substrate", default-features = false, branch = "bkchr-cumulus-branch" }
|
runtime-primitives = { package = "sr-primitives", git = "https://github.com/paritytech/substrate", default-features = false, branch = "bkchr-cumulus-branch" }
|
||||||
primitives = { package = "substrate-primitives", git = "https://github.com/paritytech/substrate", default-features = false, branch = "bkchr-cumulus-branch" }
|
primitives = { package = "substrate-primitives", git = "https://github.com/paritytech/substrate", default-features = false, branch = "bkchr-cumulus-branch" }
|
||||||
rio = { package = "sr-io", git = "https://github.com/paritytech/substrate", default-features = false, branch = "bkchr-cumulus-branch" }
|
rio = { package = "sr-io", git = "https://github.com/paritytech/substrate", default-features = false, branch = "bkchr-cumulus-branch" }
|
||||||
executive = { package = "srml-executive", git = "https://github.com/paritytech/substrate", default-features = false, branch = "bkchr-cumulus-branch" }
|
executive = { package = "srml-executive", git = "https://github.com/paritytech/substrate", default-features = false, branch = "bkchr-cumulus-branch" }
|
||||||
substrate-trie = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "bkchr-cumulus-branch" }
|
substrate-trie = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "bkchr-cumulus-branch" }
|
||||||
|
|
||||||
|
# Polkadot dependencies
|
||||||
|
parachain = { package = "polkadot-parachain", git = "https://github.com/paritytech/polkadot", default-features = false, branch = "bkchr-cumulus-branch" }
|
||||||
|
|
||||||
|
# Other deps
|
||||||
|
codec = { package = "parity-codec", version = "3.5.1", default-features = false, features = [ "derive" ] }
|
||||||
memory-db = { version = "0.12.2", default-features = false }
|
memory-db = { version = "0.12.2", default-features = false }
|
||||||
hash-db = { version = "0.12.2", default-features = false }
|
hash-db = { version = "0.12.2", default-features = false }
|
||||||
trie-db = { version = "0.12.2", default-features = false }
|
trie-db = { version = "0.12.2", default-features = false }
|
||||||
@@ -36,8 +42,10 @@ std = [
|
|||||||
"hash-db/std",
|
"hash-db/std",
|
||||||
"trie-db/std",
|
"trie-db/std",
|
||||||
"substrate-trie/std",
|
"substrate-trie/std",
|
||||||
|
"parachain/std",
|
||||||
]
|
]
|
||||||
no_std = [
|
no_std = [
|
||||||
"hashbrown/nightly",
|
"hashbrown/nightly",
|
||||||
"rio/wasm-nice-panic-message",
|
"rio/wasm-nice-panic-message",
|
||||||
|
"parachain/wasm-api",
|
||||||
]
|
]
|
||||||
|
|||||||
@@ -28,7 +28,9 @@ use rstd::{slice, ptr, cmp, vec::Vec, boxed::Box, mem};
|
|||||||
|
|
||||||
use hash_db::HashDB;
|
use hash_db::HashDB;
|
||||||
|
|
||||||
static mut STORAGE: Option<Box<Storage>> = None;
|
use parachain::ValidationParams;
|
||||||
|
|
||||||
|
static mut STORAGE: Option<Box<dyn Storage>> = None;
|
||||||
/// The message to use as expect message while accessing the `STORAGE`.
|
/// The message to use as expect message while accessing the `STORAGE`.
|
||||||
const STORAGE_SET_EXPECT: &str =
|
const STORAGE_SET_EXPECT: &str =
|
||||||
"`STORAGE` needs to be set before calling this function.";
|
"`STORAGE` needs to be set before calling this function.";
|
||||||
@@ -53,18 +55,20 @@ trait Storage {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Validate a given parachain block on a validator.
|
/// Validate a given parachain block on a validator.
|
||||||
#[cfg(not(feature = "std"))]
|
|
||||||
#[doc(hidden)]
|
#[doc(hidden)]
|
||||||
pub fn validate_block<B: BlockT, E: ExecuteBlock<B>>(
|
pub fn validate_block<B: BlockT, E: ExecuteBlock<B>>(
|
||||||
mut arguments: &[u8],
|
params: ValidationParams,
|
||||||
) {
|
) {
|
||||||
use codec::Decode;
|
use codec::Decode;
|
||||||
|
|
||||||
let (parent_hash, block_data): (B::Hash, crate::ParachainBlockData::<B>) = Decode::decode(&mut arguments)
|
let block_data = crate::ParachainBlockData::<B>::decode(&mut ¶ms.block_data[..])
|
||||||
.expect("Could not decode parachain block.");
|
.expect("Invalid parachain block data");
|
||||||
|
|
||||||
|
let parent_head = B::Header::decode(&mut ¶ms.parent_head[..]).expect("Invalid parent head");
|
||||||
|
|
||||||
// TODO: Add `PolkadotInherent`.
|
// TODO: Add `PolkadotInherent`.
|
||||||
let block = B::new(block_data.header, block_data.extrinsics);
|
let block = B::new(block_data.header, block_data.extrinsics);
|
||||||
assert!(parent_hash == *block.header().parent_hash(), "Invalid parent hash");
|
assert!(parent_head.hash() == *block.header().parent_hash(), "Invalid parent hash");
|
||||||
|
|
||||||
let storage = WitnessStorage::<B>::new(
|
let storage = WitnessStorage::<B>::new(
|
||||||
block_data.witness_data,
|
block_data.witness_data,
|
||||||
|
|||||||
@@ -22,6 +22,10 @@ mod tests;
|
|||||||
#[doc(hidden)]
|
#[doc(hidden)]
|
||||||
pub mod implementation;
|
pub mod implementation;
|
||||||
|
|
||||||
|
#[cfg(not(feature = "std"))]
|
||||||
|
#[doc(hidden)]
|
||||||
|
pub use parachain;
|
||||||
|
|
||||||
/// Register the `validate_block` function that is used by parachains to validate blocks on a validator.
|
/// Register the `validate_block` function that is used by parachains to validate blocks on a validator.
|
||||||
///
|
///
|
||||||
/// Does *nothing* when `std` feature is enabled.
|
/// Does *nothing* when `std` feature is enabled.
|
||||||
@@ -58,16 +62,16 @@ macro_rules! register_validate_block_impl {
|
|||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
unsafe fn validate_block(
|
unsafe fn validate_block(
|
||||||
arguments: *const u8,
|
arguments: *const u8,
|
||||||
arguments_len: u64,
|
arguments_len: usize,
|
||||||
) {
|
) {
|
||||||
let arguments = $crate::slice::from_raw_parts(
|
let params = $crate::validate_block::parachain::wasm_api::load_params(
|
||||||
arguments,
|
arguments,
|
||||||
arguments_len as usize,
|
arguments_len,
|
||||||
);
|
);
|
||||||
|
|
||||||
$crate::validate_block::implementation::validate_block::<
|
$crate::validate_block::implementation::validate_block::<
|
||||||
$block, $block_executor
|
$block, $block_executor
|
||||||
>(arguments);
|
>(params);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -19,16 +19,17 @@ use crate::{ParachainBlockData, WitnessData};
|
|||||||
use rio::TestExternalities;
|
use rio::TestExternalities;
|
||||||
use keyring::AccountKeyring;
|
use keyring::AccountKeyring;
|
||||||
use runtime_primitives::{generic::BlockId, traits::{Block as BlockT, Header as HeaderT}};
|
use runtime_primitives::{generic::BlockId, traits::{Block as BlockT, Header as HeaderT}};
|
||||||
use executor::{WasmExecutor, error::Result, wasmi::RuntimeValue::{I64, I32}};
|
use executor::{WasmExecutor, error::Result, wasmi::RuntimeValue::I32};
|
||||||
use test_client::{
|
use test_client::{
|
||||||
TestClientBuilder, TestClientBuilderExt, DefaultTestClientBuilderExt, Client, LongestChain,
|
TestClientBuilder, TestClientBuilderExt, DefaultTestClientBuilderExt, Client, LongestChain,
|
||||||
runtime::{Block, Transfer, Hash, WASM_BINARY}
|
runtime::{Block, Transfer, Hash, WASM_BINARY, Header}
|
||||||
};
|
};
|
||||||
use consensus_common::SelectChain;
|
use consensus_common::SelectChain;
|
||||||
|
use parachain::ValidationParams;
|
||||||
|
|
||||||
use codec::Encode;
|
use codec::Encode;
|
||||||
|
|
||||||
fn call_validate_block(parent_hash: Hash, block_data: ParachainBlockData<Block>) -> Result<()> {
|
fn call_validate_block(parent_head: Header, block_data: ParachainBlockData<Block>) -> Result<()> {
|
||||||
let mut ext = TestExternalities::default();
|
let mut ext = TestExternalities::default();
|
||||||
WasmExecutor::new().call_with_custom_signature(
|
WasmExecutor::new().call_with_custom_signature(
|
||||||
&mut ext,
|
&mut ext,
|
||||||
@@ -36,13 +37,17 @@ fn call_validate_block(parent_hash: Hash, block_data: ParachainBlockData<Block>)
|
|||||||
&WASM_BINARY,
|
&WASM_BINARY,
|
||||||
"validate_block",
|
"validate_block",
|
||||||
|alloc| {
|
|alloc| {
|
||||||
let arguments = (parent_hash, block_data).encode();
|
let params = ValidationParams {
|
||||||
let arguments_offset = alloc(&arguments)?;
|
block_data: block_data.encode(),
|
||||||
|
parent_head: parent_head.encode(),
|
||||||
|
ingress: Vec::new(),
|
||||||
|
}.encode();
|
||||||
|
let params_offset = alloc(¶ms)?;
|
||||||
|
|
||||||
Ok(
|
Ok(
|
||||||
vec![
|
vec![
|
||||||
I32(arguments_offset as i32),
|
I32(params_offset as i32),
|
||||||
I64(arguments.len() as i64),
|
I32(params.len() as i32),
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
@@ -111,10 +116,8 @@ fn build_block_with_proof(
|
|||||||
#[test]
|
#[test]
|
||||||
fn validate_block_with_no_extrinsics() {
|
fn validate_block_with_no_extrinsics() {
|
||||||
let (client, longest_chain) = create_test_client();
|
let (client, longest_chain) = create_test_client();
|
||||||
let witness_data_storage_root = *longest_chain
|
let parent_head = longest_chain.best_chain().expect("Best block exists");
|
||||||
.best_chain()
|
let witness_data_storage_root = *parent_head.state_root();
|
||||||
.expect("Best block exists")
|
|
||||||
.state_root();
|
|
||||||
let (block, witness_data) = build_block_with_proof(&client, Vec::new());
|
let (block, witness_data) = build_block_with_proof(&client, Vec::new());
|
||||||
let (header, extrinsics) = block.deconstruct();
|
let (header, extrinsics) = block.deconstruct();
|
||||||
|
|
||||||
@@ -124,16 +127,14 @@ fn validate_block_with_no_extrinsics() {
|
|||||||
witness_data,
|
witness_data,
|
||||||
witness_data_storage_root
|
witness_data_storage_root
|
||||||
);
|
);
|
||||||
call_validate_block(client.info().chain.genesis_hash, block_data).expect("Calls `validate_block`");
|
call_validate_block(parent_head, block_data).expect("Calls `validate_block`");
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn validate_block_with_extrinsics() {
|
fn validate_block_with_extrinsics() {
|
||||||
let (client, longest_chain) = create_test_client();
|
let (client, longest_chain) = create_test_client();
|
||||||
let witness_data_storage_root = *longest_chain
|
let parent_head = longest_chain.best_chain().expect("Best block exists");
|
||||||
.best_chain()
|
let witness_data_storage_root = *parent_head.state_root();
|
||||||
.expect("Best block exists")
|
|
||||||
.state_root();
|
|
||||||
let (block, witness_data) = build_block_with_proof(&client, create_extrinsics());
|
let (block, witness_data) = build_block_with_proof(&client, create_extrinsics());
|
||||||
let (header, extrinsics) = block.deconstruct();
|
let (header, extrinsics) = block.deconstruct();
|
||||||
|
|
||||||
@@ -143,17 +144,15 @@ fn validate_block_with_extrinsics() {
|
|||||||
witness_data,
|
witness_data,
|
||||||
witness_data_storage_root
|
witness_data_storage_root
|
||||||
);
|
);
|
||||||
call_validate_block(client.info().chain.genesis_hash, block_data).expect("Calls `validate_block`");
|
call_validate_block(parent_head, block_data).expect("Calls `validate_block`");
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
#[should_panic]
|
#[should_panic]
|
||||||
fn validate_block_invalid_parent_hash() {
|
fn validate_block_invalid_parent_hash() {
|
||||||
let (client, longest_chain) = create_test_client();
|
let (client, longest_chain) = create_test_client();
|
||||||
let witness_data_storage_root = *longest_chain
|
let parent_head = longest_chain.best_chain().expect("Best block exists");
|
||||||
.best_chain()
|
let witness_data_storage_root = *parent_head.state_root();
|
||||||
.expect("Best block exists")
|
|
||||||
.state_root();
|
|
||||||
let (block, witness_data) = build_block_with_proof(&client, Vec::new());
|
let (block, witness_data) = build_block_with_proof(&client, Vec::new());
|
||||||
let (mut header, extrinsics) = block.deconstruct();
|
let (mut header, extrinsics) = block.deconstruct();
|
||||||
header.set_parent_hash(Hash::from_low_u64_be(1));
|
header.set_parent_hash(Hash::from_low_u64_be(1));
|
||||||
@@ -164,5 +163,5 @@ fn validate_block_invalid_parent_hash() {
|
|||||||
witness_data,
|
witness_data,
|
||||||
witness_data_storage_root
|
witness_data_storage_root
|
||||||
);
|
);
|
||||||
call_validate_block(client.info().chain.genesis_hash, block_data).expect("Calls `validate_block`");
|
call_validate_block(parent_head, block_data).expect("Calls `validate_block`");
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user