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) = 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  virtual bool
50  disable(uint256 const& amendment) = 0;
51 
52  virtual bool
53  isEnabled(uint256 const& amendment) = 0;
54  virtual bool
55  isSupported(uint256 const& amendment) = 0;
56 
63  virtual bool
65  virtual boost::optional<NetClock::time_point>
67 
68  virtual Json::Value
69  getJson(int) = 0;
70 
72  virtual Json::Value
73  getJson(uint256 const&) = 0;
74 
76  void
78  std::shared_ptr<ReadView const> const& lastValidatedLedger)
79  {
80  if (needValidatedLedger(lastValidatedLedger->seq()))
82  lastValidatedLedger->seq(),
83  getEnabledAmendments(*lastValidatedLedger),
84  getMajorityAmendments(*lastValidatedLedger));
85  }
86 
90  virtual bool
92 
93  virtual void
95  LedgerIndex ledgerSeq,
96  std::set<uint256> const& enabled,
97  majorityAmendments_t const& majority) = 0;
98 
99  // Called by the consensus code when we need to
100  // inject pseudo-transactions
102  doVoting(
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) = 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() = 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->parentCloseTime(),
135  getEnabledAmendments(*lastClosedLedger),
136  getMajorityAmendments(*lastClosedLedger),
137  parentValidations);
138 
139  // Inject appropriate pseudo-transactions
140  for (auto const& it : actions)
141  {
142  STTx amendTx(
143  ttAMENDMENT,
144  [&it, seq = lastClosedLedger->seq() + 1](auto& obj) {
145  obj.setAccountID(sfAccount, AccountID());
146  obj.setFieldH256(sfAmendment, it.first);
147  obj.setFieldU32(sfLedgerSequence, seq);
148 
149  if (it.second != 0)
150  obj.setFieldU32(sfFlags, it.second);
151  });
152 
153  Serializer s;
154  amendTx.add(s);
155 
156  initialPosition->addGiveItem(
157  std::make_shared<SHAMapItem>(
158  amendTx.getTransactionID(), s.peekData()),
159  true,
160  false);
161  }
162  }
163 };
164 
167  std::chrono::seconds majorityTime,
168  int majorityFraction,
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
std::string
STL class.
std::shared_ptr
STL class.
ripple::AmendmentTable::veto
virtual bool veto(uint256 const &amendment)=0
ripple::AmendmentTable::needValidatedLedger
virtual bool needValidatedLedger(LedgerIndex seq)=0
Called to determine whether the amendment logic needs to process a new validated ledger.
ripple::AmendmentTable::find
virtual uint256 find(std::string const &name)=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:654
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:77
ripple::AmendmentTable::getDesired
virtual std::vector< uint256 > getDesired()=0
ripple::AmendmentTable::hasUnsupportedEnabled
virtual bool hasUnsupportedEnabled()=0
returns true if one or more amendments on the network have been enabled that this server does not sup...
ripple::base_uint< 256 >
ripple::AmendmentTable::unVeto
virtual bool unVeto(uint256 const &amendment)=0
ripple::AmendmentTable::~AmendmentTable
virtual ~AmendmentTable()=default
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::isSupported
virtual bool isSupported(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::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::firstUnsupportedExpected
virtual boost::optional< NetClock::time_point > firstUnsupportedExpected()=0
ripple::AmendmentTable
The amendment table stores the list of enabled and potential amendments.
Definition: AmendmentTable.h:34
std::unique_ptr
STL class.
ripple::AmendmentTable::disable
virtual bool disable(uint256 const &amendment)=0
std::set
STL class.
ripple::AmendmentTable::doValidation
virtual std::vector< uint256 > doValidation(std::set< uint256 > const &enabled)=0
ripple::AmendmentTable::getJson
virtual Json::Value getJson(int)=0
ripple::AmendmentTable::isEnabled
virtual bool isEnabled(uint256 const &amendment)=0
Json::Value
Represents a JSON value.
Definition: json_value.h:145