-
Notifications
You must be signed in to change notification settings - Fork 178
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
RPC-API: add ability to recover wallet #1461
Conversation
A couple of initial comments: I'm marking this as a solution to #1082 but I have not yet written another endpoint for blockchain rescan, I will add that in a new commit. This is still draft because I have only done one primitive test, it will need tests added into CI as well. Also, the response format for this new |
Before I actually write a second commit for
The last of those three is of course the tricky one, but also tricky is how we distinguish the former from the latter. The reason for setting up the websocket element was to address cases like this where the jmwalletd backend fires off an event elsewhere (here, a rescan on the bitcoind process) and has to notify a client when it completes. So that would be a natural part of how to address this, but .. I would appreciate any input on how you think it should work, for a client like JAM. |
I'm almost ready to add a /rescanblockchain route but I currently need a way to check that the rescan is completed by using the bitcoind rpc; does anyone know the easiest way to do that? (I seem to remember at least one rpc call will tell you 'rescan in progress' but I can't remember which one). |
There is |
Calling rescanblockchain in a running process is proving to be a much more difficult task than I had anticipated (or more accurately, I'd just forgotten the nuances here):
Not addressing this at all is hardly desirable either: as long as the rescan operation is continuing, the entire jmwalletd process is blocked and can't respond to client queries (and for mainnet, this could be an hour plus...). |
Right, thanks, I found |
Marked this as ready for review. In rudimentary testing with POSTMAN on signet, the following work:
My resolution to the above difficulties was to start a daemon-type subthread for this one specific call, and create a new JsonRPC object to handle that request. It seems to work. This needs review, but also I should try to add some kind of test to the test suite. |
Added some basic testing into |
OK, squashed and did a few more manual tests. I'm now confident that this is correct. Wil address @kristapsk 's syntax comments and then wait for any testing feedback. |
Fixes #1082: This commit allows recovery of a wallet from a seedphrase with a new endpoint wallet/recover. 4 parameters are passed in, the same three as for wallet/create but also a bip39 seedphrase as the fourth argument. This commit also adds a rescanblockchain RPC call and status: This adds a new endpoint /rescanblockchain which is (Core) wallet specific (due to underlying JM architecture). This action is spawned in a thread, since the bitcoind RPC call is blocking and can take a very long time. To monitor the status of the rescan, an extra field `rescanning` is added to the /session endpoint. Also adds test of rpc wallet recovery
Done |
@AdamISZ What tools do you use to test this? I remember there was some simple JM RPC client, but can't find it now, don't remember how it was called or who made it. |
I use POSTMAN. Here's a screenshot: You can enter the Body of POST requests using json formatted text. |
But you're right, someone wrote some python code to test it, I have that memory too .. who was it? I don't think it was @PulpCattel ? |
Yes, I made this repo to test the RPC interface when it was introduced. I will eventually update it. |
Looking at
|
Yes, I noticed this also when running the tests. I think it would be a really nice augmentation to simply rescanning=true/false, but it can be done in a later update. A related point occurred to me today: almost everyone running JAM is doing so on a packaged node which is providing other services as well as Joinmarket. Is it OK for us to just decide to do a rescan at any time? Might that not affect other running services? @openoms any thoughts? |
In my experience a rescan can add load, but finishes within an hour in the worst case even on a RasperryPi and bitcoind remains functional. I am monitoring 20+ wallets with Specter and could rescan the wallets on demand without problems. It is ok to trigger them as needed. |
Agree, that can be added later. |
That's good to know, thanks. The main reason I was asking, though, is that I was concerned if maybe some RPC calls might be disabled during rescan; thinking about it, they're probably wallet RPCs, and I guess that most applications are not using bitcoin core's wallet feature? |
That's true, RaspiBolt at one point even had disabled wallet feature in Core by default, which was a problem for JoinMarket guide. |
Perhaps a little impatient, but it's been a while and this seems to be highly desired, so I'm going to go ahead and merge without further test or review (we've had a little). |
…etwalletinfo()` for `bci` e31e839 Add get_wallet_rescan_status() instead of getwalletinfo() for bci (Kristaps Kaupe) Pull request description: Noticed this when tried to rebase #1462 after merging of #1477. #1461 added public `getwalletinfo()` method to `BitcoinCoreInterface`, which was used by code outside of `jmclient/jmclient/blockchaininterface.py`. This is bad approach, as it relies on Bitcoin Core RPC `getwalletinfo` returned `dict`, which contains a lots of different stuff too, could lead to more problems in future introducing other blockchain interface classes. Let's instead have generic method returning just wallet rescan status. Also it now returns `Tuple[bool, Optional[Decimal]]` with rescan status percentage, if rescan is in progress, although that's not used by any other code for now. ACKs for top commit: AdamISZ: utACK e31e839 , very much agree with the thinking here. Tree-SHA512: 2d8c9b8157847e713838099d0f62dfcd5321c9498cf8453a9087407e2cd9c32906739c8e71460fc6ac6426662d2ac501261080fea08388d928933f788bda9a8d
Hey @AdamISZ, I have a question regarding how to correctly use this from a client perspective.
After importing, the funds on address I know this is a theoretical scenario, but even if the funds are on other addresses (beyond the gap limit), I was not able to recover them successfully. Now before I try to be too clever, I just thought I'd ask what to do. |
I was able to replicate this effect on regtest, for now outside the API (because I want to understand it "raw" first, before considering API commands) (also, I will document exactly what I did later, but for now, just an outline comment): I find that if I do the following: (1) run wallet-tool with gap limit set to 202 (whatever is higher than your funding), (2) run rescanblockchain N with N sufficient to find the txs and then (3) run wallet-tool with gap limit set to 202 again, then it works. While awkward the logic makes sense, right: the first run of wallet tool display is going to import as many addresses into the backend Core wallet as it thinks it needs; and with -g 202 you are telling it to import all that way up. Now, after the imports have occurred, the But anyway just a quick initial report on what I'm seeing. I'll look at the same sequence of events via API next. |
@theborakompanioni ok I'm reasonably sure I understand what's going on now, after trying via the API. I can indeed reproduce what you're saying. So the problem is how we're handling gap limit. The method to open the wallet ( |
See #1525 . I think it should do what is needed. Sorry for this screw up, I can imagine quite a few people had problems because of it! |
Related joinmarket-webui/jam#743 May I open a ticket? |
Yes, of course. |
Fixes #1082.
This commit allows recovery of a wallet from a seedphrase with a new endpoint wallet/recover. 4 parameters are passed in, the same three as for wallet/create but also a bip39 seedphrase as the fourth argument.