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 
40 {
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 
123  boost::optional<std::uint32_t>
124  loadFee() const
125  {
126  return ~(*val_)[~sfLoadFee];
127  }
128 
131  unwrap() const
132  {
133  return val_;
134  }
135 
136 };
137 
148 {
149 public:
150  using ID = LedgerHash;
151  using Seq = LedgerIndex;
152  struct MakeGenesis
153  {
154  explicit MakeGenesis() = default;
155  };
156 
158 
160  std::shared_ptr<Ledger const> const& ledger,
161  beast::Journal j);
162 
164  Seq
165  seq() const;
166 
168  ID
169  id() const;
170 
177  ID operator[](Seq const& s) const;
178 
180  friend Seq
181  mismatch(RCLValidatedLedger const& a, RCLValidatedLedger const& b);
182 
183  Seq
184  minSeq() const;
185 
186 private:
191 };
192 
199 {
200 public:
201  // Type definitions for generic Validation
202  using Mutex = std::mutex;
205 
207 
211  now() const;
212 
214  boost::optional<RCLValidatedLedger>
215  acquire(LedgerHash const & id);
216 
218  journal() const
219  {
220  return j_;
221  }
222 
223 private:
226 };
227 
230 
231 
243 bool
245  Application& app,
246  STValidation::ref val,
247  std::string const& source);
248 
249 } // namespace ripple
250 
251 #endif
ripple::RCLValidationsAdaptor
Generic validations adaptor class for RCL.
Definition: RCLValidations.h:198
ripple::Application
Definition: Application.h:85
ripple::RCLValidation::setUntrusted
void setUntrusted()
Definition: RCLValidations.h:110
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::sfLoadFee
const SF_U32 sfLoadFee(access, STI_UINT32, 24, "LoadFee")
Definition: SField.h:361
ripple::RCLValidation::RCLValidation
RCLValidation(STValidation::pointer const &v)
Constructor.
Definition: RCLValidations.h:50
ripple::LedgerIndex
std::uint32_t LedgerIndex
A ledger index.
Definition: Protocol.h:57
std::string
STL class.
std::shared_ptr< STValidation >
ripple::NodeID
base_uint< 160, detail::NodeIDTag > NodeID
NodeID is a 160-bit hash representing one node.
Definition: UintTypes.h:59
ripple::RCLValidatedLedger::minSeq
Seq minSeq() const
Definition: RCLValidations.cpp:62
ripple::RCLValidatedLedger::MakeGenesis
Definition: RCLValidations.h:152
ripple::RCLValidatedLedger::ledgerID_
ID ledgerID_
Definition: RCLValidations.h:187
vector
ripple::RCLValidatedLedger::ancestors_
std::vector< uint256 > ancestors_
Definition: RCLValidations.h:189
ripple::RCLValidationsAdaptor::acquire
boost::optional< RCLValidatedLedger > acquire(LedgerHash const &id)
Attempt to acquire the ledger with given id from the network.
Definition: RCLValidations.cpp:126
ripple::RCLValidationsAdaptor::now
NetClock::time_point now() const
Current time used to determine if validations are stale.
Definition: RCLValidations.cpp:120
ripple::RCLValidationsAdaptor::journal
beast::Journal journal() const
Definition: RCLValidations.h:218
ripple::RCLValidatedLedger::id
ID id() const
The ID (hash) of the ledger.
Definition: RCLValidations.cpp:73
ripple::RCLValidationsAdaptor::RCLValidationsAdaptor
RCLValidationsAdaptor(Application &app, beast::Journal j)
Definition: RCLValidations.cpp:114
ripple::RCLValidation
Wrapper over STValidation for generic Validation code.
Definition: RCLValidations.h:39
ripple::RCLValidatedLedger
Wraps a ledger instance for use in generic Validations LedgerTrie.
Definition: RCLValidations.h:147
ripple::handleNewValidation
bool handleNewValidation(Application &app, STValidation::ref val, std::string const &source)
Handle a new validation.
Definition: RCLValidations.cpp:151
ripple::uint256
base_uint< 256 > uint256
Definition: base_uint.h:436
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:68
ripple::base_uint< 160, detail::NodeIDTag >
ripple::RCLValidatedLedger::RCLValidatedLedger
RCLValidatedLedger(MakeGenesis)
Definition: RCLValidations.cpp:40
ripple::PublicKey
A public key.
Definition: PublicKey.h:59
ripple::RCLValidationsAdaptor::j_
beast::Journal j_
Definition: RCLValidations.h:225
ripple::RCLValidatedLedger::j_
beast::Journal j_
Definition: RCLValidations.h:190
ripple::RCLValidation::full
bool full() const
Whether the validation is full (not-partial)
Definition: RCLValidations.h:117
ripple::sfLedgerSequence
const SF_U32 sfLedgerSequence(access, STI_UINT32, 6, "LedgerSequence")
Definition: SField.h:342
std::chrono::time_point
ripple::RCLValidatedLedger::ledgerSeq_
Seq ledgerSeq_
Definition: RCLValidations.h:188
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:60
std::uint32_t
ripple
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition: RCLCensorshipDetector.h:29
ripple::RCLValidation::ledgerID
uint256 ledgerID() const
Validated ledger's hash.
Definition: RCLValidations.h:56
ripple::LedgerHash
uint256 LedgerHash
Definition: RippleLedgerHash.h:27
ripple::RCLValidationsAdaptor::app_
Application & app_
Definition: RCLValidations.h:224
ripple::RCLValidation::val_
STValidation::pointer val_
Definition: RCLValidations.h:41
ripple::RCLValidation::unwrap
STValidation::pointer unwrap() const
Extract the underlying STValidation being wrapped.
Definition: RCLValidations.h:131
ripple::RCLValidation::key
PublicKey key() const
Public key of validator that published the validation.
Definition: RCLValidations.h:84
ripple::RCLValidation::loadFee
boost::optional< std::uint32_t > loadFee() const
Get the load fee of the validation if it exists.
Definition: RCLValidations.h:124
ripple::Validations< RCLValidationsAdaptor >
ripple::RCLValidation::signTime
NetClock::time_point signTime() const
Validation's signing time.
Definition: RCLValidations.h:70
std::mutex
STL class.
ripple::RCLValidatedLedger::mismatch
friend Seq mismatch(RCLValidatedLedger const &a, RCLValidatedLedger const &b)
Find the sequence number of the earliest mismatching ancestor.
Definition: RCLValidations.cpp:97
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