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
2 changes: 1 addition & 1 deletion CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +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)
- 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 still held at the startup digest's first epoch (`held_at`) and every later 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 at startup. The rollover adds a digest to it before joining one that is not listed (`Allowlist::list`), which only a clock stepped back makes it do: the filter gates this node's own joins too, and a refused join would leave the node deaf while it recorded the digest as held. 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 count limit, per peer or per RPC (`MaxCountSubscriptionFilter`): a refused join is never resent, a peer's held digests depend on its own client's join and leave timing, and gossipsub logs every over-limit RPC at `ERROR` with no penalty, which a peer could repeat at will; gossipsub does not export the `Subscription` type a quieter filter of our own would need. 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
17 changes: 7 additions & 10 deletions crates/net/p2p/src/beacon/scoring.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1354,11 +1354,11 @@ mod tests {
};
peer.swarm.dial(node_addr).expect("dial is accepted");

// 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);
// The control topic is under the digest before the one `node` starts
// on (electra's): one the subscription filter lists, as it does the
// start digest's predecessor, and outside the window the rollover
// below opens, so nothing but this test joins it.
let control_digest = schedule.digest_at(FULU - 1);
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] {
Expand All @@ -1382,12 +1382,9 @@ mod tests {
// The control: joined first, so the join grafts the peer before the
// topic has parameters.
let settings = ScoreSettings::new(&config, crate::MESH_N);
let inputs = ScoreInputs::placeholder();
let control_params = settings
.digest_topic_params(
control_digest,
DigestRole::Upcoming,
ScoreInputs::placeholder(),
)
.digest_topic_params(control_digest, DigestRole::Upcoming, inputs)
.into_iter()
.find(|(topic, _)| topic.hash() == control.hash())
.expect("the block topic is scored")
Expand Down
77 changes: 76 additions & 1 deletion crates/net/p2p/src/beacon/transition.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use ethlambda_types::beacon::preset;
use ethlambda_types::beacon::primitives::{Epoch, ForkDigest};
use ethlambda_types::time::unix_now_ms;
use libp2p::gossipsub::IdentTopic;
use tracing::{error, info};
use tracing::{error, info, warn};

use super::BeaconWire;
use super::topics::{self, BeaconTopics};
Expand Down Expand Up @@ -160,6 +160,30 @@ pub(crate) fn apply(server: &mut P2PServer, epoch: Epoch) -> Changes {
kept.push(existing.swap_remove(index));
continue;
}
// The subscription filter gates this node's own joins, and its list
// is built at startup for a clock that only moves forward: a digest
// the clock has stepped back to may not be on it. Joining it unlisted
// would be refused by gossipsub while everything below records it as
// held and leaves the digests the node was on, so it is listed first.
let every_topic = topics::every_topic(
entry.fork,
entry.digest,
wire.config.attestation_subnet_count,
);
let listed = server.subscription_allowlist.list(every_topic);
if listed > 0 {
warn!(
fork_digest = %hex::encode(entry.digest),
fork = entry.fork.as_str(),
activation_epoch = entry.activation_epoch,
epoch,
listed,
"Joining a fork digest that was not on the subscription allowlist: the clock \
has moved back to before the digests listed at startup. Listed it; peers' \
earlier subscriptions under it were dropped, so its meshes fill as peers \
connect or subscribe again"
);
}
let joined = BeaconTopics::for_fork(
entry.fork,
entry.digest,
Expand Down Expand Up @@ -326,6 +350,57 @@ mod tests {
);
}

/// A clock stepped back to before the digests listed at startup has the
/// rollover join one the subscription filter does not list. It is listed
/// first: gossipsub would refuse the joins otherwise, while the node
/// recorded them as held and left the topics it was on.
#[tokio::test]
async fn a_digest_the_clock_steps_back_to_is_listed_before_it_is_joined() {
use crate::subscription_filter::Allowlist;

let config = config();
let mut server = unconnected_beacon_server(config.clone(), 0).await;
let schedule = server.wire.beacon().expect("beacon").schedule.clone();
let gloas = schedule.current_at(GLOAS + 10);
let bpo = schedule.current_at(BPO + 10);
let subnets = config.attestation_subnet_count;
// What a node started well into gloas lists, cut down to gloas's own
// digest: the one before it is not what this test steps back to.
server.subscription_allowlist =
Allowlist::of(topics::every_topic(gloas.fork, gloas.digest, subnets));
apply(&mut server, GLOAS + 10);
assert_eq!(digests(&server), (gloas.digest, vec![]));
let block_under = |digest| topics::topic_name(digest, "beacon_block");
assert!(
!server
.subscription_allowlist
.contains(&block_under(bpo.digest))
);

// Back across two boundaries, to an epoch only the BPO digest holds.
apply(&mut server, BPO + 10);
assert_eq!(digests(&server), (bpo.digest, vec![]));
let wire = server.wire.beacon().expect("beacon");
assert!(!wire.topics.topics.is_empty());
for topic in &wire.topics.topics {
assert!(
server
.subscription_allowlist
.contains(topic.hash().as_str()),
"{topic} was joined unlisted"
);
}
// The subnets joined on demand under that digest are listed with it.
let last_attnet = topics::attestation_topic_name(bpo.digest, subnets - 1);
assert!(server.subscription_allowlist.contains(&last_attnet));
// Nothing is taken off the list: gloas's digest comes back.
assert!(
server
.subscription_allowlist
.contains(&block_under(gloas.digest))
);
}

#[tokio::test]
async fn a_live_crossing_joins_switches_and_leaves_in_order() {
let config = config();
Expand Down
Loading
Loading