While pursuing minimal background gossip support I've encountered a need more observability into the state of the network as it evolves.
Fortunately go-libp2p-pubsub includes support for tracing.
example_trace.json
is the result of using a JSONTracer
in a background gossip broadcast integration test.
By default, the library encodes the PeerIDs in these traces using base64 (as seen in example_trace.json
).
This is inconvenient as all of our logging is using the canonical string representation which makes it difficult to make use of the trace output.
I saw two choices:
- Rewrite local dependencies or fork and replace go-libp2p-pubsub to patch peerID serialization just for debugging.
- Try to re-encode the peerIDs after the fact while inspecting the trace.
Option 2 seemed like the better investment of time.
With the aid of ChatGPT, I was able to pull together recode_trace_peerids.go
fairly quickly.
go run ./tools/recode_trace_peerids.go ./pubsub-trace_12D3KooWRePJkgR7WADB_501.json | jq .
{
"type": 7,
"peerID": "12D3KooWRePJkgR7WADBpY4akqLU9hHAdK2snqDjPJHJowQBZsmJ",
"timestamp": 1685522927800014300,
"sendRPC": {
"sendTo": "12D3KooWN6kuiA2kjCNtqp3RCMRP7jaR8m7PtxcGQBu4CNCpcFUY",
"meta": {
"subscription": [
{
"subscribe": true,
"topic": "pokt/background"
}
]
}
}
}
{
"type": 9,
"peerID": "12D3KooWRePJkgR7WADBpY4akqLU9hHAdK2snqDjPJHJowQBZsmJ",
"timestamp": 1685522927800020700,
"join": {
"topic": "pokt/background"
}
}
{
"type": 4,
"peerID": "12D3KooWRePJkgR7WADBpY4akqLU9hHAdK2snqDjPJHJowQBZsmJ",
"timestamp": 1685522927800032800,
"addPeer": {
"peerID": "12D3KooWN6kuiA2kjCNtqp3RCMRP7jaR8m7PtxcGQBu4CNCpcFUY",
"proto": "/meshsub/1.1.0"
}
}
// ...
{
"type": 6,
"peerID": "12D3KooWRePJkgR7WADBpY4akqLU9hHAdK2snqDjPJHJowQBZsmJ",
"timestamp": 1685522927800567800,
"recvRPC": {
"receivedFrom": "12D3KooWQtL9bE5iHpTSREWR2NnMgtLkkGPNU5jZ98UHWEQs9zg5",
"meta": {
"subscription": [
{
"subscribe": true,
"topic": "pokt/background"
}
]
}
}
}
// ...
@bryanchriswhite How hard would it be to further map the
peerId
to a semantic host we know? E.g.fisherman1
orvalidator2
?