fix: load keyset keys from database to prevent duplicate insertions #1291

Merged
thesimplekid merged 1 commit from wallet_key_cache_duplicate into main 2025-11-17 15:23:30 +00:00
thesimplekid commented 2025-11-17 13:08:04 +00:00 (Migrated from github.com)

The wallet was failing on the second mint with "UNIQUE constraint failed: key.keyset_u32" because the MintMetadataCache never loaded keys from the database on startup. Every new process would re-fetch keys from the mint's HTTP API and try to insert them again, causing aconstraint violation. Fixed by loading existing keys from the database into the cache before fetching from HTTP (in both load_from_mint and load_auth). Checking if keys already exist before trying to insert them in persist_to_database. This eliminates the duplicate insertion errors and also saves bandwidth by not re-fetching keys we already have.

Description


Notes to the reviewers


Suggested CHANGELOG Updates

CHANGED

ADDED

REMOVED

FIXED


Checklist

The wallet was failing on the second mint with "UNIQUE constraint failed: key.keyset_u32" because the MintMetadataCache never loaded keys from the database on startup. Every new process would re-fetch keys from the mint's HTTP API and try to insert them again, causing aconstraint violation. Fixed by loading existing keys from the database into the cache before fetching from HTTP (in both load_from_mint and load_auth). Checking if keys already exist before trying to insert them in persist_to_database. This eliminates the duplicate insertion errors and also saves bandwidth by not re-fetching keys we already have. ### Description <!-- Describe the purpose of this PR, what's being adding and/or fixed --> ----- ### Notes to the reviewers <!-- In this section you can include notes directed to the reviewers, like explaining why some parts of the PR were done in a specific way --> ----- ### Suggested [CHANGELOG](https://github.com/cashubtc/cdk/blob/main/CHANGELOG.md) Updates <!-- Please do not edit the actual changelog but note what you changed here. --> #### CHANGED #### ADDED #### REMOVED #### FIXED ---- ### Checklist * [ ] I followed the [code style guidelines](https://github.com/cashubtc/cdk/blob/main/CODE_STYLE.md) * [ ] I ran `just final-check` before committing
crodas (Migrated from github.com) approved these changes 2025-11-17 13:42:11 +00:00
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
cashubtc/cdk!1291
No description provided.