rippled
Loading...
Searching...
No Matches
AmendmentTable.h
1#ifndef XRPL_APP_MISC_AMENDMENTTABLE_H_INCLUDED
2#define XRPL_APP_MISC_AMENDMENTTABLE_H_INCLUDED
3
4#include <xrpld/app/ledger/Ledger.h>
5#include <xrpld/core/ConfigSections.h>
6
7#include <xrpl/protocol/Feature.h>
8#include <xrpl/protocol/Protocol.h>
9#include <xrpl/protocol/STValidation.h>
10
11#include <optional>
12
13namespace ripple {
14
20{
21public:
23 {
24 FeatureInfo() = delete;
26 : name(n), feature(f), vote(v)
27 {
28 }
29
33 };
34
35 virtual ~AmendmentTable() = default;
36
37 virtual uint256
38 find(std::string const& name) const = 0;
39
40 virtual bool
41 veto(uint256 const& amendment) = 0;
42 virtual bool
43 unVeto(uint256 const& amendment) = 0;
44
45 virtual bool
46 enable(uint256 const& amendment) = 0;
47
48 virtual bool
49 isEnabled(uint256 const& amendment) const = 0;
50 virtual bool
51 isSupported(uint256 const& amendment) const = 0;
52
59 virtual bool
61
64
65 virtual Json::Value
66 getJson(bool isAdmin) const = 0;
67
69 virtual Json::Value
70 getJson(uint256 const& amendment, bool isAdmin) const = 0;
71
73 void
75 std::shared_ptr<ReadView const> const& lastValidatedLedger)
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 amendTx(
147 ttAMENDMENT,
148 [&it, seq = lastClosedLedger->seq() + 1](auto& obj) {
149 obj.setAccountID(sfAccount, AccountID());
150 obj.setFieldH256(sfAmendment, it.first);
151 obj.setFieldU32(sfLedgerSequence, seq);
152
153 if (it.second != 0)
154 obj.setFieldU32(sfFlags, it.second);
155 });
156
157 Serializer s;
158 amendTx.add(s);
159
160 JLOG(j.debug()) << "Amendments: Adding pseudo-transaction: "
161 << amendTx.getTransactionID() << ": "
162 << strHex(s.slice()) << ": " << amendTx;
163
164 initialPosition->addGiveItem(
166 make_shamapitem(amendTx.getTransactionID(), s.slice()));
167 }
168 }
169};
170
173 Application& app,
174 std::chrono::seconds majorityTime,
176 Section const& enabled,
177 Section const& vetoed,
178 beast::Journal journal);
179
180} // namespace ripple
181
182#endif
Represents a JSON value.
Definition json_value.h:130
A generic endpoint for log messages.
Definition Journal.h:41
Stream debug() const
Definition Journal.h:309
The amendment table stores the list of enabled and potential amendments.
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 void trustChanged(hash_set< PublicKey > const &allTrusted)=0
virtual Json::Value getJson(uint256 const &amendment, bool isAdmin) const =0
Returns a Json::objectValue.
virtual std::vector< uint256 > doValidation(std::set< uint256 > const &enabled) const =0
virtual void doValidatedLedger(LedgerIndex ledgerSeq, std::set< uint256 > const &enabled, majorityAmendments_t const &majority)=0
virtual std::optional< NetClock::time_point > firstUnsupportedExpected() const =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 bool veto(uint256 const &amendment)=0
virtual std::vector< uint256 > getDesired() const =0
virtual bool isSupported(uint256 const &amendment) const =0
virtual Json::Value getJson(bool isAdmin) 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...
void doValidatedLedger(std::shared_ptr< ReadView const > const &lastValidatedLedger)
Called when a new fully-validated ledger is accepted.
virtual bool enable(uint256 const &amendment)=0
virtual uint256 find(std::string const &name) const =0
virtual bool unVeto(uint256 const &amendment)=0
virtual bool isEnabled(uint256 const &amendment) const =0
virtual bool needValidatedLedger(LedgerIndex seq) const =0
Called to determine whether the amendment logic needs to process a new validated ledger.
virtual ~AmendmentTable()=default
Rules controlling protocol behavior.
Definition Rules.h:19
void add(Serializer &s) const override
Definition STObject.cpp:122
uint256 getTransactionID() const
Definition STTx.h:230
Slice slice() const noexcept
Definition Serializer.h:47
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:6
bool isAdmin(Port const &port, Json::Value const &params, beast::IP::Address const &remoteIp)
Definition Role.cpp:66
std::set< uint256 > getEnabledAmendments(ReadView const &view)
Definition View.cpp:902
std::string strHex(FwdIt begin, FwdIt end)
Definition strHex.h:11
VoteBehavior
Definition Feature.h:68
boost::intrusive_ptr< SHAMapItem > make_shamapitem(uint256 const &tag, Slice data)
Definition SHAMapItem.h:142
majorityAmendments_t getMajorityAmendments(ReadView const &view)
Definition View.cpp:919
std::unique_ptr< AmendmentTable > make_AmendmentTable(Application &app, std::chrono::seconds majorityTime, std::vector< AmendmentTable::FeatureInfo > const &supported, Section const &enabled, Section const &vetoed, beast::Journal journal)
FeatureInfo(std::string const &n, uint256 const &f, VoteBehavior v)