Merged
Conversation
All issues resolved. LGTM!
Mention @roomote in a comment to request specific changes to this pull request or fix all unresolved issues. |
- Replace map-based Client.Stats with StatsSnapshot - Add DHT peer/network/db snapshot helpers and typed store stats - Update status + metrics reporting; warn when peers_count=0
e196028 to
55a1574
Compare
a-ok123
previously approved these changes
Dec 30, 2025
Contributor
There was a problem hiding this comment.
Pull request overview
This PR refactors P2P statistics collection to improve performance and type safety by introducing a typed snapshot approach with caching, replacing the previous map[string]interface{} pattern. It also increases the startup delay from 30 to 300 seconds and adds a peers_count check to health reporting.
Key Changes
- Introduced
StatsSnapshotstruct andp2pStatsManagerwith ristretto-based caching to serve stats with predictable latency - Replaced untyped map-based stats with typed methods (
PeersSnapshot,DatabaseStats,NetworkHandleMetricsSnapshot) across the kademlia layer - Modified health check to require both open ports AND non-zero peer count, and increased startup delay 10x to 5 minutes
Reviewed changes
Copilot reviewed 15 out of 16 changed files in this pull request and generated 10 comments.
Show a summary per file
| File | Description |
|---|---|
p2p/stats_snapshot.go |
New typed struct defining the P2P stats snapshot schema |
p2p/p2p_stats.go |
New stats manager implementing caching layer with background refresh and last-known-good pattern |
p2p/p2p.go |
Updated Stats() method signature to return typed snapshot, added stats manager initialization |
p2p/client.go |
Updated Stats() interface to return typed snapshot |
p2p/mocks/Client.go |
Updated mock to match new Stats() signature |
p2p/kademlia/dht.go |
Refactored stats methods into typed snapshots (PeersSnapshot, NetworkHandleMetricsSnapshot, DatabaseStats) |
p2p/kademlia/hashtable.go |
Added peersCount() method for fast count without allocating peer list |
p2p/kademlia/store.go |
Introduced DatabaseStats struct for typed database statistics |
p2p/kademlia/store/sqlite/sqlite.go |
Updated Stats() to return DatabaseStats struct instead of map |
p2p/kademlia/store/mem/mem.go |
Updated Stats() to return DatabaseStats struct instead of map |
supernode/status/service.go |
Simplified stats consumption using typed snapshot, moved Network population inside includeP2PMetrics conditional |
supernode/supernode_metrics/monitor_service.go |
Added peers_count > 0 check to health validation, updated warning message |
supernode/supernode_metrics/constants.go |
Increased DefaultStartupDelaySeconds from 30 to 300 seconds |
docs/gateway.md |
Added documentation explaining the caching behavior and latency characteristics |
README.md |
Updated API documentation to clarify P2P metrics gating and caching approach |
.gitignore |
Added analysis directory to ignore list |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
5f4d583
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.
No description provided.