Skip to content

Fix RandomX hashrate units#3253

Open
Catnap7 wants to merge 3 commits into
tari-project:mainfrom
Catnap7:codex/hashrate-unit-by-algorithm
Open

Fix RandomX hashrate units#3253
Catnap7 wants to merge 3 commits into
tari-project:mainfrom
Catnap7:codex/hashrate-unit-by-algorithm

Conversation

@Catnap7

@Catnap7 Catnap7 commented May 22, 2026

Copy link
Copy Markdown

Summary

Fixes #3210 by making hashrate display units depend on the mining algorithm instead of always using graph-rate units.

This change:

  • formats C29 mining with graph units (G/s, kG/s, MG/s, etc.)
  • formats RandomX mining with hash units (H/s, kH/s, MH/s, etc.)
  • passes RandomX explicitly from the CPU mining tile so macOS CPU mining no longer displays G/s
  • adds formatter coverage for RandomX units

Verification

  • npm test -- --run src/utils/formatters.test.ts — 62 tests passed
  • npm exec tsc -- --noEmit
  • git diff --check

Note: Vitest printed its existing "close timed out" warning after the tests passed, but exited successfully.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

This pull request introduces support for the RandomX mining algorithm by adding it to the GpuMiningAlgorithm enum and updating the CPU mining tile to use it. It also modifies the formatHashrate utility to support different units ('G' for C29 and 'H' for RandomX) and includes corresponding unit tests. Feedback suggests replacing the ternary logic in formatHashrate with an explicit mapping to improve extensibility and handle other algorithms that might share the same units.

Comment thread src/utils/formatters.ts Outdated
export function formatHashrate(hashrate: number, joinUnit = true, _algo = GpuMiningAlgorithm.C29): Hashrate {
const unit = 'G';
export function formatHashrate(hashrate: number, joinUnit = true, algo = GpuMiningAlgorithm.C29): Hashrate {
const unit = algo === GpuMiningAlgorithm.C29 ? 'G' : 'H';

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

The current ternary logic defaults to 'H' for any algorithm other than C29. This is fragile because other algorithms (like C31) also use Graph-rate units (G/s). Using an explicit mapping makes the code more robust and easier to extend as new algorithms are added, while also making the intent clearer.

    const unit = {
        [GpuMiningAlgorithm.C29]: 'G',
        [GpuMiningAlgorithm.RandomX]: 'H',
    }[algo];

@Catnap7 Catnap7 May 22, 2026

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Addressed in 0f098d81: formatHashrate now uses an explicit HASHRATE_BASE_UNITS mapping keyed by GpuMiningAlgorithm, with Record<GpuMiningAlgorithm, 'G' | 'H'> so future enum additions require an explicit unit choice at type-check time.

Re-ran npm test -- --run src/utils/formatters.test.ts, npm exec tsc -- --noEmit, and git diff --check.

@Catnap7 Catnap7 force-pushed the codex/hashrate-unit-by-algorithm branch from 2c18c77 to 0f098d8 Compare May 22, 2026 18:54
@Catnap7

Catnap7 commented May 23, 2026

Copy link
Copy Markdown
Author

Follow-up after another PR appeared for the same issue: I strengthened this PR so the algorithm type is no longer GPU-specific and the RandomX coverage is broader.

Added in 23248e96:

  • renamed the frontend algorithm enum to shared MiningAlgorithm
  • kept CPU mining explicitly passing MiningAlgorithm.RandomX
  • kept C29 as the default graph-rate path for GPU/miner tiles
  • added formatter coverage for RandomX H/s, kH/s, MH/s, and joinUnit=false

Re-verified locally:

  • npm test -- --run src/utils/formatters.test.ts (65 tests passed)
  • npm exec tsc -- --noEmit
  • git diff --check

Verification on Windows:

- npm test -- --run src/utils/formatters.test.ts (65 passed)

- npm exec tsc -- --noEmit

- git diff --check origin/main...HEAD
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Tari Universe 1.6.11 reports rate in G/s on Mac for CPU

1 participant