xrpld
Loading...
Searching...
No Matches
AmendmentTable.h
1#pragma once
2
3#include <xrpl/basics/Log.h>
4#include <xrpl/basics/UnorderedContainers.h>
5#include <xrpl/basics/base_uint.h>
6#include <xrpl/basics/chrono.h>
7#include <xrpl/basics/strHex.h>
8#include <xrpl/beast/utility/Journal.h>
9#include <xrpl/json/json_value.h>
10#include <xrpl/ledger/ReadView.h>
11#include <xrpl/ledger/View.h>
12#include <xrpl/nodestore/Database.h>
13#include <xrpl/protocol/Feature.h>
14#include <xrpl/protocol/Protocol.h>
15#include <xrpl/protocol/PublicKey.h>
16#include <xrpl/protocol/Rules.h>
17#include <xrpl/protocol/SField.h>
18#include <xrpl/protocol/STTx.h>
19#include <xrpl/protocol/STValidation.h>
20#include <xrpl/protocol/Serializer.h>
21#include <xrpl/protocol/TxFormats.h>
22#include <xrpl/shamap/SHAMap.h>
23#include <xrpl/shamap/SHAMapItem.h>
24#include <xrpl/shamap/SHAMapTreeNode.h>
25
26#include <chrono>
27#include <cstdint>
28#include <map>
29#include <memory>
30#include <optional>
31#include <set>
32#include <string>
33#include <utility>
34#include <vector>
35
36namespace xrpl {
37
38class ServiceRegistry;
39
46{
47public:
49 {
50 FeatureInfo() = delete;
52 : name(std::move(n)), feature(f), vote(v)
53 {
54 }
55
59 };
60
61 virtual ~AmendmentTable() = default;
62
63 [[nodiscard]] virtual uint256
64 find(std::string const& name) const = 0;
65
66 virtual bool
67 veto(uint256 const& amendment) = 0;
68 virtual bool
69 unVeto(uint256 const& amendment) = 0;
70
71 virtual bool
72 enable(uint256 const& amendment) = 0;
73
74 [[nodiscard]] virtual bool
75 isEnabled(uint256 const& amendment) const = 0;
76 [[nodiscard]] virtual bool
77 isSupported(uint256 const& amendment) const = 0;
78
85 [[nodiscard]] virtual bool
87
88 [[nodiscard]] virtual std::optional<NetClock::time_point>
90
91 [[nodiscard]] virtual json::Value
92 getJson(bool isAdmin) const = 0;
93
97 [[nodiscard]] virtual json::Value
98 getJson(uint256 const& amendment, bool isAdmin) const = 0;
99
103 void
105 {
106 if (needValidatedLedger(lastValidatedLedger->seq()))
107 {
109 lastValidatedLedger->seq(),
110 getEnabledAmendments(*lastValidatedLedger),
111 getMajorityAmendments(*lastValidatedLedger));
112 }
113 }
114
119 [[nodiscard]] virtual bool
121
122 virtual void
124 LedgerIndex ledgerSeq,
125 std::set<uint256> const& enabled,
126 majorityAmendments_t const& majority) = 0;
127
128 // Called when the set of trusted validators changes.
129 virtual void
130 trustChanged(hash_set<PublicKey> const& allTrusted) = 0;
131
132 // Called by the consensus code when we need to
133 // inject pseudo-transactions
136 Rules const& rules,
137 NetClock::time_point closeTime,
138 std::set<uint256> const& enabledAmendments,
139 majorityAmendments_t const& majorityAmendments,
140 std::vector<std::shared_ptr<STValidation>> const& valSet) = 0;
141
142 // Called by the consensus code when we need to
143 // add feature entries to a validation
144 [[nodiscard]] virtual std::vector<uint256>
145 doValidation(std::set<uint256> const& enabled) const = 0;
146
147 // The set of amendments to enable in the genesis ledger
148 // This will return all known, non-vetoed amendments.
149 // If we ever have two amendments that should not both be
150 // enabled at the same time, we should ensure one is vetoed.
151 [[nodiscard]] virtual std::vector<uint256>
152 getDesired() const = 0;
153
154 // The function below adapts the API callers expect to the
155 // internal amendment table API. This allows the amendment
156 // table implementation to be independent of the ledger
157 // implementation. These APIs will merge when the view code
158 // supports a full ledger API
159
160 void
162 std::shared_ptr<ReadView const> const& lastClosedLedger,
163 std::vector<std::shared_ptr<STValidation>> const& parentValidations,
164 std::shared_ptr<SHAMap> const& initialPosition,
166 {
167 // Ask implementation what to do
168 auto actions = doVoting(
169 lastClosedLedger->rules(),
170 lastClosedLedger->parentCloseTime(),
171 getEnabledAmendments(*lastClosedLedger),
172 getMajorityAmendments(*lastClosedLedger),
173 parentValidations);
174
175 // Inject appropriate pseudo-transactions
176 for (auto const& it : actions)
177 {
178 STTx const amendTx(ttAMENDMENT, [&it, seq = lastClosedLedger->seq() + 1](auto& obj) {
179 obj.setAccountID(sfAccount, AccountID());
180 obj.setFieldH256(sfAmendment, it.first);
181 obj.setFieldU32(sfLedgerSequence, seq);
182
183 if (it.second != 0)
184 obj.setFieldU32(sfFlags, it.second);
185 });
186
187 Serializer s;
188 amendTx.add(s);
189
190 JLOG(j.debug()) << "Amendments: Adding pseudo-transaction: "
191 << amendTx.getTransactionID() << ": " << strHex(s.slice()) << ": "
192 << amendTx;
193
194 initialPosition->addGiveItem(
196 makeShamapitem(amendTx.getTransactionID(), s.slice()));
197 }
198 }
199};
200
203 ServiceRegistry& registry,
204 std::chrono::seconds majorityTime,
206 Section const& enabled,
207 Section const& vetoed,
208 beast::Journal journal);
209
210} // namespace xrpl
A generic endpoint for log messages.
Definition Journal.h:44
Stream debug() const
Definition Journal.h:344
Represents a JSON value.
Definition json_value.h:117
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:48
Rules controlling protocol behavior.
Definition Rules.h:40
void add(Serializer &s) const override
Definition STObject.cpp:123
uint256 getTransactionID() const
Definition STTx.h:238
Slice slice() const noexcept
Definition Serializer.h:45
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:240
std::uint32_t LedgerIndex
A ledger index.
Definition Protocol.h:370
std::string strHex(FwdIt begin, FwdIt end)
Definition strHex.h:13
VoteBehavior
Definition Feature.h:112
std::unordered_set< Value, Hash, Pred, Allocator > hash_set
boost::intrusive_ptr< SHAMapItem > makeShamapitem(uint256 const &tag, Slice data)
Definition SHAMapItem.h:148
majorityAmendments_t getMajorityAmendments(ReadView const &view)
Definition View.cpp:257
bool isAdmin(Port const &port, json::Value const &params, beast::ip::Address const &remoteIp)
Definition Role.cpp:81
std::map< uint256, NetClock::time_point > majorityAmendments_t
Definition View.h:93
BaseUInt< 256 > uint256
Definition base_uint.h:580
FeatureInfo(std::string n, uint256 const &f, VoteBehavior v)