Bitcoin Forum
May 07, 2024, 10:12:23 PM *
News: Latest Bitcoin Core release: 27.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: Deadlock in key generation due to CCryptoKeyStore  (Read 1017 times)
vector76 (OP)
Member
**
Offline Offline

Activity: 70
Merit: 18


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

Posts: 1715119943

View Profile Personal Message (Offline)

Ignore
1715119943
Reply with quote  #2

1715119943
Report to moderator
1715119943
Hero Member
*
Offline Offline

Posts: 1715119943

View Profile Personal Message (Offline)

Ignore
1715119943
Reply with quote  #2

1715119943
Report to moderator
1715119943
Hero Member
*
Offline Offline

Posts: 1715119943

View Profile Personal Message (Offline)

Ignore
1715119943
Reply with quote  #2

1715119943
Report to moderator
It is a common myth that Bitcoin is ruled by a majority of miners. This is not true. Bitcoin miners "vote" on the ordering of transactions, but that's all they do. They can't vote to change the network rules.
Advertised sites are not endorsed by the Bitcoin Forum. They may be unsafe, untrustworthy, or illegal in your jurisdiction.
1715119943
Hero Member
*
Offline Offline

Posts: 1715119943

View Profile Personal Message (Offline)

Ignore
1715119943
Reply with quote  #2

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

Activity: 755
Merit: 515


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

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

Bitcoin Core, rust-lightning, http://bitcoinfibre.org etc.
PGP ID: 07DF 3E57 A548 CCFB 7530  7091 89BB B866 3E2E65CE
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!