feat(metrics): add blocks mined counter to progress bar#10246
feat(metrics): add blocks mined counter to progress bar#10246czarcas7ic wants to merge 7 commits intoZcashFoundation:mainfrom
Conversation
1dfb00b to
37488de
Compare
Add a "blocks mined" counter that tracks all blocks successfully submitted via the submit_block RPC. This includes blocks from both Zebra's internal miner and external mining software. Changes: - Add MinedBlocksCounter struct with watch channel for progress bar updates - Add mining.blocks_mined Prometheus metric - Display "mined N blocks" in progress bar when at chain tip - Add unit tests for the counter Closes ZcashFoundation#10190
37488de to
d2910d7
Compare
There was a problem hiding this comment.
Pull request overview
This PR adds a blocks mined counter to Zebra's progress bar and exposes it as a Prometheus metric. When the node is at the chain tip, the progress bar displays "mined N blocks" instead of "waiting for next block" to help operators monitor mining activity. The counter tracks all blocks successfully submitted via the submit_block RPC, including blocks from both Zebra's internal miner and external mining software.
Changes:
- Adds
MinedBlocksCounterstruct with watch channel to track and broadcast mined block counts - Adds
mining.blocks_minedPrometheus metric that increments on successful block submissions - Updates progress bar to conditionally display mined block count when at chain tip
Reviewed changes
Copilot reviewed 13 out of 13 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| zebra-rpc/src/methods/types/submit_block.rs | Implements MinedBlocksCounter struct with watch channel for tracking mined blocks and includes comprehensive unit tests |
| zebra-rpc/src/methods/types/get_block_template.rs | Updates GetBlockTemplateHandler to accept counter and increment both metric and counter on successful block advertisement |
| zebra-rpc/src/methods.rs | Threads MinedBlocksCounter parameter through RpcImpl::new() to GetBlockTemplateHandler |
| zebra-rpc/src/lib.rs | Exports MinedBlocksCounter in public API |
| zebrad/src/components/sync/progress.rs | Updates progress bar to display mined count when at chain tip and counter > 0 |
| zebrad/src/commands/start.rs | Creates counter/receiver pair and wires them to RPC and progress bar tasks |
| zebra-rpc/src/server/tests/vectors.rs | Adds None parameter to test RpcImpl instantiations |
| zebra-rpc/src/methods/tests/vectors.rs | Adds None parameter to test RpcImpl instantiations |
| zebra-rpc/src/methods/tests/snapshot.rs | Adds None parameter to test RpcImpl instantiations |
| zebra-rpc/src/methods/tests/prop.rs | Adds None parameter to test RpcImpl instantiations |
| zebrad/tests/acceptance.rs | Adds None parameter to test RpcImpl instantiations |
| zebra-rpc/CHANGELOG.md | Documents new MinedBlocksCounter and metric |
| CHANGELOG.md | Documents user-visible feature addition |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
gustavovalverde
left a comment
There was a problem hiding this comment.
Good use of watch channels for sharing state with the progress bar. A few changes requested below.
…progress-bar # Conflicts: # zebra-rpc/CHANGELOG.md
|
@gustavovalverde I addressed all comments, thanks for the review |
There was a problem hiding this comment.
@conradoplg I suspect you had something more towards this in mind with the issue? (Ignoring code movement).
Update: This PR tracks metrics in the progress task, the branch linked in this comment tracks metrics in the RPC method. Either will work.
Sorry, would you mind summarizing the difference if it's easy to write it down? (I can work it out otherwise) |
|
Are there any changes needed from me for this PR? |
@conradoplg this PR adds a log about how many blocks have been mined to the progress task by adding a channel from the submitblock RPC rather than updating the progress bars from the submitblock RPC. |
|
The changes in this PR don't address the issue or match the PR title or description. @czarcas7ic please see the contribution guide. |
|
Hey @arya2, I am fine with this getting closed if it doesn't address the issue, but I am trying to see what I did wrong here so I can learn and better contribute next time. The issue only had this to go off of:
I also re-read the contribution guide but am not seeing what part you are referencing that I went against. Again, am just looking to learn so that I can provide helpful PRs in the future! |
|
@czarcas7ic Zebra's contribution guide asks that large changes be coordinated through issues or on discord rather than directly being proposed in a PR. The issue in this case was very light on details. Please see the branch linked above for what I think was the intended solution. |
|
@arya2 Gotcha, thanks! |
Closes: #10190
Motivation
Add a blocks mined counter to the progress bar and metrics to help node operators monitor mining activity.
Solution
Add a
MinedBlocksCounterstruct that tracks all blocks successfully submitted via thesubmit_blockRPC. This includes blocks from both Zebra's internal miner and external mining software that connects to the node.Changes:
MinedBlocksCounterstruct insubmit_block.rswith a watch channel for progress bar updatesmining.blocks_minedPrometheus metric counter, incremented on each successful block submissionRpcImplandGetBlockTemplateHandlerto the progress bar taskProgress bar display:
Nu5: waiting for next blockNu5: mined 7 blocksTests
Added 5 unit tests for
MinedBlocksCounter:new_counter_starts_at_zero- verifies initial stateincrement_increases_count- verifies increment behaviorcloned_counters_share_state- verifies Arc sharing works correctlymultiple_receivers_see_updates- verifies watch channel broadcastsmining_blocks_mined_metric_is_valid- verifies metric name is validManual testing with regtest and internal miner:
mining.blocks_minedmetric increments athttp://localhost:9999/metricsSpecifications & References
Follow-up Work
None.
PR Checklist