* 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>
* 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
* 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
* 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
* 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
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