From 37aa4f18273fee4d2ba40d3f9506a7f576a6bf43 Mon Sep 17 00:00:00 2001 From: Miguel Freitas Date: Mon, 18 Nov 2013 10:51:23 -0200 Subject: [PATCH] rework locking in getinfo to fix deadlock --- src/bitcoinrpc.cpp | 6 +++--- src/rpcwallet.cpp | 25 +++++++++++++++++-------- src/twister.cpp | 2 -- 3 files changed, 20 insertions(+), 13 deletions(-) diff --git a/src/bitcoinrpc.cpp b/src/bitcoinrpc.cpp index 34234cc8..87d1777a 100644 --- a/src/bitcoinrpc.cpp +++ b/src/bitcoinrpc.cpp @@ -210,7 +210,7 @@ static const CRPCCommand vRPCCommands[] = { "getgenerate", &getgenerate, true, false }, { "setgenerate", &setgenerate, true, false }, { "gethashespersec", &gethashespersec, true, false }, - { "getinfo", &getinfo, true, false }, + { "getinfo", &getinfo, true, true }, { "getmininginfo", &getmininginfo, true, false }, { "createwalletuser", &createwalletuser, true, false }, { "listwalletusers", &listwalletusers, true, false }, @@ -249,8 +249,8 @@ static const CRPCCommand vRPCCommands[] = { "newrtmsg", &newrtmsg, false, true }, { "getposts", &getposts, false, true }, { "getdirectmsgs", &getdirectmsgs, false, true }, - { "setspammsg", &setspammsg, false, true }, - { "getspammsg", &getspammsg, false, true }, + { "setspammsg", &setspammsg, false, false }, + { "getspammsg", &getspammsg, false, false }, { "follow", &follow, false, true }, { "unfollow", &unfollow, false, true }, { "getfollowing", &getfollowing, false, true }, diff --git a/src/rpcwallet.cpp b/src/rpcwallet.cpp index f0411058..b562ede2 100644 --- a/src/rpcwallet.cpp +++ b/src/rpcwallet.cpp @@ -77,16 +77,25 @@ Value getinfo(const Array& params, bool fHelp) obj.push_back(Pair("walletversion", pwalletMain->GetVersion())); obj.push_back(Pair("blocks", (int)nBestHeight)); obj.push_back(Pair("timeoffset", (boost::int64_t)GetTimeOffset())); - obj.push_back(Pair("connections", (int)vNodes.size())); + { + LOCK(cs_main); + obj.push_back(Pair("connections", (int)vNodes.size())); + obj.push_back(Pair("addrman_total", (int)addrman.size())); + obj.push_back(Pair("addrman_get", (int)addrman.GetAddr().size())); + } obj.push_back(Pair("dht_nodes", getDhtNodes())); - obj.push_back(Pair("addrman_total", (int)addrman.size())); - obj.push_back(Pair("addrman_get", (int)addrman.GetAddr().size())); obj.push_back(Pair("proxy", (proxy.first.IsValid() ? proxy.first.ToStringIPPort() : string()))); - obj.push_back(Pair("difficulty", (double)GetDifficulty())); - obj.push_back(Pair("testnet", TestNet())); - if (pwalletMain->IsCrypted()) - obj.push_back(Pair("unlocked_until", (boost::int64_t)nWalletUnlockTime)); - obj.push_back(Pair("errors", GetWarnings("statusbar"))); + { + LOCK(cs_main); + obj.push_back(Pair("difficulty", (double)GetDifficulty())); + obj.push_back(Pair("testnet", TestNet())); + { + LOCK(pwalletMain->cs_wallet); + if (pwalletMain->IsCrypted()) + obj.push_back(Pair("unlocked_until", (boost::int64_t)nWalletUnlockTime)); + } + obj.push_back(Pair("errors", GetWarnings("statusbar"))); + } return obj; } diff --git a/src/twister.cpp b/src/twister.cpp index 87fbfd2d..287c4251 100644 --- a/src/twister.cpp +++ b/src/twister.cpp @@ -1542,7 +1542,6 @@ Value setspammsg(const Array& params, bool fHelp) string strUsername = params[0].get_str(); string strMsg = params[1].get_str(); - LOCK(cs_main); strSpamUser = strUsername; strSpamMessage = strMsg; @@ -1557,7 +1556,6 @@ Value getspammsg(const Array& params, bool fHelp) "get spam message attached to generated blocks"); Array ret; - LOCK(cs_main); ret.push_back(strSpamUser); ret.push_back(strSpamMessage);