Repository navigation
fix(accounts): stop refunding value a top-level SEND never debited - #1820
danieljrc888 wants to merge 1 commit into
Conversation
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).
|
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
|
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
Problem and outcome
Top-level native SENDs are not debited at submission (
endpoints.py: "Skip for SEND (execute_transfer handles it)");execute_transferdebits the sender and credits the recipient together. But every terminal refund path callsAccountsManager.refund_tx_value, which credited the sendervaluewhenevervalue_credited=false. For a top-level SEND that means crediting money the sender never paid:sim_cancelTransaction, worker no-validators cancel, worker generic-retry cancel, expiredvalidUntilinPendingState)execute_transfermarks it UNDETERMINED without debiting, thenFinalizingStatetakes the no-result branch and callsrefund_tx_valueBoth mint
value. Reproduced: sender with balance 0 sends 1000; after cancel, or after UNDETERMINED finalization, the sender balance is 1000.Outcome:
refund_tx_valueskips 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_valuestill 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 therefund_tx_valueUPDATE.tests/db-sqlalchemy/test_send_value_refund.py: covers cancel via the RPC handler, UNDETERMINED to FINALIZED viaexecute_transfer+FinalizingState, plus controls showing child SEND and contract call refunds still work. Before the fix both mint tests failed (assert 1000 == 0).Related: #1819 (atomic
value_creditedclaim inexecute_transfer), which keeps "top-level SEND uncredited means never debited" true. Target v0.123.1. Risk is low; rollback is reverting the single predicate.