cargo +nightly fmt (#3540)

* cargo +nightly fmt

* add cargo-fmt check to ci

* update ci

* fmt

* fmt

* skip macro

* ignore bridges
This commit is contained in:
Shawn Tabrizi
2021-08-02 12:47:33 +02:00
committed by GitHub
parent 30e3012270
commit ff5d56fb76
350 changed files with 20617 additions and 21266 deletions
@@ -32,19 +32,19 @@
//!
//! Versioned (v1 module): The actual requests and responses as sent over the network.
use std::{borrow::Cow, u64};
use std::time::Duration;
use std::{borrow::Cow, time::Duration, u64};
use futures::channel::mpsc;
use polkadot_primitives::v1::{MAX_CODE_SIZE, MAX_POV_SIZE};
use strum::EnumIter;
pub use sc_network::config as network;
pub use sc_network::config::RequestResponseConfig;
pub use sc_network::{config as network, config::RequestResponseConfig};
/// All requests that can be sent to the network bridge.
pub mod request;
pub use request::{IncomingRequest, OutgoingRequest, Requests, Recipient, OutgoingResult, ResponseSender};
pub use request::{
IncomingRequest, OutgoingRequest, OutgoingResult, Recipient, Requests, ResponseSender,
};
///// Multiplexer for incoming requests.
// pub mod multiplexer;
@@ -70,10 +70,9 @@ pub enum Protocol {
DisputeSending,
}
/// Minimum bandwidth we expect for validators - 500Mbit/s is the recommendation, so approximately
/// 50MB per second:
const MIN_BANDWIDTH_BYTES: u64 = 50 * 1024 * 1024;
const MIN_BANDWIDTH_BYTES: u64 = 50 * 1024 * 1024;
/// Default request timeout in seconds.
///
@@ -108,12 +107,7 @@ impl Protocol {
///
/// Returns a receiver for messages received on this protocol and the requested
/// `ProtocolConfig`.
pub fn get_config(
self,
) -> (
mpsc::Receiver<network::IncomingRequest>,
RequestResponseConfig,
) {
pub fn get_config(self) -> (mpsc::Receiver<network::IncomingRequest>, RequestResponseConfig) {
let p_name = self.into_protocol_name();
let (tx, rx) = mpsc::channel(self.get_channel_size());
let cfg = match self {
@@ -208,15 +202,16 @@ impl Protocol {
// wasting precious time.
let available_bandwidth = 7 * MIN_BANDWIDTH_BYTES / 10;
let size = u64::saturating_sub(
STATEMENTS_TIMEOUT.as_millis() as u64 * available_bandwidth / (1000 * MAX_CODE_SIZE as u64),
MAX_PARALLEL_STATEMENT_REQUESTS as u64
STATEMENTS_TIMEOUT.as_millis() as u64 * available_bandwidth /
(1000 * MAX_CODE_SIZE as u64),
MAX_PARALLEL_STATEMENT_REQUESTS as u64,
);
debug_assert!(
size > 0,
"We should have a channel size greater zero, otherwise we won't accept any requests."
);
size as usize
}
},
// Incoming requests can get bursty, we should also be able to handle them fast on
// average, so something in the ballpark of 100 should be fine. Nodes will retry on
// failure, so having a good value here is mostly about performance tuning.
@@ -16,14 +16,12 @@
use std::marker::PhantomData;
use futures::channel::oneshot;
use futures::prelude::Future;
use futures::{channel::oneshot, prelude::Future};
use thiserror::Error;
use parity_scale_codec::{Decode, Encode, Error as DecodingError};
use sc_network as network;
use sc_network::config as netconfig;
use sc_network::PeerId;
use sc_network::{config as netconfig, PeerId};
use thiserror::Error;
use polkadot_primitives::v1::AuthorityDiscoveryId;
@@ -164,16 +162,9 @@ where
pub fn new(
peer: Recipient,
payload: Req,
) -> (
Self,
impl Future<Output = OutgoingResult<Req::Response>>,
) {
) -> (Self, impl Future<Output = OutgoingResult<Req::Response>>) {
let (tx, rx) = oneshot::channel();
let r = Self {
peer,
payload,
pending_response: tx,
};
let r = Self { peer, payload, pending_response: tx };
(r, receive_response::<Req>(rx))
}
@@ -182,16 +173,8 @@ where
/// As this throws away type information, we also return the `Protocol` this encoded request
/// adheres to.
pub fn encode_request(self) -> (Protocol, OutgoingRequest<Vec<u8>>) {
let OutgoingRequest {
peer,
payload,
pending_response,
} = self;
let encoded = OutgoingRequest {
peer,
payload: payload.encode(),
pending_response,
};
let OutgoingRequest { peer, payload, pending_response } = self;
let encoded = OutgoingRequest { peer, payload: payload.encode(), pending_response };
(Req::PROTOCOL, encoded)
}
}
@@ -229,12 +212,12 @@ pub struct IncomingRequest<Req> {
/// Sender for sending back responses on an `IncomingRequest`.
#[derive(Debug)]
pub struct OutgoingResponseSender<Req>{
pub struct OutgoingResponseSender<Req> {
pending_response: oneshot::Sender<netconfig::OutgoingResponse>,
phantom: PhantomData<Req>,
}
impl<Req> OutgoingResponseSender<Req>
impl<Req> OutgoingResponseSender<Req>
where
Req: IsRequest + Decode,
Req::Response: Encode,
@@ -260,20 +243,15 @@ where
/// This variant allows for waiting for the response to be sent out, allows for changing peer's
/// reputation and allows for not sending a response at all (for only changing the peer's
/// reputation).
pub fn send_outgoing_response(self, resp: OutgoingResponse<<Req as IsRequest>::Response>)
-> Result<(), ()> {
let OutgoingResponse {
result,
reputation_changes,
sent_feedback,
} = resp;
pub fn send_outgoing_response(
self,
resp: OutgoingResponse<<Req as IsRequest>::Response>,
) -> Result<(), ()> {
let OutgoingResponse { result, reputation_changes, sent_feedback } = resp;
let response = netconfig::OutgoingResponse {
result: result.map(|v| v.encode()),
reputation_changes: reputation_changes
.into_iter()
.map(|c| c.into_base_rep())
.collect(),
reputation_changes: reputation_changes.into_iter().map(|c| c.into_base_rep()).collect(),
sent_feedback,
};
@@ -313,10 +291,7 @@ where
Self {
peer,
payload,
pending_response: OutgoingResponseSender {
pending_response,
phantom: PhantomData {},
},
pending_response: OutgoingResponseSender { pending_response, phantom: PhantomData {} },
}
}
@@ -330,20 +305,14 @@ where
/// - Reputation changes to apply for the peer in case decoding fails.
pub fn try_from_raw(
raw: sc_network::config::IncomingRequest,
reputation_changes: Vec<UnifiedReputationChange>
reputation_changes: Vec<UnifiedReputationChange>,
) -> Result<Self, ReceiveError> {
let sc_network::config::IncomingRequest {
payload,
peer,
pending_response,
} = raw;
let sc_network::config::IncomingRequest { payload, peer, pending_response } = raw;
let payload = match Req::decode(&mut payload.as_ref()) {
Ok(payload) => payload,
Err(err) => {
let reputation_changes = reputation_changes
.into_iter()
.map(|r| r.into_base_rep())
.collect();
let reputation_changes =
reputation_changes.into_iter().map(|r| r.into_base_rep()).collect();
let response = sc_network::config::OutgoingResponse {
result: Err(()),
reputation_changes,
@@ -354,7 +323,7 @@ where
return Err(ReceiveError::DecodingErrorNoReputationChange(peer, err))
}
return Err(ReceiveError::DecodingError(peer, err))
}
},
};
Ok(Self::new(peer, payload, pending_response))
}
@@ -369,8 +338,10 @@ where
/// Send response with additional options.
///
/// Calls [`OutgoingResponseSender::send_outgoing_response`].
pub fn send_outgoing_response(self, resp: OutgoingResponse<<Req as IsRequest>::Response>)
-> Result<(), ()> {
pub fn send_outgoing_response(
self,
resp: OutgoingResponse<<Req as IsRequest>::Response>,
) -> Result<(), ()> {
self.pending_response.send_outgoing_response(resp)
}
}
@@ -18,12 +18,14 @@
use parity_scale_codec::{Decode, Encode};
use polkadot_primitives::v1::{CandidateHash, CandidateReceipt, CommittedCandidateReceipt, Hash, ValidatorIndex};
use polkadot_primitives::v1::Id as ParaId;
use polkadot_node_primitives::{AvailableData, DisputeMessage, ErasureChunk, PoV, UncheckedDisputeMessage};
use polkadot_node_primitives::{
AvailableData, DisputeMessage, ErasureChunk, PoV, UncheckedDisputeMessage,
};
use polkadot_primitives::v1::{
CandidateHash, CandidateReceipt, CommittedCandidateReceipt, Hash, Id as ParaId, ValidatorIndex,
};
use super::request::IsRequest;
use super::Protocol;
use super::{request::IsRequest, Protocol};
/// Request an availability chunk.
#[derive(Debug, Copy, Clone, Encode, Decode)]
@@ -69,19 +71,15 @@ pub struct ChunkResponse {
}
impl From<ErasureChunk> for ChunkResponse {
fn from(ErasureChunk {chunk, index: _, proof}: ErasureChunk) -> Self {
ChunkResponse {chunk, proof}
fn from(ErasureChunk { chunk, index: _, proof }: ErasureChunk) -> Self {
ChunkResponse { chunk, proof }
}
}
impl ChunkResponse {
/// Re-build an `ErasureChunk` from response and request.
pub fn recombine_into_chunk(self, req: &ChunkFetchingRequest) -> ErasureChunk {
ErasureChunk {
chunk: self.chunk,
proof: self.proof,
index: req.index,
}
ErasureChunk { chunk: self.chunk, proof: self.proof, index: req.index }
}
}
@@ -210,7 +208,7 @@ impl From<DisputeMessage> for DisputeRequest {
pub enum DisputeResponse {
/// Recipient successfully processed the dispute request.
#[codec(index = 0)]
Confirmed
Confirmed,
}
impl IsRequest for DisputeRequest {