20 #include <ripple/app/ledger/AcceptedLedger.h>
21 #include <ripple/app/ledger/LedgerMaster.h>
22 #include <ripple/app/ledger/LedgerToJson.h>
23 #include <ripple/app/ledger/TransactionMaster.h>
24 #include <ripple/app/misc/Manifest.h>
25 #include <ripple/app/misc/impl/AccountTxPaging.h>
26 #include <ripple/app/rdb/RelationalDBInterface_nodes.h>
27 #include <ripple/app/rdb/RelationalDBInterface_postgres.h>
28 #include <ripple/app/rdb/RelationalDBInterface_shards.h>
29 #include <ripple/app/rdb/backend/RelationalDBInterfaceSqlite.h>
30 #include <ripple/basics/BasicConfig.h>
31 #include <ripple/basics/StringUtilities.h>
32 #include <ripple/core/DatabaseCon.h>
33 #include <ripple/core/SociDB.h>
34 #include <ripple/json/to_string.h>
35 #include <ripple/nodestore/DatabaseShard.h>
36 #include <boost/algorithm/string.hpp>
37 #include <boost/range/adaptor/transformed.hpp>
38 #include <soci/sqlite3/soci-sqlite3.h>
51 ,
j_(
app_.journal(
"Ledger"))
60 <<
"AccountTransactions database should not have a primary key";
61 Throw<std::runtime_error>(
62 "AccountTransactions database initialization failed.");
72 <<
"Error during meta DB init";
73 Throw<std::runtime_error>(
74 "Shard meta database initialization failed.");
114 bool current)
override;
269 return static_cast<bool>(
lgrdb_);
279 return static_cast<bool>(
txdb_);
299 return lgrdb_->checkoutDb();
309 return txdb_->checkoutDb();
326 ledgerSeq, callback);
343 ledgerSeq, callback);
361 bool(soci::session& session,
std::uint32_t shardIndex)>
const&
365 firstIndex, callback);
383 bool(soci::session& session,
std::uint32_t shardIndex)>
const&
387 firstIndex, callback);
405 bool(soci::session& session,
std::uint32_t shardIndex)>
const&
409 firstIndex, callback);
427 bool(soci::session& session,
std::uint32_t shardIndex)>
const&
431 firstIndex, callback);
441 auto [lgr, tx, res] =
443 txdb_ = std::move(tx);
454 auto [lgrMetaDB, txMetaDB] =
734 res.numberOfRows += r.numberOfRows;
735 if (res.minLedgerSequence == 0)
736 res.minLedgerSequence = r.minLedgerSequence;
737 res.maxLedgerSequence = r.maxLedgerSequence;
761 if (ledger->info().seq < shardStore->earliestLedgerSeq())
769 auto lgrMetaSession =
lgrMetaDB_->checkoutDb();
770 auto txMetaSession =
txMetaDB_->checkoutDb();
777 shardStore->seqToShardIndex(ledger->info().seq));
795 doLedger(ledgerSeq, [&](soci::session& session) {
850 session, ledgerFirstIndex,
j_))
880 session, ledgerFirstIndex,
j_))
906 auto lgrMetaSession =
lgrMetaDB_->checkoutDb();
908 if (
auto const shardIndex =
911 shardStore->callForLedgerSQLByShardIndex(
912 *shardIndex, [&](soci::session& session) {
936 doLedger(ledgerIndex, [&](soci::session& session) {
958 doLedger(ledgerIndex, [&](soci::session& session) {
982 while (minSeq <= maxSeq)
985 if (shardMaxSeq > maxSeq)
986 shardMaxSeq = maxSeq;
987 doLedger(minSeq, [&](soci::session& session) {
990 res.
insert(r.begin(), r.end());
993 minSeq = shardMaxSeq + 1;
1021 session,
app_, startIndex, quantity,
true);
1022 txs.
insert(txs.
end(), tx.begin(), tx.end());
1032 startIndex += total;
1069 if (opt.maxLedger &&
1070 shardIndex > seqToShardIndex(opt.maxLedger))
1072 auto [r, total] = ripple::getOldestAccountTxs(
1073 session, app_, ledgerMaster, opt, limit_used, j_);
1074 ret.insert(ret.end(), r.begin(), r.end());
1079 limit_used += total;
1090 if (opt.offset <= total)
1093 opt.offset -= total;
1104 RelationalDBInterface::AccountTxs
1105 RelationalDBInterfaceSqliteImp::getNewestAccountTxs(
1113 if (existsTransaction())
1115 auto db = checkoutTransaction();
1121 if (shardStoreExists())
1126 iterateTransactionBack(
1130 if (opt.minLedger &&
1131 shardIndex < seqToShardIndex(opt.minLedger))
1133 auto [r, total] = ripple::getNewestAccountTxs(
1134 session, app_, ledgerMaster, opt, limit_used, j_);
1135 ret.insert(ret.end(), r.begin(), r.end());
1140 limit_used += total;
1151 if (opt.offset <= total)
1154 opt.offset -= total;
1165 RelationalDBInterface::MetaTxsList
1166 RelationalDBInterfaceSqliteImp::getOldestAccountTxsB(
1172 if (existsTransaction())
1174 auto db = checkoutTransaction();
1178 if (shardStoreExists())
1183 iterateTransactionForward(
1187 if (opt.maxLedger &&
1188 shardIndex > seqToShardIndex(opt.maxLedger))
1190 auto [r, total] = ripple::getOldestAccountTxsB(
1191 session, app_, opt, limit_used, j_);
1192 ret.insert(ret.end(), r.begin(), r.end());
1197 limit_used += total;
1208 if (opt.offset <= total)
1211 opt.offset -= total;
1222 RelationalDBInterface::MetaTxsList
1223 RelationalDBInterfaceSqliteImp::getNewestAccountTxsB(
1229 if (existsTransaction())
1231 auto db = checkoutTransaction();
1235 if (shardStoreExists())
1240 iterateTransactionBack(
1244 if (opt.minLedger &&
1245 shardIndex < seqToShardIndex(opt.minLedger))
1247 auto [r, total] = ripple::getNewestAccountTxsB(
1248 session, app_, opt, limit_used, j_);
1249 ret.insert(ret.end(), r.begin(), r.end());
1254 limit_used += total;
1265 if (opt.offset <= total)
1268 opt.offset -= total;
1280 RelationalDBInterface::AccountTxs,
1282 RelationalDBInterfaceSqliteImp::oldestAccountTxPage(
1290 auto onUnsavedLedger =
1294 auto onTransaction = [&ret, &app](
1302 if (existsTransaction())
1304 auto db = checkoutTransaction();
1314 return {ret, newmarker};
1317 if (shardStoreExists())
1321 iterateTransactionForward(
1325 if (opt.maxLedger != UINT32_MAX &&
1326 shardIndex > seqToShardIndex(opt.minLedger))
1328 auto [marker, total] = ripple::oldestAccountTxPage(
1336 opt.marker = marker;
1339 limit_used += total;
1343 return {ret, opt.
marker};
1352 RelationalDBInterfaceSqliteImp::newestAccountTxPage(
1360 auto onUnsavedLedger =
1364 auto onTransaction = [&ret, &app](
1372 if (existsTransaction())
1374 auto db = checkoutTransaction();
1384 return {ret, newmarker};
1387 if (shardStoreExists())
1391 iterateTransactionBack(
1395 if (opt.minLedger &&
1396 shardIndex < seqToShardIndex(opt.minLedger))
1398 auto [marker, total] = ripple::newestAccountTxPage(
1406 opt.marker = marker;
1409 limit_used += total;
1413 return {ret, opt.
marker};
1422 RelationalDBInterfaceSqliteImp::oldestAccountTxPageB(
1430 auto onUnsavedLedger =
1433 auto onTransaction = [&ret](
1438 ret.
emplace_back(std::move(rawTxn), std::move(rawMeta), ledgerIndex);
1441 if (existsTransaction())
1443 auto db = checkoutTransaction();
1453 return {ret, newmarker};
1456 if (shardStoreExists())
1460 iterateTransactionForward(
1464 if (opt.maxLedger != UINT32_MAX &&
1465 shardIndex > seqToShardIndex(opt.minLedger))
1467 auto [marker, total] = ripple::oldestAccountTxPage(
1475 opt.marker = marker;
1478 limit_used += total;
1482 return {ret, opt.
marker};
1491 RelationalDBInterfaceSqliteImp::newestAccountTxPageB(
1499 auto onUnsavedLedger =
1502 auto onTransaction = [&ret](
1507 ret.
emplace_back(std::move(rawTxn), std::move(rawMeta), ledgerIndex);
1510 if (existsTransaction())
1512 auto db = checkoutTransaction();
1522 return {ret, newmarker};
1525 if (shardStoreExists())
1529 iterateTransactionBack(
1533 if (opt.minLedger &&
1534 shardIndex < seqToShardIndex(opt.minLedger))
1536 auto [marker, total] = ripple::newestAccountTxPage(
1544 opt.marker = marker;
1547 limit_used += total;
1551 return {ret, opt.
marker};
1558 RelationalDBInterfaceSqliteImp::getTransaction(
1564 return TxSearched::unknown;
1566 if (existsTransaction())
1568 auto db = checkoutTransaction();
1575 auto txMetaSession = txMetaDB_->checkoutDb();
1577 if (
auto const shardIndex =
1580 shardStore->callForTransactionSQLByShardIndex(
1581 *shardIndex, [&](soci::session& session) {
1586 range->lower(), firstLedgerSeq(*shardIndex));
1588 range->upper(), lastLedgerSeq(*shardIndex));
1594 return res.
index() == 1 &&
1595 std::get<TxSearched>(res) !=
1596 TxSearched::unknown;
1603 return TxSearched::unknown;
1607 RelationalDBInterfaceSqliteImp::ledgerDbHasSpace(
Config const& config)
1611 auto db = checkoutLedger();
1615 if (shardStoreExists())
1617 return iterateLedgerBack(
1627 RelationalDBInterfaceSqliteImp::transactionDbHasSpace(
Config const& config)
1632 if (existsTransaction())
1634 auto db = checkoutTransaction();
1638 if (shardStoreExists())
1640 return iterateTransactionBack(
1650 RelationalDBInterfaceSqliteImp::getKBUsedAll()
1657 if (shardStoreExists())
1672 RelationalDBInterfaceSqliteImp::getKBUsedLedger()
1679 if (shardStoreExists())
1694 RelationalDBInterfaceSqliteImp::getKBUsedTransaction()
1699 if (existsTransaction())
1704 if (shardStoreExists())
1707 iterateTransactionBack(
1719 RelationalDBInterfaceSqliteImp::closeLedgerDB()
1725 RelationalDBInterfaceSqliteImp::closeTransactionDB()
1736 return std::make_unique<RelationalDBInterfaceSqliteImp>(
1737 app, config, jobQueue);
std::uint32_t lastLedgerSeq(std::uint32_t shardIndex) const noexcept
Calculates the last ledger sequence for a given shard index.
void deleteTransactionByLedgerSeq(LedgerIndex ledgerSeq) override
deleteTransactionByLedgerSeq Deletes transactions from ledger with given sequence.
std::optional< LedgerInfo > getLedgerInfoByIndex(soci::session &session, LedgerIndex ledgerSeq, beast::Journal j)
getLedgerInfoByIndex Returns ledger by its sequence.
void deleteBeforeLedgerSeq(soci::session &session, TableType type, LedgerIndex ledgerSeq)
deleteBeforeLedgerSeq Deletes all entries in given table for the ledgers with given sequence and all ...
@ ledgerMaster
ledger master data for signing
virtual bool callForLedgerSQLByLedgerSeq(LedgerIndex ledgerSeq, std::function< bool(soci::session &session)> const &callback)=0
Invoke a callback on the SQLite db holding the corresponding ledger.
std::pair< std::vector< std::shared_ptr< Transaction > >, int > getTxHistory(soci::session &session, Application &app, LedgerIndex startIndex, int quantity, bool count)
getTxHistory Returns given number of most recent transactions starting from given number of entry.
uint256 getHashByIndex(soci::session &session, LedgerIndex ledgerIndex)
getHashByIndex Returns hash of ledger with given sequence.
std::unique_ptr< RelationalDBInterface > getRelationalDBInterfaceSqlite(Application &app, Config const &config, JobQueue &jobQueue)
std::pair< RelationalDBInterface::AccountTxs, int > getOldestAccountTxs(soci::session &session, Application &app, LedgerMaster &ledgerMaster, RelationalDBInterface::AccountTxOptions const &options, std::optional< int > const &limit_used, beast::Journal j)
getOldestAccountTxs Returns oldest transactions for given account which match given criteria starting...
std::pair< MetaTxsList, std::optional< AccountTxMarker > > newestAccountTxPageB(AccountTxPageOptions const &options) override
newestAccountTxPageB Returns newest transactions in binary form for given account which match given c...
std::unique_ptr< DatabaseCon > txMetaDB_
std::pair< std::vector< RelationalDBInterface::txnMetaLedgerType >, int > getOldestAccountTxsB(soci::session &session, Application &app, RelationalDBInterface::AccountTxOptions const &options, std::optional< int > const &limit_used, beast::Journal j)
getOldestAccountTxsB Returns oldest transactions in binary form for given account which match given c...
MetaTxsList getNewestAccountTxsB(AccountTxOptions const &options) override
getNewestAccountTxsB Returns newest transactions in binary form for given account which match given c...
std::unique_ptr< DatabaseCon > lgrdb_
void deleteAccountTransactionsBeforeLedgerSeq(LedgerIndex ledgerSeq) override
deleteAccountTransactionsBeforeLedgerSeq Deletes all account transactions with given ledger sequence ...
std::pair< AccountTxs, std::optional< AccountTxMarker > > oldestAccountTxPage(AccountTxPageOptions const &options) override
oldestAccountTxPage Returns oldest transactions for given account which match given criteria starting...
std::pair< MetaTxsList, std::optional< AccountTxMarker > > oldestAccountTxPageB(AccountTxPageOptions const &options) override
oldestAccountTxPageB Returns oldest transactions in binary form for given account which match given c...
DatabaseCon::Setup setup_DatabaseCon(Config const &c, std::optional< beast::Journal > j=std::nullopt)
bool iterateTransactionBack(std::optional< std::uint32_t > firstIndex, std::function< bool(soci::session &session, std::uint32_t shardIndex)> const &callback)
iterateTransactionForward Checks out transaction databases for all shards in descending order startin...
bool shardStoreExists()
shardStoreExists Checks whether the shard store exists
RelationalDBInterface::CountMinMax getRowsMinMax(soci::session &session, TableType type)
getRowsMinMax Returns minumum ledger sequence, maximum ledger sequence and total number of rows in gi...
std::pair< std::optional< RelationalDBInterface::AccountTxMarker >, int > newestAccountTxPage(soci::session &session, AccountIDCache const &idCache, std::function< void(std::uint32_t)> const &onUnsavedLedger, std::function< void(std::uint32_t, std::string const &, Blob &&, Blob &&)> const &onTransaction, RelationalDBInterface::AccountTxPageOptions const &options, int limit_used, std::uint32_t page_length)
newestAccountTxPage Searches newest transactions for given account which match given criteria startin...
std::uint32_t getKBUsedDB(soci::session &s)
std::optional< LedgerInfo > getLedgerInfoByHash(soci::session &session, uint256 const &ledgerHash, beast::Journal j)
getLedgerInfoByHash Returns info of ledger with given hash.
virtual NodeStore::DatabaseShard * getShardStore()=0
std::optional< LedgerIndex > getAccountTransactionsMinLedgerSeq() override
getAccountTransactionsMinLedgerSeq Returns minimum ledger sequence among records in the AccountTransa...
virtual bool callForTransactionSQLByLedgerSeq(LedgerIndex ledgerSeq, std::function< bool(soci::session &session)> const &callback)=0
Invoke a callback on the transaction SQLite db for the corresponding ledger.
std::unique_ptr< DatabaseCon > lgrMetaDB_
std::optional< AccountTxMarker > marker
auto checkoutTransaction()
checkoutTransaction Checks out and returns node transaction DB.
std::unique_ptr< DatabaseCon > txdb_
void closeLedgerDB() override
Closes the ledger database.
bool iterateLedgerBack(std::optional< std::uint32_t > firstIndex, std::function< bool(soci::session &session, std::uint32_t shardIndex)> const &callback)
iterateLedgerBack Checks out ledger databases for all shards in descending order starting from given ...
uint256 getHashByIndex(LedgerIndex ledgerIndex) override
getHashByIndex Returns hash of ledger with given sequence.
bool transactionDbHasSpace(Config const &config) override
transactionDbHasSpace Checks if transaction database has available space.
std::optional< LedgerInfo > getLimitedNewestLedgerInfo(soci::session &session, LedgerIndex ledgerFirstIndex, beast::Journal j)
getLimitedNewestLedgerInfo Returns info of newest ledger from ledgers with sequences greather or equa...
std::optional< LedgerInfo > getLimitedOldestLedgerInfo(soci::session &session, LedgerIndex ledgerFirstIndex, beast::Journal j)
getLimitedOldestLedgerInfo Returns info of oldest ledger from ledgers with sequences greather or equa...
bool iterateTransactionForward(std::optional< std::uint32_t > firstIndex, std::function< bool(soci::session &session, std::uint32_t shardIndex)> const &callback)
iterateTransactionForward Checks out transaction databases for all shards in ascending order starting...
virtual AccountIDCache const & accountIDCache() const =0
bool makeLedgerDBs(Config const &config, DatabaseCon::Setup const &setup, DatabaseCon::CheckpointerSetup const &checkpointerSetup)
makeLedgerDBs Opens node ledger and transaction databases, and saves its descriptors into internal va...
std::pair< RelationalDBInterface::AccountTxs, int > getNewestAccountTxs(soci::session &session, Application &app, LedgerMaster &ledgerMaster, RelationalDBInterface::AccountTxOptions const &options, std::optional< int > const &limit_used, beast::Journal j)
getNewestAccountTxs Returns newest transactions for given account which match given criteria starting...
bool doLedger(LedgerIndex ledgerSeq, std::function< bool(soci::session &session)> const &callback)
doLedger Checks out ledger database for shard containing given ledger and calls given callback functi...
Integers of any length that is a multiple of 32-bits.
LedgerIndex lastLedgerSeq(std::uint32_t shardIndex)
lastLedgerSeq Returns last ledger sequence for given shard.
MetaTxsList getOldestAccountTxsB(AccountTxOptions const &options) override
getOldestAccountTxsB Returns oldest transactions in binary form for given account which match given c...
std::uint32_t firstLedgerSeq(std::uint32_t shardIndex) const noexcept
Calculates the first ledger sequence for a given shard index.
std::uint32_t getKBUsedAll(soci::session &s)
std::uint32_t getKBUsedAll() override
getKBUsedAll Returns space used by all databases.
static bool saveValidatedLedger(Application &app, std::shared_ptr< Ledger const > const &ledger, bool current)
void deleteTransactionsBeforeLedgerSeq(LedgerIndex ledgerSeq) override
deleteTransactionsBeforeLedgerSeq Deletes all transactions with given ledger sequence and all sequenc...
virtual LedgerMaster & getLedgerMaster()=0
virtual bool iterateLedgerSQLsBack(std::optional< std::uint32_t > maxShardIndex, std::function< bool(soci::session &session, std::uint32_t shardIndex)> const &callback)=0
iterateLedgerSQLsBack Checks out ledger databases for all shards in descending order starting from gi...
std::optional< LedgerInfo > getLimitedOldestLedgerInfo(LedgerIndex ledgerFirstIndex) override
getLimitedOldestLedgerInfo Returns info of oldest ledger from ledgers with sequences greater or equal...
bool existsLedger()
existsLedger Checks if node ledger DB exists.
virtual bool iterateLedgerSQLsForward(std::optional< std::uint32_t > minShardIndex, std::function< bool(soci::session &session, std::uint32_t shardIndex)> const &callback)=0
iterateLedgerSQLsForward Checks out ledger databases for all shards in ascending order starting from ...
std::size_t getTransactionCount() override
getTransactionCount Returns number of transactions.
void saveLedgerAsync(Application &app, std::uint32_t seq)
auto checkoutLedger()
checkoutTransaction Checks out and returns node ledger DB.
std::optional< LedgerInfo > getLedgerInfoByHash(uint256 const &ledgerHash) override
std::optional< LedgerInfo > getNewestLedgerInfo() override
getNewestLedgerInfo Returns info of newest saved ledger.
std::optional< LedgerIndex > getMinLedgerSeq() override
getMinLedgerSeq Returns minimum ledger sequence in Ledgers table.
void deleteBeforeLedgerSeq(LedgerIndex ledgerSeq) override
deleteBeforeLedgerSeq Deletes all ledgers with given sequence and all sequences below it.
void deleteByLedgerSeq(soci::session &session, TableType type, LedgerIndex ledgerSeq)
deleteByLedgerSeq Deletes all entries in given table for the ledger with given sequence.
bool makeMetaDBs(Config const &config, DatabaseCon::Setup const &setup, DatabaseCon::CheckpointerSetup const &checkpointerSetup)
makeMetaDBs Opens shard index lookup databases, and saves their descriptors into internal variables.
@ current
This was a new validation and was added.
A generic endpoint for log messages.
ClosedInterval< T > range(T low, T high)
Create a closed range interval.
RelationalDBInterface::CountMinMax getLedgerCountMinMax() override
getLedgerCountMinMax Returns minumum ledger sequence, maximum ledger sequence and total number of sav...
std::optional< LedgerInfo > getLimitedNewestLedgerInfo(LedgerIndex ledgerFirstIndex) override
getLimitedNewestLedgerInfo Returns info of newest ledger from ledgers with sequences greater or equal...
A pool of threads to perform work.
LedgerIndex firstLedgerSeq(std::uint32_t shardIndex)
firstLedgerSeq Returns first ledger sequence for given shard.
std::pair< std::vector< RelationalDBInterface::txnMetaLedgerType >, int > getNewestAccountTxsB(soci::session &session, Application &app, RelationalDBInterface::AccountTxOptions const &options, std::optional< int > const &limit_used, beast::Journal j)
getNewestAccountTxsB Returns newest transactions in binary form for given account which match given c...
bool existsTransaction()
existsTransaction Checks if node transaction DB exists.
std::uint32_t getKBUsedTransaction() override
getKBUsedTransaction Returns space used by transaction database.
std::vector< std::shared_ptr< Transaction > > getTxHistory(LedgerIndex startIndex) override
getTxHistory Returns most recent 20 transactions starting from given number or entry.
std::optional< LedgerInfo > getLedgerInfoByIndex(LedgerIndex ledgerSeq) override
getLedgerInfoByIndex Returns ledger by its sequence.
std::uint32_t seqToShardIndex(LedgerIndex ledgerSeq)
seqToShardIndex Converts ledgers sequence to shard index.
T emplace_back(T... args)
std::variant< RelationalDBInterface::AccountTx, TxSearched > getTransaction(soci::session &session, Application &app, uint256 const &id, std::optional< ClosedInterval< uint32_t >> const &range, error_code_i &ec)
getTransaction Returns transaction with given hash.
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
std::size_t getRows(soci::session &session, TableType type)
getRows Returns number of rows in given table.
virtual beast::Journal journal(std::string const &name)=0
std::vector< txnMetaLedgerType > MetaTxsList
std::optional< LedgerHashPair > getHashesByIndex(soci::session &session, LedgerIndex ledgerIndex, beast::Journal j)
getHashesByIndex Returns hash of the ledger and hash of parent ledger for the ledger of given sequenc...
std::uint32_t seqToShardIndex(std::uint32_t ledgerSeq) const noexcept
Calculates the shard index for a given ledger sequence.
std::optional< LedgerHashPair > getHashesByIndex(LedgerIndex ledgerIndex) override
getHashesByIndex Returns hash of the ledger and hash of parent ledger for the ledger of given sequenc...
AccountTxs getNewestAccountTxs(AccountTxOptions const &options) override
getNewestAccountTxs Returns newest transactions for given account which match given criteria starting...
void convertBlobsToTxResult(RelationalDBInterface::AccountTxs &to, std::uint32_t ledger_index, std::string const &status, Blob const &rawTxn, Blob const &rawMeta, Application &app)
void closeTransactionDB() override
Closes the transaction database.
DatabasePair makeMetaDBs(Config const &config, DatabaseCon::Setup const &setup, DatabaseCon::CheckpointerSetup const &checkpointerSetup)
makeMetaDBs Opens ledger and transaction 'meta' databases which map ledger hashes and transaction IDs...
bool doTransaction(LedgerIndex ledgerSeq, std::function< bool(soci::session &session)> const &callback)
doTransaction Checks out transaction database for shard containing given ledger and calls given callb...
DatabasePairValid makeLedgerDBs(Config const &config, DatabaseCon::Setup const &setup, DatabaseCon::CheckpointerSetup const &checkpointerSetup)
makeLedgerDBs Opens ledger and transactions databases.
std::pair< AccountTxs, std::optional< AccountTxMarker > > newestAccountTxPage(AccountTxPageOptions const &options) override
newestAccountTxPage Returns newest transactions for given account which match given criteria starting...
bool ledgerDbHasSpace(Config const &config) override
ledgerDbHasSpace Checks if ledger database has available space.
std::pair< std::optional< RelationalDBInterface::AccountTxMarker >, int > oldestAccountTxPage(soci::session &session, AccountIDCache const &idCache, std::function< void(std::uint32_t)> const &onUnsavedLedger, std::function< void(std::uint32_t, std::string const &, Blob &&, Blob &&)> const &onTransaction, RelationalDBInterface::AccountTxPageOptions const &options, int limit_used, std::uint32_t page_length)
oldestAccountTxPage Searches oldest transactions for given account which match given criteria startin...
std::size_t getAccountTransactionCount() override
getAccountTransactionCount Returns number of account transactions.
bool saveLedgerMeta(std::shared_ptr< Ledger const > const &ledger, Application &app, soci::session &lgrMetaSession, soci::session &txnMetaSession, std::uint32_t const shardIndex)
saveLedgerMeta Stores (transaction ID -> shard index) and (ledger hash -> shard index) mappings in th...
std::optional< LedgerIndex > getMaxLedgerSeq() override
getMaxLedgerSeq Returns maximum ledger sequence in Ledgers table.
bool iterateLedgerForward(std::optional< std::uint32_t > firstIndex, std::function< bool(soci::session &session, std::uint32_t shardIndex)> const &callback)
iterateLedgerForward Checks out ledger databases for all shards in ascending order starting from give...
boost::icl::closed_interval< T > ClosedInterval
A closed interval over the domain T.
bool dbHasSpace(soci::session &session, Config const &config, beast::Journal j)
dbHasSpace Checks if given database has available space.
std::optional< LedgerIndex > getMinLedgerSeq(soci::session &session, TableType type)
getMinLedgerSeq Returns minimum ledger sequence in given table.
AccountTxs getOldestAccountTxs(AccountTxOptions const &options) override
getOldestAccountTxs Returns oldest transactions for given account which match given criteria starting...
std::optional< std::uint32_t > getShardIndexforTransaction(soci::session &session, TxID const &id)
getShardIndexforTransaction Queries the transaction meta database to retrieve the index of the shard ...
bool saveValidatedLedger(std::shared_ptr< Ledger const > const &ledger, bool current) override
saveValidatedLedger Saves ledger into database.
std::optional< LedgerInfo > getNewestLedgerInfo(soci::session &session, beast::Journal j)
getNewestLedgerInfo Returns info of newest saved ledger.
std::optional< LedgerIndex > getTransactionsMinLedgerSeq() override
getTransactionsMinLedgerSeq Returns minimum ledger sequence among records in the Transactions table.
std::optional< LedgerIndex > getMaxLedgerSeq(soci::session &session, TableType type)
getMaxLedgerSeq Returns maximum ledger sequence in given table.
RelationalDBInterfaceSqliteImp(Application &app, Config const &config, JobQueue &jobQueue)
std::vector< AccountTx > AccountTxs
std::uint32_t getKBUsedLedger() override
getKBUsedLedger Returns space used by ledger database.
std::optional< std::uint32_t > getShardIndexforLedger(soci::session &session, LedgerHash const &hash)
getShardIndexforLedger Queries the ledger meta database to retrieve the index of the shard that conta...
std::variant< AccountTx, TxSearched > getTransaction(uint256 const &id, std::optional< ClosedInterval< std::uint32_t >> const &range, error_code_i &ec) override