20 #include <ripple/app/main/Application.h>
21 #include <ripple/app/misc/AmendmentTable.h>
22 #include <ripple/app/rdb/RelationalDBInterface_global.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);
249 bool vote_to_veto)
const;
321 , majorityTime_(majorityTime)
322 , unsupportedEnabled_(false)
324 , db_(app.getWalletDB())
329 bool const featureVotesExist = [
this]() {
337 if (
auto s =
add(a.first, sl))
339 JLOG(
j_.
debug()) <<
"Amendment " << a.first <<
" is supported.";
341 if (!a.second.empty())
352 if (featureVotesExist)
354 JLOG(
j_.
warn()) <<
"[amendments] section in config file ignored"
355 " in favor of data in db/wallet.db.";
360 detect_conflict.
insert(a.first);
368 if (featureVotesExist)
371 <<
"[veto_amendments] section in config file ignored"
372 " in favor of data in db/wallet.db.";
377 if (detect_conflict.
count(a.first) == 0)
384 <<
"[veto_amendments] section in config has amendment "
385 <<
'(' << a.first <<
", " << a.second
386 <<
") both [veto_amendments] and [amendments].";
395 [&](boost::optional<std::string> amendment_hash,
396 boost::optional<std::string> amendment_name,
397 boost::optional<int> vote_to_veto) {
399 if (!amend_hash.
parseHex(*amendment_hash))
401 Throw<std::runtime_error>(
402 "Invalid amendment ID '" + *amendment_hash +
408 if (
auto s =
get(amend_hash, sl))
410 JLOG(
j_.
info()) <<
"Amendment {" << *amendment_name <<
", "
411 << amend_hash <<
"} is vetoed.";
412 if (!amendment_name->empty())
413 s->name = *amendment_name;
419 if (
auto s =
add(amend_hash, sl))
421 JLOG(
j_.
debug()) <<
"Amendment {" << *amendment_name <<
", "
422 << amend_hash <<
"} is un-vetoed.";
423 if (!amendment_name->empty())
424 s->name = *amendment_name;
471 if (name == e.second.name)
482 bool vote_to_veto)
const
492 auto s =
add(amendment, sl);
505 auto s =
get(amendment, sl);
507 if (!s || !s->vetoed)
518 auto s =
add(amendment, sl);
527 JLOG(
j_.
error()) <<
"Unsupported amendment " << amendment
539 auto s =
get(amendment, sl);
540 return s && s->enabled;
547 auto s =
get(amendment, sl);
548 return s && s->supported;
577 if (e.second.supported && !e.second.vetoed &&
578 (enabled.
count(e.first) == 0))
580 amendments.push_back(e.first);
585 if (!amendments.empty())
586 std::sort(amendments.begin(), amendments.end());
607 <<
": " << enabledAmendments.
size() <<
", "
608 << majorityAmendments.
size() <<
", " << valSet.size();
610 auto vote = std::make_unique<AmendmentSet>(rules, valSet);
612 JLOG(
j_.
debug()) <<
"Received " << vote->trustedValidations()
613 <<
" trusted validations, threshold is: "
614 << vote->threshold();
627 bool const hasValMajority = vote->passes(entry.first);
630 auto const it = majorityAmendments.
find(entry.first);
631 if (it != majorityAmendments.
end())
632 majorityTime = it->second;
635 if (enabledAmendments.
count(entry.first) != 0)
637 JLOG(
j_.
debug()) << entry.first <<
": amendment already enabled";
641 !entry.second.vetoed)
644 JLOG(
j_.
debug()) << entry.first <<
": amendment got majority";
650 JLOG(
j_.
debug()) << entry.first <<
": amendment lost majority";
656 !entry.second.vetoed)
659 JLOG(
j_.
debug()) << entry.first <<
": amendment majority held";
660 actions[entry.first] = 0;
686 for (
auto& e : enabled)
698 for (
auto const& [hash, time] : majority)
700 auto s =
add(hash, sl);
707 JLOG(
j_.
info()) <<
"Unsupported amendment " << hash
708 <<
" reached majority at " <<
to_string(time);
725 v[jss::name] = fs.
name;
728 v[jss::vetoed] = fs.
vetoed;
733 auto const votesTotal =
lastVote_->trustedValidations();
734 auto const votesNeeded =
lastVote_->threshold();
735 auto const votesFor =
lastVote_->votes(
id);
737 v[jss::count] = votesFor;
738 v[jss::validations] = votesTotal;
741 v[jss::threshold] = votesNeeded;
771 auto a =
get(amendmentID, sl);
788 return std::make_unique<AmendmentTableImpl>(
789 app, 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.
Stream trace() const
Severity stream access functions.
std::optional< NetClock::time_point > firstUnsupportedExpected_
void readAmendments(soci::session &session, std::function< void(boost::optional< std::string > amendment_hash, boost::optional< std::string > amendment_name, boost::optional< int > vote_to_veto)> const &callback)
readAmendments Read all amendments from FeatureVotes table.
std::vector< uint256 > getDesired() const override
std::vector< uint256 > doValidation(std::set< uint256 > const &enabledAmendments) const override
bool createFeatureVotes(soci::session &session)
createFeatureVotes Creates FeatureVote table if it is not exists.
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
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
Integers of any length that is a multiple of 32-bits.
std::string const & name() const
Returns the name of this section.
T time_since_epoch(T... args)
void persistVote(uint256 const &amendment, std::string const &name, bool vote_to_veto) const
void voteAmendment(soci::session &session, uint256 const &amendment, std::string const &name, bool vote_to_veto)
voteAmendment Set veto value for particular amendment.
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
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
bool isSupported(uint256 const &amendment) const override
AmendmentTableImpl(Application &app, std::chrono::seconds majorityTime, Section const &supported, Section const &enabled, Section const &vetoed, beast::Journal journal)
std::unique_ptr< AmendmentTable > make_AmendmentTable(Application &app, std::chrono::seconds majorityTime, Section const &supported, Section const &enabled, Section const &vetoed, beast::Journal journal)
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.
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.
std::string to_string(Manifest const &m)
Format the specified manifest to a string for debugging purposes.
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.
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
const SF_VECTOR256 sfAmendments
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...