Skip to content

Deduplicate cached Cashu proofs#73

Open
benthecarman wants to merge 1 commit into
masterfrom
cashu-cache-fix
Open

Deduplicate cached Cashu proofs#73
benthecarman wants to merge 1 commit into
masterfrom
cashu-cache-fix

Conversation

@benthecarman
Copy link
Copy Markdown
Collaborator

Keep the in-memory proofs cache aligned with the KV store's one-proof-per-Y invariant when proofs are re-added. Replacing cached entries prevents retries or recovery replays from duplicating proofs and inflating reported balances or proof enumeration results.

Keep the in-memory proofs cache aligned with the KV store's one-proof-per-Y
invariant when proofs are re-added. Replacing cached entries prevents
retries or recovery replays from duplicating proofs and inflating reported
balances or proof enumeration results.
Copy link
Copy Markdown
Contributor

@thesimplekid thesimplekid left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice find.

// Match the KV store's proof_<Y> uniqueness by replacing cached entries with
// the same Y before appending the updated proof data.
cache.retain(|proof| !added_ys.contains(&proof.y));
cache.extend(added);
Copy link
Copy Markdown
Contributor

@thesimplekid thesimplekid May 19, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To fully protect from duplicates we could de-duplicate the added vec, though cdk should not attempt to add duplicate proofs like this anyway so maybe not needed.

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.

2 participants