Add new 'consensus_info' RPC command to help troubleshoot consensus convergence issues.

This commit is contained in:
JoelKatz
2013-02-09 14:21:57 -08:00
parent b417ff4ef1
commit 18167be5e3
7 changed files with 123 additions and 3 deletions

View File

@@ -499,6 +499,7 @@ Json::Value RPCParser::parseCommand(std::string strMethod, Json::Value jvParams)
{ "account_offers", &RPCParser::parseAccountItems, 1, 2 },
{ "account_tx", &RPCParser::parseAccountTransactions, 2, 3 },
{ "connect", &RPCParser::parseConnect, 1, 2 },
{ "consensus_info", &RPCParser::parseAsIs, 0, 0 },
{ "get_counts", &RPCParser::parseGetCounts, 0, 1 },
{ "ledger", &RPCParser::parseLedger, 0, 2 },
{ "ledger_accept", &RPCParser::parseAsIs, 0, 0 },

View File

@@ -267,6 +267,26 @@ bool LCTransaction::updateVote(int percentTime, bool proposing)
return true;
}
Json::Value LCTransaction::getJson()
{
Json::Value ret(Json::objectValue);
ret["yays"] = mYays;
ret["nays"] = mNays;
ret["our_vote"] = mOurVote;
if (!mVotes.empty())
{
Json::Value votesj(Json::objectValue);
typedef boost::unordered_map<uint160, bool>::value_type vt;
BOOST_FOREACH(vt& vote, mVotes)
{
votesj[vote.first.GetHex()] = vote.second;
}
ret["votes"] = votesj;
}
return ret;
}
LedgerConsensus::LedgerConsensus(const uint256& prevLCLHash, Ledger::ref previousLedger, uint32 closeTime)
: mState(lcsPRE_CLOSE), mCloseTime(closeTime), mPrevLedgerHash(prevLCLHash), mPreviousLedger(previousLedger),
mValPublic(theConfig.VALIDATION_PUB), mValPrivate(theConfig.VALIDATION_PRIV), mConsensusFail(false),
@@ -1363,7 +1383,7 @@ void LedgerConsensus::simulate()
cLog(lsINFO) << "Simulation complete";
}
Json::Value LedgerConsensus::getJson()
Json::Value LedgerConsensus::getJson(bool full)
{
Json::Value ret(Json::objectValue);
ret["proposing"] = mProposing;
@@ -1388,12 +1408,88 @@ Json::Value LedgerConsensus::getJson()
}
int v = mDisputes.size();
if (v != 0)
if ((v != 0) && !full)
ret["disputes"] = v;
if (mOurPosition)
ret["our_position"] = mOurPosition->getJson();
if (full)
{
ret["current_ms"] = mCurrentMSeconds;
ret["close_percent"] = mClosePercent;
ret["close_resolution"] = mCloseResolution;
ret["have_time_consensus"] = mHaveCloseTimeConsensus;
ret["previous_proposers"] = mPreviousProposers;
ret["previous_mseconds"] = mPreviousMSeconds;
if (!mPeerPositions.empty())
{
typedef boost::unordered_map<uint160, LedgerProposal::pointer>::value_type pp_t;
Json::Value ppj(Json::objectValue);
BOOST_FOREACH(pp_t& pp, mPeerPositions)
{
ppj[pp.first.GetHex()] = pp.second->getJson();
}
ret["peer_positions"] = ppj;
}
if (!mAcquired.empty())
{ // acquired
typedef boost::unordered_map<uint256, SHAMap::pointer>::value_type ac_t;
Json::Value acq(Json::arrayValue);
BOOST_FOREACH(ac_t& at, mAcquired)
{
acq.append(at.first.GetHex());
}
ret["acquired"] = acq;
}
if (!mAcquiring.empty())
{
typedef boost::unordered_map<uint256, TransactionAcquire::pointer>::value_type ac_t;
Json::Value acq(Json::arrayValue);
BOOST_FOREACH(ac_t& at, mAcquiring)
{
acq.append(at.first.GetHex());
}
ret["acquiring"] = acq;
}
if (!mDisputes.empty())
{
typedef boost::unordered_map<uint256, LCTransaction::pointer>::value_type d_t;
Json::Value dsj(Json::objectValue);
BOOST_FOREACH(d_t& dt, mDisputes)
{
dsj[dt.first.GetHex()] = dt.second->getJson();
}
ret["disputes"] = dsj;
}
if (!mCloseTimes.empty())
{
typedef std::map<uint32, int>::value_type ct_t;
Json::Value ctj(Json::objectValue);
BOOST_FOREACH(ct_t& ct, mCloseTimes)
{
ctj[boost::lexical_cast<std::string>(ct.first)] = ct.second;
}
ret["close_times"] = ctj;
}
if (!mDeadNodes.empty())
{
Json::Value dnj(Json::arrayValue);
BOOST_FOREACH(const uint160& dn, mDeadNodes)
{
dnj.append(dn.GetHex());
}
ret["dead_nodes"] = dnj;
}
}
return ret;
}

