Format first-party source according to .clang-format

This commit is contained in:
Pretty Printer
2020-04-17 09:56:34 -05:00
committed by manojsdoshi
parent 65dfc5d19e
commit 50760c6935
1076 changed files with 86161 additions and 77449 deletions

View File

@@ -19,11 +19,11 @@
#include <ripple/app/main/Application.h>
#include <ripple/app/misc/AmendmentTable.h>
#include <ripple/protocol/STValidation.h>
#include <ripple/core/DatabaseCon.h>
#include <ripple/core/ConfigSections.h>
#include <ripple/protocol/jss.h>
#include <ripple/core/DatabaseCon.h>
#include <ripple/protocol/STValidation.h>
#include <ripple/protocol/TxFlags.h>
#include <ripple/protocol/jss.h>
#include <boost/format.hpp>
#include <boost/regex.hpp>
#include <algorithm>
@@ -31,38 +31,36 @@
namespace ripple {
static
std::vector<std::pair<uint256, std::string>>
parseSection (Section const& section)
static std::vector<std::pair<uint256, std::string>>
parseSection(Section const& section)
{
static boost::regex const re1 (
"^" // start of line
"(?:\\s*)" // whitespace (optional)
"([abcdefABCDEF0-9]{64})" // <hexadecimal amendment ID>
"(?:\\s+)" // whitespace
"(\\S+)" // <description>
, boost::regex_constants::optimize
);
static boost::regex const re1(
"^" // start of line
"(?:\\s*)" // whitespace (optional)
"([abcdefABCDEF0-9]{64})" // <hexadecimal amendment ID>
"(?:\\s+)" // whitespace
"(\\S+)" // <description>
,
boost::regex_constants::optimize);
std::vector<std::pair<uint256, std::string>> names;
for (auto const& line : section.lines ())
for (auto const& line : section.lines())
{
boost::smatch match;
if (!boost::regex_match (line, match, re1))
Throw<std::runtime_error> (
"Invalid entry '" + line +
"' in [" + section.name () + "]");
if (!boost::regex_match(line, match, re1))
Throw<std::runtime_error>(
"Invalid entry '" + line + "' in [" + section.name() + "]");
uint256 id;
if (!id.SetHexExact (match[1]))
Throw<std::runtime_error> (
"Invalid amendment ID '" + match[1] +
"' in [" + section.name () + "]");
if (!id.SetHexExact(match[1]))
Throw<std::runtime_error>(
"Invalid amendment ID '" + match[1] + "' in [" +
section.name() + "]");
names.push_back (std::make_pair (id, match[2]));
names.push_back(std::make_pair(id, match[2]));
}
return names;
@@ -90,7 +88,7 @@ struct AmendmentState
/** The name of this amendment, possibly empty. */
std::string name;
explicit AmendmentState () = default;
explicit AmendmentState() = default;
};
/** The status of all amendments requested in a given window. */
@@ -107,9 +105,10 @@ public:
// number of votes needed
int mThreshold = 0;
AmendmentSet () = default;
AmendmentSet() = default;
void tally (std::set<uint256> const& amendments)
void
tally(std::set<uint256> const& amendments)
{
++mTrustedValidations;
@@ -117,9 +116,10 @@ public:
++votes_[amendment];
}
int votes (uint256 const& amendment) const
int
votes(uint256 const& amendment) const
{
auto const& it = votes_.find (amendment);
auto const& it = votes_.find(amendment);
if (it == votes_.end())
return 0;
@@ -136,8 +136,7 @@ public:
Amendments are proposed and then adopted or rejected by the network. An
Amendment is uniquely identified by its AmendmentID, a 256-bit key.
*/
class AmendmentTableImpl final
: public AmendmentTable
class AmendmentTableImpl final : public AmendmentTable
{
protected:
std::mutex mutex_;
@@ -154,7 +153,7 @@ protected:
// The results of the last voting round - may be empty if
// we haven't participated in one yet.
std::unique_ptr <AmendmentSet> lastVote_;
std::unique_ptr<AmendmentSet> lastVote_;
// True if an unsupported amendment is enabled
bool unsupportedEnabled_;
@@ -166,15 +165,18 @@ protected:
beast::Journal const j_;
// Finds or creates state
AmendmentState* add (uint256 const& amendment);
AmendmentState*
add(uint256 const& amendment);
// Finds existing state
AmendmentState* get (uint256 const& amendment);
AmendmentState*
get(uint256 const& amendment);
void setJson (Json::Value& v, uint256 const& amendment, const AmendmentState&);
void
setJson(Json::Value& v, uint256 const& amendment, const AmendmentState&);
public:
AmendmentTableImpl (
AmendmentTableImpl(
std::chrono::seconds majorityTime,
int majorityFraction,
Section const& supported,
@@ -182,25 +184,36 @@ public:
Section const& vetoed,
beast::Journal journal);
uint256 find (std::string const& name) override;
uint256
find(std::string const& name) override;
bool veto (uint256 const& amendment) override;
bool unVeto (uint256 const& amendment) override;
bool
veto(uint256 const& amendment) override;
bool
unVeto(uint256 const& amendment) override;
bool enable (uint256 const& amendment) override;
bool disable (uint256 const& amendment) override;
bool
enable(uint256 const& amendment) override;
bool
disable(uint256 const& amendment) override;
bool isEnabled (uint256 const& amendment) override;
bool isSupported (uint256 const& amendment) override;
bool
isEnabled(uint256 const& amendment) override;
bool
isSupported(uint256 const& amendment) override;
bool hasUnsupportedEnabled () override;
bool
hasUnsupportedEnabled() override;
boost::optional<NetClock::time_point>
firstUnsupportedExpected() override;
Json::Value getJson (int) override;
Json::Value getJson (uint256 const&) override;
Json::Value
getJson(int) override;
Json::Value
getJson(uint256 const&) override;
bool needValidatedLedger (LedgerIndex seq) override;
bool
needValidatedLedger(LedgerIndex seq) override;
void
doValidatedLedger(
@@ -208,14 +221,14 @@ public:
std::set<uint256> const& enabled,
majorityAmendments_t const& majority) override;
std::vector <uint256>
doValidation (std::set<uint256> const& enabledAmendments) override;
std::vector<uint256>
doValidation(std::set<uint256> const& enabledAmendments) override;
std::vector <uint256>
getDesired () override;
std::vector<uint256>
getDesired() override;
std::map <uint256, std::uint32_t>
doVoting (
std::map<uint256, std::uint32_t>
doVoting(
NetClock::time_point closeTime,
std::set<uint256> const& enabledAmendments,
majorityAmendments_t const& majorityAmendments,
@@ -224,45 +237,43 @@ public:
//------------------------------------------------------------------------------
AmendmentTableImpl::AmendmentTableImpl (
std::chrono::seconds majorityTime,
int majorityFraction,
Section const& supported,
Section const& enabled,
Section const& vetoed,
beast::Journal journal)
: lastUpdateSeq_ (0)
, majorityTime_ (majorityTime)
, majorityFraction_ (majorityFraction)
, unsupportedEnabled_ (false)
, j_ (journal)
AmendmentTableImpl::AmendmentTableImpl(
std::chrono::seconds majorityTime,
int majorityFraction,
Section const& supported,
Section const& enabled,
Section const& vetoed,
beast::Journal journal)
: lastUpdateSeq_(0)
, majorityTime_(majorityTime)
, majorityFraction_(majorityFraction)
, unsupportedEnabled_(false)
, j_(journal)
{
assert (majorityFraction_ != 0);
assert(majorityFraction_ != 0);
std::lock_guard sl (mutex_);
std::lock_guard sl(mutex_);
for (auto const& a : parseSection(supported))
{
if (auto s = add (a.first))
if (auto s = add(a.first))
{
JLOG (j_.debug()) <<
"Amendment " << a.first << " is supported.";
JLOG(j_.debug()) << "Amendment " << a.first << " is supported.";
if (!a.second.empty ())
if (!a.second.empty())
s->name = a.second;
s->supported = true;
}
}
for (auto const& a : parseSection (enabled))
for (auto const& a : parseSection(enabled))
{
if (auto s = add (a.first))
if (auto s = add(a.first))
{
JLOG (j_.debug()) <<
"Amendment " << a.first << " is enabled.";
JLOG(j_.debug()) << "Amendment " << a.first << " is enabled.";
if (!a.second.empty ())
if (!a.second.empty())
s->name = a.second;
s->supported = true;
@@ -270,15 +281,14 @@ AmendmentTableImpl::AmendmentTableImpl (
}
}
for (auto const& a : parseSection (vetoed))
for (auto const& a : parseSection(vetoed))
{
// Unknown amendments are effectively vetoed already
if (auto s = get (a.first))
if (auto s = get(a.first))
{
JLOG (j_.info()) <<
"Amendment " << a.first << " is vetoed.";
JLOG(j_.info()) << "Amendment " << a.first << " is vetoed.";
if (!a.second.empty ())
if (!a.second.empty())
s->name = a.second;
s->vetoed = true;
@@ -287,17 +297,17 @@ AmendmentTableImpl::AmendmentTableImpl (
}
AmendmentState*
AmendmentTableImpl::add (uint256 const& amendmentHash)
AmendmentTableImpl::add(uint256 const& amendmentHash)
{
// call with the mutex held
return &amendmentMap_[amendmentHash];
}
AmendmentState*
AmendmentTableImpl::get (uint256 const& amendmentHash)
AmendmentTableImpl::get(uint256 const& amendmentHash)
{
// call with the mutex held
auto ret = amendmentMap_.find (amendmentHash);
auto ret = amendmentMap_.find(amendmentHash);
if (ret == amendmentMap_.end())
return nullptr;
@@ -306,9 +316,9 @@ AmendmentTableImpl::get (uint256 const& amendmentHash)
}
uint256
AmendmentTableImpl::find (std::string const& name)
AmendmentTableImpl::find(std::string const& name)
{
std::lock_guard sl (mutex_);
std::lock_guard sl(mutex_);
for (auto const& e : amendmentMap_)
{
@@ -320,10 +330,10 @@ AmendmentTableImpl::find (std::string const& name)
}
bool
AmendmentTableImpl::veto (uint256 const& amendment)
AmendmentTableImpl::veto(uint256 const& amendment)
{
std::lock_guard sl (mutex_);
auto s = add (amendment);
std::lock_guard sl(mutex_);
auto s = add(amendment);
if (s->vetoed)
return false;
@@ -332,10 +342,10 @@ AmendmentTableImpl::veto (uint256 const& amendment)
}
bool
AmendmentTableImpl::unVeto (uint256 const& amendment)
AmendmentTableImpl::unVeto(uint256 const& amendment)
{
std::lock_guard sl (mutex_);
auto s = get (amendment);
std::lock_guard sl(mutex_);
auto s = get(amendment);
if (!s || !s->vetoed)
return false;
@@ -344,20 +354,20 @@ AmendmentTableImpl::unVeto (uint256 const& amendment)
}
bool
AmendmentTableImpl::enable (uint256 const& amendment)
AmendmentTableImpl::enable(uint256 const& amendment)
{
std::lock_guard sl (mutex_);
auto s = add (amendment);
std::lock_guard sl(mutex_);
auto s = add(amendment);
if (s->enabled)
return false;
s->enabled = true;
if (! s->supported)
if (!s->supported)
{
JLOG (j_.error()) <<
"Unsupported amendment " << amendment << " activated.";
JLOG(j_.error()) << "Unsupported amendment " << amendment
<< " activated.";
unsupportedEnabled_ = true;
}
@@ -365,10 +375,10 @@ AmendmentTableImpl::enable (uint256 const& amendment)
}
bool
AmendmentTableImpl::disable (uint256 const& amendment)
AmendmentTableImpl::disable(uint256 const& amendment)
{
std::lock_guard sl (mutex_);
auto s = get (amendment);
std::lock_guard sl(mutex_);
auto s = get(amendment);
if (!s || !s->enabled)
return false;
@@ -378,25 +388,25 @@ AmendmentTableImpl::disable (uint256 const& amendment)
}
bool
AmendmentTableImpl::isEnabled (uint256 const& amendment)
AmendmentTableImpl::isEnabled(uint256 const& amendment)
{
std::lock_guard sl (mutex_);
auto s = get (amendment);
std::lock_guard sl(mutex_);
auto s = get(amendment);
return s && s->enabled;
}
bool
AmendmentTableImpl::isSupported (uint256 const& amendment)
AmendmentTableImpl::isSupported(uint256 const& amendment)
{
std::lock_guard sl (mutex_);
auto s = get (amendment);
std::lock_guard sl(mutex_);
auto s = get(amendment);
return s && s->supported;
}
bool
AmendmentTableImpl::hasUnsupportedEnabled ()
AmendmentTableImpl::hasUnsupportedEnabled()
{
std::lock_guard sl (mutex_);
std::lock_guard sl(mutex_);
return unsupportedEnabled_;
}
@@ -407,86 +417,82 @@ AmendmentTableImpl::firstUnsupportedExpected()
return firstUnsupportedExpected_;
}
std::vector <uint256>
AmendmentTableImpl::doValidation (
std::set<uint256> const& enabled)
std::vector<uint256>
AmendmentTableImpl::doValidation(std::set<uint256> const& enabled)
{
// Get the list of amendments we support and do not
// veto, but that are not already enabled
std::vector <uint256> amendments;
amendments.reserve (amendmentMap_.size());
std::vector<uint256> amendments;
amendments.reserve(amendmentMap_.size());
{
std::lock_guard sl (mutex_);
std::lock_guard sl(mutex_);
for (auto const& e : amendmentMap_)
{
if (e.second.supported && ! e.second.vetoed &&
(enabled.count (e.first) == 0))
if (e.second.supported && !e.second.vetoed &&
(enabled.count(e.first) == 0))
{
amendments.push_back (e.first);
amendments.push_back(e.first);
}
}
}
if (! amendments.empty())
std::sort (amendments.begin (), amendments.end ());
if (!amendments.empty())
std::sort(amendments.begin(), amendments.end());
return amendments;
}
std::vector <uint256>
AmendmentTableImpl::getDesired ()
std::vector<uint256>
AmendmentTableImpl::getDesired()
{
// Get the list of amendments we support and do not veto
return doValidation({});
}
std::map <uint256, std::uint32_t>
AmendmentTableImpl::doVoting (
std::map<uint256, std::uint32_t>
AmendmentTableImpl::doVoting(
NetClock::time_point closeTime,
std::set<uint256> const& enabledAmendments,
majorityAmendments_t const& majorityAmendments,
std::vector<STValidation::pointer> const& valSet)
{
JLOG (j_.trace()) <<
"voting at " << closeTime.time_since_epoch().count() <<
": " << enabledAmendments.size() <<
", " << majorityAmendments.size() <<
", " << valSet.size();
JLOG(j_.trace()) << "voting at " << closeTime.time_since_epoch().count()
<< ": " << enabledAmendments.size() << ", "
<< majorityAmendments.size() << ", " << valSet.size();
auto vote = std::make_unique <AmendmentSet> ();
auto vote = std::make_unique<AmendmentSet>();
// process validations for ledger before flag ledger
for (auto const& val : valSet)
{
if (val->isTrusted ())
if (val->isTrusted())
{
std::set<uint256> ballot;
if (val->isFieldPresent (sfAmendments))
if (val->isFieldPresent(sfAmendments))
{
auto const choices =
val->getFieldV256 (sfAmendments);
ballot.insert (choices.begin (), choices.end ());
auto const choices = val->getFieldV256(sfAmendments);
ballot.insert(choices.begin(), choices.end());
}
vote->tally (ballot);
vote->tally(ballot);
}
}
vote->mThreshold = std::max(1,
(vote->mTrustedValidations * majorityFraction_) / 256);
vote->mThreshold =
std::max(1, (vote->mTrustedValidations * majorityFraction_) / 256);
JLOG (j_.debug()) <<
"Received " << vote->mTrustedValidations <<
" trusted validations, threshold is: " << vote->mThreshold;
JLOG(j_.debug()) << "Received " << vote->mTrustedValidations
<< " trusted validations, threshold is: "
<< vote->mThreshold;
// Map of amendments to the action to be taken for each one. The action is
// the value of the flags in the pseudo-transaction
std::map <uint256, std::uint32_t> actions;
std::map<uint256, std::uint32_t> actions;
{
std::lock_guard sl (mutex_);
std::lock_guard sl(mutex_);
// process all amendments we know of
for (auto const& entry : amendmentMap_)
@@ -494,43 +500,41 @@ AmendmentTableImpl::doVoting (
NetClock::time_point majorityTime = {};
bool const hasValMajority =
(vote->votes (entry.first) >= vote->mThreshold);
(vote->votes(entry.first) >= vote->mThreshold);
{
auto const it = majorityAmendments.find (entry.first);
if (it != majorityAmendments.end ())
auto const it = majorityAmendments.find(entry.first);
if (it != majorityAmendments.end())
majorityTime = it->second;
}
if (enabledAmendments.count (entry.first) != 0)
if (enabledAmendments.count(entry.first) != 0)
{
JLOG (j_.debug()) <<
entry.first << ": amendment already enabled";
JLOG(j_.debug())
<< entry.first << ": amendment already enabled";
}
else if (hasValMajority &&
(majorityTime == NetClock::time_point{}) &&
! entry.second.vetoed)
else if (
hasValMajority && (majorityTime == NetClock::time_point{}) &&
!entry.second.vetoed)
{
// Ledger says no majority, validators say yes
JLOG (j_.debug()) <<
entry.first << ": amendment got majority";
JLOG(j_.debug()) << entry.first << ": amendment got majority";
actions[entry.first] = tfGotMajority;
}
else if (! hasValMajority &&
(majorityTime != NetClock::time_point{}))
else if (
!hasValMajority && (majorityTime != NetClock::time_point{}))
{
// Ledger says majority, validators say no
JLOG (j_.debug()) <<
entry.first << ": amendment lost majority";
JLOG(j_.debug()) << entry.first << ": amendment lost majority";
actions[entry.first] = tfLostMajority;
}
else if ((majorityTime != NetClock::time_point{}) &&
else if (
(majorityTime != NetClock::time_point{}) &&
((majorityTime + majorityTime_) <= closeTime) &&
! entry.second.vetoed)
!entry.second.vetoed)
{
// Ledger says majority held
JLOG (j_.debug()) <<
entry.first << ": amendment majority held";
JLOG(j_.debug()) << entry.first << ": amendment majority held";
actions[entry.first] = 0;
}
}
@@ -543,9 +547,9 @@ AmendmentTableImpl::doVoting (
}
bool
AmendmentTableImpl::needValidatedLedger (LedgerIndex ledgerSeq)
AmendmentTableImpl::needValidatedLedger(LedgerIndex ledgerSeq)
{
std::lock_guard sl (mutex_);
std::lock_guard sl(mutex_);
// Is there a ledger in which an amendment could have been enabled
// between these two ledger sequences?
@@ -567,7 +571,7 @@ AmendmentTableImpl::doValidatedLedger(
// it's currently set. If it's not set when the loop is done, then any
// prior unknown amendments have lost majority.
firstUnsupportedExpected_.reset();
for (auto const& [ hash, time ] : majority)
for (auto const& [hash, time] : majority)
{
auto s = add(hash);
@@ -577,7 +581,7 @@ AmendmentTableImpl::doValidatedLedger(
if (!s->supported)
{
JLOG(j_.info()) << "Unsupported amendment " << hash
<< " reached majority at " << to_string(time);
<< " reached majority at " << to_string(time);
if (!firstUnsupportedExpected_ || firstUnsupportedExpected_ > time)
firstUnsupportedExpected_ = time;
}
@@ -587,7 +591,10 @@ AmendmentTableImpl::doValidatedLedger(
}
void
AmendmentTableImpl::setJson (Json::Value& v, const uint256& id, const AmendmentState& fs)
AmendmentTableImpl::setJson(
Json::Value& v,
const uint256& id,
const AmendmentState& fs)
{
if (!fs.name.empty())
v[jss::name] = fs.name;
@@ -600,7 +607,7 @@ AmendmentTableImpl::setJson (Json::Value& v, const uint256& id, const AmendmentS
{
auto const votesTotal = lastVote_->mTrustedValidations;
auto const votesNeeded = lastVote_->mThreshold;
auto const votesFor = lastVote_->votes (id);
auto const votesFor = lastVote_->votes(id);
v[jss::count] = votesFor;
v[jss::validations] = votesTotal;
@@ -614,36 +621,37 @@ AmendmentTableImpl::setJson (Json::Value& v, const uint256& id, const AmendmentS
}
Json::Value
AmendmentTableImpl::getJson (int)
AmendmentTableImpl::getJson(int)
{
Json::Value ret(Json::objectValue);
{
std::lock_guard sl(mutex_);
for (auto const& e : amendmentMap_)
{
setJson (ret[to_string (e.first)] = Json::objectValue,
e.first, e.second);
setJson(
ret[to_string(e.first)] = Json::objectValue, e.first, e.second);
}
}
return ret;
}
Json::Value
AmendmentTableImpl::getJson (uint256 const& amendmentID)
AmendmentTableImpl::getJson(uint256 const& amendmentID)
{
Json::Value ret = Json::objectValue;
Json::Value& jAmendment = (ret[to_string (amendmentID)] = Json::objectValue);
Json::Value& jAmendment = (ret[to_string(amendmentID)] = Json::objectValue);
{
std::lock_guard sl(mutex_);
auto a = add (amendmentID);
setJson (jAmendment, amendmentID, *a);
auto a = add(amendmentID);
setJson(jAmendment, amendmentID, *a);
}
return ret;
}
std::unique_ptr<AmendmentTable> make_AmendmentTable (
std::unique_ptr<AmendmentTable>
make_AmendmentTable(
std::chrono::seconds majorityTime,
int majorityFraction,
Section const& supported,
@@ -651,13 +659,8 @@ std::unique_ptr<AmendmentTable> make_AmendmentTable (
Section const& vetoed,
beast::Journal journal)
{
return std::make_unique<AmendmentTableImpl> (
majorityTime,
majorityFraction,
supported,
enabled,
vetoed,
journal);
return std::make_unique<AmendmentTableImpl>(
majorityTime, majorityFraction, supported, enabled, vetoed, journal);
}
} // ripple
} // namespace ripple