Repository navigation
Rpc api 2 - #996
Rpc api 2#996
Conversation
|
Thanks for doing this; and don't worry about the conflict (rebase needed), we can do that later. |
|
Little update on status for anyone following: most core functions are working: create wallet, load wallet, send direct, deposit funds, send coinjoin, start and stop maker, display wallet details including utxos. (Here by "working" i mean both the front-end at https://github.com/shobhitaa/Joinmarket-SOB and the backend here) Still some rough edges to clean up around wallet state management, and handling how wallet state updates on the backend are communicated to the front end. People can probably start testing it on signet soon (feel free to start already if you're patient and interested). |
|
On downloading this branch and attempting to install the backend, I found a few issues:
|
I think (2) will be fixed once you create a self signed certificate. Since the server is TLS, you need a |
|
Thanks! That fixed it. |
|
After those two minor fixes we have something that's close to viable at least for testing, so I'll try to do the rebase now (today), since master has diverged quite far ahead at this point. |
|
Rebased on master as of 828cec2 and just cleaned up some imports in f30009d. Happy to report that the most basic tests on regtest are working fairly smoothly; was able to fund wallet and show updates to balance by returning to main wallet display. (Obviously we have previously done a fair bit of testing of sending, receiving, coinjoining and running maker so tons more testing to do, especially after rebase which could throw up new errors with code base changes). (Also we'll want a test module to test each of the RPC methods, and make sure we've got test suite passing). |
Add these dependencies to |
2782691 to
4ca735d
Compare
|
Not sure if it's something you'd be willing to do, but having an OpenAPI definition for this would be very useful. |
Thanks. Something like this is needed for sure. (I was just thinking about versioning today, but this is a nice link thanks, also there are a ton of other things before we get there, testing and a subscription element of the API. Still working very actively on this. Note the doc I wrote early on, it is at least a start). |
|
See the commit comment for f00a201 but, to expand:
According to my cursory test, the functionality that was already in place in our So you can see there is still tons to do, in particular:
|
Spent quite a bit of time looking into it. Unfortunately all the tools available are hooked into Flask specifically, and there was some specific reason (which I might revisit) as to why this setup in twisted worked with Klein but not Flask. |
|
After 18191ef docs more accurately reflect what exists in the API.
Next job will be: make the websocket transaction notification do what is intended, and test it with a client. |
PulpCattel
left a comment
There was a problem hiding this comment.
Mostly nits found while skimming through the code (I'm halfway through it), I'll try to keep testing this as time allows.
|
Yeah makes sense, you have addressed most of the stuff anyway, I'll reopen the relevant discussions if something is lost in the process. |
|
Squashed the last 27 commits in 9f334ab to make things a bit more manageable, I think there was only one outstanding issue from the earlier comment round. |
|
Shall I add a GET and POST for any config var based on values "section" and "parameter=x"? That seems like the simplest way to address the config issue (perhaps there should be a secondary GET that returns the entire config as json, it might take a moment to convert configparser->json or it might be trivial). |
PulpCattel
left a comment
There was a problem hiding this comment.
Shall I add a GET and POST for any config var based on values "section" and "parameter=x"? That seems like the simplest way to address the config issue (perhaps there should be a secondary GET that returns the entire config as json, it might take a moment to convert configparser->json or it might be trivial).
Both points seem reasonable.
|
Added config get/set in 2893c7e and tested with POSTMAN that i could read/write/read OK with those routes. I'll avoid the work of figuring out how to do "get the entire config", for now. This is theoretically enough to be working with (one very important practical element: to do a coinjoin you might want to set the transaction fee, which you can now do by setting POLICY/tx_fees in the client, otherwise you would have had to edit the config file). I am mostly ready to merge now. I'll spend a few hours looking at the websocket and seeing if I can improve it (the repeated tx notifications don't bother me though, I think I know the reason). And of course it's super-bare bones with only the tx notification and nothing else, but in principle that's enough for someone writing client side code to do something approximating to what they need. If there's some other function that absolutely must be in the first version, let me know. Advanced features like payjoin will wait for a later update. |
@AdamISZ I think you forgot this review comment of yourself, call to |
Yes, I did. Thanks! |
|
@PulpCattel i think i've finished cleaning up the bits and pieces now. The last one adds a |
There was a problem hiding this comment.
Tried the new notification and it works, it seems that this one is only sent once, while the transaction one is still sent 4 times (but as you said, no big deal).
The maker service starts and stops correctly in benign cases, but it seems to reach a weird state when, e.g., we pass it invalid values.
In this case a min size too high.
2021-10-07 23:56:07,519 [INFO] JoinMarket 0.9.2
2021-10-07 23:56:09,520 [INFO] minsize (50000000000) > maxsize (67451966)
2021-10-07 23:56:09,521 [INFO] Not a fidelity bond wallet, not announcing fidelity bond
2021-10-07 23:56:09,521 [ERROR] Failed to create offers.
2021-10-07 23:56:09,521 [INFO] offerlist=[]
2021-10-07 23:56:09,522 [INFO] Shutting down YieldGenerator service.
client fac is <jmclient.client_protocol.JMClientProtocolFactory object at 0x7b79dc203080>
2021-10-07 23:56:12,813 [INFO] joined: #joinmarket-pit-sig irc-eu-1.darkscience.net
2021-10-07 23:56:12,814 [INFO] Could not connect to *ALL* servers yet, waiting up to 60 more seconds.
2021-10-07 23:56:13,222 [INFO] joined: #joinmarket-pit-sig guybrush.hackint.org
2021-10-07 23:56:13,223 [INFO] All IRC servers connected, starting execution.
When it reaches this state, it's not possible to stop it via maker-stop (not even after fixing the other comment), the command goes through (and JoinMarket thinks it's stopped) but the service actually keeps running.
p.s. Could be only IRC connections? I didn't try to be picked for a CoinJoin while in this state.
p.p.s. Tested configset and configget and both seems to work, I was able to get a setting, set it to a different value, get it again and assert it's equal to the value I just set.
This is in the weeds and not interesting, but the reason is that the underlying bitcoin wallet gets a new transaction event multiple times if there are multiple input/outputs that involve the wallet, plus it also gets a separate event for confirmed and unconfirmed; with our normal callbacks we "swallow" the event the first time a specific txid is seen (i.e. once such a callback is called, it is removed from the list, so is guaranteed to be called once), but for the special "all" type callback, we are calling back every time we see a record of a transaction that involves the wallet in any way at all, and we don't delete that callback from the list, it's supposed to keep going continuously. I'm sure it would not be super hard to change the code to make sure that such callbacks are not repeatedly called on the same transaction, but it's not enough of a priority to be worth testing and so on. |
That's a good catch. I'll catch the assertion error in (Unfortunately though, there may be other cases like this dotted around) |
The changes in 3af86d5 should have fixed this. I tested by : maker start/stop/start/stop with valid arguments, then tried to start once more with invalid minsize, it did as expected (started then immediately shut down the service), then I did start again, and it started up correctly. (There is still an unpleasant leftover: I believe, though didn't check in detail, that the IRC bot/nick created for the version of the maker which was invalid, is left dangling. I can fix that later; it's an edge case, and a couple of nicks hanging around, only if the maker is ill configured, until the process shuts down is not a disaster). Can't guarantee there might be other ways to trigger Exceptions that cause an issue, but of note is that the Maker bots have been refined over a long period of time to basically not ever crash based on external input. |
|
OK done a fair bit of testing of all the main functions using postman. Anybody else seeing any outstanding issues? |
bdc5ea7 to
66b5273
Compare
Uses Klein to provide HTTP server support. Adds cookie based auth to requests (made JWT token based in later commits). Basic routes are: /unlock, /lock, /display, /create of wallet. Encapsulates WalletDaemon as a Service Add snicker receiver service start, stop Adds yg/maker function as stoppable service. Adds a JMShutdown command to the AMP protocol, allowing a clean shutdown of a long running bot (e.g. maker) by shutting down its message channel connections, without shutting down the entire process. Adds payment(direct send) request, first draft
The /utxos route is the equivalent of the showutxos wallet tool method. The heartbeat route /session allows a client to make sure the backend is still running and in the expected state (but see later commits for the coinjoin state update via the websocket). Fixes to sendpayment, the maker service, the create wallet function. sendpayment fix Also substantially improved and made functional the coinjoin route, a schedule is now created and a complete taker-side coinjoin is now possible.
|
Squashed to three commits ready for merge. |
1. Moves the JMWalletDaemon service class into the jmclient package (see the wallet_rpc.py module). 2. Adds dependencies "klein" and "autobahn" to the jmclient package, as well as "pyjwt". 3. Adds another module websocketserver.py, using autobahn, to allow the JMWalletDaemon service to serve subscriptions over a websocket, for e.g. transaction notifications. 4. Adds tests both for the websocket connection and for the JSON-RPC HTTP connection. JmwalletdWebSocketServerFactory.sendTxNotification sends the json-ified transaction details using jmbitcoin.human_readable_transaction (as is currently used in our CLI), along with the txid. Also adds a coinjoin state update event sent via the websocket (switch from taker/maker/none). Require authentication to connect to websocket. 5. Add OpenApi definition of API in yaml; also auto-create human-readable API docs in markdown. 6. Add fidelity bond function to API 7. Add config read/write route to API 8. Remove snicker rpc calls temporarily 9. Updates to docoinjoin: corrects taker_finished for this custom case, does not shut down at end. 10. Address detailed review comments of @PulpCattel.
|
Did lots of testing last couple of days and cleaned off a few edge cases. Merging now; obviously it's not perfect but this should be viable for someone wishing to write client code, as a first functional version. Thanks to everyone for helping out. |
840189c Fix SNICKER daemon startup (Kristaps Kaupe) Pull request description: Fixes #1067. Bug was introduced with 7e73e4c (part of #996) when return value of `start_daemon_on_port()` was changed from `int` to `tuple`. Top commit has no ACKs. Tree-SHA512: 76bfbbf89b66d39d277bac4aed515cd251fe5f40e6eaafc2596c2e095a60931f1cddd2b147e4fd51d07c99c6ff8c94bbc2fe661a618da0220ff4924128833031

Extension of rpc-api-1, backend API for the Web based Joinmarket wallet interface