Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Update to latest Substrate master + warning fixes #292

Merged
merged 2 commits into from Jun 20, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
883 changes: 366 additions & 517 deletions Cargo.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion collator/Cargo.toml
Expand Up @@ -10,8 +10,8 @@ futures = "0.1.17"
client = { package = "substrate-client", git = "https://github.com/paritytech/substrate", branch = "polkadot-master" }
parity-codec = "3.0"
primitives = { package = "substrate-primitives", git = "https://github.com/paritytech/substrate", branch = "polkadot-master" }
consensus_authorities = { package = "substrate-consensus-authorities", 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-primitives = { path = "../primitives", version = "0.1" }
polkadot-cli = { path = "../cli" }
Expand Down
8 changes: 4 additions & 4 deletions collator/src/lib.rs
Expand Up @@ -63,8 +63,8 @@ use polkadot_cli::{Worker, IntoExit, ProvideRuntimeApi, TaskExecutor};
use polkadot_network::validation::{ValidationNetwork, SessionParams};
use polkadot_network::NetworkService;
use tokio::timer::Timeout;
use consensus_authorities::AuthoritiesApi;
use consensus_common::SelectChain;
use aura::AuraApi;

pub use polkadot_cli::VersionInfo;
pub use polkadot_network::validation::Incoming;
Expand Down Expand Up @@ -181,7 +181,7 @@ impl<P: 'static, E: 'static> RelayChainContext for ApiContext<P, E> where
E: Future<Item=(),Error=()> + Clone + Send + Sync + 'static,
{
type Error = String;
type FutureEgress = Box<Future<Item=ConsolidatedIngress, Error=String> + Send>;
type FutureEgress = Box<dyn Future<Item=ConsolidatedIngress, Error=String> + Send>;

fn unrouted_egress(&self, _id: ParaId) -> Self::FutureEgress {
// TODO: https://github.com/paritytech/polkadot/issues/253
Expand Down Expand Up @@ -218,7 +218,7 @@ impl<P, E> Worker for CollationNode<P, E> where
P: ParachainContext + Send + 'static,
E: Future<Item=(),Error=()> + Clone + Send + Sync + 'static
{
type Work = Box<Future<Item=(),Error=()> + Send>;
type Work = Box<dyn Future<Item=(),Error=()> + Send>;

fn configuration(&self) -> CustomConfiguration {
let mut config = CustomConfiguration::default();
Expand Down Expand Up @@ -399,7 +399,7 @@ mod tests {

impl RelayChainContext for DummyRelayChainContext {
type Error = ();
type FutureEgress = Box<Future<Item=ConsolidatedIngress,Error=()>>;
type FutureEgress = Box<dyn Future<Item=ConsolidatedIngress,Error=()>>;

fn unrouted_egress(&self, para_id: ParaId) -> Self::FutureEgress {
match self.ingress.get(&para_id) {
Expand Down
18 changes: 9 additions & 9 deletions network/src/gossip.rs
Expand Up @@ -158,14 +158,14 @@ pub fn register_validator<O: KnownOracle + 'static>(
/// Create this using `register_validator`.
#[derive(Clone)]
pub struct RegisteredMessageValidator {
inner: Arc<MessageValidator<KnownOracle>>,
inner: Arc<MessageValidator<dyn KnownOracle>>,
}

impl RegisteredMessageValidator {
#[cfg(test)]
pub(crate) fn new_test<O: KnownOracle + 'static>(
oracle: O,
report_handle: Box<Fn(&PeerId, i32) + Send + Sync>,
report_handle: Box<dyn Fn(&PeerId, i32) + Send + Sync>,
) -> Self {
let validator = Arc::new(MessageValidator::new_test(oracle, report_handle));

Expand Down Expand Up @@ -423,15 +423,15 @@ impl<O: ?Sized + KnownOracle> Inner<O> {

/// An unregistered message validator. Register this with `register_validator`.
pub struct MessageValidator<O: ?Sized> {
report_handle: Box<Fn(&PeerId, i32) + Send + Sync>,
report_handle: Box<dyn Fn(&PeerId, i32) + Send + Sync>,
inner: RwLock<Inner<O>>,
}

impl<O: KnownOracle + ?Sized> MessageValidator<O> {
#[cfg(test)]
fn new_test(
oracle: O,
report_handle: Box<Fn(&PeerId, i32) + Send + Sync>,
report_handle: Box<dyn Fn(&PeerId, i32) + Send + Sync>,
) -> Self where O: Sized{
MessageValidator {
report_handle,
Expand All @@ -449,19 +449,19 @@ impl<O: KnownOracle + ?Sized> MessageValidator<O> {
}

impl<O: KnownOracle + ?Sized> network_gossip::Validator<Block> for MessageValidator<O> {
fn new_peer(&self, _context: &mut ValidatorContext<Block>, who: &PeerId, _roles: Roles) {
fn new_peer(&self, _context: &mut dyn ValidatorContext<Block>, who: &PeerId, _roles: Roles) {
let mut inner = self.inner.write();
inner.peers.insert(who.clone(), PeerData {
live: HashMap::new(),
});
}

fn peer_disconnected(&self, _context: &mut ValidatorContext<Block>, who: &PeerId) {
fn peer_disconnected(&self, _context: &mut dyn ValidatorContext<Block>, who: &PeerId) {
let mut inner = self.inner.write();
inner.peers.remove(who);
}

fn validate(&self, context: &mut ValidatorContext<Block>, sender: &PeerId, mut data: &[u8])
fn validate(&self, context: &mut dyn ValidatorContext<Block>, sender: &PeerId, mut data: &[u8])
-> GossipValidationResult<Hash>
{
let (res, cost_benefit) = match GossipMessage::decode(&mut data) {
Expand All @@ -486,7 +486,7 @@ impl<O: KnownOracle + ?Sized> network_gossip::Validator<Block> for MessageValida
res
}

fn message_expired<'a>(&'a self) -> Box<FnMut(Hash, &[u8]) -> bool + 'a> {
fn message_expired<'a>(&'a self) -> Box<dyn FnMut(Hash, &[u8]) -> bool + 'a> {
let inner = self.inner.read();

Box::new(move |topic, _data| {
Expand All @@ -495,7 +495,7 @@ impl<O: KnownOracle + ?Sized> network_gossip::Validator<Block> for MessageValida
})
}

fn message_allowed<'a>(&'a self) -> Box<FnMut(&PeerId, MessageIntent, &Hash, &[u8]) -> bool + 'a> {
fn message_allowed<'a>(&'a self) -> Box<dyn FnMut(&PeerId, MessageIntent, &Hash, &[u8]) -> bool + 'a> {
let mut inner = self.inner.write();
Box::new(move |who, intent, topic, data| {
let &mut Inner { ref mut peers, ref mut our_view, .. } = &mut *inner;
Expand Down
43 changes: 27 additions & 16 deletions network/src/lib.rs
Expand Up @@ -175,7 +175,7 @@ pub enum Message {
Collation(Hash, Collation),
}

fn send_polkadot_message(ctx: &mut Context<Block>, to: PeerId, message: Message) {
fn send_polkadot_message(ctx: &mut dyn Context<Block>, to: PeerId, message: Message) {
trace!(target: "p_net", "Sending polkadot message to {}: {:?}", to, message);
let encoded = message.encode();
ctx.send_chain_specific(to, encoded)
Expand Down Expand Up @@ -215,7 +215,7 @@ impl PolkadotProtocol {
/// Fetch block data by candidate receipt.
fn fetch_pov_block(
&mut self,
ctx: &mut Context<Block>,
ctx: &mut dyn Context<Block>,
candidate: &CandidateReceipt,
relay_parent: Hash,
canon_roots: ConsolidatedIngressRoots,
Expand All @@ -238,7 +238,7 @@ impl PolkadotProtocol {
/// Note new validation session.
fn new_validation_session(
&mut self,
ctx: &mut Context<Block>,
ctx: &mut dyn Context<Block>,
params: validation::SessionParams,
) -> validation::ValidationSession {

Expand All @@ -265,7 +265,7 @@ impl PolkadotProtocol {
self.live_validation_sessions.remove(parent_hash)
}

fn dispatch_pending_requests(&mut self, ctx: &mut Context<Block>) {
fn dispatch_pending_requests(&mut self, ctx: &mut dyn Context<Block>) {
let mut new_pending = Vec::new();
let validator_keys = &mut self.validators;
let next_req_id = &mut self.next_req_id;
Expand Down Expand Up @@ -316,7 +316,7 @@ impl PolkadotProtocol {
self.pending = new_pending;
}

fn on_polkadot_message(&mut self, ctx: &mut Context<Block>, who: PeerId, msg: Message) {
fn on_polkadot_message(&mut self, ctx: &mut dyn Context<Block>, who: PeerId, msg: Message) {
trace!(target: "p_net", "Polkadot message from {}: {:?}", who, msg);
match msg {
Message::SessionKey(key) => self.on_session_key(ctx, who, key),
Expand Down Expand Up @@ -352,7 +352,7 @@ impl PolkadotProtocol {
}
}

fn on_session_key(&mut self, ctx: &mut Context<Block>, who: PeerId, key: SessionKey) {
fn on_session_key(&mut self, ctx: &mut dyn Context<Block>, who: PeerId, key: SessionKey) {
{
let info = match self.peers.get_mut(&who) {
Some(peer) => peer,
Expand Down Expand Up @@ -396,7 +396,7 @@ impl PolkadotProtocol {

fn on_pov_block(
&mut self,
ctx: &mut Context<Block>,
ctx: &mut dyn Context<Block>,
who: PeerId,
req_id: RequestId,
pov_block: Option<PoVBlock>,
Expand Down Expand Up @@ -429,7 +429,7 @@ impl PolkadotProtocol {
}

// when a validator sends us (a collator) a new role.
fn on_new_role(&mut self, ctx: &mut Context<Block>, who: PeerId, role: Role) {
fn on_new_role(&mut self, ctx: &mut dyn Context<Block>, who: PeerId, role: Role) {
let info = match self.peers.get_mut(&who) {
Some(peer) => peer,
None => {
Expand Down Expand Up @@ -467,7 +467,7 @@ impl Specialization<Block> for PolkadotProtocol {
Status { collating_for: self.collating_for.clone() }.encode()
}

fn on_connect(&mut self, ctx: &mut Context<Block>, who: PeerId, status: FullStatus) {
fn on_connect(&mut self, ctx: &mut dyn Context<Block>, who: PeerId, status: FullStatus) {
let local_status = match Status::decode(&mut &status.chain_status[..]) {
Some(status) => status,
None => {
Expand Down Expand Up @@ -515,7 +515,7 @@ impl Specialization<Block> for PolkadotProtocol {
self.dispatch_pending_requests(ctx);
}

fn on_disconnect(&mut self, ctx: &mut Context<Block>, who: PeerId) {
fn on_disconnect(&mut self, ctx: &mut dyn Context<Block>, who: PeerId) {
if let Some(info) = self.peers.remove(&who) {
if let Some((acc_id, _)) = info.collating_for {
let new_primary = self.collators.on_disconnect(acc_id)
Expand Down Expand Up @@ -559,7 +559,12 @@ impl Specialization<Block> for PolkadotProtocol {
}
}

fn on_message(&mut self, ctx: &mut Context<Block>, who: PeerId, message: &mut Option<message::Message<Block>>) {
fn on_message(
&mut self,
ctx: &mut dyn Context<Block>,
who: PeerId,
message: &mut Option<message::Message<Block>>
) {
match message.take() {
Some(generic_message::Message::ChainSpecific(raw)) => {
match Message::decode(&mut raw.as_slice()) {
Expand All @@ -581,7 +586,7 @@ impl Specialization<Block> for PolkadotProtocol {

fn on_abort(&mut self) { }

fn maintain_peers(&mut self, ctx: &mut Context<Block>) {
fn maintain_peers(&mut self, ctx: &mut dyn Context<Block>) {
self.collators.collect_garbage(None);
self.local_collations.collect_garbage(None);
self.dispatch_pending_requests(ctx);
Expand All @@ -600,15 +605,21 @@ impl Specialization<Block> for PolkadotProtocol {
}
}

fn on_block_imported(&mut self, _ctx: &mut Context<Block>, hash: Hash, header: &Header) {
fn on_block_imported(&mut self, _ctx: &mut dyn Context<Block>, hash: Hash, header: &Header) {
self.collators.collect_garbage(Some(&hash));
self.local_collations.collect_garbage(Some(&header.parent_hash));
}
}

impl PolkadotProtocol {
// we received a collation from a peer
fn on_collation(&mut self, ctx: &mut Context<Block>, from: PeerId, relay_parent: Hash, collation: Collation) {
fn on_collation(
&mut self,
ctx: &mut dyn Context<Block>,
from: PeerId,
relay_parent: Hash,
collation: Collation
) {
let collation_para = collation.receipt.parachain_index;
let collated_acc = collation.receipt.collator.clone();

Expand Down Expand Up @@ -656,7 +667,7 @@ impl PolkadotProtocol {
}

// disconnect a collator by account-id.
fn disconnect_bad_collator(&mut self, ctx: &mut Context<Block>, collator_id: CollatorId) {
fn disconnect_bad_collator(&mut self, ctx: &mut dyn Context<Block>, collator_id: CollatorId) {
if let Some((who, _)) = self.collator_peer(collator_id) {
ctx.report_peer(who, cost::BAD_COLLATION)
}
Expand All @@ -667,7 +678,7 @@ impl PolkadotProtocol {
/// Add a local collation and broadcast it to the necessary peers.
pub fn add_local_collation(
&mut self,
ctx: &mut Context<Block>,
ctx: &mut dyn Context<Block>,
relay_parent: Hash,
targets: HashSet<SessionKey>,
collation: Collation,
Expand Down
4 changes: 2 additions & 2 deletions network/src/tests/validation.rs
Expand Up @@ -154,13 +154,13 @@ impl NetworkService for TestNetwork {
}

fn with_gossip<F: Send + 'static>(&self, with: F)
where F: FnOnce(&mut GossipService, &mut NetContext<Block>)
where F: FnOnce(&mut dyn GossipService, &mut dyn NetContext<Block>)
{
unimplemented!()
}

fn with_spec<F: Send + 'static>(&self, with: F)
where F: FnOnce(&mut PolkadotProtocol, &mut NetContext<Block>)
where F: FnOnce(&mut PolkadotProtocol, &mut dyn NetContext<Block>)
{
let mut context = TestContext::default();
let res = with(&mut *self.proto.lock(), &mut context);
Expand Down
8 changes: 4 additions & 4 deletions network/src/validation.rs
Expand Up @@ -78,11 +78,11 @@ impl Executor for TaskExecutor {

/// A gossip network subservice.
pub trait GossipService {
fn send_message(&mut self, ctx: &mut NetContext<Block>, who: &PeerId, message: ConsensusMessage);
fn send_message(&mut self, ctx: &mut dyn NetContext<Block>, who: &PeerId, message: ConsensusMessage);
}

impl GossipService for consensus_gossip::ConsensusGossip<Block> {
fn send_message(&mut self, ctx: &mut NetContext<Block>, who: &PeerId, message: ConsensusMessage) {
fn send_message(&mut self, ctx: &mut dyn NetContext<Block>, who: &PeerId, message: ConsensusMessage) {
consensus_gossip::ConsensusGossip::send_message(self, ctx, who, message)
}
}
Expand Down Expand Up @@ -135,7 +135,7 @@ impl NetworkService for super::NetworkService {
}

fn with_spec<F: Send + 'static>(&self, with: F)
where F: FnOnce(&mut PolkadotProtocol, &mut NetContext<Block>)
where F: FnOnce(&mut PolkadotProtocol, &mut dyn NetContext<Block>)
{
super::NetworkService::with_spec(self, with)
}
Expand Down Expand Up @@ -260,7 +260,7 @@ impl<P, E, N, T> ParachainNetwork for ValidationNetwork<P, E, N, T> where
{
type Error = String;
type TableRouter = Router<P, E, N, T>;
type BuildTableRouter = Box<Future<Item=Self::TableRouter,Error=String> + Send>;
type BuildTableRouter = Box<dyn Future<Item=Self::TableRouter, Error=String> + Send>;

fn communication_for(
&self,
Expand Down
5 changes: 4 additions & 1 deletion primitives/src/lib.rs
Expand Up @@ -77,8 +77,11 @@ pub type SessionKey = ed25519::Public;
/// that 32 bits may be multiplied with a balance in 128 bits without worrying about overflow.
pub type Balance = u128;

/// The Ed25519 pub key of an session that belongs to an Aura authority of the chain.
pub type AuraId = ed25519::Public;

/// Header type.
pub type Header = generic::Header<BlockNumber, BlakeTwo256, generic::DigestItem<Hash, SessionKey, SessionSignature>>;
pub type Header = generic::Header<BlockNumber, BlakeTwo256>;
/// Block type.
pub type Block = generic::Block<Header, UncheckedExtrinsic>;
/// Block ID.
Expand Down
4 changes: 0 additions & 4 deletions runtime/Cargo.toml
Expand Up @@ -24,7 +24,6 @@ consensus_aura = { package = "substrate-consensus-aura-primitives", git = "https
offchain_primitives = { package = "substrate-offchain-primitives", git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-master" }
aura = { package = "srml-aura", git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-master" }
balances = { package = "srml-balances", git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-master" }
consensus = { package = "srml-consensus", git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-master" }
council = { package = "srml-council", git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-master" }
democracy = { package = "srml-democracy", git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-master" }
executive = { package = "srml-executive", git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-master" }
Expand All @@ -38,7 +37,6 @@ system = { package = "srml-system", git = "https://github.com/paritytech/substra
timestamp = { package = "srml-timestamp", git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-master" }
treasury = { package = "srml-treasury", git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-master" }
version = { package = "sr-version", git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-master" }
consensus_authorities = { package = "substrate-consensus-authorities", git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-master" }

[dev-dependencies]
hex-literal = "0.2.0"
Expand All @@ -63,7 +61,6 @@ std = [
"sr-io/std",
"srml-support/std",
"balances/std",
"consensus/std",
"council/std",
"democracy/std",
"executive/std",
Expand All @@ -81,7 +78,6 @@ std = [
"serde/std",
"log",
"safe-mix/std",
"consensus_authorities/std",
"consensus_aura/std",
"aura/std",
]
4 changes: 1 addition & 3 deletions runtime/src/claims.rs
Expand Up @@ -193,7 +193,7 @@ mod tests {
// The testing primitives are very useful for avoiding having to work with signatures
// or public keys. `u64` is used as the `AccountId` and no `Signature`s are requried.
use sr_primitives::{
BuildStorage, traits::{BlakeTwo256, IdentityLookup}, testing::{Digest, DigestItem, Header}
BuildStorage, traits::{BlakeTwo256, IdentityLookup}, testing::Header
};
use balances;
use srml_support::{impl_outer_origin, assert_ok, assert_err, assert_noop};
Expand All @@ -213,12 +213,10 @@ mod tests {
type BlockNumber = u64;
type Hash = H256;
type Hashing = BlakeTwo256;
type Digest = Digest;
type AccountId = u64;
type Lookup = IdentityLookup<u64>;
type Header = Header;
type Event = ();
type Log = DigestItem;
}
impl balances::Trait for Test {
type Balance = u64;
Expand Down