Commit af0d87af authored by Kian Paimani's avatar Kian Paimani Committed by Gavin Wood
Browse files

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: asynchronous rob's avatarRobert 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
parent 7c6390fe
Pipeline #48863 passed with stages
in 50 minutes and 40 seconds
This source diff could not be displayed because it is too large. You can view the blob instead.
...@@ -9,7 +9,7 @@ edition = "2018" ...@@ -9,7 +9,7 @@ edition = "2018"
polkadot-primitives = { path = "../primitives" } polkadot-primitives = { path = "../primitives" }
parking_lot = "0.9.0" parking_lot = "0.9.0"
log = "0.4.6" log = "0.4.6"
parity-codec = "4.1" codec = { package = "parity-scale-codec", version = "~1.0.0", default-features = false, features = ["derive"] }
substrate-primitives = { git = "https://github.com/paritytech/substrate", branch = "polkadot-master" } substrate-primitives = { git = "https://github.com/paritytech/substrate", branch = "polkadot-master" }
kvdb = { git = "https://github.com/paritytech/parity-common", rev="616b40150ded71f57f650067fcbc5c99d7c343e6" } kvdb = { git = "https://github.com/paritytech/parity-common", rev="616b40150ded71f57f650067fcbc5c99d7c343e6" }
kvdb-rocksdb = { git = "https://github.com/paritytech/parity-common", rev="616b40150ded71f57f650067fcbc5c99d7c343e6" } kvdb-rocksdb = { git = "https://github.com/paritytech/parity-common", rev="616b40150ded71f57f650067fcbc5c99d7c343e6" }
......
...@@ -16,7 +16,7 @@ ...@@ -16,7 +16,7 @@
//! Persistent database for parachain data. //! Persistent database for parachain data.
use parity_codec::{Encode, Decode}; use codec::{Encode, Decode};
use kvdb::{KeyValueDB, DBTransaction}; use kvdb::{KeyValueDB, DBTransaction};
use kvdb_rocksdb::{Database, DatabaseConfig}; use kvdb_rocksdb::{Database, DatabaseConfig};
use polkadot_primitives::Hash; use polkadot_primitives::Hash;
......
...@@ -26,15 +26,15 @@ pub enum ChainSpec { ...@@ -26,15 +26,15 @@ pub enum ChainSpec {
Development, Development,
/// Whatever the current runtime is, with simple Alice/Bob auths. /// Whatever the current runtime is, with simple Alice/Bob auths.
LocalTestnet, LocalTestnet,
/// The PoC-3 era testnet. /// The Kusama network.
Alexander, Kusama,
/// Whatever the current runtime is with the "global testnet" defaults. /// Whatever the current runtime is with the "global testnet" defaults.
StagingTestnet, StagingTestnet,
} }
impl Default for ChainSpec { impl Default for ChainSpec {
fn default() -> Self { fn default() -> Self {
ChainSpec::Alexander ChainSpec::Kusama
} }
} }
...@@ -42,7 +42,7 @@ impl Default for ChainSpec { ...@@ -42,7 +42,7 @@ impl Default for ChainSpec {
impl ChainSpec { impl ChainSpec {
pub(crate) fn load(self) -> Result<service::ChainSpec, String> { pub(crate) fn load(self) -> Result<service::ChainSpec, String> {
Ok(match self { Ok(match self {
ChainSpec::Alexander => service::chain_spec::poc_3_testnet_config()?, ChainSpec::Kusama => service::chain_spec::kusama_config()?,
ChainSpec::Development => service::chain_spec::development_config(), ChainSpec::Development => service::chain_spec::development_config(),
ChainSpec::LocalTestnet => service::chain_spec::local_testnet_config(), ChainSpec::LocalTestnet => service::chain_spec::local_testnet_config(),
ChainSpec::StagingTestnet => service::chain_spec::staging_testnet_config(), ChainSpec::StagingTestnet => service::chain_spec::staging_testnet_config(),
...@@ -53,7 +53,7 @@ impl ChainSpec { ...@@ -53,7 +53,7 @@ impl ChainSpec {
match s { match s {
"dev" => Some(ChainSpec::Development), "dev" => Some(ChainSpec::Development),
"local" => Some(ChainSpec::LocalTestnet), "local" => Some(ChainSpec::LocalTestnet),
"poc-3" | "alex" | "alexander" => Some(ChainSpec::Alexander), "kusama" => Some(ChainSpec::Kusama),
"staging" => Some(ChainSpec::StagingTestnet), "staging" => Some(ChainSpec::StagingTestnet),
"" => Some(ChainSpec::default()), "" => Some(ChainSpec::default()),
_ => None, _ => None,
......
...@@ -9,11 +9,9 @@ edition = "2018" ...@@ -9,11 +9,9 @@ edition = "2018"
futures = "0.1.17" futures = "0.1.17"
futures03 = { package = "futures-preview", version = "0.3.0-alpha.17", features = ["compat"] } futures03 = { package = "futures-preview", version = "0.3.0-alpha.17", features = ["compat"] }
client = { package = "substrate-client", git = "https://github.com/paritytech/substrate", branch = "polkadot-master" } client = { package = "substrate-client", git = "https://github.com/paritytech/substrate", branch = "polkadot-master" }
parity-codec = "4.1"
primitives = { package = "substrate-primitives", git = "https://github.com/paritytech/substrate", branch = "polkadot-master" } primitives = { package = "substrate-primitives", git = "https://github.com/paritytech/substrate", branch = "polkadot-master" }
substrate-network = { git = "https://github.com/paritytech/substrate", branch = "polkadot-master" } substrate-network = { git = "https://github.com/paritytech/substrate", branch = "polkadot-master" }
consensus_common = { package = "substrate-consensus-common", git = "https://github.com/paritytech/substrate", branch = "polkadot-master" } consensus_common = { package = "substrate-consensus-common", git = "https://github.com/paritytech/substrate", branch = "polkadot-master" }
aura = { package = "substrate-consensus-aura", git = "https://github.com/paritytech/substrate", branch = "polkadot-master" }
polkadot-runtime = { path = "../runtime", version = "0.1" } polkadot-runtime = { path = "../runtime", version = "0.1" }
polkadot-primitives = { path = "../primitives", version = "0.1" } polkadot-primitives = { path = "../primitives", version = "0.1" }
polkadot-cli = { path = "../cli" } polkadot-cli = { path = "../cli" }
......
...@@ -53,12 +53,12 @@ use futures::{future, Stream, Future, IntoFuture}; ...@@ -53,12 +53,12 @@ use futures::{future, Stream, Future, IntoFuture};
use futures03::{TryStreamExt as _, StreamExt as _}; use futures03::{TryStreamExt as _, StreamExt as _};
use log::{info, warn}; use log::{info, warn};
use client::BlockchainEvents; use client::BlockchainEvents;
use primitives::{ed25519, Pair}; use primitives::Pair;
use polkadot_primitives::{ use polkadot_primitives::{
BlockId, SessionKey, Hash, Block, BlockId, Hash, Block,
parachain::{ parachain::{
self, BlockData, DutyRoster, HeadData, ConsolidatedIngress, Message, Id as ParaId, Extrinsic, self, BlockData, DutyRoster, HeadData, ConsolidatedIngress, Message, Id as ParaId, Extrinsic,
PoVBlock, Status as ParachainStatus, PoVBlock, Status as ParachainStatus, ValidatorId, CollatorPair,
} }
}; };
use polkadot_cli::{ use polkadot_cli::{
...@@ -69,7 +69,6 @@ use polkadot_network::validation::{SessionParams, ValidationNetwork}; ...@@ -69,7 +69,6 @@ use polkadot_network::validation::{SessionParams, ValidationNetwork};
use polkadot_network::NetworkService; use polkadot_network::NetworkService;
use tokio::timer::Timeout; use tokio::timer::Timeout;
use consensus_common::SelectChain; use consensus_common::SelectChain;
use aura::AuraApi;
pub use polkadot_cli::VersionInfo; pub use polkadot_cli::VersionInfo;
pub use polkadot_network::validation::Incoming; pub use polkadot_network::validation::Incoming;
...@@ -177,7 +176,7 @@ pub fn collate<'a, R, P>( ...@@ -177,7 +176,7 @@ pub fn collate<'a, R, P>(
parachain_status: ParachainStatus, parachain_status: ParachainStatus,
relay_context: R, relay_context: R,
para_context: P, para_context: P,
key: Arc<ed25519::Pair>, key: Arc<CollatorPair>,
) )
-> impl Future<Item=parachain::Collation, Error=Error<R::Error>> + 'a -> impl Future<Item=parachain::Collation, Error=Error<R::Error>> + 'a
where where
...@@ -230,7 +229,7 @@ pub fn collate<'a, R, P>( ...@@ -230,7 +229,7 @@ pub fn collate<'a, R, P>(
struct ApiContext<P, E> { struct ApiContext<P, E> {
network: Arc<ValidationNetwork<P, E, NetworkService, TaskExecutor>>, network: Arc<ValidationNetwork<P, E, NetworkService, TaskExecutor>>,
parent_hash: Hash, parent_hash: Hash,
authorities: Vec<SessionKey>, validators: Vec<ValidatorId>,
} }
impl<P: 'static, E: 'static> RelayChainContext for ApiContext<P, E> where impl<P: 'static, E: 'static> RelayChainContext for ApiContext<P, E> where
...@@ -248,7 +247,7 @@ impl<P: 'static, E: 'static> RelayChainContext for ApiContext<P, E> where ...@@ -248,7 +247,7 @@ impl<P: 'static, E: 'static> RelayChainContext for ApiContext<P, E> where
let _session = self.network.instantiate_session(SessionParams { let _session = self.network.instantiate_session(SessionParams {
local_session_key: None, local_session_key: None,
parent_hash: self.parent_hash, parent_hash: self.parent_hash,
authorities: self.authorities.clone(), authorities: self.validators.clone(),
}).map_err(|e| format!("unable to instantiate validation session: {:?}", e)); }).map_err(|e| format!("unable to instantiate validation session: {:?}", e));
Box::new(future::ok(ConsolidatedIngress(Vec::new()))) Box::new(future::ok(ConsolidatedIngress(Vec::new())))
...@@ -259,7 +258,7 @@ struct CollationNode<P, E> { ...@@ -259,7 +258,7 @@ struct CollationNode<P, E> {
build_parachain_context: P, build_parachain_context: P,
exit: E, exit: E,
para_id: ParaId, para_id: ParaId,
key: Arc<ed25519::Pair>, key: Arc<CollatorPair>,
} }
impl<P, E> IntoExit for CollationNode<P, E> where impl<P, E> IntoExit for CollationNode<P, E> where
...@@ -364,18 +363,18 @@ impl<P, E> Worker for CollationNode<P, E> where ...@@ -364,18 +363,18 @@ impl<P, E> Worker for CollationNode<P, E> where
None => return future::Either::A(future::ok(())), None => return future::Either::A(future::ok(())),
}; };
let authorities = try_fr!(api.authorities(&id)); let validators = try_fr!(api.validators(&id));
let targets = compute_targets( let targets = compute_targets(
para_id, para_id,
authorities.as_slice(), validators.as_slice(),
try_fr!(api.duty_roster(&id)), try_fr!(api.duty_roster(&id)),
); );
let context = ApiContext { let context = ApiContext {
network: validation_network, network: validation_network,
parent_hash: relay_parent, parent_hash: relay_parent,
authorities, validators,
}; };
let collation_work = collate( let collation_work = collate(
...@@ -414,7 +413,7 @@ impl<P, E> Worker for CollationNode<P, E> where ...@@ -414,7 +413,7 @@ impl<P, E> Worker for CollationNode<P, E> where
} }
} }
fn compute_targets(para_id: ParaId, session_keys: &[SessionKey], roster: DutyRoster) -> HashSet<SessionKey> { fn compute_targets(para_id: ParaId, session_keys: &[ValidatorId], roster: DutyRoster) -> HashSet<ValidatorId> {
use polkadot_primitives::parachain::Chain; use polkadot_primitives::parachain::Chain;
roster.validator_duty.iter().enumerate() roster.validator_duty.iter().enumerate()
...@@ -433,7 +432,7 @@ pub fn run_collator<P, E>( ...@@ -433,7 +432,7 @@ pub fn run_collator<P, E>(
build_parachain_context: P, build_parachain_context: P,
para_id: ParaId, para_id: ParaId,
exit: E, exit: E,
key: Arc<ed25519::Pair>, key: Arc<CollatorPair>,
version: VersionInfo, version: VersionInfo,
) -> polkadot_cli::error::Result<()> where ) -> polkadot_cli::error::Result<()> where
P: BuildParachainContext + Send + 'static, P: BuildParachainContext + Send + 'static,
...@@ -450,7 +449,7 @@ pub fn run_collator<P, E>( ...@@ -450,7 +449,7 @@ pub fn run_collator<P, E>(
mod tests { mod tests {
use std::collections::HashMap; use std::collections::HashMap;
use polkadot_primitives::parachain::{OutgoingMessage, FeeSchedule}; use polkadot_primitives::parachain::{OutgoingMessage, FeeSchedule};
use keyring::Ed25519Keyring; use keyring::Sr25519Keyring;
use super::*; use super::*;
#[derive(Default, Clone)] #[derive(Default, Clone)]
...@@ -540,7 +539,7 @@ mod tests { ...@@ -540,7 +539,7 @@ mod tests {
}, },
context.clone(), context.clone(),
DummyParachainContext, DummyParachainContext,
Ed25519Keyring::Alice.pair().into(), Arc::new(Sr25519Keyring::Alice.pair().into()),
).wait().unwrap(); ).wait().unwrap();
// ascending order by root. // ascending order by root.
......
...@@ -7,6 +7,6 @@ edition = "2018" ...@@ -7,6 +7,6 @@ edition = "2018"
[dependencies] [dependencies]
primitives = { package = "polkadot-primitives", path = "../primitives" } primitives = { package = "polkadot-primitives", path = "../primitives" }
reed_solomon = { package = "reed-solomon-erasure", git = "https://github.com/paritytech/reed-solomon-erasure" } reed_solomon = { package = "reed-solomon-erasure", git = "https://github.com/paritytech/reed-solomon-erasure" }
parity-codec = "4.1" codec = { package = "parity-scale-codec", version = "~1.0.0", default-features = false, features = ["derive"] }
substrate-primitives = { git = "https://github.com/paritytech/substrate", branch = "polkadot-master" } substrate-primitives = { git = "https://github.com/paritytech/substrate", branch = "polkadot-master" }
trie = { package = "substrate-trie", git = "https://github.com/paritytech/substrate", branch = "polkadot-master" } trie = { package = "substrate-trie", git = "https://github.com/paritytech/substrate", branch = "polkadot-master" }
...@@ -24,12 +24,12 @@ ...@@ -24,12 +24,12 @@
//! f is the maximum number of faulty validators in the system. //! f is the maximum number of faulty validators in the system.
//! The data is coded so any f+1 chunks can be used to reconstruct the full data. //! The data is coded so any f+1 chunks can be used to reconstruct the full data.
use parity_codec::{Encode, Decode}; use codec::{Encode, Decode};
use reed_solomon::galois_16::{self, ReedSolomon}; use reed_solomon::galois_16::{self, ReedSolomon};
use primitives::{Hash as H256, BlakeTwo256, HashT}; use primitives::{Hash as H256, BlakeTwo256, HashT};
use primitives::parachain::{BlockData, Extrinsic}; use primitives::parachain::{BlockData, Extrinsic};
use substrate_primitives::Blake2Hasher; use substrate_primitives::Blake2Hasher;
use trie::{MemoryDB, Trie, TrieMut, TrieDB, TrieDBMut}; use trie::{EMPTY_PREFIX, MemoryDB, Trie, TrieMut, trie_types::{TrieDBMut, TrieDB}};
use self::wrapped_shard::WrappedShard; use self::wrapped_shard::WrappedShard;
...@@ -187,13 +187,14 @@ pub fn reconstruct<'a, I: 'a>(n_validators: usize, chunks: I) ...@@ -187,13 +187,14 @@ pub fn reconstruct<'a, I: 'a>(n_validators: usize, chunks: I)
// lazily decode from the data shards. // lazily decode from the data shards.
Decode::decode(&mut ShardInput { Decode::decode(&mut ShardInput {
remaining_len: shard_len.map(|s| s * params.data_shards).unwrap_or(0),
cur_shard: None, cur_shard: None,
shards: shards.iter() shards: shards.iter()
.map(|x| x.as_ref()) .map(|x| x.as_ref())
.take(params.data_shards) .take(params.data_shards)
.map(|x| x.expect("all data shards have been recovered; qed")) .map(|x| x.expect("all data shards have been recovered; qed"))
.map(|x| x.as_ref()), .map(|x| x.as_ref()),
}).ok_or_else(|| Error::BadPayload) }).or_else(|_| Err(Error::BadPayload))
} }
/// An iterator that yields merkle branches and chunk data for all chunks to /// An iterator that yields merkle branches and chunk data for all chunks to
...@@ -269,7 +270,7 @@ pub fn branches<'a>(chunks: Vec<&'a [u8]>) -> Branches<'a> { ...@@ -269,7 +270,7 @@ pub fn branches<'a>(chunks: Vec<&'a [u8]>) -> Branches<'a> {
pub fn branch_hash(root: &H256, branch_nodes: &[Vec<u8>], index: usize) -> Result<H256, Error> { pub fn branch_hash(root: &H256, branch_nodes: &[Vec<u8>], index: usize) -> Result<H256, Error> {
let mut trie_storage: MemoryDB<Blake2Hasher> = MemoryDB::default(); let mut trie_storage: MemoryDB<Blake2Hasher> = MemoryDB::default();
for node in branch_nodes.iter() { for node in branch_nodes.iter() {
(&mut trie_storage as &mut trie::HashDB<_>).insert(&[], node.as_slice()); (&mut trie_storage as &mut trie::HashDB<_>).insert(EMPTY_PREFIX, node.as_slice());
} }
let trie = TrieDB::new(&trie_storage, &root).map_err(|_| Error::InvalidBranchProof)?; let trie = TrieDB::new(&trie_storage, &root).map_err(|_| Error::InvalidBranchProof)?;
...@@ -278,21 +279,26 @@ pub fn branch_hash(root: &H256, branch_nodes: &[Vec<u8>], index: usize) -> Resul ...@@ -278,21 +279,26 @@ pub fn branch_hash(root: &H256, branch_nodes: &[Vec<u8>], index: usize) -> Resul
); );
match res { match res {
Ok(Some(Some(hash))) => Ok(hash), Ok(Some(Ok(hash))) => Ok(hash),
Ok(Some(None)) => Err(Error::InvalidBranchProof), // hash failed to decode Ok(Some(Err(_))) => Err(Error::InvalidBranchProof), // hash failed to decode
Ok(None) => Err(Error::BranchOutOfBounds), Ok(None) => Err(Error::BranchOutOfBounds),
Err(_) => Err(Error::InvalidBranchProof), Err(_) => Err(Error::InvalidBranchProof),
} }
} }
// input for `parity_codec` which draws data from the data shards // input for `codec` which draws data from the data shards
struct ShardInput<'a, I> { struct ShardInput<'a, I> {
remaining_len: usize,
shards: I, shards: I,
cur_shard: Option<(&'a [u8], usize)>, cur_shard: Option<(&'a [u8], usize)>,
} }
impl<'a, I: Iterator<Item=&'a [u8]>> parity_codec::Input for ShardInput<'a, I> { impl<'a, I: Iterator<Item=&'a [u8]>> codec::Input for ShardInput<'a, I> {
fn read(&mut self, into: &mut [u8]) -> usize { fn remaining_len(&mut self) -> Result<Option<usize>, codec::Error> {
Ok(Some(self.remaining_len))
}
fn read(&mut self, into: &mut [u8]) -> Result<(), codec::Error> {
let mut read_bytes = 0; let mut read_bytes = 0;
loop { loop {
...@@ -320,7 +326,12 @@ impl<'a, I: Iterator<Item=&'a [u8]>> parity_codec::Input for ShardInput<'a, I> { ...@@ -320,7 +326,12 @@ impl<'a, I: Iterator<Item=&'a [u8]>> parity_codec::Input for ShardInput<'a, I> {
self.cur_shard = Some((active_shard, in_shard)) self.cur_shard = Some((active_shard, in_shard))
} }
read_bytes self.remaining_len -= read_bytes;
if read_bytes == into.len() {
Ok(())
} else {
Err("slice provided too big for input".into())
}
} }
} }
......
...@@ -11,7 +11,7 @@ parking_lot = "0.9.0" ...@@ -11,7 +11,7 @@ parking_lot = "0.9.0"
av_store = { package = "polkadot-availability-store", path = "../availability-store" } av_store = { package = "polkadot-availability-store", path = "../availability-store" }
polkadot-validation = { path = "../validation" } polkadot-validation = { path = "../validation" }
polkadot-primitives = { path = "../primitives" } polkadot-primitives = { path = "../primitives" }
parity-codec = { version = "4.1", features = ["derive"] } codec = { package = "parity-scale-codec", version = "~1.0.0", default-features = false, features = ["derive"] }
substrate-network = { git = "https://github.com/paritytech/substrate", branch = "polkadot-master" } substrate-network = { git = "https://github.com/paritytech/substrate", branch = "polkadot-master" }
substrate-primitives = { git = "https://github.com/paritytech/substrate", branch = "polkadot-master" } substrate-primitives = { git = "https://github.com/paritytech/substrate", branch = "polkadot-master" }
sr-primitives = { git = "https://github.com/paritytech/substrate", branch = "polkadot-master" } sr-primitives = { git = "https://github.com/paritytech/substrate", branch = "polkadot-master" }
......
...@@ -16,7 +16,7 @@ ...@@ -16,7 +16,7 @@
//! Bridge between the network and consensus service for getting collations to it. //! Bridge between the network and consensus service for getting collations to it.
use parity_codec::{Encode, Decode}; use codec::{Encode, Decode};
use polkadot_primitives::Hash; use polkadot_primitives::Hash;
use polkadot_primitives::parachain::{CollatorId, Id as ParaId, Collation}; use polkadot_primitives::parachain::{CollatorId, Id as ParaId, Collation};
use substrate_network::PeerId; use substrate_network::PeerId;
......
...@@ -22,8 +22,8 @@ use substrate_network::consensus_gossip::{ ...@@ -22,8 +22,8 @@ use substrate_network::consensus_gossip::{
ValidatorContext, MessageIntent, ConsensusMessage, ValidatorContext, MessageIntent, ConsensusMessage,
}; };
use polkadot_validation::{GenericStatement, SignedStatement}; use polkadot_validation::{GenericStatement, SignedStatement};
use polkadot_primitives::{Block, Hash, SessionKey, parachain::ValidatorIndex}; use polkadot_primitives::{Block, Hash, parachain::{ValidatorIndex, ValidatorId}};
use parity_codec::{Decode, Encode}; use codec::{Decode, Encode};
use std::collections::{HashMap, HashSet}; use std::collections::{HashMap, HashSet};
use std::sync::Arc; use std::sync::Arc;
...@@ -218,9 +218,9 @@ impl RegisteredMessageValidator { ...@@ -218,9 +218,9 @@ impl RegisteredMessageValidator {
#[derive(Default)] #[derive(Default)]
pub(crate) struct MessageValidationData { pub(crate) struct MessageValidationData {
/// The authorities at a block. /// The authorities at a block.
pub(crate) authorities: Vec<SessionKey>, pub(crate) authorities: Vec<ValidatorId>,
/// Mapping from validator index to `SessionKey`. /// Mapping from validator index to `ValidatorId`.
pub(crate) index_mapping: HashMap<ValidatorIndex, SessionKey>, pub(crate) index_mapping: HashMap<ValidatorIndex, ValidatorId>,
} }
impl MessageValidationData { impl MessageValidationData {
...@@ -481,15 +481,15 @@ impl<O: KnownOracle + ?Sized> network_gossip::Validator<Block> for MessageValida ...@@ -481,15 +481,15 @@ impl<O: KnownOracle + ?Sized> network_gossip::Validator<Block> for MessageValida
-> GossipValidationResult<Hash> -> GossipValidationResult<Hash>
{ {
let (res, cost_benefit) = match GossipMessage::decode(&mut data) { let (res, cost_benefit) = match GossipMessage::decode(&mut data) {
None => (GossipValidationResult::Discard, cost::MALFORMED_MESSAGE), Err(_) => (GossipValidationResult::Discard, cost::MALFORMED_MESSAGE),
Some(GossipMessage::Neighbor(VersionedNeighborPacket::V1(packet))) => { Ok(GossipMessage::Neighbor(VersionedNeighborPacket::V1(packet))) => {
let (res, cb, topics) = self.inner.write().validate_neighbor_packet(sender, packet); let (res, cb, topics) = self.inner.write().validate_neighbor_packet(sender, packet);
for new_topic in topics { for new_topic in topics {
context.send_topic(sender, new_topic, false); context.send_topic(sender, new_topic, false);
} }
(res, cb) (res, cb)
} }
Some(GossipMessage::Statement(statement)) => { Ok(GossipMessage::Statement(statement)) => {
let (res, cb) = self.inner.write().validate_statement(statement); let (res, cb) = self.inner.write().validate_statement(statement);
if let GossipValidationResult::ProcessAndKeep(ref topic) = res { if let GossipValidationResult::ProcessAndKeep(ref topic) = res {
context.broadcast_message(topic.clone(), data.to_vec(), false); context.broadcast_message(topic.clone(), data.to_vec(), false);
...@@ -535,7 +535,7 @@ impl<O: KnownOracle + ?Sized> network_gossip::Validator<Block> for MessageValida ...@@ -535,7 +535,7 @@ impl<O: KnownOracle + ?Sized> network_gossip::Validator<Block> for MessageValida
}; };
match GossipMessage::decode(&mut &data[..]) { match GossipMessage::decode(&mut &data[..]) {
Some(GossipMessage::Statement(statement)) => { Ok(GossipMessage::Statement(statement)) => {
let signed = statement.signed_statement; let signed = statement.signed_statement;
match signed.statement { match signed.statement {
...@@ -573,7 +573,7 @@ mod tests { ...@@ -573,7 +573,7 @@ mod tests {
use parking_lot::Mutex; use parking_lot::Mutex;
use polkadot_primitives::parachain::{CandidateReceipt, HeadData}; use polkadot_primitives::parachain::{CandidateReceipt, HeadData};
use substrate_primitives::crypto::UncheckedInto; use substrate_primitives::crypto::UncheckedInto;
use substrate_primitives::ed25519::Signature as Ed25519Signature; use substrate_primitives::sr25519::Signature as Sr25519Signature;
#[derive(PartialEq, Clone, Debug)] #[derive(PartialEq, Clone, Debug)]
enum ContextEvent { enum ContextEvent {
...@@ -669,7 +669,7 @@ mod tests { ...@@ -669,7 +669,7 @@ mod tests {
relay_parent: hash_a, relay_parent: hash_a,
signed_statement: SignedStatement { signed_statement: SignedStatement {
statement: GenericStatement::Candidate(candidate_receipt), statement: GenericStatement::Candidate(candidate_receipt),
signature: Ed25519Signature([255u8; 64]), signature: Sr25519Signature([255u8; 64]).into(),
sender: 1, sender: 1,
} }
}); });
...@@ -786,7 +786,7 @@ mod tests { ...@@ -786,7 +786,7 @@ mod tests {
relay_parent: hash_a, relay_parent: hash_a,
signed_statement: SignedStatement { signed_statement: SignedStatement {
statement: GenericStatement::Valid(c_hash), statement: GenericStatement::Valid(c_hash),
signature: Ed25519Signature([255u8; 64]), signature: Sr25519Signature([255u8; 64]).into(),
sender: 1, sender: 1,
} }
}); });
......
// Copyright 2019 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/>.
//! Data structures and synchronous logic for ICMP message gossip.
use sr_primitives::traits::{BlakeTwo256, Hash as HashT};
use polkadot_primitives::Hash;
use std::collections::{HashMap, HashSet};
use substrate_client::error::Error as ClientError;
use super::{MAX_CHAIN_HEADS, GossipValidationResult, LeavesVec, ChainContext};
/// Construct a topic for a message queue root deterministically.
pub fn queue_topic(queue_root: Hash) -> Hash {
let mut v = queue_root.as_ref().to_vec();
v.extend(b"message_queue");
BlakeTwo256::hash(&v[..])
}