Update to latest Substrate master + warning fixes (#292)

* Update to latest Substrate master + warning fixes

* Update runtime/src/lib.rs

Co-Authored-By: thiolliere <gui.thiolliere@gmail.com>
This commit is contained in:
Bastian Köcher
2019-06-20 13:57:58 +02:00
committed by Robert Habermeier
parent 58ab4f6b9f
commit a016bac6ad
21 changed files with 989 additions and 1225 deletions
+9 -9
View File
@@ -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));
@@ -423,7 +423,7 @@ 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>>,
}
@@ -431,7 +431,7 @@ 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,
@@ -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) {
@@ -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| {
@@ -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;
+27 -16
View File
@@ -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)
@@ -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: StructuredUnroutedIngress,
@@ -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 {
@@ -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;
@@ -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),
@@ -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,
@@ -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>,
@@ -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 => {
@@ -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 => {
@@ -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)
@@ -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()) {
@@ -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);
@@ -600,7 +605,7 @@ 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));
}
@@ -608,7 +613,13 @@ impl Specialization<Block> for PolkadotProtocol {
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();
@@ -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)
}
@@ -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,
+2 -2
View File
@@ -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);
+4 -4
View File
@@ -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)
}
}
@@ -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)
}
@@ -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,