rippled
RCLValidations.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_CONSENSUSS_VALIDATIONS_H_INCLUDED
21 #define RIPPLE_APP_CONSENSUSS_VALIDATIONS_H_INCLUDED
22 
23 #include <ripple/app/ledger/Ledger.h>
24 #include <ripple/consensus/Validations.h>
25 #include <ripple/protocol/Protocol.h>
26 #include <ripple/protocol/RippleLedgerHash.h>
27 #include <ripple/protocol/STValidation.h>
28 #include <vector>
29 
30 namespace ripple {
31 
32 class Application;
33 
39 {
41 
42 public:
45 
51  {
52  }
53 
55  uint256
56  ledgerID() const
57  {
58  return val_->getLedgerHash();
59  }
60 
63  seq() const
64  {
65  return val_->getFieldU32(sfLedgerSequence);
66  }
67 
70  signTime() const
71  {
72  return val_->getSignTime();
73  }
74 
77  seenTime() const
78  {
79  return val_->getSeenTime();
80  }
81 
83  PublicKey
84  key() const
85  {
86  return val_->getSignerPublic();
87  }
88 
90  NodeID
91  nodeID() const
92  {
93  return val_->getNodeID();
94  }
95 
97  bool
98  trusted() const
99  {
100  return val_->isTrusted();
101  }
102 
103  void
105  {
106  val_->setTrusted();
107  }
108 
109  void
111  {
112  val_->setUntrusted();
113  }
114 
116  bool
117  full() const
118  {
119  return val_->isFull();
120  }
121 
124  loadFee() const
125  {
126  return ~(*val_)[~sfLoadFee];
127  }
128 
131  cookie() const
132  {
133  return (*val_)[sfCookie];
134  }
135 
138  unwrap() const
139  {
140  return val_;
141  }
142 };
143 
154 {
155 public:
156  using ID = LedgerHash;
157  using Seq = LedgerIndex;
158  struct MakeGenesis
159  {
160  explicit MakeGenesis() = default;
161  };
162 
164 
166  std::shared_ptr<Ledger const> const& ledger,
167  beast::Journal j);
168 
170  Seq
171  seq() const;
172 
174  ID
175  id() const;
176 
183  ID
184  operator[](Seq const& s) const;
185 
187  friend Seq
188  mismatch(RCLValidatedLedger const& a, RCLValidatedLedger const& b);
189 
190  Seq
191  minSeq() const;
192 
193 private:
198 };
199 
206 {
207 public:
208  // Type definitions for generic Validation
209  using Mutex = std::mutex;
212 
214 
218  now() const;
219 
222  acquire(LedgerHash const& id);
223 
225  journal() const
226  {
227  return j_;
228  }
229 
230 private:
233 };
234 
237 
247 void
249  Application& app,
251  std::string const& source);
252 
253 } // namespace ripple
254 
255 #endif
ripple::RCLValidationsAdaptor
Generic validations adaptor class for RCL.
Definition: RCLValidations.h:205
ripple::Application
Definition: Application.h:115
ripple::RCLValidation::setUntrusted
void setUntrusted()
Definition: RCLValidations.h:110
ripple::RCLValidation::loadFee
std::optional< std::uint32_t > loadFee() const
Get the load fee of the validation if it exists.
Definition: RCLValidations.h:124
ripple::LedgerHash
uint256 LedgerHash
Definition: RippleLedgerHash.h:27
ripple::RCLValidation::nodeID
NodeID nodeID() const
NodeID of validator that published the validation.
Definition: RCLValidations.h:91
ripple::RCLValidation::setTrusted
void setTrusted()
Definition: RCLValidations.h:104
ripple::LedgerIndex
std::uint32_t LedgerIndex
A ledger index.
Definition: Protocol.h:90
std::string
STL class.
std::shared_ptr
STL class.
ripple::NodeID
base_uint< 160, detail::NodeIDTag > NodeID
NodeID is a 160-bit hash representing one node.
Definition: UintTypes.h:59
ripple::sfLedgerSequence
const SF_UINT32 sfLedgerSequence
ripple::RCLValidatedLedger::minSeq
Seq minSeq() const
Definition: RCLValidations.cpp:61
ripple::RCLValidatedLedger::MakeGenesis
Definition: RCLValidations.h:158
ripple::RCLValidatedLedger::ledgerID_
ID ledgerID_
Definition: RCLValidations.h:194
ripple::RCLValidation::unwrap
std::shared_ptr< STValidation > unwrap() const
Extract the underlying STValidation being wrapped.
Definition: RCLValidations.h:138
vector
ripple::RCLValidatedLedger::ancestors_
std::vector< uint256 > ancestors_
Definition: RCLValidations.h:196
ripple::RCLValidationsAdaptor::now
NetClock::time_point now() const
Current time used to determine if validations are stale.
Definition: RCLValidations.cpp:121
ripple::RCLValidationsAdaptor::journal
beast::Journal journal() const
Definition: RCLValidations.h:225
ripple::RCLValidatedLedger::id
ID id() const
The ID (hash) of the ledger.
Definition: RCLValidations.cpp:72
ripple::RCLValidationsAdaptor::RCLValidationsAdaptor
RCLValidationsAdaptor(Application &app, beast::Journal j)
Definition: RCLValidations.cpp:115
ripple::RCLValidation
Wrapper over STValidation for generic Validation code.
Definition: RCLValidations.h:38
ripple::RCLValidatedLedger
Wraps a ledger instance for use in generic Validations LedgerTrie.
Definition: RCLValidations.h:153
ripple::uint256
base_uint< 256 > uint256
Definition: base_uint.h:550
ripple::RCLValidation::seq
std::uint32_t seq() const
Validated ledger's sequence number (0 if none)
Definition: RCLValidations.h:63
ripple::RCLValidatedLedger::seq
Seq seq() const
The sequence (index) of the ledger.
Definition: RCLValidations.cpp:67
ripple::base_uint< 160, detail::NodeIDTag >
ripple::RCLValidatedLedger::RCLValidatedLedger
RCLValidatedLedger(MakeGenesis)
Definition: RCLValidations.cpp:39
ripple::sfLoadFee
const SF_UINT32 sfLoadFee
ripple::PublicKey
A public key.
Definition: PublicKey.h:59
ripple::RCLValidationsAdaptor::j_
beast::Journal j_
Definition: RCLValidations.h:232
ripple::RCLValidationsAdaptor::acquire
std::optional< RCLValidatedLedger > acquire(LedgerHash const &id)
Attempt to acquire the ledger with given id from the network.
Definition: RCLValidations.cpp:127
ripple::sfCookie
const SF_UINT64 sfCookie
ripple::RCLValidatedLedger::j_
beast::Journal j_
Definition: RCLValidations.h:197
ripple::RCLValidation::full
bool full() const
Whether the validation is full (not-partial)
Definition: RCLValidations.h:117
std::chrono::time_point
ripple::RCLValidatedLedger::ledgerSeq_
Seq ledgerSeq_
Definition: RCLValidations.h:195
ripple::RCLValidatedLedger::operator[]
ID operator[](Seq const &s) const
Lookup the ID of the ancestor ledger.
Definition: RCLValidations.cpp:78
ripple::RCLValidatedLedger::MakeGenesis::MakeGenesis
MakeGenesis()=default
beast::Journal
A generic endpoint for log messages.
Definition: Journal.h:58
std::uint32_t
ripple::RCLValidation::RCLValidation
RCLValidation(std::shared_ptr< STValidation > const &v)
Constructor.
Definition: RCLValidations.h:50
ripple
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition: RCLCensorshipDetector.h:29
ripple::RCLValidation::cookie
std::uint64_t cookie() const
Get the cookie specified in the validation (0 if not set)
Definition: RCLValidations.h:131
ripple::RCLValidation::ledgerID
uint256 ledgerID() const
Validated ledger's hash.
Definition: RCLValidations.h:56
ripple::RCLValidationsAdaptor::app_
Application & app_
Definition: RCLValidations.h:231
ripple::RCLValidation::key
PublicKey key() const
Public key of validator that published the validation.
Definition: RCLValidations.h:84
ripple::Validations< RCLValidationsAdaptor >
ripple::RCLValidation::signTime
NetClock::time_point signTime() const
Validation's signing time.
Definition: RCLValidations.h:70
std::optional< std::uint32_t >
std::mutex
STL class.
ripple::RCLValidation::val_
std::shared_ptr< STValidation > val_
Definition: RCLValidations.h:40
ripple::RCLValidatedLedger::mismatch
friend Seq mismatch(RCLValidatedLedger const &a, RCLValidatedLedger const &b)
Find the sequence number of the earliest mismatching ancestor.
Definition: RCLValidations.cpp:98
ripple::handleNewValidation
void handleNewValidation(Application &app, std::shared_ptr< STValidation > const &val, std::string const &source)
Handle a new validation.
Definition: RCLValidations.cpp:152
ripple::RCLValidation::trusted
bool trusted() const
Whether the validation is considered trusted.
Definition: RCLValidations.h:98
ripple::RCLValidation::seenTime
NetClock::time_point seenTime() const
Validated ledger's first seen time.
Definition: RCLValidations.h:77