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 namespace ripple {
29 
35 {
36 public:
37  virtual ~AmendmentTable() = default;
38 
39  virtual uint256
40  find(std::string const& name) const = 0;
41 
42  virtual bool
43  veto(uint256 const& amendment) = 0;
44  virtual bool
45  unVeto(uint256 const& amendment) = 0;
46 
47  virtual bool
48  enable(uint256 const& amendment) = 0;
49 
50  virtual bool
51  isEnabled(uint256 const& amendment) const = 0;
52  virtual bool
53  isSupported(uint256 const& amendment) const = 0;
54 
61  virtual bool
62  hasUnsupportedEnabled() const = 0;
63 
64  virtual boost::optional<NetClock::time_point>
65  firstUnsupportedExpected() const = 0;
66 
67  virtual Json::Value
68  getJson() const = 0;
69 
71  virtual Json::Value
72  getJson(uint256 const& amendment) const = 0;
73 
75  void
77  std::shared_ptr<ReadView const> const& lastValidatedLedger)
78  {
79  if (needValidatedLedger(lastValidatedLedger->seq()))
81  lastValidatedLedger->seq(),
82  getEnabledAmendments(*lastValidatedLedger),
83  getMajorityAmendments(*lastValidatedLedger));
84  }
85 
89  virtual bool
90  needValidatedLedger(LedgerIndex seq) const = 0;
91 
92  virtual void
94  LedgerIndex ledgerSeq,
95  std::set<uint256> const& enabled,
96  majorityAmendments_t const& majority) = 0;
97 
98  // Called by the consensus code when we need to
99  // inject pseudo-transactions
101  doVoting(
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
110  virtual std::vector<uint256>
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.
117  virtual std::vector<uint256>
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)
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(
144  ttAMENDMENT,
145  [&it, seq = lastClosedLedger->seq() + 1](auto& obj) {
146  obj.setAccountID(sfAccount, AccountID());
147  obj.setFieldH256(sfAmendment, it.first);
148  obj.setFieldU32(sfLedgerSequence, seq);
149 
150  if (it.second != 0)
151  obj.setFieldU32(sfFlags, it.second);
152  });
153 
154  Serializer s;
155  amendTx.add(s);
156 
157  initialPosition->addGiveItem(
158  std::make_shared<SHAMapItem>(
159  amendTx.getTransactionID(), s.peekData()),
160  true,
161  false);
162  }
163  }
164 };
165 
168  std::chrono::seconds majorityTime,
169  Section const& supported,
170  Section const& enabled,
171  Section const& vetoed,
172  beast::Journal journal);
173 
174 } // namespace ripple
175 
176 #endif
ripple::getMajorityAmendments
majorityAmendments_t getMajorityAmendments(ReadView const &view)
Definition: View.cpp:550
ripple::getEnabledAmendments
std::set< uint256 > getEnabledAmendments(ReadView const &view)
Definition: View.cpp:533
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:127
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:76
ripple::AmendmentTable::getJson
virtual Json::Value getJson() const =0
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::isEnabled
virtual bool isEnabled(uint256 const &amendment) const =0
ripple::make_AmendmentTable
std::unique_ptr< AmendmentTable > make_AmendmentTable(std::chrono::seconds majorityTime, Section const &supported, Section const &enabled, Section const &vetoed, beast::Journal journal)
Definition: AmendmentTable.cpp:695
std::chrono::time_point
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:123
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:358
ripple::Serializer::peekData
Blob const & peekData() const
Definition: Serializer.h:166
ripple::Rules
Rules controlling protocol behavior.
Definition: ReadView.h:131
ripple::AmendmentTable
The amendment table stores the list of enabled and potential amendments.
Definition: AmendmentTable.h:34
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::firstUnsupportedExpected
virtual boost::optional< NetClock::time_point > firstUnsupportedExpected() const =0
ripple::AmendmentTable::getDesired
virtual std::vector< uint256 > getDesired() const =0
Json::Value
Represents a JSON value.
Definition: json_value.h:145