mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-12 22:51:13 +00:00
Rename on_demand to light_dispatch and various minor changes (#3315)
* Rename on_demand to light_server * Small docs improvement * Rename on_block_announce to update_best_number * More minor documentation * Light server -> light dispatch * is_light_rq_response -> is_light_response
This commit is contained in:
committed by
Gavin Wood
parent
87e72d9327
commit
b5b1c2a4d8
@@ -34,7 +34,7 @@ use message::{BlockAttributes, Direction, FromBlock, Message, RequestId};
|
||||
use message::generic::{Message as GenericMessage, ConsensusMessage};
|
||||
use event::Event;
|
||||
use consensus_gossip::{ConsensusGossip, MessageRecipient as GossipMessageRecipient};
|
||||
use on_demand::{OnDemandCore, OnDemandNetwork, RequestData};
|
||||
use light_dispatch::{LightDispatch, LightDispatchNetwork, RequestData};
|
||||
use specialization::NetworkSpecialization;
|
||||
use sync::{ChainSync, SyncState};
|
||||
use crate::service::{TransactionPool, ExHashT};
|
||||
@@ -53,7 +53,7 @@ mod util;
|
||||
pub mod consensus_gossip;
|
||||
pub mod message;
|
||||
pub mod event;
|
||||
pub mod on_demand;
|
||||
pub mod light_dispatch;
|
||||
pub mod specialization;
|
||||
pub mod sync;
|
||||
|
||||
@@ -96,8 +96,8 @@ pub struct Protocol<B: BlockT, S: NetworkSpecialization<B>, H: ExHashT> {
|
||||
/// Interval at which we call `propagate_extrinsics`.
|
||||
propagate_timeout: Box<dyn Stream<Item = (), Error = ()> + Send>,
|
||||
config: ProtocolConfig,
|
||||
/// Handler for on-demand requests.
|
||||
on_demand_core: OnDemandCore<B>,
|
||||
/// Handler for light client requests.
|
||||
light_dispatch: LightDispatch<B>,
|
||||
genesis_hash: B::Hash,
|
||||
sync: ChainSync<B>,
|
||||
specialization: S,
|
||||
@@ -149,12 +149,12 @@ pub struct PeerInfo<B: BlockT> {
|
||||
pub best_number: <B::Header as HeaderT>::Number,
|
||||
}
|
||||
|
||||
struct OnDemandIn<'a, B: BlockT> {
|
||||
struct LightDispatchIn<'a, B: BlockT> {
|
||||
behaviour: &'a mut CustomProto<B, Substream<StreamMuxerBox>>,
|
||||
peerset: peerset::PeersetHandle,
|
||||
}
|
||||
|
||||
impl<'a, B: BlockT> OnDemandNetwork<B> for OnDemandIn<'a, B> {
|
||||
impl<'a, B: BlockT> LightDispatchNetwork<B> for LightDispatchIn<'a, B> {
|
||||
fn report_peer(&mut self, who: &PeerId, reputation: i32) {
|
||||
self.peerset.report_peer(who.clone(), reputation)
|
||||
}
|
||||
@@ -373,7 +373,7 @@ impl<B: BlockT, S: NetworkSpecialization<B>, H: ExHashT> Protocol<B, S, H> {
|
||||
peers: HashMap::new(),
|
||||
chain,
|
||||
},
|
||||
on_demand_core: OnDemandCore::new(checker),
|
||||
light_dispatch: LightDispatch::new(checker),
|
||||
genesis_hash: info.chain.genesis_hash,
|
||||
sync,
|
||||
specialization: specialization,
|
||||
@@ -445,15 +445,15 @@ impl<B: BlockT, S: NetworkSpecialization<B>, H: ExHashT> Protocol<B, S, H> {
|
||||
/// Starts a new data demand request.
|
||||
///
|
||||
/// The parameter contains a `Sender` where the result, once received, must be sent.
|
||||
pub(crate) fn add_on_demand_request(&mut self, rq: RequestData<B>) {
|
||||
self.on_demand_core.add_request(OnDemandIn {
|
||||
pub(crate) fn add_light_client_request(&mut self, rq: RequestData<B>) {
|
||||
self.light_dispatch.add_request(LightDispatchIn {
|
||||
behaviour: &mut self.behaviour,
|
||||
peerset: self.peerset_handle.clone(),
|
||||
}, rq);
|
||||
}
|
||||
|
||||
fn is_on_demand_response(&self, who: &PeerId, response_id: message::RequestId) -> bool {
|
||||
self.on_demand_core.is_on_demand_response(&who, response_id)
|
||||
fn is_light_response(&self, who: &PeerId, response_id: message::RequestId) -> bool {
|
||||
self.light_dispatch.is_light_response(&who, response_id)
|
||||
}
|
||||
|
||||
fn handle_response(
|
||||
@@ -506,7 +506,7 @@ impl<B: BlockT, S: NetworkSpecialization<B>, H: ExHashT> Protocol<B, S, H> {
|
||||
GenericMessage::BlockRequest(r) => self.on_block_request(who, r),
|
||||
GenericMessage::BlockResponse(r) => {
|
||||
// Note, this is safe because only `ordinary bodies` and `remote bodies` are received in this matter.
|
||||
if self.is_on_demand_response(&who, r.id) {
|
||||
if self.is_light_response(&who, r.id) {
|
||||
self.on_remote_body_response(who, r);
|
||||
} else {
|
||||
if let Some(request) = self.handle_response(who.clone(), &r) {
|
||||
@@ -629,7 +629,7 @@ impl<B: BlockT, S: NetworkSpecialization<B>, H: ExHashT> Protocol<B, S, H> {
|
||||
}
|
||||
self.sync.peer_disconnected(peer.clone());
|
||||
self.specialization.on_disconnect(&mut context, peer.clone());
|
||||
self.on_demand_core.on_disconnect(OnDemandIn {
|
||||
self.light_dispatch.on_disconnect(LightDispatchIn {
|
||||
behaviour: &mut self.behaviour,
|
||||
peerset: self.peerset_handle.clone(),
|
||||
}, peer);
|
||||
@@ -793,7 +793,7 @@ impl<B: BlockT, S: NetworkSpecialization<B>, H: ExHashT> Protocol<B, S, H> {
|
||||
&mut ProtocolContext::new(&mut self.context_data, &mut self.behaviour, &self.peerset_handle)
|
||||
);
|
||||
self.maintain_peers();
|
||||
self.on_demand_core.maintain_peers(OnDemandIn {
|
||||
self.light_dispatch.maintain_peers(LightDispatchIn {
|
||||
behaviour: &mut self.behaviour,
|
||||
peerset: self.peerset_handle.clone(),
|
||||
});
|
||||
@@ -914,7 +914,7 @@ impl<B: BlockT, S: NetworkSpecialization<B>, H: ExHashT> Protocol<B, S, H> {
|
||||
};
|
||||
|
||||
let info = self.context_data.peers.get(&who).expect("We just inserted above; QED").info.clone();
|
||||
self.on_demand_core.on_connect(OnDemandIn {
|
||||
self.light_dispatch.on_connect(LightDispatchIn {
|
||||
behaviour: &mut self.behaviour,
|
||||
peerset: self.peerset_handle.clone(),
|
||||
}, who.clone(), status.roles, status.best_number);
|
||||
@@ -1053,7 +1053,7 @@ impl<B: BlockT, S: NetworkSpecialization<B>, H: ExHashT> Protocol<B, S, H> {
|
||||
peer.known_blocks.insert(hash.clone());
|
||||
}
|
||||
}
|
||||
self.on_demand_core.on_block_announce(OnDemandIn {
|
||||
self.light_dispatch.update_best_number(LightDispatchIn {
|
||||
behaviour: &mut self.behaviour,
|
||||
peerset: self.peerset_handle.clone(),
|
||||
}, who.clone(), *header.number());
|
||||
@@ -1253,7 +1253,7 @@ impl<B: BlockT, S: NetworkSpecialization<B>, H: ExHashT> Protocol<B, S, H> {
|
||||
response: message::RemoteCallResponse
|
||||
) {
|
||||
trace!(target: "sync", "Remote call response {} from {}", response.id, who);
|
||||
self.on_demand_core.on_remote_call_response(OnDemandIn {
|
||||
self.light_dispatch.on_remote_call_response(LightDispatchIn {
|
||||
behaviour: &mut self.behaviour,
|
||||
peerset: self.peerset_handle.clone(),
|
||||
}, who, response);
|
||||
@@ -1294,7 +1294,7 @@ impl<B: BlockT, S: NetworkSpecialization<B>, H: ExHashT> Protocol<B, S, H> {
|
||||
response: message::RemoteReadResponse
|
||||
) {
|
||||
trace!(target: "sync", "Remote read response {} from {}", response.id, who);
|
||||
self.on_demand_core.on_remote_read_response(OnDemandIn {
|
||||
self.light_dispatch.on_remote_read_response(LightDispatchIn {
|
||||
behaviour: &mut self.behaviour,
|
||||
peerset: self.peerset_handle.clone(),
|
||||
}, who, response);
|
||||
@@ -1335,7 +1335,7 @@ impl<B: BlockT, S: NetworkSpecialization<B>, H: ExHashT> Protocol<B, S, H> {
|
||||
response: message::RemoteHeaderResponse<B::Header>,
|
||||
) {
|
||||
trace!(target: "sync", "Remote header proof response {} from {}", response.id, who);
|
||||
self.on_demand_core.on_remote_header_response(OnDemandIn {
|
||||
self.light_dispatch.on_remote_header_response(LightDispatchIn {
|
||||
behaviour: &mut self.behaviour,
|
||||
peerset: self.peerset_handle.clone(),
|
||||
}, who, response);
|
||||
@@ -1401,7 +1401,7 @@ impl<B: BlockT, S: NetworkSpecialization<B>, H: ExHashT> Protocol<B, S, H> {
|
||||
who,
|
||||
response.max
|
||||
);
|
||||
self.on_demand_core.on_remote_changes_response(OnDemandIn {
|
||||
self.light_dispatch.on_remote_changes_response(LightDispatchIn {
|
||||
behaviour: &mut self.behaviour,
|
||||
peerset: self.peerset_handle.clone(),
|
||||
}, who, response);
|
||||
@@ -1462,7 +1462,7 @@ impl<B: BlockT, S: NetworkSpecialization<B>, H: ExHashT> Protocol<B, S, H> {
|
||||
peer: PeerId,
|
||||
response: message::BlockResponse<B>
|
||||
) {
|
||||
self.on_demand_core.on_remote_body_response(OnDemandIn {
|
||||
self.light_dispatch.on_remote_body_response(LightDispatchIn {
|
||||
behaviour: &mut self.behaviour,
|
||||
peerset: self.peerset_handle.clone(),
|
||||
}, peer, response);
|
||||
|
||||
Reference in New Issue
Block a user