Fix CPU RandomX hashrate units#3262
Conversation
There was a problem hiding this comment.
Code Review
This pull request refactors hashrate formatting by replacing algorithm-specific logic with a generic HashrateUnit type across the CPU, GPU, and Miner components. The changes include removing the getSelectedMiner dependency and adding unit tests for the new 'H' unit. Feedback highlights that the formatHashrate implementation contains inconsistent spacing for units and fails to respect the joinUnit parameter for values below 1000.
| const unit = 'G'; | ||
| export type HashrateUnit = 'H' | 'G'; | ||
|
|
||
| export function formatHashrate(hashrate: number, joinUnit = true, unit: HashrateUnit = 'G'): Hashrate { |
There was a problem hiding this comment.
The implementation of formatHashrate (lines 132-167) contains a few issues that affect the new 'H' unit:
- Inconsistent Spacing: Base units (e.g.,
H/s) are formatted without a leading space (line 135), while prefixed units (e.g.,kH/s) include one (lines 141, 147, etc.). This leads to inconsistent UI presentation (e.g., "500H/s" vs "1.5 kH/s"). joinUnitBug: ThejoinUnitparameter is ignored for hashrates under 1000 (lines 132-137), always returning the full unit string even whenjoinUnitisfalse.
Since this PR modifies the function signature and introduces the HashrateUnit type, it's a good opportunity to fix these implementation details for better consistency.
|
Addressed the Gemini Code Assist feedback in 200ee62: Verified locally:
|
Description
Fixes CPU hashrate display units so RandomX CPU mining is shown as H/s, kH/s, MH/s, etc. GPU/C29 display remains on the existing G/s-based unit scale.
Motivation and Context
Closes #3210. CPU RandomX hashrate values were formatted with the GPU/C29 base unit, which caused CPU mining to appear as G/s on macOS.
How Has This Been Tested?
npx vitest run src/utils/formatters.test.tsnpx tsc --noEmitnpm run lintWhat process can a PR reviewer use to test or verify this change?
Start CPU mining and confirm the CPU tile/pill reports RandomX hashrate with H/s-derived units instead of G/s-derived units. GPU mining should continue to use G/s-derived units.
Breaking Changes