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/Feature.h>
26 #include <ripple/protocol/Protocol.h>
27 #include <ripple/protocol/STValidation.h>
28 
29 #include <optional>
30 
31 namespace ripple {
32 
38 {
39 public:
40  struct FeatureInfo
41  {
42  FeatureInfo() = delete;
44  : name(n), feature(f), vote(v)
45  {
46  }
47 
51  };
52 
53  virtual ~AmendmentTable() = default;
54 
55  virtual uint256
56  find(std::string const& name) const = 0;
57 
58  virtual bool
59  veto(uint256 const& amendment) = 0;
60  virtual bool
61  unVeto(uint256 const& amendment) = 0;
62 
63  virtual bool
64  enable(uint256 const& amendment) = 0;
65 
66  virtual bool
67  isEnabled(uint256 const& amendment) const = 0;
68  virtual bool
69  isSupported(uint256 const& amendment) const = 0;
70 
77  virtual bool
78  hasUnsupportedEnabled() const = 0;
79 
81  firstUnsupportedExpected() const = 0;
82 
83  virtual Json::Value
84  getJson() const = 0;
85 
87  virtual Json::Value
88  getJson(uint256 const& amendment) const = 0;
89 
91  void
93  std::shared_ptr<ReadView const> const& lastValidatedLedger)
94  {
95  if (needValidatedLedger(lastValidatedLedger->seq()))
97  lastValidatedLedger->seq(),
98  getEnabledAmendments(*lastValidatedLedger),
99  getMajorityAmendments(*lastValidatedLedger));
100  }
101 
105  virtual bool
106  needValidatedLedger(LedgerIndex seq) const = 0;
107 
108  virtual void
110  LedgerIndex ledgerSeq,
111  std::set<uint256> const& enabled,
112  majorityAmendments_t const& majority) = 0;
113 
114  // Called by the consensus code when we need to
115  // inject pseudo-transactions
117  doVoting(
118  Rules const& rules,
119  NetClock::time_point closeTime,
120  std::set<uint256> const& enabledAmendments,
121  majorityAmendments_t const& majorityAmendments,
122  std::vector<std::shared_ptr<STValidation>> const& valSet) = 0;
123 
124  // Called by the consensus code when we need to
125  // add feature entries to a validation
126  virtual std::vector<uint256>
127  doValidation(std::set<uint256> const& enabled) const = 0;
128 
129  // The set of amendments to enable in the genesis ledger
130  // This will return all known, non-vetoed amendments.
131  // If we ever have two amendments that should not both be
132  // enabled at the same time, we should ensure one is vetoed.
133  virtual std::vector<uint256>
134  getDesired() const = 0;
135 
136  // The function below adapts the API callers expect to the
137  // internal amendment table API. This allows the amendment
138  // table implementation to be independent of the ledger
139  // implementation. These APIs will merge when the view code
140  // supports a full ledger API
141 
142  void
144  std::shared_ptr<ReadView const> const& lastClosedLedger,
145  std::vector<std::shared_ptr<STValidation>> const& parentValidations,
146  std::shared_ptr<SHAMap> const& initialPosition)
147  {
148  // Ask implementation what to do
149  auto actions = doVoting(
150  lastClosedLedger->rules(),
151  lastClosedLedger->parentCloseTime(),
152  getEnabledAmendments(*lastClosedLedger),
153  getMajorityAmendments(*lastClosedLedger),
154  parentValidations);
155 
156  // Inject appropriate pseudo-transactions
157  for (auto const& it : actions)
158  {
159  STTx amendTx(
160  ttAMENDMENT,
161  [&it, seq = lastClosedLedger->seq() + 1](auto& obj) {
162  obj.setAccountID(sfAccount, AccountID());
163  obj.setFieldH256(sfAmendment, it.first);
164  obj.setFieldU32(sfLedgerSequence, seq);
165 
166  if (it.second != 0)
167  obj.setFieldU32(sfFlags, it.second);
168  });
169 
170  Serializer s;
171  amendTx.add(s);
172 
173  initialPosition->addGiveItem(
175  make_shamapitem(amendTx.getTransactionID(), s.slice()));
176  }
177  }
178 };
179 
182  Application& app,
183  std::chrono::seconds majorityTime,
185  Section const& enabled,
186  Section const& vetoed,
187  beast::Journal journal);
188 
189 } // namespace ripple
190 
191 #endif
ripple::AmendmentTable::FeatureInfo::name
const std::string name
Definition: AmendmentTable.h:48
ripple::getMajorityAmendments
majorityAmendments_t getMajorityAmendments(ReadView const &view)
Definition: View.cpp:621
ripple::AmendmentTable::FeatureInfo::vote
const VoteBehavior vote
Definition: AmendmentTable.h:50
ripple::getEnabledAmendments
std::set< uint256 > getEnabledAmendments(ReadView const &view)
Definition: View.cpp:604
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::FeatureInfo::feature
const uint256 feature
Definition: AmendmentTable.h:49
ripple::AmendmentTable::veto
virtual bool veto(uint256 const &amendment)=0
ripple::AmendmentTable::find
virtual uint256 find(std::string const &name) const =0
ripple::make_shamapitem
boost::intrusive_ptr< SHAMapItem > make_shamapitem(uint256 const &tag, Slice data)
Definition: SHAMapItem.h:160
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:143
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:92
ripple::AmendmentTable::getJson
virtual Json::Value getJson() const =0
ripple::ttAMENDMENT
@ ttAMENDMENT
This system-generated transaction type is used to update the status of the various amendments.
Definition: TxFormats.h:146
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::VoteBehavior
VoteBehavior
Definition: Feature.h:69
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::STTx
Definition: STTx.h:45
beast::Journal
A generic endpoint for log messages.
Definition: Journal.h:58
std::uint32_t
std::map
STL class.
ripple::AmendmentTable::enable
virtual bool enable(uint256 const &amendment)=0
ripple::AmendmentTable::FeatureInfo
Definition: AmendmentTable.h:40
ripple::STTx::getTransactionID
uint256 getTransactionID() const
Definition: STTx.h:191
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::STObject::add
void add(Serializer &s) const override
Definition: STObject.cpp:85
ripple
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition: RCLCensorshipDetector.h:29
ripple::AmendmentTable::FeatureInfo::FeatureInfo
FeatureInfo()=delete
ripple::Rules
Rules controlling protocol behavior.
Definition: Rules.h:33
optional
ripple::make_AmendmentTable
std::unique_ptr< AmendmentTable > make_AmendmentTable(Application &app, std::chrono::seconds majorityTime, std::vector< AmendmentTable::FeatureInfo > const &supported, Section const &enabled, Section const &vetoed, beast::Journal journal)
Definition: AmendmentTable.cpp:812
ripple::AmendmentTable::FeatureInfo::FeatureInfo
FeatureInfo(std::string const &n, uint256 const &f, VoteBehavior v)
Definition: AmendmentTable.h:43
ripple::AmendmentTable
The amendment table stores the list of enabled and potential amendments.
Definition: AmendmentTable.h:37
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