mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-13 21:01:05 +00:00
network: Use "one shot" protocol handler. (#3520)
* network: Use "one shot" protocol handler. Add two new `NetworkBehaviour`s, one handling remote block requests and another one to handle light client requests (both local and from remote). The change is motivated by the desire to use multiple substreams of a single connection for different protocols. To achieve this, libp2p's `OneShotHandler` is used as a protocol handler in each behaviour. It will open a fresh substream for the duration of the request and close it afterwards. For block requests, we currently only handle incoming requests from remote and tests are missing. For light client handling we support incoming requests from remote and also ported a substantial amount of functionality over from `light_dispatch.rs` (including several tests). However the result lacks in at least two aspects: (1) We require external updates w.r.t. the best block per peer and currently nothing updates this information. (2) We carry a lot of peer-related state around. Both aspects could be simplified by externalising peer selection and just requiring a specific peer ID where the request should be sent to. We still have to maintain some peer related state due to the way libp2p's swarm and network behaviour work (e.g. we must make sure to always issue `NetworkBehaviourAction::SendEvent`s to peers we are connected to, otherwise the actions die a silent death. Another change implemented here is the use of protocol buffers as the encoding for network messages. Certain individual fields of messages are still SCALE encoded. There has been some discussion about this in another PR (https://github.com/paritytech/substrate/pull/3452), so far without resolution. * Uncomment `Behaviour::light_client_request`. * Add license headers.
This commit is contained in:
@@ -0,0 +1,354 @@
|
||||
// Copyright 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/>.
|
||||
|
||||
//! `NetworkBehaviour` implementation which handles incoming block requests.
|
||||
//!
|
||||
//! Every request is coming in on a separate connection substream which gets
|
||||
//! closed after we have sent the response back. Incoming requests are encoded
|
||||
//! as protocol buffers (cf. `api.v1.proto`).
|
||||
|
||||
#![allow(unused)]
|
||||
|
||||
use bytes::Bytes;
|
||||
use codec::{Encode, Decode};
|
||||
use crate::{
|
||||
chain::Client,
|
||||
config::ProtocolId,
|
||||
protocol::{api, message::BlockAttributes}
|
||||
};
|
||||
use futures::{future::BoxFuture, prelude::*, stream::FuturesUnordered};
|
||||
use libp2p::{
|
||||
core::{
|
||||
ConnectedPoint,
|
||||
Multiaddr,
|
||||
PeerId,
|
||||
upgrade::{InboundUpgrade, ReadOneError, UpgradeInfo, Negotiated},
|
||||
upgrade::{DeniedUpgrade, read_one, write_one}
|
||||
},
|
||||
swarm::{NetworkBehaviour, NetworkBehaviourAction, OneShotHandler, PollParameters, SubstreamProtocol}
|
||||
};
|
||||
use prost::Message;
|
||||
use sp_runtime::{generic::BlockId, traits::{Block, Header, One, Zero}};
|
||||
use std::{
|
||||
cmp::min,
|
||||
io,
|
||||
iter,
|
||||
sync::Arc,
|
||||
time::Duration,
|
||||
task::{Context, Poll}
|
||||
};
|
||||
use void::{Void, unreachable};
|
||||
|
||||
// Type alias for convenience.
|
||||
pub type Error = Box<dyn std::error::Error + 'static>;
|
||||
|
||||
/// Configuration options for `BlockRequests`.
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct Config {
|
||||
max_block_data_response: u32,
|
||||
max_request_len: usize,
|
||||
inactivity_timeout: Duration,
|
||||
protocol: Bytes,
|
||||
}
|
||||
|
||||
impl Config {
|
||||
/// Create a fresh configuration with the following options:
|
||||
///
|
||||
/// - max. block data in response = 128
|
||||
/// - max. request size = 1 MiB
|
||||
/// - inactivity timeout = 15s
|
||||
pub fn new(id: &ProtocolId) -> Self {
|
||||
let mut c = Config {
|
||||
max_block_data_response: 128,
|
||||
max_request_len: 1024 * 1024,
|
||||
inactivity_timeout: Duration::from_secs(15),
|
||||
protocol: Bytes::new(),
|
||||
};
|
||||
c.set_protocol(id);
|
||||
c
|
||||
}
|
||||
|
||||
/// Limit the max. number of block data in a response.
|
||||
pub fn set_max_block_data_response(&mut self, v: u32) -> &mut Self {
|
||||
self.max_block_data_response = v;
|
||||
self
|
||||
}
|
||||
|
||||
/// Limit the max. length of incoming block request bytes.
|
||||
pub fn set_max_request_len(&mut self, v: usize) -> &mut Self {
|
||||
self.max_request_len = v;
|
||||
self
|
||||
}
|
||||
|
||||
/// Limit the max. duration the substream may remain inactive before closing it.
|
||||
pub fn set_inactivity_timeout(&mut self, v: Duration) -> &mut Self {
|
||||
self.inactivity_timeout = v;
|
||||
self
|
||||
}
|
||||
|
||||
/// Set protocol to use for upgrade negotiation.
|
||||
pub fn set_protocol(&mut self, id: &ProtocolId) -> &mut Self {
|
||||
let mut v = Vec::new();
|
||||
v.extend_from_slice(b"/");
|
||||
v.extend_from_slice(id.as_bytes());
|
||||
v.extend_from_slice(b"/sync/1");
|
||||
self.protocol = v.into();
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
/// The block request handling behaviour.
|
||||
pub struct BlockRequests<T, B: Block> {
|
||||
/// This behaviour's configuration.
|
||||
config: Config,
|
||||
/// Blockchain client.
|
||||
chain: Arc<dyn Client<B>>,
|
||||
/// Futures sending back the block request response.
|
||||
outgoing: FuturesUnordered<BoxFuture<'static, ()>>,
|
||||
/// Type witness term.
|
||||
_marker: std::marker::PhantomData<T>
|
||||
}
|
||||
|
||||
impl<T, B> BlockRequests<T, B>
|
||||
where
|
||||
T: AsyncRead + AsyncWrite + Unpin + Send + 'static,
|
||||
B: Block,
|
||||
{
|
||||
pub fn new(cfg: Config, chain: Arc<dyn Client<B>>) -> Self {
|
||||
BlockRequests {
|
||||
config: cfg,
|
||||
chain,
|
||||
outgoing: FuturesUnordered::new(),
|
||||
_marker: std::marker::PhantomData
|
||||
}
|
||||
}
|
||||
|
||||
/// Callback, invoked when a new block request has been received from remote.
|
||||
fn on_block_request
|
||||
( &mut self
|
||||
, peer: &PeerId
|
||||
, request: &api::v1::BlockRequest
|
||||
) -> Result<api::v1::BlockResponse, Error>
|
||||
{
|
||||
log::trace!("block request {} from peer {}: from block {:?} to block {:?}, max blocks {:?}",
|
||||
request.id,
|
||||
peer,
|
||||
request.from_block,
|
||||
request.to_block,
|
||||
request.max_blocks);
|
||||
|
||||
let from_block_id =
|
||||
match request.from_block {
|
||||
Some(api::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)) => {
|
||||
let n = Decode::decode(&mut n.as_ref())?;
|
||||
BlockId::<B>::Number(n)
|
||||
}
|
||||
None => {
|
||||
let msg = "missing `BlockRequest::from_block` field";
|
||||
return Err(io::Error::new(io::ErrorKind::Other, msg).into())
|
||||
}
|
||||
};
|
||||
|
||||
let max_blocks =
|
||||
if request.max_blocks == 0 {
|
||||
self.config.max_block_data_response
|
||||
} else {
|
||||
min(request.max_blocks, self.config.max_block_data_response)
|
||||
};
|
||||
|
||||
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
|
||||
} else {
|
||||
let msg = format!("invalid `BlockRequest::direction` value: {}", request.direction);
|
||||
return Err(io::Error::new(io::ErrorKind::Other, msg).into())
|
||||
};
|
||||
|
||||
let attributes = BlockAttributes::decode(&mut request.fields.to_be_bytes().as_ref())?;
|
||||
let get_header = attributes.contains(BlockAttributes::HEADER);
|
||||
let get_body = attributes.contains(BlockAttributes::BODY);
|
||||
let get_justification = attributes.contains(BlockAttributes::JUSTIFICATION);
|
||||
|
||||
let mut blocks = Vec::new();
|
||||
let mut block_id = from_block_id;
|
||||
while let Some(header) = self.chain.header(&block_id).unwrap_or(None) {
|
||||
if blocks.len() >= max_blocks as usize {
|
||||
break
|
||||
}
|
||||
|
||||
let number = header.number().clone();
|
||||
let hash = header.hash();
|
||||
let parent_hash = header.parent_hash().clone();
|
||||
|
||||
let block_data = api::v1::BlockData {
|
||||
hash: hash.encode(),
|
||||
header: if get_header {
|
||||
header.encode()
|
||||
} else {
|
||||
Vec::new()
|
||||
},
|
||||
body: if get_body {
|
||||
self.chain.body(&BlockId::Hash(hash))?
|
||||
.unwrap_or(Vec::new())
|
||||
.iter_mut()
|
||||
.map(|extrinsic| extrinsic.encode())
|
||||
.collect()
|
||||
} else {
|
||||
Vec::new()
|
||||
},
|
||||
receipt: Vec::new(),
|
||||
message_queue: Vec::new(),
|
||||
justification: if get_justification {
|
||||
self.chain.justification(&BlockId::Hash(hash))?.unwrap_or(Vec::new())
|
||||
} else {
|
||||
Vec::new()
|
||||
}
|
||||
};
|
||||
|
||||
blocks.push(block_data);
|
||||
|
||||
match direction {
|
||||
api::v1::Direction::Ascending => {
|
||||
block_id = BlockId::Number(number + One::one())
|
||||
}
|
||||
api::v1::Direction::Descending => {
|
||||
if number.is_zero() {
|
||||
break
|
||||
}
|
||||
block_id = BlockId::Hash(parent_hash)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Ok(api::v1::BlockResponse { id: request.id, blocks })
|
||||
}
|
||||
}
|
||||
|
||||
impl<T, B> NetworkBehaviour for BlockRequests<T, B>
|
||||
where
|
||||
T: AsyncRead + AsyncWrite + Unpin + Send + 'static,
|
||||
B: Block
|
||||
{
|
||||
type ProtocolsHandler = OneShotHandler<T, Protocol, DeniedUpgrade, Request<Negotiated<T>>>;
|
||||
type OutEvent = Void;
|
||||
|
||||
fn new_handler(&mut self) -> Self::ProtocolsHandler {
|
||||
let p = Protocol {
|
||||
max_request_len: self.config.max_request_len,
|
||||
protocol: self.config.protocol.clone(),
|
||||
};
|
||||
OneShotHandler::new(SubstreamProtocol::new(p), self.config.inactivity_timeout)
|
||||
}
|
||||
|
||||
fn addresses_of_peer(&mut self, _: &PeerId) -> Vec<Multiaddr> {
|
||||
Vec::new()
|
||||
}
|
||||
|
||||
fn inject_connected(&mut self, _peer: PeerId, _info: ConnectedPoint) {
|
||||
}
|
||||
|
||||
fn inject_disconnected(&mut self, _peer: &PeerId, _info: ConnectedPoint) {
|
||||
}
|
||||
|
||||
fn inject_node_event(&mut self, peer: PeerId, Request(request, mut stream): Request<Negotiated<T>>) {
|
||||
match self.on_block_request(&peer, &request) {
|
||||
Ok(res) => {
|
||||
log::trace!("enqueueing block response {} for peer {} with {} blocks", res.id, peer, res.blocks.len());
|
||||
let mut data = Vec::with_capacity(res.encoded_len());
|
||||
if let Err(e) = res.encode(&mut data) {
|
||||
log::debug!("error encoding block response {} for peer {}: {}", res.id, peer, e)
|
||||
} else {
|
||||
let future = async move {
|
||||
if let Err(e) = write_one(&mut stream, data).await {
|
||||
log::debug!("error writing block response: {}", e)
|
||||
}
|
||||
};
|
||||
self.outgoing.push(future.boxed())
|
||||
}
|
||||
}
|
||||
Err(e) => log::debug!("error handling block request {} from peer {}: {}", request.id, peer, e)
|
||||
}
|
||||
}
|
||||
|
||||
fn poll(&mut self, cx: &mut Context, _: &mut impl PollParameters) -> Poll<NetworkBehaviourAction<DeniedUpgrade, Void>> {
|
||||
while let Poll::Ready(Some(_)) = self.outgoing.poll_next_unpin(cx) {}
|
||||
Poll::Pending
|
||||
}
|
||||
}
|
||||
|
||||
/// The incoming block request.
|
||||
///
|
||||
/// Holds the protobuf value and the connection substream which made the
|
||||
/// request and over which to send the response.
|
||||
#[derive(Debug)]
|
||||
pub struct Request<T>(api::v1::BlockRequest, T);
|
||||
|
||||
impl<T> From<Void> for Request<T> {
|
||||
fn from(v: Void) -> Self {
|
||||
unreachable(v)
|
||||
}
|
||||
}
|
||||
|
||||
/// Substream upgrade protocol.
|
||||
///
|
||||
/// We attempt to parse an incoming protobuf encoded request (cf. `Request`)
|
||||
/// which will be handled by the `BlockRequests` behaviour, i.e. the request
|
||||
/// will become visible via `inject_node_event` which then dispatches to the
|
||||
/// relevant callback to process the message and prepare a response.
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct Protocol {
|
||||
/// The max. request length in bytes.
|
||||
max_request_len: usize,
|
||||
/// The protocol to use during upgrade negotiation.
|
||||
protocol: Bytes,
|
||||
}
|
||||
|
||||
impl UpgradeInfo for Protocol {
|
||||
type Info = Bytes;
|
||||
type InfoIter = iter::Once<Self::Info>;
|
||||
|
||||
fn protocol_info(&self) -> Self::InfoIter {
|
||||
iter::once(self.protocol.clone())
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> InboundUpgrade<T> for Protocol
|
||||
where
|
||||
T: AsyncRead + AsyncWrite + Unpin + Send + 'static
|
||||
{
|
||||
type Output = Request<T>;
|
||||
type Error = ReadOneError;
|
||||
type Future = BoxFuture<'static, Result<Self::Output, Self::Error>>;
|
||||
|
||||
fn upgrade_inbound(self, mut s: T, _: Self::Info) -> Self::Future {
|
||||
let future = async move {
|
||||
let len = self.max_request_len;
|
||||
let vec = read_one(&mut s, len).await?;
|
||||
match api::v1::BlockRequest::decode(&vec[..]) {
|
||||
Ok(r) => Ok(Request(r, s)),
|
||||
Err(e) => Err(ReadOneError::Io(io::Error::new(io::ErrorKind::Other, e)))
|
||||
}
|
||||
};
|
||||
future.boxed()
|
||||
}
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -41,7 +41,7 @@ const REQUEST_TIMEOUT: Duration = Duration::from_secs(15);
|
||||
/// Default request retry count.
|
||||
const RETRY_COUNT: usize = 1;
|
||||
/// Reputation change for a peer when a request timed out.
|
||||
const TIMEOUT_REPUTATION_CHANGE: i32 = -(1 << 8);
|
||||
pub(crate) const TIMEOUT_REPUTATION_CHANGE: i32 = -(1 << 8);
|
||||
|
||||
/// Trait used by the `LightDispatch` service to communicate messages back to the network.
|
||||
pub trait LightDispatchNetwork<B: BlockT> {
|
||||
@@ -692,17 +692,26 @@ pub mod tests {
|
||||
use crate::message::{self, BlockAttributes, Direction, FromBlock, RequestId};
|
||||
use libp2p::PeerId;
|
||||
use super::{REQUEST_TIMEOUT, LightDispatch, LightDispatchNetwork, RequestData, StorageProof};
|
||||
use sp_test_primitives::{Block, Extrinsic, Header};
|
||||
use sp_test_primitives::{Block, Header};
|
||||
|
||||
struct DummyFetchChecker { ok: bool }
|
||||
pub(crate) struct DummyFetchChecker<B> {
|
||||
pub(crate) ok: bool,
|
||||
_mark: std::marker::PhantomData<B>
|
||||
}
|
||||
|
||||
impl FetchChecker<Block> for DummyFetchChecker {
|
||||
impl<B> DummyFetchChecker<B> {
|
||||
pub(crate) fn new(ok: bool) -> Self {
|
||||
DummyFetchChecker { ok, _mark: std::marker::PhantomData }
|
||||
}
|
||||
}
|
||||
|
||||
impl<B: BlockT> FetchChecker<B> for DummyFetchChecker<B> {
|
||||
fn check_header_proof(
|
||||
&self,
|
||||
_request: &RemoteHeaderRequest<Header>,
|
||||
header: Option<Header>,
|
||||
_request: &RemoteHeaderRequest<B::Header>,
|
||||
header: Option<B::Header>,
|
||||
_remote_proof: StorageProof,
|
||||
) -> ClientResult<Header> {
|
||||
) -> ClientResult<B::Header> {
|
||||
match self.ok {
|
||||
true if header.is_some() => Ok(header.unwrap()),
|
||||
_ => Err(ClientError::Backend("Test error".into())),
|
||||
@@ -711,7 +720,7 @@ pub mod tests {
|
||||
|
||||
fn check_read_proof(
|
||||
&self,
|
||||
request: &RemoteReadRequest<Header>,
|
||||
request: &RemoteReadRequest<B::Header>,
|
||||
_: StorageProof,
|
||||
) -> ClientResult<HashMap<Vec<u8>, Option<Vec<u8>>>> {
|
||||
match self.ok {
|
||||
@@ -727,7 +736,7 @@ pub mod tests {
|
||||
|
||||
fn check_read_child_proof(
|
||||
&self,
|
||||
request: &RemoteReadChildRequest<Header>,
|
||||
request: &RemoteReadChildRequest<B::Header>,
|
||||
_: StorageProof,
|
||||
) -> ClientResult<HashMap<Vec<u8>, Option<Vec<u8>>>> {
|
||||
match self.ok {
|
||||
@@ -741,7 +750,7 @@ pub mod tests {
|
||||
}
|
||||
}
|
||||
|
||||
fn check_execution_proof(&self, _: &RemoteCallRequest<Header>, _: StorageProof) -> ClientResult<Vec<u8>> {
|
||||
fn check_execution_proof(&self, _: &RemoteCallRequest<B::Header>, _: StorageProof) -> ClientResult<Vec<u8>> {
|
||||
match self.ok {
|
||||
true => Ok(vec![42]),
|
||||
false => Err(ClientError::Backend("Test error".into())),
|
||||
@@ -750,20 +759,20 @@ pub mod tests {
|
||||
|
||||
fn check_changes_proof(
|
||||
&self,
|
||||
_: &RemoteChangesRequest<Header>,
|
||||
_: ChangesProof<Header>
|
||||
) -> ClientResult<Vec<(NumberFor<Block>, u32)>> {
|
||||
_: &RemoteChangesRequest<B::Header>,
|
||||
_: ChangesProof<B::Header>
|
||||
) -> ClientResult<Vec<(NumberFor<B>, u32)>> {
|
||||
match self.ok {
|
||||
true => Ok(vec![(100, 2)]),
|
||||
true => Ok(vec![(100.into(), 2)]),
|
||||
false => Err(ClientError::Backend("Test error".into())),
|
||||
}
|
||||
}
|
||||
|
||||
fn check_body_proof(
|
||||
&self,
|
||||
_: &RemoteBodyRequest<Header>,
|
||||
body: Vec<Extrinsic>
|
||||
) -> ClientResult<Vec<Extrinsic>> {
|
||||
_: &RemoteBodyRequest<B::Header>,
|
||||
body: Vec<B::Extrinsic>
|
||||
) -> ClientResult<Vec<B::Extrinsic>> {
|
||||
match self.ok {
|
||||
true => Ok(body),
|
||||
false => Err(ClientError::Backend("Test error".into())),
|
||||
@@ -772,7 +781,7 @@ pub mod tests {
|
||||
}
|
||||
|
||||
fn dummy(ok: bool) -> LightDispatch<Block> {
|
||||
LightDispatch::new(Arc::new(DummyFetchChecker { ok }))
|
||||
LightDispatch::new(Arc::new(DummyFetchChecker::new(ok)))
|
||||
}
|
||||
|
||||
fn total_peers(light_dispatch: &LightDispatch<Block>) -> usize {
|
||||
@@ -791,7 +800,7 @@ pub mod tests {
|
||||
});
|
||||
}
|
||||
|
||||
fn dummy_header() -> Header {
|
||||
pub(crate) fn dummy_header() -> Header {
|
||||
Header {
|
||||
parent_hash: Default::default(),
|
||||
number: 0,
|
||||
|
||||
@@ -0,0 +1,59 @@
|
||||
// Schema definition for block request/response messages.
|
||||
|
||||
syntax = "proto3";
|
||||
|
||||
package api.v1;
|
||||
|
||||
// Block enumeration direction.
|
||||
enum Direction {
|
||||
// Enumerate in ascending order (from child to parent).
|
||||
Ascending = 0;
|
||||
// Enumerate in descendfing order (from parent to canonical child).
|
||||
Descending = 1;
|
||||
}
|
||||
|
||||
// Request block data from a peer.
|
||||
message BlockRequest {
|
||||
// Unique request id.
|
||||
uint64 id = 1;
|
||||
// Bits of block data to request.
|
||||
uint32 fields = 2;
|
||||
// Start from this block.
|
||||
oneof from_block {
|
||||
// Start with given hash.
|
||||
bytes hash = 3;
|
||||
// Start with given block number.
|
||||
bytes number = 4;
|
||||
}
|
||||
// End at this block. An implementation defined maximum is used when unspecified.
|
||||
bytes to_block = 5; // optional
|
||||
// Sequence direction.
|
||||
Direction direction = 6;
|
||||
// Maximum number of blocks to return. An implementation defined maximum is used when unspecified.
|
||||
uint32 max_blocks = 7; // optional
|
||||
}
|
||||
|
||||
// Response to `BlockRequest`
|
||||
message BlockResponse {
|
||||
// Id of a request this response was made for.
|
||||
uint64 id = 1;
|
||||
// Block data for the requested sequence.
|
||||
repeated BlockData blocks = 2;
|
||||
}
|
||||
|
||||
// Block data sent in the response.
|
||||
message BlockData {
|
||||
// Block header hash.
|
||||
bytes hash = 1;
|
||||
// Block header if requested.
|
||||
bytes header = 2; // optional
|
||||
// Block body if requested.
|
||||
repeated bytes body = 3; // optional
|
||||
// Block receipt if requested.
|
||||
bytes receipt = 4; // optional
|
||||
// Block message queue if requested.
|
||||
bytes message_queue = 5; // optional
|
||||
// Justification if requested.
|
||||
bytes justification = 6; // optional
|
||||
}
|
||||
|
||||
@@ -0,0 +1,128 @@
|
||||
// Schema definition for light client messages.
|
||||
|
||||
syntax = "proto3";
|
||||
|
||||
package api.v1.light;
|
||||
|
||||
// A pair of arbitrary bytes.
|
||||
message Pair {
|
||||
// The first element of the pair.
|
||||
bytes fst = 1;
|
||||
// The second element of the pair.
|
||||
bytes snd = 2;
|
||||
}
|
||||
|
||||
// Enumerate all possible light client request messages.
|
||||
message Request {
|
||||
// Unique request id.
|
||||
uint64 id = 1;
|
||||
oneof request {
|
||||
RemoteCallRequest remote_call_request = 2;
|
||||
RemoteReadRequest remote_read_request = 3;
|
||||
RemoteHeaderRequest remote_header_request = 4;
|
||||
RemoteReadChildRequest remote_read_child_request = 5;
|
||||
RemoteChangesRequest remote_changes_request = 6;
|
||||
}
|
||||
}
|
||||
|
||||
// Enumerate all possible light client response messages.
|
||||
message Response {
|
||||
/// Id of a request this response was made for.
|
||||
uint64 id = 1;
|
||||
oneof response {
|
||||
RemoteCallResponse remote_call_response = 2;
|
||||
RemoteReadResponse remote_read_response = 3;
|
||||
RemoteHeaderResponse remote_header_response = 4;
|
||||
RemoteChangesResponse remote_changes_response = 6;
|
||||
}
|
||||
}
|
||||
|
||||
// Remote call request.
|
||||
message RemoteCallRequest {
|
||||
// Block at which to perform call.
|
||||
bytes block = 2;
|
||||
// Method name.
|
||||
string method = 3;
|
||||
// Call data.
|
||||
bytes data = 4;
|
||||
}
|
||||
|
||||
// Remote call response.
|
||||
message RemoteCallResponse {
|
||||
// Execution proof.
|
||||
bytes proof = 2;
|
||||
}
|
||||
|
||||
// Remote storage read request.
|
||||
message RemoteReadRequest {
|
||||
// Block at which to perform call.
|
||||
bytes block = 2;
|
||||
// Storage keys.
|
||||
repeated bytes keys = 3;
|
||||
}
|
||||
|
||||
// Remote read response.
|
||||
message RemoteReadResponse {
|
||||
// Read proof.
|
||||
bytes proof = 2;
|
||||
}
|
||||
|
||||
// Remote storage read child request.
|
||||
message RemoteReadChildRequest {
|
||||
// Block at which to perform call.
|
||||
bytes block = 2;
|
||||
// Child Storage key.
|
||||
bytes storage_key = 3;
|
||||
// Child trie source information.
|
||||
bytes child_info = 4;
|
||||
/// Child type, its required to resolve `child_info`
|
||||
/// content and choose child implementation.
|
||||
uint32 child_type = 5;
|
||||
// Storage keys.
|
||||
repeated bytes keys = 6;
|
||||
}
|
||||
|
||||
// Remote header request.
|
||||
message RemoteHeaderRequest {
|
||||
// Block number to request header for.
|
||||
bytes block = 2;
|
||||
}
|
||||
|
||||
// Remote header response.
|
||||
message RemoteHeaderResponse {
|
||||
// Header. None if proof generation has failed (e.g. header is unknown).
|
||||
bytes header = 2; // optional
|
||||
// Header proof.
|
||||
bytes proof = 3;
|
||||
}
|
||||
|
||||
/// Remote changes request.
|
||||
message RemoteChangesRequest {
|
||||
// Hash of the first block of the range (including first) where changes are requested.
|
||||
bytes first = 2;
|
||||
// Hash of the last block of the range (including last) where changes are requested.
|
||||
bytes last = 3;
|
||||
// Hash of the first block for which the requester has the changes trie root. All other
|
||||
// affected roots must be proved.
|
||||
bytes min = 4;
|
||||
// Hash of the last block that we can use when querying changes.
|
||||
bytes max = 5;
|
||||
// Storage child node key which changes are requested.
|
||||
bytes storage_key = 6; // optional
|
||||
// Storage key which changes are requested.
|
||||
bytes key = 7;
|
||||
}
|
||||
|
||||
// Remote changes response.
|
||||
message RemoteChangesResponse {
|
||||
// Proof has been generated using block with this number as a max block. Should be
|
||||
// less than or equal to the RemoteChangesRequest::max block number.
|
||||
bytes max = 2;
|
||||
// Changes proof.
|
||||
repeated bytes proof = 3;
|
||||
// Changes tries roots missing on the requester' node.
|
||||
repeated Pair roots = 4;
|
||||
// Missing changes tries roots proof.
|
||||
bytes roots_proof = 5;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user