Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,7 @@ actual_slot = finalized_slot + 1 + relative_index
- Topic: `/leanconsensus/{fork_digest}/{block|aggregation|attestation_N}/ssz_snappy`
- `fork_digest` is a 4-byte hex string (no `0x` prefix); currently the dummy `12345678` agreed across clients
- Mesh size: 8 (6-12 bounds), heartbeat: 700ms
- Subscription filter (`p2p/src/subscription_filter.rs`): gossipsub stores a peer's subscription only for a topic on the allowlist, which bounds what one peer holds, so a peer cannot grow this node's memory with topics of its own. The allowlist is every kind and every column, attestation and sync committee subnet under every digest of the `ForkSchedule` (`beacon::topics::every_topic`; lean: its three kinds and every committee subnet below `VALIDATOR_REGISTRY_LIMIT`, plus the ones it was told to join), built once at startup. Every subnet is on it, joined or not, because fanout publishing picks its peers from the stored subscriptions. The same filter gates this node's own `subscribe`, so a new subnet family has to be added to `every_topic` or the node cannot join it (a new global kind comes through `BeaconTopics::for_fork`). There is no per-peer count below the whole allowlist: a refused join is never resent, and a peer's held digests depend on its own client's join and leave timing (each join counted before the leaves that follow it). A hello over the per-RPC limit (twice the allowlist, at least 500) is ignored whole. See [`docs/beacon_wire.md`](docs/beacon_wire.md#which-subscriptions-are-kept)
- Beacon wire: `validate_messages()` is on, so every beacon message waits for a verdict (~4.2s before gossipsub's cache evicts it). Rules in `state_transition::beacon::gossip` (cheap half inline, stateful half on a bounded `spawn_blocking` task); plumbing in `p2p/src/beacon/verdict.rs`. Lean gossip still auto-forwards
- A subnet attestation or aggregate whose vote block is not imported yet (`UnknownBlock`/`StateUnavailable`) is parked with its verdict withheld (`p2p/src/beacon/parked_votes.rs`, lighthouse's reprocess queue) and checked once more when the chain actor's import sends `block_state_ready`; past 2.5 s, or with 16,384 held (parked, or released and not checked again yet; 2,048 of them aggregates; votes for a block not stored yet, whose root any peer can make up, at most half of each), it gets its first verdict instead. Rechecks run on their own permit pool (`recheck_permits`), not the attestation pool
- Beacon peer scoring: lighthouse's parameters ported in `p2p/src/beacon/scoring.rs` (block, aggregate, 64 attestation subnets, exits, slashings; columns and sync contributions unscored), refreshed every slot from the head's active validator count. Mesh-delivery scoring (P3) is gated off while the head lags more than 4 slots and for an epoch after, because a catching-up node `Ignore`s every aggregate and would otherwise graylist its own mesh. Every held fork digest is parametrized before `transition::apply` joins it (gossipsub never scores a mesh grafted before its topic had parameters); the previous digest's weights are zeroed at the switch, and the switch restarts the P3 warmup. The swarm disconnects peers below the graylist (-16000) every 10 s, and peers gossipsub reported as `SlowPeer` in every check for a minute (a disabled gossipsub handler never drains its send queue, so the queue's message copies stay in memory until the connection closes). Gossipsub reports an expired forward like a full queue, so our own saturated uplink makes every peer look slow: a report counts only above `SLOW_PEER_REPORT_THRESHOLD` failures (Lighthouse's cut), and one check disconnects at most `MAX_SLOW_PEER_DISCONNECTS_PER_CHECK` peers. Lean runs unscored. See [`docs/beacon_wire.md`](docs/beacon_wire.md#peer-scoring)
Expand Down
13 changes: 11 additions & 2 deletions crates/net/p2p/src/beacon/scoring.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1354,7 +1354,12 @@ mod tests {
};
peer.swarm.dial(node_addr).expect("dial is accepted");

let control = IdentTopic::new(topic_name([0xAB; 4], BEACON_BLOCK));
// The control topic is under the genesis digest: one the subscription
// filter lists, as it does every digest of the schedule, and far
// outside the window the rollover below opens, so nothing but this
// test joins it.
let control_digest = schedule.digest_at(0);
let control = IdentTopic::new(topic_name(control_digest, BEACON_BLOCK));
let upcoming = IdentTopic::new(topic_name(schedule.digest_at(BPO), BEACON_BLOCK));
for topic in [&control, &upcoming] {
let gossipsub = &mut peer.swarm.behaviour_mut().gossipsub;
Expand All @@ -1378,7 +1383,11 @@ mod tests {
// topic has parameters.
let settings = ScoreSettings::new(&config, crate::MESH_N);
let control_params = settings
.digest_topic_params([0xAB; 4], DigestRole::Upcoming, ScoreInputs::placeholder())
.digest_topic_params(
control_digest,
DigestRole::Upcoming,
ScoreInputs::placeholder(),
)
.into_iter()
.find(|(topic, _)| topic.hash() == control.hash())
.expect("the block topic is scored")
Expand Down
34 changes: 34 additions & 0 deletions crates/net/p2p/src/beacon/topics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,40 @@ pub fn data_column_subnet(kind: &str) -> Option<u64> {
suffix.parse().ok()
}

/// Every topic that exists under `fork_digest`, for the fork that digest
/// names: the global kinds, and every data column, attestation and sync
/// committee subnet.
///
/// This is what a peer on every subnet subscribes to, and so the widest this
/// node can subscribe or publish under one digest: a custody set grown by
/// validator custody, an aggregator duty and a sync committee duty each join
/// subnets inside these families, and the Beacon API publishes on subnets this
/// node never joins. The subscription allowlist
/// ([`crate::subscription_filter`]) is built from it.
///
/// The global kinds come from [`BeaconTopics::for_fork`], which stays the one
/// place a fork changes which kinds exist. `sync_committee_{n}` is listed
/// under every digest, phase0's included, where no peer uses it.
pub fn every_topic(
fork: ForkName,
fork_digest: ForkDigest,
attestation_subnet_count: u64,
) -> Vec<IdentTopic> {
use ethlambda_types::beacon::constants::{
DATA_COLUMN_SIDECAR_SUBNET_COUNT, SYNC_COMMITTEE_SUBNET_COUNT,
};

let column_subnets: Vec<u64> = (0..DATA_COLUMN_SIDECAR_SUBNET_COUNT).collect();
let attestation_subnets: Vec<u64> = (0..attestation_subnet_count).collect();
let mut topics =
BeaconTopics::for_fork(fork, fork_digest, &column_subnets, &attestation_subnets).topics;
topics.extend(
(0..SYNC_COMMITTEE_SUBNET_COUNT as u64)
.map(|subnet_id| IdentTopic::new(sync_committee_topic_name(fork_digest, subnet_id))),
);
topics
}

/// The subscribed topics for one fork digest, built once at startup.
#[derive(Debug, Clone)]
pub struct BeaconTopics {
Expand Down
Loading
Loading