Skip to content

fix: use UTXO state root in block producer#2076

Merged
Scottcjn merged 1 commit intoScottcjn:mainfrom
createkr:feat/issue2075-state-root-utxo-commitment
Apr 5, 2026
Merged

fix: use UTXO state root in block producer#2076
Scottcjn merged 1 commit intoScottcjn:mainfrom
createkr:feat/issue2075-state-root-utxo-commitment

Conversation

@createkr
Copy link
Copy Markdown
Contributor

@createkr createkr commented Apr 5, 2026

Summary

BlockProducer.get_state_root() currently commits the legacy account-model balances root even when the node is operating against the UTXO database. This patch lets BlockProducer prefer utxo_db.compute_state_root() whenever a UTXO handle is available, while preserving the legacy balances-table path as a fallback.

What changed

  • add an optional utxo_db handle to BlockProducer
  • prefer the UTXO Merkle root in get_state_root() when utxo_db is attached
  • fall back to the legacy balances-table root when no UTXO DB is present or UTXO root computation fails
  • add focused state-root regression coverage

Validation

  • PYTHONPATH=node python3 -m py_compile node/rustchain_block_producer.py node/test_block_producer_state_root.py node/utxo_db.py
  • PYTHONPATH=node python3 node/test_block_producer_state_root.py

Reviewer note

The semantic change is intentionally small (constructor wiring + get_state_root() preference/fallback logic + focused tests). If GitHub shows the Python file as a large diff, that is due to repository line-ending normalization noise around this file history rather than broad logic churn.

@github-actions github-actions bot added BCOS-L1 Beacon Certified Open Source tier BCOS-L1 (required for non-doc PRs) node Node server related labels Apr 5, 2026
@github-actions github-actions bot added the size/XL PR: 500+ lines label Apr 5, 2026
@zhuzhushiwojia
Copy link
Copy Markdown

Good catch! This fix addresses an important issue. The approach looks correct.

@zhuzhushiwojia
Copy link
Copy Markdown

Great fix! The change to use state_root from the UTXO model in the block producer is a solid improvement. A few observations:

Code Quality:

  • Changes look clean and well-structured
  • New test file covers state root verification

Suggestions:

  • Consider adding edge case tests for genesis block (height=0)
  • Could add integration test with real UTXO set operations

Overall LGTM! ✅

@Scottcjn
Copy link
Copy Markdown
Owner

Scottcjn commented Apr 5, 2026

Reviewed. Block producer now uses UTXO Merkle state root when utxo_db is available, with clean fallback to legacy account-model balances. Soft import of utxo_db avoids hard dependency. 7 tests cover: UTXO preferred, fallback on failure, determinism, spend-changes-root, empty set. Good work.

Payment: 50 RTC (Medium-High — consensus state root integrity)

Thank you @createkr.

@Scottcjn Scottcjn merged commit e87078c into Scottcjn:main Apr 5, 2026
7 of 9 checks passed
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/XL PR: 500+ lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants