Skip to content

feat(metrics): add blocks mined counter to progress bar#10246

Closed
czarcas7ic wants to merge 7 commits intoZcashFoundation:mainfrom
czarcas7ic:fix/add-blocks-mined-progress-bar
Closed

feat(metrics): add blocks mined counter to progress bar#10246
czarcas7ic wants to merge 7 commits intoZcashFoundation:mainfrom
czarcas7ic:fix/add-blocks-mined-progress-bar

Conversation

@czarcas7ic
Copy link

@czarcas7ic czarcas7ic commented Jan 29, 2026

Closes: #10190

Motivation

Add a blocks mined counter to the progress bar and metrics to help node operators monitor mining activity.

Solution

Add a MinedBlocksCounter struct that tracks all blocks successfully submitted via the submit_block RPC. This includes blocks from both Zebra's internal miner and external mining software that connects to the node.

Changes:

  • Add MinedBlocksCounter struct in submit_block.rs with a watch channel for progress bar updates
  • Add mining.blocks_mined Prometheus metric counter, incremented on each successful block submission
  • Update progress bar to display "mined N blocks" when at chain tip (instead of "waiting for next block")
  • Wire the counter through RpcImpl and GetBlockTemplateHandler to the progress bar task

Progress bar display:

State Display
At tip, no blocks mined Nu5: waiting for next block
At tip, blocks mined Nu5: mined 7 blocks

Tests

  • Added 5 unit tests for MinedBlocksCounter:

    • new_counter_starts_at_zero - verifies initial state
    • increment_increases_count - verifies increment behavior
    • cloned_counters_share_state - verifies Arc sharing works correctly
    • multiple_receivers_see_updates - verifies watch channel broadcasts
    • mining_blocks_mined_metric_is_valid - verifies metric name is valid
  • Manual testing with regtest and internal miner:

    • Verified mining.blocks_mined metric increments at http://localhost:9999/metrics
    • Verified progress bar displays mined count

Specifications & References

Follow-up Work

None.

PR Checklist

  • The PR name is suitable for the release notes.
  • The PR follows the contribution guidelines.
  • The library crate changelogs are up to date.
  • The solution is tested.
  • The documentation is up to date.

@github-actions github-actions bot added the C-feature Category: New features label Jan 29, 2026
@czarcas7ic czarcas7ic marked this pull request as ready for review January 29, 2026 15:37
@czarcas7ic czarcas7ic force-pushed the fix/add-blocks-mined-progress-bar branch from 1dfb00b to 37488de Compare January 29, 2026 15:39
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
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 MinedBlocksCounter struct with watch channel to track and broadcast mined block counts
  • Adds mining.blocks_mined Prometheus 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.

Copy link
Member

@gustavovalverde gustavovalverde left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good use of watch channels for sharing state with the progress bar. A few changes requested below.

@czarcas7ic
Copy link
Author

@gustavovalverde I addressed all comments, thanks for the review

Copy link
Contributor

@arya2 arya2 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@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.

@conradoplg
Copy link
Collaborator

@conradoplg I suspect you had something more towards this in mind with the issue? (Ignoring code movement).

Sorry, would you mind summarizing the difference if it's easy to write it down? (I can work it out otherwise)

@czarcas7ic
Copy link
Author

Are there any changes needed from me for this PR?

@arya2
Copy link
Contributor

arya2 commented Feb 26, 2026

Sorry, would you mind summarizing the difference if it's easy to write it down? (I can work it out otherwise)

@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.

@arya2
Copy link
Contributor

arya2 commented Feb 26, 2026

The changes in this PR don't address the issue or match the PR title or description. @czarcas7ic please see the contribution guide.

@arya2 arya2 closed this Feb 26, 2026
@czarcas7ic
Copy link
Author

czarcas7ic commented Feb 27, 2026

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:

Add "blocks mined" to the progress bar, and possibly to the metrics if we don't support it yet

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!

@arya2
Copy link
Contributor

arya2 commented Feb 27, 2026

@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.

@czarcas7ic
Copy link
Author

@arya2 Gotcha, thanks!

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

Labels

C-feature Category: New features

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feature: add blocks mined to progress bar

5 participants