Skip to content

Commit 2a30e67

Browse files
author
MarcoFalke
committed
Merge #12330: Reduce scope of cs_main and cs_wallet locks in listtransactions
c409b1a [rpc] Reduce scope of cs_main and cs_wallet locks in listtransactions (João Barbosa) Pull request description: Trivial change, no behaviour change. Benchmark done as follow: - run with `-regtest` - wallet with 5000 transactions - measured the time spent with the lock and the total time - times are an average of 100 `listtransactions --count=...` calls | `--count` | lock (ms) | total (ms) | saving | |--:|--:|--:|--:| | 10 | 0.2230 | 0.2510 | 11% | | 100 | 2.5150 | 2.8690 | 12% | | 1000 | 20.0320 | 23.3490 | 14% | | 10000 | 105.2070 | 125.5310 | 16% | Tree-SHA512: ebedfeeb4c8ad75c89128e53cae976a82967dbb5ffd129da0f7204ccf9c3c15070b3d509f3767bebd745512e410200cc546147c836e82409f95fc9b8d14fc3ed
2 parents d32528e + c409b1a commit 2a30e67

File tree

1 file changed

+16
-13
lines changed

1 file changed

+16
-13
lines changed

src/wallet/rpcwallet.cpp

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1794,8 +1794,6 @@ UniValue listtransactions(const JSONRPCRequest& request)
17941794
// the user could have gotten from another RPC command prior to now
17951795
pwallet->BlockUntilSyncedToCurrentChain();
17961796

1797-
LOCK2(cs_main, pwallet->cs_wallet);
1798-
17991797
std::string strAccount = "*";
18001798
if (!request.params[0].isNull())
18011799
strAccount = request.params[0].get_str();
@@ -1817,20 +1815,25 @@ UniValue listtransactions(const JSONRPCRequest& request)
18171815

18181816
UniValue ret(UniValue::VARR);
18191817

1820-
const CWallet::TxItems & txOrdered = pwallet->wtxOrdered;
1821-
1822-
// iterate backwards until we have nCount items to return:
1823-
for (CWallet::TxItems::const_reverse_iterator it = txOrdered.rbegin(); it != txOrdered.rend(); ++it)
18241818
{
1825-
CWalletTx *const pwtx = (*it).second.first;
1826-
if (pwtx != nullptr)
1827-
ListTransactions(pwallet, *pwtx, strAccount, 0, true, ret, filter);
1828-
CAccountingEntry *const pacentry = (*it).second.second;
1829-
if (pacentry != nullptr)
1830-
AcentryToJSON(*pacentry, strAccount, ret);
1819+
LOCK2(cs_main, pwallet->cs_wallet);
1820+
1821+
const CWallet::TxItems & txOrdered = pwallet->wtxOrdered;
18311822

1832-
if ((int)ret.size() >= (nCount+nFrom)) break;
1823+
// iterate backwards until we have nCount items to return:
1824+
for (CWallet::TxItems::const_reverse_iterator it = txOrdered.rbegin(); it != txOrdered.rend(); ++it)
1825+
{
1826+
CWalletTx *const pwtx = (*it).second.first;
1827+
if (pwtx != nullptr)
1828+
ListTransactions(pwallet, *pwtx, strAccount, 0, true, ret, filter);
1829+
CAccountingEntry *const pacentry = (*it).second.second;
1830+
if (pacentry != nullptr)
1831+
AcentryToJSON(*pacentry, strAccount, ret);
1832+
1833+
if ((int)ret.size() >= (nCount+nFrom)) break;
1834+
}
18331835
}
1836+
18341837
// ret is newest to oldest
18351838

18361839
if (nFrom > (int)ret.size())

0 commit comments

Comments
 (0)