rippled
RelationalDBInterfaceSqlite.cpp
1 //------------------------------------------------------------------------------
2 /*
3  This file is part of rippled: https://github.com/ripple/rippled
4  Copyright (c) 2020 Ripple Labs Inc.
5 
6  Permission to use, copy, modify, and/or distribute this software for any
7  purpose with or without fee is hereby granted, provided that the above
8  copyright notice and this permission notice appear in all copies.
9 
10  THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11  WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12  MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13  ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14  WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15  ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16  OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 */
18 //==============================================================================
19 
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>
39 
40 namespace ripple {
41 
43 {
44 public:
46  Application& app,
47  Config const& config,
48  JobQueue& jobQueue)
49  : app_(app)
50  , useTxTables_(config.useTxTables())
51  , j_(app_.journal("Ledger"))
52  {
53  DatabaseCon::Setup setup = setup_DatabaseCon(config, j_);
54  if (!makeLedgerDBs(
55  config,
56  setup,
58  {
59  JLOG(app_.journal("RelationalDBInterfaceSqlite").fatal())
60  << "AccountTransactions database should not have a primary key";
61  Throw<std::runtime_error>(
62  "AccountTransactions database initialization failed.");
63  }
64 
65  if (app.getShardStore() &&
66  !makeMetaDBs(
67  config,
68  setup,
70  {
71  JLOG(app_.journal("RelationalDBInterfaceSqlite").fatal())
72  << "Error during meta DB init";
73  Throw<std::runtime_error>(
74  "Shard meta database initialization failed.");
75  }
76  }
77 
79  getMinLedgerSeq() override;
80 
82  getTransactionsMinLedgerSeq() override;
83 
86 
88  getMaxLedgerSeq() override;
89 
90  void
91  deleteTransactionByLedgerSeq(LedgerIndex ledgerSeq) override;
92 
93  void
94  deleteBeforeLedgerSeq(LedgerIndex ledgerSeq) override;
95 
96  void
98 
99  void
101 
103  getTransactionCount() override;
104 
106  getAccountTransactionCount() override;
107 
109  getLedgerCountMinMax() override;
110 
111  bool
113  std::shared_ptr<Ledger const> const& ledger,
114  bool current) override;
115 
117  getLedgerInfoByIndex(LedgerIndex ledgerSeq) override;
118 
120  getNewestLedgerInfo() override;
121 
123  getLimitedOldestLedgerInfo(LedgerIndex ledgerFirstIndex) override;
124 
126  getLimitedNewestLedgerInfo(LedgerIndex ledgerFirstIndex) override;
127 
129  getLedgerInfoByHash(uint256 const& ledgerHash) override;
130 
131  uint256
132  getHashByIndex(LedgerIndex ledgerIndex) override;
133 
135  getHashesByIndex(LedgerIndex ledgerIndex) override;
136 
138  getHashesByIndex(LedgerIndex minSeq, LedgerIndex maxSeq) override;
139 
141  getTxHistory(LedgerIndex startIndex) override;
142 
143  AccountTxs
144  getOldestAccountTxs(AccountTxOptions const& options) override;
145 
146  AccountTxs
147  getNewestAccountTxs(AccountTxOptions const& options) override;
148 
150  getOldestAccountTxsB(AccountTxOptions const& options) override;
151 
153  getNewestAccountTxsB(AccountTxOptions const& options) override;
154 
156  oldestAccountTxPage(AccountTxPageOptions const& options) override;
157 
159  newestAccountTxPage(AccountTxPageOptions const& options) override;
160 
162  oldestAccountTxPageB(AccountTxPageOptions const& options) override;
163 
165  newestAccountTxPageB(AccountTxPageOptions const& options) override;
166 
169  uint256 const& id,
171  error_code_i& ec) override;
172 
173  bool
174  ledgerDbHasSpace(Config const& config) override;
175 
176  bool
177  transactionDbHasSpace(Config const& config) override;
178 
180  getKBUsedAll() override;
181 
183  getKBUsedLedger() override;
184 
186  getKBUsedTransaction() override;
187 
188  void
189  closeLedgerDB() override;
190 
191  void
192  closeTransactionDB() override;
193 
194 private:
196  bool const useTxTables_;
200 
209  bool
211  Config const& config,
212  DatabaseCon::Setup const& setup,
213  DatabaseCon::CheckpointerSetup const& checkpointerSetup);
214 
223  bool
224  makeMetaDBs(
225  Config const& config,
226  DatabaseCon::Setup const& setup,
227  DatabaseCon::CheckpointerSetup const& checkpointerSetup);
228 
236  {
237  return app_.getShardStore()->seqToShardIndex(ledgerSeq);
238  }
239 
247  {
248  return app_.getShardStore()->firstLedgerSeq(shardIndex);
249  }
250 
258  {
259  return app_.getShardStore()->lastLedgerSeq(shardIndex);
260  }
261 
266  bool
268  {
269  return static_cast<bool>(lgrdb_);
270  }
271 
276  bool
278  {
279  return static_cast<bool>(txdb_);
280  }
281 
286  bool
288  {
289  return app_.getShardStore() != nullptr;
290  }
291 
296  auto
298  {
299  return lgrdb_->checkoutDb();
300  }
301 
306  auto
308  {
309  return txdb_->checkoutDb();
310  }
311 
320  bool
322  LedgerIndex ledgerSeq,
323  std::function<bool(soci::session& session)> const& callback)
324  {
326  ledgerSeq, callback);
327  }
328 
337  bool
339  LedgerIndex ledgerSeq,
340  std::function<bool(soci::session& session)> const& callback)
341  {
343  ledgerSeq, callback);
344  }
345 
357  bool
359  std::optional<std::uint32_t> firstIndex,
361  bool(soci::session& session, std::uint32_t shardIndex)> const&
362  callback)
363  {
365  firstIndex, callback);
366  }
367 
379  bool
381  std::optional<std::uint32_t> firstIndex,
383  bool(soci::session& session, std::uint32_t shardIndex)> const&
384  callback)
385  {
387  firstIndex, callback);
388  }
389 
401  bool
403  std::optional<std::uint32_t> firstIndex,
405  bool(soci::session& session, std::uint32_t shardIndex)> const&
406  callback)
407  {
409  firstIndex, callback);
410  }
411 
423  bool
425  std::optional<std::uint32_t> firstIndex,
427  bool(soci::session& session, std::uint32_t shardIndex)> const&
428  callback)
429  {
431  firstIndex, callback);
432  }
433 };
434 
435 bool
437  Config const& config,
438  DatabaseCon::Setup const& setup,
439  DatabaseCon::CheckpointerSetup const& checkpointerSetup)
440 {
441  auto [lgr, tx, res] =
442  ripple::makeLedgerDBs(config, setup, checkpointerSetup);
443  txdb_ = std::move(tx);
444  lgrdb_ = std::move(lgr);
445  return res;
446 }
447 
448 bool
450  Config const& config,
451  DatabaseCon::Setup const& setup,
452  DatabaseCon::CheckpointerSetup const& checkpointerSetup)
453 {
454  auto [lgrMetaDB, txMetaDB] =
455  ripple::makeMetaDBs(config, setup, checkpointerSetup);
456 
457  txMetaDB_ = std::move(txMetaDB);
458  lgrMetaDB_ = std::move(lgrMetaDB);
459 
460  return true;
461 }
462 
465 {
466  /* if databases exists, use it */
467  if (existsLedger())
468  {
469  auto db = checkoutLedger();
471  }
472 
473  /* else use shard databases, if available */
474  if (shardStoreExists())
475  {
478  {}, [&](soci::session& session, std::uint32_t shardIndex) {
480  return !res;
481  });
482  return res;
483  }
484 
485  /* else return empty value */
486  return {};
487 }
488 
491 {
492  if (!useTxTables_)
493  return {};
494 
495  if (existsTransaction())
496  {
497  auto db = checkoutTransaction();
499  }
500 
501  if (shardStoreExists())
502  {
505  {}, [&](soci::session& session, std::uint32_t shardIndex) {
507  return !res;
508  });
509  return res;
510  }
511 
512  return {};
513 }
514 
517 {
518  if (!useTxTables_)
519  return {};
520 
521  if (existsTransaction())
522  {
523  auto db = checkoutTransaction();
525  }
526 
527  if (shardStoreExists())
528  {
531  {}, [&](soci::session& session, std::uint32_t shardIndex) {
534  return !res;
535  });
536  return res;
537  }
538 
539  return {};
540 }
541 
544 {
545  if (existsLedger())
546  {
547  auto db = checkoutLedger();
549  }
550 
551  if (shardStoreExists())
552  {
555  {}, [&](soci::session& session, std::uint32_t shardIndex) {
557  return !res;
558  });
559  return res;
560  }
561 
562  return {};
563 }
564 
565 void
567  LedgerIndex ledgerSeq)
568 {
569  if (!useTxTables_)
570  return;
571 
572  if (existsTransaction())
573  {
574  auto db = checkoutTransaction();
576  return;
577  }
578 
579  if (shardStoreExists())
580  {
581  doTransaction(ledgerSeq, [&](soci::session& session) {
583  session, TableType::Transactions, ledgerSeq);
584  return true;
585  });
586  }
587 }
588 
589 void
591 {
592  if (existsLedger())
593  {
594  auto db = checkoutLedger();
596  return;
597  }
598 
599  if (shardStoreExists())
600  {
602  seqToShardIndex(ledgerSeq),
603  [&](soci::session& session, std::uint32_t shardIndex) {
605  session, TableType::Ledgers, ledgerSeq);
606  return true;
607  });
608  }
609 }
610 
611 void
613  LedgerIndex ledgerSeq)
614 {
615  if (!useTxTables_)
616  return;
617 
618  if (existsTransaction())
619  {
620  auto db = checkoutTransaction();
622  return;
623  }
624 
625  if (shardStoreExists())
626  {
628  seqToShardIndex(ledgerSeq),
629  [&](soci::session& session, std::uint32_t shardIndex) {
631  session, TableType::Transactions, ledgerSeq);
632  return true;
633  });
634  }
635 }
636 
637 void
639  LedgerIndex ledgerSeq)
640 {
641  if (!useTxTables_)
642  return;
643 
644  if (existsTransaction())
645  {
646  auto db = checkoutTransaction();
648  *db, TableType::AccountTransactions, ledgerSeq);
649  return;
650  }
651 
652  if (shardStoreExists())
653  {
655  seqToShardIndex(ledgerSeq),
656  [&](soci::session& session, std::uint32_t shardIndex) {
658  session, TableType::AccountTransactions, ledgerSeq);
659  return true;
660  });
661  }
662 }
663 
666 {
667  if (!useTxTables_)
668  return 0;
669 
670  if (existsTransaction())
671  {
672  auto db = checkoutTransaction();
674  }
675 
676  if (shardStoreExists())
677  {
678  std::size_t rows = 0;
680  {}, [&](soci::session& session, std::uint32_t shardIndex) {
681  rows += ripple::getRows(session, TableType::Transactions);
682  return true;
683  });
684  return rows;
685  }
686 
687  return 0;
688 }
689 
692 {
693  if (!useTxTables_)
694  return 0;
695 
696  if (existsTransaction())
697  {
698  auto db = checkoutTransaction();
700  }
701 
702  if (shardStoreExists())
703  {
704  std::size_t rows = 0;
706  {}, [&](soci::session& session, std::uint32_t shardIndex) {
707  rows +=
709  return true;
710  });
711  return rows;
712  }
713 
714  return 0;
715 }
716 
719 {
720  if (existsLedger())
721  {
722  auto db = checkoutLedger();
724  }
725 
726  if (shardStoreExists())
727  {
728  CountMinMax res{0, 0, 0};
730  {}, [&](soci::session& session, std::uint32_t shardIndex) {
731  auto r = ripple::getRowsMinMax(session, TableType::Ledgers);
732  if (r.numberOfRows)
733  {
734  res.numberOfRows += r.numberOfRows;
735  if (res.minLedgerSequence == 0)
736  res.minLedgerSequence = r.minLedgerSequence;
737  res.maxLedgerSequence = r.maxLedgerSequence;
738  }
739  return true;
740  });
741  return res;
742  }
743 
744  return {0, 0, 0};
745 }
746 
747 bool
749  std::shared_ptr<Ledger const> const& ledger,
750  bool current)
751 {
752  if (existsLedger())
753  {
755  *lgrdb_, *txdb_, app_, ledger, current))
756  return false;
757  }
758 
759  if (auto shardStore = app_.getShardStore(); shardStore)
760  {
761  if (ledger->info().seq < shardStore->earliestLedgerSeq())
762  // For the moment return false only when the ShardStore
763  // should accept the ledger, but fails when attempting
764  // to do so, i.e. when saveLedgerMeta fails. Later when
765  // the ShardStore supercedes the NodeStore, change this
766  // line to return false if the ledger is too early.
767  return true;
768 
769  auto lgrMetaSession = lgrMetaDB_->checkoutDb();
770  auto txMetaSession = txMetaDB_->checkoutDb();
771 
772  return ripple::saveLedgerMeta(
773  ledger,
774  app_,
775  *lgrMetaSession,
776  *txMetaSession,
777  shardStore->seqToShardIndex(ledger->info().seq));
778  }
779 
780  return true;
781 }
782 
785 {
786  if (existsLedger())
787  {
788  auto db = checkoutLedger();
789  return ripple::getLedgerInfoByIndex(*db, ledgerSeq, j_);
790  }
791 
792  if (shardStoreExists())
793  {
795  doLedger(ledgerSeq, [&](soci::session& session) {
796  res = ripple::getLedgerInfoByIndex(session, ledgerSeq, j_);
797  return true;
798  });
799  return res;
800  }
801 
802  return {};
803 }
804 
807 {
808  if (existsLedger())
809  {
810  auto db = checkoutLedger();
811  return ripple::getNewestLedgerInfo(*db, j_);
812  }
813 
814  if (shardStoreExists())
815  {
818  {}, [&](soci::session& session, std::uint32_t shardIndex) {
819  if (auto info = ripple::getNewestLedgerInfo(session, j_))
820  {
821  res = info;
822  return false;
823  }
824  return true;
825  });
826 
827  return res;
828  }
829 
830  return {};
831 }
832 
835  LedgerIndex ledgerFirstIndex)
836 {
837  if (existsLedger())
838  {
839  auto db = checkoutLedger();
840  return ripple::getLimitedOldestLedgerInfo(*db, ledgerFirstIndex, j_);
841  }
842 
843  if (shardStoreExists())
844  {
847  seqToShardIndex(ledgerFirstIndex),
848  [&](soci::session& session, std::uint32_t shardIndex) {
849  if (auto info = ripple::getLimitedOldestLedgerInfo(
850  session, ledgerFirstIndex, j_))
851  {
852  res = info;
853  return false;
854  }
855  return true;
856  });
857 
858  return res;
859  }
860 
861  return {};
862 }
863 
866  LedgerIndex ledgerFirstIndex)
867 {
868  if (existsLedger())
869  {
870  auto db = checkoutLedger();
871  return ripple::getLimitedNewestLedgerInfo(*db, ledgerFirstIndex, j_);
872  }
873 
874  if (shardStoreExists())
875  {
878  {}, [&](soci::session& session, std::uint32_t shardIndex) {
879  if (auto info = ripple::getLimitedNewestLedgerInfo(
880  session, ledgerFirstIndex, j_))
881  {
882  res = info;
883  return false;
884  }
885  return shardIndex >= seqToShardIndex(ledgerFirstIndex);
886  });
887 
888  return res;
889  }
890 
891  return {};
892 }
893 
896 {
897  if (existsLedger())
898  {
899  auto db = checkoutLedger();
900  return ripple::getLedgerInfoByHash(*db, ledgerHash, j_);
901  }
902 
903  if (auto shardStore = app_.getShardStore())
904  {
906  auto lgrMetaSession = lgrMetaDB_->checkoutDb();
907 
908  if (auto const shardIndex =
909  ripple::getShardIndexforLedger(*lgrMetaSession, ledgerHash))
910  {
911  shardStore->callForLedgerSQLByShardIndex(
912  *shardIndex, [&](soci::session& session) {
913  res = ripple::getLedgerInfoByHash(session, ledgerHash, j_);
914  return false; // unused
915  });
916  }
917 
918  return res;
919  }
920 
921  return {};
922 }
923 
924 uint256
926 {
927  if (existsLedger())
928  {
929  auto db = checkoutLedger();
930  return ripple::getHashByIndex(*db, ledgerIndex);
931  }
932 
933  if (shardStoreExists())
934  {
935  uint256 hash;
936  doLedger(ledgerIndex, [&](soci::session& session) {
937  hash = ripple::getHashByIndex(session, ledgerIndex);
938  return true;
939  });
940  return hash;
941  }
942 
943  return uint256();
944 }
945 
948 {
949  if (existsLedger())
950  {
951  auto db = checkoutLedger();
952  return ripple::getHashesByIndex(*db, ledgerIndex, j_);
953  }
954 
955  if (shardStoreExists())
956  {
958  doLedger(ledgerIndex, [&](soci::session& session) {
959  res = ripple::getHashesByIndex(session, ledgerIndex, j_);
960  return true;
961  });
962  return res;
963  }
964 
965  return {};
966 }
967 
970  LedgerIndex minSeq,
971  LedgerIndex maxSeq)
972 {
973  if (existsLedger())
974  {
975  auto db = checkoutLedger();
976  return ripple::getHashesByIndex(*db, minSeq, maxSeq, j_);
977  }
978 
979  if (shardStoreExists())
980  {
982  while (minSeq <= maxSeq)
983  {
984  LedgerIndex shardMaxSeq = lastLedgerSeq(seqToShardIndex(minSeq));
985  if (shardMaxSeq > maxSeq)
986  shardMaxSeq = maxSeq;
987  doLedger(minSeq, [&](soci::session& session) {
988  auto r =
989  ripple::getHashesByIndex(session, minSeq, shardMaxSeq, j_);
990  res.insert(r.begin(), r.end());
991  return true;
992  });
993  minSeq = shardMaxSeq + 1;
994  }
995 
996  return res;
997  }
998 
999  return {};
1000 }
1001 
1004 {
1005  if (!useTxTables_)
1006  return {};
1007 
1008  if (existsTransaction())
1009  {
1010  auto db = checkoutTransaction();
1011  return ripple::getTxHistory(*db, app_, startIndex, 20, false).first;
1012  }
1013 
1014  if (shardStoreExists())
1015  {
1017  int quantity = 20;
1019  {}, [&](soci::session& session, std::uint32_t shardIndex) {
1020  auto [tx, total] = ripple::getTxHistory(
1021  session, app_, startIndex, quantity, true);
1022  txs.insert(txs.end(), tx.begin(), tx.end());
1023  if (total > 0)
1024  {
1025  quantity -= total;
1026  if (quantity <= 0)
1027  return false;
1028  startIndex = 0;
1029  }
1030  else
1031  {
1032  startIndex += total;
1033  }
1034  return true;
1035  });
1036 
1037  return txs;
1038  }
1039 
1040  return {};
1041 }
1042 
1045  AccountTxOptions const& options)
1046 {
1047  if (!useTxTables_)
1048  return {};
1049 
1051 
1052  if (existsTransaction())
1053  {
1054  auto db = checkoutTransaction();
1056  *db, app_, ledgerMaster, options, {}, j_)
1057  .first;
1058  }
1059 
1060  if (shardStoreExists())
1061  {
1062  AccountTxs ret;
1063  AccountTxOptions opt = options;
1064  int limit_used = 0;
1068  [&](soci::session& session, std::uint32_t shardIndex) {
1069  if (opt.maxLedger &&
1070  shardIndex > seqToShardIndex(opt.maxLedger))
1071  return false;
1072  auto [r, total] = ripple::getOldestAccountTxs(
1073  session, app_, ledgerMaster, opt, limit_used, j_);
1074  ret.insert(ret.end(), r.begin(), r.end());
1075  if (!total)
1076  return false;
1077  if (total > 0)
1078  {
1079  limit_used += total;
1080  opt.offset = 0;
1081  }
1082  else
1083  {
1084  /*
1085  * If total < 0, then -total means number of transactions
1086  * skipped, see definition of return value of function
1087  * ripple::getOldestAccountTxs().
1088  */
1089  total = -total;
1090  if (opt.offset <= total)
1091  opt.offset = 0;
1092  else
1093  opt.offset -= total;
1094  }
1095  return true;
1096  });
1097 
1098  return ret;
1099  }
1100 
1101  return {};
1102 }
1103 
1104 RelationalDBInterface::AccountTxs
1105 RelationalDBInterfaceSqliteImp::getNewestAccountTxs(
1106  AccountTxOptions const& options)
1107 {
1108  if (!useTxTables_)
1109  return {};
1110 
1112 
1113  if (existsTransaction())
1114  {
1115  auto db = checkoutTransaction();
1117  *db, app_, ledgerMaster, options, {}, j_)
1118  .first;
1119  }
1120 
1121  if (shardStoreExists())
1122  {
1123  AccountTxs ret;
1124  AccountTxOptions opt = options;
1125  int limit_used = 0;
1126  iterateTransactionBack(
1127  opt.maxLedger ? seqToShardIndex(opt.maxLedger)
1129  [&](soci::session& session, std::uint32_t shardIndex) {
1130  if (opt.minLedger &&
1131  shardIndex < seqToShardIndex(opt.minLedger))
1132  return false;
1133  auto [r, total] = ripple::getNewestAccountTxs(
1134  session, app_, ledgerMaster, opt, limit_used, j_);
1135  ret.insert(ret.end(), r.begin(), r.end());
1136  if (!total)
1137  return false;
1138  if (total > 0)
1139  {
1140  limit_used += total;
1141  opt.offset = 0;
1142  }
1143  else
1144  {
1145  /*
1146  * If total < 0, then -total means number of transactions
1147  * skipped, see definition of return value of function
1148  * ripple::getNewestAccountTxs().
1149  */
1150  total = -total;
1151  if (opt.offset <= total)
1152  opt.offset = 0;
1153  else
1154  opt.offset -= total;
1155  }
1156  return true;
1157  });
1158 
1159  return ret;
1160  }
1161 
1162  return {};
1163 }
1164 
1165 RelationalDBInterface::MetaTxsList
1166 RelationalDBInterfaceSqliteImp::getOldestAccountTxsB(
1167  AccountTxOptions const& options)
1168 {
1169  if (!useTxTables_)
1170  return {};
1171 
1172  if (existsTransaction())
1173  {
1174  auto db = checkoutTransaction();
1175  return ripple::getOldestAccountTxsB(*db, app_, options, {}, j_).first;
1176  }
1177 
1178  if (shardStoreExists())
1179  {
1180  MetaTxsList ret;
1181  AccountTxOptions opt = options;
1182  int limit_used = 0;
1183  iterateTransactionForward(
1184  opt.minLedger ? seqToShardIndex(opt.minLedger)
1186  [&](soci::session& session, std::uint32_t shardIndex) {
1187  if (opt.maxLedger &&
1188  shardIndex > seqToShardIndex(opt.maxLedger))
1189  return false;
1190  auto [r, total] = ripple::getOldestAccountTxsB(
1191  session, app_, opt, limit_used, j_);
1192  ret.insert(ret.end(), r.begin(), r.end());
1193  if (!total)
1194  return false;
1195  if (total > 0)
1196  {
1197  limit_used += total;
1198  opt.offset = 0;
1199  }
1200  else
1201  {
1202  /*
1203  * If total < 0, then -total means number of transactions
1204  * skipped, see definition of return value of function
1205  * ripple::getOldestAccountTxsB().
1206  */
1207  total = -total;
1208  if (opt.offset <= total)
1209  opt.offset = 0;
1210  else
1211  opt.offset -= total;
1212  }
1213  return true;
1214  });
1215 
1216  return ret;
1217  }
1218 
1219  return {};
1220 }
1221 
1222 RelationalDBInterface::MetaTxsList
1223 RelationalDBInterfaceSqliteImp::getNewestAccountTxsB(
1224  AccountTxOptions const& options)
1225 {
1226  if (!useTxTables_)
1227  return {};
1228 
1229  if (existsTransaction())
1230  {
1231  auto db = checkoutTransaction();
1232  return ripple::getNewestAccountTxsB(*db, app_, options, {}, j_).first;
1233  }
1234 
1235  if (shardStoreExists())
1236  {
1237  MetaTxsList ret;
1238  AccountTxOptions opt = options;
1239  int limit_used = 0;
1240  iterateTransactionBack(
1241  opt.maxLedger ? seqToShardIndex(opt.maxLedger)
1243  [&](soci::session& session, std::uint32_t shardIndex) {
1244  if (opt.minLedger &&
1245  shardIndex < seqToShardIndex(opt.minLedger))
1246  return false;
1247  auto [r, total] = ripple::getNewestAccountTxsB(
1248  session, app_, opt, limit_used, j_);
1249  ret.insert(ret.end(), r.begin(), r.end());
1250  if (!total)
1251  return false;
1252  if (total > 0)
1253  {
1254  limit_used += total;
1255  opt.offset = 0;
1256  }
1257  else
1258  {
1259  /*
1260  * If total < 0, then -total means number of transactions
1261  * skipped, see definition of return value of function
1262  * ripple::getNewestAccountTxsB().
1263  */
1264  total = -total;
1265  if (opt.offset <= total)
1266  opt.offset = 0;
1267  else
1268  opt.offset -= total;
1269  }
1270  return true;
1271  });
1272 
1273  return ret;
1274  }
1275 
1276  return {};
1277 }
1278 
1279 std::pair<
1280  RelationalDBInterface::AccountTxs,
1282 RelationalDBInterfaceSqliteImp::oldestAccountTxPage(
1283  AccountTxPageOptions const& options)
1284 {
1285  if (!useTxTables_)
1286  return {};
1287 
1288  static std::uint32_t const page_length(200);
1289  auto& idCache = app_.accountIDCache();
1290  auto onUnsavedLedger =
1291  std::bind(saveLedgerAsync, std::ref(app_), std::placeholders::_1);
1292  AccountTxs ret;
1293  Application& app = app_;
1294  auto onTransaction = [&ret, &app](
1295  std::uint32_t ledger_index,
1296  std::string const& status,
1297  Blob&& rawTxn,
1298  Blob&& rawMeta) {
1299  convertBlobsToTxResult(ret, ledger_index, status, rawTxn, rawMeta, app);
1300  };
1301 
1302  if (existsTransaction())
1303  {
1304  auto db = checkoutTransaction();
1305  auto newmarker = ripple::oldestAccountTxPage(
1306  *db,
1307  idCache,
1308  onUnsavedLedger,
1309  onTransaction,
1310  options,
1311  0,
1312  page_length)
1313  .first;
1314  return {ret, newmarker};
1315  }
1316 
1317  if (shardStoreExists())
1318  {
1319  AccountTxPageOptions opt = options;
1320  int limit_used = 0;
1321  iterateTransactionForward(
1322  opt.minLedger ? seqToShardIndex(opt.minLedger)
1324  [&](soci::session& session, std::uint32_t shardIndex) {
1325  if (opt.maxLedger != UINT32_MAX &&
1326  shardIndex > seqToShardIndex(opt.minLedger))
1327  return false;
1328  auto [marker, total] = ripple::oldestAccountTxPage(
1329  session,
1330  idCache,
1331  onUnsavedLedger,
1332  onTransaction,
1333  opt,
1334  limit_used,
1335  page_length);
1336  opt.marker = marker;
1337  if (total < 0)
1338  return false;
1339  limit_used += total;
1340  return true;
1341  });
1342 
1343  return {ret, opt.marker};
1344  }
1345 
1346  return {};
1347 }
1348 
1349 std::pair<
1352 RelationalDBInterfaceSqliteImp::newestAccountTxPage(
1353  AccountTxPageOptions const& options)
1354 {
1355  if (!useTxTables_)
1356  return {};
1357 
1358  static std::uint32_t const page_length(200);
1359  auto& idCache = app_.accountIDCache();
1360  auto onUnsavedLedger =
1361  std::bind(saveLedgerAsync, std::ref(app_), std::placeholders::_1);
1362  AccountTxs ret;
1363  Application& app = app_;
1364  auto onTransaction = [&ret, &app](
1365  std::uint32_t ledger_index,
1366  std::string const& status,
1367  Blob&& rawTxn,
1368  Blob&& rawMeta) {
1369  convertBlobsToTxResult(ret, ledger_index, status, rawTxn, rawMeta, app);
1370  };
1371 
1372  if (existsTransaction())
1373  {
1374  auto db = checkoutTransaction();
1375  auto newmarker = ripple::newestAccountTxPage(
1376  *db,
1377  idCache,
1378  onUnsavedLedger,
1379  onTransaction,
1380  options,
1381  0,
1382  page_length)
1383  .first;
1384  return {ret, newmarker};
1385  }
1386 
1387  if (shardStoreExists())
1388  {
1389  AccountTxPageOptions opt = options;
1390  int limit_used = 0;
1391  iterateTransactionBack(
1392  opt.maxLedger != UINT32_MAX ? seqToShardIndex(opt.maxLedger)
1394  [&](soci::session& session, std::uint32_t shardIndex) {
1395  if (opt.minLedger &&
1396  shardIndex < seqToShardIndex(opt.minLedger))
1397  return false;
1398  auto [marker, total] = ripple::newestAccountTxPage(
1399  session,
1400  idCache,
1401  onUnsavedLedger,
1402  onTransaction,
1403  opt,
1404  limit_used,
1405  page_length);
1406  opt.marker = marker;
1407  if (total < 0)
1408  return false;
1409  limit_used += total;
1410  return true;
1411  });
1412 
1413  return {ret, opt.marker};
1414  }
1415 
1416  return {};
1417 }
1418 
1419 std::pair<
1422 RelationalDBInterfaceSqliteImp::oldestAccountTxPageB(
1423  AccountTxPageOptions const& options)
1424 {
1425  if (!useTxTables_)
1426  return {};
1427 
1428  static std::uint32_t const page_length(500);
1429  auto& idCache = app_.accountIDCache();
1430  auto onUnsavedLedger =
1431  std::bind(saveLedgerAsync, std::ref(app_), std::placeholders::_1);
1432  MetaTxsList ret;
1433  auto onTransaction = [&ret](
1434  std::uint32_t ledgerIndex,
1435  std::string const& status,
1436  Blob&& rawTxn,
1437  Blob&& rawMeta) {
1438  ret.emplace_back(std::move(rawTxn), std::move(rawMeta), ledgerIndex);
1439  };
1440 
1441  if (existsTransaction())
1442  {
1443  auto db = checkoutTransaction();
1444  auto newmarker = ripple::oldestAccountTxPage(
1445  *db,
1446  idCache,
1447  onUnsavedLedger,
1448  onTransaction,
1449  options,
1450  0,
1451  page_length)
1452  .first;
1453  return {ret, newmarker};
1454  }
1455 
1456  if (shardStoreExists())
1457  {
1458  AccountTxPageOptions opt = options;
1459  int limit_used = 0;
1460  iterateTransactionForward(
1461  opt.minLedger ? seqToShardIndex(opt.minLedger)
1463  [&](soci::session& session, std::uint32_t shardIndex) {
1464  if (opt.maxLedger != UINT32_MAX &&
1465  shardIndex > seqToShardIndex(opt.minLedger))
1466  return false;
1467  auto [marker, total] = ripple::oldestAccountTxPage(
1468  session,
1469  idCache,
1470  onUnsavedLedger,
1471  onTransaction,
1472  opt,
1473  limit_used,
1474  page_length);
1475  opt.marker = marker;
1476  if (total < 0)
1477  return false;
1478  limit_used += total;
1479  return true;
1480  });
1481 
1482  return {ret, opt.marker};
1483  }
1484 
1485  return {};
1486 }
1487 
1488 std::pair<
1491 RelationalDBInterfaceSqliteImp::newestAccountTxPageB(
1492  AccountTxPageOptions const& options)
1493 {
1494  if (!useTxTables_)
1495  return {};
1496 
1497  static std::uint32_t const page_length(500);
1498  auto& idCache = app_.accountIDCache();
1499  auto onUnsavedLedger =
1500  std::bind(saveLedgerAsync, std::ref(app_), std::placeholders::_1);
1501  MetaTxsList ret;
1502  auto onTransaction = [&ret](
1503  std::uint32_t ledgerIndex,
1504  std::string const& status,
1505  Blob&& rawTxn,
1506  Blob&& rawMeta) {
1507  ret.emplace_back(std::move(rawTxn), std::move(rawMeta), ledgerIndex);
1508  };
1509 
1510  if (existsTransaction())
1511  {
1512  auto db = checkoutTransaction();
1513  auto newmarker = ripple::newestAccountTxPage(
1514  *db,
1515  idCache,
1516  onUnsavedLedger,
1517  onTransaction,
1518  options,
1519  0,
1520  page_length)
1521  .first;
1522  return {ret, newmarker};
1523  }
1524 
1525  if (shardStoreExists())
1526  {
1527  AccountTxPageOptions opt = options;
1528  int limit_used = 0;
1529  iterateTransactionBack(
1530  opt.maxLedger != UINT32_MAX ? seqToShardIndex(opt.maxLedger)
1532  [&](soci::session& session, std::uint32_t shardIndex) {
1533  if (opt.minLedger &&
1534  shardIndex < seqToShardIndex(opt.minLedger))
1535  return false;
1536  auto [marker, total] = ripple::newestAccountTxPage(
1537  session,
1538  idCache,
1539  onUnsavedLedger,
1540  onTransaction,
1541  opt,
1542  limit_used,
1543  page_length);
1544  opt.marker = marker;
1545  if (total < 0)
1546  return false;
1547  limit_used += total;
1548  return true;
1549  });
1550 
1551  return {ret, opt.marker};
1552  }
1553 
1554  return {};
1555 }
1556 
1558 RelationalDBInterfaceSqliteImp::getTransaction(
1559  uint256 const& id,
1561  error_code_i& ec)
1562 {
1563  if (!useTxTables_)
1564  return TxSearched::unknown;
1565 
1566  if (existsTransaction())
1567  {
1568  auto db = checkoutTransaction();
1569  return ripple::getTransaction(*db, app_, id, range, ec);
1570  }
1571 
1572  if (auto shardStore = app_.getShardStore(); shardStore)
1573  {
1574  std::variant<AccountTx, TxSearched> res(TxSearched::unknown);
1575  auto txMetaSession = txMetaDB_->checkoutDb();
1576 
1577  if (auto const shardIndex =
1578  ripple::getShardIndexforTransaction(*txMetaSession, id))
1579  {
1580  shardStore->callForTransactionSQLByShardIndex(
1581  *shardIndex, [&](soci::session& session) {
1583  if (range)
1584  {
1585  std::uint32_t const low = std::max(
1586  range->lower(), firstLedgerSeq(*shardIndex));
1587  std::uint32_t const high = std::min(
1588  range->upper(), lastLedgerSeq(*shardIndex));
1589  if (low <= high)
1590  range1 = ClosedInterval<std::uint32_t>(low, high);
1591  }
1592  res = ripple::getTransaction(session, app_, id, range1, ec);
1593 
1594  return res.index() == 1 &&
1595  std::get<TxSearched>(res) !=
1596  TxSearched::unknown; // unused
1597  });
1598  }
1599 
1600  return res;
1601  }
1602 
1603  return TxSearched::unknown;
1604 }
1605 
1606 bool
1607 RelationalDBInterfaceSqliteImp::ledgerDbHasSpace(Config const& config)
1608 {
1609  if (existsLedger())
1610  {
1611  auto db = checkoutLedger();
1612  return ripple::dbHasSpace(*db, config, j_);
1613  }
1614 
1615  if (shardStoreExists())
1616  {
1617  return iterateLedgerBack(
1618  {}, [&](soci::session& session, std::uint32_t shardIndex) {
1619  return ripple::dbHasSpace(session, config, j_);
1620  });
1621  }
1622 
1623  return true;
1624 }
1625 
1626 bool
1627 RelationalDBInterfaceSqliteImp::transactionDbHasSpace(Config const& config)
1628 {
1629  if (!useTxTables_)
1630  return true;
1631 
1632  if (existsTransaction())
1633  {
1634  auto db = checkoutTransaction();
1635  return ripple::dbHasSpace(*db, config, j_);
1636  }
1637 
1638  if (shardStoreExists())
1639  {
1640  return iterateTransactionBack(
1641  {}, [&](soci::session& session, std::uint32_t shardIndex) {
1642  return ripple::dbHasSpace(session, config, j_);
1643  });
1644  }
1645 
1646  return true;
1647 }
1648 
1650 RelationalDBInterfaceSqliteImp::getKBUsedAll()
1651 {
1652  if (existsLedger())
1653  {
1654  return ripple::getKBUsedAll(lgrdb_->getSession());
1655  }
1656 
1657  if (shardStoreExists())
1658  {
1659  std::uint32_t sum = 0;
1660  iterateLedgerBack(
1661  {}, [&](soci::session& session, std::uint32_t shardIndex) {
1662  sum += ripple::getKBUsedAll(session);
1663  return true;
1664  });
1665  return sum;
1666  }
1667 
1668  return 0;
1669 }
1670 
1672 RelationalDBInterfaceSqliteImp::getKBUsedLedger()
1673 {
1674  if (existsLedger())
1675  {
1676  return ripple::getKBUsedDB(lgrdb_->getSession());
1677  }
1678 
1679  if (shardStoreExists())
1680  {
1681  std::uint32_t sum = 0;
1682  iterateLedgerBack(
1683  {}, [&](soci::session& session, std::uint32_t shardIndex) {
1684  sum += ripple::getKBUsedDB(session);
1685  return true;
1686  });
1687  return sum;
1688  }
1689 
1690  return 0;
1691 }
1692 
1694 RelationalDBInterfaceSqliteImp::getKBUsedTransaction()
1695 {
1696  if (!useTxTables_)
1697  return 0;
1698 
1699  if (existsTransaction())
1700  {
1701  return ripple::getKBUsedDB(txdb_->getSession());
1702  }
1703 
1704  if (shardStoreExists())
1705  {
1706  std::uint32_t sum = 0;
1707  iterateTransactionBack(
1708  {}, [&](soci::session& session, std::uint32_t shardIndex) {
1709  sum += ripple::getKBUsedDB(session);
1710  return true;
1711  });
1712  return sum;
1713  }
1714 
1715  return 0;
1716 }
1717 
1718 void
1719 RelationalDBInterfaceSqliteImp::closeLedgerDB()
1720 {
1721  lgrdb_.reset();
1722 }
1723 
1724 void
1725 RelationalDBInterfaceSqliteImp::closeTransactionDB()
1726 {
1727  txdb_.reset();
1728 }
1729 
1732  Application& app,
1733  Config const& config,
1734  JobQueue& jobQueue)
1735 {
1736  return std::make_unique<RelationalDBInterfaceSqliteImp>(
1737  app, config, jobQueue);
1738 }
1739 
1740 } // namespace ripple
beast::Journal::fatal
Stream fatal() const
Definition: Journal.h:339
ripple::NodeStore::Database::lastLedgerSeq
std::uint32_t lastLedgerSeq(std::uint32_t shardIndex) const noexcept
Calculates the last ledger sequence for a given shard index.
Definition: Database.h:270
ripple::RelationalDBInterfaceSqliteImp::deleteTransactionByLedgerSeq
void deleteTransactionByLedgerSeq(LedgerIndex ledgerSeq) override
deleteTransactionByLedgerSeq Deletes transactions from ledger with given sequence.
Definition: RelationalDBInterfaceSqlite.cpp:566
ripple::getLedgerInfoByIndex
std::optional< LedgerInfo > getLedgerInfoByIndex(soci::session &session, LedgerIndex ledgerSeq, beast::Journal j)
getLedgerInfoByIndex Returns ledger by its sequence.
Definition: RelationalDBInterface_nodes.cpp:455
ripple::Application
Definition: Application.h:115
ripple::deleteBeforeLedgerSeq
void deleteBeforeLedgerSeq(soci::session &session, TableType type, LedgerIndex ledgerSeq)
deleteBeforeLedgerSeq Deletes all entries in given table for the ledgers with given sequence and all ...
Definition: RelationalDBInterface_nodes.cpp:148
ripple::HashPrefix::ledgerMaster
@ ledgerMaster
ledger master data for signing
ripple::NodeStore::DatabaseShard::callForLedgerSQLByLedgerSeq
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::bind
T bind(T... args)
std::string
STL class.
std::shared_ptr
STL class.
ripple::getTxHistory
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.
Definition: RelationalDBInterface_nodes.cpp:615
ripple::getHashByIndex
uint256 getHashByIndex(soci::session &session, LedgerIndex ledgerIndex)
getHashByIndex Returns hash of ledger with given sequence.
Definition: RelationalDBInterface_nodes.cpp:509
ripple::getRelationalDBInterfaceSqlite
std::unique_ptr< RelationalDBInterface > getRelationalDBInterfaceSqlite(Application &app, Config const &config, JobQueue &jobQueue)
Definition: RelationalDBInterfaceSqlite.cpp:1731
ripple::getOldestAccountTxs
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...
Definition: RelationalDBInterface_nodes.cpp:897
ripple::RelationalDBInterfaceSqliteImp::newestAccountTxPageB
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...
Definition: RelationalDBInterfaceSqlite.cpp:1491
ripple::RelationalDBInterfaceSqliteImp::txMetaDB_
std::unique_ptr< DatabaseCon > txMetaDB_
Definition: RelationalDBInterfaceSqlite.cpp:199
ripple::DatabaseCon::Setup
Definition: DatabaseCon.h:84
ripple::getOldestAccountTxsB
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...
Definition: RelationalDBInterface_nodes.cpp:1018
ripple::RelationalDBInterfaceSqliteImp::getNewestAccountTxsB
MetaTxsList getNewestAccountTxsB(AccountTxOptions const &options) override
getNewestAccountTxsB Returns newest transactions in binary form for given account which match given c...
Definition: RelationalDBInterfaceSqlite.cpp:1223
ripple::RelationalDBInterfaceSqliteImp::lgrdb_
std::unique_ptr< DatabaseCon > lgrdb_
Definition: RelationalDBInterfaceSqlite.cpp:198
std::pair
ripple::RelationalDBInterfaceSqliteImp::deleteAccountTransactionsBeforeLedgerSeq
void deleteAccountTransactionsBeforeLedgerSeq(LedgerIndex ledgerSeq) override
deleteAccountTransactionsBeforeLedgerSeq Deletes all account transactions with given ledger sequence ...
Definition: RelationalDBInterfaceSqlite.cpp:638
ripple::LedgerMaster
Definition: LedgerMaster.h:70
ripple::RelationalDBInterface::AccountTxOptions::maxLedger
std::uint32_t maxLedger
Definition: RelationalDBInterface.h:68
ripple::RelationalDBInterfaceSqliteImp::oldestAccountTxPage
std::pair< AccountTxs, std::optional< AccountTxMarker > > oldestAccountTxPage(AccountTxPageOptions const &options) override
oldestAccountTxPage Returns oldest transactions for given account which match given criteria starting...
Definition: RelationalDBInterfaceSqlite.cpp:1282
ripple::RelationalDBInterfaceSqliteImp::oldestAccountTxPageB
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...
Definition: RelationalDBInterfaceSqlite.cpp:1422
ripple::setup_DatabaseCon
DatabaseCon::Setup setup_DatabaseCon(Config const &c, std::optional< beast::Journal > j=std::nullopt)
Definition: DatabaseCon.cpp:106
std::vector
STL class.
ripple::RelationalDBInterfaceSqliteImp::iterateTransactionBack
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...
Definition: RelationalDBInterfaceSqlite.cpp:424
ripple::RelationalDBInterfaceSqliteImp::shardStoreExists
bool shardStoreExists()
shardStoreExists Checks whether the shard store exists
Definition: RelationalDBInterfaceSqlite.cpp:287
ripple::getRowsMinMax
RelationalDBInterface::CountMinMax getRowsMinMax(soci::session &session, TableType type)
getRowsMinMax Returns minumum ledger sequence, maximum ledger sequence and total number of rows in gi...
Definition: RelationalDBInterface_nodes.cpp:170
ripple::DatabaseCon::CheckpointerSetup
Definition: DatabaseCon.h:107
ripple::newestAccountTxPage
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...
Definition: RelationalDBInterface_nodes.cpp:1247
ripple::getKBUsedDB
std::uint32_t getKBUsedDB(soci::session &s)
Definition: SociDB.cpp:139
ripple::getLedgerInfoByHash
std::optional< LedgerInfo > getLedgerInfoByHash(soci::session &session, uint256 const &ledgerHash, beast::Journal j)
getLedgerInfoByHash Returns info of ledger with given hash.
Definition: RelationalDBInterface_nodes.cpp:498
ripple::RelationalDBInterfaceSqliteImp::j_
beast::Journal j_
Definition: RelationalDBInterfaceSqlite.cpp:197
ripple::Application::getShardStore
virtual NodeStore::DatabaseShard * getShardStore()=0
ripple::RelationalDBInterfaceSqliteImp::getAccountTransactionsMinLedgerSeq
std::optional< LedgerIndex > getAccountTransactionsMinLedgerSeq() override
getAccountTransactionsMinLedgerSeq Returns minimum ledger sequence among records in the AccountTransa...
Definition: RelationalDBInterfaceSqlite.cpp:516
ripple::NodeStore::DatabaseShard::callForTransactionSQLByLedgerSeq
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.
ripple::RelationalDBInterfaceSqliteImp::lgrMetaDB_
std::unique_ptr< DatabaseCon > lgrMetaDB_
Definition: RelationalDBInterfaceSqlite.cpp:199
ripple::RelationalDBInterface::AccountTxPageOptions::marker
std::optional< AccountTxMarker > marker
Definition: RelationalDBInterface.h:79
ripple::RelationalDBInterfaceSqliteImp::checkoutTransaction
auto checkoutTransaction()
checkoutTransaction Checks out and returns node transaction DB.
Definition: RelationalDBInterfaceSqlite.cpp:307
std::function
ripple::RelationalDBInterfaceSqliteImp::txdb_
std::unique_ptr< DatabaseCon > txdb_
Definition: RelationalDBInterfaceSqlite.cpp:198
ripple::RelationalDBInterfaceSqliteImp::closeLedgerDB
void closeLedgerDB() override
Closes the ledger database.
Definition: RelationalDBInterfaceSqlite.cpp:1719
ripple::RelationalDBInterfaceSqliteImp::iterateLedgerBack
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 ...
Definition: RelationalDBInterfaceSqlite.cpp:402
ripple::RelationalDBInterfaceSqliteImp::getHashByIndex
uint256 getHashByIndex(LedgerIndex ledgerIndex) override
getHashByIndex Returns hash of ledger with given sequence.
Definition: RelationalDBInterfaceSqlite.cpp:925
ripple::RelationalDBInterfaceSqliteImp::transactionDbHasSpace
bool transactionDbHasSpace(Config const &config) override
transactionDbHasSpace Checks if transaction database has available space.
Definition: RelationalDBInterfaceSqlite.cpp:1627
ripple::getLimitedNewestLedgerInfo
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...
Definition: RelationalDBInterface_nodes.cpp:486
std::unique_ptr::reset
T reset(T... args)
ripple::error_code_i
error_code_i
Definition: ErrorCodes.h:40
ripple::getLimitedOldestLedgerInfo
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...
Definition: RelationalDBInterface_nodes.cpp:474
ripple::RelationalDBInterfaceSqliteImp::iterateTransactionForward
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...
Definition: RelationalDBInterfaceSqlite.cpp:380
ripple::Application::accountIDCache
virtual AccountIDCache const & accountIDCache() const =0
ripple::uint256
base_uint< 256 > uint256
Definition: base_uint.h:529
ripple::RelationalDBInterfaceSqliteImp::makeLedgerDBs
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...
Definition: RelationalDBInterfaceSqlite.cpp:436
ripple::getNewestAccountTxs
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...
Definition: RelationalDBInterface_nodes.cpp:910
ripple::RelationalDBInterface::CountMinMax
Definition: RelationalDBInterface.h:51
ripple::RelationalDBInterfaceSqliteImp::doLedger
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...
Definition: RelationalDBInterfaceSqlite.cpp:321
ripple::base_uint
Integers of any length that is a multiple of 32-bits.
Definition: base_uint.h:75
ripple::RelationalDBInterfaceSqliteImp::lastLedgerSeq
LedgerIndex lastLedgerSeq(std::uint32_t shardIndex)
lastLedgerSeq Returns last ledger sequence for given shard.
Definition: RelationalDBInterfaceSqlite.cpp:257
ripple::RelationalDBInterfaceSqliteImp::getOldestAccountTxsB
MetaTxsList getOldestAccountTxsB(AccountTxOptions const &options) override
getOldestAccountTxsB Returns oldest transactions in binary form for given account which match given c...
Definition: RelationalDBInterfaceSqlite.cpp:1166
ripple::NodeStore::Database::firstLedgerSeq
std::uint32_t firstLedgerSeq(std::uint32_t shardIndex) const noexcept
Calculates the first ledger sequence for a given shard index.
Definition: Database.h:256
ripple::getKBUsedAll
std::uint32_t getKBUsedAll(soci::session &s)
Definition: SociDB.cpp:130
ripple::RelationalDBInterfaceSqliteImp::getKBUsedAll
std::uint32_t getKBUsedAll() override
getKBUsedAll Returns space used by all databases.
Definition: RelationalDBInterfaceSqlite.cpp:1650
ripple::saveValidatedLedger
static bool saveValidatedLedger(Application &app, std::shared_ptr< Ledger const > const &ledger, bool current)
Definition: Ledger.cpp:916
ripple::RelationalDBInterfaceSqliteImp::deleteTransactionsBeforeLedgerSeq
void deleteTransactionsBeforeLedgerSeq(LedgerIndex ledgerSeq) override
deleteTransactionsBeforeLedgerSeq Deletes all transactions with given ledger sequence and all sequenc...
Definition: RelationalDBInterfaceSqlite.cpp:612
ripple::Application::getLedgerMaster
virtual LedgerMaster & getLedgerMaster()=0
ripple::Config
Definition: Config.h:68
ripple::NodeStore::DatabaseShard::iterateLedgerSQLsBack
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...
ripple::RelationalDBInterfaceSqlite
Definition: RelationalDBInterfaceSqlite.h:27
ripple::RelationalDBInterfaceSqliteImp::getLimitedOldestLedgerInfo
std::optional< LedgerInfo > getLimitedOldestLedgerInfo(LedgerIndex ledgerFirstIndex) override
getLimitedOldestLedgerInfo Returns info of oldest ledger from ledgers with sequences greater or equal...
Definition: RelationalDBInterfaceSqlite.cpp:834
ripple::RelationalDBInterfaceSqliteImp::existsLedger
bool existsLedger()
existsLedger Checks if node ledger DB exists.
Definition: RelationalDBInterfaceSqlite.cpp:267
ripple::NodeStore::DatabaseShard::iterateLedgerSQLsForward
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 ...
ripple::RelationalDBInterfaceSqliteImp::getTransactionCount
std::size_t getTransactionCount() override
getTransactionCount Returns number of transactions.
Definition: RelationalDBInterfaceSqlite.cpp:665
ripple::saveLedgerAsync
void saveLedgerAsync(Application &app, std::uint32_t seq)
Definition: AccountTxPaging.cpp:57
ripple::RelationalDBInterfaceSqliteImp::checkoutLedger
auto checkoutLedger()
checkoutTransaction Checks out and returns node ledger DB.
Definition: RelationalDBInterfaceSqlite.cpp:297
ripple::RelationalDBInterface::AccountTxOptions::minLedger
std::uint32_t minLedger
Definition: RelationalDBInterface.h:67
ripple::RelationalDBInterfaceSqliteImp
Definition: RelationalDBInterfaceSqlite.cpp:42
ripple::RelationalDBInterfaceSqliteImp::getLedgerInfoByHash
std::optional< LedgerInfo > getLedgerInfoByHash(uint256 const &ledgerHash) override
Definition: RelationalDBInterfaceSqlite.cpp:895
ripple::RelationalDBInterfaceSqliteImp::getNewestLedgerInfo
std::optional< LedgerInfo > getNewestLedgerInfo() override
getNewestLedgerInfo Returns info of newest saved ledger.
Definition: RelationalDBInterfaceSqlite.cpp:806
ripple::RelationalDBInterfaceSqliteImp::useTxTables_
const bool useTxTables_
Definition: RelationalDBInterfaceSqlite.cpp:196
ripple::RelationalDBInterfaceSqliteImp::getMinLedgerSeq
std::optional< LedgerIndex > getMinLedgerSeq() override
getMinLedgerSeq Returns minimum ledger sequence in Ledgers table.
Definition: RelationalDBInterfaceSqlite.cpp:464
ripple::RelationalDBInterfaceSqliteImp::deleteBeforeLedgerSeq
void deleteBeforeLedgerSeq(LedgerIndex ledgerSeq) override
deleteBeforeLedgerSeq Deletes all ledgers with given sequence and all sequences below it.
Definition: RelationalDBInterfaceSqlite.cpp:590
ripple::deleteByLedgerSeq
void deleteByLedgerSeq(soci::session &session, TableType type, LedgerIndex ledgerSeq)
deleteByLedgerSeq Deletes all entries in given table for the ledger with given sequence.
Definition: RelationalDBInterface_nodes.cpp:141
ripple::RelationalDBInterfaceSqliteImp::makeMetaDBs
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.
Definition: RelationalDBInterfaceSqlite.cpp:449
ripple::Application::logs
virtual Logs & logs()=0
ripple::TableType::Transactions
@ Transactions
ripple::ValStatus::current
@ current
This was a new validation and was added.
beast::Journal
A generic endpoint for log messages.
Definition: Journal.h:58
std::uint32_t
std::map
STL class.
ripple::RelationalDBInterface::AccountTxPageOptions::maxLedger
std::uint32_t maxLedger
Definition: RelationalDBInterface.h:78
ripple::range
ClosedInterval< T > range(T low, T high)
Create a closed range interval.
Definition: RangeSet.h:53
ripple::RelationalDBInterface::AccountTxPageOptions::minLedger
std::uint32_t minLedger
Definition: RelationalDBInterface.h:77
ripple::RelationalDBInterfaceSqliteImp::getLedgerCountMinMax
RelationalDBInterface::CountMinMax getLedgerCountMinMax() override
getLedgerCountMinMax Returns minumum ledger sequence, maximum ledger sequence and total number of sav...
Definition: RelationalDBInterfaceSqlite.cpp:718
ripple::TableType::Ledgers
@ Ledgers
ripple::TableType::AccountTransactions
@ AccountTransactions
ripple::RelationalDBInterfaceSqliteImp::getLimitedNewestLedgerInfo
std::optional< LedgerInfo > getLimitedNewestLedgerInfo(LedgerIndex ledgerFirstIndex) override
getLimitedNewestLedgerInfo Returns info of newest ledger from ledgers with sequences greater or equal...
Definition: RelationalDBInterfaceSqlite.cpp:865
ripple::JobQueue
A pool of threads to perform work.
Definition: JobQueue.h:55
ripple::RelationalDBInterfaceSqliteImp::firstLedgerSeq
LedgerIndex firstLedgerSeq(std::uint32_t shardIndex)
firstLedgerSeq Returns first ledger sequence for given shard.
Definition: RelationalDBInterfaceSqlite.cpp:246
std::min
T min(T... args)
ripple::getNewestAccountTxsB
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...
Definition: RelationalDBInterface_nodes.cpp:1029
ripple::RelationalDBInterfaceSqliteImp::existsTransaction
bool existsTransaction()
existsTransaction Checks if node transaction DB exists.
Definition: RelationalDBInterfaceSqlite.cpp:277
ripple::RelationalDBInterfaceSqliteImp::getKBUsedTransaction
std::uint32_t getKBUsedTransaction() override
getKBUsedTransaction Returns space used by transaction database.
Definition: RelationalDBInterfaceSqlite.cpp:1694
std::variant::index
T index(T... args)
ripple::RelationalDBInterfaceSqliteImp::getTxHistory
std::vector< std::shared_ptr< Transaction > > getTxHistory(LedgerIndex startIndex) override
getTxHistory Returns most recent 20 transactions starting from given number or entry.
Definition: RelationalDBInterfaceSqlite.cpp:1003
ripple::RelationalDBInterfaceSqliteImp::getLedgerInfoByIndex
std::optional< LedgerInfo > getLedgerInfoByIndex(LedgerIndex ledgerSeq) override
getLedgerInfoByIndex Returns ledger by its sequence.
Definition: RelationalDBInterfaceSqlite.cpp:784
ripple::RelationalDBInterfaceSqliteImp::seqToShardIndex
std::uint32_t seqToShardIndex(LedgerIndex ledgerSeq)
seqToShardIndex Converts ledgers sequence to shard index.
Definition: RelationalDBInterfaceSqlite.cpp:235
std::vector::emplace_back
T emplace_back(T... args)
ripple::getTransaction
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.
Definition: RelationalDBInterface_nodes.cpp:1270
ripple
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition: RCLCensorshipDetector.h:29
ripple::getRows
std::size_t getRows(soci::session &session, TableType type)
getRows Returns number of rows in given table.
Definition: RelationalDBInterface_nodes.cpp:158
ripple::Application::journal
virtual beast::Journal journal(std::string const &name)=0
ripple::RelationalDBInterface::MetaTxsList
std::vector< txnMetaLedgerType > MetaTxsList
Definition: RelationalDBInterface.h:88
ripple::getHashesByIndex
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...
Definition: RelationalDBInterface_nodes.cpp:539
ripple::NodeStore::Database::seqToShardIndex
std::uint32_t seqToShardIndex(std::uint32_t ledgerSeq) const noexcept
Calculates the shard index for a given ledger sequence.
Definition: Database.h:282
ripple::RelationalDBInterfaceSqliteImp::getHashesByIndex
std::optional< LedgerHashPair > getHashesByIndex(LedgerIndex ledgerIndex) override
getHashesByIndex Returns hash of the ledger and hash of parent ledger for the ledger of given sequenc...
Definition: RelationalDBInterfaceSqlite.cpp:947
ripple::RelationalDBInterfaceSqliteImp::getNewestAccountTxs
AccountTxs getNewestAccountTxs(AccountTxOptions const &options) override
getNewestAccountTxs Returns newest transactions for given account which match given criteria starting...
Definition: RelationalDBInterfaceSqlite.cpp:1105
std::map::insert
T insert(T... args)
ripple::convertBlobsToTxResult
void convertBlobsToTxResult(RelationalDBInterface::AccountTxs &to, std::uint32_t ledger_index, std::string const &status, Blob const &rawTxn, Blob const &rawMeta, Application &app)
Definition: AccountTxPaging.cpp:33
ripple::RelationalDBInterfaceSqliteImp::closeTransactionDB
void closeTransactionDB() override
Closes the transaction database.
Definition: RelationalDBInterfaceSqlite.cpp:1725
ripple::makeMetaDBs
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...
Definition: RelationalDBInterface_shards.cpp:36
ripple::RelationalDBInterfaceSqliteImp::app_
Application & app_
Definition: RelationalDBInterfaceSqlite.cpp:195
ripple::RelationalDBInterfaceSqliteImp::doTransaction
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...
Definition: RelationalDBInterfaceSqlite.cpp:338
ripple::makeLedgerDBs
DatabasePairValid makeLedgerDBs(Config const &config, DatabaseCon::Setup const &setup, DatabaseCon::CheckpointerSetup const &checkpointerSetup)
makeLedgerDBs Opens ledger and transactions databases.
Definition: RelationalDBInterface_nodes.cpp:65
ripple::RelationalDBInterfaceSqliteImp::newestAccountTxPage
std::pair< AccountTxs, std::optional< AccountTxMarker > > newestAccountTxPage(AccountTxPageOptions const &options) override
newestAccountTxPage Returns newest transactions for given account which match given criteria starting...
Definition: RelationalDBInterfaceSqlite.cpp:1352
ripple::RelationalDBInterfaceSqliteImp::ledgerDbHasSpace
bool ledgerDbHasSpace(Config const &config) override
ledgerDbHasSpace Checks if ledger database has available space.
Definition: RelationalDBInterfaceSqlite.cpp:1607
ripple::oldestAccountTxPage
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...
Definition: RelationalDBInterface_nodes.cpp:1224
ripple::RelationalDBInterfaceSqliteImp::getAccountTransactionCount
std::size_t getAccountTransactionCount() override
getAccountTransactionCount Returns number of account transactions.
Definition: RelationalDBInterfaceSqlite.cpp:691
ripple::saveLedgerMeta
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...
Definition: RelationalDBInterface_shards.cpp:66
std::optional
std::size_t
ripple::RelationalDBInterfaceSqliteImp::getMaxLedgerSeq
std::optional< LedgerIndex > getMaxLedgerSeq() override
getMaxLedgerSeq Returns maximum ledger sequence in Ledgers table.
Definition: RelationalDBInterfaceSqlite.cpp:543
std::vector::end
T end(T... args)
ripple::RelationalDBInterfaceSqliteImp::iterateLedgerForward
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...
Definition: RelationalDBInterfaceSqlite.cpp:358
ripple::RelationalDBInterface::AccountTxPageOptions
Definition: RelationalDBInterface.h:74
ripple::ClosedInterval
boost::icl::closed_interval< T > ClosedInterval
A closed interval over the domain T.
Definition: RangeSet.h:44
std::max
T max(T... args)
ripple::dbHasSpace
bool dbHasSpace(soci::session &session, Config const &config, beast::Journal j)
dbHasSpace Checks if given database has available space.
Definition: RelationalDBInterface_nodes.cpp:1351
ripple::getMinLedgerSeq
std::optional< LedgerIndex > getMinLedgerSeq(soci::session &session, TableType type)
getMinLedgerSeq Returns minimum ledger sequence in given table.
Definition: RelationalDBInterface_nodes.cpp:121
ripple::RelationalDBInterfaceSqliteImp::getOldestAccountTxs
AccountTxs getOldestAccountTxs(AccountTxOptions const &options) override
getOldestAccountTxs Returns oldest transactions for given account which match given criteria starting...
Definition: RelationalDBInterfaceSqlite.cpp:1044
ripple::getShardIndexforTransaction
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 ...
Definition: RelationalDBInterface_shards.cpp:144
std::unique_ptr
STL class.
ripple::RelationalDBInterfaceSqliteImp::saveValidatedLedger
bool saveValidatedLedger(std::shared_ptr< Ledger const > const &ledger, bool current) override
saveValidatedLedger Saves ledger into database.
Definition: RelationalDBInterfaceSqlite.cpp:748
ripple::RelationalDBInterface::AccountTxOptions
Definition: RelationalDBInterface.h:64
ripple::getNewestLedgerInfo
std::optional< LedgerInfo > getNewestLedgerInfo(soci::session &session, beast::Journal j)
getNewestLedgerInfo Returns info of newest saved ledger.
Definition: RelationalDBInterface_nodes.cpp:466
ripple::RelationalDBInterfaceSqliteImp::getTransactionsMinLedgerSeq
std::optional< LedgerIndex > getTransactionsMinLedgerSeq() override
getTransactionsMinLedgerSeq Returns minimum ledger sequence among records in the Transactions table.
Definition: RelationalDBInterfaceSqlite.cpp:490
ripple::getMaxLedgerSeq
std::optional< LedgerIndex > getMaxLedgerSeq(soci::session &session, TableType type)
getMaxLedgerSeq Returns maximum ledger sequence in given table.
Definition: RelationalDBInterface_nodes.cpp:131
ripple::RelationalDBInterfaceSqliteImp::RelationalDBInterfaceSqliteImp
RelationalDBInterfaceSqliteImp(Application &app, Config const &config, JobQueue &jobQueue)
Definition: RelationalDBInterfaceSqlite.cpp:45
std::ref
T ref(T... args)
std::variant
ripple::RelationalDBInterface::AccountTxs
std::vector< AccountTx > AccountTxs
Definition: RelationalDBInterface.h:86
ripple::RelationalDBInterfaceSqliteImp::getKBUsedLedger
std::uint32_t getKBUsedLedger() override
getKBUsedLedger Returns space used by ledger database.
Definition: RelationalDBInterfaceSqlite.cpp:1672
ripple::getShardIndexforLedger
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...
Definition: RelationalDBInterface_shards.cpp:130
ripple::RelationalDBInterfaceSqliteImp::getTransaction
std::variant< AccountTx, TxSearched > getTransaction(uint256 const &id, std::optional< ClosedInterval< std::uint32_t >> const &range, error_code_i &ec) override
Definition: RelationalDBInterfaceSqlite.cpp:1558