Skip to content

Commit

Permalink
Merge #12639: Reduce cs_main lock and avoid extra lookups of mapAddre…
Browse files Browse the repository at this point in the history
…ssBook in listunspent RPC

Summary:
Reduce cs_main lock in listunspent and refactor replacing three `mapAddressBook` lookups with one.

Backport of Core PR12639
bitcoin/bitcoin#12639

Test Plan:
  ../configure --enable-debug
  make check
  test_runner.py

Reviewers: deadalnix, Fabien, jasonbcox, O1 Bitcoin ABC, #bitcoin_abc

Reviewed By: deadalnix, O1 Bitcoin ABC, #bitcoin_abc

Differential Revision: https://reviews.bitcoinabc.org/D4516
  • Loading branch information
promag authored and jonspock committed Oct 10, 2020
1 parent 1a75394 commit 48cb79b
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions src/wallet/rpcwallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3971,12 +3971,13 @@ static UniValue listunspent(const Config &config,
std::vector<COutput> vecOutputs;
{
auto locked_chain = pwallet->chain().lock();
LOCK(pwallet->cs_wallet);
LOCK2(cs_main, pwallet->cs_wallet);
pwallet->AvailableCoins(*locked_chain, vecOutputs, !include_unsafe, nullptr,
nMinimumAmount, nMaximumAmount, nMinimumSumAmount,
nMaximumCount, nMinDepth, nMaxDepth);
}

LOCK(pwallet->cs_wallet);

for (const COutput &out : vecOutputs) {
CTxDestination address;
const CScript &scriptPubKey = out.tx->tx->vout[out.i].scriptPubKey;
Expand All @@ -3994,9 +3995,12 @@ static UniValue listunspent(const Config &config,
if (fValidAddress) {
entry.pushKV("address", EncodeDestination(address));

if (pwallet->mapAddressBook.count(address)) {
entry.pushKV("label", pwallet->mapAddressBook[address].name);
entry.pushKV("account", pwallet->mapAddressBook[address].name);
auto i = pwallet->mapAddressBook.find(address);
if (i != pwallet->mapAddressBook.end()) {
entry.pushKV("label", i->second.name);
if (IsDeprecatedRPCEnabled(gArgs, "accounts")) {
entry.pushKV("account", i->second.name);
}
}

if (scriptPubKey.IsPayToScriptHash()) {
Expand Down

0 comments on commit 48cb79b

Please sign in to comment.