feat(libp2p): add local_peer_id to join/leave additional data#821
Open
feat(libp2p): add local_peer_id to join/leave additional data#821
Conversation
…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).
bdbccb7 to
00b0a76
Compare
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.
Summary
xatu.libp2p.TraceEventMetadata.peer_idis shared across most libp2pAdditionalDatatypes and consistently means "the remote peer involved" — except forLibp2PTraceJoin/Libp2PTraceLeave, where it semantically referred to the local host that subscribed/unsubscribed. Two consequences:peer_id_unique_keyonlibp2p_join/libp2p_leavewas overloaded with the same name as 26 other libp2p tables that mean "remote peer", but its actual meaning was the local node.pubsub.RawTracer.Join(topic)/Leave(topic)don't pass apeer.IDto producers (because there is no remote peer for those callbacks). Producers like TYSM end up emitting events withmetadata.peer_id == "", the route handler'snil PeerIdvalidator hard-rejects them, andlibp2p_join/libp2p_leaveend up with zero rows onclickhouse-raw.Changes
string local_peer_idfield toAdditionalLibP2PTraceJoinDataandAdditionalLibP2PTraceLeaveData.metadata.peer_idis no longer used for these two events.peer_id_unique_key→local_peer_id_unique_keyonlibp2p_join_local/libp2p_leave_local(plus the Distributed parents). Because the column is inORDER BY,RENAME COLUMNisn't supported; the migration drops and recreates the tables.libp2p_join.go,libp2p_leave.go): read onlylocal_peer_id. No fallback to the legacymetadata.peer_id— sentries that haven't been updated will fail validation, by design.make clickhouse-routes. New field isLocalPeerIDUniqueKey, column islocal_peer_id_unique_key.handleJoinEvent/handleLeaveEventpopulate the newLocalPeerIdfield from the inboundTraceEvent.PeerID.Pairs with
A tysm change populates
TraceEvent.PeerIDwith the local host'speer.IDforJoin/Leave(the upstreampubsub.RawTracerinterface doesn't pass one). Once both ship,libp2p_join/libp2p_leaveget real, non-sentinel local peer IDs end-to-end.