Make console line edit disable by default, and only enable once RPCConsole::setClientModel is called.
Fixes #16119.
A long term alternative is to move this rescan after the initialization? /cc @ryanofsky
Since the rescan loop doesn’t hold onto cs_main anymore, I’d expect that RPC commands could work during a rescan, and don’t understand exactly what problem causes this crash, and what problem causes bitcoin-cli not to work right now.
Longer term, I think the main thing that needs to happen is for the rescan loop to move out of the wallet into the node (src/node/rescan.cpp or someplace like that) so when multiple wallets are loaded they are all rescanned in parallel instead of sequentially one after another other. I expect the way that would work is that during loading, each wallet would asynchronously request a rescan from the node, passing it a locator. Then after all the wallets are loaded, the node would do a single rescan from the earliest point, sending wallets the normal notifications.
In terms of implementation I would build this on top of #15719 by adding a CBlockLocator argument to Chain::requestNotifications()Chain::handleNotifications(). There would also need to be explicit requestRescan/abortRescan Chain methods to trigger rescans after wallets are loaded, for when users import keys or explicity request rescans.
and what problem causes bitcoin-cli not to work right now.
Because the server gives RPC_IN_WARMUP:
0src/bitcoin-cli -regtest help
1error code: -28
2error message:
3Rescanning...
don’t understand exactly what problem causes this crash
Because  autoCompleter is null here:
https://github.com/bitcoin/bitcoin/blob/727143b65cdb801a0b755cb8b3aff97da5fe8f27/src/qt/rpcconsole.cpp#L535
I think the main thing that needs to happen is for the rescan loop to move out of the wallet into the node
This would go away right? https://github.com/bitcoin/bitcoin/blob/c7cfd20a77ce57d200b3b9e5e0dfb0d63818abdc/src/walletinitinterface.h#L22-L23
676@@ -677,6 +677,7 @@ void RPCConsole::setClientModel(ClientModel *model)
677         wordList.sort();
678         autoCompleter = new QCompleter(wordList, this);
679         autoCompleter->setModelSorting(QCompleter::CaseSensitivelySortedModel);
680+        ui->lineEdit->setEnabled(true);
utACK 727143b65cdb801a0b755cb8b3aff97da5fe8f27
Thanks for the explanations.
This would go away right?
I think adding a CBlockLocator argument to handleNotifications (sorry I mistakenly wrote requestNotifications before) should be the only init interface change needed for simultaneous rescanning.
The WalletInitInterface::Construct call shouldn’t be affected and isn’t directly involved in loading wallets. The Construct method is only responsible for parsing -wallet and -disablewallet options and constructing WalletClientImpl objects. Wallet loading happens later when WalletClientImpl::load is called.
tACK https://github.com/bitcoin/bitcoin/pull/16122/commits/2d8ad2f99710a8981e33fe2d6ce834b0076c4e80 on macOS.
Using master (c7cfd20a77ce57d200b3b9e5e0dfb0d63818abdc) it’s possible to cause a crash during startup by opening Window -> Console typing anything into the console and hitting enter.
 0lldb Bitcoin-Qt.app
 1(lldb) target create "Bitcoin-Qt.app"
 2Current executable set to 'Bitcoin-Qt.app' (x86_64).
 3(lldb) run
 4Process 59937 launched: '/Users/michael/github/bitcoin/Bitcoin-Qt.app/Contents/MacOS/Bitcoin-Qt' (x86_64)
 52019-05-31 09:53:29.580881-0400 Bitcoin-Qt[59937:3647765] MessageTracer: Falling back to default whitelist
 6Process 59937 stopped
 7* thread [#1](/bitcoin-bitcoin/1/), name = 'bitcoin-main', queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS (code=1, address=0x8)
 8    frame [#0](/bitcoin-bitcoin/0/): 0x00000001011a78ba QtWidgets`QCompleter::popup() const + 10
 9QtWidgets`QCompleter::popup:
10->  0x1011a78ba <+10>: movq   0x8(%rdi), %rbx
11    0x1011a78be <+14>: movq   0x88(%rbx), %rax
12    0x1011a78c5 <+21>: testq  %rax, %rax
13    0x1011a78c8 <+24>: jne    0x1011a7942               ; <+146>
14Target 0: (Bitcoin-Qt) stopped.
Using this PR (https://github.com/bitcoin/bitcoin/pull/16122/commits/2d8ad2f99710a8981e33fe2d6ce834b0076c4e80), it’s still possible to get to the console during startup, but it’s impossible to enter or execute any commands. The console is enabled when startup completes.