20#include <xrpl/protocol/Feature.h>
22#include <xrpl/basics/Slice.h>
23#include <xrpl/basics/contract.h>
24#include <xrpl/protocol/digest.h>
25#include <boost/container_hash/hash.hpp>
26#include <boost/multi_index/hashed_index.hpp>
27#include <boost/multi_index/key_extractors.hpp>
28#include <boost/multi_index/random_access_index.hpp>
29#include <boost/multi_index_container.hpp>
38 using namespace boost;
39 for (
auto const& n : feature)
40 hash_combine(seed, n);
75class FeatureCollections
84 : name(name_), feature(feature_)
103 template <
class tag,
typename Type, Type Feature::*PtrToMember>
104 using feature_hashed_unique = boost::multi_index::hashed_unique<
105 boost::multi_index::tag<tag>,
106 boost::multi_index::member<Feature, Type, PtrToMember>>;
109 using feature_indexing = boost::multi_index::indexed_by<
110 boost::multi_index::random_access<
111 boost::multi_index::tag<Feature::byIndex>>,
112 feature_hashed_unique<Feature::byFeature, uint256, &Feature::feature>,
113 feature_hashed_unique<Feature::byName, std::string, &Feature::name>>;
117 boost::multi_index::multi_index_container<Feature, feature_indexing>
129 getByIndex(
size_t i)
const
131 if (i >= features.size())
133 const auto& sequence = features.get<Feature::byIndex>();
137 getIndex(Feature
const& feature)
const
139 const auto& sequence = features.get<Feature::byIndex>();
140 auto const it_to = sequence.iterator_to(feature);
141 return it_to - sequence.begin();
144 getByFeature(
uint256 const& feature)
const
146 const auto& feature_index = features.get<Feature::byFeature>();
147 auto const feature_it = feature_index.find(feature);
148 return feature_it == feature_index.end() ? nullptr : &*feature_it;
153 const auto& name_index = features.get<Feature::byName>();
154 auto const name_it = name_index.find(name);
155 return name_it == name_index.end() ? nullptr : &*name_it;
159 FeatureCollections();
216FeatureCollections::FeatureCollections()
222FeatureCollections::getRegisteredFeature(
std::string const& name)
const
226 "ripple::FeatureCollections::getRegisteredFeature : startup completed");
227 Feature
const* feature = getByName(name);
229 return feature->feature;
234check(
bool condition,
const char* logicErrorMessage)
241FeatureCollections::registerFeature(
246 check(!readOnly,
"Attempting to register a feature after startup.");
249 "Invalid feature parameters. Must be supported to be up-voted.");
250 Feature
const* i = getByName(name);
257 "More features defined than allocated. Adjust numFeatures in "
262 features.emplace_back(name, f);
264 auto const getAmendmentSupport = [=]() {
270 all.emplace(name, getAmendmentSupport());
272 if (support == Supported::yes)
274 supported.emplace(name, vote);
282 upVotes + downVotes == supported.size(),
283 "Feature counting logic broke");
285 supported.size() <= features.size(),
286 "More supported features than defined features");
288 features.size() ==
all.size(),
289 "The 'all' features list is populated incorrectly");
299FeatureCollections::registrationIsDone()
306FeatureCollections::featureToBitsetIndex(
uint256 const& f)
const
310 "ripple::FeatureCollections::featureToBitsetIndex : startup completed");
312 Feature
const* feature = getByFeature(f);
316 return getIndex(*feature);
320FeatureCollections::bitsetIndexToFeature(
size_t i)
const
324 "ripple::FeatureCollections::bitsetIndexToFeature : startup completed");
325 Feature
const& feature = getByIndex(i);
326 return feature.feature;
330FeatureCollections::featureToName(
uint256 const& f)
const
334 "ripple::FeatureCollections::featureToName : startup completed");
335 Feature
const* feature = getByFeature(f);
336 return feature ? feature->name :
to_string(f);
339static FeatureCollections featureCollections;
347 return featureCollections.allAmendments();
356 return featureCollections.supportedAmendments();
363 return featureCollections.numDownVotedAmendments();
370 return featureCollections.numUpVotedAmendments();
378 return featureCollections.getRegisteredFeature(name);
384 return featureCollections.registerFeature(name, support, vote);
399 return featureCollections.registrationIsDone();
405 return featureCollections.featureToBitsetIndex(f);
411 return featureCollections.bitsetIndexToFeature(i);
417 return featureCollections.featureToName(f);
423#pragma push_macro("XRPL_FEATURE")
425#pragma push_macro("XRPL_FIX")
428#define XRPL_FEATURE(name, supported, vote) \
429 uint256 const feature##name = registerFeature(#name, supported, vote);
430#define XRPL_FIX(name, supported, vote) \
431 uint256 const fix##name = registerFeature("fix" #name, supported, vote);
433#include <xrpl/protocol/detail/features.macro>
436#pragma pop_macro("XRPL_FIX")
438#pragma pop_macro("XRPL_FEATURE")
446[[deprecated(
"The referenced amendment has been retired"), maybe_unused]]
472 featureCollections.registrationIsDone();
void check(bool condition, std::string const &message)
static constexpr std::size_t numFeatures
std::size_t numUpVotedAmendments()
Amendments that this server will vote for by default.
std::size_t numDownVotedAmendments()
Amendments that this server won't vote for by default.
std::map< std::string, VoteBehavior > const & supportedAmendments()
Amendments that this server supports and the default voting behavior.
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
uint256 const retiredFeeEscalation
uint256 const retiredFix1528
uint256 const retiredFix1368
uint256 bitsetIndexToFeature(size_t i)
uint256 const retiredFix1512
static const bool readOnlySet
uint256 const retiredTrustSetAuth
uint256 registerFeature(std::string const &name, Supported support, VoteBehavior vote)
uint256 const retiredCryptoConditions
uint256 const retiredSortedDirectories
uint256 const retiredFix1523
size_t featureToBitsetIndex(uint256 const &f)
std::map< std::string, AmendmentSupport > const & allAmendments()
All amendments libxrpl knows about.
std::size_t hash_value(ripple::uint256 const &feature)
uint256 const retiredFix1373
uint256 retireFeature(std::string const &name)
uint256 const retiredEscrow
std::string featureToName(uint256 const &f)
std::optional< uint256 > getRegisteredFeature(std::string const &name)
uint256 const retiredFix1201
std::string to_string(base_uint< Bits, Tag > const &a)
bool registrationIsDone()
Tell FeatureCollections when registration is complete.
uint256 const retiredMultiSign
uint256 const retiredTickSize
uint256 const retiredPayChan
sha512_half_hasher::result_type sha512Half(Args const &... args)
Returns the SHA512-Half of a series of objects.
uint256 const retiredEnforceInvariants
void LogicError(std::string const &how) noexcept
Called when faulty logic causes a broken invariant.