View File

@@ -75,6 +75,7 @@ public:
void unVote(const uint160& peer);
bool updateVote(int percentTime, bool proposing);
Json::Value getJson();
};
enum LCState
@@ -161,7 +162,7 @@ public:
LedgerConsensus(const uint256& prevLCLHash, Ledger::ref previousLedger, uint32 closeTime);
int startup();
Json::Value getJson();
Json::Value getJson(bool full);
Ledger::ref peekPreviousLedger() { return mPreviousLedger; }
uint256 getLCL() { return mPrevLedgerHash; }

View File

@@ -1106,6 +1106,16 @@ bool NetworkOPs::recvValidation(const SerializedValidation::pointer& val)
return theApp->getValidations().addValidation(val);
}
Json::Value NetworkOPs::getConsensusInfo()
{
if (mConsensus)
return mConsensus->getJson(true);
Json::Value info = Json::objectValue;
info["consensus"] = "none";
return info;
}
Json::Value NetworkOPs::getServerInfo(bool human, bool admin)
{
Json::Value info = Json::objectValue;

View File

@@ -250,6 +250,7 @@ public:
int getPreviousConvergeTime() { return mLastCloseConvergeTime; }
uint32 getLastCloseTime() { return mLastCloseTime; }
void setLastCloseTime(uint32 t) { mLastCloseTime = t; }
Json::Value getConsensusInfo();
Json::Value getServerInfo(bool human, bool admin);
uint32 acceptLedger();
boost::unordered_map<uint160,

View File

@@ -1343,6 +1343,15 @@ Json::Value RPCHandler::doSubmit(Json::Value jvRequest)
}
}
Json::Value RPCHandler::doConsensusInfo(Json::Value)
{
Json::Value ret(Json::objectValue);
ret["info"] = theApp->getOPs().getConsensusInfo();
return ret;
}
Json::Value RPCHandler::doServerInfo(Json::Value)
{
Json::Value ret(Json::objectValue);
@@ -2682,6 +2691,7 @@ Json::Value RPCHandler::doCommand(const Json::Value& jvRequest, int iRole)
{ "account_offers", &RPCHandler::doAccountOffers, false, optCurrent },
{ "account_tx", &RPCHandler::doAccountTransactions, false, optNetwork },
{ "connect", &RPCHandler::doConnect, true, optNone },
{ "consensus_info", &RPCHandler::doConsensusInfo, true, optNone },
{ "get_counts", &RPCHandler::doGetCounts, true, optNone },
{ "internal", &RPCHandler::doInternal, true, optNone },
{ "ledger", &RPCHandler::doLedger, false, optNetwork },

View File

@@ -50,6 +50,7 @@ class RPCHandler
Json::Value doAccountOffers(Json::Value params);
Json::Value doAccountTransactions(Json::Value params);
Json::Value doConnect(Json::Value params);
Json::Value doConsensusInfo(Json::Value params);
#if ENABLE_INSECURE
Json::Value doDataDelete(Json::Value params);
Json::Value doDataFetch(Json::Value params);