Bitcoin Forum
September 26, 2018, 12:09:40 PM *
News: ♦♦ New info! Bitcoin Core users absolutely must upgrade to previously-announced 0.16.3 [Torrent]. All Bitcoin users should temporarily trust confirmations slightly less. More info.
   Home   Help Search Donate Login Register  
Pages: [1]
Author Topic: Deadlock in key generation due to CCryptoKeyStore  (Read 909 times)
Offline Offline

Activity: 70
Merit: 10

View Profile
August 05, 2011, 03:48:45 PM

This is in the latest version in Git.  This is not in the released client.

Creating a new key can freeze the client.  It appears to be much more frequent when there are blocks and transactions to download.

I've been digging in the code to try and find the cause, and I think this is the reason:

CAddressBookDialog::OnButtonNew grabs the cs_vMasterKey, then calls pwalletMain->GetOrReuseKeyFromPool()
GetOrReuseKeyFromPool() calls ReserveKeyFromKeyPool() which attempts to grab cs_main


ProcessMessages grabs cs_main and then calls ProcessMessage
ProcessMessage() calls SyncWithWallets, either directly when receiving "tx" or indirectly when receiving a block (via ProcessBlock -> AcceptBlock -> AddToBlockIndex -> SetBestChain -> ConnectBlock -> SyncWithWallets)
SyncWithWallets calls AddToWalletIfInvolvingMe
AddToWalletIfInvolvingMe calls CWallet::IsMine, which calls the global ::IsMine
IsMine(const CKeyStore &keystore, const CScript& scriptPubKey) then calls keystore.GetPubKey
CCryptoKeyStore::GetPubKey then grabs cs_vMasterKey


Most of the critical sections protect something small well-defined, though I'm not quite sure what cs_main is supposed to be protecting.

I would generate a pull request, except that
1. I have an ugly hack but not a good fix.  I'm not sure what the final strategy is going to be on wallet encryption, and whether the public keys are going to be encrypted too.
2. I am new to git and I am not yet skilled at rebasing commits to include only the changes I want.
Advertised sites are not endorsed by the Bitcoin Forum. They may be unsafe, untrustworthy, or illegal in your jurisdiction. Advertise here.
Matt Corallo
Hero Member
Offline Offline

Activity: 755
Merit: 501

View Profile
August 05, 2011, 04:32:15 PM

Bitcoin Ubuntu PPA maintainer - donate to me personally: 1JBMattRztKDF2KRS3vhjJXA7h47NEsn2c maintainer
PGP ID: 07DF 3E57 A548 CCFB 7530  7091 89BB B866 3E2E65CE
Pages: [1]
Jump to:  

Sponsored by , a Bitcoin-accepting VPN.
Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!