Skip to content

fix(consensus): use atomic debit/credit in execute_transfer - #1737

Open
Sertug17 wants to merge 1 commit into
genlayerlabs:v0.123-devfrom
Sertug17:fix/execute-transfer-race-condition-1734
Open

fix(consensus): use atomic debit/credit in execute_transfer#1737
Sertug17 wants to merge 1 commit into
genlayerlabs:v0.123-devfrom
Sertug17:fix/execute-transfer-race-condition-1734

Conversation

@Sertug17

@Sertug17 Sertug17 commented Aug 15, 2026

Copy link
Copy Markdown

Fixes #1734

Summary

execute_transfer used a non-atomic read→check→write pattern for balance updates. Since _process_finalization_task creates 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.

AccountsManager already had atomic SQL alternatives that were used elsewhere but not here.

Changes

  • backend/consensus/base.py switched sender debit to debit_account_balance (SQL UPDATE WHERE balance >= amount) and recipient credit to credit_account_balance (SQL UPDATE balance + amount). UNDETERMINED short-circuit path preserved.

Test plan

  • pytest tests/db-sqlalchemy/test_execute_transfer_undetermined_finalization.py passes
  • Integration tests pass

@github-actions
github-actions Bot changed the base branch from main to v0.123-dev August 15, 2026 10:45
@github-actions

Copy link
Copy Markdown
Contributor

This PR targeted main, which is only the default/static branch.

I retargeted it to v0.123-dev, the active development branch. Pushes to v0.123-dev automatically fast-forward main.

@coderabbitai

coderabbitai Bot commented Aug 15, 2026

Copy link
Copy Markdown
Contributor

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 352f7721-64e1-43fc-b3c6-319d6ba3304e

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug: race condition in execute_transfer causes incorrect account balances under concurrent finalization

1 participant