mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-11 13:01:07 +00:00
Try to fix the build
This commit is contained in:
Generated
+2235
-1351
File diff suppressed because it is too large
Load Diff
@@ -16,6 +16,6 @@ polkadot-collator = { git = "https://github.com/paritytech/polkadot", branch = "
|
||||
polkadot-primitives = { git = "https://github.com/paritytech/polkadot", branch = "bkchr-cumulus-branch" }
|
||||
|
||||
# other deps
|
||||
log = "0.4.6"
|
||||
codec = { package = "parity-codec", version = "4.1.1", features = [ "derive" ] }
|
||||
futures = "0.1.27"
|
||||
log = "0.4.8"
|
||||
codec = { package = "parity-scale-codec", version = "1.0.5", features = [ "derive" ] }
|
||||
futures = "0.1.29"
|
||||
|
||||
@@ -17,7 +17,8 @@ polkadot-primitives = { git = "https://github.com/paritytech/polkadot", branch =
|
||||
polkadot-runtime = { git = "https://github.com/paritytech/polkadot", branch = "bkchr-cumulus-branch" }
|
||||
|
||||
# other deps
|
||||
futures = "0.1.21"
|
||||
tokio = "0.1.8"
|
||||
parity-codec = "4.1.1"
|
||||
futures = "0.1.29"
|
||||
futures03 = { package = "futures-preview", version = "0.3.0-alpha.18"}
|
||||
tokio = "0.1.22"
|
||||
codec = { package = "parity-scale-codec", version = "1.0.5", features = [ "derive" ] }
|
||||
log = "0.4"
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Cumulus. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
use substrate_client::{backend::Backend, CallExecutor, Client, BlockchainEvents};
|
||||
use substrate_client::{backend::{Backend, Finalizer}, CallExecutor, Client, BlockchainEvents};
|
||||
use substrate_client::error::{Error as ClientError, Result as ClientResult};
|
||||
use substrate_primitives::{Blake2Hasher, H256};
|
||||
use sr_primitives::generic::BlockId;
|
||||
@@ -22,8 +22,10 @@ use sr_primitives::traits::{Block as BlockT, Header as HeaderT, ProvideRuntimeAp
|
||||
use polkadot_primitives::{Hash as PHash, Block as PBlock};
|
||||
use polkadot_primitives::parachain::{Id as ParaId, ParachainHost};
|
||||
|
||||
use futures::{prelude::*, stream};
|
||||
use parity_codec::{Encode, Decode};
|
||||
use futures03::{
|
||||
Stream, stream, StreamExt, TryStreamExt, TryStream, future, Future, TryFutureExt, FutureExt,
|
||||
};
|
||||
use codec::{Encode, Decode};
|
||||
use log::warn;
|
||||
|
||||
use std::sync::Arc;
|
||||
@@ -44,11 +46,9 @@ pub trait LocalClient {
|
||||
|
||||
/// Errors that can occur while following the polkadot relay-chain.
|
||||
#[derive(Debug)]
|
||||
pub enum Error<P> {
|
||||
pub enum Error {
|
||||
/// An underlying client error.
|
||||
Client(ClientError),
|
||||
/// Polkadot client error.
|
||||
Polkadot(P),
|
||||
/// Head data returned was not for our parachain.
|
||||
InvalidHeadData,
|
||||
}
|
||||
@@ -68,38 +68,37 @@ pub trait PolkadotClient: Clone {
|
||||
type Error: std::fmt::Debug + Send;
|
||||
|
||||
/// A stream that yields updates to the parachain head.
|
||||
type HeadUpdates: Stream<Item=HeadUpdate, Error=Self::Error> + Send;
|
||||
type HeadUpdates: Stream<Item = HeadUpdate> + Send;
|
||||
/// A stream that yields finalized head-data for a certain parachain.
|
||||
type Finalized: Stream<Item=Vec<u8>, Error=Self::Error> + Send;
|
||||
type Finalized: Stream<Item = Vec<u8>> + Send;
|
||||
|
||||
/// Get a stream of head updates.
|
||||
fn head_updates(&self, para_id: ParaId) -> Self::HeadUpdates;
|
||||
fn head_updates(&self, para_id: ParaId) -> ClientResult<Self::HeadUpdates>;
|
||||
/// Get a stream of finalized heads.
|
||||
fn finalized_heads(&self, para_id: ParaId) -> Self::Finalized;
|
||||
fn finalized_heads(&self, para_id: ParaId) -> ClientResult<Self::Finalized>;
|
||||
}
|
||||
|
||||
/// Spawns a future that follows the Polkadot relay chain for the given parachain.
|
||||
pub fn follow_polkadot<'a, L: 'a, P: 'a>(para_id: ParaId, local: Arc<L>, polkadot: P)
|
||||
-> impl Future<Item=(),Error=()> + Send + 'a
|
||||
-> ClientResult<impl Future<Output = ()> + Send + 'a>
|
||||
where
|
||||
L: LocalClient + Send + Sync,
|
||||
P: PolkadotClient + Send + Sync,
|
||||
{
|
||||
let head_updates = polkadot.head_updates(para_id);
|
||||
let finalized_heads = polkadot.finalized_heads(para_id);
|
||||
let head_updates = polkadot.head_updates(para_id)?;
|
||||
let finalized_heads = polkadot.finalized_heads(para_id)?;
|
||||
|
||||
let follow_best = {
|
||||
let local = local.clone();
|
||||
|
||||
head_updates
|
||||
.map_err(Error::Polkadot)
|
||||
.and_then(|update| -> Result<Option<<L::Block as BlockT>::Header>, _> {
|
||||
Decode::decode(&mut &update.head_data[..]).ok_or_else(|| Error::InvalidHeadData)
|
||||
.map(|update| {
|
||||
<Option<<L::Block as BlockT>::Header>>::decode(&mut &update.head_data[..])
|
||||
.map_err(|_| Error::InvalidHeadData)
|
||||
})
|
||||
.filter_map(|h| h)
|
||||
.for_each(move |p_head| {
|
||||
let _synced = local.mark_best(p_head.hash()).map_err(Error::Client)?;
|
||||
Ok(())
|
||||
.try_filter_map(|h| future::ready(Ok(h)))
|
||||
.try_for_each(move |p_head| {
|
||||
future::ready(local.mark_best(p_head.hash()).map_err(Error::Client).map(|_| ()))
|
||||
})
|
||||
};
|
||||
|
||||
@@ -107,20 +106,21 @@ pub fn follow_polkadot<'a, L: 'a, P: 'a>(para_id: ParaId, local: Arc<L>, polkado
|
||||
let local = local.clone();
|
||||
|
||||
finalized_heads
|
||||
.map_err(Error::Polkadot)
|
||||
.and_then(|head_data| -> Result<Option<<L::Block as BlockT>::Header>, _> {
|
||||
Decode::decode(&mut &head_data[..]).ok_or_else(|| Error::InvalidHeadData)
|
||||
.map(|head_data| {
|
||||
<Option<<L::Block as BlockT>::Header>>::decode(&mut &head_data[..])
|
||||
.map_err(|_| Error::InvalidHeadData)
|
||||
})
|
||||
.filter_map(|h| h)
|
||||
.for_each(move |p_head| {
|
||||
let _synced = local.finalize(p_head.hash()).map_err(Error::Client)?;
|
||||
Ok(())
|
||||
.try_filter_map(|h| future::ready(Ok(h)))
|
||||
.try_for_each(move |p_head| {
|
||||
future::ready(local.finalize(p_head.hash()).map_err(Error::Client).map(|_| ()))
|
||||
})
|
||||
};
|
||||
|
||||
follow_best.join(follow_finalized)
|
||||
.map_err(|e| warn!("Could not follow relay-chain: {:?}", e))
|
||||
.map(|((), ())| ())
|
||||
Ok(
|
||||
future::try_join(follow_best, follow_finalized)
|
||||
.map_err(|e| warn!("Could not follow relay-chain: {:?}", e))
|
||||
.map(|_| ())
|
||||
)
|
||||
}
|
||||
|
||||
impl<B, E, Block, RA> LocalClient for Client<B, E, Block, RA> where
|
||||
@@ -168,41 +168,45 @@ impl<B, E, RA> PolkadotClient for Arc<Client<B, E, PBlock, RA>> where
|
||||
{
|
||||
type Error = ClientError;
|
||||
|
||||
type HeadUpdates = Box<dyn Stream<Item=HeadUpdate, Error=Self::Error> + Send>;
|
||||
type Finalized = Box<dyn Stream<Item=Vec<u8>, Error=Self::Error> + Send>;
|
||||
type HeadUpdates = Box<dyn Stream<Item=HeadUpdate> + Send + Unpin>;
|
||||
type Finalized = Box<dyn Stream<Item=Vec<u8>> + Send + Unpin>;
|
||||
|
||||
fn head_updates(&self, para_id: ParaId) -> Self::HeadUpdates {
|
||||
fn head_updates(&self, para_id: ParaId) -> ClientResult<Self::HeadUpdates> {
|
||||
let parachain_key = parachain_key(para_id);
|
||||
let stream = stream::once(self.storage_changes_notification_stream(Some(&[parachain_key.clone()]), None))
|
||||
.map(|s| s.map_err(|()| panic!("unbounded receivers never yield errors; qed")))
|
||||
.flatten();
|
||||
let stream = self.storage_changes_notification_stream(Some(&[parachain_key.clone()]), None)?;
|
||||
|
||||
let s = stream.filter_map(move |(hash, changes)| {
|
||||
let head_data = changes.iter()
|
||||
.filter_map(|(_, k, v)| if k == ¶chain_key { Some(v) } else { None })
|
||||
.next();
|
||||
|
||||
match head_data {
|
||||
let res = match head_data {
|
||||
Some(Some(head_data)) => Some(HeadUpdate {
|
||||
relay_hash: hash,
|
||||
head_data: head_data.0.clone(),
|
||||
}),
|
||||
Some(None) | None => None,
|
||||
}
|
||||
};
|
||||
|
||||
future::ready(res)
|
||||
});
|
||||
|
||||
Box::new(s)
|
||||
Ok(Box::new(s))
|
||||
}
|
||||
|
||||
fn finalized_heads(&self, para_id: ParaId) -> Self::Finalized {
|
||||
fn finalized_heads(&self, para_id: ParaId) -> ClientResult<Self::Finalized> {
|
||||
let polkadot = self.clone();
|
||||
let parachain_key = parachain_key(para_id);
|
||||
|
||||
let s = self.finality_notification_stream()
|
||||
.map_err(|()| panic!("unbounded receivers never yield errors; qed"))
|
||||
.and_then(move |n| polkadot.storage(&BlockId::hash(n.hash), ¶chain_key))
|
||||
.filter_map(|d| d.map(|d| d.0));
|
||||
.filter_map(move |n|
|
||||
future::ready(
|
||||
polkadot.storage(&BlockId::hash(n.hash), ¶chain_key)
|
||||
.ok()
|
||||
.and_then(|d| d.map(|d| d.0)),
|
||||
),
|
||||
);
|
||||
|
||||
Box::new(s)
|
||||
Ok(Box::new(s))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,17 +5,17 @@ authors = ["Parity Technologies <admin@parity.io>"]
|
||||
edition = "2018"
|
||||
|
||||
[dependencies]
|
||||
codec = { package = "parity-codec", version = "4.1.1", default-features = false, features = [ "derive" ] }
|
||||
codec = { package = "parity-scale-codec", version = "1.0.5", default-features = false, features = [ "derive" ] }
|
||||
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" }
|
||||
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" }
|
||||
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" }
|
||||
memory-db = { version = "0.14.0", default-features = false }
|
||||
hash-db = { version = "0.14.0", default-features = false }
|
||||
trie-db = { version = "0.14.0", default-features = false }
|
||||
hashbrown = "0.5.0"
|
||||
memory-db = { version = "0.15.2", default-features = false }
|
||||
hash-db = { version = "0.15.2", default-features = false }
|
||||
trie-db = { version = "0.15.2", default-features = false }
|
||||
hashbrown = "0.6.0"
|
||||
|
||||
[dev-dependencies]
|
||||
keyring = { package = "substrate-keyring", git = "https://github.com/paritytech/substrate", branch = "bkchr-cumulus-branch" }
|
||||
@@ -37,7 +37,3 @@ std = [
|
||||
"trie-db/std",
|
||||
"substrate-trie/std",
|
||||
]
|
||||
no_std = [
|
||||
"hashbrown/nightly",
|
||||
"rio/wasm-nice-panic-message",
|
||||
]
|
||||
|
||||
@@ -21,12 +21,13 @@ use runtime_primitives::traits::{
|
||||
Block as BlockT, Header as HeaderT, Hash as HashT
|
||||
};
|
||||
use executive::ExecuteBlock;
|
||||
use primitives::{Blake2Hasher, H256};
|
||||
|
||||
use substrate_trie::{MemoryDB, read_trie_value, delta_trie_root};
|
||||
use substrate_trie::{MemoryDB, read_trie_value, delta_trie_root, Layout};
|
||||
|
||||
use rstd::{slice, ptr, cmp, vec::Vec, boxed::Box, mem};
|
||||
|
||||
use hash_db::HashDB;
|
||||
use hash_db::{HashDB, EMPTY_PREFIX};
|
||||
|
||||
static mut STORAGE: Option<Box<dyn Storage>> = None;
|
||||
/// The message to use as expect message while accessing the `STORAGE`.
|
||||
@@ -55,7 +56,7 @@ trait Storage {
|
||||
/// Validate a given parachain block on a validator.
|
||||
#[cfg(not(feature = "std"))]
|
||||
#[doc(hidden)]
|
||||
pub fn validate_block<B: BlockT, E: ExecuteBlock<B>>(
|
||||
pub fn validate_block<B: BlockT<Hash = H256>, E: ExecuteBlock<B>>(
|
||||
mut arguments: &[u8],
|
||||
) {
|
||||
use codec::Decode;
|
||||
@@ -90,12 +91,12 @@ pub fn validate_block<B: BlockT, E: ExecuteBlock<B>>(
|
||||
/// The storage implementation used when validating a block that is using the
|
||||
/// witness data as source.
|
||||
struct WitnessStorage<B: BlockT> {
|
||||
witness_data: MemoryDB<<HashingOf<B> as HashT>::Hasher>,
|
||||
witness_data: MemoryDB<Blake2Hasher>,
|
||||
overlay: hashbrown::HashMap<Vec<u8>, Option<Vec<u8>>>,
|
||||
storage_root: B::Hash,
|
||||
}
|
||||
|
||||
impl<B: BlockT> WitnessStorage<B> {
|
||||
impl<B: BlockT<Hash = H256>> WitnessStorage<B> {
|
||||
/// Initialize from the given witness data and storage root.
|
||||
///
|
||||
/// Returns an error if given storage root was not found in the witness data.
|
||||
@@ -104,9 +105,9 @@ impl<B: BlockT> WitnessStorage<B> {
|
||||
storage_root: B::Hash,
|
||||
) -> Result<Self, &'static str> {
|
||||
let mut db = MemoryDB::default();
|
||||
data.into_iter().for_each(|i| { db.insert(&[], &i); });
|
||||
data.into_iter().for_each(|i| { db.insert(EMPTY_PREFIX, &i); });
|
||||
|
||||
if !db.contains(&storage_root, &[]) {
|
||||
if !db.contains(&storage_root, EMPTY_PREFIX) {
|
||||
return Err("Witness data does not contain given storage root.")
|
||||
}
|
||||
|
||||
@@ -118,10 +119,10 @@ impl<B: BlockT> WitnessStorage<B> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<B: BlockT> Storage for WitnessStorage<B> {
|
||||
impl<B: BlockT<Hash = H256>> Storage for WitnessStorage<B> {
|
||||
fn get(&self, key: &[u8]) -> Option<Vec<u8>> {
|
||||
self.overlay.get(key).cloned().or_else(|| {
|
||||
read_trie_value(
|
||||
read_trie_value::<Layout<Blake2Hasher>, _>(
|
||||
&self.witness_data,
|
||||
&self.storage_root,
|
||||
key,
|
||||
@@ -138,7 +139,7 @@ impl<B: BlockT> Storage for WitnessStorage<B> {
|
||||
}
|
||||
|
||||
fn storage_root(&mut self) -> [u8; STORAGE_ROOT_LEN] {
|
||||
let root = match delta_trie_root(
|
||||
let root = match delta_trie_root::<Layout<Blake2Hasher>, _, _, _, _>(
|
||||
&mut self.witness_data,
|
||||
self.storage_root.clone(),
|
||||
self.overlay.drain()
|
||||
@@ -230,4 +231,4 @@ unsafe fn ext_storage_root(result: *mut u8) {
|
||||
let res = STORAGE.as_mut().expect(STORAGE_SET_EXPECT).storage_root();
|
||||
let result = slice::from_raw_parts_mut(result, STORAGE_ROOT_LEN);
|
||||
result.copy_from_slice(&res);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,3 +9,6 @@ test-client = { package = "substrate-test-client", git = "https://github.com/par
|
||||
runtime = { package = "cumulus-test-runtime", path = "../runtime" }
|
||||
runtime_primitives = { package = "sr-primitives", git = "https://github.com/paritytech/substrate", branch = "bkchr-cumulus-branch" }
|
||||
primitives = { package = "substrate-primitives", git = "https://github.com/paritytech/substrate", branch = "bkchr-cumulus-branch" }
|
||||
keyring = { package = "substrate-keyring", git = "https://github.com/paritytech/substrate", branch = "bkchr-cumulus-branch" }
|
||||
codec = { package = "parity-scale-codec", version = "1.0.5", default-features = false, features = [ "derive" ] }
|
||||
|
||||
|
||||
@@ -20,7 +20,8 @@ pub use test_client::*;
|
||||
pub use runtime;
|
||||
use runtime::{Block, genesismap::{GenesisConfig, additional_storage_with_genesis}};
|
||||
use runtime_primitives::traits::{Hash as HashT, Header as HeaderT, Block as BlockT};
|
||||
use primitives::storage::well_known_keys;
|
||||
use primitives::{storage::well_known_keys, sr25519};
|
||||
use keyring::{Sr25519Keyring, AccountKeyring};
|
||||
|
||||
mod local_executor {
|
||||
use test_client::executor::native_executor_instance;
|
||||
@@ -28,7 +29,6 @@ mod local_executor {
|
||||
pub LocalExecutor,
|
||||
runtime::api::dispatch,
|
||||
runtime::native_version,
|
||||
runtime::WASM_BINARY
|
||||
);
|
||||
}
|
||||
|
||||
@@ -58,16 +58,23 @@ pub struct GenesisParameters {
|
||||
|
||||
impl test_client::GenesisInit for GenesisParameters {
|
||||
fn genesis_storage(&self) -> (StorageOverlay, ChildrenStorageOverlay) {
|
||||
use codec::Encode;
|
||||
let mut storage = genesis_config(self.support_changes_trie).genesis_map();
|
||||
storage.insert(well_known_keys::CODE.to_vec(), runtime::WASM_BINARY.to_vec());
|
||||
storage.0.insert(well_known_keys::CODE.to_vec(), runtime::WASM_BINARY.to_vec());
|
||||
|
||||
let state_root = <<<Block as BlockT>::Header as HeaderT>::Hashing as HashT>::trie_root(
|
||||
storage.clone().into_iter()
|
||||
let child_roots = storage.1.iter().map(|(sk, child_map)| {
|
||||
let state_root = <<<runtime::Block as BlockT>::Header as HeaderT>::Hashing as HashT>::trie_root(
|
||||
child_map.clone().into_iter().collect()
|
||||
);
|
||||
(sk.clone(), state_root.encode())
|
||||
});
|
||||
let state_root = <<<runtime::Block as BlockT>::Header as HeaderT>::Hashing as HashT>::trie_root(
|
||||
storage.0.clone().into_iter().chain(child_roots).collect()
|
||||
);
|
||||
let block: runtime::Block = client::genesis::construct_genesis_block(state_root);
|
||||
storage.extend(additional_storage_with_genesis(&block));
|
||||
storage.0.extend(additional_storage_with_genesis(&block));
|
||||
|
||||
(storage, Default::default())
|
||||
storage
|
||||
}
|
||||
}
|
||||
|
||||
@@ -109,15 +116,21 @@ impl DefaultTestClientBuilderExt for TestClientBuilder {
|
||||
}
|
||||
|
||||
fn genesis_config(support_changes_trie: bool) -> GenesisConfig {
|
||||
GenesisConfig::new(support_changes_trie, vec![
|
||||
AuthorityKeyring::Alice.into(),
|
||||
AuthorityKeyring::Bob.into(),
|
||||
AuthorityKeyring::Charlie.into(),
|
||||
], vec![
|
||||
AccountKeyring::Alice.into(),
|
||||
AccountKeyring::Bob.into(),
|
||||
AccountKeyring::Charlie.into(),
|
||||
],
|
||||
1000
|
||||
GenesisConfig::new(
|
||||
support_changes_trie,
|
||||
vec![
|
||||
sr25519::Public::from(Sr25519Keyring::Alice).into(),
|
||||
sr25519::Public::from(Sr25519Keyring::Bob).into(),
|
||||
sr25519::Public::from(Sr25519Keyring::Charlie).into(),
|
||||
],
|
||||
vec![
|
||||
AccountKeyring::Alice.into(),
|
||||
AccountKeyring::Bob.into(),
|
||||
AccountKeyring::Charlie.into(),
|
||||
],
|
||||
1000,
|
||||
None,
|
||||
Default::default(),
|
||||
Default::default(),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,7 +18,3 @@ std = [
|
||||
"runtime/std",
|
||||
"substrate-test-runtime/std",
|
||||
]
|
||||
no_std = [
|
||||
"runtime/no_std",
|
||||
"substrate-test-runtime/no_std",
|
||||
]
|
||||
|
||||
@@ -17,5 +17,5 @@
|
||||
use wasm_builder_runner::{build_current_project, WasmBuilderSource};
|
||||
|
||||
fn main() {
|
||||
build_current_project("wasm_binary.rs", WasmBuilderSource::Crates("1.0.4"));
|
||||
}
|
||||
build_current_project("wasm_binary.rs", WasmBuilderSource::Crates("1.0.7"));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user