stacks-core icon indicating copy to clipboard operation
stacks-core copied to clipboard

fix: do not break UTXO chain

Open obycode opened this issue 7 months ago • 4 comments

Bad timing between the Stacks node's processing and the Bitcoin network including a block commit can cause a miner to submit a block commit which breaks the UTXO chain, severly hurting its chances of winning blocks. It is better to just miss this commit than to break the UTXO chain.

obycode avatar May 27 '25 19:05 obycode

TODO: this still needs an integration test

obycode avatar May 27 '25 19:05 obycode

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Project coverage is 83.90%. Comparing base (d23c861) to head (52fcf78). Report is 288 commits behind head on develop.

Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #6157      +/-   ##
===========================================
+ Coverage    82.91%   83.90%   +0.98%     
===========================================
  Files          543      538       -5     
  Lines       390327   389503     -824     
  Branches       323        0     -323     
===========================================
+ Hits        323654   326814    +3160     
+ Misses       66665    62689    -3976     
+ Partials         8        0       -8     
Files with missing lines Coverage Δ
...-node/src/burnchains/bitcoin_regtest_controller.rs 89.72% <100.00%> (+0.41%) :arrow_up:

... and 70 files with indirect coverage changes


Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update d23c861...52fcf78. Read the comment docs.

:rocket: New features to boost your workflow:
  • :snowflake: Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • :package: JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

codecov[bot] avatar May 29 '25 21:05 codecov[bot]

I am failing to come up with a way to test this without intrusive changes in the code that are more likely to cause a new bug then test this one. If someone else is able to help come up with a test for this, please feel free to contribute, otherwise, I am leaning towards just having this reviewed as-is.

obycode avatar Jun 02 '25 21:06 obycode

I am failing to come up with a way to test this without intrusive changes in the code that are more likely to cause a new bug then test this one. If someone else is able to help come up with a test for this, please feel free to contribute, otherwise, I am leaning towards just having this reviewed as-is.

As discussed during the Nakasync:

  • Writing a true unit test doesn't seem feasible at the moment due to the current architecture of BitcoinRegtestController, which is tightly coupled with bitcoind APIs via BitcoinRPCRequest (used for fetching unspent UTXOs and other blockchain data).
  • Unless we're open to refactoring the design to decouple these dependencies, an alternative would be to write an integration test. This would involve setting up bitcoind using BitcoinCoreController and generating blocks to produce UTXOs, possibly allowing us to simulate the behavior of BitcoinRegtestController::build_leader_block_commit_tx.

fdefelici avatar Jun 09 '25 15:06 fdefelici

Trying creating tests in this PR: #6219

fdefelici avatar Jun 24 '25 14:06 fdefelici

Closing -- included in #6219

obycode avatar Jul 01 '25 14:07 obycode

This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

github-actions[bot] avatar Jul 09 '25 00:07 github-actions[bot]