mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-26 06:27:58 +00:00
Change on-the-wire protocol names to include genesis hash & fork id (#11938)
* Rename transactions protocol to include genesis hash
* Add protocol name generation to sc_network::utils
* Use utils functions for transactions protocol name generation
* Extract protocol name generation into public module
* Use sc_network::protocol_name::standard_protocol_name() for BEEFY and GRANDPA
* minor: add missing newline at EOF
* Change block-announces protocol name to include genesis_hash & fork_id
* Change protocol names to include genesis hash and fork id
Protocols changed:
- sync
- state
- light
- sync/warp
* Revert "Use sc_network::protocol_name::standard_protocol_name() for BEEFY and GRANDPA"
This reverts commit cd60a95a3face397e1b67f4bc95dd0f2b581bfae.
* Get rid of `protocol_name` module
This commit is contained in:
@@ -25,16 +25,31 @@ use sc_network_common::{config::ProtocolId, request_responses::ProtocolConfig};
|
||||
|
||||
use std::time::Duration;
|
||||
|
||||
/// Generate the light client protocol name from chain specific protocol identifier.
|
||||
fn generate_protocol_name(protocol_id: &ProtocolId) -> String {
|
||||
/// Generate the light client protocol name from the genesis hash and fork id.
|
||||
fn generate_protocol_name<Hash: AsRef<[u8]>>(genesis_hash: Hash, fork_id: Option<&str>) -> String {
|
||||
if let Some(fork_id) = fork_id {
|
||||
format!("/{}/{}/light/2", hex::encode(genesis_hash), fork_id)
|
||||
} else {
|
||||
format!("/{}/light/2", hex::encode(genesis_hash))
|
||||
}
|
||||
}
|
||||
|
||||
/// Generate the legacy light client protocol name from chain specific protocol identifier.
|
||||
fn generate_legacy_protocol_name(protocol_id: &ProtocolId) -> String {
|
||||
format!("/{}/light/2", protocol_id.as_ref())
|
||||
}
|
||||
|
||||
/// Generates a [`ProtocolConfig`] for the light client request protocol, refusing incoming
|
||||
/// requests.
|
||||
pub fn generate_protocol_config(protocol_id: &ProtocolId) -> ProtocolConfig {
|
||||
pub fn generate_protocol_config<Hash: AsRef<[u8]>>(
|
||||
protocol_id: &ProtocolId,
|
||||
genesis_hash: Hash,
|
||||
fork_id: Option<&str>,
|
||||
) -> ProtocolConfig {
|
||||
ProtocolConfig {
|
||||
name: generate_protocol_name(protocol_id).into(),
|
||||
name: generate_protocol_name(genesis_hash, fork_id).into(),
|
||||
fallback_names: std::iter::once(generate_legacy_protocol_name(protocol_id).into())
|
||||
.collect(),
|
||||
max_request_size: 1 * 1024 * 1024,
|
||||
max_response_size: 16 * 1024 * 1024,
|
||||
request_timeout: Duration::from_secs(15),
|
||||
|
||||
@@ -28,7 +28,7 @@ use futures::{channel::mpsc, prelude::*};
|
||||
use libp2p::PeerId;
|
||||
use log::{debug, trace};
|
||||
use prost::Message;
|
||||
use sc_client_api::{ProofProvider, StorageProof};
|
||||
use sc_client_api::{BlockBackend, ProofProvider, StorageProof};
|
||||
use sc_network_common::{
|
||||
config::ProtocolId,
|
||||
request_responses::{IncomingRequest, OutgoingResponse, ProtocolConfig},
|
||||
@@ -54,15 +54,27 @@ pub struct LightClientRequestHandler<B, Client> {
|
||||
impl<B, Client> LightClientRequestHandler<B, Client>
|
||||
where
|
||||
B: Block,
|
||||
Client: ProofProvider<B> + Send + Sync + 'static,
|
||||
Client: BlockBackend<B> + ProofProvider<B> + Send + Sync + 'static,
|
||||
{
|
||||
/// Create a new [`LightClientRequestHandler`].
|
||||
pub fn new(protocol_id: &ProtocolId, client: Arc<Client>) -> (Self, ProtocolConfig) {
|
||||
pub fn new(
|
||||
protocol_id: &ProtocolId,
|
||||
fork_id: Option<&str>,
|
||||
client: Arc<Client>,
|
||||
) -> (Self, ProtocolConfig) {
|
||||
// For now due to lack of data on light client request handling in production systems, this
|
||||
// value is chosen to match the block request limit.
|
||||
let (tx, request_receiver) = mpsc::channel(20);
|
||||
|
||||
let mut protocol_config = super::generate_protocol_config(protocol_id);
|
||||
let mut protocol_config = super::generate_protocol_config(
|
||||
protocol_id,
|
||||
client
|
||||
.block_hash(0u32.into())
|
||||
.ok()
|
||||
.flatten()
|
||||
.expect("Genesis block exists; qed"),
|
||||
fork_id,
|
||||
);
|
||||
protocol_config.inbound_queue = Some(tx);
|
||||
|
||||
(Self { client, request_receiver, _block: PhantomData::default() }, protocol_config)
|
||||
|
||||
Reference in New Issue
Block a user