broadcast: implement Observer interface + NoOpObserver + SessionRole#68
Merged
Conversation
Replaces the empty `observer.zig` placeholder with the full broadcast
event Observer, aligned with ethp2p `broadcast/observer.go`. Zig has no
interfaces, so it is type-erased (ptr + vtable, like `std.mem.Allocator`)
with a `noop` default used by `EngineConfig`. Adds the `SessionRole`
enum (origin/relay) to `layer.broadcast_types`.
The full 15-callback surface mirrors the Go interface. Emission is wired
at the sites that exist in the Zig port today:
- onChannelAttached (Engine.attachChannelRs)
- onPeerSubscribed / onPeerUnsubscribed (ChannelRs.addMember/removeMember)
- onSessionStarted (publish -> origin, attachRelaySession -> relay)
- onSessionDecoded (ChannelRs.sessionDecode)
- onChunkRcvd (relayIngestChunk / relayIngestChunkVerified, one
emission per ingest with the resolved verdict)
The remaining callbacks (peer handshake/gone, session disposal,
chunk-sent/error, routing, preamble, strategy-progress) match the Go
interface for forward compatibility and are emitted as their subsystems
land. A `Recording` test observer plus an engine integration test cover
the wired events.
README: implementation-status table now lists the Observer/SessionRole
and the trace writer; requirements bumped to Zig 0.16.0.
Closes #58.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #58.
Replaces the empty
src/broadcast/observer.zigplaceholder (pub const Observer = struct {};) with the full broadcast event Observer, aligned withbroadcast/observer.go, and adds theSessionRoleenum (origin/relay) tolayer.broadcast_types.Design
Zig has no interfaces, so
Observeris type-erased (ptr+vtable, likestd.mem.Allocator) with anoopdefault thatEngineConfignow uses. The full 15-callback surface mirrors the Go interface for forward compatibility.Emission (wired where the events exist today)
onChannelAttachedEngine.attachChannelRsonPeerSubscribed/onPeerUnsubscribedChannelRs.addMember/removeMemberonSessionStartedpublish→origin,attachRelaySession→relayonSessionDecodedChannelRs.sessionDecodeonChunkRcvdrelayIngestChunk/relayIngestChunkVerified— one emission per ingest with the resolved verdictThe remaining callbacks (
onPeerHandshook/Gone,onSessionDisposed,onChunkSent/Error,onRoutingUpdate,onPreambleOpened,onStrategyProgress) match the Go interface and will be emitted as their subsystems land (engine peer tracking; session disposal #62; strategy hooks). This unblocks theTracingObserverfollow-up for the trace subsystem (#59).Tests
Recordingtest observer verifies vtable dispatch + the no-op path.Engineintegration test drives publish→decode and asserts channel-attach / peer-subscribe / session-start(origin) / session-decode fire.Docs
README implementation-status table now lists the Observer +
SessionRoleand the trace writer; requirements bumped to Zig 0.16.0.Verified on stock Zig 0.16.0:
zig fmt --check,zig build test, andzig build test-broadcast(TSan) pass.