From abac7f1106011c1694874cad9c5cccf18534d844 Mon Sep 17 00:00:00 2001 From: Pierre Krieger Date: Wed, 11 Aug 2021 18:42:35 +0200 Subject: [PATCH 01/10] Remove Prometheus metrics prefix --- client/authority-discovery/src/worker.rs | 14 ++--- client/cli/src/commands/run_cmd.rs | 8 +-- client/consensus/common/src/metrics.rs | 8 +-- .../src/communication/gossip.rs | 2 +- client/finality-grandpa/src/environment.rs | 6 +- client/finality-grandpa/src/until_imported.rs | 2 +- client/network-gossip/src/state_machine.rs | 4 +- client/network/src/protocol.rs | 8 +-- client/network/src/service/metrics.rs | 60 +++++++++---------- client/network/src/service/out_events.rs | 6 +- client/network/src/transactions.rs | 2 +- client/proposer-metrics/src/lib.rs | 4 +- client/rpc-servers/src/middleware.rs | 2 +- client/service/src/config.rs | 5 +- client/service/src/metrics.rs | 18 +++--- client/service/src/task_manager/mod.rs | 8 +-- client/transaction-pool/src/metrics.rs | 12 ++-- 17 files changed, 85 insertions(+), 84 deletions(-) diff --git a/client/authority-discovery/src/worker.rs b/client/authority-discovery/src/worker.rs index 5974bb7afb0a4..ed93491b67eca 100644 --- a/client/authority-discovery/src/worker.rs +++ b/client/authority-discovery/src/worker.rs @@ -635,14 +635,14 @@ impl Metrics { Ok(Self { publish: register( Counter::new( - "authority_discovery_times_published_total", + "substrate_authority_discovery_times_published_total", "Number of times authority discovery has published external addresses.", )?, registry, )?, amount_addresses_last_published: register( Gauge::new( - "authority_discovery_amount_external_addresses_last_published", + "substrate_authority_discovery_amount_external_addresses_last_published", "Number of external addresses published when authority discovery last \ published addresses.", )?, @@ -650,7 +650,7 @@ impl Metrics { )?, requests: register( Counter::new( - "authority_discovery_authority_addresses_requested_total", + "substrate_authority_discovery_authority_addresses_requested_total", "Number of times authority discovery has requested external addresses of a \ single authority.", )?, @@ -658,7 +658,7 @@ impl Metrics { )?, requests_pending: register( Gauge::new( - "authority_discovery_authority_address_requests_pending", + "substrate_authority_discovery_authority_address_requests_pending", "Number of pending authority address requests.", )?, registry, @@ -666,7 +666,7 @@ impl Metrics { dht_event_received: register( CounterVec::new( Opts::new( - "authority_discovery_dht_event_received", + "substrate_authority_discovery_dht_event_received", "Number of dht events received by authority discovery.", ), &["name"], @@ -675,14 +675,14 @@ impl Metrics { )?, handle_value_found_event_failure: register( Counter::new( - "authority_discovery_handle_value_found_event_failure", + "substrate_authority_discovery_handle_value_found_event_failure", "Number of times handling a dht value found event failed.", )?, registry, )?, known_authorities_count: register( Gauge::new( - "authority_discovery_known_authorities_count", + "substrate_authority_discovery_known_authorities_count", "Number of authorities known by authority discovery.", )?, registry, diff --git a/client/cli/src/commands/run_cmd.rs b/client/cli/src/commands/run_cmd.rs index fcc486297b21a..984d419f5af92 100644 --- a/client/cli/src/commands/run_cmd.rs +++ b/client/cli/src/commands/run_cmd.rs @@ -366,10 +366,10 @@ impl CliConfiguration for RunCmd { let interface = if self.prometheus_external { Ipv4Addr::UNSPECIFIED } else { Ipv4Addr::LOCALHOST }; - Some(PrometheusConfig::new_with_default_registry(SocketAddr::new( - interface.into(), - self.prometheus_port.unwrap_or(default_listen_port), - ))) + Some(PrometheusConfig::new_with_default_registry( + SocketAddr::new(interface.into(), self.prometheus_port.unwrap_or(default_listen_port)), + self.chain_id() + )) }) } diff --git a/client/consensus/common/src/metrics.rs b/client/consensus/common/src/metrics.rs index e9af41914a6e6..c5e04d79142ee 100644 --- a/client/consensus/common/src/metrics.rs +++ b/client/consensus/common/src/metrics.rs @@ -40,28 +40,28 @@ impl Metrics { Ok(Self { import_queue_processed: register( CounterVec::new( - Opts::new("import_queue_processed_total", "Blocks processed by import queue"), + Opts::new("substrate_import_queue_processed_total", "Blocks processed by import queue"), &["result"], // 'success or failure )?, registry, )?, block_verification_time: register( HistogramVec::new( - HistogramOpts::new("block_verification_time", "Time taken to verify blocks"), + HistogramOpts::new("substrate_block_verification_time", "Time taken to verify blocks"), &["result"], )?, registry, )?, block_verification_and_import_time: register( Histogram::with_opts(HistogramOpts::new( - "block_verification_and_import_time", + "substrate_block_verification_and_import_time", "Time taken to verify and import blocks", ))?, registry, )?, justification_import_time: register( Histogram::with_opts(HistogramOpts::new( - "justification_import_time", + "substrate_justification_import_time", "Time taken to import justifications", ))?, registry, diff --git a/client/finality-grandpa/src/communication/gossip.rs b/client/finality-grandpa/src/communication/gossip.rs index 90f40a93cb9e0..acbda0b2f32d3 100644 --- a/client/finality-grandpa/src/communication/gossip.rs +++ b/client/finality-grandpa/src/communication/gossip.rs @@ -1298,7 +1298,7 @@ impl Metrics { messages_validated: register( CounterVec::new( Opts::new( - "finality_grandpa_communication_gossip_validator_messages", + "substrate_finality_grandpa_communication_gossip_validator_messages", "Number of messages validated by the finality grandpa gossip validator.", ), &["message", "action"], diff --git a/client/finality-grandpa/src/environment.rs b/client/finality-grandpa/src/environment.rs index f27a530ed2f40..b83443dcf0a42 100644 --- a/client/finality-grandpa/src/environment.rs +++ b/client/finality-grandpa/src/environment.rs @@ -404,19 +404,19 @@ impl Metrics { ) -> Result { Ok(Self { finality_grandpa_round: register( - Gauge::new("finality_grandpa_round", "Highest completed GRANDPA round.")?, + Gauge::new("substrate_finality_grandpa_round", "Highest completed GRANDPA round.")?, registry, )?, finality_grandpa_prevotes: register( Counter::new( - "finality_grandpa_prevotes_total", + "substrate_finality_grandpa_prevotes_total", "Total number of GRANDPA prevotes cast locally.", )?, registry, )?, finality_grandpa_precommits: register( Counter::new( - "finality_grandpa_precommits_total", + "substrate_finality_grandpa_precommits_total", "Total number of GRANDPA precommits cast locally.", )?, registry, diff --git a/client/finality-grandpa/src/until_imported.rs b/client/finality-grandpa/src/until_imported.rs index 4063a3d484cf5..1f17450bd6566 100644 --- a/client/finality-grandpa/src/until_imported.rs +++ b/client/finality-grandpa/src/until_imported.rs @@ -101,7 +101,7 @@ impl Metrics { Ok(Self { global_waiting_messages: register( Gauge::new( - "finality_grandpa_until_imported_waiting_messages_number", + "substrate_finality_grandpa_until_imported_waiting_messages_number", "Number of finality grandpa messages waiting within the until imported queue.", )?, registry, diff --git a/client/network-gossip/src/state_machine.rs b/client/network-gossip/src/state_machine.rs index 5cda52b9db493..d0649a1e65316 100644 --- a/client/network-gossip/src/state_machine.rs +++ b/client/network-gossip/src/state_machine.rs @@ -507,14 +507,14 @@ impl Metrics { Ok(Self { registered_messages: register( Counter::new( - "network_gossip_registered_messages_total", + "substrate_network_gossip_registered_messages_total", "Number of registered messages by the gossip service.", )?, registry, )?, expired_messages: register( Counter::new( - "network_gossip_expired_messages_total", + "substrate_network_gossip_expired_messages_total", "Number of expired messages by the gossip service.", )?, registry, diff --git a/client/network/src/protocol.rs b/client/network/src/protocol.rs index a5675dbdc34d6..49262c66a4dff 100644 --- a/client/network/src/protocol.rs +++ b/client/network/src/protocol.rs @@ -132,21 +132,21 @@ impl Metrics { fn register(r: &Registry) -> Result { Ok(Metrics { peers: { - let g = Gauge::new("sync_peers", "Number of peers we sync with")?; + let g = Gauge::new("substrate_sync_peers", "Number of peers we sync with")?; register(g, r)? }, queued_blocks: { - let g = Gauge::new("sync_queued_blocks", "Number of blocks in import queue")?; + let g = Gauge::new("substrate_sync_queued_blocks", "Number of blocks in import queue")?; register(g, r)? }, fork_targets: { - let g = Gauge::new("sync_fork_targets", "Number of fork sync targets")?; + let g = Gauge::new("substrate_sync_fork_targets", "Number of fork sync targets")?; register(g, r)? }, justifications: { let g = GaugeVec::new( Opts::new( - "sync_extra_justifications", + "substrate_sync_extra_justifications", "Number of extra justifications requests", ), &["status"], diff --git a/client/network/src/service/metrics.rs b/client/network/src/service/metrics.rs index e33cd4b194d69..d146103dcf9d3 100644 --- a/client/network/src/service/metrics.rs +++ b/client/network/src/service/metrics.rs @@ -84,54 +84,54 @@ impl Metrics { // This list is ordered alphabetically connections_closed_total: prometheus::register(CounterVec::new( Opts::new( - "sub_libp2p_connections_closed_total", + "substrate_sub_libp2p_connections_closed_total", "Total number of connections closed, by direction and reason" ), &["direction", "reason"] )?, registry)?, connections_opened_total: prometheus::register(CounterVec::new( Opts::new( - "sub_libp2p_connections_opened_total", + "substrate_sub_libp2p_connections_opened_total", "Total number of connections opened by direction" ), &["direction"] )?, registry)?, distinct_peers_connections_closed_total: prometheus::register(Counter::new( - "sub_libp2p_distinct_peers_connections_closed_total", + "substrate_sub_libp2p_distinct_peers_connections_closed_total", "Total number of connections closed with distinct peers" )?, registry)?, distinct_peers_connections_opened_total: prometheus::register(Counter::new( - "sub_libp2p_distinct_peers_connections_opened_total", + "substrate_sub_libp2p_distinct_peers_connections_opened_total", "Total number of connections opened with distinct peers" )?, registry)?, import_queue_blocks_submitted: prometheus::register(Counter::new( - "import_queue_blocks_submitted", + "substrate_import_queue_blocks_submitted", "Number of blocks submitted to the import queue.", )?, registry)?, import_queue_justifications_submitted: prometheus::register(Counter::new( - "import_queue_justifications_submitted", + "substrate_import_queue_justifications_submitted", "Number of justifications submitted to the import queue.", )?, registry)?, incoming_connections_errors_total: prometheus::register(CounterVec::new( Opts::new( - "sub_libp2p_incoming_connections_handshake_errors_total", + "substrate_sub_libp2p_incoming_connections_handshake_errors_total", "Total number of incoming connections that have failed during the \ initial handshake" ), &["reason"] )?, registry)?, incoming_connections_total: prometheus::register(Counter::new( - "sub_libp2p_incoming_connections_total", + "substrate_sub_libp2p_incoming_connections_total", "Total number of incoming connections on the listening sockets" )?, registry)?, issued_light_requests: prometheus::register(Counter::new( - "issued_light_requests", + "substrate_issued_light_requests", "Number of light client requests that our node has issued.", )?, registry)?, kademlia_query_duration: prometheus::register(HistogramVec::new( HistogramOpts { common_opts: Opts::new( - "sub_libp2p_kademlia_query_duration", + "substrate_sub_libp2p_kademlia_query_duration", "Duration of Kademlia queries per query type" ), buckets: prometheus::exponential_buckets(0.5, 2.0, 10) @@ -141,43 +141,43 @@ impl Metrics { )?, registry)?, kademlia_random_queries_total: prometheus::register(CounterVec::new( Opts::new( - "sub_libp2p_kademlia_random_queries_total", + "substrate_sub_libp2p_kademlia_random_queries_total", "Number of random Kademlia queries started" ), &["protocol"] )?, registry)?, kademlia_records_count: prometheus::register(GaugeVec::new( Opts::new( - "sub_libp2p_kademlia_records_count", + "substrate_sub_libp2p_kademlia_records_count", "Number of records in the Kademlia records store" ), &["protocol"] )?, registry)?, kademlia_records_sizes_total: prometheus::register(GaugeVec::new( Opts::new( - "sub_libp2p_kademlia_records_sizes_total", + "substrate_sub_libp2p_kademlia_records_sizes_total", "Total size of all the records in the Kademlia records store" ), &["protocol"] )?, registry)?, kbuckets_num_nodes: prometheus::register(GaugeVec::new( Opts::new( - "sub_libp2p_kbuckets_num_nodes", + "substrate_sub_libp2p_kbuckets_num_nodes", "Number of nodes per kbucket per Kademlia instance" ), &["protocol", "lower_ilog2_bucket_bound"] )?, registry)?, listeners_local_addresses: prometheus::register(Gauge::new( - "sub_libp2p_listeners_local_addresses", "Number of local addresses we're listening on" + "substrate_sub_libp2p_listeners_local_addresses", "Number of local addresses we're listening on" )?, registry)?, listeners_errors_total: prometheus::register(Counter::new( - "sub_libp2p_listeners_errors_total", + "substrate_sub_libp2p_listeners_errors_total", "Total number of non-fatal errors reported by a listener" )?, registry)?, notifications_sizes: prometheus::register(HistogramVec::new( HistogramOpts { common_opts: Opts::new( - "sub_libp2p_notifications_sizes", + "substrate_sub_libp2p_notifications_sizes", "Sizes of the notifications send to and received from all nodes" ), buckets: prometheus::exponential_buckets(64.0, 4.0, 8) @@ -187,38 +187,38 @@ impl Metrics { )?, registry)?, notifications_streams_closed_total: prometheus::register(CounterVec::new( Opts::new( - "sub_libp2p_notifications_streams_closed_total", + "substrate_sub_libp2p_notifications_streams_closed_total", "Total number of notification substreams that have been closed" ), &["protocol"] )?, registry)?, notifications_streams_opened_total: prometheus::register(CounterVec::new( Opts::new( - "sub_libp2p_notifications_streams_opened_total", + "substrate_sub_libp2p_notifications_streams_opened_total", "Total number of notification substreams that have been opened" ), &["protocol"] )?, registry)?, peerset_num_discovered: prometheus::register(Gauge::new( - "sub_libp2p_peerset_num_discovered", "Number of nodes stored in the peerset manager", + "substrate_sub_libp2p_peerset_num_discovered", "Number of nodes stored in the peerset manager", )?, registry)?, peerset_num_requested: prometheus::register(Gauge::new( - "sub_libp2p_peerset_num_requested", "Number of nodes that the peerset manager wants us to be connected to", + "substrate_sub_libp2p_peerset_num_requested", "Number of nodes that the peerset manager wants us to be connected to", )?, registry)?, pending_connections: prometheus::register(Gauge::new( - "sub_libp2p_pending_connections", + "substrate_sub_libp2p_pending_connections", "Number of connections in the process of being established", )?, registry)?, pending_connections_errors_total: prometheus::register(CounterVec::new( Opts::new( - "sub_libp2p_pending_connections_errors_total", + "substrate_sub_libp2p_pending_connections_errors_total", "Total number of pending connection errors" ), &["reason"] )?, registry)?, requests_in_failure_total: prometheus::register(CounterVec::new( Opts::new( - "sub_libp2p_requests_in_failure_total", + "substrate_sub_libp2p_requests_in_failure_total", "Total number of incoming requests that the node has failed to answer" ), &["protocol", "reason"] @@ -226,7 +226,7 @@ impl Metrics { requests_in_success_total: prometheus::register(HistogramVec::new( HistogramOpts { common_opts: Opts::new( - "sub_libp2p_requests_in_success_total", + "substrate_sub_libp2p_requests_in_success_total", "For successful incoming requests, time between receiving the request and \ starting to send the response" ), @@ -237,7 +237,7 @@ impl Metrics { )?, registry)?, requests_out_failure_total: prometheus::register(CounterVec::new( Opts::new( - "sub_libp2p_requests_out_failure_total", + "substrate_sub_libp2p_requests_out_failure_total", "Total number of requests that have failed" ), &["protocol", "reason"] @@ -245,7 +245,7 @@ impl Metrics { requests_out_success_total: prometheus::register(HistogramVec::new( HistogramOpts { common_opts: Opts::new( - "sub_libp2p_requests_out_success_total", + "substrate_sub_libp2p_requests_out_success_total", "For successful outgoing requests, time between a request's start and finish" ), buckets: prometheus::exponential_buckets(0.001, 2.0, 16) @@ -267,7 +267,7 @@ impl BandwidthCounters { fn register(registry: &Registry, sinks: Arc) -> Result<(), PrometheusError> { prometheus::register( SourcedCounter::new( - &Opts::new("sub_libp2p_network_bytes_total", "Total bandwidth usage") + &Opts::new("substrate_sub_libp2p_network_bytes_total", "Total bandwidth usage") .variable_label("direction"), BandwidthCounters(sinks), )?, @@ -298,7 +298,7 @@ impl MajorSyncingGauge { prometheus::register( SourcedGauge::new( &Opts::new( - "sub_libp2p_is_major_syncing", + "substrate_sub_libp2p_is_major_syncing", "Whether the node is performing a major sync or not.", ), MajorSyncingGauge(value), @@ -328,7 +328,7 @@ impl NumConnectedGauge { fn register(registry: &Registry, value: Arc) -> Result<(), PrometheusError> { prometheus::register( SourcedGauge::new( - &Opts::new("sub_libp2p_peers_count", "Number of connected peers"), + &Opts::new("substrate_sub_libp2p_peers_count", "Number of connected peers"), NumConnectedGauge(value), )?, registry, diff --git a/client/network/src/service/out_events.rs b/client/network/src/service/out_events.rs index fad61491fb225..2c9a3068045a0 100644 --- a/client/network/src/service/out_events.rs +++ b/client/network/src/service/out_events.rs @@ -192,7 +192,7 @@ impl Metrics { Ok(Self { events_total: register(CounterVec::new( Opts::new( - "sub_libp2p_out_events_events_total", + "substrate_sub_libp2p_out_events_events_total", "Number of broadcast network events that have been sent or received across all \ channels" ), @@ -200,7 +200,7 @@ impl Metrics { )?, registry)?, notifications_sizes: register(CounterVec::new( Opts::new( - "sub_libp2p_out_events_notifications_sizes", + "substrate_sub_libp2p_out_events_notifications_sizes", "Size of notification events that have been sent or received across all \ channels" ), @@ -208,7 +208,7 @@ impl Metrics { )?, registry)?, num_channels: register(GaugeVec::new( Opts::new( - "sub_libp2p_out_events_num_channels", + "substrate_sub_libp2p_out_events_num_channels", "Number of internal active channels that broadcast network events", ), &["name"] diff --git a/client/network/src/transactions.rs b/client/network/src/transactions.rs index 82e7e8fe1714c..c2b9640e7d11c 100644 --- a/client/network/src/transactions.rs +++ b/client/network/src/transactions.rs @@ -95,7 +95,7 @@ impl Metrics { Ok(Metrics { propagated_transactions: register( Counter::new( - "sync_propagated_transactions", + "substrate_sync_propagated_transactions", "Number of transactions propagated to at least one peer", )?, r, diff --git a/client/proposer-metrics/src/lib.rs b/client/proposer-metrics/src/lib.rs index da29fb2951995..45ee6b524ffb3 100644 --- a/client/proposer-metrics/src/lib.rs +++ b/client/proposer-metrics/src/lib.rs @@ -54,14 +54,14 @@ impl Metrics { Ok(Self { block_constructed: register( Histogram::with_opts(HistogramOpts::new( - "proposer_block_constructed", + "substrate_proposer_block_constructed", "Histogram of time taken to construct new block", ))?, registry, )?, number_of_transactions: register( Gauge::new( - "proposer_number_of_transactions", + "substrate_proposer_number_of_transactions", "Number of transactions included in block", )?, registry, diff --git a/client/rpc-servers/src/middleware.rs b/client/rpc-servers/src/middleware.rs index d87c653e2b250..9c8c319f7496c 100644 --- a/client/rpc-servers/src/middleware.rs +++ b/client/rpc-servers/src/middleware.rs @@ -39,7 +39,7 @@ impl RpcMetrics { .map(|r| { register( CounterVec::new( - Opts::new("rpc_calls_total", "Number of rpc calls received"), + Opts::new("substrate_rpc_calls_total", "Number of rpc calls received"), &["protocol"], )?, r, diff --git a/client/service/src/config.rs b/client/service/src/config.rs index 67a4a2acfcb53..a9f05b0100756 100644 --- a/client/service/src/config.rs +++ b/client/service/src/config.rs @@ -38,6 +38,7 @@ use sp_core::crypto::SecretString; use std::{ future::Future, io, + iter, net::SocketAddr, path::{Path, PathBuf}, pin::Pin, @@ -197,10 +198,10 @@ impl PrometheusConfig { /// Create a new config using the default registry. /// /// The default registry prefixes metrics with `substrate`. - pub fn new_with_default_registry(port: SocketAddr) -> Self { + pub fn new_with_default_registry(port: SocketAddr, chain_id: String) -> Self { Self { port, - registry: Registry::new_custom(Some("substrate".into()), None) + registry: Registry::new_custom(None, Some(iter::once((String::from("chain"), chain_id)).collect())) .expect("this can only fail if the prefix is empty"), } } diff --git a/client/service/src/metrics.rs b/client/service/src/metrics.rs index cd03916c9261b..d0c6cc7719e4b 100644 --- a/client/service/src/metrics.rs +++ b/client/service/src/metrics.rs @@ -53,7 +53,7 @@ impl PrometheusMetrics { register( Gauge::::with_opts( Opts::new( - "build_info", + "substrate_build_info", "A metric with a constant '1' value labeled by name, version", ) .const_label("name", name) @@ -63,7 +63,7 @@ impl PrometheusMetrics { )? .set(1); - register(Gauge::::new("node_roles", "The roles the node is running as")?, ®istry)? + register(Gauge::::new("substrate_node_roles", "The roles the node is running as")?, ®istry)? .set(roles); register_globals(registry)?; @@ -72,7 +72,7 @@ impl PrometheusMetrics { SystemTime::now().duration_since(SystemTime::UNIX_EPOCH).unwrap_or_default(); register( Gauge::::new( - "process_start_time_seconds", + "substrate_process_start_time_seconds", "Number of seconds between the UNIX epoch and the moment the process started", )?, registry, @@ -83,20 +83,20 @@ impl PrometheusMetrics { // generic internals block_height: register( GaugeVec::new( - Opts::new("block_height", "Block height info of the chain"), + Opts::new("substrate_block_height", "Block height info of the chain"), &["status"], )?, registry, )?, number_leaves: register( - Gauge::new("number_leaves", "Number of known chain leaves (aka forks)")?, + Gauge::new("substrate_number_leaves", "Number of known chain leaves (aka forks)")?, registry, )?, ready_transactions_number: register( Gauge::new( - "ready_transactions_number", + "substrate_ready_transactions_number", "Number of transactions in the ready queue", )?, registry, @@ -104,16 +104,16 @@ impl PrometheusMetrics { // I/ O database_cache: register( - Gauge::new("database_cache_bytes", "RocksDB cache size in bytes")?, + Gauge::new("substrate_database_cache_bytes", "RocksDB cache size in bytes")?, registry, )?, state_cache: register( - Gauge::new("state_cache_bytes", "State cache size in bytes")?, + Gauge::new("substrate_state_cache_bytes", "State cache size in bytes")?, registry, )?, state_db: register( GaugeVec::new( - Opts::new("state_db_cache_bytes", "State DB cache in bytes"), + Opts::new("substrate_state_db_cache_bytes", "State DB cache in bytes"), &["subtype"], )?, registry, diff --git a/client/service/src/task_manager/mod.rs b/client/service/src/task_manager/mod.rs index d759798f744b6..6f4d863a40ad2 100644 --- a/client/service/src/task_manager/mod.rs +++ b/client/service/src/task_manager/mod.rs @@ -389,7 +389,7 @@ impl Metrics { poll_duration: register(HistogramVec::new( HistogramOpts { common_opts: Opts::new( - "tasks_polling_duration", + "substrate_tasks_polling_duration", "Duration in seconds of each invocation of Future::poll" ), buckets: exponential_buckets(0.001, 4.0, 9) @@ -399,21 +399,21 @@ impl Metrics { )?, registry)?, poll_start: register(CounterVec::new( Opts::new( - "tasks_polling_started_total", + "substrate_tasks_polling_started_total", "Total number of times we started invoking Future::poll" ), &["task_name"] )?, registry)?, tasks_spawned: register(CounterVec::new( Opts::new( - "tasks_spawned_total", + "substrate_tasks_spawned_total", "Total number of tasks that have been spawned on the Service" ), &["task_name"] )?, registry)?, tasks_ended: register(CounterVec::new( Opts::new( - "tasks_ended_total", + "substrate_tasks_ended_total", "Total number of tasks for which Future::poll has returned Ready(()) or panicked" ), &["task_name", "reason"] diff --git a/client/transaction-pool/src/metrics.rs b/client/transaction-pool/src/metrics.rs index d62d64f13a0a4..7afed21509781 100644 --- a/client/transaction-pool/src/metrics.rs +++ b/client/transaction-pool/src/metrics.rs @@ -56,28 +56,28 @@ impl Metrics { Ok(Self { submitted_transactions: register( Counter::new( - "sub_txpool_submitted_transactions", + "substrate_sub_txpool_submitted_transactions", "Total number of transactions submitted", )?, registry, )?, validations_invalid: register( Counter::new( - "sub_txpool_validations_invalid", + "substrate_sub_txpool_validations_invalid", "Total number of transactions that were removed from the pool as invalid", )?, registry, )?, block_transactions_pruned: register( Counter::new( - "sub_txpool_block_transactions_pruned", + "substrate_sub_txpool_block_transactions_pruned", "Total number of transactions that was requested to be pruned by block events", )?, registry, )?, block_transactions_resubmitted: register( Counter::new( - "sub_txpool_block_transactions_resubmitted", + "substrate_sub_txpool_block_transactions_resubmitted", "Total number of transactions that was requested to be resubmitted by block events", )?, registry, @@ -98,14 +98,14 @@ impl ApiMetrics { Ok(Self { validations_scheduled: register( Counter::new( - "sub_txpool_validations_scheduled", + "substrate_sub_txpool_validations_scheduled", "Total number of transactions scheduled for validation", )?, registry, )?, validations_finished: register( Counter::new( - "sub_txpool_validations_finished", + "substrate_sub_txpool_validations_finished", "Total number of transactions that finished validation", )?, registry, From fb30bd3ee637db15b817fbb578667d33a68ed909 Mon Sep 17 00:00:00 2001 From: Pierre Krieger Date: Wed, 11 Aug 2021 18:54:07 +0200 Subject: [PATCH 02/10] Fix line widths --- client/network/src/service/metrics.rs | 9 ++++++--- client/service/src/config.rs | 3 ++- client/service/src/metrics.rs | 6 ++++-- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/client/network/src/service/metrics.rs b/client/network/src/service/metrics.rs index d146103dcf9d3..2550f255e848c 100644 --- a/client/network/src/service/metrics.rs +++ b/client/network/src/service/metrics.rs @@ -168,7 +168,8 @@ impl Metrics { &["protocol", "lower_ilog2_bucket_bound"] )?, registry)?, listeners_local_addresses: prometheus::register(Gauge::new( - "substrate_sub_libp2p_listeners_local_addresses", "Number of local addresses we're listening on" + "substrate_sub_libp2p_listeners_local_addresses", + "Number of local addresses we're listening on" )?, registry)?, listeners_errors_total: prometheus::register(Counter::new( "substrate_sub_libp2p_listeners_errors_total", @@ -200,10 +201,12 @@ impl Metrics { &["protocol"] )?, registry)?, peerset_num_discovered: prometheus::register(Gauge::new( - "substrate_sub_libp2p_peerset_num_discovered", "Number of nodes stored in the peerset manager", + "substrate_sub_libp2p_peerset_num_discovered", + "Number of nodes stored in the peerset manager", )?, registry)?, peerset_num_requested: prometheus::register(Gauge::new( - "substrate_sub_libp2p_peerset_num_requested", "Number of nodes that the peerset manager wants us to be connected to", + "substrate_sub_libp2p_peerset_num_requested", + "Number of nodes that the peerset manager wants us to be connected to", )?, registry)?, pending_connections: prometheus::register(Gauge::new( "substrate_sub_libp2p_pending_connections", diff --git a/client/service/src/config.rs b/client/service/src/config.rs index a9f05b0100756..2236d5cdf0b1a 100644 --- a/client/service/src/config.rs +++ b/client/service/src/config.rs @@ -199,9 +199,10 @@ impl PrometheusConfig { /// /// The default registry prefixes metrics with `substrate`. pub fn new_with_default_registry(port: SocketAddr, chain_id: String) -> Self { + let param = iter::once((String::from("chain"), chain_id)).collect(); Self { port, - registry: Registry::new_custom(None, Some(iter::once((String::from("chain"), chain_id)).collect())) + registry: Registry::new_custom(None, Some(param)) .expect("this can only fail if the prefix is empty"), } } diff --git a/client/service/src/metrics.rs b/client/service/src/metrics.rs index d0c6cc7719e4b..2a24d415b21b6 100644 --- a/client/service/src/metrics.rs +++ b/client/service/src/metrics.rs @@ -63,8 +63,10 @@ impl PrometheusMetrics { )? .set(1); - register(Gauge::::new("substrate_node_roles", "The roles the node is running as")?, ®istry)? - .set(roles); + register( + Gauge::::new("substrate_node_roles", "The roles the node is running as")?, + ®istry + )?.set(roles); register_globals(registry)?; From 98a026bc5a47109e563ad7bc6362027df73fac4d Mon Sep 17 00:00:00 2001 From: Pierre Krieger Date: Wed, 11 Aug 2021 19:03:14 +0200 Subject: [PATCH 03/10] Missed some metrics --- primitives/utils/src/metrics.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/primitives/utils/src/metrics.rs b/primitives/utils/src/metrics.rs index 45d8b3b7311d7..e0e3a78c83fd0 100644 --- a/primitives/utils/src/metrics.rs +++ b/primitives/utils/src/metrics.rs @@ -28,17 +28,17 @@ use prometheus::{core::GenericCounterVec, Opts}; lazy_static! { pub static ref TOKIO_THREADS_TOTAL: GenericCounter = - GenericCounter::new("tokio_threads_total", "Total number of threads created") + GenericCounter::new("substrate_tokio_threads_total", "Total number of threads created") .expect("Creating of statics doesn't fail. qed"); pub static ref TOKIO_THREADS_ALIVE: GenericGauge = - GenericGauge::new("tokio_threads_alive", "Number of threads alive right now") + GenericGauge::new("substrate_tokio_threads_alive", "Number of threads alive right now") .expect("Creating of statics doesn't fail. qed"); } #[cfg(feature = "metered")] lazy_static! { pub static ref UNBOUNDED_CHANNELS_COUNTER : GenericCounterVec = GenericCounterVec::new( - Opts::new("unbounded_channel_len", "Items in each mpsc::unbounded instance"), + Opts::new("substrate_unbounded_channel_len", "Items in each mpsc::unbounded instance"), &["entity", "action"] // 'name of channel, send|received|dropped ).expect("Creating of statics doesn't fail. qed"); From ce3072af03e041f613ba18f7a87c6959a283a69b Mon Sep 17 00:00:00 2001 From: Pierre Krieger Date: Wed, 11 Aug 2021 19:21:21 +0200 Subject: [PATCH 04/10] Fix CLI --- client/cli/src/commands/run_cmd.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/cli/src/commands/run_cmd.rs b/client/cli/src/commands/run_cmd.rs index 984d419f5af92..1ff3cd828692f 100644 --- a/client/cli/src/commands/run_cmd.rs +++ b/client/cli/src/commands/run_cmd.rs @@ -368,7 +368,7 @@ impl CliConfiguration for RunCmd { Some(PrometheusConfig::new_with_default_registry( SocketAddr::new(interface.into(), self.prometheus_port.unwrap_or(default_listen_port)), - self.chain_id() + self.shared_params.chain_id(self.shared_params.dev) )) }) } From 373caebf4960e8425fa3c66af7dc62654556b97d Mon Sep 17 00:00:00 2001 From: Pierre Krieger Date: Thu, 12 Aug 2021 11:02:26 +0200 Subject: [PATCH 05/10] Run rustfmt on modified files --- client/cli/src/commands/run_cmd.rs | 21 ++- client/consensus/common/src/metrics.rs | 10 +- client/network/src/protocol.rs | 221 +++++++++++++------------ client/service/src/config.rs | 5 +- client/service/src/metrics.rs | 5 +- 5 files changed, 144 insertions(+), 118 deletions(-) diff --git a/client/cli/src/commands/run_cmd.rs b/client/cli/src/commands/run_cmd.rs index 1ff3cd828692f..78e8b8a6899d8 100644 --- a/client/cli/src/commands/run_cmd.rs +++ b/client/cli/src/commands/run_cmd.rs @@ -367,8 +367,11 @@ impl CliConfiguration for RunCmd { if self.prometheus_external { Ipv4Addr::UNSPECIFIED } else { Ipv4Addr::LOCALHOST }; Some(PrometheusConfig::new_with_default_registry( - SocketAddr::new(interface.into(), self.prometheus_port.unwrap_or(default_listen_port)), - self.shared_params.chain_id(self.shared_params.dev) + SocketAddr::new( + interface.into(), + self.prometheus_port.unwrap_or(default_listen_port), + ), + self.shared_params.chain_id(self.shared_params.dev), )) }) } @@ -461,19 +464,19 @@ impl CliConfiguration for RunCmd { pub fn is_node_name_valid(_name: &str) -> std::result::Result<(), &str> { let name = _name.to_string(); if name.chars().count() >= crate::NODE_NAME_MAX_LENGTH { - return Err("Node name too long") + return Err("Node name too long"); } let invalid_chars = r"[\\.@]"; let re = Regex::new(invalid_chars).unwrap(); if re.is_match(&name) { - return Err("Node name should not contain invalid chars such as '.' and '@'") + return Err("Node name should not contain invalid chars such as '.' and '@'"); } let invalid_patterns = r"(https?:\\/+)?(www)+"; let re = Regex::new(invalid_patterns).unwrap(); if re.is_match(&name) { - return Err("Node name should not contain urls") + return Err("Node name should not contain urls"); } Ok(()) @@ -491,7 +494,7 @@ fn rpc_interface( a validator. Use `--unsafe-rpc-external` or `--rpc-methods=unsafe` if you understand \ the risks. See the options description for more information." .to_owned(), - )) + )); } if is_external || is_unsafe_external { @@ -534,7 +537,7 @@ fn parse_telemetry_endpoints(s: &str) -> std::result::Result<(String, u8), Telem let verbosity = s[pos_ + 1..].parse().map_err(TelemetryParsingError::VerbosityParsingError)?; Ok((url, verbosity)) - }, + } } } @@ -567,8 +570,8 @@ fn parse_cors(s: &str) -> std::result::Result> match part { "all" | "*" => { is_all = true; - break - }, + break; + } other => origins.push(other.to_owned()), } } diff --git a/client/consensus/common/src/metrics.rs b/client/consensus/common/src/metrics.rs index c5e04d79142ee..d834c41107eb2 100644 --- a/client/consensus/common/src/metrics.rs +++ b/client/consensus/common/src/metrics.rs @@ -40,14 +40,20 @@ impl Metrics { Ok(Self { import_queue_processed: register( CounterVec::new( - Opts::new("substrate_import_queue_processed_total", "Blocks processed by import queue"), + Opts::new( + "substrate_import_queue_processed_total", + "Blocks processed by import queue", + ), &["result"], // 'success or failure )?, registry, )?, block_verification_time: register( HistogramVec::new( - HistogramOpts::new("substrate_block_verification_time", "Time taken to verify blocks"), + HistogramOpts::new( + "substrate_block_verification_time", + "Time taken to verify blocks", + ), &["result"], )?, registry, diff --git a/client/network/src/protocol.rs b/client/network/src/protocol.rs index 49262c66a4dff..f6cd715f18572 100644 --- a/client/network/src/protocol.rs +++ b/client/network/src/protocol.rs @@ -136,7 +136,8 @@ impl Metrics { register(g, r)? }, queued_blocks: { - let g = Gauge::new("substrate_sync_queued_blocks", "Number of blocks in import queue")?; + let g = + Gauge::new("substrate_sync_queued_blocks", "Number of blocks in import queue")?; register(g, r)? }, fork_targets: { @@ -239,8 +240,9 @@ impl ProtocolConfig { } else { match self.sync_mode { config::SyncMode::Full => sync::SyncMode::Full, - config::SyncMode::Fast { skip_proofs, storage_chain_mode } => - sync::SyncMode::LightState { skip_proofs, storage_chain_mode }, + config::SyncMode::Fast { skip_proofs, storage_chain_mode } => { + sync::SyncMode::LightState { skip_proofs, storage_chain_mode } + } config::SyncMode::Warp => sync::SyncMode::Warp, } } @@ -357,8 +359,8 @@ impl Protocol { out_peers: network_config.default_peers_set.out_peers, bootnodes, reserved_nodes: default_sets_reserved.clone(), - reserved_only: network_config.default_peers_set.non_reserved_mode == - config::NonReservedPeerMode::Deny, + reserved_only: network_config.default_peers_set.non_reserved_mode + == config::NonReservedPeerMode::Deny, }); for set_cfg in &network_config.extra_sets { @@ -423,8 +425,8 @@ impl Protocol { }; let block_announce_data_cache = lru::LruCache::new( - network_config.default_peers_set.in_peers as usize + - network_config.default_peers_set.out_peers as usize, + network_config.default_peers_set.in_peers as usize + + network_config.default_peers_set.out_peers as usize, ); let protocol = Protocol { @@ -660,8 +662,8 @@ impl Protocol { Err(err) => { debug!(target: "sync", "Failed to decode block response from {}: {}", peer_id, err); self.peerset_handle.report_peer(peer_id, rep::BAD_MESSAGE); - return CustomMessageOutcome::None - }, + return CustomMessageOutcome::None; + } }; let block_response = message::BlockResponse:: { id: request.id, blocks }; @@ -687,24 +689,26 @@ impl Protocol { if request.fields == message::BlockAttributes::JUSTIFICATION { match self.sync.on_block_justification(peer_id, block_response) { Ok(sync::OnBlockJustification::Nothing) => CustomMessageOutcome::None, - Ok(sync::OnBlockJustification::Import { peer, hash, number, justifications }) => - CustomMessageOutcome::JustificationImport(peer, hash, number, justifications), + Ok(sync::OnBlockJustification::Import { peer, hash, number, justifications }) => { + CustomMessageOutcome::JustificationImport(peer, hash, number, justifications) + } Err(sync::BadPeer(id, repu)) => { self.behaviour.disconnect_peer(&id, HARDCODED_PEERSETS_SYNC); self.peerset_handle.report_peer(id, repu); CustomMessageOutcome::None - }, + } } } else { match self.sync.on_block_data(&peer_id, Some(request), block_response) { - Ok(sync::OnBlockData::Import(origin, blocks)) => - CustomMessageOutcome::BlockImport(origin, blocks), + Ok(sync::OnBlockData::Import(origin, blocks)) => { + CustomMessageOutcome::BlockImport(origin, blocks) + } Ok(sync::OnBlockData::Request(peer, req)) => self.prepare_block_request(peer, req), Err(sync::BadPeer(id, repu)) => { self.behaviour.disconnect_peer(&id, HARDCODED_PEERSETS_SYNC); self.peerset_handle.report_peer(id, repu); CustomMessageOutcome::None - }, + } } } } @@ -717,15 +721,17 @@ impl Protocol { response: StateResponse, ) -> CustomMessageOutcome { match self.sync.on_state_data(&peer_id, response) { - Ok(sync::OnStateData::Import(origin, block)) => - CustomMessageOutcome::BlockImport(origin, vec![block]), - Ok(sync::OnStateData::Request(peer, req)) => - prepare_state_request::(&mut self.peers, peer, req), + Ok(sync::OnStateData::Import(origin, block)) => { + CustomMessageOutcome::BlockImport(origin, vec![block]) + } + Ok(sync::OnStateData::Request(peer, req)) => { + prepare_state_request::(&mut self.peers, peer, req) + } Err(sync::BadPeer(id, repu)) => { self.behaviour.disconnect_peer(&id, HARDCODED_PEERSETS_SYNC); self.peerset_handle.report_peer(id, repu); CustomMessageOutcome::None - }, + } } } @@ -737,15 +743,17 @@ impl Protocol { response: crate::warp_request_handler::EncodedProof, ) -> CustomMessageOutcome { match self.sync.on_warp_sync_data(&peer_id, response) { - Ok(sync::OnWarpSyncData::WarpProofRequest(peer, req)) => - prepare_warp_sync_request::(&mut self.peers, peer, req), - Ok(sync::OnWarpSyncData::StateRequest(peer, req)) => - prepare_state_request::(&mut self.peers, peer, req), + Ok(sync::OnWarpSyncData::WarpProofRequest(peer, req)) => { + prepare_warp_sync_request::(&mut self.peers, peer, req) + } + Ok(sync::OnWarpSyncData::StateRequest(peer, req)) => { + prepare_state_request::(&mut self.peers, peer, req) + } Err(sync::BadPeer(id, repu)) => { self.behaviour.disconnect_peer(&id, HARDCODED_PEERSETS_SYNC); self.peerset_handle.report_peer(id, repu); CustomMessageOutcome::None - }, + } } } @@ -771,7 +779,7 @@ impl Protocol { if self.peers.contains_key(&who) { log::error!(target: "sync", "Called on_sync_peer_connected with already connected peer {}", who); debug_assert!(false); - return Err(()) + return Err(()); } if status.genesis_hash != self.genesis_hash { @@ -794,7 +802,7 @@ impl Protocol { ); } - return Err(()) + return Err(()); } if self.config.roles.is_light() { @@ -803,7 +811,7 @@ impl Protocol { debug!(target: "sync", "Peer {} is unable to serve light requests", who); self.peerset_handle.report_peer(who.clone(), rep::BAD_ROLE); self.behaviour.disconnect_peer(&who, HARDCODED_PEERSETS_SYNC); - return Err(()) + return Err(()); } // we don't interested in peers that are far behind us @@ -816,7 +824,7 @@ impl Protocol { debug!(target: "sync", "Peer {} is far behind us and will unable to serve light requests", who); self.peerset_handle.report_peer(who.clone(), rep::PEER_BEHIND_US_LIGHT); self.behaviour.disconnect_peer(&who, HARDCODED_PEERSETS_SYNC); - return Err(()) + return Err(()); } } @@ -838,8 +846,8 @@ impl Protocol { Err(sync::BadPeer(id, repu)) => { self.behaviour.disconnect_peer(&id, HARDCODED_PEERSETS_SYNC); self.peerset_handle.report_peer(id, repu); - return Err(()) - }, + return Err(()); + } } } else { None @@ -868,17 +876,17 @@ impl Protocol { Ok(Some(header)) => header, Ok(None) => { warn!("Trying to announce unknown block: {}", hash); - return - }, + return; + } Err(e) => { warn!("Error reading block header {}: {:?}", hash, e); - return - }, + return; + } }; // don't announce genesis block since it will be ignored if header.number().is_zero() { - return + return; } let is_best = self.chain.info().best_hash == hash; @@ -929,8 +937,8 @@ impl Protocol { None => { log::error!(target: "sync", "Received block announce from disconnected peer {}", who); debug_assert!(false); - return - }, + return; + } }; peer.known_blocks.insert(hash.clone()); @@ -968,11 +976,11 @@ impl Protocol { // AND // 2) parent block is already imported and not pruned. if is_best { - return CustomMessageOutcome::PeerNewBest(who, *announce.header.number()) + return CustomMessageOutcome::PeerNewBest(who, *announce.header.number()); } else { - return CustomMessageOutcome::None + return CustomMessageOutcome::None; } - }, + } sync::PollBlockAnnounceValidation::ImportHeader { announce, is_best, who } => { self.update_peer_info(&who); @@ -983,15 +991,15 @@ impl Protocol { } (announce.header, is_best, who) - }, + } sync::PollBlockAnnounceValidation::Failure { who, disconnect } => { if disconnect { self.behaviour.disconnect_peer(&who, HARDCODED_PEERSETS_SYNC); } self.report_peer(who, rep::BAD_BLOCK_ANNOUNCEMENT); - return CustomMessageOutcome::None - }, + return CustomMessageOutcome::None; + } }; let number = *header.number(); @@ -1021,14 +1029,15 @@ impl Protocol { } match blocks_to_import { - Ok(sync::OnBlockData::Import(origin, blocks)) => - CustomMessageOutcome::BlockImport(origin, blocks), + Ok(sync::OnBlockData::Import(origin, blocks)) => { + CustomMessageOutcome::BlockImport(origin, blocks) + } Ok(sync::OnBlockData::Request(peer, req)) => self.prepare_block_request(peer, req), Err(sync::BadPeer(id, repu)) => { self.behaviour.disconnect_peer(&id, HARDCODED_PEERSETS_SYNC); self.peerset_handle.report_peer(id, repu); CustomMessageOutcome::None - }, + } } } @@ -1081,11 +1090,11 @@ impl Protocol { id, req, )); - }, + } Err(sync::BadPeer(id, repu)) => { self.behaviour.disconnect_peer(&id, HARDCODED_PEERSETS_SYNC); self.peerset_handle.report_peer(id, repu) - }, + } } } } @@ -1246,10 +1255,12 @@ fn prepare_block_request( let request = crate::schema::v1::BlockRequest { fields: request.fields.to_be_u32(), from_block: match request.from { - message::FromBlock::Hash(h) => - Some(crate::schema::v1::block_request::FromBlock::Hash(h.encode())), - message::FromBlock::Number(n) => - Some(crate::schema::v1::block_request::FromBlock::Number(n.encode())), + message::FromBlock::Hash(h) => { + Some(crate::schema::v1::block_request::FromBlock::Hash(h.encode())) + } + message::FromBlock::Number(n) => { + Some(crate::schema::v1::block_request::FromBlock::Number(n.encode())) + } }, to_block: request.to.map(|h| h.encode()).unwrap_or_default(), direction: request.direction as i32, @@ -1402,7 +1413,7 @@ impl NetworkBehaviour for Protocol { > >{ if let Some(message) = self.pending_messages.pop_front() { - return Poll::Ready(NetworkBehaviourAction::GenerateEvent(message)) + return Poll::Ready(NetworkBehaviourAction::GenerateEvent(message)); } // Check for finished outgoing requests. @@ -1430,12 +1441,12 @@ impl NetworkBehaviour for Protocol { .report_peer(id.clone(), rep::BAD_MESSAGE); self.behaviour .disconnect_peer(id, HARDCODED_PEERSETS_SYNC); - continue - }, + continue; + } }; finished_block_requests.push((id.clone(), req, protobuf_response)); - }, + } PeerRequest::State => { let protobuf_response = match crate::schema::v1::StateResponse::decode(&resp[..]) { @@ -1451,17 +1462,17 @@ impl NetworkBehaviour for Protocol { .report_peer(id.clone(), rep::BAD_MESSAGE); self.behaviour .disconnect_peer(id, HARDCODED_PEERSETS_SYNC); - continue - }, + continue; + } }; finished_state_requests.push((id.clone(), protobuf_response)); - }, + } PeerRequest::WarpProof => { finished_warp_sync_requests.push((id.clone(), resp)); - }, + } } - }, + } Poll::Ready(Ok(Err(e))) => { peer.request.take(); debug!(target: "sync", "Request to peer {:?} failed: {:?}.", id, e); @@ -1470,37 +1481,37 @@ impl NetworkBehaviour for Protocol { RequestFailure::Network(OutboundFailure::Timeout) => { self.peerset_handle.report_peer(id.clone(), rep::TIMEOUT); self.behaviour.disconnect_peer(id, HARDCODED_PEERSETS_SYNC); - }, + } RequestFailure::Network(OutboundFailure::UnsupportedProtocols) => { self.peerset_handle.report_peer(id.clone(), rep::BAD_PROTOCOL); self.behaviour.disconnect_peer(id, HARDCODED_PEERSETS_SYNC); - }, + } RequestFailure::Network(OutboundFailure::DialFailure) => { self.behaviour.disconnect_peer(id, HARDCODED_PEERSETS_SYNC); - }, + } RequestFailure::Refused => { self.peerset_handle.report_peer(id.clone(), rep::REFUSED); self.behaviour.disconnect_peer(id, HARDCODED_PEERSETS_SYNC); - }, - RequestFailure::Network(OutboundFailure::ConnectionClosed) | - RequestFailure::NotConnected => { + } + RequestFailure::Network(OutboundFailure::ConnectionClosed) + | RequestFailure::NotConnected => { self.behaviour.disconnect_peer(id, HARDCODED_PEERSETS_SYNC); - }, + } RequestFailure::UnknownProtocol => { debug_assert!( false, "Block request protocol should always be known." ); - }, + } RequestFailure::Obsolete => { debug_assert!( false, "Can not receive `RequestFailure::Obsolete` after dropping the \ response receiver.", ); - }, + } } - }, + } Poll::Ready(Err(oneshot::Canceled)) => { peer.request.take(); trace!( @@ -1509,8 +1520,8 @@ impl NetworkBehaviour for Protocol { id, ); self.behaviour.disconnect_peer(id, HARDCODED_PEERSETS_SYNC); - }, - Poll::Pending => {}, + } + Poll::Pending => {} } } } @@ -1551,30 +1562,34 @@ impl NetworkBehaviour for Protocol { // Check if there is any block announcement validation finished. while let Poll::Ready(result) = self.sync.poll_block_announce_validation(cx) { match self.process_block_announce_validation_result(result) { - CustomMessageOutcome::None => {}, + CustomMessageOutcome::None => {} outcome => self.pending_messages.push_back(outcome), } } if let Some(message) = self.pending_messages.pop_front() { - return Poll::Ready(NetworkBehaviourAction::GenerateEvent(message)) + return Poll::Ready(NetworkBehaviourAction::GenerateEvent(message)); } let event = match self.behaviour.poll(cx, params) { Poll::Pending => return Poll::Pending, Poll::Ready(NetworkBehaviourAction::GenerateEvent(ev)) => ev, - Poll::Ready(NetworkBehaviourAction::DialAddress { address }) => - return Poll::Ready(NetworkBehaviourAction::DialAddress { address }), - Poll::Ready(NetworkBehaviourAction::DialPeer { peer_id, condition }) => - return Poll::Ready(NetworkBehaviourAction::DialPeer { peer_id, condition }), - Poll::Ready(NetworkBehaviourAction::NotifyHandler { peer_id, handler, event }) => + Poll::Ready(NetworkBehaviourAction::DialAddress { address }) => { + return Poll::Ready(NetworkBehaviourAction::DialAddress { address }) + } + Poll::Ready(NetworkBehaviourAction::DialPeer { peer_id, condition }) => { + return Poll::Ready(NetworkBehaviourAction::DialPeer { peer_id, condition }) + } + Poll::Ready(NetworkBehaviourAction::NotifyHandler { peer_id, handler, event }) => { return Poll::Ready(NetworkBehaviourAction::NotifyHandler { peer_id, handler, event, - }), - Poll::Ready(NetworkBehaviourAction::ReportObservedAddr { address, score }) => - return Poll::Ready(NetworkBehaviourAction::ReportObservedAddr { address, score }), + }) + } + Poll::Ready(NetworkBehaviourAction::ReportObservedAddr { address, score }) => { + return Poll::Ready(NetworkBehaviourAction::ReportObservedAddr { address, score }) + } }; let outcome = match event { @@ -1606,7 +1621,7 @@ impl NetworkBehaviour for Protocol { } else { CustomMessageOutcome::None } - }, + } Ok(msg) => { debug!( target: "sync", @@ -1616,7 +1631,7 @@ impl NetworkBehaviour for Protocol { ); self.peerset_handle.report_peer(peer_id, rep::BAD_MESSAGE); CustomMessageOutcome::None - }, + } Err(err) => { match as DecodeAll>::decode_all( &mut &received_handshake[..], @@ -1630,7 +1645,7 @@ impl NetworkBehaviour for Protocol { } else { CustomMessageOutcome::None } - }, + } Err(err2) => { debug!( target: "sync", @@ -1642,9 +1657,9 @@ impl NetworkBehaviour for Protocol { ); self.peerset_handle.report_peer(peer_id, rep::BAD_MESSAGE); CustomMessageOutcome::None - }, + } } - }, + } } } else { match ( @@ -1674,18 +1689,18 @@ impl NetworkBehaviour for Protocol { roles: peer.info.roles, notifications_sink, } - }, + } (Err(err), _) => { debug!(target: "sync", "Failed to parse remote handshake: {}", err); self.bad_handshake_substreams.insert((peer_id.clone(), set_id)); self.behaviour.disconnect_peer(&peer_id, set_id); self.peerset_handle.report_peer(peer_id, rep::BAD_MESSAGE); CustomMessageOutcome::None - }, + } } } - }, - NotificationsOut::CustomProtocolReplaced { peer_id, notifications_sink, set_id } => + } + NotificationsOut::CustomProtocolReplaced { peer_id, notifications_sink, set_id } => { if set_id == HARDCODED_PEERSETS_SYNC { CustomMessageOutcome::None } else if self.bad_handshake_substreams.contains(&(peer_id.clone(), set_id)) { @@ -1698,7 +1713,8 @@ impl NetworkBehaviour for Protocol { .clone(), notifications_sink, } - }, + } + } NotificationsOut::CustomProtocolClosed { peer_id, set_id } => { // Set number 0 is hardcoded the default set of peers we sync from. if set_id == HARDCODED_PEERSETS_SYNC { @@ -1725,7 +1741,7 @@ impl NetworkBehaviour for Protocol { .clone(), } } - }, + } NotificationsOut::Notification { peer_id, set_id, message } => match set_id { HARDCODED_PEERSETS_SYNC if self.peers.contains_key(&peer_id) => { if let Ok(announce) = message::BlockAnnounce::decode(&mut message.as_ref()) { @@ -1742,7 +1758,7 @@ impl NetworkBehaviour for Protocol { warn!(target: "sub-libp2p", "Failed to decode block announce"); CustomMessageOutcome::None } - }, + } HARDCODED_PEERSETS_SYNC => { trace!( target: "sync", @@ -1750,9 +1766,10 @@ impl NetworkBehaviour for Protocol { peer_id ); CustomMessageOutcome::None - }, - _ if self.bad_handshake_substreams.contains(&(peer_id.clone(), set_id)) => - CustomMessageOutcome::None, + } + _ if self.bad_handshake_substreams.contains(&(peer_id.clone(), set_id)) => { + CustomMessageOutcome::None + } _ => { let protocol_name = self.notification_protocols [usize::from(set_id) - NUM_HARDCODED_PEERSETS] @@ -1761,16 +1778,16 @@ impl NetworkBehaviour for Protocol { remote: peer_id, messages: vec![(protocol_name, message.freeze())], } - }, + } }, }; if !matches!(outcome, CustomMessageOutcome::::None) { - return Poll::Ready(NetworkBehaviourAction::GenerateEvent(outcome)) + return Poll::Ready(NetworkBehaviourAction::GenerateEvent(outcome)); } if let Some(message) = self.pending_messages.pop_front() { - return Poll::Ready(NetworkBehaviourAction::GenerateEvent(message)) + return Poll::Ready(NetworkBehaviourAction::GenerateEvent(message)); } // This block can only be reached if an event was pulled from the behaviour and that diff --git a/client/service/src/config.rs b/client/service/src/config.rs index 2236d5cdf0b1a..4e97042ab7aeb 100644 --- a/client/service/src/config.rs +++ b/client/service/src/config.rs @@ -37,8 +37,7 @@ pub use sc_transaction_pool::Options as TransactionPoolOptions; use sp_core::crypto::SecretString; use std::{ future::Future, - io, - iter, + io, iter, net::SocketAddr, path::{Path, PathBuf}, pin::Pin, @@ -230,7 +229,7 @@ impl Configuration { crate::DEFAULT_PROTOCOL_ID ); crate::DEFAULT_PROTOCOL_ID - }, + } }; sc_network::config::ProtocolId::from(protocol_id_full) } diff --git a/client/service/src/metrics.rs b/client/service/src/metrics.rs index 2a24d415b21b6..2915ef96d82a9 100644 --- a/client/service/src/metrics.rs +++ b/client/service/src/metrics.rs @@ -65,8 +65,9 @@ impl PrometheusMetrics { register( Gauge::::new("substrate_node_roles", "The roles the node is running as")?, - ®istry - )?.set(roles); + ®istry, + )? + .set(roles); register_globals(registry)?; From b312baa5b84aa331d14c8933b7f0f46df93bb34d Mon Sep 17 00:00:00 2001 From: Pierre Krieger Date: Thu, 18 Nov 2021 18:01:53 +0100 Subject: [PATCH 06/10] Missing prefixes --- client/api/src/notifications.rs | 2 +- client/beefy/src/metrics.rs | 12 ++++++------ client/rpc-servers/src/lib.rs | 4 ++-- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/client/api/src/notifications.rs b/client/api/src/notifications.rs index 1346afd5e54d2..9565fd673acf4 100644 --- a/client/api/src/notifications.rs +++ b/client/api/src/notifications.rs @@ -121,7 +121,7 @@ impl StorageNotifications { let metrics = prometheus_registry.and_then(|r| { CounterVec::new( Opts::new( - "storage_notification_subscribers", + "substrate_storage_notification_subscribers", "Number of subscribers in storage notification sytem", ), &["action"], // added | removed diff --git a/client/beefy/src/metrics.rs b/client/beefy/src/metrics.rs index 0fdc29f97c37a..149edc3978bf4 100644 --- a/client/beefy/src/metrics.rs +++ b/client/beefy/src/metrics.rs @@ -40,28 +40,28 @@ impl Metrics { pub(crate) fn register(registry: &Registry) -> Result { Ok(Self { beefy_validator_set_id: register( - Gauge::new("beefy_validator_set_id", "Current BEEFY active validator set id.")?, + Gauge::new("substrate_beefy_validator_set_id", "Current BEEFY active validator set id.")?, registry, )?, beefy_votes_sent: register( - Counter::new("beefy_votes_sent", "Number of votes sent by this node")?, + Counter::new("substrate_beefy_votes_sent", "Number of votes sent by this node")?, registry, )?, beefy_round_concluded: register( - Gauge::new("beefy_round_concluded", "Voting round, that has been concluded")?, + Gauge::new("substrate_beefy_round_concluded", "Voting round, that has been concluded")?, registry, )?, beefy_best_block: register( - Gauge::new("beefy_best_block", "Best block finalized by BEEFY")?, + Gauge::new("substrate_beefy_best_block", "Best block finalized by BEEFY")?, registry, )?, beefy_should_vote_on: register( - Gauge::new("beefy_should_vote_on", "Next block, BEEFY should vote on")?, + Gauge::new("substrate_beefy_should_vote_on", "Next block, BEEFY should vote on")?, registry, )?, beefy_skipped_sessions: register( Counter::new( - "beefy_skipped_sessions", + "substrate_beefy_skipped_sessions", "Number of sessions without a signed commitment", )?, registry, diff --git a/client/rpc-servers/src/lib.rs b/client/rpc-servers/src/lib.rs index 1ac409d6ba89f..82da848343209 100644 --- a/client/rpc-servers/src/lib.rs +++ b/client/rpc-servers/src/lib.rs @@ -90,7 +90,7 @@ impl ServerMetrics { Ok(Self { session_opened: register( Counter::new( - "rpc_sessions_opened", + "substrate_rpc_sessions_opened", "Number of persistent RPC sessions opened", )?, r, @@ -98,7 +98,7 @@ impl ServerMetrics { .into(), session_closed: register( Counter::new( - "rpc_sessions_closed", + "substrate_rpc_sessions_closed", "Number of persistent RPC sessions closed", )?, r, From f78f10ec0e230e7a154e5629ff65e81ecd3812af Mon Sep 17 00:00:00 2001 From: Pierre Krieger Date: Fri, 19 Nov 2021 17:28:24 +0100 Subject: [PATCH 07/10] Hopefully fix compilation --- client/network/src/protocol.rs | 182 ++++++++++++++++----------------- 1 file changed, 86 insertions(+), 96 deletions(-) diff --git a/client/network/src/protocol.rs b/client/network/src/protocol.rs index 3fe05ca9e2b61..abeadb2ad6145 100644 --- a/client/network/src/protocol.rs +++ b/client/network/src/protocol.rs @@ -136,8 +136,7 @@ impl Metrics { register(g, r)? }, queued_blocks: { - let g = - Gauge::new("substrate_sync_queued_blocks", "Number of blocks in import queue")?; + let g = Gauge::new("substrate_sync_queued_blocks", "Number of blocks in import queue")?; register(g, r)? }, fork_targets: { @@ -240,9 +239,8 @@ impl ProtocolConfig { } else { match self.sync_mode { config::SyncMode::Full => sync::SyncMode::Full, - config::SyncMode::Fast { skip_proofs, storage_chain_mode } => { - sync::SyncMode::LightState { skip_proofs, storage_chain_mode } - } + config::SyncMode::Fast { skip_proofs, storage_chain_mode } => + sync::SyncMode::LightState { skip_proofs, storage_chain_mode }, config::SyncMode::Warp => sync::SyncMode::Warp, } } @@ -350,8 +348,8 @@ impl Protocol { out_peers: network_config.default_peers_set.out_peers, bootnodes, reserved_nodes: default_sets_reserved.clone(), - reserved_only: network_config.default_peers_set.non_reserved_mode - == config::NonReservedPeerMode::Deny, + reserved_only: network_config.default_peers_set.non_reserved_mode == + config::NonReservedPeerMode::Deny, }); for set_cfg in &network_config.extra_sets { @@ -416,8 +414,8 @@ impl Protocol { }; let block_announce_data_cache = lru::LruCache::new( - network_config.default_peers_set.in_peers as usize - + network_config.default_peers_set.out_peers as usize, + network_config.default_peers_set.in_peers as usize + + network_config.default_peers_set.out_peers as usize, ); let protocol = Self { @@ -653,8 +651,8 @@ impl Protocol { Err(err) => { debug!(target: "sync", "Failed to decode block response from {}: {}", peer_id, err); self.peerset_handle.report_peer(peer_id, rep::BAD_MESSAGE); - return CustomMessageOutcome::None; - } + return CustomMessageOutcome::None + }, }; let block_response = message::BlockResponse:: { id: request.id, blocks }; @@ -680,26 +678,24 @@ impl Protocol { if request.fields == message::BlockAttributes::JUSTIFICATION { match self.sync.on_block_justification(peer_id, block_response) { Ok(sync::OnBlockJustification::Nothing) => CustomMessageOutcome::None, - Ok(sync::OnBlockJustification::Import { peer, hash, number, justifications }) => { - CustomMessageOutcome::JustificationImport(peer, hash, number, justifications) - } + Ok(sync::OnBlockJustification::Import { peer, hash, number, justifications }) => + CustomMessageOutcome::JustificationImport(peer, hash, number, justifications), Err(sync::BadPeer(id, repu)) => { self.behaviour.disconnect_peer(&id, HARDCODED_PEERSETS_SYNC); self.peerset_handle.report_peer(id, repu); CustomMessageOutcome::None - } + }, } } else { match self.sync.on_block_data(&peer_id, Some(request), block_response) { - Ok(sync::OnBlockData::Import(origin, blocks)) => { - CustomMessageOutcome::BlockImport(origin, blocks) - } + Ok(sync::OnBlockData::Import(origin, blocks)) => + CustomMessageOutcome::BlockImport(origin, blocks), Ok(sync::OnBlockData::Request(peer, req)) => self.prepare_block_request(peer, req), Err(sync::BadPeer(id, repu)) => { self.behaviour.disconnect_peer(&id, HARDCODED_PEERSETS_SYNC); self.peerset_handle.report_peer(id, repu); CustomMessageOutcome::None - } + }, } } } @@ -719,7 +715,7 @@ impl Protocol { self.behaviour.disconnect_peer(&id, HARDCODED_PEERSETS_SYNC); self.peerset_handle.report_peer(id, repu); CustomMessageOutcome::None - } + }, } } @@ -736,7 +732,7 @@ impl Protocol { self.behaviour.disconnect_peer(&id, HARDCODED_PEERSETS_SYNC); self.peerset_handle.report_peer(id, repu); CustomMessageOutcome::None - } + }, } } @@ -762,7 +758,7 @@ impl Protocol { if self.peers.contains_key(&who) { error!(target: "sync", "Called on_sync_peer_connected with already connected peer {}", who); debug_assert!(false); - return Err(()); + return Err(()) } if status.genesis_hash != self.genesis_hash { @@ -785,7 +781,7 @@ impl Protocol { ); } - return Err(()); + return Err(()) } if self.config.roles.is_light() { @@ -794,7 +790,7 @@ impl Protocol { debug!(target: "sync", "Peer {} is unable to serve light requests", who); self.peerset_handle.report_peer(who, rep::BAD_ROLE); self.behaviour.disconnect_peer(&who, HARDCODED_PEERSETS_SYNC); - return Err(()); + return Err(()) } // we don't interested in peers that are far behind us @@ -807,7 +803,7 @@ impl Protocol { debug!(target: "sync", "Peer {} is far behind us and will unable to serve light requests", who); self.peerset_handle.report_peer(who, rep::PEER_BEHIND_US_LIGHT); self.behaviour.disconnect_peer(&who, HARDCODED_PEERSETS_SYNC); - return Err(()); + return Err(()) } } @@ -829,8 +825,8 @@ impl Protocol { Err(sync::BadPeer(id, repu)) => { self.behaviour.disconnect_peer(&id, HARDCODED_PEERSETS_SYNC); self.peerset_handle.report_peer(id, repu); - return Err(()); - } + return Err(()) + }, } } else { None @@ -859,17 +855,17 @@ impl Protocol { Ok(Some(header)) => header, Ok(None) => { warn!("Trying to announce unknown block: {}", hash); - return; - } + return + }, Err(e) => { warn!("Error reading block header {}: {:?}", hash, e); - return; - } + return + }, }; // don't announce genesis block since it will be ignored if header.number().is_zero() { - return; + return } let is_best = self.chain.info().best_hash == hash; @@ -920,8 +916,8 @@ impl Protocol { None => { log::error!(target: "sync", "Received block announce from disconnected peer {}", who); debug_assert!(false); - return; - } + return + }, }; peer.known_blocks.insert(hash.clone()); @@ -959,11 +955,11 @@ impl Protocol { // AND // 2) parent block is already imported and not pruned. if is_best { - return CustomMessageOutcome::PeerNewBest(who, *announce.header.number()); + return CustomMessageOutcome::PeerNewBest(who, *announce.header.number()) } else { - return CustomMessageOutcome::None; + return CustomMessageOutcome::None } - } + }, sync::PollBlockAnnounceValidation::ImportHeader { announce, is_best, who } => { self.update_peer_info(&who); @@ -974,15 +970,15 @@ impl Protocol { } (announce.header, is_best, who) - } + }, sync::PollBlockAnnounceValidation::Failure { who, disconnect } => { if disconnect { self.behaviour.disconnect_peer(&who, HARDCODED_PEERSETS_SYNC); } self.report_peer(who, rep::BAD_BLOCK_ANNOUNCEMENT); - return CustomMessageOutcome::None; - } + return CustomMessageOutcome::None + }, }; let number = *header.number(); @@ -1012,15 +1008,14 @@ impl Protocol { } match blocks_to_import { - Ok(sync::OnBlockData::Import(origin, blocks)) => { - CustomMessageOutcome::BlockImport(origin, blocks) - } + Ok(sync::OnBlockData::Import(origin, blocks)) => + CustomMessageOutcome::BlockImport(origin, blocks), Ok(sync::OnBlockData::Request(peer, req)) => self.prepare_block_request(peer, req), Err(sync::BadPeer(id, repu)) => { self.behaviour.disconnect_peer(&id, HARDCODED_PEERSETS_SYNC); self.peerset_handle.report_peer(id, repu); CustomMessageOutcome::None - } + }, } } @@ -1073,11 +1068,11 @@ impl Protocol { id, req, )); - } + }, Err(sync::BadPeer(id, repu)) => { self.behaviour.disconnect_peer(&id, HARDCODED_PEERSETS_SYNC); self.peerset_handle.report_peer(id, repu) - } + }, } } } @@ -1252,12 +1247,10 @@ fn prepare_block_request( let request = crate::schema::v1::BlockRequest { fields: request.fields.to_be_u32(), from_block: match request.from { - message::FromBlock::Hash(h) => { - Some(crate::schema::v1::block_request::FromBlock::Hash(h.encode())) - } - message::FromBlock::Number(n) => { - Some(crate::schema::v1::block_request::FromBlock::Number(n.encode())) - } + message::FromBlock::Hash(h) => + Some(crate::schema::v1::block_request::FromBlock::Hash(h.encode())), + message::FromBlock::Number(n) => + Some(crate::schema::v1::block_request::FromBlock::Number(n.encode())), }, to_block: request.to.map(|h| h.encode()).unwrap_or_default(), direction: request.direction as i32, @@ -1410,7 +1403,7 @@ impl NetworkBehaviour for Protocol { > >{ if let Some(message) = self.pending_messages.pop_front() { - return Poll::Ready(NetworkBehaviourAction::GenerateEvent(message)); + return Poll::Ready(NetworkBehaviourAction::GenerateEvent(message)) } // Check for finished outgoing requests. @@ -1437,12 +1430,12 @@ impl NetworkBehaviour for Protocol { self.peerset_handle.report_peer(*id, rep::BAD_MESSAGE); self.behaviour .disconnect_peer(id, HARDCODED_PEERSETS_SYNC); - continue; - } + continue + }, }; finished_block_requests.push((id.clone(), req, protobuf_response)); - } + }, PeerRequest::State => { let protobuf_response = match crate::schema::v1::StateResponse::decode(&resp[..]) { @@ -1457,8 +1450,8 @@ impl NetworkBehaviour for Protocol { self.peerset_handle.report_peer(*id, rep::BAD_MESSAGE); self.behaviour .disconnect_peer(id, HARDCODED_PEERSETS_SYNC); - continue; - } + continue + }, }; finished_state_requests.push((*id, protobuf_response)); @@ -1467,7 +1460,7 @@ impl NetworkBehaviour for Protocol { finished_warp_sync_requests.push((*id, resp)); }, } - } + }, Poll::Ready(Ok(Err(e))) => { peer.request.take(); debug!(target: "sync", "Request to peer {:?} failed: {:?}.", id, e); @@ -1476,37 +1469,37 @@ impl NetworkBehaviour for Protocol { RequestFailure::Network(OutboundFailure::Timeout) => { self.peerset_handle.report_peer(*id, rep::TIMEOUT); self.behaviour.disconnect_peer(id, HARDCODED_PEERSETS_SYNC); - } + }, RequestFailure::Network(OutboundFailure::UnsupportedProtocols) => { self.peerset_handle.report_peer(*id, rep::BAD_PROTOCOL); self.behaviour.disconnect_peer(id, HARDCODED_PEERSETS_SYNC); - } + }, RequestFailure::Network(OutboundFailure::DialFailure) => { self.behaviour.disconnect_peer(id, HARDCODED_PEERSETS_SYNC); - } + }, RequestFailure::Refused => { self.peerset_handle.report_peer(*id, rep::REFUSED); self.behaviour.disconnect_peer(id, HARDCODED_PEERSETS_SYNC); - } - RequestFailure::Network(OutboundFailure::ConnectionClosed) - | RequestFailure::NotConnected => { + }, + RequestFailure::Network(OutboundFailure::ConnectionClosed) | + RequestFailure::NotConnected => { self.behaviour.disconnect_peer(id, HARDCODED_PEERSETS_SYNC); - } + }, RequestFailure::UnknownProtocol => { debug_assert!( false, "Block request protocol should always be known." ); - } + }, RequestFailure::Obsolete => { debug_assert!( false, "Can not receive `RequestFailure::Obsolete` after dropping the \ response receiver.", ); - } + }, } - } + }, Poll::Ready(Err(oneshot::Canceled)) => { peer.request.take(); trace!( @@ -1515,8 +1508,8 @@ impl NetworkBehaviour for Protocol { id, ); self.behaviour.disconnect_peer(id, HARDCODED_PEERSETS_SYNC); - } - Poll::Pending => {} + }, + Poll::Pending => {}, } } } @@ -1557,25 +1550,23 @@ impl NetworkBehaviour for Protocol { // Check if there is any block announcement validation finished. while let Poll::Ready(result) = self.sync.poll_block_announce_validation(cx) { match self.process_block_announce_validation_result(result) { - CustomMessageOutcome::None => {} + CustomMessageOutcome::None => {}, outcome => self.pending_messages.push_back(outcome), } } if let Some(message) = self.pending_messages.pop_front() { - return Poll::Ready(NetworkBehaviourAction::GenerateEvent(message)); + return Poll::Ready(NetworkBehaviourAction::GenerateEvent(message)) } let event = match self.behaviour.poll(cx, params) { Poll::Pending => return Poll::Pending, Poll::Ready(NetworkBehaviourAction::GenerateEvent(ev)) => ev, - Poll::Ready(NetworkBehaviourAction::DialAddress { address }) => { - return Poll::Ready(NetworkBehaviourAction::DialAddress { address }) - } - Poll::Ready(NetworkBehaviourAction::DialPeer { peer_id, condition }) => { - return Poll::Ready(NetworkBehaviourAction::DialPeer { peer_id, condition }) - } - Poll::Ready(NetworkBehaviourAction::NotifyHandler { peer_id, handler, event }) => { + Poll::Ready(NetworkBehaviourAction::DialAddress { address }) => + return Poll::Ready(NetworkBehaviourAction::DialAddress { address }), + Poll::Ready(NetworkBehaviourAction::DialPeer { peer_id, condition }) => + return Poll::Ready(NetworkBehaviourAction::DialPeer { peer_id, condition }), + Poll::Ready(NetworkBehaviourAction::NotifyHandler { peer_id, handler, event }) => return Poll::Ready(NetworkBehaviourAction::NotifyHandler { peer_id, handler, @@ -1616,7 +1607,7 @@ impl NetworkBehaviour for Protocol { } else { CustomMessageOutcome::None } - } + }, Ok(msg) => { debug!( target: "sync", @@ -1626,7 +1617,7 @@ impl NetworkBehaviour for Protocol { ); self.peerset_handle.report_peer(peer_id, rep::BAD_MESSAGE); CustomMessageOutcome::None - } + }, Err(err) => { match as DecodeAll>::decode_all( &mut &received_handshake[..], @@ -1637,7 +1628,7 @@ impl NetworkBehaviour for Protocol { } else { CustomMessageOutcome::None } - } + }, Err(err2) => { debug!( target: "sync", @@ -1649,9 +1640,9 @@ impl NetworkBehaviour for Protocol { ); self.peerset_handle.report_peer(peer_id, rep::BAD_MESSAGE); CustomMessageOutcome::None - } + }, } - } + }, } } else { match ( @@ -1681,18 +1672,18 @@ impl NetworkBehaviour for Protocol { roles: peer.info.roles, notifications_sink, } - } + }, (Err(err), _) => { debug!(target: "sync", "Failed to parse remote handshake: {}", err); self.bad_handshake_substreams.insert((peer_id, set_id)); self.behaviour.disconnect_peer(&peer_id, set_id); self.peerset_handle.report_peer(peer_id, rep::BAD_MESSAGE); CustomMessageOutcome::None - } + }, } } - } - NotificationsOut::CustomProtocolReplaced { peer_id, notifications_sink, set_id } => { + }, + NotificationsOut::CustomProtocolReplaced { peer_id, notifications_sink, set_id } => if set_id == HARDCODED_PEERSETS_SYNC { CustomMessageOutcome::None } else if self.bad_handshake_substreams.contains(&(peer_id, set_id)) { @@ -1705,8 +1696,7 @@ impl NetworkBehaviour for Protocol { .clone(), notifications_sink, } - } - } + }, NotificationsOut::CustomProtocolClosed { peer_id, set_id } => { // Set number 0 is hardcoded the default set of peers we sync from. if set_id == HARDCODED_PEERSETS_SYNC { @@ -1733,7 +1723,7 @@ impl NetworkBehaviour for Protocol { .clone(), } } - } + }, NotificationsOut::Notification { peer_id, set_id, message } => match set_id { HARDCODED_PEERSETS_SYNC if self.peers.contains_key(&peer_id) => { if let Ok(announce) = message::BlockAnnounce::decode(&mut message.as_ref()) { @@ -1750,7 +1740,7 @@ impl NetworkBehaviour for Protocol { warn!(target: "sub-libp2p", "Failed to decode block announce"); CustomMessageOutcome::None } - } + }, HARDCODED_PEERSETS_SYNC => { trace!( target: "sync", @@ -1769,16 +1759,16 @@ impl NetworkBehaviour for Protocol { remote: peer_id, messages: vec![(protocol_name, message.freeze())], } - } + }, }, }; if !matches!(outcome, CustomMessageOutcome::::None) { - return Poll::Ready(NetworkBehaviourAction::GenerateEvent(outcome)); + return Poll::Ready(NetworkBehaviourAction::GenerateEvent(outcome)) } if let Some(message) = self.pending_messages.pop_front() { - return Poll::Ready(NetworkBehaviourAction::GenerateEvent(message)); + return Poll::Ready(NetworkBehaviourAction::GenerateEvent(message)) } // This block can only be reached if an event was pulled from the behaviour and that From 5a54314e2a4feef9059109ba348e6b443c6ce58a Mon Sep 17 00:00:00 2001 From: Pierre Krieger Date: Fri, 19 Nov 2021 17:31:34 +0100 Subject: [PATCH 08/10] Rustfmt protocol.rs --- client/network/src/protocol.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/client/network/src/protocol.rs b/client/network/src/protocol.rs index abeadb2ad6145..bc4357da1a4a0 100644 --- a/client/network/src/protocol.rs +++ b/client/network/src/protocol.rs @@ -136,7 +136,8 @@ impl Metrics { register(g, r)? }, queued_blocks: { - let g = Gauge::new("substrate_sync_queued_blocks", "Number of blocks in import queue")?; + let g = + Gauge::new("substrate_sync_queued_blocks", "Number of blocks in import queue")?; register(g, r)? }, fork_targets: { From 5172d294cbb5cee38046db66f2cfeba57a6c0d69 Mon Sep 17 00:00:00 2001 From: Pierre Krieger Date: Thu, 25 Nov 2021 11:47:05 +0100 Subject: [PATCH 09/10] Should compile now I guess --- client/service/src/config.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/service/src/config.rs b/client/service/src/config.rs index d4a75c5ad4dee..8f0f5d813167a 100644 --- a/client/service/src/config.rs +++ b/client/service/src/config.rs @@ -36,7 +36,7 @@ pub use sc_telemetry::TelemetryEndpoints; pub use sc_transaction_pool::Options as TransactionPoolOptions; use sp_core::crypto::SecretString; use std::{ - io, + io, iter, net::SocketAddr, path::{Path, PathBuf}, }; From 864d2b6e4de38702d28158e121d17d6b3573749d Mon Sep 17 00:00:00 2001 From: Pierre Krieger Date: Thu, 25 Nov 2021 12:27:55 +0100 Subject: [PATCH 10/10] Rustfmt --- client/beefy/src/metrics.rs | 10 ++++++++-- client/cli/src/commands/run_cmd.rs | 14 +++++++------- client/service/src/config.rs | 2 +- 3 files changed, 16 insertions(+), 10 deletions(-) diff --git a/client/beefy/src/metrics.rs b/client/beefy/src/metrics.rs index 149edc3978bf4..55edee962a2ee 100644 --- a/client/beefy/src/metrics.rs +++ b/client/beefy/src/metrics.rs @@ -40,7 +40,10 @@ impl Metrics { pub(crate) fn register(registry: &Registry) -> Result { Ok(Self { beefy_validator_set_id: register( - Gauge::new("substrate_beefy_validator_set_id", "Current BEEFY active validator set id.")?, + Gauge::new( + "substrate_beefy_validator_set_id", + "Current BEEFY active validator set id.", + )?, registry, )?, beefy_votes_sent: register( @@ -48,7 +51,10 @@ impl Metrics { registry, )?, beefy_round_concluded: register( - Gauge::new("substrate_beefy_round_concluded", "Voting round, that has been concluded")?, + Gauge::new( + "substrate_beefy_round_concluded", + "Voting round, that has been concluded", + )?, registry, )?, beefy_best_block: register( diff --git a/client/cli/src/commands/run_cmd.rs b/client/cli/src/commands/run_cmd.rs index bf43d4a474921..622206fdf2977 100644 --- a/client/cli/src/commands/run_cmd.rs +++ b/client/cli/src/commands/run_cmd.rs @@ -471,19 +471,19 @@ impl CliConfiguration for RunCmd { pub fn is_node_name_valid(_name: &str) -> std::result::Result<(), &str> { let name = _name.to_string(); if name.chars().count() >= crate::NODE_NAME_MAX_LENGTH { - return Err("Node name too long"); + return Err("Node name too long") } let invalid_chars = r"[\\.@]"; let re = Regex::new(invalid_chars).unwrap(); if re.is_match(&name) { - return Err("Node name should not contain invalid chars such as '.' and '@'"); + return Err("Node name should not contain invalid chars such as '.' and '@'") } let invalid_patterns = r"(https?:\\/+)?(www)+"; let re = Regex::new(invalid_patterns).unwrap(); if re.is_match(&name) { - return Err("Node name should not contain urls"); + return Err("Node name should not contain urls") } Ok(()) @@ -501,7 +501,7 @@ fn rpc_interface( a validator. Use `--unsafe-rpc-external` or `--rpc-methods=unsafe` if you understand \ the risks. See the options description for more information." .to_owned(), - )); + )) } if is_external || is_unsafe_external { @@ -544,7 +544,7 @@ fn parse_telemetry_endpoints(s: &str) -> std::result::Result<(String, u8), Telem let verbosity = s[pos_ + 1..].parse().map_err(TelemetryParsingError::VerbosityParsingError)?; Ok((url, verbosity)) - } + }, } } @@ -577,8 +577,8 @@ fn parse_cors(s: &str) -> std::result::Result> match part { "all" | "*" => { is_all = true; - break; - } + break + }, other => origins.push(other.to_owned()), } } diff --git a/client/service/src/config.rs b/client/service/src/config.rs index 8f0f5d813167a..0552baf5c209f 100644 --- a/client/service/src/config.rs +++ b/client/service/src/config.rs @@ -220,7 +220,7 @@ impl Configuration { crate::DEFAULT_PROTOCOL_ID ); crate::DEFAULT_PROTOCOL_ID - } + }, }; sc_network::config::ProtocolId::from(protocol_id_full) }