Skip to content
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

Abort sync_unspent if blockheight RPC call fails #1348

Merged
merged 1 commit into from
Dec 19, 2022

Conversation

AdamISZ
Copy link
Member

@AdamISZ AdamISZ commented Sep 12, 2022

Fixes #510.
Prior to this commit, if the call to
jmclient.BitcoinCoreInterface.get_current_blockheight() failed and returned None, the function jmclient.WalletService.sync_unspent() would simply ignore the failure and the wallet syncing process would complete, without ever resetting and updating the wallet's utxo set, resulting in a situation where users saw out of date utxo sets in their wallets (and concomitant spending failures).
After this commit, if that blockheight access call fails 5 times, we instead abandon the attempt to sync the wallet, and shut down the application.

@AdamISZ
Copy link
Member Author

AdamISZ commented Sep 12, 2022

I've done some testing and I believe this is functionally correct. There is a slightly suboptimal aspect of each of the effects, on CLI and on Qt, but imo it's fine (since it's such a pain to get everything exactly perfect, and this does the job, and also this is a rare condition).

On CLI it looks like this:

(jmvenv) waxwing@here:~/joinmarket-clientserver/scripts$python wallet-tool.py --datadir=. regtest2.jmdat showutxos
User data location: .
2022-09-12 16:29:35,813 [DEBUG]  rpc: getblockchaininfo []
2022-09-12 16:29:35,815 [DEBUG]  rpc: listwallets []
2022-09-12 16:29:35,816 [DEBUG]  rpc: getwalletinfo []
2022-09-12 16:29:35,822 [DEBUG]  rpc: getnewaddress []
Enter passphrase to decrypt wallet: 
2022-09-12 16:29:42,723 [DEBUG]  rpc: listaddressgroupings []
2022-09-12 16:29:42,805 [INFO]  Detected new wallet, performing initial import
2022-09-12 16:29:42,805 [DEBUG]  requesting detailed wallet history
2022-09-12 16:29:49,656 [DEBUG]  rpc: listlabels []
2022-09-12 16:29:49,657 [DEBUG]  rpc: getaddressesbylabel ['joinmarket-wallet-4729c1']
2022-09-12 16:29:50,266 [DEBUG]  got used indices: {0: [0, 0, 0, 0], 1: [0, 0, 0, 0], 2: [0, 0, 0, 0], 3: [0, 0, 0, 0], 4: [0, 0, 0, 0]}
2022-09-12 16:29:50,483 [DEBUG]  rpc: listlabels []
2022-09-12 16:29:50,485 [DEBUG]  rpc: getaddressesbylabel ['joinmarket-wallet-4729c1']
2022-09-12 16:29:50,494 [DEBUG]  Wallet successfully synced
2022-09-12 16:29:50,497 [ERROR]  Failed to access the current blockheight, and therefore could not sync the wallet. Shutting down.

suboptimal because last two lines contradict, but color coded RED failure message and the fact that it shuts down,is good enough.

And on Qt you get a stack trace after the Qt app shuts down, but only after you got a modal dialog telling you that the RPC call fails, so the user is forced to see the actual reason, the stack trace won't really matter.

for _ in range(5):
current_blockheight = self.bci.get_current_block_height()
if current_blockheight:
break
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we add some delay here maybe? In case bitcoind is temporary not responding, five very fast consecutive calls has higher probability to fail than, let's say, five calls in five seconds.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not a bad idea but I'm worried about doing it synchronously.
There is already a delay where you wait for the RPC call to return (that part of the code is synchronous now).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On second thoughts this is a blocker anyway (and of course, usually not - usually it just works first time), so there's not much reason to not wait before repeating the RPC call.

It feels really bad to put a sleep call in here, but maybe that's the right thing to do?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See 84686b9 . I thought about this for a while and decided: this is a step before the main monitoring loop begins, and it is by design a synchronous operation; I'm not actually sure an extra half second sleep is needed (since we are in any case waiting for the RPC call to return), but, just in case it helps, I added it.

@AdamISZ AdamISZ added the bug label Sep 17, 2022
@AdamISZ
Copy link
Member Author

AdamISZ commented Dec 19, 2022

@kristapsk let me know what to do about the Py3.6 fail (assuming you know!) and also if the above answers your concern about delays. If so, I will merge it.

@kristapsk
Copy link
Member

@kristapsk let me know what to do about the Py3.6 fail (assuming you know!)

You should rebase, it was solved with #1409. Python 3.6 is not available for ubuntu-latest anymore.

if the above answers your concern about delays.

Yes, it's ok with me, minor detail anyway.

@AdamISZ AdamISZ force-pushed the utxo-sync-no-blockheight branch from 84686b9 to 4775689 Compare December 19, 2022 17:43
@AdamISZ
Copy link
Member Author

AdamISZ commented Dec 19, 2022

Huh, weird, I rebased on master (which includes #1409 ) but it is still trying to do py3.6 .

@AdamISZ
Copy link
Member Author

AdamISZ commented Dec 19, 2022

I'm gonna assume it's just a weird CI error and merge and see what happens.

Fixes #510.
Prior to this commit, if the call to
jmclient.BitcoinCoreInterface.get_current_blockheight() failed and
returned None, the function jmclient.WalletService.sync_unspent() would
simply ignore the failure and the wallet syncing process would complete,
without ever resetting and updating the wallet's utxo set, resulting in
a situation where users saw out of date utxo sets in their wallets (and
concomitant spending failures).
After this commit, if that blockheight access call fails 5 times, we
instead abandon the attempt to sync the wallet, and shut down the
application.
@AdamISZ AdamISZ force-pushed the utxo-sync-no-blockheight branch from 4775689 to 0b34e0b Compare December 19, 2022 18:01
@AdamISZ AdamISZ merged commit b1804c0 into master Dec 19, 2022
@AdamISZ AdamISZ deleted the utxo-sync-no-blockheight branch January 23, 2023 14:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

rpc: sendrawtransaction fails with "[MainThread ] [DEBUG] error pushing = -25 Missing inputs"
2 participants