mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-05-30 10:31:03 +00:00
cargo +nightly fmt (#3540)
* cargo +nightly fmt * add cargo-fmt check to ci * update ci * fmt * fmt * skip macro * ignore bridges
This commit is contained in:
@@ -19,13 +19,13 @@
|
||||
|
||||
use sp_std::vec::Vec;
|
||||
|
||||
use parity_scale_codec::{Encode, Decode, CompactAs};
|
||||
use frame_support::weights::Weight;
|
||||
use parity_scale_codec::{CompactAs, Decode, Encode};
|
||||
use sp_core::{RuntimeDebug, TypeId};
|
||||
use sp_runtime::traits::Hash as _;
|
||||
use frame_support::weights::Weight;
|
||||
|
||||
#[cfg(feature = "std")]
|
||||
use serde::{Serialize, Deserialize};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[cfg(feature = "std")]
|
||||
use sp_core::bytes;
|
||||
@@ -39,9 +39,11 @@ use polkadot_core_primitives::{Hash, OutboundHrmpMessage};
|
||||
pub use polkadot_core_primitives::BlockNumber as RelayChainBlockNumber;
|
||||
|
||||
/// Parachain head data included in the chain.
|
||||
#[derive(PartialEq, Eq, Clone, PartialOrd, Ord, Encode, Decode, RuntimeDebug, derive_more::From)]
|
||||
#[derive(
|
||||
PartialEq, Eq, Clone, PartialOrd, Ord, Encode, Decode, RuntimeDebug, derive_more::From,
|
||||
)]
|
||||
#[cfg_attr(feature = "std", derive(Serialize, Deserialize, Default, Hash, MallocSizeOf))]
|
||||
pub struct HeadData(#[cfg_attr(feature = "std", serde(with="bytes"))] pub Vec<u8>);
|
||||
pub struct HeadData(#[cfg_attr(feature = "std", serde(with = "bytes"))] pub Vec<u8>);
|
||||
|
||||
#[cfg(feature = "std")]
|
||||
impl HeadData {
|
||||
@@ -117,11 +119,22 @@ pub struct BlockData(#[cfg_attr(feature = "std", serde(with = "bytes"))] pub Vec
|
||||
|
||||
/// Unique identifier of a parachain.
|
||||
#[derive(
|
||||
Clone, CompactAs, Copy, Decode, Default, Encode, Eq,
|
||||
Hash, Ord, PartialEq, PartialOrd, RuntimeDebug,
|
||||
Clone,
|
||||
CompactAs,
|
||||
Copy,
|
||||
Decode,
|
||||
Default,
|
||||
Encode,
|
||||
Eq,
|
||||
Hash,
|
||||
Ord,
|
||||
PartialEq,
|
||||
PartialOrd,
|
||||
RuntimeDebug,
|
||||
)]
|
||||
#[cfg_attr(feature = "std", derive(
|
||||
serde::Serialize, serde::Deserialize, derive_more::Display, MallocSizeOf)
|
||||
#[cfg_attr(
|
||||
feature = "std",
|
||||
derive(serde::Serialize, serde::Deserialize, derive_more::Display, MallocSizeOf)
|
||||
)]
|
||||
pub struct Id(u32);
|
||||
|
||||
@@ -130,11 +143,15 @@ impl TypeId for Id {
|
||||
}
|
||||
|
||||
impl From<Id> for u32 {
|
||||
fn from(x: Id) -> Self { x.0 }
|
||||
fn from(x: Id) -> Self {
|
||||
x.0
|
||||
}
|
||||
}
|
||||
|
||||
impl From<u32> for Id {
|
||||
fn from(x: u32) -> Self { Id(x) }
|
||||
fn from(x: u32) -> Self {
|
||||
Id(x)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<usize> for Id {
|
||||
@@ -237,11 +254,15 @@ impl TypeId for Sibling {
|
||||
}
|
||||
|
||||
impl From<Sibling> for u32 {
|
||||
fn from(x: Sibling) -> Self { x.0.into() }
|
||||
fn from(x: Sibling) -> Self {
|
||||
x.0.into()
|
||||
}
|
||||
}
|
||||
|
||||
impl From<u32> for Sibling {
|
||||
fn from(x: u32) -> Self { Sibling(x.into()) }
|
||||
fn from(x: u32) -> Self {
|
||||
Sibling(x.into())
|
||||
}
|
||||
}
|
||||
|
||||
impl IsSystem for Sibling {
|
||||
@@ -282,14 +303,16 @@ impl<'a> parity_scale_codec::Input for TrailingZeroInput<'a> {
|
||||
/// zeroes to fill AccountId.
|
||||
impl<T: Encode + Decode + Default> AccountIdConversion<T> for Id {
|
||||
fn into_account(&self) -> T {
|
||||
(b"para", self).using_encoded(|b|
|
||||
T::decode(&mut TrailingZeroInput(b))
|
||||
).unwrap_or_default()
|
||||
(b"para", self)
|
||||
.using_encoded(|b| T::decode(&mut TrailingZeroInput(b)))
|
||||
.unwrap_or_default()
|
||||
}
|
||||
|
||||
fn try_from_account(x: &T) -> Option<Self> {
|
||||
x.using_encoded(|d| {
|
||||
if &d[0..4] != b"para" { return None }
|
||||
if &d[0..4] != b"para" {
|
||||
return None
|
||||
}
|
||||
let mut cursor = &d[4..];
|
||||
let result = Decode::decode(&mut cursor).ok()?;
|
||||
if cursor.iter().all(|x| *x == 0) {
|
||||
|
||||
@@ -21,9 +21,7 @@
|
||||
/// 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
|
||||
{
|
||||
pub unsafe fn load_params(params: *const u8, len: usize) -> crate::primitives::ValidationParams {
|
||||
let mut slice = sp_std::slice::from_raw_parts(params, len);
|
||||
|
||||
parity_scale_codec::Decode::decode(&mut slice).expect("Invalid input data")
|
||||
|
||||
@@ -17,8 +17,5 @@
|
||||
use substrate_wasm_builder::WasmBuilder;
|
||||
|
||||
fn main() {
|
||||
WasmBuilder::new()
|
||||
.with_current_project()
|
||||
.export_heap_base()
|
||||
.build()
|
||||
WasmBuilder::new().with_current_project().export_heap_base().build()
|
||||
}
|
||||
|
||||
@@ -93,17 +93,15 @@ impl SubstrateCli for Cli {
|
||||
fn load_spec(&self, id: &str) -> std::result::Result<Box<dyn sc_service::ChainSpec>, String> {
|
||||
let id = if id.is_empty() { "rococo" } else { id };
|
||||
Ok(match id {
|
||||
"rococo-staging" => {
|
||||
Box::new(polkadot_service::chain_spec::rococo_staging_testnet_config()?)
|
||||
}
|
||||
"rococo-local" => {
|
||||
Box::new(polkadot_service::chain_spec::rococo_local_testnet_config()?)
|
||||
}
|
||||
"rococo-staging" =>
|
||||
Box::new(polkadot_service::chain_spec::rococo_staging_testnet_config()?),
|
||||
"rococo-local" =>
|
||||
Box::new(polkadot_service::chain_spec::rococo_local_testnet_config()?),
|
||||
"rococo" => Box::new(polkadot_service::chain_spec::rococo_config()?),
|
||||
path => {
|
||||
let path = std::path::PathBuf::from(path);
|
||||
Box::new(polkadot_service::RococoChainSpec::from_json_file(path)?)
|
||||
}
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@@ -16,19 +16,23 @@
|
||||
|
||||
//! Collator for the adder test parachain.
|
||||
|
||||
use futures::channel::oneshot;
|
||||
use futures_timer::Delay;
|
||||
use polkadot_node_primitives::{Collation, CollatorFn, CollationResult, Statement, SignedFullStatement};
|
||||
use parity_scale_codec::{Decode, Encode};
|
||||
use polkadot_node_primitives::{
|
||||
Collation, CollationResult, CollatorFn, PoV, SignedFullStatement, Statement,
|
||||
};
|
||||
use polkadot_primitives::v1::{CollatorId, CollatorPair};
|
||||
use polkadot_node_primitives::PoV;
|
||||
use parity_scale_codec::{Encode, Decode};
|
||||
use sp_core::{Pair, traits::SpawnNamed};
|
||||
use sp_core::{traits::SpawnNamed, Pair};
|
||||
use std::{
|
||||
collections::HashMap,
|
||||
sync::{Arc, Mutex, atomic::{AtomicU32, Ordering}},
|
||||
sync::{
|
||||
atomic::{AtomicU32, Ordering},
|
||||
Arc, Mutex,
|
||||
},
|
||||
time::Duration,
|
||||
};
|
||||
use test_parachain_adder::{execute, hash_state, BlockData, HeadData};
|
||||
use futures::channel::oneshot;
|
||||
|
||||
/// The amount we add when producing a new block.
|
||||
///
|
||||
@@ -37,11 +41,8 @@ const ADD: u64 = 2;
|
||||
|
||||
/// Calculates the head and state for the block with the given `number`.
|
||||
fn calculate_head_and_state_for_number(number: u64) -> (HeadData, u64) {
|
||||
let mut head = HeadData {
|
||||
number: 0,
|
||||
parent_hash: Default::default(),
|
||||
post_state: hash_state(0),
|
||||
};
|
||||
let mut head =
|
||||
HeadData { number: 0, parent_hash: Default::default(), post_state: hash_state(0) };
|
||||
|
||||
let mut state = 0u64;
|
||||
|
||||
@@ -89,11 +90,11 @@ impl State {
|
||||
add: ADD,
|
||||
};
|
||||
|
||||
let new_head = execute(parent_head.hash(), parent_head, &block).expect("Produces valid block");
|
||||
let new_head =
|
||||
execute(parent_head.hash(), parent_head, &block).expect("Produces valid block");
|
||||
|
||||
let new_head_arc = Arc::new(new_head.clone());
|
||||
self.head_to_state
|
||||
.insert(new_head_arc.clone(), block.state.wrapping_add(ADD));
|
||||
self.head_to_state.insert(new_head_arc.clone(), block.state.wrapping_add(ADD));
|
||||
self.number_to_head.insert(new_head.number, new_head_arc);
|
||||
|
||||
(block, new_head)
|
||||
@@ -146,7 +147,10 @@ impl Collator {
|
||||
/// Create the collation function.
|
||||
///
|
||||
/// This collation function can be plugged into the overseer to generate collations for the adder parachain.
|
||||
pub fn create_collation_function(&self, spawner: impl SpawnNamed + Clone + 'static) -> CollatorFn {
|
||||
pub fn create_collation_function(
|
||||
&self,
|
||||
spawner: impl SpawnNamed + Clone + 'static,
|
||||
) -> CollatorFn {
|
||||
use futures::FutureExt as _;
|
||||
|
||||
let state = self.state.clone();
|
||||
@@ -180,21 +184,29 @@ impl Collator {
|
||||
|
||||
let (result_sender, recv) = oneshot::channel::<SignedFullStatement>();
|
||||
let seconded_collations = seconded_collations.clone();
|
||||
spawner.spawn("adder-collator-seconded", async move {
|
||||
if let Ok(res) = recv.await {
|
||||
if !matches!(
|
||||
res.payload(),
|
||||
Statement::Seconded(s) if s.descriptor.pov_hash == compressed_pov.hash(),
|
||||
) {
|
||||
log::error!("Seconded statement should match our collation: {:?}", res.payload());
|
||||
std::process::exit(-1);
|
||||
spawner.spawn(
|
||||
"adder-collator-seconded",
|
||||
async move {
|
||||
if let Ok(res) = recv.await {
|
||||
if !matches!(
|
||||
res.payload(),
|
||||
Statement::Seconded(s) if s.descriptor.pov_hash == compressed_pov.hash(),
|
||||
) {
|
||||
log::error!(
|
||||
"Seconded statement should match our collation: {:?}",
|
||||
res.payload()
|
||||
);
|
||||
std::process::exit(-1);
|
||||
}
|
||||
|
||||
seconded_collations.fetch_add(1, Ordering::Relaxed);
|
||||
}
|
||||
|
||||
seconded_collations.fetch_add(1, Ordering::Relaxed);
|
||||
}
|
||||
}.boxed());
|
||||
.boxed(),
|
||||
);
|
||||
|
||||
async move { Some(CollationResult { collation, result_sender: Some(result_sender) }) }.boxed()
|
||||
async move { Some(CollationResult { collation, result_sender: Some(result_sender) }) }
|
||||
.boxed()
|
||||
})
|
||||
}
|
||||
|
||||
@@ -207,7 +219,7 @@ impl Collator {
|
||||
let current_block = self.state.lock().unwrap().best_block;
|
||||
|
||||
if start_block + blocks <= current_block {
|
||||
return;
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -222,7 +234,7 @@ impl Collator {
|
||||
Delay::new(Duration::from_secs(1)).await;
|
||||
|
||||
if seconded <= seconded_collations.load(Ordering::Relaxed) {
|
||||
return;
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -233,7 +245,7 @@ mod tests {
|
||||
use super::*;
|
||||
|
||||
use futures::executor::block_on;
|
||||
use polkadot_parachain::{primitives::{ValidationParams, ValidationResult}};
|
||||
use polkadot_parachain::primitives::{ValidationParams, ValidationResult};
|
||||
use polkadot_primitives::v1::PersistedValidationData;
|
||||
|
||||
#[test]
|
||||
@@ -243,14 +255,8 @@ mod tests {
|
||||
let collation_function = collator.create_collation_function(spawner);
|
||||
|
||||
for i in 0..5 {
|
||||
let parent_head = collator
|
||||
.state
|
||||
.lock()
|
||||
.unwrap()
|
||||
.number_to_head
|
||||
.get(&i)
|
||||
.unwrap()
|
||||
.clone();
|
||||
let parent_head =
|
||||
collator.state.lock().unwrap().number_to_head.get(&i).unwrap().clone();
|
||||
|
||||
let validation_data = PersistedValidationData {
|
||||
parent_head: parent_head.encode().into(),
|
||||
@@ -263,11 +269,7 @@ mod tests {
|
||||
}
|
||||
}
|
||||
|
||||
fn validate_collation(
|
||||
collator: &Collator,
|
||||
parent_head: HeadData,
|
||||
collation: Collation,
|
||||
) {
|
||||
fn validate_collation(collator: &Collator, parent_head: HeadData, collation: Collation) {
|
||||
use polkadot_node_core_pvf::testing::validate_candidate;
|
||||
|
||||
let ret_buf = validate_candidate(
|
||||
@@ -277,7 +279,8 @@ mod tests {
|
||||
block_data: collation.proof_of_validity.block_data,
|
||||
relay_parent_number: 1,
|
||||
relay_parent_storage_root: Default::default(),
|
||||
}.encode(),
|
||||
}
|
||||
.encode(),
|
||||
)
|
||||
.unwrap();
|
||||
let ret = ValidationResult::decode(&mut &ret_buf[..]).unwrap();
|
||||
@@ -307,7 +310,16 @@ mod tests {
|
||||
}
|
||||
|
||||
let collator = Collator::new();
|
||||
let mut second_head = collator.state.lock().unwrap().number_to_head.get(&0).cloned().unwrap().as_ref().clone();
|
||||
let mut second_head = collator
|
||||
.state
|
||||
.lock()
|
||||
.unwrap()
|
||||
.number_to_head
|
||||
.get(&0)
|
||||
.cloned()
|
||||
.unwrap()
|
||||
.as_ref()
|
||||
.clone();
|
||||
|
||||
for _ in 1..20 {
|
||||
second_head = collator.state.lock().unwrap().advance(second_head.clone()).1;
|
||||
|
||||
@@ -16,10 +16,10 @@
|
||||
|
||||
//! Collator for the adder test parachain.
|
||||
|
||||
use polkadot_cli::{Error, Result};
|
||||
use polkadot_node_primitives::CollationGenerationConfig;
|
||||
use polkadot_node_subsystem::messages::{CollationGenerationMessage, CollatorProtocolMessage};
|
||||
use polkadot_primitives::v1::Id as ParaId;
|
||||
use polkadot_cli::{Error, Result};
|
||||
use sc_cli::{Error as SubstrateCliError, Role, SubstrateCli};
|
||||
use sp_core::hexdisplay::HexDisplay;
|
||||
use test_parachain_adder_collator::Collator;
|
||||
@@ -39,16 +39,19 @@ fn main() -> Result<()> {
|
||||
println!("0x{:?}", HexDisplay::from(&collator.genesis_head()));
|
||||
|
||||
Ok::<_, Error>(())
|
||||
}
|
||||
},
|
||||
Some(cli::Subcommand::ExportGenesisWasm(_params)) => {
|
||||
let collator = Collator::new();
|
||||
println!("0x{:?}", HexDisplay::from(&collator.validation_code()));
|
||||
|
||||
Ok(())
|
||||
}
|
||||
},
|
||||
None => {
|
||||
let runner = cli.create_runner(&cli.run.base)
|
||||
.map_err(|e| SubstrateCliError::Application(Box::new(e) as Box::<(dyn 'static + Send + Sync + std::error::Error)>))?;
|
||||
let runner = cli.create_runner(&cli.run.base).map_err(|e| {
|
||||
SubstrateCliError::Application(
|
||||
Box::new(e) as Box<(dyn 'static + Send + Sync + std::error::Error)>
|
||||
)
|
||||
})?;
|
||||
|
||||
runner.run_node_until_exit(|config| async move {
|
||||
let role = config.role.clone();
|
||||
@@ -66,7 +69,8 @@ fn main() -> Result<()> {
|
||||
None,
|
||||
None,
|
||||
polkadot_service::RealOverseerGen,
|
||||
).map_err(|e| e.to_string())?;
|
||||
)
|
||||
.map_err(|e| e.to_string())?;
|
||||
let mut overseer_handle = full_node
|
||||
.overseer_handle
|
||||
.expect("Overseer handle should be initialized for collators");
|
||||
@@ -76,7 +80,8 @@ fn main() -> Result<()> {
|
||||
let validation_code_hex =
|
||||
format!("0x{:?}", HexDisplay::from(&collator.validation_code()));
|
||||
|
||||
let para_id = cli.run.parachain_id.map(ParaId::from).unwrap_or(DEFAULT_PARA_ID);
|
||||
let para_id =
|
||||
cli.run.parachain_id.map(ParaId::from).unwrap_or(DEFAULT_PARA_ID);
|
||||
|
||||
log::info!("Running adder collator for parachain id: {}", para_id);
|
||||
log::info!("Genesis state: {}", genesis_head_hex);
|
||||
@@ -84,7 +89,8 @@ fn main() -> Result<()> {
|
||||
|
||||
let config = CollationGenerationConfig {
|
||||
key: collator.collator_key(),
|
||||
collator: collator.create_collation_function(full_node.task_manager.spawn_handle()),
|
||||
collator: collator
|
||||
.create_collation_function(full_node.task_manager.spawn_handle()),
|
||||
para_id,
|
||||
};
|
||||
overseer_handle
|
||||
@@ -96,10 +102,10 @@ fn main() -> Result<()> {
|
||||
.await;
|
||||
|
||||
Ok(full_node.task_manager)
|
||||
}
|
||||
},
|
||||
}
|
||||
})
|
||||
}
|
||||
},
|
||||
}?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -22,9 +22,9 @@ const PUPPET_EXE: &str = env!("CARGO_BIN_EXE_adder_collator_puppet_worker");
|
||||
// If this test is failing, make sure to run all tests with the `real-overseer` feature being enabled.
|
||||
#[substrate_test_utils::test]
|
||||
async fn collating_using_adder_collator(task_executor: sc_service::TaskExecutor) {
|
||||
use sp_keyring::AccountKeyring::*;
|
||||
use futures::join;
|
||||
use polkadot_primitives::v1::Id as ParaId;
|
||||
use sp_keyring::AccountKeyring::*;
|
||||
|
||||
let mut builder = sc_cli::LoggerBuilder::new("");
|
||||
builder.with_colors(false);
|
||||
@@ -35,7 +35,8 @@ async fn collating_using_adder_collator(task_executor: sc_service::TaskExecutor)
|
||||
// start alice
|
||||
let alice = polkadot_test_service::run_validator_node(
|
||||
task_executor.clone(),
|
||||
Alice, || {},
|
||||
Alice,
|
||||
|| {},
|
||||
vec![],
|
||||
Some(PUPPET_EXE.into()),
|
||||
);
|
||||
@@ -53,11 +54,7 @@ async fn collating_using_adder_collator(task_executor: sc_service::TaskExecutor)
|
||||
|
||||
// register parachain
|
||||
alice
|
||||
.register_parachain(
|
||||
para_id,
|
||||
collator.validation_code().to_vec(),
|
||||
collator.genesis_head(),
|
||||
)
|
||||
.register_parachain(para_id, collator.validation_code().to_vec(), collator.genesis_head())
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
@@ -70,11 +67,13 @@ async fn collating_using_adder_collator(task_executor: sc_service::TaskExecutor)
|
||||
collator.collator_key(),
|
||||
);
|
||||
|
||||
charlie.register_collator(
|
||||
collator.collator_key(),
|
||||
para_id,
|
||||
collator.create_collation_function(charlie.task_manager.spawn_handle()),
|
||||
).await;
|
||||
charlie
|
||||
.register_collator(
|
||||
collator.collator_key(),
|
||||
para_id,
|
||||
collator.create_collation_function(charlie.task_manager.spawn_handle()),
|
||||
)
|
||||
.await;
|
||||
|
||||
// Wait until the parachain has 4 blocks produced.
|
||||
collator.wait_for_blocks(4).await;
|
||||
|
||||
@@ -17,10 +17,12 @@
|
||||
//! Basic parachain that adds a number as part of its state.
|
||||
|
||||
#![no_std]
|
||||
#![cfg_attr(
|
||||
not(feature = "std"),
|
||||
feature(core_intrinsics, lang_items, core_panic_info, alloc_error_handler)
|
||||
)]
|
||||
|
||||
#![cfg_attr(not(feature = "std"), feature(core_intrinsics, lang_items, core_panic_info, alloc_error_handler))]
|
||||
|
||||
use parity_scale_codec::{Encode, Decode};
|
||||
use parity_scale_codec::{Decode, Encode};
|
||||
use tiny_keccak::{Hasher as _, Keccak};
|
||||
|
||||
#[cfg(not(feature = "std"))]
|
||||
@@ -45,8 +47,10 @@ fn keccak256(input: &[u8]) -> [u8; 32] {
|
||||
/// Wasm binary unwrapped. If built with `BUILD_DUMMY_WASM_BINARY`, the function panics.
|
||||
#[cfg(feature = "std")]
|
||||
pub fn wasm_binary_unwrap() -> &'static [u8] {
|
||||
WASM_BINARY.expect("Development wasm binary is not available. Testing is only \
|
||||
supported with the flag disabled.")
|
||||
WASM_BINARY.expect(
|
||||
"Development wasm binary is not available. Testing is only \
|
||||
supported with the flag disabled.",
|
||||
)
|
||||
}
|
||||
|
||||
/// Head data for this parachain.
|
||||
@@ -93,14 +97,10 @@ pub fn execute(
|
||||
assert_eq!(parent_hash, parent_head.hash());
|
||||
|
||||
if hash_state(block_data.state) != parent_head.post_state {
|
||||
return Err(StateMismatch);
|
||||
return Err(StateMismatch)
|
||||
}
|
||||
|
||||
let new_state = block_data.state.wrapping_add(block_data.add);
|
||||
|
||||
Ok(HeadData {
|
||||
number: parent_head.number + 1,
|
||||
parent_hash,
|
||||
post_state: hash_state(new_state),
|
||||
})
|
||||
Ok(HeadData { number: parent_head.number + 1, parent_hash, post_state: hash_state(new_state) })
|
||||
}
|
||||
|
||||
@@ -16,32 +16,30 @@
|
||||
|
||||
//! WASM validation for adder parachain.
|
||||
|
||||
use crate::{HeadData, BlockData};
|
||||
use crate::{BlockData, HeadData};
|
||||
use core::panic;
|
||||
use parachain::primitives::{HeadData as GenericHeadData, ValidationResult};
|
||||
use parity_scale_codec::{Decode, Encode};
|
||||
use sp_std::vec::Vec;
|
||||
use parachain::primitives::{ValidationResult, HeadData as GenericHeadData};
|
||||
use parity_scale_codec::{Encode, Decode};
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn validate_block(params: *const u8, len: usize) -> u64 {
|
||||
let params = unsafe { parachain::load_params(params, len) };
|
||||
let parent_head = HeadData::decode(&mut ¶ms.parent_head.0[..])
|
||||
.expect("invalid parent head format.");
|
||||
let parent_head =
|
||||
HeadData::decode(&mut ¶ms.parent_head.0[..]).expect("invalid parent head format.");
|
||||
|
||||
let block_data = BlockData::decode(&mut ¶ms.block_data.0[..])
|
||||
.expect("invalid block data format.");
|
||||
let block_data =
|
||||
BlockData::decode(&mut ¶ms.block_data.0[..]).expect("invalid block data format.");
|
||||
|
||||
let parent_hash = crate::keccak256(¶ms.parent_head.0[..]);
|
||||
|
||||
let new_head = crate::execute(parent_hash, parent_head, &block_data).expect("Executes block");
|
||||
parachain::write_result(
|
||||
&ValidationResult {
|
||||
head_data: GenericHeadData(new_head.encode()),
|
||||
new_validation_code: None,
|
||||
upward_messages: sp_std::vec::Vec::new(),
|
||||
horizontal_messages: sp_std::vec::Vec::new(),
|
||||
processed_downward_messages: 0,
|
||||
hrmp_watermark: params.relay_parent_number,
|
||||
}
|
||||
)
|
||||
parachain::write_result(&ValidationResult {
|
||||
head_data: GenericHeadData(new_head.encode()),
|
||||
new_validation_code: None,
|
||||
upward_messages: sp_std::vec::Vec::new(),
|
||||
horizontal_messages: sp_std::vec::Vec::new(),
|
||||
processed_downward_messages: 0,
|
||||
hrmp_watermark: params.relay_parent_number,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -17,8 +17,5 @@
|
||||
use substrate_wasm_builder::WasmBuilder;
|
||||
|
||||
fn main() {
|
||||
WasmBuilder::new()
|
||||
.with_current_project()
|
||||
.export_heap_base()
|
||||
.build()
|
||||
WasmBuilder::new().with_current_project().export_heap_base().build()
|
||||
}
|
||||
|
||||
@@ -17,7 +17,10 @@
|
||||
//! Basic parachain that executes forever.
|
||||
|
||||
#![no_std]
|
||||
#![cfg_attr(not(feature = "std"), feature(core_intrinsics, lang_items, core_panic_info, alloc_error_handler))]
|
||||
#![cfg_attr(
|
||||
not(feature = "std"),
|
||||
feature(core_intrinsics, lang_items, core_panic_info, alloc_error_handler)
|
||||
)]
|
||||
|
||||
// Make the WASM binary available.
|
||||
#[cfg(feature = "std")]
|
||||
@@ -26,17 +29,17 @@ include!(concat!(env!("OUT_DIR"), "/wasm_binary.rs"));
|
||||
#[cfg(feature = "std")]
|
||||
/// Wasm binary unwrapped. If built with `BUILD_DUMMY_WASM_BINARY`, the function panics.
|
||||
pub fn wasm_binary_unwrap() -> &'static [u8] {
|
||||
WASM_BINARY.expect("Development wasm binary is not available. Testing is only \
|
||||
supported with the flag disabled.")
|
||||
WASM_BINARY.expect(
|
||||
"Development wasm binary is not available. Testing is only \
|
||||
supported with the flag disabled.",
|
||||
)
|
||||
}
|
||||
|
||||
#[cfg(not(feature = "std"))]
|
||||
#[panic_handler]
|
||||
#[no_mangle]
|
||||
pub fn panic(_info: &core::panic::PanicInfo) -> ! {
|
||||
unsafe {
|
||||
core::intrinsics::abort()
|
||||
}
|
||||
unsafe { core::intrinsics::abort() }
|
||||
}
|
||||
|
||||
#[cfg(not(feature = "std"))]
|
||||
@@ -50,6 +53,6 @@ pub fn oom(_: core::alloc::Layout) -> ! {
|
||||
|
||||
#[cfg(not(feature = "std"))]
|
||||
#[no_mangle]
|
||||
pub extern fn validate_block(params: *const u8, len: usize) -> u64 {
|
||||
pub extern "C" fn validate_block(params: *const u8, len: usize) -> u64 {
|
||||
loop {}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user