rippled
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 <ripple/app/ledger/Ledger.h>
24 #include <ripple/core/ConfigSections.h>
25 #include <ripple/protocol/Protocol.h>
26 #include <ripple/protocol/STValidation.h>
27 
28 #include <optional>
29 
30 namespace ripple {
31 
37 {
38 public:
39  virtual ~AmendmentTable() = default;
40 
41  virtual uint256
42  find(std::string const& name) const = 0;
43 
44  virtual bool
45  veto(uint256 const& amendment) = 0;
46  virtual bool
47  unVeto(uint256 const& amendment) = 0;
48 
49  virtual bool
50  enable(uint256 const& amendment) = 0;
51 
52  virtual bool
53  isEnabled(uint256 const& amendment) const = 0;
54  virtual bool
55  isSupported(uint256 const& amendment) const = 0;
56 
63  virtual bool
64  hasUnsupportedEnabled() const = 0;
65 
67  firstUnsupportedExpected() const = 0;
68 
69  virtual Json::Value
70  getJson() const = 0;
71 
73  virtual Json::Value
74  getJson(uint256 const& amendment) const = 0;
75 
77  void
79  std::shared_ptr<ReadView const> const& lastValidatedLedger)
80  {
81  if (needValidatedLedger(lastValidatedLedger->seq()))
83  lastValidatedLedger->seq(),
84  getEnabledAmendments(*lastValidatedLedger),
85  getMajorityAmendments(*lastValidatedLedger));
86  }
87 
91  virtual bool
92  needValidatedLedger(LedgerIndex seq) const = 0;
93 
94  virtual void
96  LedgerIndex ledgerSeq,
97  std::set<uint256> const& enabled,
98  majorityAmendments_t const& majority) = 0;
99 
100  // Called by the consensus code when we need to
101  // inject pseudo-transactions
103  doVoting(
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
112  virtual std::vector<uint256>
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.
119  virtual std::vector<uint256>
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)
133  {
134  // Ask implementation what to do
135  auto actions = doVoting(
136  lastClosedLedger->rules(),
137  lastClosedLedger->parentCloseTime(),
138  getEnabledAmendments(*lastClosedLedger),
139  getMajorityAmendments(*lastClosedLedger),
140  parentValidations);
141 
142  // Inject appropriate pseudo-transactions
143  for (auto const& it : actions)
144  {
145  STTx amendTx(
146  ttAMENDMENT,
147  [&it, seq = lastClosedLedger->seq() + 1](auto& obj) {
148  obj.setAccountID(sfAccount, AccountID());
149  obj.setFieldH256(sfAmendment, it.first);
150  obj.setFieldU32(sfLedgerSequence, seq);
151 
152  if (it.second != 0)
153  obj.setFieldU32(sfFlags, it.second);
154  });
155 
156  Serializer s;
157  amendTx.add(s);
158 
159  initialPosition->addGiveItem(
161  std::make_shared<SHAMapItem>(
162  amendTx.getTransactionID(), s.slice()));
163  }
164  }
165 };
166 
169  Application& app,
170  std::chrono::seconds majorityTime,
171  Section const& supported,
172  Section const& enabled,
173  Section const& vetoed,
174  beast::Journal journal);
175 
176 } // namespace ripple
177 
178 #endif
ripple::getMajorityAmendments
majorityAmendments_t getMajorityAmendments(ReadView const &view)
Definition: View.cpp:554
ripple::getEnabledAmendments
std::set< uint256 > getEnabledAmendments(ReadView const &view)
Definition: View.cpp:537
ripple::AmendmentTable::doVoting
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
std::string
STL class.
std::shared_ptr
STL class.
ripple::AmendmentTable::veto
virtual bool veto(uint256 const &amendment)=0
ripple::AmendmentTable::find
virtual uint256 find(std::string const &name) const =0
std::vector
STL class.
ripple::AmendmentTable::doVoting
void doVoting(std::shared_ptr< ReadView const > const &lastClosedLedger, std::vector< std::shared_ptr< STValidation >> const &parentValidations, std::shared_ptr< SHAMap > const &initialPosition)
Definition: AmendmentTable.h:129
std::chrono::seconds
ripple::AmendmentTable::doValidatedLedger
void doValidatedLedger(std::shared_ptr< ReadView const > const &lastValidatedLedger)
Called when a new fully-validated ledger is accepted.
Definition: AmendmentTable.h:78
ripple::AmendmentTable::getJson
virtual Json::Value getJson() const =0
ripple::SHAMapNodeType::tnTRANSACTION_NM
@ tnTRANSACTION_NM
ripple::base_uint< 256 >
ripple::AmendmentTable::doValidation
virtual std::vector< uint256 > doValidation(std::set< uint256 > const &enabled) const =0
ripple::AmendmentTable::unVeto
virtual bool unVeto(uint256 const &amendment)=0
ripple::AmendmentTable::~AmendmentTable
virtual ~AmendmentTable()=default
ripple::AmendmentTable::firstUnsupportedExpected
virtual std::optional< NetClock::time_point > firstUnsupportedExpected() const =0
ripple::AmendmentTable::isEnabled
virtual bool isEnabled(uint256 const &amendment) const =0
ripple::Serializer::slice
Slice slice() const noexcept
Definition: Serializer.h:63
std::chrono::time_point
ripple::make_AmendmentTable
std::unique_ptr< AmendmentTable > make_AmendmentTable(Application &app, std::chrono::seconds majorityTime, Section const &supported, Section const &enabled, Section const &vetoed, beast::Journal journal)
Definition: AmendmentTable.cpp:780
ripple::STTx
Definition: STTx.h:42
beast::Journal
A generic endpoint for log messages.
Definition: Journal.h:58
std::uint32_t
ripple::ttAMENDMENT
@ ttAMENDMENT
Definition: TxFormats.h:61
std::map
STL class.
ripple::AmendmentTable::enable
virtual bool enable(uint256 const &amendment)=0
ripple::STTx::getTransactionID
uint256 getTransactionID() const
Definition: STTx.h:117
ripple::AmendmentTable::hasUnsupportedEnabled
virtual bool hasUnsupportedEnabled() const =0
returns true if one or more amendments on the network have been enabled that this server does not sup...
ripple::AmendmentTable::isSupported
virtual bool isSupported(uint256 const &amendment) const =0
ripple::Serializer
Definition: Serializer.h:39
ripple
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition: RCLCensorshipDetector.h:29
ripple::STObject::add
virtual void add(Serializer &s) const override
Definition: STObject.h:352
ripple::Rules
Rules controlling protocol behavior.
Definition: ReadView.h:131
optional
ripple::AmendmentTable
The amendment table stores the list of enabled and potential amendments.
Definition: AmendmentTable.h:36
std::unique_ptr
STL class.
ripple::AmendmentTable::needValidatedLedger
virtual bool needValidatedLedger(LedgerIndex seq) const =0
Called to determine whether the amendment logic needs to process a new validated ledger.
std::set
STL class.
ripple::AmendmentTable::getDesired
virtual std::vector< uint256 > getDesired() const =0
Json::Value
Represents a JSON value.
Definition: json_value.h:145