rippled
Loading...
Searching...
No Matches
include/xrpl/ledger/Ledger.h
1#pragma once
2
3#include <xrpl/basics/CountedObject.h>
4#include <xrpl/beast/utility/Journal.h>
5#include <xrpl/ledger/CachedView.h>
6#include <xrpl/ledger/View.h>
7#include <xrpl/protocol/Fees.h>
8#include <xrpl/protocol/Indexes.h>
9#include <xrpl/protocol/Rules.h>
10#include <xrpl/protocol/STLedgerEntry.h>
11#include <xrpl/protocol/Serializer.h>
12#include <xrpl/protocol/TxMeta.h>
13#include <xrpl/shamap/SHAMap.h>
14
15namespace xrpl {
16
17class ServiceRegistry;
18class Job;
19class TransactionMaster;
20
21class SqliteStatement;
22
24{
25 explicit create_genesis_t() = default;
26};
28
55class Ledger final : public std::enable_shared_from_this<Ledger>,
57 public TxsRawView,
58 public CountedObject<Ledger>
59{
60public:
61 Ledger(Ledger const&) = delete;
62 Ledger&
63 operator=(Ledger const&) = delete;
64
65 Ledger(Ledger&&) = delete;
66 Ledger&
67 operator=(Ledger&&) = delete;
68
83 Ledger(
85 Rules const& rules,
86 Fees const& fees,
87 std::vector<uint256> const& amendments,
88 Family& family);
89
90 Ledger(LedgerHeader const& info, Rules const& rules, Family& family);
91
99 Ledger(
100 LedgerHeader const& info,
101 bool& loaded,
102 bool acquire,
103 Rules const& rules,
104 Fees const& fees,
105 Family& family,
107
114 Ledger(Ledger const& previous, NetClock::time_point closeTime);
115
116 // used for database ledgers
117 Ledger(
118 std::uint32_t ledgerSeq,
119 NetClock::time_point closeTime,
120 Rules const& rules,
121 Fees const& fees,
122 Family& family);
123
124 ~Ledger() = default;
125
126 //
127 // ReadView
128 //
129
130 bool
131 open() const override
132 {
133 return false;
134 }
135
136 LedgerHeader const&
137 header() const override
138 {
139 return header_;
140 }
141
142 void
144 {
145 header_ = info;
146 }
147
148 Fees const&
149 fees() const override
150 {
151 return fees_;
152 }
153
154 Rules const&
155 rules() const override
156 {
157 return rules_;
158 }
159
160 bool
161 exists(Keylet const& k) const override;
162
163 bool
164 exists(uint256 const& key) const;
165
167 succ(uint256 const& key, std::optional<uint256> const& last = std::nullopt) const override;
168
170 read(Keylet const& k) const override;
171
173 slesBegin() const override;
174
176 slesEnd() const override;
177
179 slesUpperBound(uint256 const& key) const override;
180
182 txsBegin() const override;
183
185 txsEnd() const override;
186
187 bool
188 txExists(uint256 const& key) const override;
189
190 tx_type
191 txRead(key_type const& key) const override;
192
193 //
194 // DigestAwareReadView
195 //
196
198 digest(key_type const& key) const override;
199
200 //
201 // RawView
202 //
203
204 void
205 rawErase(std::shared_ptr<SLE> const& sle) override;
206
207 void
208 rawInsert(std::shared_ptr<SLE> const& sle) override;
209
210 void
211 rawErase(uint256 const& key);
212
213 void
214 rawReplace(std::shared_ptr<SLE> const& sle) override;
215
216 void
217 rawDestroyXRP(XRPAmount const& fee) override
218 {
219 header_.drops -= fee;
220 }
221
222 //
223 // TxsRawView
224 //
225
226 void
228 uint256 const& key,
230 std::shared_ptr<Serializer const> const& metaData) override;
231
232 // Insert the transaction, and return the hash of the SHAMap leaf node
233 // holding the transaction. The hash can be used to fetch the transaction
234 // directly, instead of traversing the SHAMap
235 // @param key transaction ID
236 // @param txn transaction
237 // @param metaData transaction metadata
238 // @return hash of SHAMap leaf node that holds the transaction
239 uint256
241 uint256 const& key,
243 std::shared_ptr<Serializer const> const& metaData);
244
245 //--------------------------------------------------------------------------
246
247 void
249 {
250 header_.validated = true;
251 }
252
253 void
255 NetClock::time_point closeTime,
256 NetClock::duration closeResolution,
257 bool correctCloseTime);
258
259 void
260 setImmutable(bool rehash = true);
261
262 bool
264 {
265 return mImmutable;
266 }
267
268 /* Mark this ledger as "should be full".
269
270 "Full" is metadata property of the ledger, it indicates
271 that the local server wants all the corresponding nodes
272 in durable storage.
273
274 This is marked `const` because it reflects metadata
275 and not data that is in common with other nodes on the
276 network.
277 */
278 void
286
287 void
289 {
290 header_.drops = totDrops;
291 }
292
293 SHAMap const&
294 stateMap() const
295 {
296 return stateMap_;
297 }
298
299 SHAMap&
301 {
302 return stateMap_;
303 }
304
305 SHAMap const&
306 txMap() const
307 {
308 return txMap_;
309 }
310
311 SHAMap&
313 {
314 return txMap_;
315 }
316
317 // returns false on error
318 bool
319 addSLE(SLE const& sle);
320
321 //--------------------------------------------------------------------------
322
323 void
325
326 bool
327 walkLedger(beast::Journal j, bool parallel = false) const;
328
329 bool
330 isSensible() const;
331
332 void
333 invariants() const;
334 void
335 unshare() const;
336
343 negativeUNL() const;
344
351 validatorToDisable() const;
352
359 validatorToReEnable() const;
360
366 void
368
370 bool
371 isFlagLedger() const;
372
374 bool
375 isVotingLedger() const;
376
378 peek(Keylet const& k) const;
379
380private:
381 class sles_iter_impl;
382 class txs_iter_impl;
383
384 bool
385 setup();
386
394 deserializeTx(SHAMapItem const& item);
395
407
409
410 // A SHAMap containing the transactions associated with this ledger.
411 SHAMap mutable txMap_;
412
413 // A SHAMap containing the state objects for this ledger.
415
416 // Protects fee variables
418
423};
424
427
428} // namespace xrpl
A generic endpoint for log messages.
Definition Journal.h:40
Wraps a DigestAwareReadView to provide caching.
Definition CachedView.h:133
Tracks the number of instances of an object.
ReadView that associates keys with digests.
Definition ReadView.h:229
bool txExists(uint256 const &key) const override
std::unique_ptr< txs_type::iter_base > txsEnd() const override
bool isFlagLedger() const
Returns true if the ledger is a flag ledger.
std::optional< digest_type > digest(key_type const &key) const override
Return the digest associated with the key.
void rawTxInsert(uint256 const &key, std::shared_ptr< Serializer const > const &txn, std::shared_ptr< Serializer const > const &metaData) override
std::optional< PublicKey > validatorToDisable() const
get the to be disabled validator's master public key if any
void setLedgerInfo(LedgerHeader const &info)
uint256 rawTxInsertWithHash(uint256 const &key, std::shared_ptr< Serializer const > const &txn, std::shared_ptr< Serializer const > const &metaData)
std::shared_ptr< SLE const > read(Keylet const &k) const override
Return the state item associated with a key.
void updateNegativeUNL()
update the Negative UNL ledger component.
bool isVotingLedger() const
Returns true if the ledger directly precedes a flag ledger.
std::unique_ptr< sles_type::iter_base > slesBegin() const override
hash_set< PublicKey > negativeUNL() const
get Negative UNL validators' master public keys
Ledger(Ledger &&)=delete
void rawInsert(std::shared_ptr< SLE > const &sle) override
Unconditionally insert a state item.
void rawReplace(std::shared_ptr< SLE > const &sle) override
Unconditionally replace a state item.
void setImmutable(bool rehash=true)
SHAMap const & stateMap() const
SHAMap const & txMap() const
bool open() const override
Returns true if this reflects an open ledger.
void rawErase(std::shared_ptr< SLE > const &sle) override
Delete an existing state item.
static std::pair< std::shared_ptr< STTx const >, std::shared_ptr< STObject const > > deserializeTxPlusMeta(SHAMapItem const &item)
Deserialize a SHAMapItem containing STTx + STObject metadata.
LedgerHeader const & header() const override
Returns information about the ledger.
void setAccepted(NetClock::time_point closeTime, NetClock::duration closeResolution, bool correctCloseTime)
Ledger(Ledger const &)=delete
static std::shared_ptr< STTx const > deserializeTx(SHAMapItem const &item)
Deserialize a SHAMapItem containing a single STTx.
Ledger & operator=(Ledger const &)=delete
std::shared_ptr< SLE > peek(Keylet const &k) const
void setTotalDrops(std::uint64_t totDrops)
~Ledger()=default
bool addSLE(SLE const &sle)
void rawDestroyXRP(XRPAmount const &fee) override
Destroy XRP.
std::unique_ptr< txs_type::iter_base > txsBegin() const override
std::unique_ptr< sles_type::iter_base > slesEnd() const override
std::optional< uint256 > succ(uint256 const &key, std::optional< uint256 > const &last=std::nullopt) const override
Ledger & operator=(Ledger &&)=delete
Rules const & rules() const override
Returns the tx processing rules.
Fees const & fees() const override
Returns the fees for the base ledger.
bool walkLedger(beast::Journal j, bool parallel=false) const
std::unique_ptr< sles_type::iter_base > slesUpperBound(uint256 const &key) const override
std::optional< PublicKey > validatorToReEnable() const
get the to be re-enabled validator's master public key if any
tx_type txRead(key_type const &key) const override
Read a transaction from the tx map.
bool exists(Keylet const &k) const override
Determine if a state item exists.
std::pair< std::shared_ptr< STTx const >, std::shared_ptr< STObject const > > tx_type
Definition ReadView.h:33
uint256 key_type
Definition ReadView.h:35
Rules controlling protocol behavior.
Definition Rules.h:18
A SHAMap is both a radix tree with a fan-out of 16 and a Merkle tree.
Definition SHAMap.h:77
void setLedgerSeq(std::uint32_t lseq)
Definition SHAMap.h:538
void setFull()
Definition SHAMap.h:532
Interface for changing ledger entries with transactions.
Definition RawView.h:75
T is_same_v
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:5
create_genesis_t const create_genesis
Reflects the fee settings for a particular ledger.
A pair of SHAMap key and LedgerEntryType.
Definition Keylet.h:19
Information about the notional ledger backing the view.