fix(consensus): use atomic debit/credit in execute_transfer - #1737
fix(consensus): use atomic debit/credit in execute_transfer#1737Sertug17 wants to merge 1 commit into
Conversation
|
This PR targeted I retargeted it to |
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Fixes #1734
Summary
execute_transferused a non-atomic read→check→write pattern for balance updates. Since_process_finalization_taskcreates a separate DB session per task, two concurrent finalizations crediting the same recipient could both read the same stale balance the second write silently overwrites the first, losing funds with no error.AccountsManageralready had atomic SQL alternatives that were used elsewhere but not here.Changes
backend/consensus/base.pyswitched sender debit todebit_account_balance(SQLUPDATE WHERE balance >= amount) and recipient credit tocredit_account_balance(SQLUPDATE balance + amount). UNDETERMINED short-circuit path preserved.Test plan
pytest tests/db-sqlalchemy/test_execute_transfer_undetermined_finalization.pypasses