lightninglabs / lightninglabs/loop
staticaddr/deposit: separate generic OnError from caller-held rollback events
Nobody has claimed this yet.
- Dominant language
- Go
- Stars
- 595
- Forks
- 135
- Avg merge
- 1d 8h
- Merged PRs (30d)
- 12
Description
Problem
The static-address deposit FSM currently treats fsm.OnError as if it always arrives while the caller already holds the deposit lock.
That assumption is not reliable. Some fsm.OnError transitions do come from TransitionDeposits, where the manager locks deposits before sending the event. But deposit FSM actions can also emit fsm.OnError internally. Examples include:
PublishDepositExpirySweepActionreturningfsm.OnErrorafter expiry sweep publish failures;WaitForExpirySweepActionreturningfsm.OnErrorafter notifier or context errors.
Those internal paths originate from the deposit FSM's own block handling, so no external deposit lock is held.
Because fsm.OnError is in lockedEvents, updateDeposit can skip acquiring the deposit lock, call no-lock state mutation helpers, and update the store under an assumption that is false for internally generated errors.
This was discussed during PR #1161: https://github.com/lightninglabs/loop/pull/1161#discussion_r3539803146
The issue appears to predate PR #1161, but that PR touched the surrounding deposit locking/lifecycle code and made the invariant visible.
Potential fix
Do not use the generic fsm.OnError event to also mean "caller-held rollback/unlock to Deposited".
One possible shape:
- introduce a deposit-specific rollback event, for example
OnReleaseDepositorOnDepositRollback; - use that event from manager-driven
TransitionDepositscallers that already hold deposit locks and need to move selected deposits back toDeposited; - include that specific rollback event in
lockedEvents; - remove generic
fsm.OnErrorfromlockedEvents, so internally generated errors acquire the deposit lock insideupdateDeposit; - keep
fsm.OnErroras the generic action-error transition in the deposit FSM, not as an implicit lock-state signal.
That separates event meaning from caller locking context: events sent by TransitionDeposits can still avoid double-locking, while internally generated fsm.OnError paths no longer run no-lock state/store updates without a held deposit lock.
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by tracing updateDeposit, lockedEvents, and TransitionDeposits, then inspect the deposit FSM actions PublishDepositExpirySweepAction and WaitForExpirySweepAction. Separate the caller-held rollback event from generic fsm.OnError so internally generated errors acquire the deposit lock, while manager-driven rollback avoids double-locking. Done means both paths preserve the intended state and store updates without relying on an incorrect lock assumption.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- go
- Domain
- backend
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100