Introduce subscription support in the Wallet crate. #473
No reviewers
Labels
No labels
DB & Storage
Deployment
Error Handling & Logging
Maintenance
Payment Backend
backport
backport v0.13.x
backport v0.14.x
backport v0.15.x
bindings
blocked
bug
cdk-sql
ci
cli
deps
documentation
duplicate
enhancement
good first issue
help wanted
invalid
keep-open
ldk-node-ui
migrations
mint
mutation-testing
needs rebase
needs review
new nut
nut change
question
ready
rust-version
rustfmt
stacked hold
stale
testing
wallet
weekly-report
wontfix
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
cashubtc/cdk!473
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "web-socket-for-wallet"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Description
The last bit missing to wrap up #442
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 implementsActiveSubscription.In the primary implementation, there is a
SubscriptionClientthat 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. ThisSubscriptionClientstruct 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. WhenActiveSubscriptionis dropped, it will automatically unsubscribe.Notes to the reviewers
Suggested CHANGELOG Updates
Added Websocket subscription to the Wallet.
CHANGED
ADDED
REMOVED
FIXED
Checklist
just final-checkbefore committingGreat work just a few comments.
@ -0,0 +1,322 @@//! Client for subscriptionsIf we call this on a mint that does not include NUT17 in the info response which is possible because it is an optional nut
is_ws_supportis set to true when we need to assume false. This leads to an infinite loop of the wallet trying to connect to the ws endpoint that does not exist on the mint.This happens since we have the deafult of NUT17 ` Supported settings to support all the endpoints.
github.com/cashubtc/cdk@7d15587e3f/crates/cdk/src/nuts/nut17/mod.rs (L38-L65)I think we should change the default here to not support any endpoints and then for out mint we won't use the Default but will explicitly set that we support them.
It may also be worth adding a time out to the ws connection attempt so the loop does not happen.
to reproduce this you can start a cdk-mintd from the v0.4.0 tag and then use this branch as the wallet with cdk-cli.
Would it be better to put the mint specific code behind the mint feature instead of using unreachable?
This whole file in in a wallet mod so really there should be no mint relevant code here.
@ -0,0 +1,214 @@use std::collections::{HashMap, HashSet};As mentioned above this creates an infinite loop if the wallet cannot connect to the ws endpoint, I think we should add a timeout.
NIT: Code style we don't import tracing and use the full path when we use it.
https://github.com/cashubtc/cdk/blob/main/CODE_STYLE.md#full-paths-for-logging
@ -0,0 +1,214 @@use std::collections::{HashMap, HashSet};My idea is to try a few loops and then fall back to the HTTP worker otherwise. But it's better to understand the INFO response and attempt to connect to WebSocket instead of treating it as a boolean.
The HTTP subscription worker should be spawned if any subscription method is not supported over WebSocket or the WebSocket worker is exhausted of failures. The HTTP subscription method supports all methods, but it is less efficient.
@ -0,0 +1,214 @@use std::collections::{HashMap, HashSet};Yeah I think that makes sense. I noticed it because of the above noted issue with a mint that does not signal anything for nut17 and bc of the default we try anyway. In the case of a mint signaling explicitly that it does not support ws we should not try ws at all, if it does signal support we can try and then fall back on failure.
@ -0,0 +1,322 @@//! Client for subscriptionsIf the response is not part of the info, it will be false (unwrap_or_default is set to false). Keep in mind that
is_emptyis negated. Anyway, I think we can safely assume it exists _now since the WebSocket worker will fall back to HTTP (after 246e583).What do you think @thesimplekid?
@ -0,0 +1,322 @@//! Client for subscriptionsIt will not be false if NUT17 is not included in the info response since we use the default here
github.com/cashubtc/cdk@5ad4328a4e/crates/cdk/src/nuts/nut06.rs (L242-L245)and the default currently is that they are all supportedgithub.com/cashubtc/cdk@34bd97b262/crates/cdk/src/nuts/nut17/mod.rs (L40-L87). This is why i suggest we change the default to not supported.I think we should avoid the fallback in cases where we know it is not supported.
@ -0,0 +1,214 @@use std::collections::{HashMap, HashSet};Do we want to log each error and what the error is or too much logging?
I fixed #493 in 8b3ff74
@ -0,0 +1,214 @@use std::collections::{HashMap, HashSet};Fixed in 392136e
@ -0,0 +1,322 @@//! Client for subscriptionsFixed in 641c301
ACK
2462168ec9