xrpld
Loading...
Searching...
No Matches
AmendmentTable.h
1#pragma once
2
3#include <xrpl/ledger/ReadView.h>
4#include <xrpl/ledger/View.h>
5#include <xrpl/protocol/Feature.h>
6#include <xrpl/protocol/Protocol.h>
7#include <xrpl/protocol/STValidation.h>
8#include <xrpl/shamap/SHAMap.h>
9
10#include <optional>
11#include <utility>
12
13namespace xrpl {
14
15class ServiceRegistry;
16
22{
23public:
25 {
26 FeatureInfo() = delete;
28 : name(std::move(n)), feature(f), vote(v)
29 {
30 }
31
35 };
36
37 virtual ~AmendmentTable() = default;
38
39 [[nodiscard]] virtual uint256
40 find(std::string const& name) const = 0;
41
42 virtual bool
43 veto(uint256 const& amendment) = 0;
44 virtual bool
45 unVeto(uint256 const& amendment) = 0;
46
47 virtual bool
48 enable(uint256 const& amendment) = 0;
49
50 [[nodiscard]] virtual bool
51 isEnabled(uint256 const& amendment) const = 0;
52 [[nodiscard]] virtual bool
53 isSupported(uint256 const& amendment) const = 0;
54
61 [[nodiscard]] virtual bool
63
64 [[nodiscard]] virtual std::optional<NetClock::time_point>
66
67 [[nodiscard]] virtual json::Value
68 getJson(bool isAdmin) const = 0;
69
71 [[nodiscard]] virtual json::Value
72 getJson(uint256 const& amendment, bool isAdmin) const = 0;
73
75 void
77 {
78 if (needValidatedLedger(lastValidatedLedger->seq()))
79 {
81 lastValidatedLedger->seq(),
82 getEnabledAmendments(*lastValidatedLedger),
83 getMajorityAmendments(*lastValidatedLedger));
84 }
85 }
86
90 [[nodiscard]] virtual bool
92
93 virtual void
95 LedgerIndex ledgerSeq,
96 std::set<uint256> const& enabled,
97 majorityAmendments_t const& majority) = 0;
98
99 // Called when the set of trusted validators changes.
100 virtual void
101 trustChanged(hash_set<PublicKey> const& allTrusted) = 0;
102
103 // Called by the consensus code when we need to
104 // inject pseudo-transactions
107 Rules const& rules,
108 NetClock::time_point closeTime,
109 std::set<uint256> const& enabledAmendments,
110 majorityAmendments_t const& majorityAmendments,
111 std::vector<std::shared_ptr<STValidation>> const& valSet) = 0;
112
113 // Called by the consensus code when we need to
114 // add feature entries to a validation
115 [[nodiscard]] virtual std::vector<uint256>
116 doValidation(std::set<uint256> const& enabled) const = 0;
117
118 // The set of amendments to enable in the genesis ledger
119 // This will return all known, non-vetoed amendments.
120 // If we ever have two amendments that should not both be
121 // enabled at the same time, we should ensure one is vetoed.
122 [[nodiscard]] virtual std::vector<uint256>
123 getDesired() const = 0;
124
125 // The function below adapts the API callers expect to the
126 // internal amendment table API. This allows the amendment
127 // table implementation to be independent of the ledger
128 // implementation. These APIs will merge when the view code
129 // supports a full ledger API
130
131 void
133 std::shared_ptr<ReadView const> const& lastClosedLedger,
134 std::vector<std::shared_ptr<STValidation>> const& parentValidations,
135 std::shared_ptr<SHAMap> const& initialPosition,
137 {
138 // Ask implementation what to do
139 auto actions = doVoting(
140 lastClosedLedger->rules(),
141 lastClosedLedger->parentCloseTime(),
142 getEnabledAmendments(*lastClosedLedger),
143 getMajorityAmendments(*lastClosedLedger),
144 parentValidations);
145
146 // Inject appropriate pseudo-transactions
147 for (auto const& it : actions)
148 {
149 STTx const amendTx(ttAMENDMENT, [&it, seq = lastClosedLedger->seq() + 1](auto& obj) {
150 obj.setAccountID(sfAccount, AccountID());
151 obj.setFieldH256(sfAmendment, it.first);
152 obj.setFieldU32(sfLedgerSequence, seq);
153
154 if (it.second != 0)
155 obj.setFieldU32(sfFlags, it.second);
156 });
157
158 Serializer s;
159 amendTx.add(s);
160
161 JLOG(j.debug()) << "Amendments: Adding pseudo-transaction: "
162 << amendTx.getTransactionID() << ": " << strHex(s.slice()) << ": "
163 << amendTx;
164
165 initialPosition->addGiveItem(
167 makeShamapitem(amendTx.getTransactionID(), s.slice()));
168 }
169 }
170};
171
174 ServiceRegistry& registry,
175 std::chrono::seconds majorityTime,
177 Section const& enabled,
178 Section const& vetoed,
179 beast::Journal journal);
180
181} // namespace xrpl
A generic endpoint for log messages.
Definition Journal.h:38
Stream debug() const
Definition Journal.h:297
Represents a JSON value.
Definition json_value.h:130
The amendment table stores the list of enabled and potential amendments.
virtual bool isSupported(uint256 const &amendment) const =0
virtual std::vector< uint256 > doValidation(std::set< uint256 > const &enabled) const =0
virtual bool unVeto(uint256 const &amendment)=0
virtual ~AmendmentTable()=default
virtual bool isEnabled(uint256 const &amendment) const =0
virtual bool hasUnsupportedEnabled() const =0
returns true if one or more amendments on the network have been enabled that this server does not sup...
virtual std::vector< uint256 > getDesired() const =0
void doValidatedLedger(std::shared_ptr< ReadView const > const &lastValidatedLedger)
Called when a new fully-validated ledger is accepted.
virtual bool veto(uint256 const &amendment)=0
virtual bool needValidatedLedger(LedgerIndex seq) const =0
Called to determine whether the amendment logic needs to process a new validated ledger.
virtual json::Value getJson(bool isAdmin) const =0
virtual std::optional< NetClock::time_point > firstUnsupportedExpected() const =0
virtual bool enable(uint256 const &amendment)=0
virtual void trustChanged(hash_set< PublicKey > const &allTrusted)=0
virtual 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 &valSet)=0
virtual void doValidatedLedger(LedgerIndex ledgerSeq, std::set< uint256 > const &enabled, majorityAmendments_t const &majority)=0
void doVoting(std::shared_ptr< ReadView const > const &lastClosedLedger, std::vector< std::shared_ptr< STValidation > > const &parentValidations, std::shared_ptr< SHAMap > const &initialPosition, beast::Journal j)
virtual json::Value getJson(uint256 const &amendment, bool isAdmin) const =0
Returns a json::ValueType::Object.
virtual uint256 find(std::string const &name) const =0
std::chrono::time_point< NetClock > time_point
Definition chrono.h:46
Rules controlling protocol behavior.
Definition Rules.h:33
void add(Serializer &s) const override
Definition STObject.cpp:120
uint256 getTransactionID() const
Definition STTx.h:200
Slice slice() const noexcept
Definition Serializer.h:44
Service registry for dependency injection.
STL namespace.
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:5
std::unique_ptr< AmendmentTable > makeAmendmentTable(ServiceRegistry &registry, std::chrono::seconds majorityTime, std::vector< AmendmentTable::FeatureInfo > const &supported, Section const &enabled, Section const &vetoed, beast::Journal journal)
std::set< uint256 > getEnabledAmendments(ReadView const &view)
Definition View.cpp:231
std::uint32_t LedgerIndex
A ledger index.
Definition Protocol.h:259
std::string strHex(FwdIt begin, FwdIt end)
Definition strHex.h:10
VoteBehavior
Definition Feature.h:110
std::unordered_set< Value, Hash, Pred, Allocator > hash_set
boost::intrusive_ptr< SHAMapItem > makeShamapitem(uint256 const &tag, Slice data)
Definition SHAMapItem.h:139
majorityAmendments_t getMajorityAmendments(ReadView const &view)
Definition View.cpp:248
std::map< uint256, NetClock::time_point > majorityAmendments_t
Definition View.h:73
bool isAdmin(Port const &port, json::Value const &params, beast::IP::Address const &remoteIp)
Definition Role.cpp:81
BaseUInt< 256 > uint256
Definition base_uint.h:562
FeatureInfo(std::string n, uint256 const &f, VoteBehavior v)