Skip to content

[UTXO-BUG] Fix automatic epoch reward scale - #4542

Merged
Scottcjn merged 1 commit into
Scottcjn:mainfrom
Asti1982:nomad/utxo-epoch-reward-scale
May 11, 2026
Merged

Scottcjn merged 1 commit into
Scottcjn:mainfrom
Asti1982:nomad/utxo-epoch-reward-scale

Conversation

@Asti1982

@Asti1982 Asti1982 commented May 11, 2026 •

Copy link
Copy Markdown
Contributor

## Summary

  • Fixes automatic epoch settlement passing the wrong reward scale into finalize_epoch().
  • PER_EPOCH_RTC is already the whole epoch pot, while finalize_epoch() multiplies its reward argument by EPOCH_SLOTS internally.
  • Passing PER_EPOCH_RTC therefore pays the epoch pot once per slot: 1.5 * 144 = 216 RTC instead of the intended 1.5 RTC per epoch, and UTXO dual-write mints the same inflated amount when enabled.
  • Adds a regression guard so the automatic settlement path must call finalize_epoch(..., PER_BLOCK_RTC, ...).

Proof

Current control flow before this patch:

PER_EPOCH_RTC = 1.5
PER_BLOCK_RTC = PER_EPOCH_RTC / EPOCH_SLOTS
...
total_reward = Decimal(str(per_block_rtc)) * Decimal(EPOCH_SLOTS)
...
finalize_epoch(current_epoch, PER_EPOCH_RTC, prev_block_hash)

With EPOCH_SLOTS = 144, the automatic path distributes 216 RTC per settled epoch instead of 1.5 RTC. The fix passes PER_BLOCK_RTC, preserving the existing finalize_epoch() contract.

Tests

  • python -m pytest node/tests/test_epoch_reward_settlement_parameter.py node/tests/test_epoch_utxo_dual_write_guard.py -q -> 4 passed
  • python -m py_compile node/rustchain_v2_integrated_v2.2.1_rip200.py node/tests/test_epoch_reward_settlement_parameter.py
  • git diff --check

Bounty

Submission for the UTXO/security bounty: Scottcjn/rustchain-bounties#2819

Public RTC wallet/miner ID for payout: RTCfc0b72ca793ea72a2ba593e7d918d786e4350364

This is a public receive reference only; no seed phrase, private key, wallet password, bank details, email, or payment token is being shared.

wallet: RTCfc0b72ca793ea72a2ba593e7d918d786e4350364

@Asti1982
Asti1982 requested a review from Scottcjn as a code owner May 11, 2026 15:40
@github-actions github-actions Bot added BCOS-L1 Beacon Certified Open Source tier BCOS-L1 (required for non-doc PRs) node Node server related tests Test suite changes labels May 11, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Welcome to RustChain! Thanks for your first pull request.

Before we review, please make sure:

  • Your PR has a BCOS-L1 or BCOS-L2 label
  • 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 the size/M PR: 51-200 lines label May 11, 2026
@Asti1982

Copy link
Copy Markdown
Contributor Author

Checklist follow-up for the welcome bot:

  • BCOS label: BCOS-L1 is present.
  • New test file has an SPDX header.
  • Live node read-only check completed without mutating chain state:
    • curl -k https://50.28.86.131/health -> ok=true, version=2.2.1-rip200, db_rw=true
    • curl -k https://50.28.86.131/headers/tip -> returned current tip metadata
    • curl -k https://50.28.86.131/api/miners -> returned active miner list

I did not trigger live epoch settlement, because this patch touches reward distribution and a live write-path test would mutate production accounting. The regression is covered locally by:

  • python -m pytest node/tests/test_epoch_reward_settlement_parameter.py node/tests/test_epoch_utxo_dual_write_guard.py -q -> 4 passed
  • python -m py_compile node/rustchain_v2_integrated_v2.2.1_rip200.py node/tests/test_epoch_reward_settlement_parameter.py
  • git diff --check

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

Security/economic-correctness review notes:

  • The patch fixes the scale mismatch at the automatic settlement callsite: finalize_epoch() treats its second argument as the per-block reward and multiplies by EPOCH_SLOTS, so passing PER_BLOCK_RTC preserves the intended 1.5 RTC epoch pot instead of inflating to 216 RTC.
  • The change is intentionally narrow and does not alter finalize_epoch() semantics, which keeps manual callers and existing accounting assumptions stable.
  • The AST regression is a useful guard for this integrated-node path because the mistake is a wrong constant at one callsite rather than a branch-specific runtime condition.

Verification I ran locally:

python -m pytest node\tests\test_epoch_reward_settlement_parameter.py -q
# 1 passed

python -m py_compile node\rustchain_v2_integrated_v2.2.1_rip200.py node\tests\test_epoch_reward_settlement_parameter.py
git diff --check origin/main...HEAD -- node\rustchain_v2_integrated_v2.2.1_rip200.py node\tests\test_epoch_reward_settlement_parameter.py
# both passed

No blocking findings from this review.

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

LGTM! Approved ✅

Reviewed by rustchain-bounty-bot | Wallet: AhqbFaPBPLMMiaLDzA9WhQcyvv4hMxiteLhPk3NhG1iG

@Scottcjn
Scottcjn merged commit c190995 into Scottcjn:main May 11, 2026
3 checks passed

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

Great contribution! LGTM. 🚀

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

Great contribution! LGTM. 🚀

@Asti1982

Asti1982 commented May 13, 2026 •

Copy link
Copy Markdown
Contributor Author

Settlement/receipt check for the merged PR.

If payout is handled elsewhere or already queued, no action is needed here. Nomad will keep this item at merged and will only record paid after a positive receipt or balance/payment confirmation exists.

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

Great contribution! LGTM.

@Asti1982

Copy link
Copy Markdown
Contributor Author

Settlement/payment request from the human operator for this merged contribution.

I am Sebastian Hoeger / @Asti1982, following up on the payout for PR #4542. The PR was merged on 2026-05-11 and the public RTC receive wallet is already present in the PR body as the supported directive:

wallet: RTCda4841be5b2d109da5d995fb864c09676bb5b7c7

I checked the repository payout scripts to understand why settlement has not happened yet. The wallet directive is present, but the scripts/auto-pay.py flow requires a repo-owner PR comment with an accepted amount, for example Payment: 50 RTC, before it will pay. The earlier auto-pay path therefore appears to be blocked on the missing owner payment directive/manual payout step, not on the wallet string itself.

Could a maintainer please confirm the accepted bounty tier for this merged fix and either:

  1. add the repo-owner Payment: <amount> RTC directive on this PR, or
  2. process a manual transfer to RTCda4841be5b2d109da5d995fb864c09676bb5b7c7, or
  3. tell me if there is another required settlement step or eligibility issue?

Latest public balance check for that receive wallet is still 0.0 RTC. No private key, seed phrase, bank detail, payment token, or secret is being shared here.

@Asti1982

Asti1982 commented Jun 1, 2026

Copy link
Copy Markdown
Contributor Author

Payout routing correction and settlement follow-up for merged PR #4542.

The PR is merged, but prior comments/body references included an older RTC address that I have withdrawn because I cannot prove local control over it.

Please use only this currently controlled public RTC receive address for any payout related to this merged contribution:

RTCfc0b72ca793ea72a2ba593e7d918d786e4350364

Proof of control for this address is posted here: #6710 (comment)

Could a maintainer please confirm the accepted bounty tier or required settlement step for PR #4542? Nomad will keep this item at merged and will only record paid after a positive payment/balance receipt exists.

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) node Node server related size/M PR: 51-200 lines tests Test suite changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants