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  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
109  virtual std::vector<uint256>
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.
116  virtual std::vector<uint256>
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)
130  {
131  // Ask implementation what to do
132  auto actions = doVoting(
133  lastClosedLedger->parentCloseTime(),
134  getEnabledAmendments(*lastClosedLedger),
135  getMajorityAmendments(*lastClosedLedger),
136  parentValidations);
137 
138  // Inject appropriate pseudo-transactions
139  for (auto const& it : actions)
140  {
141  STTx amendTx(
142  ttAMENDMENT,
143  [&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  initialPosition->addGiveItem(
156  std::make_shared<SHAMapItem>(
157  amendTx.getTransactionID(), s.peekData()),
158  true,
159  false);
160  }
161  }
162 };
163 
166  std::chrono::seconds majorityTime,
167  int majorityFraction,
168  Section const& supported,
169  Section const& enabled,
170  Section const& vetoed,
171  beast::Journal journal);
172 
173 } // namespace ripple
174 
175 #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
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::make_AmendmentTable
std::unique_ptr< AmendmentTable > make_AmendmentTable(std::chrono::seconds majorityTime, int majorityFraction, Section const &supported, Section const &enabled, Section const &vetoed, beast::Journal journal)
Definition: AmendmentTable.cpp:667
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:126
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
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:59
std::map
STL class.
ripple::AmendmentTable::enable
virtual bool enable(uint256 const &amendment)=0
ripple::AmendmentTable::doVoting
virtual std::map< uint256, std::uint32_t > doVoting(NetClock::time_point closeTime, std::set< uint256 > const &enabledAmendments, majorityAmendments_t const &majorityAmendments, std::vector< std::shared_ptr< STValidation >> const &valSet)=0
ripple::STTx::getTransactionID
uint256 getTransactionID() const
Definition: STTx.h:131
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:351
ripple::Serializer::peekData
Blob const & peekData() const
Definition: Serializer.h:166
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