Commit Graph

55 Commits

Author SHA1 Message Date
Cesar Rodas
abdde307c6 Fix race conditions with proof state updates.
Add a strict set of updates to prevent incorrect state changes and correct
usage. Supporting the transaction at the trait level prevented some cases, but
having a strict set of state change flows is better.

This bug was found while developing the signatory. The keys are read from
memory, triggering race conditions at the database, and some `Pending` states
are selected (instead of just selecting `Unspent`).

This PR also introduces a set of generic database tests to be executed for all
database implementations, this test suite will make sure writing and
maintaining new database drivers
2025-04-19 18:15:42 -03:00
thesimplekid
0b9ca1a474 Time time series (#708)
* feat: Add created_time and paid_time fields to MintQuote struct

* feat: Add serde default of 0 for created_time in MintQuote

* feat: Add created_time and paid_time to MintQuote and MeltQuote structs

* feat: Add paid_time update when setting melt quote state to Paid

* fix: Update melt quote state with current Unix timestamp

* feat: Add paid_time update for mint quote when state is set to Paid

* feat: Add issued_time field to MintQuote conversion from SQLite row

* feat: Add issued_time tracking for MintQuoteState::Issued state

* feat: Add migration script for mint time of quotes

* feat: Add timestamp columns to mint_quote and melt_quote tables

* feat: Add timestamp columns to `add_mint_quote` method

* refactor: Improve code formatting and readability in mint quote state update logic

* feat: Add created_time and paid_time columns to melt_quote query

* feat: time on mint and melt quotes

* feat: Add migration script for mint created time signature

feat: Add created_time column to blind_signature table

feat: Add created_time to blind_signature insertion

feat: Add created_time column to proof table and update insert query

feat: time on mint and melt quotes

* feat: Add new table to track blind signature creation time

* feat: Add timestamp tracking for proofs in ReDB database

* feat: redb proof time

* chore: fmt
2025-04-07 12:51:14 +01:00
C
43ab1fdde1 Do not create the wallet struct directly; instead, call new. (#707)
The bug comes with the SQLx-sqlite pool bug, where several connections are
created by default, but the `new` function takes care of that, fixing that bug
by making a single instance of the database.

If constructed directly, the pool would create several connections to the
database, which in most instances is fine, but with SQLite :memory: each
connection is entirely independent.

Also follow documentation to make sure that failed `acquire` will not end up
dropping connections by setting  test_before_acquire to false

     However, if your workload is sensitive to dropped connections such as using an in-memory
     SQLite database with a pool size of 1, you can pretty easily ensure that a cancelled
     `acquire()` call will never drop connections by tweaking your [`PoolOptions`]:

     * Set [`test_before_acquire(false)`][PoolOptions::test_before_acquire]
     * Never set [`before_acquire`][PoolOptions::before_acquire] or
       [`after_connect`][PoolOptions::after_connect].
2025-04-06 07:13:14 +01:00
thesimplekid
5484e7c33a Merge pull request #690 from thesimplekid/request_without_dleq
Request without dleq
2025-03-27 08:45:02 +00:00
codingpeanut157
47903c3bfd split MintDatabase into separate narrower scoped traits
- MintKeysDatabase
- MintQuotesDatabase
- MintProofsDatabase
- MintSignaturesDatabase

This commit splits the MintDatabase trait with 30+ methods into a series
of smaller traits, each dedicate to a specific subsystem of the mint
service.
2025-03-26 16:53:07 +01:00
thesimplekid
be93ff2384 Clear and Blind Auth (#510)
* feat: auth

* chore: corret error codes

* chore: corret error codes

* fix: feature auth in cdk-axum

* refactor: auth logging

* feat: include dleq in auth proof

* feat: mint max auth proofs

* chore: clippy
2025-03-24 11:13:22 +00:00
benthecarman
8cd4ea301a chore: Update sqlx to 0.7.4 2025-03-10 19:01:57 -05:00
thesimplekid
162507c492 feat: payment processor 2025-03-10 14:44:57 +00:00
benthecarman
40c53e83df feat: Add support for sqlcipher 2025-03-09 15:08:43 -05:00
thesimplekid
467cc0a027 feat: Add migration for keyset_id as foreign key in SQLite database (#634) 2025-03-08 22:46:12 +00:00
thesimplekid (aider)
d41d3a7c94 refactor: Add state check before deleting proofs to prevent removing spent proofs 2025-03-06 09:23:40 +00:00
C
f7d9a1b5db Drop the in-memory database (#613)
* Drop the in-memory database

Fixes #607

This PR drops the implementation of in-memory database traits.

They are useful for testing purposes since the tests should test our codebase
and assume the database works as expected (although a follow-up PR should write
a sanity test suite for all database trait implementors).

As complexity is worth with database requirements to simplify complexity and
add more robustness, for instance, with the following plans to add support for
transactions or buffered writes, it would become more complex and
time-consuming to support a correct database trait. This PR drops the
implementation and replaces it with a SQLite memory instance

* Remove OnceCell<Mint>

Without this change, a single Mint is shared for all tests, and the first tests
to run and shutdown makes the other databases (not-reachable, as dropping the
tokio engine would also drop the database instance).

There is no real reason, other than perhaps performance. The mint should
perhaps run in their own tokio engine and share channels as API interfaces, or
a new instance should be created in each tests

* Fixed bug with foreign keys

[1] https://gist.github.com/crodas/bad00997c63bd5ac58db3c5bd90747ed

* Show more debug on failure

* Remove old code

* Remove old references to WalletMemoryDatabase
2025-03-04 19:44:34 +00:00
C
63393056a0 Do not use INSERT OR REPLACE in SQLite. (#620)
Instead, use `INSERT` and `ON CONFLICT`.  The reason is that in case of
conflicts, the `REPLACE` will trigger a DELETE and then perform an INSERT, as
outlined in the documentation[1], and that may cause a cascade of deletion due
to our FOREIGN KEYs.

Here is the official documentation:

```
When a UNIQUE or PRIMARY KEY constraint violation occurs, the REPLACE algorithm
deletes pre-existing rows that are causing the constraint violation prior to
inserting or updating the current row and the command continues executing
normally. If a NOT NULL constraint violation occurs, the REPLACE conflict
resolution replaces the NULL value with the default value for that column, or
if the column has no default value, then the ABORT algorithm is used. If
a CHECK constraint or foreign key constraint violation occurs, the REPLACE
conflict resolution algorithm works like ABORT.  When the REPLACE conflict
resolution strategy deletes rows in order to satisfy a constraint, delete
triggers fire if and only if recursive triggers are enabled.  The update
hook is not invoked for rows that are deleted by the REPLACE conflict
resolution strategy. Nor does REPLACE increment the change counter. The
exceptional behaviors defined in this paragraph might change in a future
release.
```

[1] https://www.sqlite.org/lang_conflict.html
2025-02-28 11:35:29 +00:00
callebtc
b818054f9a Add filtering for mint quote states in database (#586)
* filter for mint quote states in db

---------

Co-authored-by: thesimplekid <tsk@thesimplekid.com>
Co-authored-by: ok300 <106775972+ok300@users.noreply.github.com>
2025-02-08 09:28:54 +00:00
thesimplekid
7b69aa966a feat: add remove proofs to mint db 2025-02-05 10:48:33 +00:00
thesimplekid
c455809812 refactor: move quote_ttl to database 2025-01-29 23:58:13 +00:00
thesimplekid
5481286ec9 refactor: move mint_info to database 2025-01-29 23:29:25 +00:00
thesimplekid
0674144001 refactor: remove mint url from config 2025-01-29 20:38:53 +00:00
C
8fe0982c6d Introduce cashu to host the shared types, traits and other common code (#519)
---------

Co-authored-by: thesimplekid <tsk@thesimplekid.com>
2025-01-12 12:50:05 +00:00
thesimplekid
6a8a5a7941 fix: mpp (#523) 2025-01-05 14:42:44 +00:00
thesimplekid
003a8f1b47 feat: signature on mint witness 2024-12-23 10:25:42 -05:00
Timothée Delabrouille
7d87c4806c feat: use Uuid as mint and melt quote ids (#469) 2024-12-05 09:58:53 +00:00
Cesar Rodas
af2fe580f4 Minor improvement in the SQLite crate
This is a minor improvement over the SQLite crate, which performs fewer SQL
statements and fetches multiple results instead.

This will also remove some redundant commit() and rollback calls. Rollback
already happens on drop, and there is no need for a commit if the database
hasn't changed, as the transaction is used as a locking mechanism in this
context.
2024-11-27 08:33:16 +00:00
ok300
f6533a08de Add Proofs trait to consolidate aggregate fns 2024-10-17 23:28:56 +01:00
thesimplekid
7ea568e615 feat: sql store signatures dleq 2024-09-30 12:20:43 +02:00
thesimplekid
ca6fdb5bff feat: return change in check quote 2024-09-30 09:47:23 +02:00
thesimplekid
5139c47dac feat: check outgoing payment status flow 2024-09-25 20:28:05 +02:00
thesimplekid
974796400d feat: get proofs for quote id 2024-09-23 14:05:28 +02:00
thesimplekid
fa8776998a feat(mint): store mint_quote_id for blind sig 2024-09-21 11:13:30 +02:00
thesimplekid
117443d126 feat: store melt_quote_id for proof 2024-09-21 11:13:30 +02:00
thesimplekid
f2867188a8 fix: sqlx sqlite settings
feat: use transactions in all sql fns
2024-09-21 11:10:38 +02:00
thesimplekid
5f87df2cef refactor: use MintUrl::from_str 2024-09-03 11:36:28 +01:00
thesimplekid
bcb4a5927d refactor: remove the use of flat maps 2024-08-17 14:35:52 +02:00
thesimplekid
ba19663531 feat(mint): issued and redeamed by keyset 2024-07-25 08:43:14 -04:00
thesimplekid
97fd83c8f4 feat(mint): add get blinded_sig by keyset 2024-07-22 16:43:26 +01:00
thesimplekid
a96ba31784 refactor: remove get single blinded sig 2024-07-20 10:19:12 +01:00
thesimplekid
6705761aec fix: dont update proof state if already spent 2024-07-19 00:30:59 +01:00
thesimplekid
fb014573c1 refactor: use sproof state update 2024-07-18 23:07:09 +01:00
thesimplekid
9789475686 feat: remove unused db fns 2024-07-18 23:07:09 +01:00
thesimplekid
373a4203b2 refactor(cdk/cdk_database): rename add_active_keyset to set_active_keyset 2024-07-16 09:21:51 +01:00
thesimplekid
d45019ae8b refactor: add_blind_signature to add_blind_signatures 2024-07-16 01:31:35 +01:00
thesimplekid
ed007c475e refactor: get spent and pending proofs by list of secrets or ys 2024-07-16 00:40:28 +01:00
thesimplekid
920e5d1fd7 fix: set inactive keysets as inactive in sql db 2024-07-11 21:02:12 +01:00
thesimplekid
6d3200c72d feat: use derivation path by unit 2024-07-11 20:48:45 +01:00
thesimplekid
17263b07f5 feat(NUT02): add input_fee_ppk
chore: instrument log on mint fns
2024-07-11 12:22:20 +01:00
thesimplekid
8b775cb7f1 feat: wait invoice is stream of request_lookup_id 2024-07-05 23:49:31 +01:00
thesimplekid
6a315fc3b9 feat: mintd axum server
feat: deafult NUT-04 and NUT-05 settings to enable bolt11 sats
2024-07-05 23:49:31 +01:00
thesimplekid
5db6eaa858 fix: default state sql
fix(mint/sqlite): add pending proof state

fix(mint): adding proof to pending before checking current

fix(mint): remove double call to verify melt quote
2024-06-29 09:03:57 +01:00
thesimplekid
b528964fb6 chore: readmes
chore: doc comments on public
2024-06-28 15:37:10 +01:00
thesimplekid
b0bfaec94a feat: add and remove proofs use vecs 2024-06-27 23:11:54 +01:00