Skip to content
Open
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 @@ -357,6 +357,7 @@ actual_slot = finalized_slot + 1 + relative_index
- `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
- 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 parked (2,048 of them aggregates), 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)
- Data columns: every check runs in p2p. A column gossip did not accept (`Queue`/`Overloaded`), every fetched column, and parked columns replayed after their parent imports go through the chain checks in `p2p/src/beacon/column_checks.rs`, grouped by block with each `(block, index)` kept once. A group's rules before the KZG proofs run through one `column::ChainPrechecks`, which judges what the block's sidecars share (the fulu signed header's rules, the gloas block lookup) once; the proofs then go through `column::kzg_verdicts` in sub-batches of at most 16 columns, each on its own `column_check_permits` permit, a failed batch re-verified column by column. Each sidecar gets the verdict `column::chain_checks_for` gives it alone. The chain actor stores what it gets unchecked; only debug builds re-run `chain_checks_for` there. A held fulu block's custody columns can also come from the execution client (`engine_getBlobsV2`, `crates/blockchain/src/beacon_blobs.rs`; asked only for a block at most `MAX_ASK_AGE_SLOTS` behind the clock, so not during range sync), put through the same `ChainPrechecks` and `kzg_verdicts` in the chain actor's blocking task (the spec lets a node skip that, this one does not: a stored column keeps every other copy out, and import trusts it), and handed to p2p as `SidecarOrigin::ExecutionLayer` through `check_data_column_sidecars`, which records them seen, publishes them on their subnets and forwards them; see `docs/beacon_engine.md`
- Beacon subscribes seven global topics plus two node-id-derived subnet families: custody
Expand Down
19 changes: 19 additions & 0 deletions crates/blockchain/src/beacon_envelope.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1310,6 +1310,25 @@ pub(crate) mod tests {
assert!(server.envelopes.blocks_awaiting_parent_payload.is_empty());
}

#[tokio::test]
#[cfg_attr(
not(feature = "beacon-spec-tests"),
ignore = "needs the fork choice fixtures; run `make consensus-spec-tests`"
)]
async fn an_imported_block_tells_the_p2p_layer_its_state_is_ready() {
let case = Case::new("get_head", TIEBREAK);
let mut server = case.server(12);
let p2p = Arc::new(crate::tests::RecordingP2P::default());
server.p2p = Some(p2p.clone());

server
.on_block(case.block(PARENT), ImportTimings::default())
.await;

assert!(server.store.has_state(&root(PARENT)).unwrap());
assert_eq!(*p2p.states_ready.lock().unwrap(), vec![root(PARENT)]);
}

#[tokio::test]
#[cfg_attr(
not(feature = "beacon-spec-tests"),
Expand Down
53 changes: 51 additions & 2 deletions crates/blockchain/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3423,6 +3423,8 @@ impl BlockChainServer {
// This root now has a post-state, which is the one thing every
// sidecar parked under it was waiting for.
self.drain_sidecars_awaiting_parent(block_root);
// And every vote for it the p2p layer is holding.
self.announce_block_state_ready(block_root);

// An envelope that arrived ahead of this block can be judged now.
self.note_block_imported_for_envelope(block_root);
Expand Down Expand Up @@ -3541,6 +3543,21 @@ impl BlockChainServer {
}
}

/// Tell the p2p layer `block_root` has a post-state now, so the votes for
/// it that arrived while it was still importing can be checked.
///
/// Beacon only: lean gossip has no verdicts to hold.
pub(crate) fn announce_block_state_ready(&self, block_root: H256) {
if self.store.chain() != Chain::Beacon {
return;
}
if let Some(ref p2p) = self.p2p {
let _ = p2p.block_state_ready(block_root).inspect_err(
|err| error!(%block_root, %err, "Failed to tell the p2p layer a block's state is ready"),
);
}
}

/// Move pending children of `parent_root` into the work queue for iterative
/// processing. This replaces the old recursive `process_pending_children`.
fn collect_pending_children(
Expand Down Expand Up @@ -5237,14 +5254,17 @@ mod tests {
}

/// Every `BlockChainToP2P` message the chain actor sends, kept for a test
/// to read back. Only `check_data_column_sidecars` and `fetch_block` are
/// recorded: nothing under test here sends the others.
/// to read back. Only `check_data_column_sidecars`, `fetch_block` and
/// `block_state_ready` are recorded: nothing under test here sends the
/// others.
#[derive(Default)]
pub(crate) struct RecordingP2P {
pub(crate) checks: std::sync::Mutex<Vec<Vec<DataColumnSidecar>>>,
/// The origin each entry of `checks` was handed over with, in order.
pub(crate) check_origins: std::sync::Mutex<Vec<ethlambda_network_api::SidecarOrigin>>,
pub(crate) fetches: std::sync::Mutex<Vec<FetchRequest>>,
/// Every root announced through `block_state_ready`, in order.
pub(crate) states_ready: std::sync::Mutex<Vec<H256>>,
}

impl ethlambda_network_api::BlockChainToP2P for RecordingP2P {
Expand Down Expand Up @@ -5283,6 +5303,13 @@ mod tests {
self.checks.lock().unwrap().push(sidecars);
Ok(())
}
fn block_state_ready(
&self,
block_root: H256,
) -> Result<(), spawned_concurrency::error::ActorError> {
self.states_ready.lock().unwrap().push(block_root);
Ok(())
}
}

/// `beacon_server(store)` with a [`RecordingP2P`] wired in as its p2p ref.
Expand All @@ -5293,6 +5320,28 @@ mod tests {
(server, p2p)
}

#[test]
fn a_ready_beacon_state_is_announced_and_a_lean_one_is_not() {
let (server, p2p) = beacon_server_recording(beacon_store(GENESIS_TIME, 0));
server.announce_block_state_ready(H256::repeat_byte(7));
assert_eq!(
*p2p.states_ready.lock().unwrap(),
vec![H256::repeat_byte(7)]
);

// Lean gossip has no verdicts held, so there is nothing to release.
let store = Store::from_anchor_state(
Arc::new(InMemoryBackend::default()),
State::from_genesis(0, Vec::new()),
DEFAULT_MILLISECONDS_PER_SLOT,
);
let mut server = lean_server(store);
let p2p = Arc::new(RecordingP2P::default());
server.p2p = Some(p2p.clone());
server.announce_block_state_ready(H256::repeat_byte(7));
assert!(p2p.states_ready.lock().unwrap().is_empty());
}

/// A beacon store whose clock reads slot 10, so a sidecar at slot 10 is
/// neither future nor finalized. Fulu is active from genesis, since a
/// stored sidecar is decoded as the fork its slot names.
Expand Down
5 changes: 5 additions & 0 deletions crates/net/api/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,11 @@ pub trait BlockChainToP2P: Send + Sync {
sidecars: Vec<DataColumnSidecar>,
origin: SidecarOrigin,
) -> Result<(), ActorError>;
/// A beacon block's post-state is now cached under `block_root`. The p2p
/// layer holds the subnet attestations and aggregates that voted for it
/// before it got there, since their checks read that state, and checks
/// them again now.
fn block_state_ready(&self, block_root: H256) -> Result<(), ActorError>;
}

/// Where the sidecars handed to [`BlockChainToP2P::check_data_column_sidecars`]
Expand Down
1 change: 1 addition & 0 deletions crates/net/p2p/src/beacon/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ pub mod envelope_checks;
pub mod fork_schedule;
pub mod handler;
pub mod messages;
pub mod parked_votes;
pub mod protocols;
pub mod scoring;
pub mod subnets;
Expand Down
Loading
Loading