diff --git a/substrate/client/network/build.rs b/substrate/client/network/build.rs
index 991b1cba5d..8ed460f163 100644
--- a/substrate/client/network/build.rs
+++ b/substrate/client/network/build.rs
@@ -1,9 +1,9 @@
const PROTOS: &[&str] = &[
- "src/protocol/schema/api.v1.proto",
- "src/protocol/schema/finality.v1.proto",
- "src/protocol/schema/light.v1.proto"
+ "src/schema/api.v1.proto",
+ "src/schema/finality.v1.proto",
+ "src/schema/light.v1.proto"
];
fn main() {
- prost_build::compile_protos(PROTOS, &["src/protocol"]).unwrap();
+ prost_build::compile_protos(PROTOS, &["src/schema"]).unwrap();
}
diff --git a/substrate/client/network/src/behaviour.rs b/substrate/client/network/src/behaviour.rs
index eae20c9031..3b6224e9cc 100644
--- a/substrate/client/network/src/behaviour.rs
+++ b/substrate/client/network/src/behaviour.rs
@@ -15,14 +15,11 @@
// along with Substrate. If not, see .
use crate::{
- config::{ProtocolId, Role},
+ config::{ProtocolId, Role}, block_requests, light_client_handler, finality_requests,
debug_info, discovery::{DiscoveryBehaviour, DiscoveryConfig, DiscoveryOut},
+ protocol::{message::{self, Roles}, CustomMessageOutcome, Protocol},
Event, ObservedRole, DhtEvent, ExHashT,
};
-use crate::protocol::{
- self, block_requests, light_client_handler, finality_requests,
- message::{self, Roles}, CustomMessageOutcome, Protocol
-};
use codec::Encode as _;
use libp2p::NetworkBehaviour;
@@ -33,7 +30,6 @@ use log::debug;
use sp_consensus::{BlockOrigin, import_queue::{IncomingBlock, Origin}};
use sp_runtime::{traits::{Block as BlockT, NumberFor}, ConsensusEngineId, Justification};
use std::{borrow::Cow, iter, task::{Context, Poll}, time::Duration};
-use void;
/// General behaviour of the network. Combines all protocols together.
#[derive(NetworkBehaviour)]
@@ -47,11 +43,11 @@ pub struct Behaviour {
/// Discovers nodes of the network.
discovery: DiscoveryBehaviour,
/// Block request handling.
- block_requests: protocol::BlockRequests,
+ block_requests: block_requests::BlockRequests,
/// Finality proof request handling.
- finality_proof_requests: protocol::FinalityProofRequests,
+ finality_proof_requests: finality_requests::FinalityProofRequests,
/// Light client request handling.
- light_client_handler: protocol::LightClientHandler,
+ light_client_handler: light_client_handler::LightClientHandler,
/// Queue of events to produce for the outside.
#[behaviour(ignore)]
@@ -110,9 +106,9 @@ impl Behaviour {
role: Role,
user_agent: String,
local_public_key: PublicKey,
- block_requests: protocol::BlockRequests,
- finality_proof_requests: protocol::FinalityProofRequests,
- light_client_handler: protocol::LightClientHandler,
+ block_requests: block_requests::BlockRequests,
+ finality_proof_requests: finality_requests::FinalityProofRequests,
+ light_client_handler: light_client_handler::LightClientHandler,
disco_config: DiscoveryConfig,
) -> Self {
Behaviour {
diff --git a/substrate/client/network/src/protocol/block_requests.rs b/substrate/client/network/src/block_requests.rs
similarity index 94%
rename from substrate/client/network/src/protocol/block_requests.rs
rename to substrate/client/network/src/block_requests.rs
index 920d3f0e23..e8c96cc6d8 100644
--- a/substrate/client/network/src/protocol/block_requests.rs
+++ b/substrate/client/network/src/block_requests.rs
@@ -27,7 +27,8 @@ use codec::{Encode, Decode};
use crate::{
chain::Client,
config::ProtocolId,
- protocol::{api, message::{self, BlockAttributes}}
+ protocol::{message::{self, BlockAttributes}},
+ schema,
};
use futures::{future::BoxFuture, prelude::*, stream::FuturesUnordered};
use futures_timer::Delay;
@@ -275,18 +276,18 @@ where
return SendRequestOutcome::NotConnected;
};
- let protobuf_rq = api::v1::BlockRequest {
+ let protobuf_rq = schema::v1::BlockRequest {
fields: u32::from_be_bytes([req.fields.bits(), 0, 0, 0]),
from_block: match req.from {
message::FromBlock::Hash(h) =>
- Some(api::v1::block_request::FromBlock::Hash(h.encode())),
+ Some(schema::v1::block_request::FromBlock::Hash(h.encode())),
message::FromBlock::Number(n) =>
- Some(api::v1::block_request::FromBlock::Number(n.encode())),
+ Some(schema::v1::block_request::FromBlock::Number(n.encode())),
},
to_block: req.to.map(|h| h.encode()).unwrap_or_default(),
direction: match req.direction {
- message::Direction::Ascending => api::v1::Direction::Ascending as i32,
- message::Direction::Descending => api::v1::Direction::Descending as i32,
+ message::Direction::Ascending => schema::v1::Direction::Ascending as i32,
+ message::Direction::Descending => schema::v1::Direction::Descending as i32,
},
max_blocks: req.max.unwrap_or(0),
};
@@ -340,8 +341,8 @@ where
fn on_block_request
( &mut self
, peer: &PeerId
- , request: &api::v1::BlockRequest
- ) -> Result
+ , request: &schema::v1::BlockRequest
+ ) -> Result
{
log::trace!(
target: "sync",
@@ -353,11 +354,11 @@ where
let from_block_id =
match request.from_block {
- Some(api::v1::block_request::FromBlock::Hash(ref h)) => {
+ Some(schema::v1::block_request::FromBlock::Hash(ref h)) => {
let h = Decode::decode(&mut h.as_ref())?;
BlockId::::Hash(h)
}
- Some(api::v1::block_request::FromBlock::Number(ref n)) => {
+ Some(schema::v1::block_request::FromBlock::Number(ref n)) => {
let n = Decode::decode(&mut n.as_ref())?;
BlockId::::Number(n)
}
@@ -375,10 +376,10 @@ where
};
let direction =
- if request.direction == api::v1::Direction::Ascending as i32 {
- api::v1::Direction::Ascending
- } else if request.direction == api::v1::Direction::Descending as i32 {
- api::v1::Direction::Descending
+ if request.direction == schema::v1::Direction::Ascending as i32 {
+ schema::v1::Direction::Ascending
+ } else if request.direction == schema::v1::Direction::Descending as i32 {
+ schema::v1::Direction::Descending
} else {
let msg = format!("invalid `BlockRequest::direction` value: {}", request.direction);
return Err(io::Error::new(io::ErrorKind::Other, msg).into())
@@ -406,7 +407,7 @@ where
};
let is_empty_justification = justification.as_ref().map(|j| j.is_empty()).unwrap_or(false);
- let block_data = api::v1::BlockData {
+ let block_data = schema::v1::BlockData {
hash: hash.encode(),
header: if get_header {
header.encode()
@@ -431,10 +432,10 @@ where
blocks.push(block_data);
match direction {
- api::v1::Direction::Ascending => {
+ schema::v1::Direction::Ascending => {
block_id = BlockId::Number(number + One::one())
}
- api::v1::Direction::Descending => {
+ schema::v1::Direction::Descending => {
if number.is_zero() {
break
}
@@ -443,7 +444,7 @@ where
}
}
- Ok(api::v1::BlockResponse { blocks })
+ Ok(schema::v1::BlockResponse { blocks })
}
}
@@ -719,9 +720,9 @@ where
#[derive(Debug)]
pub enum NodeEvent {
/// Incoming request from remote and substream to use for the response.
- Request(api::v1::BlockRequest, T),
+ Request(schema::v1::BlockRequest, T),
/// Incoming response from remote.
- Response(message::BlockRequest, api::v1::BlockResponse),
+ Response(message::BlockRequest, schema::v1::BlockResponse),
}
/// Substream upgrade protocol.
@@ -762,7 +763,7 @@ where
let future = async move {
let len = self.max_request_len;
let vec = read_one(&mut s, len).await?;
- match api::v1::BlockRequest::decode(&vec[..]) {
+ match schema::v1::BlockRequest::decode(&vec[..]) {
Ok(r) => Ok(NodeEvent::Request(r, s)),
Err(e) => Err(ReadOneError::Io(io::Error::new(io::ErrorKind::Other, e)))
}
@@ -809,7 +810,7 @@ where
write_one(&mut s, &self.request).await?;
let vec = read_one(&mut s, self.max_response_size).await?;
- api::v1::BlockResponse::decode(&vec[..])
+ schema::v1::BlockResponse::decode(&vec[..])
.map(|r| NodeEvent::Response(self.original_request, r))
.map_err(|e| {
ReadOneError::Io(io::Error::new(io::ErrorKind::Other, e))
diff --git a/substrate/client/network/src/protocol/finality_requests.rs b/substrate/client/network/src/finality_requests.rs
similarity index 95%
rename from substrate/client/network/src/protocol/finality_requests.rs
rename to substrate/client/network/src/finality_requests.rs
index 0616759617..457f934350 100644
--- a/substrate/client/network/src/protocol/finality_requests.rs
+++ b/substrate/client/network/src/finality_requests.rs
@@ -27,7 +27,8 @@ use codec::{Encode, Decode};
use crate::{
chain::FinalityProofProvider,
config::ProtocolId,
- protocol::{api, message}
+ protocol::message,
+ schema,
};
use futures::{future::BoxFuture, prelude::*, stream::FuturesUnordered};
use libp2p::{
@@ -169,7 +170,7 @@ where
/// If the response doesn't arrive in time, or if the remote answers improperly, the target
/// will be disconnected.
pub fn send_request(&mut self, target: &PeerId, block_hash: B::Hash, request: Vec) {
- let protobuf_rq = api::v1::finality::FinalityProofRequest {
+ let protobuf_rq = schema::v1::finality::FinalityProofRequest {
block_hash: block_hash.encode(),
request,
};
@@ -194,8 +195,8 @@ where
}
/// Callback, invoked when a new finality request has been received from remote.
- fn on_finality_request(&mut self, peer: &PeerId, request: &api::v1::finality::FinalityProofRequest)
- -> Result
+ fn on_finality_request(&mut self, peer: &PeerId, request: &schema::v1::finality::FinalityProofRequest)
+ -> Result
{
let block_hash = Decode::decode(&mut request.block_hash.as_ref())?;
@@ -211,7 +212,7 @@ where
return Err(From::from("Empty finality proof provider".to_string()))
};
- Ok(api::v1::finality::FinalityProofResponse { proof: finality_proof })
+ Ok(schema::v1::finality::FinalityProofResponse { proof: finality_proof })
}
}
@@ -300,9 +301,9 @@ where
#[derive(Debug)]
pub enum NodeEvent {
/// Incoming request from remote and substream to use for the response.
- Request(api::v1::finality::FinalityProofRequest, T),
+ Request(schema::v1::finality::FinalityProofRequest, T),
/// Incoming response from remote.
- Response(api::v1::finality::FinalityProofResponse, B::Hash),
+ Response(schema::v1::finality::FinalityProofResponse, B::Hash),
}
/// Substream upgrade protocol.
@@ -346,7 +347,7 @@ where
async move {
let len = self.max_request_len;
let vec = read_one(&mut s, len).await?;
- match api::v1::finality::FinalityProofRequest::decode(&vec[..]) {
+ match schema::v1::finality::FinalityProofRequest::decode(&vec[..]) {
Ok(r) => Ok(NodeEvent::Request(r, s)),
Err(e) => Err(ReadOneError::Io(io::Error::new(io::ErrorKind::Other, e)))
}
@@ -392,7 +393,7 @@ where
write_one(&mut s, &self.request).await?;
let vec = read_one(&mut s, self.max_response_size).await?;
- api::v1::finality::FinalityProofResponse::decode(&vec[..])
+ schema::v1::finality::FinalityProofResponse::decode(&vec[..])
.map(|r| NodeEvent::Response(r, self.block_hash))
.map_err(|e| {
ReadOneError::Io(io::Error::new(io::ErrorKind::Other, e))
diff --git a/substrate/client/network/src/lib.rs b/substrate/client/network/src/lib.rs
index 44bb1516bd..1ed0b90540 100644
--- a/substrate/client/network/src/lib.rs
+++ b/substrate/client/network/src/lib.rs
@@ -240,11 +240,15 @@
//!
mod behaviour;
+mod block_requests;
mod chain;
mod debug_info;
mod discovery;
+mod finality_requests;
+mod light_client_handler;
mod on_demand_layer;
mod protocol;
+mod schema;
mod service;
mod transport;
mod utils;
diff --git a/substrate/client/network/src/protocol/light_client_handler.rs b/substrate/client/network/src/light_client_handler.rs
similarity index 92%
rename from substrate/client/network/src/protocol/light_client_handler.rs
rename to substrate/client/network/src/light_client_handler.rs
index 2de6f56e2b..5080d16ead 100644
--- a/substrate/client/network/src/protocol/light_client_handler.rs
+++ b/substrate/client/network/src/light_client_handler.rs
@@ -29,7 +29,8 @@ use codec::{self, Encode, Decode};
use crate::{
chain::Client,
config::ProtocolId,
- protocol::{api, message::BlockAttributes}
+ protocol::message::BlockAttributes,
+ schema,
};
use futures::{channel::oneshot, future::BoxFuture, prelude::*, stream::FuturesUnordered};
use libp2p::{
@@ -436,10 +437,10 @@ where
( &mut self
, peer: &PeerId
, request: &Request
- , response: api::v1::light::Response
+ , response: schema::v1::light::Response
) -> Result, Error>
{
- use api::v1::light::response::Response;
+ use schema::v1::light::response::Response;
match response.response {
Some(Response::RemoteCallResponse(response)) =>
if let Request::Call { request , .. } = request {
@@ -508,7 +509,7 @@ where
( &mut self
, peer: &PeerId
, request: &Request
- , response: api::v1::BlockResponse
+ , response: schema::v1::BlockResponse
) -> Result, Error>
{
let request = if let Request::Body { request , .. } = &request {
@@ -533,8 +534,8 @@ where
fn on_remote_call_request
( &mut self
, peer: &PeerId
- , request: &api::v1::light::RemoteCallRequest
- ) -> Result
+ , request: &schema::v1::light::RemoteCallRequest
+ ) -> Result
{
log::trace!("remote call request from {} ({} at {:?})",
peer,
@@ -558,18 +559,18 @@ where
};
let response = {
- let r = api::v1::light::RemoteCallResponse { proof: proof.encode() };
- api::v1::light::response::Response::RemoteCallResponse(r)
+ let r = schema::v1::light::RemoteCallResponse { proof: proof.encode() };
+ schema::v1::light::response::Response::RemoteCallResponse(r)
};
- Ok(api::v1::light::Response { response: Some(response) })
+ Ok(schema::v1::light::Response { response: Some(response) })
}
fn on_remote_read_request
( &mut self
, peer: &PeerId
- , request: &api::v1::light::RemoteReadRequest
- ) -> Result
+ , request: &schema::v1::light::RemoteReadRequest
+ ) -> Result
{
if request.keys.is_empty() {
log::debug!("invalid remote read request sent by {}", peer);
@@ -596,18 +597,18 @@ where
};
let response = {
- let r = api::v1::light::RemoteReadResponse { proof: proof.encode() };
- api::v1::light::response::Response::RemoteReadResponse(r)
+ let r = schema::v1::light::RemoteReadResponse { proof: proof.encode() };
+ schema::v1::light::response::Response::RemoteReadResponse(r)
};
- Ok(api::v1::light::Response { response: Some(response) })
+ Ok(schema::v1::light::Response { response: Some(response) })
}
fn on_remote_read_child_request
( &mut self
, peer: &PeerId
- , request: &api::v1::light::RemoteReadChildRequest
- ) -> Result
+ , request: &schema::v1::light::RemoteReadChildRequest
+ ) -> Result
{
if request.keys.is_empty() {
log::debug!("invalid remote child read request sent by {}", peer);
@@ -645,18 +646,18 @@ where
};
let response = {
- let r = api::v1::light::RemoteReadResponse { proof: proof.encode() };
- api::v1::light::response::Response::RemoteReadResponse(r)
+ let r = schema::v1::light::RemoteReadResponse { proof: proof.encode() };
+ schema::v1::light::response::Response::RemoteReadResponse(r)
};
- Ok(api::v1::light::Response { response: Some(response) })
+ Ok(schema::v1::light::Response { response: Some(response) })
}
fn on_remote_header_request
( &mut self
, peer: &PeerId
- , request: &api::v1::light::RemoteHeaderRequest
- ) -> Result
+ , request: &schema::v1::light::RemoteHeaderRequest
+ ) -> Result
{
log::trace!("remote header proof request from {} ({:?})", peer, request.block);
@@ -673,18 +674,18 @@ where
};
let response = {
- let r = api::v1::light::RemoteHeaderResponse { header, proof: proof.encode() };
- api::v1::light::response::Response::RemoteHeaderResponse(r)
+ let r = schema::v1::light::RemoteHeaderResponse { header, proof: proof.encode() };
+ schema::v1::light::response::Response::RemoteHeaderResponse(r)
};
- Ok(api::v1::light::Response { response: Some(response) })
+ Ok(schema::v1::light::Response { response: Some(response) })
}
fn on_remote_changes_request
( &mut self
, peer: &PeerId
- , request: &api::v1::light::RemoteChangesRequest
- ) -> Result
+ , request: &schema::v1::light::RemoteChangesRequest
+ ) -> Result
{
log::trace!("remote changes proof request from {} for key {} ({:?}..{:?})",
peer,
@@ -727,18 +728,18 @@ where
};
let response = {
- let r = api::v1::light::RemoteChangesResponse {
+ let r = schema::v1::light::RemoteChangesResponse {
max: proof.max_block.encode(),
proof: proof.proof,
roots: proof.roots.into_iter()
- .map(|(k, v)| api::v1::light::Pair { fst: k.encode(), snd: v.encode() })
+ .map(|(k, v)| schema::v1::light::Pair { fst: k.encode(), snd: v.encode() })
.collect(),
roots_proof: proof.roots_proof.encode(),
};
- api::v1::light::response::Response::RemoteChangesResponse(r)
+ schema::v1::light::response::Response::RemoteChangesResponse(r)
};
- Ok(api::v1::light::Response { response: Some(response) })
+ Ok(schema::v1::light::Response { response: Some(response) })
}
}
@@ -821,15 +822,15 @@ where
Event::Request(request, mut stream) => {
log::trace!("incoming request from {}", peer);
let result = match &request.request {
- Some(api::v1::light::request::Request::RemoteCallRequest(r)) =>
+ Some(schema::v1::light::request::Request::RemoteCallRequest(r)) =>
self.on_remote_call_request(&peer, r),
- Some(api::v1::light::request::Request::RemoteReadRequest(r)) =>
+ Some(schema::v1::light::request::Request::RemoteReadRequest(r)) =>
self.on_remote_read_request(&peer, r),
- Some(api::v1::light::request::Request::RemoteHeaderRequest(r)) =>
+ Some(schema::v1::light::request::Request::RemoteHeaderRequest(r)) =>
self.on_remote_header_request(&peer, r),
- Some(api::v1::light::request::Request::RemoteReadChildRequest(r)) =>
+ Some(schema::v1::light::request::Request::RemoteReadChildRequest(r)) =>
self.on_remote_read_child_request(&peer, r),
- Some(api::v1::light::request::Request::RemoteChangesRequest(r)) =>
+ Some(schema::v1::light::request::Request::RemoteChangesRequest(r)) =>
self.on_remote_changes_request(&peer, r),
None => {
log::debug!("ignoring request without request data from peer {}", peer);
@@ -1059,11 +1060,11 @@ fn retries(request: &Request) -> usize {
fn serialize_request(request: &Request) -> Result, prost::EncodeError> {
let request = match request {
Request::Body { request, .. } => {
- let rq = api::v1::BlockRequest {
+ let rq = schema::v1::BlockRequest {
fields: u32::from(BlockAttributes::BODY.bits()),
- from_block: Some(api::v1::block_request::FromBlock::Hash(request.header.hash().encode())),
+ from_block: Some(schema::v1::block_request::FromBlock::Hash(request.header.hash().encode())),
to_block: Vec::new(),
- direction: api::v1::Direction::Ascending as i32,
+ direction: schema::v1::Direction::Ascending as i32,
max_blocks: 1,
};
let mut buf = Vec::with_capacity(rq.encoded_len());
@@ -1071,34 +1072,34 @@ fn serialize_request(request: &Request) -> Result, prost::E
return Ok(buf);
}
Request::Header { request, .. } => {
- let r = api::v1::light::RemoteHeaderRequest { block: request.block.encode() };
- api::v1::light::request::Request::RemoteHeaderRequest(r)
+ let r = schema::v1::light::RemoteHeaderRequest { block: request.block.encode() };
+ schema::v1::light::request::Request::RemoteHeaderRequest(r)
}
Request::Read { request, .. } => {
- let r = api::v1::light::RemoteReadRequest {
+ let r = schema::v1::light::RemoteReadRequest {
block: request.block.encode(),
keys: request.keys.clone(),
};
- api::v1::light::request::Request::RemoteReadRequest(r)
+ schema::v1::light::request::Request::RemoteReadRequest(r)
}
Request::ReadChild { request, .. } => {
- let r = api::v1::light::RemoteReadChildRequest {
+ let r = schema::v1::light::RemoteReadChildRequest {
block: request.block.encode(),
storage_key: request.storage_key.clone().into_inner(),
keys: request.keys.clone(),
};
- api::v1::light::request::Request::RemoteReadChildRequest(r)
+ schema::v1::light::request::Request::RemoteReadChildRequest(r)
}
Request::Call { request, .. } => {
- let r = api::v1::light::RemoteCallRequest {
+ let r = schema::v1::light::RemoteCallRequest {
block: request.block.encode(),
method: request.method.clone(),
data: request.call_data.clone(),
};
- api::v1::light::request::Request::RemoteCallRequest(r)
+ schema::v1::light::request::Request::RemoteCallRequest(r)
}
Request::Changes { request, .. } => {
- let r = api::v1::light::RemoteChangesRequest {
+ let r = schema::v1::light::RemoteChangesRequest {
first: request.first_block.1.encode(),
last: request.last_block.1.encode(),
min: request.tries_roots.1.encode(),
@@ -1107,11 +1108,11 @@ fn serialize_request(request: &Request) -> Result, prost::E
.unwrap_or_default(),
key: request.key.clone(),
};
- api::v1::light::request::Request::RemoteChangesRequest(r)
+ schema::v1::light::request::Request::RemoteChangesRequest(r)
}
};
- let rq = api::v1::light::Request { request: Some(request) };
+ let rq = schema::v1::light::Request { request: Some(request) };
let mut buf = Vec::with_capacity(rq.encoded_len());
rq.encode(&mut buf)?;
Ok(buf)
@@ -1159,7 +1160,7 @@ fn send_reply(result: Result, ClientError>, request: Request<
#[derive(Debug)]
pub enum Event {
/// Incoming request from remote and substream to use for the response.
- Request(api::v1::light::Request, T),
+ Request(schema::v1::light::Request, T),
/// Incoming response from remote.
Response(RequestId, Response),
}
@@ -1168,9 +1169,9 @@ pub enum Event {
#[derive(Debug, Clone)]
pub enum Response {
/// Incoming light response from remote.
- Light(api::v1::light::Response),
+ Light(schema::v1::light::Response),
/// Incoming block response from remote.
- Block(api::v1::BlockResponse),
+ Block(schema::v1::BlockResponse),
}
/// Substream upgrade protocol.
@@ -1204,7 +1205,7 @@ where
fn upgrade_inbound(self, mut s: T, _: Self::Info) -> Self::Future {
let future = async move {
let vec = read_one(&mut s, self.max_request_size).await?;
- match api::v1::light::Request::decode(&vec[..]) {
+ match schema::v1::light::Request::decode(&vec[..]) {
Ok(r) => Ok(Event::Request(r, s)),
Err(e) => Err(ReadOneError::Io(io::Error::new(io::ErrorKind::Other, e)))
}
@@ -1261,14 +1262,14 @@ where
match self.expected {
ExpectedResponseTy::Light => {
- api::v1::light::Response::decode(&vec[..])
+ schema::v1::light::Response::decode(&vec[..])
.map(|r| Event::Response(self.request_id, Response::Light(r)))
.map_err(|e| {
ReadOneError::Io(io::Error::new(io::ErrorKind::Other, e))
})
},
ExpectedResponseTy::Block => {
- api::v1::BlockResponse::decode(&vec[..])
+ schema::v1::BlockResponse::decode(&vec[..])
.map(|r| Event::Response(self.request_id, Response::Block(r)))
.map_err(|e| {
ReadOneError::Io(io::Error::new(io::ErrorKind::Other, e))
@@ -1301,7 +1302,7 @@ mod tests {
use crate::{
chain::Client,
config::ProtocolId,
- protocol::api,
+ schema,
};
use futures::{channel::oneshot, prelude::*};
use libp2p::{
@@ -1625,9 +1626,9 @@ mod tests {
let request_id = *behaviour.outstanding.keys().next().unwrap();
let response = {
- let r = api::v1::light::RemoteCallResponse { proof: empty_proof() };
- api::v1::light::Response {
- response: Some(api::v1::light::response::Response::RemoteCallResponse(r)),
+ let r = schema::v1::light::RemoteCallResponse { proof: empty_proof() };
+ schema::v1::light::Response {
+ response: Some(schema::v1::light::response::Response::RemoteCallResponse(r)),
}
};
@@ -1656,9 +1657,9 @@ mod tests {
// Some unsolicited response
let response = {
- let r = api::v1::light::RemoteCallResponse { proof: empty_proof() };
- api::v1::light::Response {
- response: Some(api::v1::light::response::Response::RemoteCallResponse(r)),
+ let r = schema::v1::light::RemoteCallResponse { proof: empty_proof() };
+ schema::v1::light::Response {
+ response: Some(schema::v1::light::response::Response::RemoteCallResponse(r)),
}
};
@@ -1700,9 +1701,9 @@ mod tests {
let request_id = *behaviour.outstanding.keys().next().unwrap();
let response = {
- let r = api::v1::light::RemoteReadResponse { proof: empty_proof() }; // Not a RemoteCallResponse!
- api::v1::light::Response {
- response: Some(api::v1::light::response::Response::RemoteReadResponse(r)),
+ let r = schema::v1::light::RemoteReadResponse { proof: empty_proof() }; // Not a RemoteCallResponse!
+ schema::v1::light::Response {
+ response: Some(schema::v1::light::response::Response::RemoteReadResponse(r)),
}
};
@@ -1761,9 +1762,9 @@ mod tests {
let request_id = *behaviour.outstanding.keys().next().unwrap();
let responding_peer = behaviour.outstanding.values().next().unwrap().peer.clone();
let response = {
- let r = api::v1::light::RemoteCallResponse { proof: empty_proof() };
- api::v1::light::Response {
- response: Some(api::v1::light::response::Response::RemoteCallResponse(r))
+ let r = schema::v1::light::RemoteCallResponse { proof: empty_proof() };
+ schema::v1::light::Response {
+ response: Some(schema::v1::light::response::Response::RemoteCallResponse(r))
}
};
let conn = ConnectionId::new(i);
@@ -1775,9 +1776,9 @@ mod tests {
let request_id = *behaviour.outstanding.keys().next().unwrap();
let responding_peer = behaviour.outstanding.values().next().unwrap().peer.clone();
let response = {
- let r = api::v1::light::RemoteCallResponse { proof: empty_proof() };
- api::v1::light::Response {
- response: Some(api::v1::light::response::Response::RemoteCallResponse(r)),
+ let r = schema::v1::light::RemoteCallResponse { proof: empty_proof() };
+ schema::v1::light::Response {
+ response: Some(schema::v1::light::response::Response::RemoteCallResponse(r)),
}
};
behaviour.inject_event(responding_peer, conn4, Event::Response(request_id, Response::Light(response)));
@@ -1798,41 +1799,41 @@ mod tests {
let response = match request {
Request::Body { .. } => unimplemented!(),
Request::Header{..} => {
- let r = api::v1::light::RemoteHeaderResponse {
+ let r = schema::v1::light::RemoteHeaderResponse {
header: dummy_header().encode(),
proof: empty_proof()
};
- api::v1::light::Response {
- response: Some(api::v1::light::response::Response::RemoteHeaderResponse(r)),
+ schema::v1::light::Response {
+ response: Some(schema::v1::light::response::Response::RemoteHeaderResponse(r)),
}
}
Request::Read{..} => {
- let r = api::v1::light::RemoteReadResponse { proof: empty_proof() };
- api::v1::light::Response {
- response: Some(api::v1::light::response::Response::RemoteReadResponse(r)),
+ let r = schema::v1::light::RemoteReadResponse { proof: empty_proof() };
+ schema::v1::light::Response {
+ response: Some(schema::v1::light::response::Response::RemoteReadResponse(r)),
}
}
Request::ReadChild{..} => {
- let r = api::v1::light::RemoteReadResponse { proof: empty_proof() };
- api::v1::light::Response {
- response: Some(api::v1::light::response::Response::RemoteReadResponse(r)),
+ let r = schema::v1::light::RemoteReadResponse { proof: empty_proof() };
+ schema::v1::light::Response {
+ response: Some(schema::v1::light::response::Response::RemoteReadResponse(r)),
}
}
Request::Call{..} => {
- let r = api::v1::light::RemoteCallResponse { proof: empty_proof() };
- api::v1::light::Response {
- response: Some(api::v1::light::response::Response::RemoteCallResponse(r)),
+ let r = schema::v1::light::RemoteCallResponse { proof: empty_proof() };
+ schema::v1::light::Response {
+ response: Some(schema::v1::light::response::Response::RemoteCallResponse(r)),
}
}
Request::Changes{..} => {
- let r = api::v1::light::RemoteChangesResponse {
+ let r = schema::v1::light::RemoteChangesResponse {
max: iter::repeat(1).take(32).collect(),
proof: Vec::new(),
roots: Vec::new(),
roots_proof: empty_proof()
};
- api::v1::light::Response {
- response: Some(api::v1::light::response::Response::RemoteChangesResponse(r)),
+ schema::v1::light::Response {
+ response: Some(schema::v1::light::response::Response::RemoteChangesResponse(r)),
}
}
};
diff --git a/substrate/client/network/src/on_demand_layer.rs b/substrate/client/network/src/on_demand_layer.rs
index d881bf6fe2..c8bd7f2867 100644
--- a/substrate/client/network/src/on_demand_layer.rs
+++ b/substrate/client/network/src/on_demand_layer.rs
@@ -16,7 +16,7 @@
//! On-demand requests service.
-use crate::protocol::light_client_handler;
+use crate::light_client_handler;
use futures::{channel::oneshot, prelude::*};
use parking_lot::Mutex;
diff --git a/substrate/client/network/src/protocol.rs b/substrate/client/network/src/protocol.rs
index 82f0d775ec..23fd944678 100644
--- a/substrate/client/network/src/protocol.rs
+++ b/substrate/client/network/src/protocol.rs
@@ -58,32 +58,13 @@ use sc_client_api::{ChangesProof, StorageProof};
use util::LruHashSet;
use wasm_timer::Instant;
-// Include sources generated from protobuf definitions.
-pub mod api {
- pub mod v1 {
- include!(concat!(env!("OUT_DIR"), "/api.v1.rs"));
- pub mod finality {
- include!(concat!(env!("OUT_DIR"), "/api.v1.finality.rs"));
- }
- pub mod light {
- include!(concat!(env!("OUT_DIR"), "/api.v1.light.rs"));
- }
- }
-}
-
mod generic_proto;
mod util;
-pub mod block_requests;
-pub mod finality_requests;
pub mod message;
pub mod event;
-pub mod light_client_handler;
pub mod sync;
-pub use block_requests::BlockRequests;
-pub use finality_requests::FinalityProofRequests;
-pub use light_client_handler::LightClientHandler;
pub use generic_proto::LegacyConnectionKillError;
const REQUEST_TIMEOUT_SEC: u64 = 40;
diff --git a/substrate/client/network/src/schema.rs b/substrate/client/network/src/schema.rs
new file mode 100644
index 0000000000..0c8a650e69
--- /dev/null
+++ b/substrate/client/network/src/schema.rs
@@ -0,0 +1,27 @@
+// Copyright 2017-2020 Parity Technologies (UK) Ltd.
+// This file is part of Substrate.
+
+// Substrate 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.
+
+// Substrate 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 Substrate. If not, see .
+
+//! Include sources generated from protobuf definitions.
+
+pub mod v1 {
+ include!(concat!(env!("OUT_DIR"), "/api.v1.rs"));
+ pub mod finality {
+ include!(concat!(env!("OUT_DIR"), "/api.v1.finality.rs"));
+ }
+ pub mod light {
+ include!(concat!(env!("OUT_DIR"), "/api.v1.light.rs"));
+ }
+}
diff --git a/substrate/client/network/src/protocol/schema/api.v1.proto b/substrate/client/network/src/schema/api.v1.proto
similarity index 100%
rename from substrate/client/network/src/protocol/schema/api.v1.proto
rename to substrate/client/network/src/schema/api.v1.proto
diff --git a/substrate/client/network/src/protocol/schema/finality.v1.proto b/substrate/client/network/src/schema/finality.v1.proto
similarity index 100%
rename from substrate/client/network/src/protocol/schema/finality.v1.proto
rename to substrate/client/network/src/schema/finality.v1.proto
diff --git a/substrate/client/network/src/protocol/schema/light.v1.proto b/substrate/client/network/src/schema/light.v1.proto
similarity index 100%
rename from substrate/client/network/src/protocol/schema/light.v1.proto
rename to substrate/client/network/src/schema/light.v1.proto
diff --git a/substrate/client/network/src/service.rs b/substrate/client/network/src/service.rs
index 3fbfd2dd14..64b3d3b5b2 100644
--- a/substrate/client/network/src/service.rs
+++ b/substrate/client/network/src/service.rs
@@ -35,7 +35,8 @@ use crate::{
NetworkState, NotConnectedPeer as NetworkStateNotConnectedPeer, Peer as NetworkStatePeer,
},
on_demand_layer::AlwaysBadChecker,
- protocol::{self, event::Event, light_client_handler, LegacyConnectionKillError, sync::SyncState, PeerInfo, Protocol},
+ light_client_handler, block_requests, finality_requests,
+ protocol::{self, event::Event, LegacyConnectionKillError, sync::SyncState, PeerInfo, Protocol},
transport, ReputationChange,
};
use futures::prelude::*;
@@ -223,16 +224,16 @@ impl NetworkWorker {
params.network_config.node_name
);
let block_requests = {
- let config = protocol::block_requests::Config::new(¶ms.protocol_id);
- protocol::BlockRequests::new(config, params.chain.clone())
+ let config = block_requests::Config::new(¶ms.protocol_id);
+ block_requests::BlockRequests::new(config, params.chain.clone())
};
let finality_proof_requests = {
- let config = protocol::finality_requests::Config::new(¶ms.protocol_id);
- protocol::FinalityProofRequests::new(config, params.finality_proof_provider.clone())
+ let config = finality_requests::Config::new(¶ms.protocol_id);
+ finality_requests::FinalityProofRequests::new(config, params.finality_proof_provider.clone())
};
let light_client_handler = {
- let config = protocol::light_client_handler::Config::new(¶ms.protocol_id);
- protocol::LightClientHandler::new(
+ let config = light_client_handler::Config::new(¶ms.protocol_id);
+ light_client_handler::LightClientHandler::new(
config,
params.chain,
checker,