Skip to content
Open
Show file tree
Hide file tree
Changes from 11 commits
Commits
Show all changes
171 commits
Select commit Hold shift + click to select a range
3d1c62e
chore: initial statistics subsystem
EclesioMeloJunior Sep 8, 2025
c70e648
Merge branch 'master' into statistics-collector
EclesioMeloJunior Sep 9, 2025
4e8f90a
chore: account votes that approved candidate
EclesioMeloJunior Sep 9, 2025
0bc38d0
Merge branch 'statistics-collector' of github.com:ChainSafe/polkadot-…
EclesioMeloJunior Sep 9, 2025
a6feab9
chore: remove unneeded file
EclesioMeloJunior Sep 11, 2025
788bf44
Merge branch 'master' into statistics-collector
EclesioMeloJunior Sep 15, 2025
9f9d2f4
chore: add docs, get useful votes, change subsystem name
EclesioMeloJunior Sep 15, 2025
f4d1365
Merge branch 'statistics-collector' of github.com:ChainSafe/polkadot-…
EclesioMeloJunior Sep 15, 2025
8637ad7
chore: start getting chunks downloads metrics
EclesioMeloJunior Sep 17, 2025
0ee9a03
Merge branch 'master' into statistics-collector
EclesioMeloJunior Sep 17, 2025
8bae0a8
chore: include `handle_chunks_downloaded` per session and candidate
EclesioMeloJunior Sep 17, 2025
b7c47ac
address comments
EclesioMeloJunior Sep 18, 2025
d83075a
chore: revert changes in chunks.rs
EclesioMeloJunior Sep 19, 2025
2084903
Merge branch 'master' into statistics-collector
EclesioMeloJunior Sep 19, 2025
fac0526
Merge branch 'master' of github.com:paritytech/polkadot-sdk into stat…
EclesioMeloJunior Sep 19, 2025
803ae6d
Merge branch 'statistics-collector' of github.com:ChainSafe/polkadot-…
EclesioMeloJunior Sep 19, 2025
e4e00dc
chore: fix approval voting tests
EclesioMeloJunior Sep 24, 2025
a5dbccf
fix approval voting tests
EclesioMeloJunior Sep 25, 2025
4f77b87
chore: fixing approval tests
EclesioMeloJunior Sep 25, 2025
f9f4d71
chore: include tests for collectorstats subsytem
EclesioMeloJunior Sep 29, 2025
6282094
chore: include no-shows tests
EclesioMeloJunior Sep 30, 2025
c0f969d
include tests for chunks downloaded
EclesioMeloJunior Sep 30, 2025
b846ced
chore: wip using auth discovery to get peer authority id
EclesioMeloJunior Oct 2, 2025
92119bf
Merge branch 'master' into statistics-collector
EclesioMeloJunior Oct 3, 2025
0b186a1
deprecate macro was failing to build in recent rust versions
EclesioMeloJunior Oct 3, 2025
2b2c4fa
Merge branch 'statistics-collector' of github.com:ChainSafe/polkadot-…
EclesioMeloJunior Oct 3, 2025
7dfe19d
Merge branch 'master' into statistics-collector
EclesioMeloJunior Oct 6, 2025
caea9a8
feat: collect upload metrics
EclesioMeloJunior Oct 6, 2025
e6dcf11
Merge branch 'statistics-collector' of github.com:ChainSafe/polkadot-…
EclesioMeloJunior Oct 6, 2025
6b7504c
chore: finish handle_chunk_upload
EclesioMeloJunior Oct 7, 2025
ea150e1
Merge branch 'master' into statistics-collector
EclesioMeloJunior Oct 8, 2025
796f044
Merge branch 'master' into statistics-collector
EclesioMeloJunior Oct 8, 2025
9ae0211
chore: including prunning based on block finalisation
EclesioMeloJunior Oct 15, 2025
63e379d
chore: include tests for uploaded chunk
EclesioMeloJunior Oct 15, 2025
848ba5a
chore: remove unnecessary mapping
EclesioMeloJunior Oct 15, 2025
23c0512
Merge branch 'master' into statistics-collector
EclesioMeloJunior Oct 16, 2025
00c661f
chore: prune when session is finalized
EclesioMeloJunior Oct 16, 2025
e25e99a
Merge branch 'master' into statistics-collector
EclesioMeloJunior Oct 16, 2025
564e0e5
Merge branch 'master' into statistics-collector
EclesioMeloJunior Oct 17, 2025
bbab27b
chore: fix tests
EclesioMeloJunior Oct 17, 2025
2dae7cb
chore: improve metrics collection
EclesioMeloJunior Oct 20, 2025
554cd6e
Merge branch 'statistics-collector' of github.com:ChainSafe/polkadot-…
EclesioMeloJunior Oct 20, 2025
aa00e1b
chore: testing pruning capabilities
EclesioMeloJunior Oct 20, 2025
3d3686e
chore: assert collected stats for pruned are discarded
EclesioMeloJunior Oct 20, 2025
3ebd9c6
Merge branch 'master' into statistics-collector
EclesioMeloJunior Oct 21, 2025
27d8061
Merge branch 'master' into statistics-collector
EclesioMeloJunior Oct 21, 2025
ec2d55d
chore: include zombienet happy-path test
EclesioMeloJunior Oct 22, 2025
91230d2
Merge branch 'statistics-collector' of github.com:ChainSafe/polkadot-…
EclesioMeloJunior Oct 22, 2025
f3bc3d9
Merge branch 'master' into statistics-collector
EclesioMeloJunior Oct 24, 2025
0994734
Merge branch 'master' into statistics-collector
EclesioMeloJunior Oct 27, 2025
e90fb75
addressing comments
EclesioMeloJunior Oct 28, 2025
5e33f9a
Merge branch 'statistics-collector' of github.com:ChainSafe/polkadot-…
EclesioMeloJunior Oct 28, 2025
7671486
chore: implemented new pruning based on finalized blocks
EclesioMeloJunior Oct 28, 2025
e2e7b80
Merge branch 'master' into statistics-collector
EclesioMeloJunior Oct 28, 2025
e986951
chore: aggregate on tallies
EclesioMeloJunior Oct 29, 2025
0a82d3f
Merge branch 'statistics-collector' of github.com:ChainSafe/polkadot-…
EclesioMeloJunior Oct 29, 2025
4dc3efb
Merge branch 'master' into statistics-collector
EclesioMeloJunior Oct 29, 2025
2016c0c
chore: including on bench + debug logs for session collected stats
EclesioMeloJunior Oct 30, 2025
569176b
Merge branch 'statistics-collector' of github.com:ChainSafe/polkadot-…
EclesioMeloJunior Oct 30, 2025
2161ced
make per validator prometheus metrics optional
EclesioMeloJunior Oct 30, 2025
496c7ed
Merge branch 'master' into statistics-collector
EclesioMeloJunior Oct 30, 2025
ebc2f2e
Merge branch 'master' into statistics-collector
EclesioMeloJunior Nov 1, 2025
5d6a592
Merge branch 'master' into statistics-collector
EclesioMeloJunior Nov 3, 2025
880feab
chore: make publish_per_validator_approval_metrics a cli flag
EclesioMeloJunior Nov 3, 2025
5d59954
Merge branch 'master' into statistics-collector
EclesioMeloJunior Nov 4, 2025
5c166d3
Merge branch 'master' into statistics-collector
EclesioMeloJunior Nov 5, 2025
67a9cb3
Merge branch 'master' into statistics-collector
EclesioMeloJunior Nov 6, 2025
87b3ccc
chore: renaming subsystem
EclesioMeloJunior Nov 10, 2025
55da39e
Merge branch 'statistics-collector' of github.com:ChainSafe/polkadot-…
EclesioMeloJunior Nov 10, 2025
8aecc01
chore: including approval stats submission
EclesioMeloJunior Nov 11, 2025
e3f757f
Merge branch 'master' into statistics-collector
EclesioMeloJunior Nov 12, 2025
e27fc23
chore: remove onchain impl
EclesioMeloJunior Nov 17, 2025
49f783e
Merge branch 'statistics-collector' of github.com:ChainSafe/polkadot-…
EclesioMeloJunior Nov 17, 2025
f5352e2
chore: addressing comments
EclesioMeloJunior Nov 19, 2025
28ce1ef
chore: addressing comments
EclesioMeloJunior Nov 19, 2025
cbdc2bc
chore: removing unused imports
EclesioMeloJunior Nov 19, 2025
88596c2
Merge branch 'master' into statistics-collector
EclesioMeloJunior Nov 19, 2025
9ffa52c
Merge branch 'master' into statistics-collector
EclesioMeloJunior Nov 19, 2025
91305d9
Merge branch 'master' into statistics-collector
EclesioMeloJunior Nov 24, 2025
f339452
chore: fix `pre_covers_dont_stall_approval` test
EclesioMeloJunior Nov 24, 2025
96494b5
Merge branch 'statistics-collector' of github.com:ChainSafe/polkadot-…
EclesioMeloJunior Nov 24, 2025
9a37b2a
chore: solved zombienet tests
EclesioMeloJunior Nov 25, 2025
34e74fc
Merge branch 'master' into statistics-collector
EclesioMeloJunior Nov 25, 2025
ea5eeae
chore: include rewards-statistics-collector on benchmark
EclesioMeloJunior Nov 25, 2025
7b83139
Merge branch 'master' into statistics-collector
EclesioMeloJunior Nov 25, 2025
d26b8d5
Merge branch 'statistics-collector' of github.com:ChainSafe/polkadot-…
EclesioMeloJunior Nov 25, 2025
963ecb5
Merge branch 'master' into statistics-collector
EclesioMeloJunior Nov 26, 2025
200e615
Merge branch 'master' into statistics-collector
EclesioMeloJunior Dec 1, 2025
2293e70
chore: remove charts
EclesioMeloJunior Dec 1, 2025
c06eb92
Merge branch 'master' into statistics-collector
EclesioMeloJunior Dec 8, 2025
f1e2ed7
chore: update benchmark assert values
EclesioMeloJunior Dec 8, 2025
b60c6ee
Merge branch 'statistics-collector' of github.com:ChainSafe/polkadot-…
EclesioMeloJunior Dec 8, 2025
49453cb
chore: run `cargo +nightly fmt`
EclesioMeloJunior Dec 8, 2025
2972131
Merge branch 'master' of github.com:paritytech/polkadot-sdk into stat…
EclesioMeloJunior Dec 11, 2025
56ab9a3
Merge branch 'master' into statistics-collector
EclesioMeloJunior Dec 11, 2025
7ab0893
chore: address comment
EclesioMeloJunior Dec 11, 2025
24a7212
Merge branch 'statistics-collector' of github.com:ChainSafe/polkadot-…
EclesioMeloJunior Dec 11, 2025
0f21f12
Merge branch 'master' into statistics-collector
EclesioMeloJunior Dec 15, 2025
6a3dbae
Merge branch 'master' into statistics-collector
EclesioMeloJunior Dec 16, 2025
43bdc6c
chore: addressing comments
EclesioMeloJunior Dec 17, 2025
cf1d22e
Merge branch 'master' into statistics-collector
EclesioMeloJunior Dec 17, 2025
089a11f
accumulate stats w/o candidate hash
EclesioMeloJunior Jan 6, 2026
7b17b6e
Merge branch 'master' into statistics-collector
EclesioMeloJunior Jan 6, 2026
a7d75c0
Merge branch 'statistics-collector' of github.com:ChainSafe/polkadot-…
EclesioMeloJunior Jan 6, 2026
ad7130c
chore: fix tests
EclesioMeloJunior Jan 6, 2026
b9873ab
Merge branch 'master' into statistics-collector
EclesioMeloJunior Jan 6, 2026
c47f2bc
chore: prune availability chunks stats with session with old session …
EclesioMeloJunior Jan 7, 2026
f809b59
chore: changes on av-distri metrics
EclesioMeloJunior Jan 7, 2026
b4b8586
Merge branch 'statistics-collector' of github.com:ChainSafe/polkadot-…
EclesioMeloJunior Jan 7, 2026
318a3cb
chore: clean up active leaves retrieve header
EclesioMeloJunior Jan 7, 2026
4561d52
chore: changes to pruning
EclesioMeloJunior Jan 8, 2026
629fa49
Merge branch 'master' into statistics-collector
EclesioMeloJunior Jan 8, 2026
fea4944
Merge branch 'statistics-collector' of github.com:ChainSafe/polkadot-…
EclesioMeloJunior Jan 8, 2026
ff2bc65
chore: all tests passed
EclesioMeloJunior Jan 8, 2026
6f5c5a8
Merge branch 'master' into statistics-collector
EclesioMeloJunior Jan 9, 2026
11857eb
Merge branch 'master' into statistics-collector
EclesioMeloJunior Jan 12, 2026
8e98857
chore: use chunk session index from candidate metadata from av-store
EclesioMeloJunior Jan 13, 2026
27aaa6d
Merge branch 'statistics-collector' of github.com:ChainSafe/polkadot-…
EclesioMeloJunior Jan 13, 2026
54b9fdf
chore: small changes
EclesioMeloJunior Jan 13, 2026
3b753a7
Merge branch 'master' into statistics-collector
EclesioMeloJunior Jan 13, 2026
7f23347
Merge branch 'master' into statistics-collector
EclesioMeloJunior Jan 14, 2026
73a4e07
compilation successful
EclesioMeloJunior Jan 14, 2026
c2f0a0d
Merge branch 'statistics-collector' of github.com:ChainSafe/polkadot-…
EclesioMeloJunior Jan 14, 2026
dacbd86
Merge branch 'master' into statistics-collector
EclesioMeloJunior Jan 16, 2026
e41fe7a
fix cargo fmt
EclesioMeloJunior Jan 16, 2026
6acce36
Merge branch 'statistics-collector' of github.com:ChainSafe/polkadot-…
EclesioMeloJunior Jan 16, 2026
ef840b4
Merge branch 'master' into statistics-collector
EclesioMeloJunior Jan 16, 2026
d723e64
chore: provide comments to subsystem-types `RewardsStatisticsCollecto…
EclesioMeloJunior Jan 16, 2026
367e57e
Merge branch 'statistics-collector' of github.com:ChainSafe/polkadot-…
EclesioMeloJunior Jan 16, 2026
1916ecb
chore: fix toml
EclesioMeloJunior Jan 17, 2026
979f031
chore: added crate to umbrella
EclesioMeloJunior Jan 17, 2026
1aae955
chore: fix error on subsystem-test-helpers
EclesioMeloJunior Jan 17, 2026
c6e1aaa
Merge branch 'master' into statistics-collector
EclesioMeloJunior Jan 19, 2026
134e246
Merge branch 'statistics-collector' of github.com:ChainSafe/polkadot-…
EclesioMeloJunior Jan 19, 2026
4e55909
Merge branch 'master' into statistics-collector
EclesioMeloJunior Jan 20, 2026
03bbc32
chore: fixing CI
EclesioMeloJunior Jan 20, 2026
2a4a942
Merge branch 'statistics-collector' of github.com:ChainSafe/polkadot-…
EclesioMeloJunior Jan 20, 2026
78918df
Merge branch 'master' into statistics-collector
EclesioMeloJunior Jan 20, 2026
9bf6559
chore: removing unused imports
EclesioMeloJunior Jan 20, 2026
637960e
chore: trying to fix CI
EclesioMeloJunior Jan 20, 2026
91b4544
chore: rollback umbrella cargo toml adding only the new crate
EclesioMeloJunior Jan 20, 2026
b05c552
chore: left cargo lock untouched
EclesioMeloJunior Jan 20, 2026
10bdf98
chore: finally found the problem
EclesioMeloJunior Jan 20, 2026
0cbb374
Merge branch 'master' into statistics-collector
EclesioMeloJunior Jan 21, 2026
70a5444
Merge branch 'master' into statistics-collector
EclesioMeloJunior Jan 21, 2026
6ea5b1a
chore: include prdoc
EclesioMeloJunior Jan 21, 2026
95ac8e6
Merge branch 'statistics-collector' of github.com:ChainSafe/polkadot-…
EclesioMeloJunior Jan 21, 2026
819cf86
chore: update prdoc, update tests
EclesioMeloJunior Jan 21, 2026
88a21a5
chore: check fixes
EclesioMeloJunior Jan 21, 2026
0c75d4f
chore: fmt fixed
EclesioMeloJunior Jan 21, 2026
e8e7b62
chore: fixed more CI
EclesioMeloJunior Jan 21, 2026
9b192ea
chore: fix clippy
EclesioMeloJunior Jan 21, 2026
9b1777d
Merge branch 'master' into statistics-collector
EclesioMeloJunior Jan 21, 2026
93af71c
chore: fix CI
EclesioMeloJunior Jan 22, 2026
aa11c4a
Merge branch 'master' into statistics-collector
EclesioMeloJunior Jan 22, 2026
67d4c98
Merge branch 'statistics-collector' of github.com:ChainSafe/polkadot-…
EclesioMeloJunior Jan 22, 2026
d945715
chore: useless SessionIndex import
EclesioMeloJunior Jan 22, 2026
07f9abd
chore: fix cargo fmt diffs
EclesioMeloJunior Jan 22, 2026
0bdc7e1
chore: fix toml simple formatting
EclesioMeloJunior Jan 22, 2026
295017a
chore: unused imports
EclesioMeloJunior Jan 23, 2026
4a54f0e
Merge branch 'master' into statistics-collector
EclesioMeloJunior Jan 23, 2026
44a7265
Merge branch 'statistics-collector' of github.com:ChainSafe/polkadot-…
EclesioMeloJunior Jan 23, 2026
8379297
fix `availability_is_recovered_from_chunks_even_if_backing_group_supp…
EclesioMeloJunior Jan 26, 2026
2691ccb
fix `recovers_from_only_chunks_if_pov_large`
EclesioMeloJunior Jan 26, 2026
5f185b1
chore: fixed `collating_using_undying_collator`
EclesioMeloJunior Jan 27, 2026
6ad3fb3
Merge branch 'master' into statistics-collector
EclesioMeloJunior Jan 27, 2026
afae188
chore: fix clippy diffs
EclesioMeloJunior Jan 27, 2026
4ec7716
chore: fix `overseer_all_subsystems_receive_signals_and_messages`
EclesioMeloJunior Jan 27, 2026
d7c8645
Merge branch 'statistics-collector' of github.com:ChainSafe/polkadot-…
EclesioMeloJunior Jan 27, 2026
b4131d5
chore: fix clippy + fmt
EclesioMeloJunior Jan 27, 2026
a4a71c7
Merge branch 'master' into statistics-collector
EclesioMeloJunior Jan 30, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions Cargo.lock

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

