Move around stuff in sc_network (#5847)

This commit is contained in:
Pierre Krieger
2020-04-30 15:08:38 +02:00
committed by GitHub
parent c09bb1f350
commit 929bd07bef
13 changed files with 172 additions and 160 deletions
+4 -4
View File
@@ -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();
}
+8 -12
View File
@@ -15,14 +15,11 @@
// along with Substrate. If not, see <http://www.gnu.org/licenses/>.
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<B: BlockT, H: ExHashT> {
/// Discovers nodes of the network.
discovery: DiscoveryBehaviour,
/// Block request handling.
block_requests: protocol::BlockRequests<B>,
block_requests: block_requests::BlockRequests<B>,
/// Finality proof request handling.
finality_proof_requests: protocol::FinalityProofRequests<B>,
finality_proof_requests: finality_requests::FinalityProofRequests<B>,
/// Light client request handling.
light_client_handler: protocol::LightClientHandler<B>,
light_client_handler: light_client_handler::LightClientHandler<B>,
/// Queue of events to produce for the outside.
#[behaviour(ignore)]
@@ -110,9 +106,9 @@ impl<B: BlockT, H: ExHashT> Behaviour<B, H> {
role: Role,
user_agent: String,
local_public_key: PublicKey,
block_requests: protocol::BlockRequests<B>,
finality_proof_requests: protocol::FinalityProofRequests<B>,
light_client_handler: protocol::LightClientHandler<B>,
block_requests: block_requests::BlockRequests<B>,
finality_proof_requests: finality_requests::FinalityProofRequests<B>,
light_client_handler: light_client_handler::LightClientHandler<B>,
disco_config: DiscoveryConfig,
) -> Self {
Behaviour {
@@ -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<api::v1::BlockResponse, Error>
, request: &schema::v1::BlockRequest
) -> Result<schema::v1::BlockResponse, Error>
{
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::<B>::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::<B>::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<B: Block, T> {
/// 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<B>, api::v1::BlockResponse),
Response(message::BlockRequest<B>, 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))
@@ -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<u8>) {
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<api::v1::finality::FinalityProofResponse, Error>
fn on_finality_request(&mut self, peer: &PeerId, request: &schema::v1::finality::FinalityProofRequest)
-> Result<schema::v1::finality::FinalityProofResponse, Error>
{
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<B: Block, T> {
/// 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))
+4
View File
@@ -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;
@@ -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<B>
, response: api::v1::light::Response
, response: schema::v1::light::Response
) -> Result<Reply<B>, 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<B>
, response: api::v1::BlockResponse
, response: schema::v1::BlockResponse
) -> Result<Reply<B>, 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<api::v1::light::Response, Error>
, request: &schema::v1::light::RemoteCallRequest
) -> Result<schema::v1::light::Response, Error>
{
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<api::v1::light::Response, Error>
, request: &schema::v1::light::RemoteReadRequest
) -> Result<schema::v1::light::Response, Error>
{
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<api::v1::light::Response, Error>
, request: &schema::v1::light::RemoteReadChildRequest
) -> Result<schema::v1::light::Response, Error>
{
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<api::v1::light::Response, Error>
, request: &schema::v1::light::RemoteHeaderRequest
) -> Result<schema::v1::light::Response, Error>
{
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<api::v1::light::Response, Error>
, request: &schema::v1::light::RemoteChangesRequest
) -> Result<schema::v1::light::Response, Error>
{
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<B: Block>(request: &Request<B>) -> usize {
fn serialize_request<B: Block>(request: &Request<B>) -> Result<Vec<u8>, 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<B: Block>(request: &Request<B>) -> Result<Vec<u8>, 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<B: Block>(request: &Request<B>) -> Result<Vec<u8>, 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<B: Block>(result: Result<Reply<B>, ClientError>, request: Request<
#[derive(Debug)]
pub enum Event<T> {
/// 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<T> {
#[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)),
}
}
};
@@ -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;
-19
View File
@@ -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;
+27
View File
@@ -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 <http://www.gnu.org/licenses/>.
//! 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"));
}
}
+8 -7
View File
@@ -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<B: BlockT + 'static, H: ExHashT> NetworkWorker<B, H> {
params.network_config.node_name
);
let block_requests = {
let config = protocol::block_requests::Config::new(&params.protocol_id);
protocol::BlockRequests::new(config, params.chain.clone())
let config = block_requests::Config::new(&params.protocol_id);
block_requests::BlockRequests::new(config, params.chain.clone())
};
let finality_proof_requests = {
let config = protocol::finality_requests::Config::new(&params.protocol_id);
protocol::FinalityProofRequests::new(config, params.finality_proof_provider.clone())
let config = finality_requests::Config::new(&params.protocol_id);
finality_requests::FinalityProofRequests::new(config, params.finality_proof_provider.clone())
};
let light_client_handler = {
let config = protocol::light_client_handler::Config::new(&params.protocol_id);
protocol::LightClientHandler::new(
let config = light_client_handler::Config::new(&params.protocol_id);
light_client_handler::LightClientHandler::new(
config,
params.chain,
checker,