20 #include <ripple/app/main/Application.h>
21 #include <ripple/app/misc/AmendmentTable.h>
22 #include <ripple/core/ConfigSections.h>
23 #include <ripple/core/DatabaseCon.h>
24 #include <ripple/protocol/STValidation.h>
25 #include <ripple/protocol/TxFlags.h>
26 #include <ripple/protocol/jss.h>
27 #include <boost/format.hpp>
28 #include <boost/regex.hpp>
37 static boost::regex
const re1(
40 "([abcdefABCDEF0-9]{64})"
44 boost::regex_constants::optimize);
48 for (
auto const& line : section.
lines())
52 if (!boost::regex_match(line, match, re1))
53 Throw<std::runtime_error>(
54 "Invalid entry '" + line +
"' in [" + section.
name() +
"]");
58 if (!
id.SetHexExact(match[1]))
59 Throw<std::runtime_error>(
60 "Invalid amendment ID '" + match[1] +
"' in [" +
61 section.
name() +
"]");
115 for (
auto const& amendment : amendments)
122 auto const& it =
votes_.find(amendment);
181 int majorityFraction,
207 boost::optional<NetClock::time_point>
242 int majorityFraction,
248 , majorityTime_(majorityTime)
249 , majorityFraction_(majorityFraction)
250 , unsupportedEnabled_(false)
259 if (
auto s =
add(a.first))
261 JLOG(
j_.
debug()) <<
"Amendment " << a.first <<
" is supported.";
263 if (!a.second.empty())
272 if (
auto s =
add(a.first))
274 JLOG(
j_.
debug()) <<
"Amendment " << a.first <<
" is enabled.";
276 if (!a.second.empty())
287 if (
auto s =
get(a.first))
289 JLOG(
j_.
info()) <<
"Amendment " << a.first <<
" is vetoed.";
291 if (!a.second.empty())
325 if (name == e.second.name)
336 auto s =
add(amendment);
348 auto s =
get(amendment);
350 if (!s || !s->vetoed)
360 auto s =
add(amendment);
369 JLOG(
j_.
error()) <<
"Unsupported amendment " << amendment
381 auto s =
get(amendment);
383 if (!s || !s->enabled)
394 auto s =
get(amendment);
395 return s && s->enabled;
402 auto s =
get(amendment);
403 return s && s->supported;
413 boost::optional<NetClock::time_point>
432 if (e.second.supported && !e.second.vetoed &&
433 (enabled.
count(e.first) == 0))
435 amendments.push_back(e.first);
440 if (!amendments.empty())
441 std::sort(amendments.begin(), amendments.end());
461 <<
": " << enabledAmendments.
size() <<
", "
462 << majorityAmendments.
size() <<
", " << valSet.size();
464 auto vote = std::make_unique<AmendmentSet>();
467 for (
auto const& val : valSet)
469 if (val->isTrusted())
476 ballot.
insert(choices.begin(), choices.end());
486 JLOG(
j_.
debug()) <<
"Received " << vote->mTrustedValidations
487 <<
" trusted validations, threshold is: "
502 bool const hasValMajority =
503 (vote->votes(entry.first) >= vote->mThreshold);
506 auto const it = majorityAmendments.
find(entry.first);
507 if (it != majorityAmendments.
end())
508 majorityTime = it->second;
511 if (enabledAmendments.
count(entry.first) != 0)
514 << entry.first <<
": amendment already enabled";
518 !entry.second.vetoed)
521 JLOG(
j_.
debug()) << entry.first <<
": amendment got majority";
528 JLOG(
j_.
debug()) << entry.first <<
": amendment lost majority";
534 !entry.second.vetoed)
537 JLOG(
j_.
debug()) << entry.first <<
": amendment majority held";
538 actions[entry.first] = 0;
566 for (
auto& e : enabled)
574 for (
auto const& [hash, time] : majority)
583 JLOG(
j_.
info()) <<
"Unsupported amendment " << hash
584 <<
" reached majority at " <<
to_string(time);
600 v[jss::name] = fs.
name;
603 v[jss::vetoed] = fs.
vetoed;
608 auto const votesTotal =
lastVote_->mTrustedValidations;
609 auto const votesNeeded =
lastVote_->mThreshold;
610 auto const votesFor =
lastVote_->votes(
id);
612 v[jss::count] = votesFor;
613 v[jss::validations] = votesTotal;
617 v[jss::vote] = votesFor * 256 / votesNeeded;
618 v[jss::threshold] = votesNeeded;
646 auto a =
add(amendmentID);
647 setJson(jAmendment, amendmentID, *a);
656 int majorityFraction,
662 return std::make_unique<AmendmentTableImpl>(
663 majorityTime, majorityFraction, supported, enabled, vetoed, journal);
Holds a collection of configuration values.
std::map< uint256, std::uint32_t > doVoting(NetClock::time_point closeTime, std::set< uint256 > const &enabledAmendments, majorityAmendments_t const &majorityAmendments, std::vector< std::shared_ptr< STValidation >> const &validations) override
bool supported
Indicates an amendment that this server has code support for.
std::uint32_t lastUpdateSeq_
bool disable(uint256 const &amendment) override
bool hasUnsupportedEnabled() override
returns true if one or more amendments on the network have been enabled that this server does not sup...
Current state of an amendment.
boost::optional< NetClock::time_point > firstUnsupportedExpected_
Stream trace() const
Severity stream access functions.
std::unique_ptr< AmendmentTable > make_AmendmentTable(std::chrono::seconds majorityTime, int majorityFraction, Section const &supported, Section const &enabled, Section const &vetoed, beast::Journal journal)
bool isSupported(uint256 const &amendment) override
bool vetoed
If an amendment is vetoed, a server will not support it.
bool unVeto(uint256 const &amendment) override
void tally(std::set< uint256 > const &amendments)
std::string to_string(ListDisposition disposition)
bool isEnabled(uint256 const &amendment) override
const std::uint32_t tfLostMajority
const std::uint32_t tfGotMajority
Track the list of "amendments".
static std::vector< std::pair< uint256, std::string > > parseSection(Section const §ion)
hash_map< uint256, int > votes_
std::string const & name() const
Returns the name of this section.
T time_since_epoch(T... args)
void setJson(Json::Value &v, uint256 const &amendment, const AmendmentState &)
const int majorityFraction_
@ objectValue
object value (collection of name/value pairs).
boost::optional< NetClock::time_point > firstUnsupportedExpected() override
uint256 find(std::string const &name) override
int votes(uint256 const &amendment) const
std::vector< std::string > const & lines() const
Returns all the lines in the section.
A generic endpoint for log messages.
AmendmentTableImpl(std::chrono::seconds majorityTime, int majorityFraction, Section const &supported, Section const &enabled, Section const &vetoed, beast::Journal journal)
bool veto(uint256 const &amendment) override
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Json::Value getJson(int) override
hash_map< uint256, AmendmentState > amendmentMap_
std::vector< uint256 > doValidation(std::set< uint256 > const &enabledAmendments) override
std::unique_ptr< AmendmentSet > lastVote_
const std::chrono::seconds majorityTime_
bool enabled
Indicates that the amendment has been enabled.
std::string name
The name of this amendment, possibly empty.
bool needValidatedLedger(LedgerIndex seq) override
Called to determine whether the amendment logic needs to process a new validated ledger.
const SF_Vec256 sfAmendments(access, STI_VECTOR256, 3, "Amendments")
The status of all amendments requested in a given window.
The amendment table stores the list of enabled and potential amendments.
AmendmentState * get(uint256 const &amendment)
AmendmentState * add(uint256 const &amendment)
std::vector< uint256 > getDesired() override
void doValidatedLedger(LedgerIndex seq, std::set< uint256 > const &enabled, majorityAmendments_t const &majority) override
bool enable(uint256 const &amendment) override