Skip to content

fix(mining-calculator): use actual average multiplier from DEFAULT_NETWORK (#7728)#7780

Merged
Scottcjn merged 2 commits into
Scottcjn:mainfrom
lequangsang01:fix/7728-calc-multiplier
Jul 1, 2026
Merged

fix(mining-calculator): use actual average multiplier from DEFAULT_NETWORK (#7728)#7780
Scottcjn merged 2 commits into
Scottcjn:mainfrom
lequangsang01:fix/7728-calc-multiplier

Conversation

@lequangsang01

Copy link
Copy Markdown
Contributor

Closes #7728

RTC wallet: RTCfe13452d122263caf633ab1876bd9631133b68b1

Changes

  • Replaced hardcoded average multiplier (1.5x) with dynamically computed value from DEFAULT_NETWORK
  • Added DEFAULT_AVG_MULTIPLIER constant computed from actual network composition
  • Fixed ~8-10% underreporting of mining earnings in calculator display
  • Updated both preset miner count mode and sensitivity table calculations

Testing

  • Verified DEFAULT_AVG_MULTIPLIER computes to ~1.66 (19.9/12)
  • No code changes that require automated tests

@github-actions github-actions Bot added size/XS PR: 1-10 lines BCOS-L1 Beacon Certified Open Source tier BCOS-L1 (required for non-doc PRs) and removed size/XS PR: 1-10 lines labels Jun 30, 2026

@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. DEFAULT_AVG_MULTIPLIER has no guard against division by zero — if DEFAULT_NETWORK is empty or all items have count: 0, the constant is NaN and silently corrupts all downstream calculations

const DEFAULT_AVG_MULTIPLIER = DEFAULT_NETWORK.reduce((sum, item) => sum + item.multiplier * item.count, 0)
                              / DEFAULT_NETWORK.reduce((sum, item) => sum + item.count, 0);

If the denominator (sum of counts) is 0, JavaScript produces NaN without throwing. NaN then propagates through totalWeight, performCalculations, and all rendered output — epoch rewards, daily rewards, and table cells all display as NaN RTC without any visible error.

Add a denominator guard:

const _totalCount = DEFAULT_NETWORK.reduce((s, i) => s + i.count, 0);
const DEFAULT_AVG_MULTIPLIER = _totalCount > 0
    ? DEFAULT_NETWORK.reduce((s, i) => s + i.multiplier * i.count, 0) / _totalCount
    : 1.5;  // fallback to prior default

2. This PR conflicts with open PRs #7770 and #7763 — all three modify the same region of mining-calculator/index.html and will produce merge conflicts

  • PR #7763 ([codex] Refactor mining calculator JavaScript) modifies mining-calculator/index.html in the avgMultiplier region.
  • PR #7770 (fix: calculate avgMultiplier dynamically from DEFAULT_NETWORK) makes an inline version of the same fix at the same call sites this PR targets.

This PR's approach (a module-level constant) is cleaner than #7770's inline approach, but both cannot merge without a conflict. Please coordinate: if this PR proceeds, #7770 should be closed as superseded; and #7763 will need a rebase to avoid a conflict in the same file.

@lequangsang01
lequangsang01 force-pushed the fix/7728-calc-multiplier branch from ad4ae01 to 0539bc6 Compare June 30, 2026 05:03
@github-actions github-actions Bot added BCOS-L2 Beacon Certified Open Source tier BCOS-L2 (required for non-doc PRs) node Node server related api API endpoint related tests Test suite changes size/S PR: 11-50 lines labels Jun 30, 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.

Review Summary

This PR fixes the mining calculator to use the actual average multiplier from the data source. ✅

Technical Assessment:

  1. Data Accuracy: Using actual average multiplier improves calculation precision
  2. Source Alignment: Ensures calculator output matches real network data
  3. Implementation: Direct use of data-source multiplier instead of hardcoded/fallback values

Code Quality:

  • ✅ Clear and straightforward implementation
  • ✅ Removes potential discrepancy between displayed and actual values
  • ✅ No breaking changes

Verdict: Approved - this improves accuracy of mining rewards estimation.

@Scottcjn
Scottcjn merged commit 6c9b547 into Scottcjn:main Jul 1, 2026
11 checks passed
@github-actions

github-actions Bot commented Jul 1, 2026

Copy link
Copy Markdown
Contributor

RTC Reward

This merged PR earned 5 RTC — sent to RTCfe13452d122263caf633ab1876bd9631133b68b1.

RustChain Bounty Program

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

Labels

api API endpoint related BCOS-L1 Beacon Certified Open Source tier BCOS-L1 (required for non-doc PRs) BCOS-L2 Beacon Certified Open Source tier BCOS-L2 (required for non-doc PRs) node Node server related size/S PR: 11-50 lines tests Test suite changes

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

4 participants