Commit Graph

33 Commits

Author SHA1 Message Date
C
ade48cd8a9 Introduce a SignatoryManager service. (#509)
* WIP: Introduce a SignatoryManager service.

The SignatoryManager manager provides an API to interact with keysets, private
keys, and all key-related operations, offering segregation between the mint and
the most sensible part of the mind: the private keys.

Although the default signatory runs in memory, it is completely isolated from
the rest of the system and can only be communicated through the interface
offered by the signatory manager. Only messages can be sent from the mintd to
the Signatory trait through the Signatory Manager.

This pull request sets the foundation for eventually being able to run the
Signatory and all the key-related operations in a separate service, possibly in
a foreign service, to offload risks, as described in #476.

The Signatory manager is concurrent and deferred any mechanism needed to handle
concurrency to the Signatory trait.

* Fixed missing default feature for signatory

* Do not read keys from the DB

* Removed KeysDatabase Trait from MintDatabase

All Keys operations should be done through the signatory

* Make sure signatory has all the keys in memory

Drop also foreign constraints on sqlite

* Fix race condition

* Adding debug info to failing test

* Add `sleep` in test

* Fixed issue with active auth keyset

* Fixed dependency

* Move all keys and keysets to an ArcSwap.

Since the keys and keysets exist in RAM, most wrapping functions are infallible
and synchronous, improving performance and adding breaking API changes.

The signatory will provide this information on the boot and update when the
`rotate_keyset` is executed.

Todo: Implement a subscription key to reload the keys when the GRPC server
changes the keys. For the embedded mode, that makes no sense since there is a
single way to rotate keys, and that bit is already covered.

* Implementing https://github.com/cashubtc/nuts/pull/250

* Add CLI for cdk-signatory to spawn an external signatory

Add to the pipeline the external signatory

* Update tests

* Apply suggestions from code review

Co-authored-by: ok300 <106775972+ok300@users.noreply.github.com>
Co-authored-by: thesimplekid <tsk@thesimplekid.com>

* Minor change

* Update proto buf to use the newest format

* Rename binary

* Add instrumentations

* Add more comments

* Use a single database for the signatory

Store all keys, even auth keys, in a single database. Leave the MintAuthDatabse
trait implementation for the CDK but not the signagtory

This commit also moves the cli mod to its own file

* Update dep

* Add `test_mint_keyset_gen` test

---------

Co-authored-by: ok300 <106775972+ok300@users.noreply.github.com>
Co-authored-by: thesimplekid <tsk@thesimplekid.com>
2025-05-28 11:43:30 -04:00
KnowWhoami
ffce3a8aef test: use expect/unwrap instead of anyhow 2025-05-01 03:29:43 +05:30
thesimplekid
fa67271cca Int tests (#685)
* Here's a commit message for this change:

refactor: Move mint tests to fake_wallet.rs and add descriptive comments

refactor: pure wallet/mint does not need arc

refactor: Consolidate NUT-06 test into single function and remove redundant module

docs: Add comments explaining test purposes in integration tests file

refactor: Remove anyhow and replace with expect for error handling

refactor: use expect in pure tests

feat: Add configurable database type via environment variable for test mint and wallet

refactor: Update database initialization in test mint and wallet creation

feat: Add temporary directory support for redb and sqlite databases in tests

feat: Add database type argument to test commands in justfile

ci: Add build matrix for pure-itest with memory, sqlite, and redb databases

refactor: use expect in pure tests

refactor: Move and refactor `test_swap_unbalanced` from mint to integration tests pure

refactor: move mint tests to pure tests

docs: Add detailed comments explaining test file purposes for mint and integration tests

refactor: Extract keyset ID retrieval into a reusable function

test: Add concurrent double-spend test with 3 swap transactions

refactor: Simplify concurrent swap request processing and error handling

test: Add check to verify all proofs are marked as spent in concurrent double-spend test

refactor: Optimize proof state retrieval in concurrent double-spend test

feat: Add test for concurrent melt race condition with same proofs

fix: Update concurrent melt test to use melt quote and handle errors

refactor: melt concurrrent

refactor: Rename test function for clarity in concurrent double-spend scenario

refactor: Modify test_concurrent_double_spend_melt to manually create melt requests in mint tasks

feat: con melt test

refactor: Optimize proof state handling and error recovery in check_spendable

refactor: Extract helper method to reset proofs to original state

fix: reset y states

fix: reset y states

* fix: acces of priv feilds

* fix: add extra migrate
2025-03-27 12:48:36 +00:00
thesimplekid
5484e7c33a Merge pull request #690 from thesimplekid/request_without_dleq
Request without dleq
2025-03-27 08:45:02 +00:00
thesimplekid
162507c492 feat: payment processor 2025-03-10 14:44:57 +00:00
ok300
5a7362c09f Simplify process_swap_request (#631)
* Simplify process_swap_request

* Fix occasional test_swap_to_send wallet errors
2025-03-06 15:08:59 +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
thesimplekid
a82e3eb314 fix: attempt to swap after a failed transaction (#622)
* fix: attempt to swap after a failed transaction

* fix: revert test change in https://github.com/cashubtc/cdk/pull/585
2025-03-03 14:10:47 +00:00
thesimplekid
a8ec52612b Refactor mint tranactions checks (#585)
* refactor: consolidate validation checks

* refactor: melt verification checks

* refactor: mint verification

* chore: clippy

* chore: use error codes

* fix: order of verifications

* fix: p2pk test ws updates

We only expect the proof to be set to pending once. As a proof without
a signature failes before the spent check where the state is chaged.

* fix: mint_melt regtest frome wait
2025-02-08 11:17:44 +00:00
thesimplekid
47ee54d7f5 feat: mint management rpc server and client cli 2025-02-06 12:05:13 +00:00
thesimplekid
df8291dc04 feat: rotate next keyset 2025-02-02 14:30:59 +00:00
thesimplekid
65e07e37f1 fix: mint start with newest keyset
chore: test for newest keyset

chore: add pure tests to ci
2025-02-02 11:53:19 +00:00
thesimplekid
335bac7bca chore: clippy 2025-01-30 00:07:46 +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
C
c6e27d0de9 Add ArcSwap to update Mint configuration at runtime (#503)
* Add ArcSwap to update Mint configuration at runtime

The main goal is to change settings without having multiple RwLock everywhere,
instead having ArcSwap to update the configuration without having access to a
mutable reference to the Mint.

This will allow the RPC Server, or any other medium to update the Mint without
minimum contention.

* Rename structs

* Move quote_ttl to the new config

* Fixed clippy issues
2024-12-25 09:53:58 -05:00
thesimplekid
003a8f1b47 feat: signature on mint witness 2024-12-23 10:25:42 -05:00
Cesar Rodas
760564cee0 Introduce subscription support in the Wallet crate.
The main goal is to add a subscription to CDK Mint updates into the wallet.
This feature will be particularly useful for improving the code whenever loops
hit the mint server to check status changes.

The goal is to add an easy-to-use interface that will hide the fact that we're
connecting to WebSocket and subscribing to events. This will also hide the fact
that the CDK-mint server may not support WebSocket updates.

To be fully backward compatible, the HttpClientMethods traits have a new
method, `subscribe,` which will return an object that implements
`ActiveSubscription.`

In the primary implementation, there is a `SubscriptionClient` that will
attempt to connect through WebSocket and will fall to the HTTP-status pull and
sleep approach (the current approach), but upper stream code will receive
updates as if they come from a stream of updates through WebSocket. This
`SubscriptionClient` struct will also manage reconnections to WebSockets (with
automatic resubscriptions) and all the low-level stuff, providing an
easy-to-use interface and leaving the upper-level code with a nice interface
that is hard to misuse. When `ActiveSubscription` is dropped, it will
automatically unsubscribe.

Fixed bug with Default as described in https://github.com/cashubtc/cdk/pull/473#discussion_r1871032297
2024-12-08 16:25:00 +00:00
thesimplekid
6dd023a71c chore: cargo fmt 2024-11-15 19:38:59 +00:00
César D. Rodas
6973e53799 Mint Websockets (NUT-17) (#394)
---------

Co-authored-by: thesimplekid <tsk@thesimplekid.com>
2024-11-06 14:36:13 +00:00
thesimplekid
3db25640dc feat: support custom unit 2024-11-05 14:21:21 +00:00
thesimplekid
008c913583 refactor: ln backends within mint 2024-09-27 10:04:33 +02:00
thesimplekid
5139c47dac feat: check outgoing payment status flow 2024-09-25 20:28:05 +02:00
thesimplekid
f2867188a8 fix: sqlx sqlite settings
feat: use transactions in all sql fns
2024-09-21 11:10:38 +02:00
thesimplekid
59deb34143 refactor: itest as lib 2024-09-10 14:27:05 +01:00
thesimplekid
9b78305722 refactor: calc fee 2024-09-08 13:34:54 +01:00
thesimplekid
2fdf48cc72 feat: remove mint and wallet errors 2024-09-08 11:48:52 +01:00
thesimplekid
eb0ba7da43 fix: check for addition overflow 2024-09-04 19:49:00 +01:00
thesimplekid
5f87df2cef refactor: use MintUrl::from_str 2024-09-03 11:36:28 +01:00
thesimplekid
65163b89bc refactor: check scripts for justfile
chore: ci run examples
2024-08-19 14:48:45 +02:00
thesimplekid
e8114f3383 feat(tests): integration test 2024-08-19 00:01:30 +02:00