Skip to content

Commit

Permalink
[FOLD] Assortment of small potential changes
Browse files Browse the repository at this point in the history
  • Loading branch information
scottschurr committed May 18, 2020
1 parent 3fcfcfc commit 5989fc9
Show file tree
Hide file tree
Showing 9 changed files with 58 additions and 48 deletions.
2 changes: 1 addition & 1 deletion src/ripple/app/consensus/RCLConsensus.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -860,7 +860,7 @@ RCLConsensus::getJson(bool full) const
std::lock_guard _{mutex_};
ret = consensus_.getJson(full);
}
ret["validating"] = adaptor_.validating();
ret[jss::validating] = adaptor_.validating();
return ret;
}

Expand Down
29 changes: 17 additions & 12 deletions src/ripple/app/misc/NetworkOPs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -873,18 +873,23 @@ class NetworkOPsImp final : public NetworkOPs

//------------------------------------------------------------------------------

static std::array<char const*, 5> const stateNames{
{"disconnected", "connected", "syncing", "tracking", "full"}};

std::array<char const*, 5> const NetworkOPsImp::states_ = stateNames;
static std::array<Json::StaticString const, 5> const stateNames{
{jss::disconnected,
jss::connected,
jss::syncing,
jss::tracking,
jss::full}};

std::array<char const*, 5> const NetworkOPsImp::states_ = {{
stateNames[0].c_str(),
stateNames[1].c_str(),
stateNames[2].c_str(),
stateNames[3].c_str(),
stateNames[4].c_str(),
}};

std::array<Json::StaticString const, 5> const
NetworkOPsImp::StateAccounting::states_ = {
{Json::StaticString(stateNames[0]),
Json::StaticString(stateNames[1]),
Json::StaticString(stateNames[2]),
Json::StaticString(stateNames[3]),
Json::StaticString(stateNames[4])}};
NetworkOPsImp::StateAccounting::states_ = stateNames;