3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -180,13 +180,15 @@ members = [
"polkadot/node/core/dispute-coordinator",
"polkadot/node/core/parachains-inherent",
"polkadot/node/core/prospective-parachains",
"polkadot/node/core/consensus-statistics-collector",
"polkadot/node/core/provisioner",
"polkadot/node/core/pvf",
"polkadot/node/core/pvf-checker",
"polkadot/node/core/pvf/common",
"polkadot/node/core/pvf/execute-worker",
"polkadot/node/core/pvf/prepare-worker",
"polkadot/node/core/runtime-api",
"polkadot/node/core/consensus-statistics-collector",
"polkadot/node/gum",
"polkadot/node/gum/proc-macro",
"polkadot/node/malus",
Expand Down Expand Up @@ -1126,6 +1128,7 @@ polkadot-node-core-chain-selection = { path = "polkadot/node/core/chain-selectio
polkadot-node-core-dispute-coordinator = { path = "polkadot/node/core/dispute-coordinator", default-features = false }
polkadot-node-core-parachains-inherent = { path = "polkadot/node/core/parachains-inherent", default-features = false }
polkadot-node-core-prospective-parachains = { path = "polkadot/node/core/prospective-parachains", default-features = false }
polkadot-node-core-consensus-statistics-collector = { path = "polkadot/node/core/consensus-statistics-collector", default-features = false }
polkadot-node-core-provisioner = { path = "polkadot/node/core/provisioner", default-features = false }
polkadot-node-core-pvf = { path = "polkadot/node/core/pvf", default-features = false }
polkadot-node-core-pvf-checker = { path = "polkadot/node/core/pvf-checker", default-features = false }
Expand Down
5 changes: 3 additions & 2 deletions polkadot/node/core/approval-voting/src/import.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ use crate::{
};

use polkadot_node_primitives::approval::time::{slot_number_to_tick, Tick};

use polkadot_node_subsystem::messages::ConsensusStatisticsCollectorMessage;
use super::{State, LOG_TARGET};

#[derive(Debug)]
Expand Down Expand Up @@ -335,7 +335,8 @@ pub struct BlockImportedCandidates {
pub(crate) async fn handle_new_head<
Sender: SubsystemSender<ChainApiMessage>
+ SubsystemSender<RuntimeApiMessage>
+ SubsystemSender<ChainSelectionMessage>,
+ SubsystemSender<ChainSelectionMessage>
+ SubsystemSender<ConsensusStatisticsCollectorMessage>,
AVSender: SubsystemSender<ApprovalDistributionMessage>,
B: Backend,
>(
Expand Down
60 changes: 57 additions & 3 deletions polkadot/node/core/approval-voting/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ use persisted_entries::{ApprovalEntry, BlockEntry, CandidateEntry};
use polkadot_node_primitives::approval::time::{
slot_number_to_tick, Clock, ClockExt, DelayedApprovalTimer, SystemClock, Tick,
};
use polkadot_node_subsystem::messages::ConsensusStatisticsCollectorMessage;

mod approval_checking;
pub mod approval_db;
Expand Down Expand Up @@ -2883,7 +2884,8 @@ async fn import_approval<Sender>(
wakeups: &Wakeups,
) -> SubsystemResult<(Vec<Action>, ApprovalCheckResult)>
where
Sender: SubsystemSender<RuntimeApiMessage>,
Sender: SubsystemSender<RuntimeApiMessage> +
SubsystemSender<ConsensusStatisticsCollectorMessage>,
{
macro_rules! respond_early {
($e: expr) => {{
Expand Down Expand Up @@ -2922,7 +2924,7 @@ where
gum::trace!(
target: LOG_TARGET,
"Received approval for num_candidates {:}",
approval.candidate_indices.count_ones()
approval.candidate_indices.clone().count_ones()
);

let mut actions = Vec::new();
Expand Down Expand Up @@ -3036,7 +3038,8 @@ async fn advance_approval_state<Sender>(
wakeups: &Wakeups,
) -> Vec<Action>
where
Sender: SubsystemSender<RuntimeApiMessage>,
Sender: SubsystemSender<RuntimeApiMessage> +
SubsystemSender<ConsensusStatisticsCollectorMessage>,
{
let validator_index = transition.validator_index();

Expand Down Expand Up @@ -3091,6 +3094,14 @@ where
let is_approved = check.is_approved(tick_now.saturating_sub(APPROVAL_DELAY));
if status.last_no_shows != 0 {
metrics.on_observed_no_shows(status.last_no_shows);
sender
.send_message(
ConsensusStatisticsCollectorMessage::ObservedNoShows(
session_index,
status.no_show_validators.clone(),
))
.await;

gum::trace!(
target: LOG_TARGET,
?candidate_hash,
Expand Down Expand Up @@ -3163,7 +3174,50 @@ where
}
if newly_approved {
state.record_no_shows(session_index, para_id.into(), &status.no_show_validators);
let mut collected_useful_approvals = vec![];

match status.required_tranches {
RequiredTranches::All => {
collected_useful_approvals.extend(candidate_entry.approvals().iter_ones().into());
},
RequiredTranches::Exact {needed, ..} => {
let tranches = approval_entry.tranches();
for validator_approval_idx in candidate_entry.approvals().iter_ones() {
for tranche_entry in tranches {
if tranche_entry.tranche() <= needed {
let trance_assignments = tranche_entry.assignments();
let useful_vote = trance_assignments
.iter()
.find(|(validator_on_tranche, _)| *validator_on_tranche == ValidatorIndex(validator_approval_idx as _));

match useful_vote {
Some((vidx, _)) => collected_useful_approvals.push(*vidx),
// Found no useful votes on a needed tranche
None => {}
}
}
}
}
},
RequiredTranches::Pending {..} => panic!("Newly approved candidate should never be pending; qed"),
}

if collected_useful_approvals.len() > 0 {
_ = sender.try_send_message(ConsensusStatisticsCollectorMessage::CandidateApproved(
candidate_hash,
block_hash,
collected_useful_approvals,
)).map_err(|_| {
gum::warn!(
target: LOG_TARGET,
?candidate_hash,
?block_hash,
"Failed to send approvals to statistics subsystem",
);
});
}
}

actions.extend(schedule_wakeup_action(
&approval_entry,
block_hash,
Expand Down
33 changes: 33 additions & 0 deletions polkadot/node/core/consensus-statistics-collector/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
[package]
name = "polkadot-node-core-consensus-statistics-collector"
version = "6.0.0"
authors.workspace = true
edition.workspace = true
license.workspace = true
description = "The Statistics Collector subsystem. Collects Approval Voting and Approvals Distributions stats."
homepage.workspace = true
repository.workspace = true

[lints]
workspace = true

[dependencies]
fatality = { workspace = true }
futures = { workspace = true }
gum = { workspace = true, default-features = true }
thiserror = { workspace = true }

polkadot-node-subsystem = { workspace = true, default-features = true }
polkadot-node-subsystem-util = { workspace = true, default-features = true }
polkadot-primitives = { workspace = true, default-features = true }
polkadot-node-primitives = { workspace = true, default-features = true }

[dev-dependencies]
assert_matches = { workspace = true }
polkadot-node-subsystem-test-helpers = { workspace = true }
polkadot-primitives = { workspace = true, features = ["test"] }
polkadot-primitives-test-helpers = { workspace = true }
rand = { workspace = true }
rstest = { workspace = true }
sp-core = { workspace = true, default-features = true }
sp-tracing = { workspace = true }
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
use std::collections::{HashMap, HashSet};
use polkadot_primitives::{CandidateHash, Hash, SessionIndex, ValidatorIndex};
use crate::View;
use crate::error::Result;

#[derive(Debug, Clone, Default)]
pub struct ApprovalsStats {
pub votes: HashSet<ValidatorIndex>,
}

impl ApprovalsStats {
pub fn new(votes: HashSet<ValidatorIndex>) -> Self {
Self { votes }
}
}

pub fn handle_candidate_approved(
view: &mut View,
block_hash: Hash,
candidate_hash: CandidateHash,
approvals: Vec<ValidatorIndex>
) {
if let Some(relay_view) = view.per_relay.get_mut(&block_hash) {
relay_view.approvals_stats
.entry(candidate_hash)
.or_default()
.and_modify(|a: &mut ApprovalsStats| {
a.votes.extend(approvals.into());
});
}
}

pub fn handle_observed_no_shows(
view: &mut View,
session_index: SessionIndex,
no_show_validators: Vec<ValidatorIndex>,
) {
view.no_shows_per_session
.entry(session_index)
.and_modify(|q: &mut HashMap<ValidatorIndex, usize>| {
for v_idx in no_show_validators {
q.entry(*v_idx)
.and_modify(|v: &mut usize| *v += 1)
.or_insert(1);
}
})
.or_insert(HashMap::new());
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
use std::collections::{HashMap, HashSet};
use std::ops::Add;
use gum::CandidateHash;
use polkadot_primitives::{SessionIndex, ValidatorIndex};
use crate::View;

pub struct ChunksDownloaded {
pub per_candidate: HashMap<CandidateHash, HashMap<ValidatorIndex, u64>>,
}

impl ChunksDownloaded {
pub fn new() -> Self {
Self {
per_candidate: Default::default(),
}
}

pub fn note_candidate_chunk_downloaded(
&mut self,
hash: CandidateHash,
validator_index: ValidatorIndex,
count: u64,
) {
self.per_candidate
.entry(hash)
.or_default()
.entry(validator_index)
.or_default()
.add(count);
}
}

// whenever chunks are acquired throughout availability
// recovery we collect the metrics about what validator
// provided and the amount of chunks
pub fn handle_chunks_downloaded(
view: &mut View,
session_index: SessionIndex,
candidate_hash: CandidateHash,
downloads: HashMap<ValidatorIndex, u64>,
) {
view.candidates_per_session
.entry(session_index)
.or_default()
.insert(candidate_hash);

for (validator_index, download_count) in downloads {
view.chunks_downloaded
.note_candidate_chunk_downloaded(candidate_hash, validator_index, download_count)
}
}
56 changes: 56 additions & 0 deletions polkadot/node/core/consensus-statistics-collector/src/error.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
// Copyright (C) Parity Technologies (UK) Ltd.
// This file is part of Polkadot.

// Polkadot is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.

// Polkadot is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.

// You should have received a copy of the GNU General Public License
// along with Polkadot. If not, see <http://www.gnu.org/licenses/>.

//! Error types.

use futures::channel::oneshot;

use polkadot_node_subsystem::{
SubsystemError,
};
use polkadot_node_subsystem_util::runtime;

use crate::LOG_TARGET;
use fatality::Nested;

#[allow(missing_docs)]
#[fatality::fatality(splitable)]
pub enum Error {
#[fatal]
#[error("Receiving message from overseer failed: {0}")]
SubsystemReceive(#[source] SubsystemError),
}

/// General `Result` type.
pub type Result<R> = std::result::Result<R, Error>;
/// Result for non-fatal only failures.
pub type JfyiErrorResult<T> = std::result::Result<T, JfyiError>;
/// Result for fatal only failures.
pub type FatalResult<T> = std::result::Result<T, FatalError>;

/// Utility for eating top level errors and log them.
///
/// We basically always want to try and continue on error. This utility function is meant to
/// consume top-level errors by simply logging them
pub fn log_error(result: Result<()>, ctx: &'static str) -> FatalResult<()> {
match result.into_nested()? {
Ok(()) => Ok(()),
Err(jfyi) => {
gum::debug!(target: LOG_TARGET, error = ?jfyi, ctx);
Ok(())
},
}
}
Loading