mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-05-30 10:31:03 +00:00
Update to latest Substrate master. (#353)
* Integrate srml/im-online * Fix all build errors with old aura. * Fix most of the build errors. * Builds and tests seem to pass (I will not trust this commit yet) * Apply suggestions from code review Co-Authored-By: Robert Habermeier <rphmeier@gmail.com> * Kill some warnings. * fix panics on 0 validators * Fix dev chain. * Fix author stuff * fix im online integration. * Some tweaks * Introduce app-crypto * Initial build work * codec update / tweaks * patch polkadot-erasure-coding input * More fixes for new crypto * More fixes * Update parachains module * evamp parachain crypto * More crypto work. * Chain spec and service. * ChainSpec stuff * Last bits for a clean build * Tweak coment * adapt polkadot-validation to the new keystore * polkadot-network compiles, but tests don't * Integrate the new parachain validation stuff * delete message_routing file * make polkadot-network tests compile and pass * runtime tests compile and pass * update substrate ref * service compiles * all tests pass * Add TODO, change branch back to polkadot-master * Lock file * TODOs done * Issue number * Remove old tODO * Remove commented code
This commit is contained in:
@@ -6,11 +6,10 @@ description = "Types and utilities for creating and working with parachains"
|
||||
edition = "2018"
|
||||
|
||||
[dependencies]
|
||||
codec = { package = "parity-codec", version = "4.1", default-features = false, features = [ "derive" ] }
|
||||
codec = { package = "parity-scale-codec", version = "1.0.5", default-features = false, features = [ "derive" ] }
|
||||
wasmi = { version = "0.4.3", optional = true }
|
||||
derive_more = { version = "0.14", optional = true }
|
||||
serde = { version = "1.0", default-features = false, features = [ "derive" ] }
|
||||
|
||||
rstd = { package = "sr-std", git = "https://github.com/paritytech/substrate", branch = "polkadot-master", default-features = false }
|
||||
lazy_static = { version = "1.3.0", optional = true }
|
||||
parking_lot = { version = "0.7.1", optional = true }
|
||||
@@ -27,4 +26,14 @@ halt = { path = "../test-parachains/halt" }
|
||||
[features]
|
||||
default = ["std"]
|
||||
wasm-api = []
|
||||
std = [ "codec/std", "wasmi", "derive_more", "serde/std", "rstd/std", "shared_memory", "lazy_static", "parking_lot", "log" ]
|
||||
std = [
|
||||
"codec/std",
|
||||
"wasmi",
|
||||
"derive_more",
|
||||
"serde/std",
|
||||
"rstd/std",
|
||||
"shared_memory",
|
||||
"lazy_static",
|
||||
"parking_lot",
|
||||
"log"
|
||||
]
|
||||
|
||||
@@ -51,22 +51,9 @@ pub mod wasm_executor;
|
||||
#[cfg(feature = "wasm-api")]
|
||||
pub mod wasm_api;
|
||||
|
||||
use codec::{Encode, Decode};
|
||||
|
||||
use rstd::vec::Vec;
|
||||
|
||||
struct TrailingZeroInput<'a>(&'a [u8]);
|
||||
impl<'a> codec::Input for TrailingZeroInput<'a> {
|
||||
fn read(&mut self, into: &mut [u8]) -> usize {
|
||||
let len = into.len().min(self.0.len());
|
||||
into[..len].copy_from_slice(&self.0[..len]);
|
||||
for i in &mut into[len..] {
|
||||
*i = 0;
|
||||
}
|
||||
self.0 = &self.0[len..];
|
||||
len
|
||||
}
|
||||
}
|
||||
use codec::{Encode, Decode};
|
||||
|
||||
/// Validation parameters for evaluating the parachain validity function.
|
||||
// TODO: balance downloads (https://github.com/paritytech/polkadot/issues/220)
|
||||
@@ -110,37 +97,6 @@ impl From<codec::Compact<Id>> for Id {
|
||||
}
|
||||
}
|
||||
|
||||
/// This type can be converted into and possibly from an AccountId (which itself is generic).
|
||||
pub trait AccountIdConversion<AccountId>: Sized {
|
||||
/// Convert into an account ID. This is infallible.
|
||||
fn into_account(&self) -> AccountId;
|
||||
|
||||
/// Try to convert an account ID into this type. Might not succeed.
|
||||
fn try_from_account(a: &AccountId) -> Option<Self>;
|
||||
}
|
||||
|
||||
/// Format is b"para" ++ encode(parachain ID) ++ 00.... where 00... is indefinite trailing 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()
|
||||
}
|
||||
|
||||
fn try_from_account(x: &T) -> Option<Self> {
|
||||
x.using_encoded(|d| {
|
||||
if &d[0..4] != b"para" { return None }
|
||||
let mut cursor = &d[4..];
|
||||
let result = Decode::decode(&mut cursor)?;
|
||||
if cursor.iter().all(|x| *x == 0) {
|
||||
Some(result)
|
||||
} else {
|
||||
None
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
impl From<Id> for u32 {
|
||||
fn from(x: Id) -> Self { x.0 }
|
||||
}
|
||||
@@ -156,6 +112,56 @@ impl Id {
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: Remove all of this, move sr-primitives::AccountIdConversion to own crate and and use that.
|
||||
// #360
|
||||
struct TrailingZeroInput<'a>(&'a [u8]);
|
||||
impl<'a> codec::Input for TrailingZeroInput<'a> {
|
||||
fn remaining_len(&mut self) -> Result<Option<usize>, codec::Error> {
|
||||
Ok(None)
|
||||
}
|
||||
|
||||
fn read(&mut self, into: &mut [u8]) -> Result<(), codec::Error> {
|
||||
let len = into.len().min(self.0.len());
|
||||
into[..len].copy_from_slice(&self.0[..len]);
|
||||
for i in &mut into[len..] {
|
||||
*i = 0;
|
||||
}
|
||||
self.0 = &self.0[len..];
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
/// This type can be converted into and possibly from an AccountId (which itself is generic).
|
||||
pub trait AccountIdConversion<AccountId>: Sized {
|
||||
/// Convert into an account ID. This is infallible.
|
||||
fn into_account(&self) -> AccountId;
|
||||
|
||||
/// Try to convert an account ID into this type. Might not succeed.
|
||||
fn try_from_account(a: &AccountId) -> Option<Self>;
|
||||
}
|
||||
|
||||
/// Format is b"para" ++ encode(parachain ID) ++ 00.... where 00... is indefinite trailing 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()
|
||||
}
|
||||
|
||||
fn try_from_account(x: &T) -> Option<Self> {
|
||||
x.using_encoded(|d| {
|
||||
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) {
|
||||
Some(result)
|
||||
} else {
|
||||
None
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
/// An incoming message.
|
||||
#[derive(PartialEq, Eq, Decode)]
|
||||
#[cfg_attr(feature = "std", derive(Debug, Encode))]
|
||||
|
||||
@@ -431,7 +431,7 @@ pub fn validate_candidate_internal<E: Externalities>(
|
||||
let len_offset = len_offset as usize;
|
||||
|
||||
let len = u32::decode(&mut &len_bytes[..])
|
||||
.ok_or_else(|| Error::BadReturn)? as usize;
|
||||
.map_err(|_| Error::BadReturn)? as usize;
|
||||
|
||||
let return_offset = if len > len_offset {
|
||||
return Err(Error::BadReturn);
|
||||
@@ -445,8 +445,7 @@ pub fn validate_candidate_internal<E: Externalities>(
|
||||
}
|
||||
|
||||
ValidationResult::decode(&mut &mem[return_offset..][..len])
|
||||
.ok_or_else(|| Error::BadReturn)
|
||||
.map_err(Into::into)
|
||||
.map_err(|_| Error::BadReturn.into())
|
||||
})
|
||||
}
|
||||
_ => Err(Error::BadReturn),
|
||||
|
||||
@@ -95,7 +95,7 @@ pub fn run_worker(mem_id: &str) -> Result<(), String> {
|
||||
let (header_buf, rest) = data.split_at_mut(1024);
|
||||
let mut header_buf: &[u8] = header_buf;
|
||||
let header = ValidationHeader::decode(&mut header_buf)
|
||||
.ok_or_else(|| format!("Error decoding validation request."))?;
|
||||
.map_err(|_| format!("Error decoding validation request."))?;
|
||||
debug!("Candidate header: {:?}", header);
|
||||
let (code, rest) = rest.split_at_mut(MAX_CODE_MEM);
|
||||
let (code, _) = code.split_at_mut(header.code_size as usize);
|
||||
|
||||
@@ -169,7 +169,7 @@ fn processes_messages() {
|
||||
};
|
||||
|
||||
let bad_message_data = vec![1];
|
||||
assert!(AddMessage::decode(&mut &bad_message_data[..]).is_none());
|
||||
assert!(AddMessage::decode(&mut &bad_message_data[..]).is_err());
|
||||
|
||||
let ret = parachain::wasm_executor::validate_candidate(
|
||||
TEST_CODE,
|
||||
|
||||
Reference in New Issue
Block a user