//------------------------------------------------------------------------------
std::string
Expand Down Expand Up @@ -1088,10 +1093,10 @@ NetworkOPsImp::strOperatingMode(OperatingMode const mode, bool const admin)
if (consensusMode != ConsensusMode::wrongLedger)
{
if (consensusMode == ConsensusMode::proposing)
return "proposing";
return jss::proposing.c_str();

if (mConsensus.validating())
return "validating";
return jss::validating.c_str();
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/ripple/consensus/Consensus.h
Original file line number Diff line number Diff line change
Expand Up @@ -913,8 +913,8 @@ Consensus<Adaptor>::getJson(bool full) const

Json::Value ret(Json::objectValue);

ret["proposing"] = (mode_.get() == ConsensusMode::proposing);
ret["proposers"] = static_cast<int>(currPeerPositions_.size());
ret[jss::proposing] = (mode_.get() == ConsensusMode::proposing);
ret[jss::proposers] = static_cast<int>(currPeerPositions_.size());

if (mode_.get() != ConsensusMode::wrongLedger)
{
Expand Down
2 changes: 1 addition & 1 deletion src/ripple/consensus/ConsensusTypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ to_string(ConsensusMode m)
switch (m)
{
case ConsensusMode::proposing:
return "proposing";
return jss::proposing.c_str();
case ConsensusMode::observing:
return "observing";
case ConsensusMode::wrongLedger:
Expand Down
44 changes: 21 additions & 23 deletions src/ripple/overlay/impl/OverlayImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1084,17 +1084,7 @@ OverlayImpl::processHealth(http_request_type const& req, Handoff& handoff)
msg.insert("Content-Type", "application/json");
msg.insert("Connection", "close");

auto info = getServerInfo();

int last_validated_ledger_age = std::numeric_limits<int>::max();
if (info.isMember("validated_ledger"))
last_validated_ledger_age = info["validated_ledger"]["age"].asInt();
bool amendment_blocked = false;
if (info.isMember("amendment_blocked"))
amendment_blocked = true;
int number_peers = info["peers"].asInt();
std::string server_state = info["server_state"].asString();
auto load_factor = info["load_factor"].asDouble();
auto const info = getServerInfo();

enum { healthy, warning, critical };
int health = healthy;
Expand All @@ -1103,46 +1093,54 @@ OverlayImpl::processHealth(http_request_type const& req, Handoff& handoff)
health = state;
};

int last_validated_ledger_age = std::numeric_limits<int>::max();
if (info.isMember(jss::validated_ledger))
last_validated_ledger_age =
info[jss::validated_ledger][jss::age].asInt();

if (last_validated_ledger_age >= 7)
{
msg.body()[jss::info]["validated_ledger"] = last_validated_ledger_age;
msg.body()[jss::info][jss::validated_ledger] =
last_validated_ledger_age;
if (last_validated_ledger_age < 20)
set_health(warning);
else
set_health(critical);
}

if (amendment_blocked)
if (!info.isMember(jss::amendment_blocked))
{
msg.body()[jss::info]["amendment_blocked"] = true;
msg.body()[jss::info][jss::amendment_blocked] = true;
set_health(critical);
}

if (number_peers <= 7)
if (int const number_peers = info[jss::peers].asInt(); number_peers <= 7)
{
msg.body()[jss::info]["peers"] = number_peers;
msg.body()[jss::info][jss::peers] = number_peers;
if (number_peers != 0)
set_health(warning);
else
set_health(critical);
}

if (!(server_state == "full" || server_state == "validating" ||
server_state == "proposing"))
if (std::string const server_state = info[jss::server_state].asString();
!(server_state == jss::full || server_state == jss::validating ||
server_state == jss::proposing))
{
msg.body()[jss::info]["server_state"] = server_state;
if (server_state == "syncing" || server_state == "tracking" ||
server_state == "connected")
msg.body()[jss::info][jss::server_state] = server_state;
if (server_state == jss::syncing || server_state == jss::tracking ||
server_state == jss::connected)
{
set_health(warning);
}
else
set_health(critical);
}

if (load_factor > 100)
if (double const load_factor = info[jss::load_factor].asDouble();
load_factor > 100)
{
msg.body()[jss::info]["load_factor"] = load_factor;
msg.body()[jss::info][jss::load_factor] = load_factor;
if (load_factor < 1000)
set_health(warning);
else
Expand Down
4 changes: 2 additions & 2 deletions src/ripple/overlay/impl/PeerImp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -386,15 +386,15 @@ PeerImp::json()
break;

case protocol::nsCONNECTED:
ret[jss::status] = "connected";
ret[jss::status] = jss::connected;
break;

case protocol::nsMONITORING:
ret[jss::status] = "monitoring";
break;

case protocol::nsVALIDATING:
ret[jss::status] = "validating";
ret[jss::status] = jss::validating;
break;

case protocol::nsSHUTTING:
Expand Down
3 changes: 2 additions & 1 deletion src/ripple/peerfinder/impl/Logic.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
#include <ripple/peerfinder/impl/Source.h>
#include <ripple/peerfinder/impl/Store.h>
#include <ripple/peerfinder/impl/iosformat.h>
#include <ripple/protocol/jss.h>

#include <algorithm>
#include <functional>
Expand Down Expand Up @@ -1182,7 +1183,7 @@ class Logic
case Slot::connect:
return "connect";
case Slot::connected:
return "connected";
return jss::connected.c_str();
case Slot::active:
return "active";
case Slot::closing:
Expand Down
6 changes: 6 additions & 0 deletions src/ripple/protocol/jss.h
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ JSS(command); // in: RPCHandler
JSS(complete); // out: NetworkOPs, InboundLedger
JSS(complete_ledgers); // out: NetworkOPs, PeerImp
JSS(complete_shards); // out: OverlayImpl, PeerImp
JSS(connected); // out: server_info
JSS(consensus); // out: NetworkOPs, LedgerConsensus
JSS(converge_time); // out: NetworkOPs
JSS(converge_time_s); // out: NetworkOPs
Expand Down Expand Up @@ -207,6 +208,7 @@ JSS(dir_entry); // out: DirectoryEntryIterator
JSS(dir_index); // out: DirectoryEntryIterator
JSS(dir_root); // out: DirectoryEntryIterator
JSS(directory); // in: LedgerEntry
JSS(disconnected); // out: server_info
JSS(domain); // out: ValidatorInfo, Manifest
JSS(drops); // out: TxQ
JSS(duration_us); // out: NetworkOPs
Expand Down Expand Up @@ -416,6 +418,7 @@ JSS(previous_ledger); // out: LedgerPropose
JSS(proof); // in: BookOffers
JSS(propose_seq); // out: LedgerPropose
JSS(proposers); // out: NetworkOPs, LedgerConsensus
JSS(proposing); // out: server_info
JSS(protocol); // out: PeerImp
JSS(proxied); // out: RPC ping
JSS(pubkey_node); // out: NetworkOPs
Expand Down Expand Up @@ -503,6 +506,7 @@ JSS(sub_index); // in: LedgerEntry
JSS(subcommand); // in: PathFind
JSS(success); // rpc
JSS(supported); // out: AmendmentTableImpl
JSS(syncing); // out: server_info
JSS(system_time_offset); // out: NetworkOPs
JSS(tag); // out: Peers
JSS(taker); // in: Subscribe, BookOffers
Expand All @@ -520,6 +524,7 @@ JSS(totalCoins); // out: LedgerToJson
JSS(total_bytes_recv); // out: Peers
JSS(total_bytes_sent); // out: Peers
JSS(total_coins); // out: LedgerToJson
JSS(tracking); // out: server_info
JSS(transTreeHash); // out: ledger/Ledger.cpp
JSS(transaction); // in: Tx
// out: NetworkOPs, AcceptedLedgerTx,
Expand Down Expand Up @@ -556,6 +561,7 @@ JSS(urlgravatar); //
JSS(username); // in: Subscribe
JSS(validated); // out: NetworkOPs, RPCHelpers, AccountTx*
// Tx
JSS(validating); // out: server_info
JSS(validator_list_expires); // out: NetworkOps, ValidatorList
JSS(validator_list); // out: NetworkOps, ValidatorList
JSS(validators);
Expand Down
12 changes: 6 additions & 6 deletions src/test/server/ServerStatus_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -824,7 +824,7 @@ class ServerStatus_test : public beast::unit_test::suite,
BEAST_EXPECT(si.isMember(jss::info));
BEAST_EXPECT(!si[jss::info].isMember(jss::amendment_blocked));
BEAST_EXPECT(
env.app().getOPs().getConsensusInfo()["validating"] == true);
env.app().getOPs().getConsensusInfo()[jss::validating] == true);
BEAST_EXPECT(!si.isMember(jss::warnings));

// make an RPC server state request and look for
Expand All @@ -833,7 +833,7 @@ class ServerStatus_test : public beast::unit_test::suite,
BEAST_EXPECT(si.isMember(jss::state));
BEAST_EXPECT(!si[jss::state].isMember(jss::amendment_blocked));
BEAST_EXPECT(
env.app().getOPs().getConsensusInfo()["validating"] == true);
env.app().getOPs().getConsensusInfo()[jss::validating] == true);
BEAST_EXPECT(!si[jss::state].isMember(jss::warnings));

auto const port_ws =
Expand Down Expand Up @@ -864,7 +864,7 @@ class ServerStatus_test : public beast::unit_test::suite,

// consensus doesn't change
BEAST_EXPECT(
env.app().getOPs().getConsensusInfo()["validating"] == true);
env.app().getOPs().getConsensusInfo()[jss::validating] == true);

