Fixed race-condition caused by multiple threads being able execute tx #509
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.
At the moment transaction execution is protected b y read lock, which allows different threads execute transactions on the same writable accounts at the same time. This leads to invalid account states.
Example: RPC executes TX on magic_context & at the same time slot-ticker executes
AcceptScheduleCommitstx in magic_context.outcome: Even though accept was executed - MagicContext still contains just accepted Commits
Greptile Summary
This PR addresses a critical race condition in transaction execution by changing the synchronization mechanism in the bank's transaction processing. The change modifies the lock acquisition in
load_and_execute_sanitized_transactionsfrom a read lock to a write lock on thetransaction_processor.The issue stems from the current implementation allowing multiple threads to concurrently execute transactions that modify the same writable accounts. This is particularly problematic for the MagicBlock validator's
magic_contextaccount, which manages scheduled commits. The race condition occurs when, for example, an RPC request executes a transaction onmagic_contextwhile simultaneously the slot-ticker executes anAcceptScheduleCommitstransaction on the same account. Even though both transactions might appear to succeed individually, the concurrent execution leads to invalid account states where committed changes can be lost or overwritten.The fix ensures proper serialization of transaction execution by requiring exclusive access during the execution phase. This prevents multiple threads from simultaneously modifying the same accounts, maintaining data consistency and preventing the loss of scheduled commits or other account state corruption. The change aligns with the broader architecture where the validator manages complex state transitions through scheduled commits and account delegations.
PR Description Notes:
Confidence score: 5/5