Skip to content

feat(libp2p): add local_peer_id to join/leave additional data#821

Open
samcm wants to merge 1 commit intomasterfrom
feat/libp2p-join-leave-local-peer-id
Open

feat(libp2p): add local_peer_id to join/leave additional data#821
samcm wants to merge 1 commit intomasterfrom
feat/libp2p-join-leave-local-peer-id

Conversation

@samcm
Copy link
Copy Markdown
Member

@samcm samcm commented May 8, 2026

Summary

xatu.libp2p.TraceEventMetadata.peer_id is shared across most libp2p AdditionalData types and consistently means "the remote peer involved" — except for Libp2PTraceJoin / Libp2PTraceLeave, where it semantically referred to the local host that subscribed/unsubscribed. Two consequences:

  1. The clickhouse column peer_id_unique_key on libp2p_join / libp2p_leave was overloaded with the same name as 26 other libp2p tables that mean "remote peer", but its actual meaning was the local node.
  2. pubsub.RawTracer.Join(topic) / Leave(topic) don't pass a peer.ID to producers (because there is no remote peer for those callbacks). Producers like TYSM end up emitting events with metadata.peer_id == "", the route handler's nil PeerId validator hard-rejects them, and libp2p_join / libp2p_leave end up with zero rows on clickhouse-raw.

Changes

  • proto: add a dedicated string local_peer_id field to AdditionalLibP2PTraceJoinData and AdditionalLibP2PTraceLeaveData. metadata.peer_id is no longer used for these two events.
  • migration: 002_libp2p_join_leave_local_peer_id renames the column peer_id_unique_keylocal_peer_id_unique_key on libp2p_join_local / libp2p_leave_local (plus the Distributed parents). Because the column is in ORDER BY, RENAME COLUMN isn't supported; the migration drops and recreates the tables.
  • route handlers (libp2p_join.go, libp2p_leave.go): read only local_peer_id. No fallback to the legacy metadata.peer_id — sentries that haven't been updated will fail validation, by design.
  • gen.go: regenerated via make clickhouse-routes. New field is LocalPeerIDUniqueKey, column is local_peer_id_unique_key.
  • clmimicry: handleJoinEvent / handleLeaveEvent populate the new LocalPeerId field from the inbound TraceEvent.PeerID.
  • tests: updated to use the new field and column name.

Pairs with

A tysm change populates TraceEvent.PeerID with the local host's peer.ID for Join / Leave (the upstream pubsub.RawTracer interface doesn't pass one). Once both ship, libp2p_join / libp2p_leave get real, non-sentinel local peer IDs end-to-end.

…n join/leave

The shared TraceEventMetadata.peer_id field has overloaded semantics:
for most libp2p events it carries the remote peer involved
(deliver/graft/prune/gossipsub/etc), but for join/leave it described
the local host that subscribed/unsubscribed — there is no remote peer
for those callbacks. Reusing the same field name with two meanings
made the schema confusing, and pubsub.RawTracer's Join(topic) /
Leave(topic) signatures don't even hand producers a peer.ID, so the
field was empty in practice and the route validator hard-rejected
every event.

  * Add a dedicated `local_peer_id` string to
    AdditionalLibP2PTraceJoinData and AdditionalLibP2PTraceLeaveData.
  * Migration 002 renames the clickhouse column
    `peer_id_unique_key` to `local_peer_id_unique_key` on
    libp2p_join_local / libp2p_leave_local (and the Distributed
    parents). The column is in ORDER BY so RENAME COLUMN is not
    supported; the migration drops and recreates the tables.
  * Regenerate route .gen.go files via `make clickhouse-routes`.
  * Route handlers read only `local_peer_id`; no fallback to the
    legacy metadata.peer_id. Sentries that haven't been updated will
    fail validation, by design.
  * clmimicry.handleJoinEvent / handleLeaveEvent populate the new
    field from the inbound TraceEvent.PeerID.

Pairs with a tysm change that populates TraceEvent.PeerID with the
local host's peer.ID for Join/Leave (where the libp2p RawTracer
interface provides no peer.ID at all).
@samcm samcm force-pushed the feat/libp2p-join-leave-local-peer-id branch from bdbccb7 to 00b0a76 Compare May 8, 2026 04:01
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.

1 participant