Skip to content

Commit

Permalink
Merge pull request #911 from MonsieurNicolas/scpVerbose
Browse files Browse the repository at this point in the history
scp info endpoint improvements

Reviewed-by: jedmccaleb
  • Loading branch information
latobarita committed Nov 5, 2015
2 parents 924ad4b + e706bd6 commit 5167ebe
Show file tree
Hide file tree
Showing 8 changed files with 45 additions and 13 deletions.
3 changes: 2 additions & 1 deletion docs/learn/commands.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,8 @@ debugging purpose).
The actual deletion is performed by invoking the `maintenance` endpoint.

* **scp**
Returns a JSON object with the internal state of the SCP engine.
`/scp?[limit=n]
Returns a JSON object with the internal state of the SCP engine for the last n (default 2) ledgers.

* **tx**
`/tx?blob=Base64`<br>
Expand Down
2 changes: 1 addition & 1 deletion src/herder/Herder.h
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ class Herder
{
}

virtual void dumpInfo(Json::Value& ret) = 0;
virtual void dumpInfo(Json::Value& ret, size_t limit) = 0;
virtual void dumpQuorumInfo(Json::Value& ret, NodeID const& id,
bool summary, uint64 index = 0) = 0;
};
Expand Down
4 changes: 2 additions & 2 deletions src/herder/HerderImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1473,11 +1473,11 @@ HerderImpl::acceptedCommit(uint64 slotIndex, SCPBallot const& ballot)
}

void
HerderImpl::dumpInfo(Json::Value& ret)
HerderImpl::dumpInfo(Json::Value& ret, size_t limit)
{
ret["you"] = mApp.getConfig().toStrKey(mSCP.getSecretKey().getPublicKey());

mSCP.dumpInfo(ret);
mSCP.dumpInfo(ret, limit);

mPendingEnvelopes.dumpInfo(ret);
}
Expand Down
2 changes: 1 addition & 1 deletion src/herder/HerderImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ class HerderImpl : public Herder, public SCPDriver

bool resolveNodeID(std::string const& s, PublicKey& retKey) override;

void dumpInfo(Json::Value& ret) override;
void dumpInfo(Json::Value& ret, size_t limit) override;
void dumpQuorumInfo(Json::Value& ret, NodeID const& id, bool summary,
uint64 index) override;

Expand Down
21 changes: 18 additions & 3 deletions src/main/CommandHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -281,8 +281,9 @@ CommandHandler::fileNotFound(std::string const& params, std::string& retStr)
" default). NODE_ID is either a full key (`GABCD...`), an alias "
"(`$name`) or an abbreviated ID(`@GABCD`)."
"If compact is set, only returns a summary version."
"</p><p><h1> /scp</h1>"
"returns a JSON object with the internal state of the SCP engine"
"</p><p><h1> /scp?[limit=n]</h1>"
"returns a JSON object with the internal state of the SCP engine for "
"the last n (default 2) ledgers."
"</p><p><h1> /tx?blob=HEX</h1>"
"submit a transaction to the network.<br>"
"blob is a hex encoded XDR serialized 'TransactionEnvelope'<br>"
Expand Down Expand Up @@ -632,7 +633,21 @@ CommandHandler::scpInfo(std::string const& params, std::string& retStr)
{
Json::Value root;

mApp.getHerder().dumpInfo(root);
std::map<std::string, std::string> retMap;
http::server::server::parseParams(params, retMap);

size_t lim = 2;
std::string limStr = retMap["limit"];
if (!limStr.empty())
{
size_t n = strtoul(limStr.c_str(), NULL, 0);
if (n != 0)
{
lim = n;
}
}

mApp.getHerder().dumpInfo(root, lim);

retStr = root.toStyledString();
}
Expand Down
8 changes: 5 additions & 3 deletions src/scp/SCP.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,11 +126,13 @@ SCP::getSlot(uint64 slotIndex, bool create)
}

void
SCP::dumpInfo(Json::Value& ret)
SCP::dumpInfo(Json::Value& ret, size_t limit)
{
for (auto& item : mKnownSlots)
auto it = mKnownSlots.rbegin();
while (it != mKnownSlots.rend() && limit-- != 0)
{
item.second->dumpInfo(ret);
it->second->dumpInfo(ret);
it++;
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/scp/SCP.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ class SCP
// returns the local node descriptor
std::shared_ptr<LocalNode> getLocalNode();

void dumpInfo(Json::Value& ret);
void dumpInfo(Json::Value& ret, size_t limit);

// summary: only return object counts
// index = 0 for returning information for all slots
Expand Down
16 changes: 15 additions & 1 deletion src/scp/Slot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -265,12 +265,26 @@ Slot::dumpInfo(Json::Value& ret)

Json::Value& slotValue = slots[std::to_string(mSlotIndex)];

std::map<Hash, SCPQuorumSetPtr> qSetsUsed;

int count = 0;
for (auto const& item : mStatementsHistory)
{
Json::Value& v = slotValue["statements"][count++];
v.append(envToStr(item.first));
v.append(item.second);

Hash const& qSetHash =
getCompanionQuorumSetHashFromStatement(item.first);
auto qSet = getSCPDriver().getQSet(qSetHash);
qSetsUsed.insert(std::make_pair(qSetHash, qSet));
}

auto& qSets = slotValue["quorum_sets"];
for (auto const& q : qSetsUsed)
{
auto& qs = qSets[hexAbbrev(q.first)];
getLocalNode()->toJson(*q.second, qs);
}

slotValue["validated"] = mFullyValidated;
Expand Down Expand Up @@ -326,7 +340,7 @@ Slot::envToStr(SCPStatement const& st) const
{
std::ostringstream oss;

Hash qSetHash = getCompanionQuorumSetHashFromStatement(st);
Hash const& qSetHash = getCompanionQuorumSetHashFromStatement(st);

oss << "{ENV@" << getSCPDriver().toShortString(st.nodeID) << " | "
<< " i: " << st.slotIndex;
Expand Down

0 comments on commit 5167ebe

Please sign in to comment.