fix(escrow): save closed payments before account hooks#2078
Conversation
Add regression coverage for the account-close hook path that can call back into PaymentClose while closing an escrow account. This captures the validator log path that returned account closed before the production fix changes save ordering. Signed-off-by: Joseph Chalabi <chalabi.joseph@gmail.com>
Persist dirty payments before the account during escrow batch saves. This prevents account-close hooks from observing a closed account while related payments are still open in the store. Signed-off-by: Joseph Chalabi <chalabi.joseph@gmail.com>
WalkthroughThis PR reformats a conditional block in the escrow keeper's save method without altering its logic, and adds a new test verifying that payments can be closed from within an account-closed hook before the account itself finishes closing. ChangesEscrow Save Formatting and Hook Ordering Test
Estimated code review effort: 2 (Simple) | ~10 minutes Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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 |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
x/escrow/keeper/keeper_test.go (1)
303-316: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueConsider a short comment documenting why the hook's
PaymentClosebranch is expected to be skipped post-fix.As written, the interesting regression path (hook calling
PaymentClose) is exercised only in the pre-fix/broken code; with the fix applied, the condition at line 311 is expected to be false becauseAccountClosealready closed and persisted the payment before the hook fires. A one-line comment clarifying this would help future maintainers understand what's actually being asserted here, since the branch not firing is itself the proof of the fix.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@x/escrow/keeper/keeper_test.go` around lines 303 - 316, Add a short inline test comment in the AddOnAccountClosedHook callback near the PaymentClose branch to explain that this path should no longer run after the fix. Reference the nested hook logic around GetPayment and PaymentClose so it’s clear that AccountClose has already closed and persisted the payment before this hook executes, making the StateClosed check expected to fail and the branch skipped.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@x/escrow/keeper/keeper_test.go`:
- Around line 303-316: Add a short inline test comment in the
AddOnAccountClosedHook callback near the PaymentClose branch to explain that
this path should no longer run after the fix. Reference the nested hook logic
around GetPayment and PaymentClose so it’s clear that AccountClose has already
closed and persisted the payment before this hook executes, making the
StateClosed check expected to fail and the branch skipped.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 05282eba-eac6-4e97-a0a3-2b050c67fc6b
📒 Files selected for processing (2)
x/escrow/keeper/keeper.gox/escrow/keeper/keeper_test.go
Summary
Root cause
AccountClose marked related payments closed in memory, then save persisted the account before payments. Persisting the account fired the account-closed hook. The market hook could then call PaymentClose while the account was already stored as closed and the payment was still stored as open, producing account closed.
Verification
Failing-before output from the regression test:
Passing-after checks: