rippled
Loading...
Searching...
No Matches
AmendmentTable.h
1//------------------------------------------------------------------------------
2/*
3 This file is part of rippled: https://github.com/ripple/rippled
4 Copyright (c) 2012, 2013 Ripple Labs Inc.
5
6 Permission to use, copy, modify, and/or distribute this software for any
7 purpose with or without fee is hereby granted, provided that the above
8 copyright notice and this permission notice appear in all copies.
9
10 THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13 ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15 ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16 OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17*/
18//==============================================================================
19
20#ifndef RIPPLE_APP_MISC_AMENDMENTTABLE_H_INCLUDED
21#define RIPPLE_APP_MISC_AMENDMENTTABLE_H_INCLUDED
22
23#include <xrpld/app/ledger/Ledger.h>
24#include <xrpld/core/ConfigSections.h>
25
26#include <xrpl/protocol/Feature.h>
27#include <xrpl/protocol/Protocol.h>
28#include <xrpl/protocol/STValidation.h>
29
30#include <optional>
31
32namespace ripple {
33
39{
40public:
42 {
43 FeatureInfo() = delete;
45 : name(n), feature(f), vote(v)
46 {
47 }
48
52 };
53
54 virtual ~AmendmentTable() = default;
55
56 virtual uint256
57 find(std::string const& name) const = 0;
58
59 virtual bool
60 veto(uint256 const& amendment) = 0;
61 virtual bool
62 unVeto(uint256 const& amendment) = 0;
63
64 virtual bool
65 enable(uint256 const& amendment) = 0;
66
67 virtual bool
68 isEnabled(uint256 const& amendment) const = 0;
69 virtual bool
70 isSupported(uint256 const& amendment) const = 0;
71
78 virtual bool
80
83
84 virtual Json::Value
85 getJson(bool isAdmin) const = 0;
86
88 virtual Json::Value
89 getJson(uint256 const& amendment, bool isAdmin) const = 0;
90
92 void
94 std::shared_ptr<ReadView const> const& lastValidatedLedger)
95 {
96 if (needValidatedLedger(lastValidatedLedger->seq()))
98 lastValidatedLedger->seq(),
99 getEnabledAmendments(*lastValidatedLedger),
100 getMajorityAmendments(*lastValidatedLedger));
101 }
102
106 virtual bool
108
109 virtual void
111 LedgerIndex ledgerSeq,
112 std::set<uint256> const& enabled,
113 majorityAmendments_t const& majority) = 0;
114
115 // Called when the set of trusted validators changes.
116 virtual void
117 trustChanged(hash_set<PublicKey> const& allTrusted) = 0;
118
119 // Called by the consensus code when we need to
120 // inject pseudo-transactions
123 Rules const& rules,
124 NetClock::time_point closeTime,
125 std::set<uint256> const& enabledAmendments,
126 majorityAmendments_t const& majorityAmendments,
127 std::vector<std::shared_ptr<STValidation>> const& valSet) = 0;
128
129 // Called by the consensus code when we need to
130 // add feature entries to a validation
132 doValidation(std::set<uint256> const& enabled) const = 0;
133
134 // The set of amendments to enable in the genesis ledger
135 // This will return all known, non-vetoed amendments.
136 // If we ever have two amendments that should not both be
137 // enabled at the same time, we should ensure one is vetoed.
139 getDesired() const = 0;
140
141 // The function below adapts the API callers expect to the
142 // internal amendment table API. This allows the amendment
143 // table implementation to be independent of the ledger
144 // implementation. These APIs will merge when the view code
145 // supports a full ledger API
146
147 void
149 std::shared_ptr<ReadView const> const& lastClosedLedger,
150 std::vector<std::shared_ptr<STValidation>> const& parentValidations,
151 std::shared_ptr<SHAMap> const& initialPosition,
153 {
154 // Ask implementation what to do
155 auto actions = doVoting(
156 lastClosedLedger->rules(),
157 lastClosedLedger->parentCloseTime(),
158 getEnabledAmendments(*lastClosedLedger),
159 getMajorityAmendments(*lastClosedLedger),
160 parentValidations);
161
162 // Inject appropriate pseudo-transactions
163 for (auto const& it : actions)
164 {
165 STTx amendTx(
166 ttAMENDMENT,
167 [&it, seq = lastClosedLedger->seq() + 1](auto& obj) {
168 obj.setAccountID(sfAccount, AccountID());
169 obj.setFieldH256(sfAmendment, it.first);
170 obj.setFieldU32(sfLedgerSequence, seq);
171
172 if (it.second != 0)
173 obj.setFieldU32(sfFlags, it.second);
174 });
175
176 Serializer s;
177 amendTx.add(s);
178
179 JLOG(j.debug()) << "Amendments: Adding pseudo-transaction: "
180 << amendTx.getTransactionID() << ": "
181 << strHex(s.slice()) << ": " << amendTx;
182
183 initialPosition->addGiveItem(
185 make_shamapitem(amendTx.getTransactionID(), s.slice()));
186 }
187 }
188};
189
192 Application& app,
193 std::chrono::seconds majorityTime,
195 Section const& enabled,
196 Section const& vetoed,
197 beast::Journal journal);
198
199} // namespace ripple
200
201#endif
Represents a JSON value.
Definition: json_value.h:148
A generic endpoint for log messages.
Definition: Journal.h:60
Stream debug() const
Definition: Journal.h:328
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:35
void add(Serializer &s) const override
Definition: STObject.cpp:141
uint256 getTransactionID() const
Definition: STTx.h:194
Slice slice() const noexcept
Definition: Serializer.h:67
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition: algorithm.h:26
bool isAdmin(Port const &port, Json::Value const &params, beast::IP::Address const &remoteIp)
Definition: Role.cpp:85
std::set< uint256 > getEnabledAmendments(ReadView const &view)
Definition: View.cpp:796
std::string strHex(FwdIt begin, FwdIt end)
Definition: strHex.h:30
VoteBehavior
Definition: Feature.h:76
boost::intrusive_ptr< SHAMapItem > make_shamapitem(uint256 const &tag, Slice data)
Definition: SHAMapItem.h:161
majorityAmendments_t getMajorityAmendments(ReadView const &view)
Definition: View.cpp:813
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)