fix(attribution): measure confidence over votes cast, not the whole window
deploy / build (push) Successful in 6m46s
deploy / deploy-web (push) Successful in 4s
deploy / deploy-api (push) Successful in 14s

Mainnet has shown no node names since launch. Every miner renders as its raw
preimage while Planck, on the same code and the same feed, names twenty.

`votes` holds one slot per block checked and a `None` for every block whose
first reporter the feed could not separate from its second. Those are
abstentions — the feed did not say who led — but confidence divided agreement
by `votes.len()`, counting them as votes against. Measured on the live feed,
mainnet resolves a clean lead on about a quarter of blocks, so the best score
any author could reach was 0.25 against a `MIN_CONFIDENCE` of 0.6. No name
could ever be held, however unanimous the votes that were actually cast. Planck
cleared the bar only because 41-87% of its blocks produced usable votes.

Confidence is now agreement among cast votes, which is what it always meant:
"of the blocks where we could tell who was first, this fraction pointed here".
`MIN_VOTES` guards the other side, so a single vote in an otherwise silent
window is not read as 100% agreement.

`a_held_name_survives_a_confidence_dip` asserted `confidence < 1.0` after five
unresolvable blocks. That assertion encoded the bug. It now asserts the
opposite for abstentions and keeps a real dip — disagreeing votes — as the case
that lowers confidence.

