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/Feature.h>
25 #include <ripple/protocol/STValidation.h>
26 #include <ripple/protocol/TxFlags.h>
27 #include <ripple/protocol/jss.h>
28 #include <boost/format.hpp>
29 #include <boost/regex.hpp>
38 static boost::regex
const re1(
41 "([abcdefABCDEF0-9]{64})"
45 boost::regex_constants::optimize);
49 for (
auto const& line : section.
lines())
53 if (!boost::regex_match(line, match, re1))
54 Throw<std::runtime_error>(
55 "Invalid entry '" + line +
"' in [" + section.
name() +
"]");
59 if (!
id.SetHexExact(match[1]))
60 Throw<std::runtime_error>(
61 "Invalid amendment ID '" + match[1] +
"' in [" +
62 section.
name() +
"]");
114 for (
auto const& val : valSet)
116 if (val->isTrusted())
124 [&](
auto const& amendment) { ++votes_[amendment]; });
149 auto const& it =
votes_.find(amendment);
169 auto const& it =
votes_.find(amendment);
269 boost::optional<NetClock::time_point>
310 , majorityTime_(majorityTime)
311 , unsupportedEnabled_(false)
318 if (
auto s =
add(a.first, sl))
320 JLOG(
j_.
debug()) <<
"Amendment " << a.first <<
" is supported.";
322 if (!a.second.empty())
331 if (
auto s =
add(a.first, sl))
333 JLOG(
j_.
debug()) <<
"Amendment " << a.first <<
" is enabled.";
335 if (!a.second.empty())
346 if (
auto s =
get(a.first, sl))
348 JLOG(
j_.
info()) <<
"Amendment " << a.first <<
" is vetoed.";
350 if (!a.second.empty())
398 if (name == e.second.name)
409 auto s =
add(amendment, sl);
421 auto s =
get(amendment, sl);
423 if (!s || !s->vetoed)
433 auto s =
add(amendment, sl);
442 JLOG(
j_.
error()) <<
"Unsupported amendment " << amendment
454 auto s =
get(amendment, sl);
455 return s && s->enabled;
462 auto s =
get(amendment, sl);
463 return s && s->supported;
473 boost::optional<NetClock::time_point>
492 if (e.second.supported && !e.second.vetoed &&
493 (enabled.
count(e.first) == 0))
495 amendments.push_back(e.first);
500 if (!amendments.empty())
501 std::sort(amendments.begin(), amendments.end());
522 <<
": " << enabledAmendments.
size() <<
", "
523 << majorityAmendments.
size() <<
", " << valSet.size();
525 auto vote = std::make_unique<AmendmentSet>(rules, valSet);
527 JLOG(
j_.
debug()) <<
"Received " << vote->trustedValidations()
528 <<
" trusted validations, threshold is: "
529 << vote->threshold();
542 bool const hasValMajority = vote->passes(entry.first);
545 auto const it = majorityAmendments.
find(entry.first);
546 if (it != majorityAmendments.
end())
547 majorityTime = it->second;
550 if (enabledAmendments.
count(entry.first) != 0)
552 JLOG(
j_.
debug()) << entry.first <<
": amendment already enabled";
556 !entry.second.vetoed)
559 JLOG(
j_.
debug()) << entry.first <<
": amendment got majority";
565 JLOG(
j_.
debug()) << entry.first <<
": amendment lost majority";
571 !entry.second.vetoed)
574 JLOG(
j_.
debug()) << entry.first <<
": amendment majority held";
575 actions[entry.first] = 0;
601 for (
auto& e : enabled)
613 for (
auto const& [hash, time] : majority)
615 auto s =
add(hash, sl);
622 JLOG(
j_.
info()) <<
"Unsupported amendment " << hash
623 <<
" reached majority at " <<
to_string(time);
640 v[jss::name] = fs.
name;
643 v[jss::vetoed] = fs.
vetoed;
648 auto const votesTotal =
lastVote_->trustedValidations();
649 auto const votesNeeded =
lastVote_->threshold();
650 auto const votesFor =
lastVote_->votes(
id);
652 v[jss::count] = votesFor;
653 v[jss::validations] = votesTotal;
656 v[jss::threshold] = votesNeeded;
686 auto a =
get(amendmentID, sl);
702 return std::make_unique<AmendmentTableImpl>(
703 majorityTime, supported, enabled, vetoed, journal);
Holds a collection of configuration values.
bool supported
Indicates an amendment that this server has code support for.
std::uint32_t lastUpdateSeq_
Current state of an amendment.
boost::optional< NetClock::time_point > firstUnsupportedExpected_
Stream trace() const
Severity stream access functions.
std::vector< uint256 > getDesired() const override
std::vector< uint256 > doValidation(std::set< uint256 > const &enabledAmendments) const override
uint256 find(std::string const &name) const override
bool vetoed
If an amendment is vetoed, a server will not support it.
hash_map< uint256, int > votes_
bool unVeto(uint256 const &amendment) override
boost::optional< NetClock::time_point > firstUnsupportedExpected() const override
std::string to_string(ListDisposition disposition)
The status of all amendments requested in a given window.
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)
bool passes(uint256 const &amendment) const
std::string const & name() const
Returns the name of this section.
T time_since_epoch(T... args)
@ objectValue
object value (collection of name/value pairs).
constexpr std::ratio< 204, 256 > preFixAmendmentMajorityCalcThreshold
The minimum amount of support an amendment should have.
const uint256 fixAmendmentMajorityCalc
std::map< uint256, std::uint32_t > doVoting(Rules const &rules, NetClock::time_point closeTime, std::set< uint256 > const &enabledAmendments, majorityAmendments_t const &majorityAmendments, std::vector< std::shared_ptr< STValidation >> const &validations) override
std::unique_ptr< AmendmentTable > make_AmendmentTable(std::chrono::seconds majorityTime, Section const &supported, Section const &enabled, Section const &vetoed, beast::Journal journal)
bool isSupported(uint256 const &amendment) const override
std::vector< std::string > const & lines() const
Returns all the lines in the section.
A generic endpoint for log messages.
bool enabled(uint256 const &id) const
Returns true if a feature is enabled.
bool veto(uint256 const &amendment) override
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
AmendmentTableImpl(std::chrono::seconds majorityTime, Section const &supported, Section const &enabled, Section const &vetoed, beast::Journal journal)
hash_map< uint256, AmendmentState > amendmentMap_
std::unique_ptr< AmendmentSet > lastVote_
const std::chrono::seconds majorityTime_
bool enabled
Indicates that the amendment has been enabled.
AmendmentSet(Rules const &rules, std::vector< std::shared_ptr< STValidation >> const &valSet)
Json::Value getJson() const override
std::string name
The name of this amendment, possibly empty.
Rules controlling protocol behavior.
int trustedValidations() const
const SF_Vec256 sfAmendments(access, STI_VECTOR256, 3, "Amendments")
bool isEnabled(uint256 const &amendment) const override
void injectJson(Json::Value &v, uint256 const &amendment, AmendmentState const &state, std::lock_guard< std::mutex > const &sl) const
AmendmentState * add(uint256 const &amendment, std::lock_guard< std::mutex > const &sl)
The amendment table stores the list of enabled and potential amendments.
bool needValidatedLedger(LedgerIndex seq) const override
Called to determine whether the amendment logic needs to process a new validated ledger.
int votes(uint256 const &amendment) const
constexpr std::ratio< 80, 100 > postFixAmendmentMajorityCalcThreshold
void doValidatedLedger(LedgerIndex seq, std::set< uint256 > const &enabled, majorityAmendments_t const &majority) override
bool enable(uint256 const &amendment) override
AmendmentState * get(uint256 const &amendment, std::lock_guard< std::mutex > const &sl)
bool hasUnsupportedEnabled() const override
returns true if one or more amendments on the network have been enabled that this server does not sup...