Skip to content

fix(accounts): stop refunding value a top-level SEND never debited - #1820

Open
danieljrc888 wants to merge 1 commit into
v0.123-devfrom
fix/send-cancel-refund
Open

danieljrc888 wants to merge 1 commit into
v0.123-devfrom
fix/send-cancel-refund

Conversation

@danieljrc888

Copy link
Copy Markdown
Contributor

Problem and outcome

Top-level native SENDs are not debited at submission (endpoints.py: "Skip for SEND (execute_transfer handles it)"); execute_transfer debits the sender and credits the recipient together. But every terminal refund path calls AccountsManager.refund_tx_value, which credited the sender value whenever value_credited=false. For a top-level SEND that means crediting money the sender never paid:

  • cancelling a PENDING SEND (sim_cancelTransaction, worker no-validators cancel, worker generic-retry cancel, expired validUntil in PendingState)
  • finalizing an insufficient-balance SEND: execute_transfer marks it UNDETERMINED without debiting, then FinalizingState takes the no-result branch and calls refund_tx_value

Both mint value. Reproduced: sender with balance 0 sends 1000; after cancel, or after UNDETERMINED finalization, the sender balance is 1000.

Outcome: refund_tx_value skips top-level SENDs (type = SEND AND triggered_by_hash IS NULL), fixing all six call sites at once. Contract-emitted SEND children keep their refund because the emitting contract was debited at acceptance.

Non-goals: invariants.get_in_transit_value still counts uncredited PENDING top-level SENDs as in transit even though the value is still in the sender's balance. That is a reporting skew, not a mint, and is left as is.

Implementation and validation

  • backend/database_handler/accounts_manager.py: one extra predicate in the refund_tx_value UPDATE.
  • tests/db-sqlalchemy/test_send_value_refund.py: covers cancel via the RPC handler, UNDETERMINED to FINALIZED via execute_transfer + FinalizingState, plus controls showing child SEND and contract call refunds still work. Before the fix both mint tests failed (assert 1000 == 0).
  • Full db-sqlalchemy suite: 274 passed, 1 xfailed.

Related: #1819 (atomic value_credited claim in execute_transfer), which keeps "top-level SEND uncredited means never debited" true. Target v0.123.1. Risk is low; rollback is reverting the single predicate.

Top-level SENDs are debited only inside execute_transfer, atomically with
the recipient credit, never at submission. refund_tx_value credited the
sender whenever value_credited=false, so cancelling a PENDING SEND (RPC
cancel, worker no-validators / generic-retry cancel, expired validUntil)
or finalizing an insufficient-balance UNDETERMINED SEND minted `value`
to the sender.

refund_tx_value now skips top-level SENDs. Contract-emitted SEND children
(triggered_by_hash set) keep their refund: the emitting contract was
debited at acceptance.

Validated with tests/db-sqlalchemy/test_send_value_refund.py (both mint
cases failed with sender balance 1000 instead of 0 before the fix) and the
full db-sqlalchemy suite (274 passed).
@danieljrc888 danieljrc888 self-assigned this Nov 10, 2026
@coderabbitai

coderabbitai Bot commented Nov 10, 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

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 0864fdb9-0ad4-4375-8c5e-2bd08b2c49df

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
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 10, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-10T00:53:12.457353Z 9ba1ac2 PR opened
🔒 Security Review ✅ Completed 2026-11-10T00:54:40.489054Z 9ba1ac2 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

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.

1 participant