Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Remove av-store, av-distribution, chain-api subsystems from minimal node #1903

Merged
merged 11 commits into from
Nov 27, 2022
2 changes: 0 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 0 additions & 2 deletions client/relay-chain-minimal-node/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ polkadot-service = { git = "https://github.com/paritytech/polkadot", branch = "m
polkadot-node-subsystem-util = { git = "https://github.com/paritytech/polkadot", branch = "master" }
polkadot-node-network-protocol = { git = "https://github.com/paritytech/polkadot", branch = "master" }
polkadot-network-bridge = { git = "https://github.com/paritytech/polkadot", branch = "master" }
polkadot-node-core-av-store = { git = "https://github.com/paritytech/polkadot", branch = "master" }
polkadot-availability-distribution = { git = "https://github.com/paritytech/polkadot", branch = "master" }

# substrate deps
sc-authority-discovery = { git = "https://github.com/paritytech/substrate", branch = "master" }
Expand Down
47 changes: 9 additions & 38 deletions client/relay-chain-minimal-node/src/collator_overseer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,10 @@

use cumulus_relay_chain_interface::RelayChainError;
use lru::LruCache;
use polkadot_availability_distribution::{
AvailabilityDistributionSubsystem, IncomingRequestReceivers,
};
use polkadot_node_core_av_store::Config;
use polkadot_node_network_protocol::{
peer_set::PeerSetProtocolNames,
request_response::{
v1::{
AvailableDataFetchingRequest, ChunkFetchingRequest, CollationFetchingRequest,
PoVFetchingRequest,
},
v1::{AvailableDataFetchingRequest, CollationFetchingRequest},
IncomingRequestReceiver, ReqProtocolNames,
},
};
Expand All @@ -38,14 +31,13 @@ use polkadot_overseer::{
use polkadot_primitives::v2::CollatorPair;
use polkadot_service::{
overseer::{
AvailabilityRecoverySubsystem, AvailabilityStoreSubsystem, ChainApiSubsystem,
CollationGenerationSubsystem, CollatorProtocolSubsystem, NetworkBridgeMetrics,
NetworkBridgeRxSubsystem, NetworkBridgeTxSubsystem, ProtocolSide, RuntimeApiSubsystem,
AvailabilityRecoverySubsystem, CollationGenerationSubsystem, CollatorProtocolSubsystem,
NetworkBridgeMetrics, NetworkBridgeRxSubsystem, NetworkBridgeTxSubsystem, ProtocolSide,
RuntimeApiSubsystem,
},
Error, OverseerConnector,
};
use sc_authority_discovery::Service as AuthorityDiscoveryService;
use sc_keystore::LocalKeystore;
use sc_network::NetworkStateInfo;

use std::sync::Arc;
Expand All @@ -66,13 +58,9 @@ pub(crate) struct CollatorOverseerGenArgs<'a> {
pub network_service: Arc<sc_network::NetworkService<Block, PHash>>,
/// Underlying authority discovery service.
pub authority_discovery_service: AuthorityDiscoveryService,
// Receiver for collation request protocol
/// Receiver for collation request protocol
pub collation_req_receiver: IncomingRequestReceiver<CollationFetchingRequest>,
// Receiver for PoV request protocol
pub pov_req_receiver: IncomingRequestReceiver<PoVFetchingRequest>,
// Receiver for chunk request protocol
pub chunk_req_receiver: IncomingRequestReceiver<ChunkFetchingRequest>,
// Receiver for availability request protocol
/// Receiver for availability request protocol
pub available_data_req_receiver: IncomingRequestReceiver<AvailableDataFetchingRequest>,
/// Prometheus registry, commonly used for production systems, less so for test.
pub registry: Option<&'a Registry>,
Expand All @@ -84,10 +72,6 @@ pub(crate) struct CollatorOverseerGenArgs<'a> {
pub req_protocol_names: ReqProtocolNames,
/// Peerset protocols name mapping
pub peer_set_protocol_names: PeerSetProtocolNames,
/// Config for the availability store
pub availability_config: Config,
/// The underlying key value store for the parachains.
pub parachains_db: Arc<dyn polkadot_node_subsystem_util::database::Database>,
}

fn build_overseer<'a>(
Expand All @@ -98,46 +82,33 @@ fn build_overseer<'a>(
authority_discovery_service,
collation_req_receiver,
available_data_req_receiver,
availability_config,
registry,
spawner,
collator_pair,
req_protocol_names,
peer_set_protocol_names,
parachains_db,
pov_req_receiver,
chunk_req_receiver,
}: CollatorOverseerGenArgs<'a>,
) -> Result<
(Overseer<SpawnGlue<sc_service::SpawnTaskHandle>, Arc<BlockChainRpcClient>>, OverseerHandle),
Error,
> {
let leaves = Vec::new();
let metrics = <OverseerMetrics as MetricsTrait>::register(registry)?;
let keystore = Arc::new(LocalKeystore::in_memory());
let spawner = SpawnGlue(spawner);
let network_bridge_metrics: NetworkBridgeMetrics = Metrics::register(registry)?;
let builder = Overseer::builder()
.availability_distribution(AvailabilityDistributionSubsystem::new(
keystore.clone(),
IncomingRequestReceivers { pov_req_receiver, chunk_req_receiver },
Metrics::register(registry)?,
))
.availability_distribution(DummySubsystem)
.availability_recovery(AvailabilityRecoverySubsystem::with_chunks_only(
available_data_req_receiver,
Metrics::register(registry)?,
))
.availability_store(AvailabilityStoreSubsystem::new(
parachains_db.clone(),
availability_config,
Metrics::register(registry)?,
))
.availability_store(DummySubsystem)
.bitfield_distribution(DummySubsystem)
.bitfield_signing(DummySubsystem)
.candidate_backing(DummySubsystem)
.candidate_validation(DummySubsystem)
.pvf_checker(DummySubsystem)
.chain_api(ChainApiSubsystem::new(runtime_client.clone(), Metrics::register(registry)?))
.chain_api(DummySubsystem)
.collation_generation(CollationGenerationSubsystem::new(Metrics::register(registry)?))
.collator_protocol({
let side = ProtocolSide::Collator(
Expand Down
57 changes: 41 additions & 16 deletions client/relay-chain-minimal-node/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,10 @@ use cumulus_relay_chain_rpc_interface::{RelayChainRpcInterface, Url};
use polkadot_network_bridge::{peer_sets_info, IsAuthority};
use polkadot_node_network_protocol::{
peer_set::PeerSetProtocolNames,
request_response::{self, IncomingRequest, ReqProtocolNames},
request_response::{v1, IncomingRequest, IncomingRequestReceiver, ReqProtocolNames},
UnifiedReputationChange,
};

use polkadot_node_subsystem_util::metrics::prometheus::Registry;
use polkadot_primitives::v2::CollatorPair;

Expand All @@ -31,7 +33,7 @@ use sc_network::{Event, NetworkService};
use sc_network_common::service::NetworkEventStream;
use std::sync::Arc;

use polkadot_service::{open_database, Configuration, TaskManager};
use polkadot_service::{Configuration, TaskManager};

use futures::StreamExt;

Expand All @@ -44,6 +46,10 @@ mod network;
mod blockchain_rpc_client;
pub use blockchain_rpc_client::BlockChainRpcClient;

const LOG_TARGET: &'static str = "polkadot-minimal-node";
const COST_INVALID_REQUEST: UnifiedReputationChange =
UnifiedReputationChange::CostMajor("Received message could not be decoded.");

fn build_authority_discovery_service<Block: BlockT>(
task_manager: &TaskManager,
client: Arc<BlockChainRpcClient>,
Expand Down Expand Up @@ -152,8 +158,10 @@ async fn new_minimal_relay_chain(
.extend(peer_sets_info(is_authority, &peer_set_protocol_names));

let request_protocol_names = ReqProtocolNames::new(genesis_hash, config.chain_spec.fork_id());
let (collation_req_receiver, available_data_req_receiver, pov_req_receiver, chunk_req_receiver) =
let (collation_req_receiver, available_data_req_receiver, chunk_req_receiver) =
build_request_response_protocol_receivers(&request_protocol_names, &mut config);
drain_unwanted_request_channels(&task_manager, chunk_req_receiver);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, this is unneeded. We can not do two things. Either we drop this channel or we do not even register the channel.


let (network, network_starter) =
network::build_collator_network(network::BuildCollatorNetworkParams {
config: &config,
Expand All @@ -170,8 +178,6 @@ async fn new_minimal_relay_chain(
prometheus_registry.clone(),
);

let parachains_db = open_database(&config.database)?;

let overseer_args = CollatorOverseerGenArgs {
runtime_client: relay_chain_rpc_client.clone(),
network_service: network.clone(),
Expand All @@ -183,10 +189,6 @@ async fn new_minimal_relay_chain(
collator_pair,
req_protocol_names: request_protocol_names,
peer_set_protocol_names,
parachains_db,
availability_config: polkadot_service::AVAILABILITY_CONFIG,
pov_req_receiver,
chunk_req_receiver,
};

let overseer_handle = collator_overseer::spawn_overseer(
Expand All @@ -200,24 +202,47 @@ async fn new_minimal_relay_chain(
Ok(NewMinimalNode { task_manager, overseer_handle, network })
}

/// Usually availability-distribution subsystem handles these requests.
/// We do not run it in this minimal node and therefore we answer
/// that we do not have the chunk/PoV.
fn drain_unwanted_request_channels(
task_manager: &TaskManager,
mut chunk_req_receiver: IncomingRequestReceiver<v1::ChunkFetchingRequest>,
) {
task_manager.spawn_handle().spawn("chunk-request-drainer", None, async move {
loop {
if let Ok(request) = chunk_req_receiver.recv(|| vec![COST_INVALID_REQUEST]).await {
tracing::debug!(
target: LOG_TARGET,
"Received chunk fetching request. Collators should not receive this."
altonen marked this conversation as resolved.
Show resolved Hide resolved
);
if let Err(err) = request.send_response(v1::ChunkFetchingResponse::NoSuchChunk) {
tracing::debug!(
target: LOG_TARGET,
?err,
"Unable to answer chunk fetching request"
);
}
};
}
});
}

fn build_request_response_protocol_receivers(
request_protocol_names: &ReqProtocolNames,
config: &mut Configuration,
) -> (
request_response::IncomingRequestReceiver<request_response::v1::CollationFetchingRequest>,
request_response::IncomingRequestReceiver<request_response::v1::AvailableDataFetchingRequest>,
request_response::IncomingRequestReceiver<request_response::v1::PoVFetchingRequest>,
request_response::IncomingRequestReceiver<request_response::v1::ChunkFetchingRequest>,
IncomingRequestReceiver<v1::CollationFetchingRequest>,
IncomingRequestReceiver<v1::AvailableDataFetchingRequest>,
IncomingRequestReceiver<v1::ChunkFetchingRequest>,
) {
let (collation_req_receiver, cfg) =
IncomingRequest::get_config_receiver(request_protocol_names);
config.network.request_response_protocols.push(cfg);
let (available_data_req_receiver, cfg) =
IncomingRequest::get_config_receiver(request_protocol_names);
config.network.request_response_protocols.push(cfg);
let (pov_req_receiver, cfg) = IncomingRequest::get_config_receiver(request_protocol_names);
config.network.request_response_protocols.push(cfg);
let (chunk_req_receiver, cfg) = IncomingRequest::get_config_receiver(request_protocol_names);
config.network.request_response_protocols.push(cfg);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
let (chunk_req_receiver, cfg) = IncomingRequest::get_config_receiver(request_protocol_names);
config.network.request_response_protocols.push(cfg);
let (_, cfg) = IncomingRequest::get_config_receiver(request_protocol_names);
// We don't support inbound requests for this protocol.
let cfg = RequestResponseConfig { inbound_queue: None, ..cfg };
config.network.request_response_protocols.push(cfg);

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should probably support this in Polkadot directly. When it is a collator/full node we should not register an incoming receiver

(collation_req_receiver, available_data_req_receiver, pov_req_receiver, chunk_req_receiver)
(collation_req_receiver, available_data_req_receiver, chunk_req_receiver)
}