Implement real-time metrics collection for admin dashboard#89
Conversation
- Add messages_sent and messages_received counters - Add average_trust_score gauge (stored as fixed-point for atomic operations) - Add slashing_events_total counter - Update export_prometheus to include all new metrics - Add comprehensive tests for new metrics Co-authored-by: Steake <530040+Steake@users.noreply.github.com>
- Add message_sent counter increments in broadcast_block and broadcast_transaction - Add message_received counter increments in handle_incoming_block and handle_incoming_transaction - Update tournament manager to calculate and report average trust score - Track slashing events when negative evidence is recorded - All metrics now populated with real data from node operations Co-authored-by: Steake <530040+Steake@users.noreply.github.com>
- Add DEFAULT_TRUST_SCORE constant instead of magic number 0.85 - Use evidence_type.is_negative() method instead of hardcoded match - Add bounds checking to trust score fixed-point conversion with clamp(0.0, 1000.0) - Add clarifying comment about trust score precision range Co-authored-by: Steake <530040+Steake@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
This PR implements real-time metrics collection for the admin dashboard, replacing mock data with actual node operational metrics. The implementation adds network message volume tracking, EBSL trust scores, and slashing event monitoring to provide live observability into node operations.
Key Changes:
- Added 4 new atomic metrics to
MetricsRegistry: message counters (sent/received), average trust score (fixed-point), and slashing events counter - Integrated message counting into network broadcast and receive operations for blocks and transactions
- Implemented trust score averaging across miners and slashing event tracking in tournament manager
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
crates/bitcell-node/src/monitoring/mod.rs |
Added 4 new metrics with atomic storage, getter/setter methods, Prometheus export format updates, and comprehensive unit tests |
crates/bitcell-node/src/network.rs |
Integrated message counters into broadcast_block(), broadcast_transaction(), handle_incoming_block(), and handle_incoming_transaction() methods |
crates/bitcell-node/src/tournament.rs |
Added slashing event tracking on negative evidence recording and average trust score calculation across all miners with default fallback |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| // Store as fixed-point * 1000 for atomic operations | ||
| // Trust scores are typically in range [0.0, 1.0], so this provides | ||
| // 3 decimal places of precision without overflow risk | ||
| let clamped_score = score.clamp(0.0, 1000.0); |
There was a problem hiding this comment.
The clamping upper bound should be 1.0, not 1000.0. Trust scores from the EBSL system are in the range [0.0, 1.0] (as stated in the comment on line 189 and confirmed by TrustScore::new() which clamps to [0.0, 1.0]). The current upper bound of 1000.0 is incorrect and would allow values far outside the valid range.
Change to: let clamped_score = score.clamp(0.0, 1.0);
| let clamped_score = score.clamp(0.0, 1000.0); | |
| let clamped_score = score.clamp(0.0, 1.0); |
There was a problem hiding this comment.
Fixed in 76882f1. Changed the clamp upper bound from 1000.0 to 1.0 to match the valid trust score range.
| @@ -35,6 +37,7 @@ pub struct MetricsRegistry { | |||
| banned_miners: Arc<AtomicUsize>, | |||
| #[allow(dead_code)] | |||
There was a problem hiding this comment.
The #[allow(dead_code)] attribute is no longer needed since avg_trust_score is now actively used via set_average_trust_score() and get_average_trust_score() methods. This attribute should be removed.
| #[allow(dead_code)] | |
There was a problem hiding this comment.
Fixed in 76882f1. Removed the #[allow(dead_code)] attribute since the field is now actively used.
|
@copilot:all please review this pull request again, previous attempt seemed to stall. |
- Change trust score clamp upper bound from 1000.0 to 1.0 (trust scores are in range [0.0, 1.0]) - Remove #[allow(dead_code)] attribute from avg_trust_score field as it's now actively used Co-authored-by: Steake <530040+Steake@users.noreply.github.com>
|
[autopilot] 🤖 LLM Analysis of Copilot Review Decision: approve |
✅ Implementation Complete: Real-Time Metrics Collection in Admin Dashboard
This PR implements real-time metrics collection for the admin dashboard, completing issue #73 (part of RC1 Epic #71 - Zero-Knowledge & Observability).
🎯 Goal Achieved
The admin dashboard now displays real network and system metrics including:
All mock values have been replaced with actual metrics data.
📊 Changes Made
1. Node Metrics Registry
Added 4 new metrics to
MetricsRegistry:2. Network Manager Integration
Updated network operations to track metrics:
broadcast_block(): Counts messages sent per peerbroadcast_transaction(): Counts messages sent per peerhandle_incoming_block(): Counts messages receivedhandle_incoming_transaction(): Counts messages received3. Tournament Manager Integration
Enhanced EBSL metrics collection:
DEFAULT_TRUST_SCOREconstant andis_negative()method4. Testing
🏗️ Architecture
Complete Data Flow:
System Metrics (already implemented):
sysinfocrate✅ Acceptance Criteria Met
🔒 Security
📈 Performance Impact
Minimal - all updates use lock-free atomic operations with no blocking in hot paths.
📝 Files Changed
crates/bitcell-node/src/monitoring/mod.rs(+110 lines)crates/bitcell-node/src/network.rs(+10 lines)crates/bitcell-node/src/tournament.rs(+24 lines)Total: 145 insertions, 2 deletions
Original prompt
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.