fix: covering balance cache - #5610
Open
sbackend123 wants to merge 3 commits into
Open
sbackend123 wants to merge 3 commits into
sbackend123 wants to merge 3 commits into
Conversation
sbackend123
marked this pull request as ready for review
September 13, 2026 20:01
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Checklist
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:
Open API Spec Version Changes (if applicable)
Motivation and Context (Optional)
Related Issue (Optional)
#5570
Screenshots (if appropriate):
Results:

AI Disclosure