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