Skip to content

Conversation

TheBlueMatt
Copy link
Contributor

This fixes #9148, though with a bit more code than I intended.

There were two issues: a) wallet could return data based on partial block processing, because there were no locks between SyncTransaction calls, which is fixed relatively easily. and b) you could be busy-waiting on getbestblockheight , and call getbalance immediately after that changed, getting your balance as of the previous block instead of the new one, which is a regression in master from 0.13.

To resolve the second, we introduce a primitive to block until the wallet has caught up either with the current chain, or the best chain (to resolve a simple race condition).

This should probably get a test case, because I know you can see a in simple tests, but I'm not 100% sure about b.

@TheBlueMatt TheBlueMatt force-pushed the 2017-01-fix-wallet-rpc-stale branch 4 times, most recently from cbf8fb9 to 4ec00df Compare January 18, 2017 00:18
This simplifies fixing bitcoin#9148 as we can now hold cs_wallet across
an entire block instead of only per-tx.

This change also removes the NOT_IN_BLOCK constant in favor of only
passing the CBlockIndex* parameter to SyncTransactions when a new
block is being connected, instead of also when a block is being
disconnected.
@TheBlueMatt TheBlueMatt force-pushed the 2017-01-fix-wallet-rpc-stale branch 5 times, most recently from 3ccf3d4 to 9010f29 Compare January 18, 2017 01:18
This removes another callback from block connection logic, one more
step towards fixing bitcoin#9148.

Note that this does a full mapWallet loop after the first block
which is connected after restart. This is due to a previous bug
where a coinbase transaction from the current best tip which
existed in wallet immediately prior to restart would not be shown
in the GUI except because on-load -checkblocks would call
DisconnectBlock and ConnectBlock on the current tip. To avoid
making it worse (ie that such transactions would never be displayed
until restart), a scan to find such transactions was added.
@TheBlueMatt TheBlueMatt force-pushed the 2017-01-fix-wallet-rpc-stale branch from 9010f29 to 593a8f1 Compare January 18, 2017 01:41
@TheBlueMatt
Copy link
Contributor Author

@morcos points out that the cs_main holding at for the block's transaction's processing loop might interfere with all the fancy new fast block-response networking stuff we have going in 0.14. Sadly, because cs_main must come before cs_wallet, this isnt trivial to fix.

One easy fix is to add another cs_wallet - cs_wallet_before_main which is locked here to emulate the behavior prior to the lock split in #7946.

@TheBlueMatt
Copy link
Contributor Author

Thinking about it more, most of those things will not be running at that time anyway, because we only have one message processing thread. This may have adverse effects on miners who run with a wallet, but aside from that I dont think there is really all that much cs_main contention here (and certainly wouldn't be a regression from 0.13). We can add a cs_wallet_before_main when we split message processing thread.

@TheBlueMatt TheBlueMatt force-pushed the 2017-01-fix-wallet-rpc-stale branch from 887291d to da28613 Compare January 18, 2017 21:16
@TheBlueMatt TheBlueMatt mentioned this pull request Jan 18, 2017
@laanwj laanwj added this to the 0.14.0 milestone Jan 19, 2017
@morcos
Copy link
Contributor

morcos commented Jan 19, 2017

utACK?

I think the code is right, but I wish there were a bit more straightforward way of doing this.

@TheBlueMatt
Copy link
Contributor Author

Closing in favor of #9583 for 0.14. Will open a new PR with a bigger set of changes that also addresses the concerns in #9584.

@bitcoin bitcoin locked as resolved and limited conversation to collaborators Sep 8, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Wallet RPCs can return stale info due to ProcessNewBlock Race
4 participants