xrpld
Loading...
Searching...
No Matches
RCLValidations.h
1#pragma once
2
3#include <xrpl/basics/base_uint.h>
4#include <xrpl/basics/chrono.h>
5#include <xrpl/beast/utility/Journal.h>
6#include <xrpl/consensus/Validations.h>
7#include <xrpl/ledger/Ledger.h>
8#include <xrpl/protocol/Protocol.h>
9#include <xrpl/protocol/PublicKey.h>
10#include <xrpl/protocol/RippleLedgerHash.h>
11#include <xrpl/protocol/SField.h>
12#include <xrpl/protocol/STValidation.h>
13#include <xrpl/protocol/UintTypes.h>
14
15#include <cstdint>
16#include <memory>
17#include <mutex>
18#include <optional>
19#include <string>
20#include <utility>
21#include <vector>
22
23namespace xrpl {
24
25class Application;
26
27enum class BypassAccept : bool { No = false, Yes };
28
35{
37
38public:
41
50
54 [[nodiscard]] uint256
55 ledgerID() const
56 {
57 return val_->getLedgerHash();
58 }
59
63 [[nodiscard]] std::uint32_t
64 seq() const
65 {
66 return val_->getFieldU32(sfLedgerSequence);
67 }
68
72 [[nodiscard]] NetClock::time_point
73 signTime() const
74 {
75 return val_->getSignTime();
76 }
77
81 [[nodiscard]] NetClock::time_point
82 seenTime() const
83 {
84 return val_->getSeenTime();
85 }
86
90 [[nodiscard]] PublicKey
91 key() const
92 {
93 return val_->getSignerPublic();
94 }
95
99 [[nodiscard]] NodeID
100 nodeID() const
101 {
102 return val_->getNodeID();
103 }
104
108 [[nodiscard]] bool
109 trusted() const
110 {
111 return val_->isTrusted();
112 }
113
114 void
116 {
117 val_->setTrusted();
118 }
119
120 void
122 {
123 val_->setUntrusted();
124 }
125
129 [[nodiscard]] bool
130 full() const
131 {
132 return val_->isFull();
133 }
134
138 [[nodiscard]] std::optional<std::uint32_t>
139 loadFee() const
140 {
141 return ~(*val_)[~sfLoadFee];
142 }
143
147 [[nodiscard]] std::uint64_t
148 cookie() const
149 {
150 return (*val_)[sfCookie];
151 }
152
157 unwrap() const
158 {
159 return val_;
160 }
161};
162
174{
175public:
176 using ID = LedgerHash;
179 {
180 explicit MakeGenesis() = default;
181 };
182
184
186
190 [[nodiscard]] Seq
191 seq() const;
192
196 [[nodiscard]] ID
197 id() const;
198
206 ID
207 operator[](Seq const& s) const;
208
212 friend Seq
214
215 [[nodiscard]] Seq
216 minSeq() const;
217
218private:
223};
224
232{
233public:
234 // Type definitions for generic Validation
238
240
244 [[nodiscard]] NetClock::time_point
245 now() const;
246
251 acquire(LedgerHash const& id);
252
253 [[nodiscard]] beast::Journal
254 journal() const
255 {
256 return j_;
257 }
258
259private:
262};
263
268
279void
281 Application& app,
283 std::string const& source,
284 BypassAccept const bypassAccept = BypassAccept::No,
285 std::optional<beast::Journal> j = std::nullopt);
286
287} // namespace xrpl
A generic endpoint for log messages.
Definition Journal.h:44
std::chrono::time_point< NetClock > time_point
Definition chrono.h:48
A public key.
Definition PublicKey.h:53
Wraps a ledger instance for use in generic Validations LedgerTrie.
friend Seq mismatch(RCLValidatedLedger const &a, RCLValidatedLedger const &b)
Find the sequence number of the earliest mismatching ancestor.
Seq seq() const
The sequence (index) of the ledger.
ID id() const
The ID (hash) of the ledger.
ID operator[](Seq const &s) const
Lookup the ID of the ancestor ledger.
std::vector< uint256 > ancestors_
Wrapper over STValidation for generic Validation code.
std::uint32_t seq() const
Validated ledger's sequence number (0 if none).
bool full() const
Whether the validation is full (not-partial).
NodeID nodeID() const
NodeID of validator that published the validation.
xrpl::PublicKey NodeKey
RCLValidation(std::shared_ptr< STValidation > v)
Constructor.
std::shared_ptr< STValidation > val_
bool trusted() const
Whether the validation is considered trusted.
NetClock::time_point seenTime() const
Validated ledger's first seen time.
std::uint64_t cookie() const
Get the cookie specified in the validation (0 if not set).
std::optional< std::uint32_t > loadFee() const
Get the load fee of the validation if it exists.
NetClock::time_point signTime() const
Validation's signing time.
PublicKey key() const
Public key of validator that published the validation.
std::shared_ptr< STValidation > unwrap() const
Extract the underlying STValidation being wrapped.
uint256 ledgerID() const
Validated ledger's hash.
std::optional< RCLValidatedLedger > acquire(LedgerHash const &id)
Attempt to acquire the ledger with given id from the network.
NetClock::time_point now() const
Current time used to determine if validations are stale.
beast::Journal journal() const
RCLValidationsAdaptor(Application &app, beast::Journal j)
Maintains current and recent ledger validations.
STL namespace.
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:5
void handleNewValidation(Application &app, std::shared_ptr< STValidation > const &val, std::string const &source, BypassAccept const bypassAccept, std::optional< beast::Journal > j)
Handle a new validation.
std::uint32_t LedgerIndex
A ledger index.
Definition Protocol.h:370
@ Yes
We have consensus along with the network.
@ No
We do not have consensus.
uint256 LedgerHash
Validations< RCLValidationsAdaptor > RCLValidations
Alias for RCL-specific instantiation of generic Validations.
BaseUInt< 256 > uint256
Definition base_uint.h:580
BaseUInt< 160, detail::NodeIDTag > NodeID
NodeID is a 160-bit hash representing one node.
Definition UintTypes.h:47