From 10869fff3b2cb7af5c4880c45e63bd85adec6084 Mon Sep 17 00:00:00 2001 From: Konstantin Akimov Date: Tue, 30 Apr 2024 01:18:00 +0700 Subject: [PATCH] fix: order of locks cs_wallet and cs_main in rpc/evo It also reduce scope of both locks --- src/rpc/evo.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/rpc/evo.cpp b/src/rpc/evo.cpp index 592600bf19..df6ab7d831 100644 --- a/src/rpc/evo.cpp +++ b/src/rpc/evo.cpp @@ -1372,7 +1372,6 @@ static UniValue protx_list(const JSONRPCRequest& request, CDeterministicMNManage throw std::runtime_error("\"protx list wallet\" not supported when wallet is disabled"); } #ifdef ENABLE_WALLET - LOCK2(wallet->cs_wallet, cs_main); if (request.params.size() > 4) { protx_list_help(request); @@ -1380,6 +1379,7 @@ static UniValue protx_list(const JSONRPCRequest& request, CDeterministicMNManage bool detailed = !request.params[1].isNull() ? ParseBoolV(request.params[1], "detailed") : false; + LOCK2(wallet->cs_wallet, cs_main); int height = !request.params[2].isNull() ? ParseInt32V(request.params[2], "height") : chainman.ActiveChain().Height(); if (height < 1 || height > chainman.ActiveChain().Height()) { throw JSONRPCError(RPC_INVALID_PARAMETER, "invalid height specified"); @@ -1408,10 +1408,13 @@ static UniValue protx_list(const JSONRPCRequest& request, CDeterministicMNManage protx_list_help(request); } - LOCK(cs_main); - bool detailed = !request.params[1].isNull() ? ParseBoolV(request.params[1], "detailed") : false; +#ifdef ENABLE_WALLET + LOCK2(wallet ? wallet->cs_wallet : cs_main, cs_main); +#else + LOCK(cs_main); +#endif int height = !request.params[2].isNull() ? ParseInt32V(request.params[2], "height") : chainman.ActiveChain().Height(); if (height < 1 || height > chainman.ActiveChain().Height()) { throw JSONRPCError(RPC_INVALID_PARAMETER, "invalid height specified");