Browse Source

rework locking in getinfo to fix deadlock

miguelfreitas
Miguel Freitas 11 years ago
parent
commit
37aa4f1827
  1. 6
      src/bitcoinrpc.cpp
  2. 25
      src/rpcwallet.cpp
  3. 2
      src/twister.cpp

6
src/bitcoinrpc.cpp

@ -210,7 +210,7 @@ static const CRPCCommand vRPCCommands[] =
{ "getgenerate", &getgenerate, true, false }, { "getgenerate", &getgenerate, true, false },
{ "setgenerate", &setgenerate, true, false }, { "setgenerate", &setgenerate, true, false },
{ "gethashespersec", &gethashespersec, true, false }, { "gethashespersec", &gethashespersec, true, false },
{ "getinfo", &getinfo, true, false }, { "getinfo", &getinfo, true, true },
{ "getmininginfo", &getmininginfo, true, false }, { "getmininginfo", &getmininginfo, true, false },
{ "createwalletuser", &createwalletuser, true, false }, { "createwalletuser", &createwalletuser, true, false },
{ "listwalletusers", &listwalletusers, true, false }, { "listwalletusers", &listwalletusers, true, false },
@ -249,8 +249,8 @@ static const CRPCCommand vRPCCommands[] =
{ "newrtmsg", &newrtmsg, false, true }, { "newrtmsg", &newrtmsg, false, true },
{ "getposts", &getposts, false, true }, { "getposts", &getposts, false, true },
{ "getdirectmsgs", &getdirectmsgs, false, true }, { "getdirectmsgs", &getdirectmsgs, false, true },
{ "setspammsg", &setspammsg, false, true }, { "setspammsg", &setspammsg, false, false },
{ "getspammsg", &getspammsg, false, true }, { "getspammsg", &getspammsg, false, false },
{ "follow", &follow, false, true }, { "follow", &follow, false, true },
{ "unfollow", &unfollow, false, true }, { "unfollow", &unfollow, false, true },
{ "getfollowing", &getfollowing, false, true }, { "getfollowing", &getfollowing, false, true },

25
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("walletversion", pwalletMain->GetVersion()));
obj.push_back(Pair("blocks", (int)nBestHeight)); obj.push_back(Pair("blocks", (int)nBestHeight));
obj.push_back(Pair("timeoffset", (boost::int64_t)GetTimeOffset())); 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("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("proxy", (proxy.first.IsValid() ? proxy.first.ToStringIPPort() : string())));
obj.push_back(Pair("difficulty", (double)GetDifficulty())); {
obj.push_back(Pair("testnet", TestNet())); LOCK(cs_main);
if (pwalletMain->IsCrypted()) obj.push_back(Pair("difficulty", (double)GetDifficulty()));
obj.push_back(Pair("unlocked_until", (boost::int64_t)nWalletUnlockTime)); obj.push_back(Pair("testnet", TestNet()));
obj.push_back(Pair("errors", GetWarnings("statusbar"))); {
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; return obj;
} }

2
src/twister.cpp

@ -1542,7 +1542,6 @@ Value setspammsg(const Array& params, bool fHelp)
string strUsername = params[0].get_str(); string strUsername = params[0].get_str();
string strMsg = params[1].get_str(); string strMsg = params[1].get_str();
LOCK(cs_main);
strSpamUser = strUsername; strSpamUser = strUsername;
strSpamMessage = strMsg; strSpamMessage = strMsg;
@ -1557,7 +1556,6 @@ Value getspammsg(const Array& params, bool fHelp)
"get spam message attached to generated blocks"); "get spam message attached to generated blocks");
Array ret; Array ret;
LOCK(cs_main);
ret.push_back(strSpamUser); ret.push_back(strSpamUser);
ret.push_back(strSpamMessage); ret.push_back(strSpamMessage);

Loading…
Cancel
Save