Skip to content

Commit

Permalink
Refactor Feature name management and creation:
Browse files Browse the repository at this point in the history
* Only require adding the new feature names in one place. (Also need to
  increment a counter, but a check on startup will catch that.)
* Allows rippled to have the code to support a given amendment, but
  not vote for it by default. This allows the amendment to be enabled in
  a future version without necessarily amendment blocking these older
  versions.
* The default vote is carried with the amendment name in the list of
  supported amendments.
* The amendment table is constructed with the amendment and default
  vote.
  • Loading branch information
ximinez committed Oct 2, 2021
1 parent 8a25f32 commit 5e11ad5
Show file tree
Hide file tree
Showing 13 changed files with 831 additions and 484 deletions.
34 changes: 18 additions & 16 deletions src/ripple/app/main/Application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1250,27 +1250,29 @@ ApplicationImp::setup()

// Configure the amendments the server supports
{
auto const& sa = detail::supportedAmendments();
std::vector<std::string> saHashes;
saHashes.reserve(sa.size());
for (auto const& name : sa)
{
auto const f = getRegisteredFeature(name);
BOOST_ASSERT(f);
if (f)
saHashes.push_back(to_string(*f) + " " + name);
}
Section supportedAmendments("Supported Amendments");
supportedAmendments.append(saHashes);
auto const supported = []() {
auto const& amendments = detail::supportedAmendments();
std::vector<AmendmentTable::FeatureInfo> supported;
supported.reserve(amendments.size());
for (auto const& [a, vote] : amendments)
{
auto const f = ripple::getRegisteredFeature(a);
assert(f);
if (f)
supported.emplace_back(a, *f, vote);
}
return supported;
}();
Section const& downVoted = config_->section(SECTION_VETO_AMENDMENTS);

Section enabledAmendments = config_->section(SECTION_AMENDMENTS);
Section const& upVoted = config_->section(SECTION_AMENDMENTS);

m_amendmentTable = make_AmendmentTable(
*this,
config().AMENDMENT_MAJORITY_TIME,
supportedAmendments,
enabledAmendments,
config_->section(SECTION_VETO_AMENDMENTS),
supported,
upVoted,
downVoted,
logs_->journal("Amendments"));
}

Expand Down
16 changes: 15 additions & 1 deletion src/ripple/app/misc/AmendmentTable.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

#include <ripple/app/ledger/Ledger.h>
#include <ripple/core/ConfigSections.h>
#include <ripple/protocol/Feature.h>
#include <ripple/protocol/Protocol.h>
#include <ripple/protocol/STValidation.h>

Expand All @@ -36,6 +37,19 @@ namespace ripple {
class AmendmentTable
{
public:
struct FeatureInfo
{
FeatureInfo() = delete;
FeatureInfo(std::string const& n, uint256 const& f, DefaultVote v)
: name(n), feature(f), vote(v)
{
}

std::string const name;
uint256 const feature;
DefaultVote const vote;
};

virtual ~AmendmentTable() = default;

virtual uint256
Expand Down Expand Up @@ -168,7 +182,7 @@ std::unique_ptr<AmendmentTable>
make_AmendmentTable(
Application& app,
std::chrono::seconds majorityTime,
Section const& supported,
std::vector<AmendmentTable::FeatureInfo> const& supported,
Section const& enabled,
Section const& vetoed,
beast::Journal journal);
Expand Down
Loading

0 comments on commit 5e11ad5

Please sign in to comment.