xrpld
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;
20
21class SqliteStatement;
22
24{
25 explicit CreateGenesisT() = 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(
86 Fees const& fees,
87 std::vector<uint256> const& amendments,
88 Family& family);
89
90 Ledger(LedgerHeader const& info, Rules rules, Family& family);
91
99 Ledger(
100 LedgerHeader const& info,
101 bool& loaded,
102 bool acquire,
103 Rules 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 rules,
121 Fees const& fees,
122 Family& family);
123
124 ~Ledger() override = 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(SLE::ref sle) override;
206
207 void
208 rawInsert(SLE::ref sle) override;
209
210 void
211 rawErase(uint256 const& key);
212
213 void
214 rawReplace(SLE::ref 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 //--------------------------------------------------------------------------
233
234 void
236 {
237 header_.validated = true;
238 }
239
240 void
242 NetClock::time_point closeTime,
243 NetClock::duration closeResolution,
244 bool correctCloseTime);
245
246 void
247 setImmutable(bool rehash = true);
248
249 bool
251 {
252 return immutable_;
253 }
254
255 /* Mark this ledger as "should be full".
256
257 "Full" is metadata property of the ledger, it indicates
258 that the local server wants all the corresponding nodes
259 in durable storage.
260
261 This is marked `const` because it reflects metadata
262 and not data that is in common with other nodes on the
263 network.
264 */
265 void
266 setFull() const
267 {
268 txMap_.setFull();
269 txMap_.setLedgerSeq(header_.seq);
270 stateMap_.setFull();
271 stateMap_.setLedgerSeq(header_.seq);
272 }
273
274 void
276 {
277 header_.drops = totDrops;
278 }
279
280 SHAMap const&
281 stateMap() const
282 {
283 return stateMap_;
284 }
285
286 SHAMap&
288 {
289 return stateMap_;
290 }
291
292 SHAMap const&
293 txMap() const
294 {
295 return txMap_;
296 }
297
298 SHAMap&
300 {
301 return txMap_;
302 }
303
304 // returns false on error
305 bool
306 addSLE(SLE const& sle);
307
308 //--------------------------------------------------------------------------
309
310 void
312
313 bool
314 walkLedger(beast::Journal j, bool parallel = false) const;
315
316 bool
317 isSensible() const;
318
319 void
320 invariants() const;
321 void
322 unshare() const;
323
330 negativeUNL() const;
331
338 validatorToDisable() const;
339
346 validatorToReEnable() const;
347
353 void
355
357 bool
358 isFlagLedger() const;
359
361 bool
362 isVotingLedger() const;
363
365 peek(Keylet const& k) const;
366
367private:
368 class SlesIterImpl;
369 class TxsIterImpl;
370
371 bool
372 setup();
373
381 deserializeTx(SHAMapItem const& item);
382
394
396
397 // A SHAMap containing the transactions associated with this ledger.
398 SHAMap mutable txMap_;
399
400 // A SHAMap containing the state objects for this ledger.
402
403 // Protects fee variables
405
410};
411
414
415} // namespace xrpl
A generic endpoint for log messages.
Definition Journal.h:38
Wraps a DigestAwareReadView to provide caching.
Definition CachedView.h:133
void rawErase(SLE::ref sle) override
Delete an existing state item.
bool txExists(uint256 const &key) const override
std::unique_ptr< TxsType::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)
void updateNegativeUNL()
update the Negative UNL ledger component.
void rawInsert(SLE::ref sle) override
Unconditionally insert a state item.
bool isVotingLedger() const
Returns true if the ledger directly precedes a flag ledger.
std::unique_ptr< SlesType::iter_base > slesBegin() const override
hash_set< PublicKey > negativeUNL() const
get Negative UNL validators' master public keys
Ledger(Ledger &&)=delete
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.
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
void rawReplace(SLE::ref sle) override
Unconditionally replace a state item.
static std::shared_ptr< STTx const > deserializeTx(SHAMapItem const &item)
Deserialize a SHAMapItem containing a single STTx.
Ledger & operator=(Ledger const &)=delete
void setTotalDrops(std::uint64_t totDrops)
bool addSLE(SLE const &sle)
void rawDestroyXRP(XRPAmount const &fee) override
Destroy XRP.
std::unique_ptr< TxsType::iter_base > txsBegin() const override
std::unique_ptr< SlesType::iter_base > slesEnd() const override
~Ledger() override=default
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< SlesType::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.
SLE::const_pointer read(Keylet const &k) const override
Return the state item associated with a key.
SLE::pointer peek(Keylet const &k) const
bool exists(Keylet const &k) const override
Determine if a state item exists.
std::chrono::time_point< NetClock > time_point
Definition chrono.h:46
std::chrono::duration< rep, period > duration
Definition chrono.h:45
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:33
A SHAMap is both a radix tree with a fan-out of 16 and a Merkle tree.
Definition SHAMap.h:77
std::shared_ptr< STLedgerEntry > const & ref
std::shared_ptr< STLedgerEntry > pointer
std::shared_ptr< STLedgerEntry const > const_pointer
Service registry for dependency injection.
Interface for changing ledger entries with transactions.
Definition RawView.h:75
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:5
CreateGenesisT const kCreateGenesis
std::unordered_set< Value, Hash, Pred, Allocator > hash_set
STLedgerEntry SLE
CachedView< Ledger > CachedLedger
A ledger wrapped in a CachedView.
BaseUInt< 256 > uint256
Definition base_uint.h:562
CreateGenesisT()=default
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.