Skip to content

[codex] Compute mining calculator average multiplier#7763

Closed
zack-bolich wants to merge 1 commit into
Scottcjn:mainfrom
zack-bolich:fix-mining-calculator-average-multiplier
Closed

[codex] Compute mining calculator average multiplier#7763
zack-bolich wants to merge 1 commit into
Scottcjn:mainfrom
zack-bolich:fix-mining-calculator-average-multiplier

Conversation

@zack-bolich

Copy link
Copy Markdown

Summary

  • Replace the mining calculator's hardcoded default-network average multiplier with a computed value derived from DEFAULT_NETWORK.
  • Reuse the computed average in preset miner mode and the sensitivity table.

Why

The calculator had two paths using const avgMultiplier = 1.5, so estimates could drift when DEFAULT_NETWORK changes. With the current DEFAULT_NETWORK, the derived value is 19.9 / 12 = 1.6583 instead of the hardcoded 1.5.

Fixes #7728.

Validation

  • git diff --check
  • node static calculation check confirmed totalWeight=19.9, totalMiners=12, avg=1.6583

@github-actions

Copy link
Copy Markdown
Contributor

Welcome to RustChain! Thanks for your first pull request.

Before we review, please make sure:

  • Non-doc PRs have a BCOS-L1 or BCOS-L2 label
  • Doc-only PRs are exempt from BCOS tier labels when they only touch docs/**, *.md, or common image/PDF files
  • New code files include an SPDX license header
  • You've tested your changes against the live node

Bounty tiers: Micro (1-10 RTC) | Standard (20-50) | Major (75-100) | Critical (100-150)

A maintainer will review your PR soon. Thanks for contributing!

@github-actions github-actions Bot added BCOS-L1 Beacon Certified Open Source tier BCOS-L1 (required for non-doc PRs) size/S PR: 11-50 lines labels Jun 29, 2026

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

PR Review

Thank you for this contribution! Here's my review:

Summary

This PR improves the wallet tracker and mining calculator functionality.

Code Quality

  • ✅ Clean implementation of number formatting
  • ✅ Proper decimal precision handling
  • ✅ Good use of existing utility functions

Observations

✅ Calculator logic updated in mining-calculator/index.html - useful metric

Testing

The changes appear to be focused on display/UX improvements. Consider:

  • Adding unit tests for formatting functions
  • Testing edge cases with very large/small numbers

Verdict

APPROVE ✅ - Changes are beneficial and low-risk.


Review by @jaxint | Wallet: AhqbFaPBPLMMiaLDzA9WhQcyvv4hMxiteLhPk3NhG1iG

@jujujuda jujujuda left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Review: LGTM ✅

Replace hardcoded average multiplier with computed value from . Weighted average is correct: . Graceful fallback to 1.0 when network is empty.

Recommendation: APPROVE.

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

Two concerns before merging:

1. calculateDefaultAverageMultiplier() is called twice on every render cycle but always returns the same value — it should be a module-level constant

The function reads DEFAULT_NETWORK, which is a static constant that never changes at runtime. Calling Array.reduce on it twice per page interaction (once at line ~582 for the preset-miner estimate and once at line ~631 for the network-size table) is redundant work.

Replace with a single computation at module scope:

const DEFAULT_AVG_MULTIPLIER = (() => {
    const totalWeight = DEFAULT_NETWORK.reduce(
        (sum, item) => sum + item.multiplier * item.count, 0);
    const totalMiners = DEFAULT_NETWORK.reduce(
        (sum, item) => sum + item.count, 0);
    return totalMiners > 0 ? totalWeight / totalMiners : 1.0;
})();

This also makes the value visible to anyone reading the file without needing to trace through a function call.

2. The totalWeight variable name inside calculateDefaultAverageMultiplier() shadows the totalWeight used immediately after the call — different concepts, same name

Inside the function, totalWeight means:

the sum of (multiplier × count) across all hardware tiers in DEFAULT_NETWORK

Immediately after the call, at the call site, totalWeight means:

the estimated total network hashrate weight: presetMiners × avgMultiplier + userMultiplier

These are semantically different quantities with the same identifier. A maintainer reading the two blocks in sequence could easily confuse them, especially since the outer totalWeight formula references avgMultiplier (the return value of the function) but has the same name as the inner intermediate variable.

Please rename the internal variable — e.g. weightedMultiplierSum inside the function — to make the distinction clear:

const weightedMultiplierSum = DEFAULT_NETWORK.reduce(
    (sum, item) => sum + item.multiplier * item.count, 0);
const totalMiners = DEFAULT_NETWORK.reduce(
    (sum, item) => sum + item.count, 0);
return totalMiners > 0 ? weightedMultiplierSum / totalMiners : 1.0;

@Scottcjn

Scottcjn commented Jul 1, 2026

Copy link
Copy Markdown
Owner

Closing — the mining-calculator dynamic-multiplier fix (#7728/#7729) already landed via #7780. Thanks for the fix; it raced with the merged one. Open bounties welcome.

@Scottcjn Scottcjn closed this Jul 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

BCOS-L1 Beacon Certified Open Source tier BCOS-L1 (required for non-doc PRs) size/S PR: 11-50 lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] Mining Calculator uses hardcoded average multiplier (1.5x) causing ~8-10% underreporting of earnings

5 participants