Skip to content

fix: covering balance cache - #5610

Open
sbackend123 wants to merge 3 commits into
masterfrom
fix/chequebook-covering-balance-cache
Open

sbackend123 wants to merge 3 commits into
masterfrom
fix/chequebook-covering-balance-cache

Conversation

@sbackend123

@sbackend123 sbackend123 commented Sep 13, 2026

Copy link
Copy Markdown
Contributor

Checklist

  • I have read the coding guide.
  • [] My change requires a documentation update, and I have done it.
  • I have added tests to cover my changes.
  • I have filled out the description and linked the related issues.

Description

Adds an in-memory cache for the chequebook covering balance (balance + totalPaidOut) so cheque issuance no longer does two live RPC calls under the global mutex on every Issue.

Known corner cases
a) Deposit may stay invisible until the cache expires
If the cache is loaded (or reloaded) before a deposit is mined, the node can keep using a stale covering balance for up to 5 minutes and refuse to issue cheques (ErrOutOfFunds). Impact is temporary under-issuance only. In practice the node is already struggling to settle when the chequebook is empty; an extra few minutes is unlikely to change the outcome meaningfully.

b) Withdrawal + cache refresh can allow an uncovered cheque
After Withdraw, the cache is reduced locally. An uncovered cheque is possible only if the cache is refreshed from chain after the withdrawal is broadcast but before it is mined, so the pending withdrawal is missing from the reloaded value.

That requires either:

  • a short window where the cache is invalidated/reloaded while the tx is still pending (e.g. a deposit invalidation), or
  • a stuck withdrawal that remains unmined longer than the 5-minute TTL

Open API Spec Version Changes (if applicable)

Motivation and Context (Optional)

Related Issue (Optional)

#5570

Screenshots (if appropriate):

Results:

Screenshot from 2026-09-13 21-51-45

AI Disclosure

  • This PR contains code that has been generated by an LLM.
  • I have reviewed the AI generated code thoroughly.
  • I possess the technical expertise to responsibly review the code generated in this PR.

@sbackend123
sbackend123 marked this pull request as ready for review September 13, 2026 20:01
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