Skip to content

feat(metrics): add block transaction count and SR set change monitoring#123

Closed
halibobo1205 wants to merge 7 commits intohalibobo1205:developfrom
warku123:metric_modify_clean
Closed

feat(metrics): add block transaction count and SR set change monitoring#123
halibobo1205 wants to merge 7 commits intohalibobo1205:developfrom
warku123:metric_modify_clean

Conversation

@halibobo1205
Copy link
Copy Markdown
Owner

@halibobo1205 halibobo1205 commented Apr 7, 2026

User description

What does this PR do?

Add two new metrics enhancements for better network monitoring:

  1. Block Transaction Count Histogram

    • Replace tron:block_empty_total counter with tron:block_transaction_count histogram
    • Track transaction count distribution per block with buckets: [0, 10, 50, 100, 200, 500, 1000, 2000, 5000, 10000]
    • Empty blocks can be monitored via le=0.0 bucket
    • Remove unused BLOCK_EMPTY counter
  2. SR Set Change Monitoring

    • Add tron:sr_set_change counter to track SR membership changes
    • Detect SR additions and removals at each maintenance time interval
    • Labels: action (add/remove), witness (SR address)

Changes:

  • Add overloaded init() method in MetricsHistogram for custom buckets
  • Add BLOCK_TRANSACTION_COUNT histogram metric
  • Add SR_SET_CHANGE counter with SR_ADD/SR_REMOVE labels
  • Implement SR set change detection logic in BlockChainMetricManager
  • Update PrometheusApiServiceTest with comprehensive test coverage

Why are these changes required?

  • Transaction histogram provides richer insights than simple counter for network analysis while maintaining empty block detection capability
  • SR set change monitoring enables tracking of network consensus participant changes for governance analysis

Compared to tronprotocol#6602, this PR provides a cleaner implementation focused solely on metrics enhancement without additional complexity.

This PR has been tested by:

  • Unit Tests (updated PrometheusApiServiceTest)
  • Manual Testing

Follow up

N/A


CodeAnt-AI Description

Track block transaction counts and SR membership changes in metrics

What Changed

  • Blocks now contribute to a transaction-count histogram, including empty blocks, so empty blocks can be found from the 0 bucket instead of a separate counter.
  • A new metric records when SRs are added or removed at maintenance time, making consensus member changes visible with one entry per witness.
  • Test coverage was updated to check empty-block counting and SR add/remove tracking.

Impact

✅ Empty blocks remain observable
✅ Clearer network activity tracking
✅ Visible SR change monitoring

💡 Usage Guide

Checking Your Pull Request

Every time you make a pull request, our system automatically looks through it. We check for security issues, mistakes in how you're setting up your infrastructure, and common code problems. We do this to make sure your changes are solid and won't cause any trouble later.

Talking to CodeAnt AI

Got a question or need a hand with something in your pull request? You can easily get in touch with CodeAnt AI right here. Just type the following in a comment on your pull request, and replace "Your question here" with whatever you want to ask:

@codeant-ai ask: Your question here

This lets you have a chat with CodeAnt AI about your pull request, making it easier to understand and improve your code.

Example

@codeant-ai ask: Can you suggest a safer alternative to storing this secret?

Preserve Org Learnings with CodeAnt

You can record team preferences so CodeAnt AI applies them in future reviews. Reply directly to the specific CodeAnt AI suggestion (in the same thread) and replace "Your feedback here" with your input:

@codeant-ai: Your feedback here

This helps CodeAnt AI learn and adapt to your team's coding style and standards.

Example

@codeant-ai: Do not flag unused imports.

Retrigger review

Ask CodeAnt AI to review the PR again, by typing:

@codeant-ai: review

Check Your Repository Health

To analyze the health of your code repository, visit our dashboard at https://app.codeant.ai. This tool helps you identify potential issues and areas for improvement in your codebase, ensuring your repository maintains high standards of code health.

…monitoring

Replace the dedicated tron:block_empty_total counter with a more comprehensive
tron:block_transaction_count histogram that tracks the distribution of
transaction counts per block.

Changes:
- Add overloaded init() method in MetricsHistogram to support custom buckets
- Add BLOCK_TRANSACTION_COUNT histogram with buckets [0, 10, 50, 100, 200, 500, 1000, 2000, 5000, 10000]
- Record transaction count for all blocks (including empty blocks with txCount=0)
- Empty blocks can be queried via bucket le=0.0
- Remove unused BLOCK_EMPTY counter

This provides richer insights for network analysis while still supporting
empty block monitoring via histogram bucket queries.

Closes tronprotocol#6590
Extract repeated 'miner' string literal into MINER_LABEL constant
in MetricsHistogram to follow DRY principle and fix SonarQube warning.

Also update PrometheusApiServiceTest to use MINER_LABEL constant
for test assertions.

Relates tronprotocol#6624
@codeant-ai
Copy link
Copy Markdown

codeant-ai bot commented Apr 7, 2026

CodeAnt AI is reviewing your PR.


Thanks for using CodeAnt! 🎉

We're free for open-source projects. if you're enjoying it, help us grow by sharing.

Share on X ·
Reddit ·
LinkedIn

@chatgpt-codex-connector
Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

@codeant-ai codeant-ai bot added the size:L This PR changes 100-499 lines, ignoring generated files label Apr 7, 2026
@codeant-ai
Copy link
Copy Markdown

codeant-ai bot commented Apr 7, 2026

CodeAnt AI finished reviewing your PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:L This PR changes 100-499 lines, ignoring generated files

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants