Skip to content

Commit c409b1a

Browse files
committed
[rpc] Reduce scope of cs_main and cs_wallet locks in listtransactions
1 parent 41363fe commit c409b1a

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)