Bitcoin Forum
December 08, 2016, 06:12:23 PM *
News: Latest stable version of Bitcoin Core: 0.13.1  [Torrent].
 
   Home   Help Search Donate Login Register  
Pages: [1]
  Print  
Author Topic: Deadlock in key generation due to CCryptoKeyStore  (Read 807 times)
vector76
Member
**
Offline Offline

Activity: 70


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

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

Meanwhile..

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

Deadlock.

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.
1481220743
Hero Member
*
Offline Offline

Posts: 1481220743

View Profile Personal Message (Offline)

Ignore
1481220743
Reply with quote  #2

1481220743
Report to moderator
1481220743
Hero Member
*
Offline Offline

Posts: 1481220743

View Profile Personal Message (Offline)

Ignore
1481220743
Reply with quote  #2

1481220743
Report to moderator
1481220743
Hero Member
*
Offline Offline

Posts: 1481220743

View Profile Personal Message (Offline)

Ignore
1481220743
Reply with quote  #2

1481220743
Report to moderator
Advertised sites are not endorsed by the Bitcoin Forum. They may be unsafe, untrustworthy, or illegal in your jurisdiction. Advertise here.
1481220743
Hero Member
*
Offline Offline

Posts: 1481220743

View Profile Personal Message (Offline)

Ignore
1481220743
Reply with quote  #2

1481220743
Report to moderator
1481220743
Hero Member
*
Offline Offline

Posts: 1481220743

View Profile Personal Message (Offline)

Ignore
1481220743
Reply with quote  #2

1481220743
Report to moderator
Matt Corallo
Hero Member
*****
expert
Offline Offline

Activity: 751


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

https://github.com/bitcoin/bitcoin/issues/453

Bitcoin Ubuntu PPA maintainer - donate to me personally: 1JBMattRztKDF2KRS3vhjJXA7h47NEsn2c
http://bitcoinrelaynetwork.org maintainer
PGP ID: 07DF 3E57 A548 CCFB 7530  7091 89BB B866 3E2E65CE
Pages: [1]
  Print  
 
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!