Two false leads are recorded in CLAUDE.md so the next person does not spend the
afternoon on them: the feed delivers a 190-node roster before any live block
traffic, so `ImportedBlock` does not appear for ~40 s after subscribing and a
short probe concludes the feed is dead; and the roster's `AddedNode` entries
carry a height-0 placeholder block with a zero hash, which inflates the
apparent count of nodes claiming to be first if counted as import reports.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Jp6a8EDar9ueEhAxzep4V5
This commit is contained in:
2026-09-09 13:59:21 +03:00
co-authored by Claude Opus 5
parent 2cb8f1cf21
commit 057937e9cc
2 changed files with 118 additions and 5 deletions
+17
View File
@@ -46,6 +46,23 @@ have pruned; an error there is `None`, never a fallback to the current value —
substituting it is how a gap fill stamps today's difficulty across a stretch of
old heights and draws a flat plateau in the history chart.
**Attribution confidence is measured over votes *cast*, not over the window.**
`votes` holds one slot per block checked and a `None` for every block whose
first reporter the feed could not separate from its second. Those are
abstentions. Dividing agreement by the window length counts them as votes
against, and on a chain where clean leads are the minority that makes
`MIN_CONFIDENCE` unreachable: mainnet resolves a lead on about a quarter of
blocks, which capped every author at 0.25 against a 0.6 bar and named nobody,
however unanimous the cast votes were. `MIN_VOTES` is the companion guard, so
one lucky vote in a silent window is not 100% agreement.
Two things that look like this bug and are not: the feed sends a **190-node
roster before any live block traffic** — `ImportedBlock` does not start until
about 40 s after `subscribe:`, so any probe shorter than that sees zero and
concludes the feed is dead. And the roster's `AddedNode` entries carry a
placeholder block of height 0 with a zero hash; counting those as import
reports inflates the apparent number of nodes claiming to be first.
**`observed_at` is only a measurement when `at_tip` is true.** The flag is now a
column (`0002`). A gap fill writes a whole batch of `observed_at` within the same
second, so any query treating it as timing data must filter on it. The chain
+101 -5
View File
@@ -38,8 +38,23 @@ use blackbeard_entities::{AttributionSource, MinerId};
pub const LEAD_MS: i64 = 20;
/// Blocks that must have been checked before any name is shown.
pub const MIN_ATTEMPTS: u32 = 3;
/// Fraction of the vote window that must agree before a name is shown.
/// Fraction of the **cast** votes that must agree before a name is shown.
///
/// Cast, not the whole window. A block whose first reporter cannot be told from
/// its second is an abstention — the feed did not say who was first — and
/// counting it against the candidate makes the threshold unreachable on any
/// chain where clean leads are the minority. Mainnet yields a usable lead on
/// about a quarter of blocks, so measuring against the window capped every
/// author at 0.25 and no name was ever held, however unanimous the votes that
/// *were* cast.
pub const MIN_CONFIDENCE: f32 = 0.6;
/// Votes that must actually have been cast before any name is shown.
///
/// The companion to measuring confidence over cast votes: without it a single
/// lucky vote in an otherwise silent window reads as 100% agreement. Three is
/// the same evidence bar [`MIN_ATTEMPTS`] sets for blocks checked.
pub const MIN_VOTES: usize = 3;
/// Votes kept per author.
///
/// Bounded so a node that restarts or is renamed — which gives it a new
@@ -175,7 +190,11 @@ impl Attributor {
for vote in entry.votes.iter().flatten() {
*counts.entry(vote).or_default() += 1;
}
let total = entry.votes.len() as f32;
// Votes actually cast. `votes` holds one slot per block checked and a
// `None` for every block the feed could not resolve, so the window
// length is a count of *observations*, not of evidence.
let cast = entry.votes.iter().flatten().count();
let total = cast as f32;
let mut held = entry.held.clone();
if let Some(h) = &held
@@ -193,7 +212,10 @@ impl Attributor {
if let Some((best_key, best_n)) = best {
match &held {
None => {
if entry.attempts >= MIN_ATTEMPTS && best_n as f32 / total >= MIN_CONFIDENCE {
if entry.attempts >= MIN_ATTEMPTS
&& cast >= MIN_VOTES
&& best_n as f32 / total >= MIN_CONFIDENCE
{
held = Some(best_key);
}
}
@@ -232,6 +254,63 @@ impl NodeKey {
#[cfg(test)]
mod tests {
/// The bug this file was changed to fix.
///
/// Mainnet resolves a clean first-reporter on roughly a quarter of blocks;
/// the rest are ties the feed cannot separate. Measuring agreement against
/// the whole window capped every author at 0.25 against a 0.6 threshold, so
/// no name was ever held however unanimous the cast votes were.
#[test]
fn abstentions_do_not_count_against_the_candidate() {
let mut a = Attributor::new();
let m = MinerId("0xaa".into());
let node = NodeKey::Peer("QmAuthor".into());
// Twelve blocks, three resolvable and all naming the same node. The
// other nine are ties: the feed saw the block but could not say who led.
for i in 0..12 {
if i % 4 == 0 {
a.observe(&m, Some((node.clone(), Some(80))));
} else {
a.observe(&m, None);
}
}
let got = a.attribute(&m, |_| Some("author-node".into()));
assert_eq!(got.source, AttributionSource::Telemetry, "{got:?}");
assert_eq!(got.display, "author-node");
assert!(got.confidence > 0.99, "unanimous cast votes: {got:?}");
}
#[test]
fn a_single_lucky_vote_still_names_nobody() {
// The other half of measuring over cast votes: one vote in an otherwise
// silent window is 100% agreement and almost no evidence.
let mut a = Attributor::new();
let m = MinerId("0xbb".into());
a.observe(&m, Some((NodeKey::Peer("QmOnce".into()), Some(90))));
for _ in 0..11 {
a.observe(&m, None);
}
assert_eq!(
a.attribute(&m, |_| Some("whoever".into())).source,
AttributionSource::Preimage
);
}
#[test]
fn cast_votes_that_disagree_still_name_nobody() {
// Abstentions are discounted; genuine disagreement is not.
let mut a = Attributor::new();
let m = MinerId("0xcc".into());
for i in 0..9 {
let key = NodeKey::Peer(format!("Qm{}", i % 3));
a.observe(&m, Some((key, Some(75))));
}
assert_eq!(
a.attribute(&m, |_| Some("nope".into())).source,
AttributionSource::Preimage
);
}
use super::*;
fn miner() -> MinerId {
@@ -318,13 +397,30 @@ mod tests {
a.attribute(&miner(), named).source,
AttributionSource::Telemetry
);
// Five blocks the feed missed. Confidence falls to 10/15, still named.
// Five blocks the feed could not resolve. These are abstentions, not
// evidence against: the name stays and confidence is undiluted, because
// every vote actually cast still agrees. (This assertion used to read
// `confidence < 1.0`, which encoded the bug — counting abstentions in
// the denominator is what made the threshold unreachable on a chain
// where clean leads are the minority.)
for _ in 0..5 {
a.observe(&miner(), None);
}
let got = a.attribute(&miner(), named);
assert_eq!(got.source, AttributionSource::Telemetry);
assert!(got.confidence < 1.0);
assert!(
got.confidence > 0.99,
"abstentions must not dilute: {got:?}"
);
// A genuine dip is disagreement, and that does lower confidence while
// the held name rides it out.
for _ in 0..3 {
a.observe(&miner(), Some((NodeKey::Peer("other".into()), Some(80))));
}
let got = a.attribute(&miner(), named);
assert_eq!(got.source, AttributionSource::Telemetry);
assert!(got.confidence < 1.0, "disagreement must dilute: {got:?}");
}
#[test]