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/protocol/STValidation.h>
25 #include <ripple/core/ConfigSections.h>
26 #include <ripple/protocol/Protocol.h>
27 
28 namespace ripple {
29 
35 {
36 public:
37  virtual ~AmendmentTable() = default;
38 
39  virtual uint256 find (std::string const& name) = 0;
40 
41  virtual bool veto (uint256 const& amendment) = 0;
42  virtual bool unVeto (uint256 const& amendment) = 0;
43 
44  virtual bool enable (uint256 const& amendment) = 0;
45  virtual bool disable (uint256 const& amendment) = 0;
46 
47  virtual bool isEnabled (uint256 const& amendment) = 0;
48  virtual bool isSupported (uint256 const& amendment) = 0;
49 
56  virtual bool hasUnsupportedEnabled () = 0;
57  virtual boost::optional<NetClock::time_point>
59 
60  virtual Json::Value getJson (int) = 0;
61 
63  virtual Json::Value getJson (uint256 const& ) = 0;
64 
66  void
68  std::shared_ptr<ReadView const> const& lastValidatedLedger)
69  {
70  if (needValidatedLedger(lastValidatedLedger->seq()))
72  lastValidatedLedger->seq(),
73  getEnabledAmendments(*lastValidatedLedger),
74  getMajorityAmendments(*lastValidatedLedger));
75  }
76 
80  virtual bool
82 
83  virtual void
85  LedgerIndex ledgerSeq,
86  std::set <uint256> const& enabled,
87  majorityAmendments_t const& majority) = 0;
88 
89  // Called by the consensus code when we need to
90  // inject pseudo-transactions
92  doVoting (
93  NetClock::time_point closeTime,
94  std::set <uint256> const& enabledAmendments,
95  majorityAmendments_t const& majorityAmendments,
96  std::vector<STValidation::pointer> const& valSet) = 0;
97 
98  // Called by the consensus code when we need to
99  // add feature entries to a validation
100  virtual std::vector <uint256>
101  doValidation (std::set <uint256> const& enabled) = 0;
102 
103  // The set of amendments to enable in the genesis ledger
104  // This will return all known, non-vetoed amendments.
105  // If we ever have two amendments that should not both be
106  // enabled at the same time, we should ensure one is vetoed.
107  virtual std::vector <uint256>
108  getDesired () = 0;
109 
110  // The function below adapts the API callers expect to the
111  // internal amendment table API. This allows the amendment
112  // table implementation to be independent of the ledger
113  // implementation. These APIs will merge when the view code
114  // supports a full ledger API
115 
116  void
118  std::shared_ptr <ReadView const> const& lastClosedLedger,
119  std::vector<STValidation::pointer> const& parentValidations,
120  std::shared_ptr<SHAMap> const& initialPosition)
121  {
122  // Ask implementation what to do
123  auto actions = doVoting (
124  lastClosedLedger->parentCloseTime(),
125  getEnabledAmendments(*lastClosedLedger),
126  getMajorityAmendments(*lastClosedLedger),
127  parentValidations);
128 
129  // Inject appropriate pseudo-transactions
130  for (auto const& it : actions)
131  {
132  STTx amendTx (ttAMENDMENT,
133  [&it, seq = lastClosedLedger->seq() + 1](auto& obj)
134  {
135  obj.setAccountID (sfAccount, AccountID());
136  obj.setFieldH256 (sfAmendment, it.first);
137  obj.setFieldU32 (sfLedgerSequence, seq);
138 
139  if (it.second != 0)
140  obj.setFieldU32 (sfFlags, it.second);
141  });
142 
143  Serializer s;
144  amendTx.add (s);
145 
146  initialPosition->addGiveItem (
147  std::make_shared <SHAMapItem> (
148  amendTx.getTransactionID(),
149  s.peekData()),
150  true,
151  false);
152  }
153  }
154 
155 };
156 
158  std::chrono::seconds majorityTime,
159  int majorityFraction,
160  Section const& supported,
161  Section const& enabled,
162  Section const& vetoed,
163  beast::Journal journal);
164 
165 } // ripple
166 
167 #endif
ripple::getMajorityAmendments
majorityAmendments_t getMajorityAmendments(ReadView const &view)
Definition: View.cpp:530
ripple::getEnabledAmendments
std::set< uint256 > getEnabledAmendments(ReadView const &view)
Definition: View.cpp:513
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:646
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< STValidation::pointer > const &valSet)=0
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:67
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:43
beast::Journal
A generic endpoint for log messages.
Definition: Journal.h:60
std::uint32_t
ripple::ttAMENDMENT
@ ttAMENDMENT
Definition: TxFormats.h:60
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::STTx::getTransactionID
uint256 getTransactionID() const
Definition: STTx.h:120
ripple::Serializer
Definition: Serializer.h:43
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:343
ripple::Serializer::peekData
Blob const & peekData() const
Definition: Serializer.h:173
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::doVoting
void doVoting(std::shared_ptr< ReadView const > const &lastClosedLedger, std::vector< STValidation::pointer > const &parentValidations, std::shared_ptr< SHAMap > const &initialPosition)
Definition: AmendmentTable.h:117
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:141