xrpld
Loading...
Searching...
No Matches
SQLiteDatabase.h
1#pragma once
2
3#include <xrpl/basics/RangeSet.h>
4#include <xrpl/basics/base_uint.h>
5#include <xrpl/beast/utility/Journal.h>
6#include <xrpl/protocol/ErrorCodes.h>
7#include <xrpl/protocol/LedgerHeader.h>
8#include <xrpl/protocol/Protocol.h>
9#include <xrpl/protocol/TxSearched.h>
10#include <xrpl/rdb/DatabaseCon.h>
11#include <xrpl/rdb/RelationalDatabase.h>
12
13#include <cstddef>
14#include <cstdint>
15#include <functional>
16#include <map>
17#include <memory>
18#include <optional>
19#include <utility>
20#include <variant>
21#include <vector>
22
23namespace xrpl {
24
25class Config;
26class JobQueue;
27class ServiceRegistry;
28
30{
31public:
38 getMinLedgerSeq() override;
39
46 getMaxLedgerSeq() override;
47
54 getLedgerInfoByIndex(LedgerIndex ledgerSeq) override;
55
61 getNewestLedgerInfo() override;
62
70 getLedgerInfoByHash(uint256 const& ledgerHash) override;
71
79 getHashByIndex(LedgerIndex ledgerIndex) override;
80
89 getHashesByIndex(LedgerIndex ledgerIndex) override;
90
101 getHashesByIndex(LedgerIndex minSeq, LedgerIndex maxSeq) override;
102
111 getTxHistory(LedgerIndex startIndex) override;
112
120
128
134 void
135 deleteTransactionByLedgerSeq(LedgerIndex ledgerSeq) override;
136
142 void
143 deleteBeforeLedgerSeq(LedgerIndex ledgerSeq) override;
144
151 void
153
160 void
162
168 getTransactionCount() override;
169
177
185 getLedgerCountMinMax() override;
186
193 bool
194 saveValidatedLedger(std::shared_ptr<Ledger const> const& ledger, bool current) override;
195
204 getLimitedOldestLedgerInfo(LedgerIndex ledgerFirstIndex) override;
205
214 getLimitedNewestLedgerInfo(LedgerIndex ledgerFirstIndex) override;
215
228 getOldestAccountTxs(AccountTxOptions const& options) override;
229
242 getNewestAccountTxs(AccountTxOptions const& options) override;
243
256 getOldestAccountTxsB(AccountTxOptions const& options) override;
257
271 getNewestAccountTxsB(AccountTxOptions const& options) override;
272
286 oldestAccountTxPage(AccountTxPageOptions const& options) override;
287
301 newestAccountTxPage(AccountTxPageOptions const& options) override;
302
317 oldestAccountTxPageB(AccountTxPageOptions const& options) override;
318
333 newestAccountTxPageB(AccountTxPageOptions const& options) override;
334
352 uint256 const& id,
354 ErrorCodeI& ec) override;
355
361 getKBUsedAll() override;
362
369 getKBUsedLedger() override;
370
377 getKBUsedTransaction() override;
378
382 void
383 closeLedgerDB() override;
384
388 void
389 closeTransactionDB() override;
390
391 SQLiteDatabase(ServiceRegistry& registry, Config const& config, JobQueue& jobQueue);
392
394 SQLiteDatabase(SQLiteDatabase&& rhs) noexcept;
395
397 operator=(SQLiteDatabase const&) = delete;
400
407 bool
408 ledgerDbHasSpace(Config const& config);
409
416 bool
417 transactionDbHasSpace(Config const& config);
418
419private:
424
433 bool
435 Config const& config,
436 DatabaseCon::Setup const& setup,
437 DatabaseCon::CheckpointerSetup const& checkpointerSetup);
438
443 bool
445 {
446 return static_cast<bool>(ledgerDb_);
447 }
448
454 bool
456 {
457 return static_cast<bool>(txdb_);
458 }
459
465 auto
467 {
468 return ledgerDb_->checkoutDb();
469 }
470
476 auto
478 {
479 return txdb_->checkoutDb();
480 }
481};
482
493SQLiteDatabase
494setupRelationalDatabase(ServiceRegistry& registry, Config const& config, JobQueue& jobQueue);
495
496} // namespace xrpl
A generic endpoint for log messages.
Definition Journal.h:44
A pool of threads to perform work.
Definition JobQueue.h:60
std::vector< AccountTx > AccountTxs
std::vector< txnMetaLedgerType > MetaTxsList
bool existsLedger()
existsLedger Checks if the node store ledger database exists.
uint256 getHashByIndex(LedgerIndex ledgerIndex) override
getHashByIndex Returns the hash of the ledger with the given sequence.
MetaTxsList getNewestAccountTxsB(AccountTxOptions const &options) override
getNewestAccountTxsB Returns the newest transactions in binary form for the account that matches the ...
bool ledgerDbHasSpace(Config const &config)
ledgerDbHasSpace Checks if the ledger database has available space.
auto checkoutTransaction()
checkoutTransaction Checks out and returns the node store transaction database.
void deleteTransactionByLedgerSeq(LedgerIndex ledgerSeq) override
deleteTransactionByLedgerSeq Deletes transactions from the ledger with the given sequence.
std::optional< LedgerHeader > getLimitedOldestLedgerInfo(LedgerIndex ledgerFirstIndex) override
getLimitedOldestLedgerInfo Returns the info of the oldest ledger whose sequence number is greater tha...
SQLiteDatabase(ServiceRegistry &registry, Config const &config, JobQueue &jobQueue)
bool makeLedgerDBs(Config const &config, DatabaseCon::Setup const &setup, DatabaseCon::CheckpointerSetup const &checkpointerSetup)
makeLedgerDBs Opens ledger and transaction databases for the node store, and stores their descriptors...
std::vector< std::shared_ptr< Transaction > > getTxHistory(LedgerIndex startIndex) override
getTxHistory Returns the 20 most recent transactions starting from the given number.
AccountTxs getOldestAccountTxs(AccountTxOptions const &options) override
getOldestAccountTxs Returns the oldest transactions for the account that matches the given criteria s...
void closeTransactionDB() override
Closes the transaction database.
auto checkoutLedger()
checkoutTransaction Checks out and returns node store ledger database.
void closeLedgerDB() override
Closes the ledger database.
SQLiteDatabase & operator=(SQLiteDatabase const &)=delete
std::reference_wrapper< ServiceRegistry > registry_
std::optional< LedgerHeader > getLimitedNewestLedgerInfo(LedgerIndex ledgerFirstIndex) override
getLimitedNewestLedgerInfo Returns the info of the newest ledger whose sequence number is greater tha...
CountMinMax getLedgerCountMinMax() override
getLedgerCountMinMax Returns the minimum ledger sequence, maximum ledger sequence and total number of...
std::unique_ptr< DatabaseCon > txdb_
MetaTxsList getOldestAccountTxsB(AccountTxOptions const &options) override
getOldestAccountTxsB Returns the oldest transactions in binary form for the account that matches the ...
bool saveValidatedLedger(std::shared_ptr< Ledger const > const &ledger, bool current) override
saveValidatedLedger Saves a ledger into the database.
std::optional< LedgerIndex > getMaxLedgerSeq() override
getMaxLedgerSeq Returns the maximum ledger sequence in the Ledgers table.
std::optional< LedgerIndex > getMinLedgerSeq() override
getMinLedgerSeq Returns the minimum ledger sequence in the Ledgers table.
std::uint32_t getKBUsedTransaction() override
getKBUsedTransaction Returns the amount of space used by the transaction database.
std::uint32_t getKBUsedLedger() override
getKBUsedLedger Returns the amount of space space used by the ledger database.
AccountTxs getNewestAccountTxs(AccountTxOptions const &options) override
getNewestAccountTxs Returns the newest transactions for the account that matches the given criteria s...
void deleteAccountTransactionsBeforeLedgerSeq(LedgerIndex ledgerSeq) override
deleteAccountTransactionsBeforeLedgerSeq Deletes all account transactions with a sequence number less...
std::optional< LedgerIndex > getAccountTransactionsMinLedgerSeq() override
getAccountTransactionsMinLedgerSeq Returns the minimum ledger sequence stored in the AccountTransacti...
std::size_t getAccountTransactionCount() override
getAccountTransactionCount Returns the number of account transactions.
bool existsTransaction()
existsTransaction Checks if the node store transaction database exists.
std::pair< AccountTxs, std::optional< AccountTxMarker > > newestAccountTxPage(AccountTxPageOptions const &options) override
newestAccountTxPage Returns the newest transactions for the account that matches the given criteria s...
std::pair< MetaTxsList, std::optional< AccountTxMarker > > oldestAccountTxPageB(AccountTxPageOptions const &options) override
oldestAccountTxPageB Returns the oldest transactions in binary form for the account that matches the ...
void deleteTransactionsBeforeLedgerSeq(LedgerIndex ledgerSeq) override
deleteTransactionsBeforeLedgerSeq Deletes all transactions with a sequence number less than or equal ...
std::unique_ptr< DatabaseCon > ledgerDb_
std::optional< LedgerHeader > getLedgerInfoByHash(uint256 const &ledgerHash) override
getLedgerInfoByHash Returns the info of the ledger with given hash.
std::optional< LedgerHeader > getNewestLedgerInfo() override
getNewestLedgerInfo Returns the info of the newest saved ledger.
void deleteBeforeLedgerSeq(LedgerIndex ledgerSeq) override
deleteBeforeLedgerSeq Deletes all ledgers with a sequence number less than or equal to the given ledg...
std::uint32_t getKBUsedAll() override
getKBUsedAll Returns the amount of space used by all databases.
std::size_t getTransactionCount() override
getTransactionCount Returns the number of transactions.
std::optional< LedgerHashPair > getHashesByIndex(LedgerIndex ledgerIndex) override
getHashesByIndex Returns the hashes of the ledger and its parent as specified by the ledgerIndex.
std::optional< LedgerIndex > getTransactionsMinLedgerSeq() override
getTransactionsMinLedgerSeq Returns the minimum ledger sequence stored in the Transactions table.
std::pair< AccountTxs, std::optional< AccountTxMarker > > oldestAccountTxPage(AccountTxPageOptions const &options) override
oldestAccountTxPage Returns the oldest transactions for the account that matches the given criteria s...
bool transactionDbHasSpace(Config const &config)
transactionDbHasSpace Checks if the transaction database has available space.
std::pair< MetaTxsList, std::optional< AccountTxMarker > > newestAccountTxPageB(AccountTxPageOptions const &options) override
newestAccountTxPageB Returns the newest transactions in binary form for the account that matches the ...
SQLiteDatabase & operator=(SQLiteDatabase &&)=delete
std::optional< LedgerHeader > getLedgerInfoByIndex(LedgerIndex ledgerSeq) override
getLedgerInfoByIndex Returns a ledger by its sequence.
std::variant< AccountTx, TxSearched > getTransaction(uint256 const &id, std::optional< ClosedInterval< std::uint32_t > > const &range, ErrorCodeI &ec) override
getTransaction Returns the transaction with the given hash.
SQLiteDatabase(SQLiteDatabase const &)=delete
Service registry for dependency injection.
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:5
ErrorCodeI
Definition ErrorCodes.h:23
std::uint32_t LedgerIndex
A ledger index.
Definition Protocol.h:370
ClosedInterval< T > range(T low, T high)
Create a closed range interval.
Definition RangeSet.h:37
boost::icl::closed_interval< T > ClosedInterval
A closed interval over the domain T.
Definition RangeSet.h:27
SQLiteDatabase setupRelationalDatabase(ServiceRegistry &registry, Config const &config, JobQueue &jobQueue)
setupRelationalDatabase Creates and returns a SQLiteDatabase instance based on configuration.
BaseUInt< 256 > uint256
Definition base_uint.h:580