fix: keep block save and tx confirmation in one transaction#2157
Merged
Scottcjn merged 1 commit intoScottcjn:mainfrom Apr 7, 2026
Merged
fix: keep block save and tx confirmation in one transaction#2157Scottcjn merged 1 commit intoScottcjn:mainfrom
Scottcjn merged 1 commit intoScottcjn:mainfrom
Conversation
Contributor
Author
|
For bounty payout, please use RTC wallet: RTC1d48d848a5aa5ecf2c5f01aa5fb64837daaf2f35. |
Owner
|
✅ Merged! 75 RTC awarded for atomicity fix — block save. Payment will be sent to wallet Total this batch: 200 RTC. Thank you @createkr — your 3 fixes today touched security, data integrity, and epoch correctness. This is core contributor work. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Makes
BlockProducer.save_block()andTransactionPool.confirm_transaction()share a single SQLite connection so that block insertion and all transaction confirmations are a single atomic unit.Problem
save_block()opened its own DB connection and calledconfirm_transaction()for each transaction in the block.confirm_transaction()opened a separate connection and committed independently. This meant:Fix
rustchain_tx_handler.py: Added optionalconnparameter toconfirm_transaction(). When provided, the method uses the caller's connection and does not manage its own transaction boundary. The core logic is extracted into_do_confirm(cursor)to avoid duplication.rustchain_block_producer.py:save_block()now passes its connection to eachconfirm_transaction()call. If any confirmation returnsFalse, the entire block save is aborted and rolled back.Changes
node/rustchain_tx_handler.py—confirm_transaction()accepts optionalconnparameter; extracted_do_confirm()inner functionnode/rustchain_block_producer.py—save_block()passesconn=conntoconfirm_transaction()and aborts on failurenode/tests/test_f10_block_save_atomicity.py— 5 new tests:test_confirm_with_shared_connection_succeedstest_confirm_rollback_on_shared_connectiontest_confirm_fails_insufficient_balance_shared_conntest_standalone_confirm_still_works(backward compat)test_multi_tx_atomic_on_shared_connBackward Compatibility
The
connparameter is optional with a default ofNone. Existing callers that don't pass a connection continue to use the standalone path with their own transaction management. No API breakage.