Skip to content

broadcast: implement Observer interface + NoOpObserver + SessionRole#68

Merged
ch4r10t33r merged 1 commit into
mainfrom
feat/observer-sessionrole-58
Jul 3, 2026
Merged

broadcast: implement Observer interface + NoOpObserver + SessionRole#68
ch4r10t33r merged 1 commit into
mainfrom
feat/observer-sessionrole-58

Conversation

@ch4r10t33r

Copy link
Copy Markdown
Collaborator

Closes #58.

Replaces the empty src/broadcast/observer.zig placeholder (pub const Observer = struct {};) with the full broadcast event Observer, aligned with broadcast/observer.go, and adds the SessionRole enum (origin/relay) to layer.broadcast_types.

Design

Zig has no interfaces, so Observer is type-erased (ptr + vtable, like std.mem.Allocator) with a noop default that EngineConfig now uses. The full 15-callback surface mirrors the Go interface for forward compatibility.

Emission (wired where the events exist today)

Callback Site
onChannelAttached Engine.attachChannelRs
onPeerSubscribed / onPeerUnsubscribed ChannelRs.addMember / removeMember
onSessionStarted publishorigin, attachRelaySessionrelay
onSessionDecoded ChannelRs.sessionDecode
onChunkRcvd relayIngestChunk / relayIngestChunkVerified — one emission per ingest with the resolved verdict

The 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 the TracingObserver follow-up for the trace subsystem (#59).

Tests

  • Recording test observer verifies vtable dispatch + the no-op path.
  • An Engine integration 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 + SessionRole and the trace writer; requirements bumped to Zig 0.16.0.

Verified on stock Zig 0.16.0: zig fmt --check, zig build test, and zig build test-broadcast (TSan) pass.

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.
@ch4r10t33r ch4r10t33r merged commit d3ea1d6 into main Jul 3, 2026
7 checks passed
@ch4r10t33r ch4r10t33r deleted the feat/observer-sessionrole-58 branch July 3, 2026 08:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

broadcast: implement Observer interface callbacks + SessionRole enum

1 participant