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#include <xrpl/protocol/Feature.h>
26#include <xrpl/protocol/Protocol.h>
27#include <xrpl/protocol/STValidation.h>
28
29#include <optional>
30
31namespace ripple {
32
38{
39public:
41 {
42 FeatureInfo() = delete;
44 : name(n), feature(f), vote(v)
45 {
46 }
47
51 };
52
53 virtual ~AmendmentTable() = default;
54
55 virtual uint256
56 find(std::string const& name) const = 0;
57
58 virtual bool
59 veto(uint256 const& amendment) = 0;
60 virtual bool
61 unVeto(uint256 const& amendment) = 0;
62
63 virtual bool
64 enable(uint256 const& amendment) = 0;
65
66 virtual bool
67 isEnabled(uint256 const& amendment) const = 0;
68 virtual bool
69 isSupported(uint256 const& amendment) const = 0;
70
77 virtual bool
79
82
83 virtual Json::Value
84 getJson(bool isAdmin) const = 0;
85
87 virtual Json::Value
88 getJson(uint256 const& amendment, bool isAdmin) const = 0;
89
91 void
93 std::shared_ptr<ReadView const> const& lastValidatedLedger)
94 {
95 if (needValidatedLedger(lastValidatedLedger->seq()))
97 lastValidatedLedger->seq(),
98 getEnabledAmendments(*lastValidatedLedger),
99 getMajorityAmendments(*lastValidatedLedger));
100 }
101
105 virtual bool
107
108 virtual void
110 LedgerIndex ledgerSeq,
111 std::set<uint256> const& enabled,
112 majorityAmendments_t const& majority) = 0;
113
114 // Called when the set of trusted validators changes.
115 virtual void
116 trustChanged(hash_set<PublicKey> const& allTrusted) = 0;
117
118 // Called by the consensus code when we need to
119 // inject pseudo-transactions
122 Rules const& rules,
123 NetClock::time_point closeTime,
124 std::set<uint256> const& enabledAmendments,
125 majorityAmendments_t const& majorityAmendments,
126 std::vector<std::shared_ptr<STValidation>> const& valSet) = 0;
127
128 // Called by the consensus code when we need to
129 // add feature entries to a validation
131 doValidation(std::set<uint256> const& enabled) const = 0;
132
133 // The set of amendments to enable in the genesis ledger
134 // This will return all known, non-vetoed amendments.
135 // If we ever have two amendments that should not both be
136 // enabled at the same time, we should ensure one is vetoed.
138 getDesired() const = 0;
139
140 // The function below adapts the API callers expect to the
141 // internal amendment table API. This allows the amendment
142 // table implementation to be independent of the ledger
143 // implementation. These APIs will merge when the view code
144 // supports a full ledger API
145
146 void
148 std::shared_ptr<ReadView const> const& lastClosedLedger,
149 std::vector<std::shared_ptr<STValidation>> const& parentValidations,
150 std::shared_ptr<SHAMap> const& initialPosition)
151 {
152 // Ask implementation what to do
153 auto actions = doVoting(
154 lastClosedLedger->rules(),
155 lastClosedLedger->parentCloseTime(),
156 getEnabledAmendments(*lastClosedLedger),
157 getMajorityAmendments(*lastClosedLedger),
158 parentValidations);
159
160 // Inject appropriate pseudo-transactions
161 for (auto const& it : actions)
162 {
163 STTx amendTx(
164 ttAMENDMENT,
165 [&it, seq = lastClosedLedger->seq() + 1](auto& obj) {
166 obj.setAccountID(sfAccount, AccountID());
167 obj.setFieldH256(sfAmendment, it.first);
168 obj.setFieldU32(sfLedgerSequence, seq);
169
170 if (it.second != 0)
171 obj.setFieldU32(sfFlags, it.second);
172 });
173
174 Serializer s;
175 amendTx.add(s);
176
177 initialPosition->addGiveItem(
179 make_shamapitem(amendTx.getTransactionID(), s.slice()));
180 }
181 }
182};
183
186 Application& app,
187 std::chrono::seconds majorityTime,
189 Section const& enabled,
190 Section const& vetoed,
191 beast::Journal journal);
192
193} // namespace ripple
194
195#endif
Represents a JSON value.
Definition: json_value.h:147
A generic endpoint for log messages.
Definition: Journal.h:59
The amendment table stores the list of enabled and potential amendments.
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
void doVoting(std::shared_ptr< ReadView const > const &lastClosedLedger, std::vector< std::shared_ptr< STValidation > > const &parentValidations, std::shared_ptr< SHAMap > const &initialPosition)
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:111
uint256 getTransactionID() const
Definition: STTx.h:193
Slice slice() const noexcept
Definition: Serializer.h:66
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:84
std::set< uint256 > getEnabledAmendments(ReadView const &view)
Definition: View.cpp:796
VoteBehavior
Definition: Feature.h:70
boost::intrusive_ptr< SHAMapItem > make_shamapitem(uint256 const &tag, Slice data)
Definition: SHAMapItem.h:160
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)