// RPC request server_info again, now unsupported majority should be
// returned
Expand Down Expand Up @@ -954,7 +954,7 @@ class ServerStatus_test : public beast::unit_test::suite,
BEAST_EXPECT(si.isMember(jss::info));
BEAST_EXPECT(!si[jss::info].isMember(jss::amendment_blocked));
BEAST_EXPECT(
env.app().getOPs().getConsensusInfo()["validating"] == true);
env.app().getOPs().getConsensusInfo()[jss::validating] == true);
BEAST_EXPECT(!si.isMember(jss::warnings));

// make an RPC server state request and look for
Expand All @@ -963,7 +963,7 @@ class ServerStatus_test : public beast::unit_test::suite,
BEAST_EXPECT(si.isMember(jss::state));
BEAST_EXPECT(!si[jss::state].isMember(jss::amendment_blocked));
BEAST_EXPECT(
env.app().getOPs().getConsensusInfo()["validating"] == true);
env.app().getOPs().getConsensusInfo()[jss::validating] == true);
BEAST_EXPECT(!si[jss::state].isMember(jss::warnings));

auto const port_ws =
Expand Down Expand Up @@ -995,7 +995,7 @@ class ServerStatus_test : public beast::unit_test::suite,

// consensus now sees validation disabled
BEAST_EXPECT(
env.app().getOPs().getConsensusInfo()["validating"] == false);
env.app().getOPs().getConsensusInfo()[jss::validating] == false);

// RPC request server_info again, now AB should be returned
si = env.rpc("server_info")[jss::result];
Expand Down

0 comments on commit 5989fc9

Please sign in to comment.