mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-06-15 00:59:38 +02:00
[wallet] Remove locked_chain from CWallet, its RPCs and tests
This change is intended to make the bitcoin node and its rpc, network and gui interfaces more responsive while the wallet is in use. Currently because the node's cs_main mutex is always locked before the wallet's cs_wallet mutex (to prevent deadlocks), cs_main currently stays locked while the wallet does relatively slow things like creating and listing transactions. This commit only remmove chain lock tacking in wallet code, and invert lock order from cs_main, cs_wallet to cs_wallet, cs_main. must happen at once to avoid any deadlock. Previous commit were only removing Chain::Lock methods to Chain interface and enforcing they take cs_main. Remove LockChain method from CWallet and Chain::Lock interface.
This commit is contained in:
@@ -133,7 +133,6 @@ UniValue importprivkey(const JSONRPCRequest& request)
|
||||
WalletRescanReserver reserver(*pwallet);
|
||||
bool fRescan = true;
|
||||
{
|
||||
auto locked_chain = pwallet->chain().lock();
|
||||
LOCK(pwallet->cs_wallet);
|
||||
|
||||
EnsureWalletIsUnlocked(pwallet);
|
||||
@@ -285,7 +284,6 @@ UniValue importaddress(const JSONRPCRequest& request)
|
||||
fP2SH = request.params[3].get_bool();
|
||||
|
||||
{
|
||||
auto locked_chain = pwallet->chain().lock();
|
||||
LOCK(pwallet->cs_wallet);
|
||||
|
||||
CTxDestination dest = DecodeDestination(request.params[0].get_str());
|
||||
@@ -317,7 +315,6 @@ UniValue importaddress(const JSONRPCRequest& request)
|
||||
{
|
||||
RescanWallet(*pwallet, reserver);
|
||||
{
|
||||
auto locked_chain = pwallet->chain().lock();
|
||||
LOCK(pwallet->cs_wallet);
|
||||
pwallet->ReacceptWalletTransactions();
|
||||
}
|
||||
@@ -361,7 +358,6 @@ UniValue importprunedfunds(const JSONRPCRequest& request)
|
||||
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Something wrong with merkleblock");
|
||||
}
|
||||
|
||||
auto locked_chain = pwallet->chain().lock();
|
||||
LOCK(pwallet->cs_wallet);
|
||||
int height;
|
||||
if (!pwallet->chain().findAncestorByHash(pwallet->GetLastBlockHash(), merkleBlock.header.GetHash(), FoundBlock().height(height))) {
|
||||
@@ -407,7 +403,6 @@ UniValue removeprunedfunds(const JSONRPCRequest& request)
|
||||
},
|
||||
}.Check(request);
|
||||
|
||||
auto locked_chain = pwallet->chain().lock();
|
||||
LOCK(pwallet->cs_wallet);
|
||||
|
||||
uint256 hash(ParseHashV(request.params[0], "txid"));
|
||||
@@ -487,7 +482,6 @@ UniValue importpubkey(const JSONRPCRequest& request)
|
||||
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Pubkey is not a valid public key");
|
||||
|
||||
{
|
||||
auto locked_chain = pwallet->chain().lock();
|
||||
LOCK(pwallet->cs_wallet);
|
||||
|
||||
std::set<CScript> script_pub_keys;
|
||||
@@ -505,7 +499,6 @@ UniValue importpubkey(const JSONRPCRequest& request)
|
||||
{
|
||||
RescanWallet(*pwallet, reserver);
|
||||
{
|
||||
auto locked_chain = pwallet->chain().lock();
|
||||
LOCK(pwallet->cs_wallet);
|
||||
pwallet->ReacceptWalletTransactions();
|
||||
}
|
||||
@@ -557,7 +550,6 @@ UniValue importwallet(const JSONRPCRequest& request)
|
||||
int64_t nTimeBegin = 0;
|
||||
bool fGood = true;
|
||||
{
|
||||
auto locked_chain = pwallet->chain().lock();
|
||||
LOCK(pwallet->cs_wallet);
|
||||
|
||||
EnsureWalletIsUnlocked(pwallet);
|
||||
@@ -700,7 +692,6 @@ UniValue dumpprivkey(const JSONRPCRequest& request)
|
||||
|
||||
LegacyScriptPubKeyMan& spk_man = EnsureLegacyScriptPubKeyMan(*wallet);
|
||||
|
||||
auto locked_chain = pwallet->chain().lock();
|
||||
LOCK2(pwallet->cs_wallet, spk_man.cs_KeyStore);
|
||||
|
||||
EnsureWalletIsUnlocked(pwallet);
|
||||
@@ -756,7 +747,6 @@ UniValue dumpwallet(const JSONRPCRequest& request)
|
||||
// the user could have gotten from another RPC command prior to now
|
||||
wallet.BlockUntilSyncedToCurrentChain();
|
||||
|
||||
auto locked_chain = pwallet->chain().lock();
|
||||
LOCK2(pwallet->cs_wallet, spk_man.cs_KeyStore);
|
||||
|
||||
EnsureWalletIsUnlocked(&wallet);
|
||||
@@ -780,7 +770,7 @@ UniValue dumpwallet(const JSONRPCRequest& request)
|
||||
|
||||
std::map<CKeyID, int64_t> mapKeyBirth;
|
||||
const std::map<CKeyID, int64_t>& mapKeyPool = spk_man.GetAllReserveKeys();
|
||||
pwallet->GetKeyBirthTimes(*locked_chain, mapKeyBirth);
|
||||
pwallet->GetKeyBirthTimes(mapKeyBirth);
|
||||
|
||||
std::set<CScriptID> scripts = spk_man.GetCScripts();
|
||||
|
||||
@@ -1379,7 +1369,6 @@ UniValue importmulti(const JSONRPCRequest& mainRequest)
|
||||
int64_t nLowestTimestamp = 0;
|
||||
UniValue response(UniValue::VARR);
|
||||
{
|
||||
auto locked_chain = pwallet->chain().lock();
|
||||
LOCK(pwallet->cs_wallet);
|
||||
EnsureWalletIsUnlocked(pwallet);
|
||||
|
||||
@@ -1414,7 +1403,6 @@ UniValue importmulti(const JSONRPCRequest& mainRequest)
|
||||
if (fRescan && fRunScan && requests.size()) {
|
||||
int64_t scannedTime = pwallet->RescanFromTime(nLowestTimestamp, reserver, true /* update */);
|
||||
{
|
||||
auto locked_chain = pwallet->chain().lock();
|
||||
LOCK(pwallet->cs_wallet);
|
||||
pwallet->ReacceptWalletTransactions();
|
||||
}
|
||||
@@ -1676,7 +1664,6 @@ UniValue importdescriptors(const JSONRPCRequest& main_request) {
|
||||
bool rescan = false;
|
||||
UniValue response(UniValue::VARR);
|
||||
{
|
||||
auto locked_chain = pwallet->chain().lock();
|
||||
LOCK(pwallet->cs_wallet);
|
||||
EnsureWalletIsUnlocked(pwallet);
|
||||
|
||||
@@ -1705,7 +1692,6 @@ UniValue importdescriptors(const JSONRPCRequest& main_request) {
|
||||
if (rescan) {
|
||||
int64_t scanned_time = pwallet->RescanFromTime(lowest_timestamp, reserver, true /* update */);
|
||||
{
|
||||
auto locked_chain = pwallet->chain().lock();
|
||||
LOCK(pwallet->cs_wallet);
|
||||
pwallet->ReacceptWalletTransactions();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user