As discussed in last week’s meeting. The failures are annoying.
I’m sure that this isn’t the best approach, but these rpcs seem generally useful, and I believe this fixes the current race issue.
The problem is that the wallet is not yet finished dealing with transactions before getblockcount/getbestblockhash return new values, so assertions about balances are racy. The approach I’ve taken here is to wait for a signal that the processing is complete, then cache the new height/hash on the rpc side. That allows for blocking in the call rather than polling, and it ensures that we’re synced up before it returns. It also means no cs_main locking.
To fix sync_blocks in particular, wait for height 0 from all nodes. That returns the current height/hash instantly, since it should never actually have to wait. Then, grab the current height from all nodes, take the max, and wait on that height for all nodes. Repeat until all heights match. @sdaftuar Mentioned that it may be useful to a wait_for_wallet() call, which would presumably work similarly, though I’m afraid it may introduce new race issues. Suggestions on that approach are also welcome.