Move block announcement protocol config out of Protocol (#12441)

* Move Role(s) to `sc-network-common`

* Introduce `NotificationHandshake` type

* Move block announce protocol config creation to `ChainSync`

* Include block announcement into `notification_protocols`

* Apply review comments

* Remove unneeded include

* Add missing include

* Apply review comments
This commit is contained in:
Aaro Altonen
2022-10-10 10:10:53 +03:00
committed by GitHub
parent 0b77060986
commit ce9ce49bc6
23 changed files with 439 additions and 263 deletions
+17 -2
View File
@@ -55,7 +55,7 @@ use sc_network_common::{
config::{
MultiaddrWithPeerId, NonDefaultSetConfig, NonReservedPeerMode, ProtocolId, TransportConfig,
},
protocol::ProtocolName,
protocol::{role::Roles, ProtocolName},
service::{NetworkBlock, NetworkStateInfo, NetworkSyncForkRequest},
sync::warp::{AuthorityList, EncodedProof, SetId, VerificationResult, WarpSyncProvider},
};
@@ -77,7 +77,7 @@ use sp_core::H256;
use sp_runtime::{
codec::{Decode, Encode},
generic::{BlockId, OpaqueDigestItemId},
traits::{Block as BlockT, Header as HeaderT, NumberFor},
traits::{Block as BlockT, Header as HeaderT, NumberFor, Zero},
Justification, Justifications,
};
use substrate_test_runtime_client::AccountKeyring;
@@ -802,6 +802,7 @@ where
notifications_protocol: p,
fallback_names: Vec::new(),
max_notification_size: 1024 * 1024,
handshake: None,
set_config: Default::default(),
})
.collect();
@@ -879,6 +880,19 @@ where
Some(warp_sync),
)
.unwrap();
let block_announce_config = chain_sync.get_block_announce_proto_config(
protocol_id.clone(),
&fork_id,
Roles::from(if config.is_authority { &Role::Authority } else { &Role::Full }),
client.info().best_number,
client.info().best_hash,
client
.block_hash(Zero::zero())
.ok()
.flatten()
.expect("Genesis block exists; qed"),
);
let network = NetworkWorker::new(sc_network::config::Params {
role: if config.is_authority { Role::Authority } else { Role::Full },
executor: None,
@@ -889,6 +903,7 @@ where
import_queue,
chain_sync: Box::new(chain_sync),
metrics_registry: None,
block_announce_config,
block_request_protocol_config,
state_request_protocol_config,
light_client_request_protocol_config,