rippled
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
12namespace xrpl {
13
14class ServiceRegistry;
15
21{
22public:
24 {
25 FeatureInfo() = delete;
27 : name(n), feature(f), vote(v)
28 {
29 }
30
34 };
35
36 virtual ~AmendmentTable() = default;
37
38 virtual uint256
39 find(std::string const& name) const = 0;
40
41 virtual bool
42 veto(uint256 const& amendment) = 0;
43 virtual bool
44 unVeto(uint256 const& amendment) = 0;
45
46 virtual bool
47 enable(uint256 const& amendment) = 0;
48
49 virtual bool
50 isEnabled(uint256 const& amendment) const = 0;
51 virtual bool
52 isSupported(uint256 const& amendment) const = 0;
53
60 virtual bool
62
65
66 virtual Json::Value
67 getJson(bool isAdmin) const = 0;
68
70 virtual Json::Value
71 getJson(uint256 const& amendment, bool isAdmin) const = 0;
72
74 void
76 {
77 if (needValidatedLedger(lastValidatedLedger->seq()))
79 lastValidatedLedger->seq(),
80 getEnabledAmendments(*lastValidatedLedger),
81 getMajorityAmendments(*lastValidatedLedger));
82 }
83
87 virtual bool
89
90 virtual void
92 LedgerIndex ledgerSeq,
93 std::set<uint256> const& enabled,
94 majorityAmendments_t const& majority) = 0;
95
96 // Called when the set of trusted validators changes.
97 virtual void
98 trustChanged(hash_set<PublicKey> const& allTrusted) = 0;
99
100 // Called by the consensus code when we need to
101 // inject pseudo-transactions
104 Rules const& rules,
105 NetClock::time_point closeTime,
106 std::set<uint256> const& enabledAmendments,
107 majorityAmendments_t const& majorityAmendments,
108 std::vector<std::shared_ptr<STValidation>> const& valSet) = 0;
109
110 // Called by the consensus code when we need to
111 // add feature entries to a validation
113 doValidation(std::set<uint256> const& enabled) const = 0;
114
115 // The set of amendments to enable in the genesis ledger
116 // This will return all known, non-vetoed amendments.
117 // If we ever have two amendments that should not both be
118 // enabled at the same time, we should ensure one is vetoed.
120 getDesired() const = 0;
121
122 // The function below adapts the API callers expect to the
123 // internal amendment table API. This allows the amendment
124 // table implementation to be independent of the ledger
125 // implementation. These APIs will merge when the view code
126 // supports a full ledger API
127
128 void
130 std::shared_ptr<ReadView const> const& lastClosedLedger,
131 std::vector<std::shared_ptr<STValidation>> const& parentValidations,
132 std::shared_ptr<SHAMap> const& initialPosition,
134 {
135 // Ask implementation what to do
136 auto actions = doVoting(
137 lastClosedLedger->rules(),
138 lastClosedLedger->parentCloseTime(),
139 getEnabledAmendments(*lastClosedLedger),
140 getMajorityAmendments(*lastClosedLedger),
141 parentValidations);
142
143 // Inject appropriate pseudo-transactions
144 for (auto const& it : actions)
145 {
146 STTx const amendTx(ttAMENDMENT, [&it, seq = lastClosedLedger->seq() + 1](auto& obj) {
147 obj.setAccountID(sfAccount, AccountID());
148 obj.setFieldH256(sfAmendment, it.first);
149 obj.setFieldU32(sfLedgerSequence, seq);
150
151 if (it.second != 0)
152 obj.setFieldU32(sfFlags, it.second);
153 });
154
155 Serializer s;
156 amendTx.add(s);
157
158 JLOG(j.debug()) << "Amendments: Adding pseudo-transaction: "
159 << amendTx.getTransactionID() << ": " << strHex(s.slice()) << ": "
160 << amendTx;
161
162 initialPosition->addGiveItem(
164 make_shamapitem(amendTx.getTransactionID(), s.slice()));
165 }
166 }
167};
168
171 ServiceRegistry& registry,
172 std::chrono::seconds majorityTime,
174 Section const& enabled,
175 Section const& vetoed,
176 beast::Journal journal);
177
178} // namespace xrpl
Represents a JSON value.
Definition json_value.h:130
A generic endpoint for log messages.
Definition Journal.h:40
Stream debug() const
Definition Journal.h:301
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 Json::Value getJson(uint256 const &amendment, bool isAdmin) const =0
Returns a Json::objectValue.
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 Json::Value getJson(bool isAdmin) const =0
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 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 uint256 find(std::string const &name) const =0
Rules controlling protocol behavior.
Definition Rules.h:18
void add(Serializer &s) const override
Definition STObject.cpp:119
uint256 getTransactionID() const
Definition STTx.h:200
Slice slice() const noexcept
Definition Serializer.h:44
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:5
std::set< uint256 > getEnabledAmendments(ReadView const &view)
Definition View.cpp:193
boost::intrusive_ptr< SHAMapItem > make_shamapitem(uint256 const &tag, Slice data)
Definition SHAMapItem.h:139
std::string strHex(FwdIt begin, FwdIt end)
Definition strHex.h:10
VoteBehavior
Definition Feature.h:110
std::unique_ptr< AmendmentTable > make_AmendmentTable(ServiceRegistry &registry, std::chrono::seconds majorityTime, std::vector< AmendmentTable::FeatureInfo > const &supported, Section const &enabled, Section const &vetoed, beast::Journal journal)
bool isAdmin(Port const &port, Json::Value const &params, beast::IP::Address const &remoteIp)
Definition Role.cpp:64
majorityAmendments_t getMajorityAmendments(ReadView const &view)
Definition View.cpp:210
FeatureInfo(std::string const &n, uint256 const &f, VoteBehavior v)