20 #include <ripple/app/main/Application.h>
21 #include <ripple/app/misc/AmendmentTable.h>
22 #include <ripple/app/rdb/Wallet.h>
23 #include <ripple/core/ConfigSections.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.parseHex(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);
322 , majorityTime_(majorityTime)
323 , unsupportedEnabled_(false)
325 , db_(app.getWalletDB())
330 bool const featureVotesExist = [
this]() {
336 for (
auto const& [name, amendment, votebehavior] : supported)
342 switch (votebehavior)
357 JLOG(
j_.
debug()) <<
"Amendment " << amendment <<
" (" << s.
name
358 <<
") is supported and will be "
360 <<
" voted by default if not enabled on the ledger.";
367 if (featureVotesExist)
369 JLOG(
j_.
warn()) <<
"[amendments] section in config file ignored"
370 " in favor of data in db/wallet.db.";
375 detect_conflict.
insert(a.first);
383 if (featureVotesExist)
386 <<
"[veto_amendments] section in config file ignored"
387 " in favor of data in db/wallet.db.";
392 if (detect_conflict.
count(a.first) == 0)
399 <<
"[veto_amendments] section in config has amendment "
400 <<
'(' << a.first <<
", " << a.second
401 <<
") both [veto_amendments] and [amendments].";
410 [&](boost::optional<std::string> amendment_hash,
411 boost::optional<std::string> amendment_name,
412 boost::optional<AmendmentVote> vote) {
414 if (!amendment_hash || !amendment_name || !vote)
417 Throw<std::runtime_error>(
418 "Invalid FeatureVotes row in wallet.db");
420 if (!amend_hash.
parseHex(*amendment_hash))
422 Throw<std::runtime_error>(
423 "Invalid amendment ID '" + *amendment_hash +
429 if (
auto s =
get(amend_hash, lock))
431 JLOG(
j_.
info()) <<
"Amendment {" << *amendment_name <<
", "
432 << amend_hash <<
"} is downvoted.";
433 if (!amendment_name->empty())
434 s->name = *amendment_name;
444 JLOG(
j_.
debug()) <<
"Amendment {" << *amendment_name <<
", "
445 << amend_hash <<
"} is upvoted.";
446 if (!amendment_name->empty())
447 s.
name = *amendment_name;
495 if (name == e.second.name)
552 JLOG(
j_.
error()) <<
"Unsupported amendment " << amendment
603 (enabled.
count(e.first) == 0))
605 amendments.push_back(e.first);
606 JLOG(
j_.
info()) <<
"Voting for amendment " << e.second.name;
611 if (!amendments.empty())
612 std::sort(amendments.begin(), amendments.end());
633 <<
": " << enabledAmendments.
size() <<
", "
634 << majorityAmendments.
size() <<
", " << valSet.size();
636 auto vote = std::make_unique<AmendmentSet>(rules, valSet);
638 JLOG(
j_.
debug()) <<
"Received " << vote->trustedValidations()
639 <<
" trusted validations, threshold is: "
640 << vote->threshold();
653 bool const hasValMajority = vote->passes(entry.first);
656 auto const it = majorityAmendments.
find(entry.first);
657 if (it != majorityAmendments.
end())
658 majorityTime = it->second;
661 if (enabledAmendments.
count(entry.first) != 0)
663 JLOG(
j_.
debug()) << entry.first <<
": amendment already enabled";
670 JLOG(
j_.
debug()) << entry.first <<
": amendment got majority";
676 JLOG(
j_.
debug()) << entry.first <<
": amendment lost majority";
685 JLOG(
j_.
debug()) << entry.first <<
": amendment majority held";
686 actions[entry.first] = 0;
712 for (
auto& e : enabled)
724 for (
auto const& [hash, time] : majority)
733 JLOG(
j_.
info()) <<
"Unsupported amendment " << hash
734 <<
" reached majority at " <<
to_string(time);
751 v[jss::name] = fs.
name;
757 v[jss::vetoed] =
"Obsolete";
765 auto const votesTotal =
lastVote_->trustedValidations();
766 auto const votesNeeded =
lastVote_->threshold();
767 auto const votesFor =
lastVote_->votes(
id);
769 v[jss::count] = votesFor;
770 v[jss::validations] = votesTotal;
773 v[jss::threshold] = votesNeeded;
805 injectJson(jAmendment, amendmentID, *a, lock);
820 return std::make_unique<AmendmentTableImpl>(
821 app, majorityTime, supported, enabled, vetoed, journal);
constexpr std::uint32_t tfGotMajority
Holds a collection of configuration values.
bool supported
Indicates an amendment that this server has code support for.
constexpr std::uint32_t tfLostMajority
std::uint32_t lastUpdateSeq_
Current state of an amendment.
bool enabled(uint256 const &feature) const
Returns true if a feature is enabled.
Stream trace() const
Severity stream access functions.
std::optional< NetClock::time_point > firstUnsupportedExpected_
std::vector< uint256 > getDesired() const override
std::vector< uint256 > doValidation(std::set< uint256 > const &enabledAmendments) const override
bool createFeatureVotes(soci::session &session)
createFeatureVotes Creates the FeatureVote table if it does not exist.
uint256 find(std::string const &name) const override
hash_map< uint256, int > votes_
bool unVeto(uint256 const &amendment) override
AmendmentVote vote
If an amendment is down-voted, a server will not vote to enable it.
The status of all amendments requested in a given window.
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)
LockedSociSession checkoutDb()
@ objectValue
object value (collection of name/value pairs).
std::optional< NetClock::time_point > firstUnsupportedExpected() const override
constexpr std::ratio< 204, 256 > preFixAmendmentMajorityCalcThreshold
The minimum amount of support an amendment should have.
const uint256 fixAmendmentMajorityCalc
AmendmentTableImpl(Application &app, std::chrono::seconds majorityTime, std::vector< FeatureInfo > const &supported, Section const &enabled, Section const &vetoed, beast::Journal journal)
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
void readAmendments(soci::session &session, std::function< void(boost::optional< std::string > amendment_hash, boost::optional< std::string > amendment_name, boost::optional< AmendmentVote > vote)> const &callback)
readAmendments Reads all amendments from the FeatureVotes table.
AmendmentState * get(uint256 const &amendment, std::lock_guard< std::mutex > const &lock)
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 veto(uint256 const &amendment) override
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
void injectJson(Json::Value &v, uint256 const &amendment, AmendmentState const &state, std::lock_guard< std::mutex > const &lock) const
hash_map< uint256, AmendmentState > amendmentMap_
std::unique_ptr< AmendmentSet > lastVote_
const std::chrono::seconds majorityTime_
void voteAmendment(soci::session &session, uint256 const &amendment, std::string const &name, AmendmentVote vote)
voteAmendment Set the veto value for a particular amendment.
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.
std::string to_string(Manifest const &m)
Format the specified manifest to a string for debugging purposes.
std::unique_ptr< AmendmentTable > make_AmendmentTable(Application &app, std::chrono::seconds majorityTime, std::vector< AmendmentTable::FeatureInfo > const &supported, Section const &enabled, Section const &vetoed, beast::Journal journal)
AmendmentState & add(uint256 const &amendment, std::lock_guard< std::mutex > const &lock)
int trustedValidations() const
bool isEnabled(uint256 const &amendment) const override
constexpr bool parseHex(std::string_view sv)
Parse a hex string into a base_uint.
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
void persistVote(uint256 const &amendment, std::string const &name, AmendmentVote vote) 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
const SF_VECTOR256 sfAmendments
bool hasUnsupportedEnabled() const override
returns true if one or more amendments on the network have been enabled that this server does not sup...