Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion client/cli/src/params/network_params.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,11 @@ pub struct NetworkParams {
/// By default this option is true for `--dev` and false otherwise.
#[structopt(long)]
pub discover_local: bool,

/// Use the legacy "pre-mainnet-launch" networking protocol. Enable if things seem broken.
/// This option will be removed in the future.
#[structopt(long)]
pub legacy_network_protocol: bool,
}

impl NetworkParams {
Expand Down Expand Up @@ -147,7 +152,8 @@ impl NetworkParams {
use_yamux_flow_control: !self.no_yamux_flow_control,
},
max_parallel_downloads: self.max_parallel_downloads,
allow_non_globals_in_dht: self.discover_local || is_dev
allow_non_globals_in_dht: self.discover_local || is_dev,
use_new_block_requests_protocol: !self.legacy_network_protocol,
}
}
}
50 changes: 45 additions & 5 deletions client/network/src/behaviour.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,16 @@ use crate::{
debug_info, discovery::{DiscoveryBehaviour, DiscoveryConfig, DiscoveryOut},
Event, ObservedRole, DhtEvent, ExHashT,
};
use crate::protocol::{self, light_client_handler, message::Roles, CustomMessageOutcome, Protocol};
use crate::protocol::{
self, block_requests, light_client_handler, finality_requests,
message::{self, Roles}, CustomMessageOutcome, Protocol
};

use codec::Encode as _;
use libp2p::NetworkBehaviour;
use libp2p::core::{Multiaddr, PeerId, PublicKey};
use libp2p::kad::record;
use libp2p::swarm::{NetworkBehaviourAction, NetworkBehaviourEventProcess, PollParameters, toggle::Toggle};
use libp2p::swarm::{NetworkBehaviourAction, NetworkBehaviourEventProcess, PollParameters};
use log::debug;
use sp_consensus::{BlockOrigin, import_queue::{IncomingBlock, Origin}};
use sp_runtime::{traits::{Block as BlockT, NumberFor}, ConsensusEngineId, Justification};
Expand All @@ -46,7 +49,7 @@ pub struct Behaviour<B: BlockT, H: ExHashT> {
/// Block request handling.
block_requests: protocol::BlockRequests<B>,
/// Finality proof request handling.
finality_proof_requests: Toggle<protocol::FinalityProofRequests<B>>,
finality_proof_requests: protocol::FinalityProofRequests<B>,
/// Light client request handling.
light_client_handler: protocol::LightClientHandler<B>,

Expand Down Expand Up @@ -77,7 +80,7 @@ impl<B: BlockT, H: ExHashT> Behaviour<B, H> {
user_agent: String,
local_public_key: PublicKey,
block_requests: protocol::BlockRequests<B>,
finality_proof_requests: Option<protocol::FinalityProofRequests<B>>,
finality_proof_requests: protocol::FinalityProofRequests<B>,
light_client_handler: protocol::LightClientHandler<B>,
disco_config: DiscoveryConfig,
) -> Self {
Expand All @@ -86,7 +89,7 @@ impl<B: BlockT, H: ExHashT> Behaviour<B, H> {
debug_info: debug_info::DebugInfoBehaviour::new(user_agent, local_public_key.clone()),
discovery: disco_config.finish(),
block_requests,
finality_proof_requests: From::from(finality_proof_requests),
finality_proof_requests,
light_client_handler,
events: Vec::new(),
role,
Expand Down Expand Up @@ -216,6 +219,12 @@ Behaviour<B, H> {
self.events.push(BehaviourOut::JustificationImport(origin, hash, nb, justification)),
CustomMessageOutcome::FinalityProofImport(origin, hash, nb, proof) =>
self.events.push(BehaviourOut::FinalityProofImport(origin, hash, nb, proof)),
CustomMessageOutcome::BlockRequest { target, request } => {
self.block_requests.send_request(&target, request);
},
CustomMessageOutcome::FinalityProofRequest { target, block_hash, request } => {
self.finality_proof_requests.send_request(&target, block_hash, request);
},
CustomMessageOutcome::NotificationStreamOpened { remote, protocols, roles } => {
let role = reported_roles_to_observed_role(&self.role, &remote, roles);
for engine_id in protocols {
Expand Down Expand Up @@ -245,6 +254,37 @@ Behaviour<B, H> {
}
}

impl<B: BlockT, H: ExHashT> NetworkBehaviourEventProcess<block_requests::Event<B>> for Behaviour<B, H> {
fn inject_event(&mut self, event: block_requests::Event<B>) {
match event {
block_requests::Event::Response { peer, original_request, response } => {
let ev = self.substrate.on_block_response(peer, original_request, response);
self.inject_event(ev);
}
}
}
}

impl<B: BlockT, H: ExHashT> NetworkBehaviourEventProcess<finality_requests::Event<B>> for Behaviour<B, H> {
fn inject_event(&mut self, event: finality_requests::Event<B>) {
match event {
finality_requests::Event::Response { peer, block_hash, proof } => {
let response = message::FinalityProofResponse {
id: 0,
block: block_hash,
proof: if !proof.is_empty() {
Some(proof)
} else {
None
},
};
let ev = self.substrate.on_finality_proof_response(peer, response);
self.inject_event(ev);
}
}
}
}

impl<B: BlockT, H: ExHashT> NetworkBehaviourEventProcess<debug_info::DebugInfoEvent>
for Behaviour<B, H> {
fn inject_event(&mut self, event: debug_info::DebugInfoEvent) {
Expand Down
8 changes: 6 additions & 2 deletions client/network/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,10 @@ pub struct NetworkConfiguration {
/// Maximum number of peers to ask the same blocks in parallel.
pub max_parallel_downloads: u32,
/// Should we insert non-global addresses into the DHT?
pub allow_non_globals_in_dht: bool
pub allow_non_globals_in_dht: bool,
/// If true, uses the `/<chainid>/block-requests/<version>` experimental protocol rather than
/// the legacy substream. This option is meant to be hard-wired to `true` in the future.
pub use_new_block_requests_protocol: bool,
}

impl NetworkConfiguration {
Expand Down Expand Up @@ -430,7 +433,8 @@ impl NetworkConfiguration {
use_yamux_flow_control: false,
},
max_parallel_downloads: 5,
allow_non_globals_in_dht: false
allow_non_globals_in_dht: false,
use_new_block_requests_protocol: true,
}
}
}
Expand Down
Loading