rippled
Loading...
Searching...
No Matches
AmendmentTable.h
1#pragma once
2
3#include <xrpld/app/ledger/Ledger.h>
4#include <xrpld/core/ConfigSections.h>
5
6#include <xrpl/core/ServiceRegistry.h>
7#include <xrpl/protocol/Feature.h>
8#include <xrpl/protocol/Protocol.h>
9#include <xrpl/protocol/STValidation.h>
10
11#include <optional>
12
13namespace xrpl {
14
20{
21public:
23 {
24 FeatureInfo() = delete;
25 FeatureInfo(std::string const& n, uint256 const& f, VoteBehavior v) : name(n), feature(f), vote(v)
26 {
27 }
28
32 };
33
34 virtual ~AmendmentTable() = default;
35
36 virtual uint256
37 find(std::string const& name) const = 0;
38
39 virtual bool
40 veto(uint256 const& amendment) = 0;
41 virtual bool
42 unVeto(uint256 const& amendment) = 0;
43
44 virtual bool
45 enable(uint256 const& amendment) = 0;
46
47 virtual bool
48 isEnabled(uint256 const& amendment) const = 0;
49 virtual bool
50 isSupported(uint256 const& amendment) const = 0;
51
58 virtual bool
60
63
64 virtual Json::Value
65 getJson(bool isAdmin) const = 0;
66
68 virtual Json::Value
69 getJson(uint256 const& amendment, bool isAdmin) const = 0;
70
72 void
74 {
75 if (needValidatedLedger(lastValidatedLedger->seq()))
77 lastValidatedLedger->seq(),
78 getEnabledAmendments(*lastValidatedLedger),
79 getMajorityAmendments(*lastValidatedLedger));
80 }
81
85 virtual bool
87
88 virtual void
90 LedgerIndex ledgerSeq,
91 std::set<uint256> const& enabled,
92 majorityAmendments_t const& majority) = 0;
93
94 // Called when the set of trusted validators changes.
95 virtual void
96 trustChanged(hash_set<PublicKey> const& allTrusted) = 0;
97
98 // Called by the consensus code when we need to
99 // inject pseudo-transactions
102 Rules const& rules,
103 NetClock::time_point closeTime,
104 std::set<uint256> const& enabledAmendments,
105 majorityAmendments_t const& majorityAmendments,
106 std::vector<std::shared_ptr<STValidation>> const& valSet) = 0;
107
108 // Called by the consensus code when we need to
109 // add feature entries to a validation
111 doValidation(std::set<uint256> const& enabled) const = 0;
112
113 // The set of amendments to enable in the genesis ledger
114 // This will return all known, non-vetoed amendments.
115 // If we ever have two amendments that should not both be
116 // enabled at the same time, we should ensure one is vetoed.
118 getDesired() const = 0;
119
120 // The function below adapts the API callers expect to the
121 // internal amendment table API. This allows the amendment
122 // table implementation to be independent of the ledger
123 // implementation. These APIs will merge when the view code
124 // supports a full ledger API
125
126 void
128 std::shared_ptr<ReadView const> const& lastClosedLedger,
129 std::vector<std::shared_ptr<STValidation>> const& parentValidations,
130 std::shared_ptr<SHAMap> const& initialPosition,
132 {
133 // Ask implementation what to do
134 auto actions = doVoting(
135 lastClosedLedger->rules(),
136 lastClosedLedger->parentCloseTime(),
137 getEnabledAmendments(*lastClosedLedger),
138 getMajorityAmendments(*lastClosedLedger),
139 parentValidations);
140
141 // Inject appropriate pseudo-transactions
142 for (auto const& it : actions)
143 {
144 STTx amendTx(ttAMENDMENT, [&it, seq = lastClosedLedger->seq() + 1](auto& obj) {
145 obj.setAccountID(sfAccount, AccountID());
146 obj.setFieldH256(sfAmendment, it.first);
147 obj.setFieldU32(sfLedgerSequence, seq);
148
149 if (it.second != 0)
150 obj.setFieldU32(sfFlags, it.second);
151 });
152
153 Serializer s;
154 amendTx.add(s);
155
156 JLOG(j.debug()) << "Amendments: Adding pseudo-transaction: " << amendTx.getTransactionID() << ": "
157 << strHex(s.slice()) << ": " << amendTx;
158
159 initialPosition->addGiveItem(
161 }
162 }
163};
164
167 ServiceRegistry& registry,
168 std::chrono::seconds majorityTime,
170 Section const& enabled,
171 Section const& vetoed,
172 beast::Journal journal);
173
174} // 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:300
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:117
uint256 getTransactionID() const
Definition STTx.h:192
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:839
boost::intrusive_ptr< SHAMapItem > make_shamapitem(uint256 const &tag, Slice data)
Definition SHAMapItem.h:137
std::string strHex(FwdIt begin, FwdIt end)
Definition strHex.h:10
VoteBehavior
Definition Feature.h:67
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:63
majorityAmendments_t getMajorityAmendments(ReadView const &view)
Definition View.cpp:856
FeatureInfo(std::string const &n, uint256 const &f, VoteBehavior v)