feat(events): add block_gossip chain event#535
Conversation
51184e6 to
5be589f
Compare
Add the block_gossip topic to the /lean/v0/events stream, the analog of the beacon block_gossip event: a block seen on the network before import (import may pend it while its parent chain is fetched). Emitted from the blockchain actor's NewBlock handler rather than a second P2P-side publisher, so the actor stays the sole event publisher and the write flow stays one-directional. Fires for both gossip'd and by-root-fetched blocks, since both re-enter through NewBlock. Ungated like block (not recency-gated), so subscribers can watch sync progress. Low-rate (one per block), so the payload is built unconditionally behind emit's no-subscriber guard.
e17223c to
a492c00
Compare
🤖 Kimi Code ReviewThis is a clean, straightforward addition of a No critical issues found. A few minor observations:
Code quality:
LGTM. Automated review by Kimi (Moonshot AI) · kimi-k2.5 · custom prompt |
🤖 Codex Code Review
I did not find additional consensus, security, or memory-safety issues in this diff itself. Verification note: I could not run the targeted Rust tests in this environment because Cargo/Rustup needs to write under read-only home directories ( Automated review by OpenAI Codex · gpt-5.4 · custom prompt |
Greptile SummaryAdds the beacon-style
Confidence Score: 4/5The PR appears safe to merge, with a non-blocking opportunity to avoid redundant block-root hashing when no event subscribers exist. The new event is wired through topic parsing, filtering, serialization, emission, tests, and documentation; the only accepted concern is avoidable payload computation before the event bus can take its no-subscriber fast path. crates/blockchain/src/lib.rs
|
| Filename | Overview |
|---|---|
| crates/blockchain/src/events.rs | Adds complete topic parsing, naming, event mapping, and unit coverage for BlockGossip. |
| crates/blockchain/src/lib.rs | Emits BlockGossip before import, but computes the block root even when the event bus has no subscribers. |
| docs/rpc.md | Accurately documents the new SSE topic, payload, and emission timing. |
Sequence Diagram
sequenceDiagram
participant P2P
participant BC as Blockchain actor
participant Bus as Event bus
participant Import as Block import
participant SSE as SSE subscriber
P2P->>BC: NewBlock
BC->>BC: Compute block root
BC->>Bus: emit(block_gossip)
Bus-->>SSE: event: block_gossip
BC->>Import: on_block
Import->>Import: Compute block root and import or pend
Prompt To Fix All With AI
Fix the following 1 code review issue. Work through them one at a time, proposing concise fixes.
---
### Issue 1 of 1
crates/blockchain/src/lib.rs:1327
**Avoid redundant block-root hashing**
The block root is computed before `EventBus::emit` can apply its no-subscriber guard, so handling `NewBlock` without SSE subscribers computes and discards a full SSZ root before normal block processing computes the same root again. Exposing a lazy emission path or reusing the root would avoid this actor-thread CPU cost.
Reviews (1): Last reviewed commit: "Merge branch 'main' into feat/events-blo..." | Re-trigger Greptile
Continues the chain-event pub-sub series (#516 / #517 / #518, all merged). Adds the beacon
block_gossipanalog.Event added
block_gossip{ slot, block }Notes
NewBlockhandler, not a second P2P-side publisher, so the actor stays the sole event publisher and the write flow stays one-directional (a core requirement of the series' design).NewBlock. Import may pend the block while its parent chain is fetched, so this precedes import.block(not recency-gated), so subscribers can watch sync progress. Low-rate (one per block), so the payload is built unconditionally behindemit's no-subscriber guard.Testing
cargo fmt,cargo clippy -p ethlambda-blockchain -p ethlambda-rpc(clean), blockchain lib + rpc events tests pass.Independent PR, based off
main. One of three sibling PRs continuing the series — alongside #533 (chain_reorg/safe_target) and #534 (attestation/aggregate), each independently based offmain. They touch overlapping regions ofevents.rs/docs/rpc.md, so whichever two merge later will each need a small conflict rebase. Opened as draft.