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/backend/RelationalDBInterfaceSqlite.h>
29 #include <ripple/basics/BasicConfig.h>
30 #include <ripple/basics/StringUtilities.h>
31 #include <ripple/core/DatabaseCon.h>
32 #include <ripple/core/SociDB.h>
33 #include <ripple/json/to_string.h>
34 #include <ripple/nodestore/DatabaseShard.h>
35 #include <boost/algorithm/string.hpp>
36 #include <boost/range/adaptor/transformed.hpp>
37 #include <soci/sqlite3/soci-sqlite3.h>
38 
39 namespace ripple {
40 
42 {
43 public:
45  Application& app,
46  Config const& config,
47  JobQueue& jobQueue)
48  : app_(app), j_(app_.journal("Ledger"))
49  {
50  DatabaseCon::Setup setup = setup_DatabaseCon(config, j_);
51  auto res = makeLedgerDBs(
52  config,
53  setup,
55  if (!res)
56  {
57  JLOG(app_.journal("Application").fatal())
58  << "AccountTransactions database "
59  "should not have a primary key";
60  Throw<std::exception>();
61  }
62  }
63 
65  getMinLedgerSeq() override;
66 
68  getTransactionsMinLedgerSeq() override;
69 
72 
74  getMaxLedgerSeq() override;
75 
76  void
77  deleteTransactionByLedgerSeq(LedgerIndex ledgerSeq) override;
78 
79  void
80  deleteBeforeLedgerSeq(LedgerIndex ledgerSeq) override;
81 
82  void
84 
85  void
87 
89  getTransactionCount() override;
90 
92  getAccountTransactionCount() override;
93 
95  getLedgerCountMinMax() override;
96 
97  bool
99  std::shared_ptr<Ledger const> const& ledger,
100  bool current) override;
101 
103  getLedgerInfoByIndex(LedgerIndex ledgerSeq) override;
104 
106  getNewestLedgerInfo() override;
107 
109  getLimitedOldestLedgerInfo(LedgerIndex ledgerFirstIndex) override;
110 
112  getLimitedNewestLedgerInfo(LedgerIndex ledgerFirstIndex) override;
113 
115  getLedgerInfoByHash(uint256 const& ledgerHash) override;
116 
117  uint256
118  getHashByIndex(LedgerIndex ledgerIndex) override;
119 
121  getHashesByIndex(LedgerIndex ledgerIndex) override;
122 
124  getHashesByIndex(LedgerIndex minSeq, LedgerIndex maxSeq) override;
125 
127  getTxHistory(LedgerIndex startIndex) override;
128 
129  AccountTxs
130  getOldestAccountTxs(AccountTxOptions const& options) override;
131 
132  AccountTxs
133  getNewestAccountTxs(AccountTxOptions const& options) override;
134 
136  getOldestAccountTxsB(AccountTxOptions const& options) override;
137 
139  getNewestAccountTxsB(AccountTxOptions const& options) override;
140 
142  oldestAccountTxPage(AccountTxPageOptions const& options) override;
143 
145  newestAccountTxPage(AccountTxPageOptions const& options) override;
146 
148  oldestAccountTxPageB(AccountTxPageOptions const& options) override;
149 
151  newestAccountTxPageB(AccountTxPageOptions const& options) override;
152 
155  uint256 const& id,
157  error_code_i& ec) override;
158 
159  bool
160  ledgerDbHasSpace(Config const& config) override;
161 
162  bool
163  transactionDbHasSpace(Config const& config) override;
164 
165  int
166  getKBUsedAll() override;
167 
168  int
169  getKBUsedLedger() override;
170 
171  int
172  getKBUsedTransaction() override;
173 
174 private:
178 
187  bool
189  Config const& config,
190  DatabaseCon::Setup const& setup,
191  DatabaseCon::CheckpointerSetup const& checkpointerSetup);
192 
200  {
201  return app_.getShardStore()->seqToShardIndex(ledgerSeq);
202  }
203 
211  {
212  return app_.getShardStore()->firstLedgerSeq(shardIndex);
213  }
214 
222  {
223  return app_.getShardStore()->lastLedgerSeq(shardIndex);
224  }
225 
230  bool
232  {
233  return !!lgrdb_;
234  }
235 
240  bool
242  {
243  return !!txdb_;
244  }
245 
250  auto
252  {
253  return lgrdb_->checkoutDb();
254  }
255 
260  auto
262  {
263  return txdb_->checkoutDb();
264  }
265 
274  bool
276  LedgerIndex ledgerSeq,
277  std::function<bool(soci::session& session, std::uint32_t index)> const&
278  callback)
279  {
280  return app_.getShardStore()->callForLedgerSQL(ledgerSeq, callback);
281  }
282 
291  bool
293  LedgerIndex ledgerSeq,
294  std::function<bool(soci::session& session, std::uint32_t index)> const&
295  callback)
296  {
297  return app_.getShardStore()->callForTransactionSQL(ledgerSeq, callback);
298  }
299 
311  bool
313  std::optional<std::uint32_t> firstIndex,
314  std::function<bool(soci::session& session, std::uint32_t index)> const&
315  callback)
316  {
318  firstIndex, callback);
319  }
320 
332  bool
334  std::optional<std::uint32_t> firstIndex,
335  std::function<bool(soci::session& session, std::uint32_t index)> const&
336  callback)
337  {
339  firstIndex, callback);
340  }
341 
353  bool
355  std::optional<std::uint32_t> firstIndex,
356  std::function<bool(soci::session& session, std::uint32_t index)> const&
357  callback)
358  {
360  firstIndex, callback);
361  }
362 
374  bool
376  std::optional<std::uint32_t> firstIndex,
377  std::function<bool(soci::session& session, std::uint32_t index)> const&
378  callback)
379  {
381  firstIndex, callback);
382  }
383 };
384 
385 bool
387  Config const& config,
388  DatabaseCon::Setup const& setup,
389  DatabaseCon::CheckpointerSetup const& checkpointerSetup)
390 {
391  auto [lgr, tx, res] =
392  ripple::makeLedgerDBs(config, setup, checkpointerSetup);
393  txdb_ = std::move(tx);
394  lgrdb_ = std::move(lgr);
395  return res;
396 }
397 
400 {
401  /* if databases exists, use it */
402  if (existsLedger())
403  {
404  auto db = checkoutLedger();
406  }
407 
408  /* else use shard databases */
410  iterateLedgerForward({}, [&](soci::session& session, std::uint32_t index) {
412  return !res;
413  });
414  return res;
415 }
416 
419 {
420  /* if databases exists, use it */
421  if (existsTransaction())
422  {
423  auto db = checkoutTransaction();
425  }
426 
427  /* else use shard databases */
430  {}, [&](soci::session& session, std::uint32_t index) {
432  return !res;
433  });
434  return res;
435 }
436 
439 {
440  /* if databases exists, use it */
441  if (existsTransaction())
442  {
443  auto db = checkoutTransaction();
445  }
446 
447  /* else use shard databases */
450  {}, [&](soci::session& session, std::uint32_t index) {
453  return !res;
454  });
455  return res;
456 }
457 
460 {
461  /* if databases exists, use it */
462  if (existsLedger())
463  {
464  auto db = checkoutLedger();
466  }
467 
468  /* else use shard databases */
470  iterateLedgerBack({}, [&](soci::session& session, std::uint32_t index) {
472  return !res;
473  });
474  return res;
475 }
476 
477 void
479  LedgerIndex ledgerSeq)
480 {
481  /* if databases exists, use it */
482  if (existsTransaction())
483  {
484  auto db = checkoutTransaction();
486  return;
487  }
488 
489  /* else use shard database */
490  doTransaction(ledgerSeq, [&](soci::session& session, std::uint32_t index) {
492  return true;
493  });
494 }
495 
496 void
498 {
499  /* if databases exists, use it */
500  if (existsLedger())
501  {
502  auto db = checkoutLedger();
504  return;
505  }
506 
507  /* else use shard databases */
509  seqToShardIndex(ledgerSeq),
510  [&](soci::session& session, std::uint32_t index) {
512  session, TableType::Ledgers, ledgerSeq);
513  return true;
514  });
515 }
516 
517 void
519  LedgerIndex ledgerSeq)
520 {
521  /* if databases exists, use it */
522  if (existsTransaction())
523  {
524  auto db = checkoutTransaction();
526  return;
527  }
528 
529  /* else use shard databases */
531  seqToShardIndex(ledgerSeq),
532  [&](soci::session& session, std::uint32_t index) {
534  session, TableType::Transactions, ledgerSeq);
535  return true;
536  });
537 }
538 
539 void
541  LedgerIndex ledgerSeq)
542 {
543  /* if databases exists, use it */
544  if (existsTransaction())
545  {
546  auto db = checkoutTransaction();
548  *db, TableType::AccountTransactions, ledgerSeq);
549  return;
550  }
551 
552  /* else use shard databases */
554  seqToShardIndex(ledgerSeq),
555  [&](soci::session& session, std::uint32_t index) {
557  session, TableType::AccountTransactions, ledgerSeq);
558  return true;
559  });
560 }
561 
564 {
565  /* if databases exists, use it */
566  if (existsTransaction())
567  {
568  auto db = checkoutTransaction();
570  }
571 
572  /* else use shard databases */
573  std::size_t rows = 0;
575  {}, [&](soci::session& session, std::uint32_t index) {
576  rows += ripple::getRows(session, TableType::Transactions);
577  return true;
578  });
579  return rows;
580 }
581 
584 {
585  /* if databases exists, use it */
586  if (existsTransaction())
587  {
588  auto db = checkoutTransaction();
590  }
591 
592  /* else use shard databases */
593  std::size_t rows = 0;
595  {}, [&](soci::session& session, std::uint32_t index) {
597  return true;
598  });
599  return rows;
600 }
601 
604 {
605  /* if databases exists, use it */
606  if (existsLedger())
607  {
608  auto db = checkoutLedger();
610  }
611 
612  /* else use shard databases */
613  CountMinMax res{0, 0, 0};
614  iterateLedgerForward({}, [&](soci::session& session, std::uint32_t index) {
615  auto r = ripple::getRowsMinMax(session, TableType::Ledgers);
616  if (r.numberOfRows)
617  {
618  res.numberOfRows += r.numberOfRows;
619  if (res.minLedgerSequence == 0)
620  res.minLedgerSequence = r.minLedgerSequence;
621  res.maxLedgerSequence = r.maxLedgerSequence;
622  }
623  return true;
624  });
625  return res;
626 }
627 
628 bool
630  std::shared_ptr<Ledger const> const& ledger,
631  bool current)
632 {
633  /* if databases exists, use it */
634  if (existsLedger() && existsTransaction())
635  {
637  *lgrdb_, *txdb_, app_, ledger, current);
638  }
639 
640  /* Todo: use shard databases. Skipped in this PR by propose of Mickey
641  * Portilla. */
642 
643  return false;
644 }
645 
648 {
649  /* if databases exists, use it */
650  if (existsLedger())
651  {
652  auto db = checkoutLedger();
653  return ripple::getLedgerInfoByIndex(*db, ledgerSeq, j_);
654  }
655 
656  /* else use shard database */
658  doLedger(ledgerSeq, [&](soci::session& session, std::uint32_t index) {
659  res = ripple::getLedgerInfoByIndex(session, ledgerSeq, j_);
660  return true;
661  });
662  return res;
663 }
664 
667 {
668  /* if databases exists, use it */
669  if (existsLedger())
670  {
671  auto db = checkoutLedger();
672  return ripple::getNewestLedgerInfo(*db, j_);
673  }
674 
675  /* else use shard databases */
677  iterateLedgerBack({}, [&](soci::session& session, std::uint32_t index) {
678  if (auto info = ripple::getNewestLedgerInfo(session, j_))
679  {
680  res = info;
681  return false;
682  }
683  return true;
684  });
685 
686  return res;
687 }
688 
691  LedgerIndex ledgerFirstIndex)
692 {
693  /* if databases exists, use it */
694  if (existsLedger())
695  {
696  auto db = checkoutLedger();
697  return ripple::getLimitedOldestLedgerInfo(*db, ledgerFirstIndex, j_);
698  }
699 
700  /* else use shard databases */
703  seqToShardIndex(ledgerFirstIndex),
704  [&](soci::session& session, std::uint32_t index) {
705  if (auto info = ripple::getLimitedOldestLedgerInfo(
706  session, ledgerFirstIndex, j_))
707  {
708  res = info;
709  return false;
710  }
711  return true;
712  });
713 
714  return res;
715 }
716 
719  LedgerIndex ledgerFirstIndex)
720 {
721  /* if databases exists, use it */
722  if (existsLedger())
723  {
724  auto db = checkoutLedger();
725  return ripple::getLimitedNewestLedgerInfo(*db, ledgerFirstIndex, j_);
726  }
727 
728  /* else use shard databases */
730  iterateLedgerBack({}, [&](soci::session& session, std::uint32_t index) {
731  if (auto info = ripple::getLimitedNewestLedgerInfo(
732  session, ledgerFirstIndex, j_))
733  {
734  res = info;
735  return false;
736  }
737  if (index < seqToShardIndex(ledgerFirstIndex))
738  return false;
739  return true;
740  });
741 
742  return res;
743 }
744 
747 {
748  /* if databases exists, use it */
749  if (existsLedger())
750  {
751  auto db = checkoutLedger();
752  return ripple::getLedgerInfoByHash(*db, ledgerHash, j_);
753  }
754 
755  /* else use shard databases */
757  iterateLedgerBack({}, [&](soci::session& session, std::uint32_t index) {
758  if (auto info = ripple::getLedgerInfoByHash(session, ledgerHash, j_))
759  {
760  res = info;
761  return false;
762  }
763  return true;
764  });
765 
766  return res;
767 }
768 
769 uint256
771 {
772  /* if database exists, use it */
773  if (existsLedger())
774  {
775  auto db = checkoutLedger();
776  return ripple::getHashByIndex(*db, ledgerIndex);
777  }
778 
779  /* else use shard database */
780  uint256 hash;
781  doLedger(ledgerIndex, [&](soci::session& session, std::uint32_t index) {
782  hash = ripple::getHashByIndex(session, ledgerIndex);
783  return true;
784  });
785  return hash;
786 }
787 
790 {
791  /* if database exists, use it */
792  if (existsLedger())
793  {
794  auto db = checkoutLedger();
795  return ripple::getHashesByIndex(*db, ledgerIndex, j_);
796  }
797 
798  /* else use shard database */
800  doLedger(ledgerIndex, [&](soci::session& session, std::uint32_t index) {
801  res = ripple::getHashesByIndex(session, ledgerIndex, j_);
802  return true;
803  });
804  return res;
805 }
806 
809  LedgerIndex minSeq,
810  LedgerIndex maxSeq)
811 {
812  /* if database exists, use it */
813  if (existsLedger())
814  {
815  auto db = checkoutLedger();
816  return ripple::getHashesByIndex(*db, minSeq, maxSeq, j_);
817  }
818 
819  /* else use shard databases */
821  while (minSeq <= maxSeq)
822  {
823  LedgerIndex shardMaxSeq = lastLedgerSeq(seqToShardIndex(minSeq));
824  if (shardMaxSeq > maxSeq)
825  shardMaxSeq = maxSeq;
826  doLedger(minSeq, [&](soci::session& session, std::uint32_t index) {
827  auto r = ripple::getHashesByIndex(session, minSeq, shardMaxSeq, j_);
828  res.insert(r.begin(), r.end());
829  return true;
830  });
831  minSeq = shardMaxSeq + 1;
832  }
833 
834  return res;
835 }
836 
839 {
840  /* if databases exists, use it */
841  if (existsTransaction())
842  {
843  auto db = checkoutTransaction();
844  return ripple::getTxHistory(*db, app_, startIndex, 20, false).first;
845  }
846 
847  /* else use shard databases */
849  int quantity = 20;
851  {}, [&](soci::session& session, std::uint32_t index) {
852  auto [tx, total] =
853  ripple::getTxHistory(session, app_, startIndex, quantity, true);
854  txs.insert(txs.end(), tx.begin(), tx.end());
855  if (total > 0)
856  {
857  quantity -= total;
858  if (quantity <= 0)
859  return false;
860  startIndex = 0;
861  }
862  else
863  {
864  startIndex += total;
865  }
866  return true;
867  });
868 
869  return txs;
870 }
871 
874  AccountTxOptions const& options)
875 {
877 
878  /* if databases exists, use it */
879  if (existsTransaction())
880  {
881  auto db = checkoutTransaction();
883  *db, app_, ledgerMaster, options, {}, j_)
884  .first;
885  }
886 
887  /* else use shard databases */
888  AccountTxs ret;
889  AccountTxOptions opt = options;
890  int limit_used = 0;
894  [&](soci::session& session, std::uint32_t index) {
895  if (opt.maxLedger && index > seqToShardIndex(opt.maxLedger))
896  return false;
897  auto [r, total] = ripple::getOldestAccountTxs(
898  session, app_, ledgerMaster, opt, limit_used, j_);
899  ret.insert(ret.end(), r.begin(), r.end());
900  if (!total)
901  return false;
902  if (total > 0)
903  {
904  limit_used += total;
905  opt.offset = 0;
906  }
907  else
908  {
909  total = ~total;
910  if (opt.offset <= total)
911  opt.offset = 0;
912  else
913  opt.offset -= total;
914  }
915  return true;
916  });
917 
918  return ret;
919 }
920 
921 RelationalDBInterface::AccountTxs
922 RelationalDBInterfaceSqliteImp::getNewestAccountTxs(
923  AccountTxOptions const& options)
924 {
926 
927  /* if databases exists, use it */
928  if (existsTransaction())
929  {
930  auto db = checkoutTransaction();
932  *db, app_, ledgerMaster, options, {}, j_)
933  .first;
934  }
935 
936  /* else use shard databases */
937  AccountTxs ret;
938  AccountTxOptions opt = options;
939  int limit_used = 0;
940  iterateTransactionBack(
941  opt.maxLedger ? seqToShardIndex(opt.maxLedger)
943  [&](soci::session& session, std::uint32_t index) {
944  if (opt.minLedger && index < seqToShardIndex(opt.minLedger))
945  return false;
946  auto [r, total] = ripple::getNewestAccountTxs(
947  session, app_, ledgerMaster, opt, limit_used, j_);
948  ret.insert(ret.end(), r.begin(), r.end());
949  if (!total)
950  return false;
951  if (total > 0)
952  {
953  limit_used += total;
954  opt.offset = 0;
955  }
956  else
957  {
958  total = ~total;
959  if (opt.offset <= total)
960  opt.offset = 0;
961  else
962  opt.offset -= total;
963  }
964  return true;
965  });
966 
967  return ret;
968 }
969 
970 RelationalDBInterface::MetaTxsList
971 RelationalDBInterfaceSqliteImp::getOldestAccountTxsB(
972  AccountTxOptions const& options)
973 {
974  /* if databases exists, use it */
975  if (existsTransaction())
976  {
977  auto db = checkoutTransaction();
978  return ripple::getOldestAccountTxsB(*db, app_, options, {}, j_).first;
979  }
980 
981  /* else use shard databases */
982  MetaTxsList ret;
983  AccountTxOptions opt = options;
984  int limit_used = 0;
985  iterateTransactionForward(
986  opt.minLedger ? seqToShardIndex(opt.minLedger)
988  [&](soci::session& session, std::uint32_t index) {
989  if (opt.maxLedger && index > seqToShardIndex(opt.maxLedger))
990  return false;
991  auto [r, total] = ripple::getOldestAccountTxsB(
992  session, app_, opt, limit_used, j_);
993  ret.insert(ret.end(), r.begin(), r.end());
994  if (!total)
995  return false;
996  if (total > 0)
997  {
998  limit_used += total;
999  opt.offset = 0;
1000  }
1001  else
1002  {
1003  total = ~total;
1004  if (opt.offset <= total)
1005  opt.offset = 0;
1006  else
1007  opt.offset -= total;
1008  }
1009  return true;
1010  });
1011 
1012  return ret;
1013 }
1014 
1015 RelationalDBInterface::MetaTxsList
1016 RelationalDBInterfaceSqliteImp::getNewestAccountTxsB(
1017  AccountTxOptions const& options)
1018 {
1019  /* if databases exists, use it */
1020  if (existsTransaction())
1021  {
1022  auto db = checkoutTransaction();
1023  return ripple::getNewestAccountTxsB(*db, app_, options, {}, j_).first;
1024  }
1025 
1026  /* else use shard databases */
1027  MetaTxsList ret;
1028  AccountTxOptions opt = options;
1029  int limit_used = 0;
1030  iterateTransactionBack(
1031  opt.maxLedger ? seqToShardIndex(opt.maxLedger)
1033  [&](soci::session& session, std::uint32_t index) {
1034  if (opt.minLedger && index < seqToShardIndex(opt.minLedger))
1035  return false;
1036  auto [r, total] = ripple::getNewestAccountTxsB(
1037  session, app_, opt, limit_used, j_);
1038  ret.insert(ret.end(), r.begin(), r.end());
1039  if (!total)
1040  return false;
1041  if (total > 0)
1042  {
1043  limit_used += total;
1044  opt.offset = 0;
1045  }
1046  else
1047  {
1048  total = ~total;
1049  if (opt.offset <= total)
1050  opt.offset = 0;
1051  else
1052  opt.offset -= total;
1053  }
1054  return true;
1055  });
1056 
1057  return ret;
1058 }
1059 
1060 std::pair<
1061  RelationalDBInterface::AccountTxs,
1063 RelationalDBInterfaceSqliteImp::oldestAccountTxPage(
1064  AccountTxPageOptions const& options)
1065 {
1066  static std::uint32_t const page_length(200);
1067  auto& idCache = app_.accountIDCache();
1068  auto onUnsavedLedger =
1069  std::bind(saveLedgerAsync, std::ref(app_), std::placeholders::_1);
1070  AccountTxs ret;
1071  Application& app = app_;
1072  auto onTransaction = [&ret, &app](
1073  std::uint32_t ledger_index,
1074  std::string const& status,
1075  Blob&& rawTxn,
1076  Blob&& rawMeta) {
1077  convertBlobsToTxResult(ret, ledger_index, status, rawTxn, rawMeta, app);
1078  };
1079 
1080  /* if databases exists, use it */
1081  if (existsTransaction())
1082  {
1083  auto db = checkoutTransaction();
1084  auto newmarker = ripple::oldestAccountTxPage(
1085  *db,
1086  idCache,
1087  onUnsavedLedger,
1088  onTransaction,
1089  options,
1090  0,
1091  page_length)
1092  .first;
1093  return {ret, newmarker};
1094  }
1095 
1096  /* else use shard databases */
1097  AccountTxPageOptions opt = options;
1098  int limit_used = 0;
1099  iterateTransactionForward(
1100  opt.minLedger ? seqToShardIndex(opt.minLedger)
1102  [&](soci::session& session, std::uint32_t index) {
1103  if (opt.maxLedger != UINT32_MAX &&
1104  index > seqToShardIndex(opt.minLedger))
1105  return false;
1106  auto [marker, total] = ripple::oldestAccountTxPage(
1107  session,
1108  idCache,
1109  onUnsavedLedger,
1110  onTransaction,
1111  opt,
1112  limit_used,
1113  page_length);
1114  opt.marker = marker;
1115  if (total < 0)
1116  return false;
1117  limit_used += total;
1118  return true;
1119  });
1120 
1121  return {ret, opt.marker};
1122 }
1123 
1124 std::pair<
1127 RelationalDBInterfaceSqliteImp::newestAccountTxPage(
1128  AccountTxPageOptions const& options)
1129 {
1130  static std::uint32_t const page_length(200);
1131  auto& idCache = app_.accountIDCache();
1132  auto onUnsavedLedger =
1133  std::bind(saveLedgerAsync, std::ref(app_), std::placeholders::_1);
1134  AccountTxs ret;
1135  Application& app = app_;
1136  auto onTransaction = [&ret, &app](
1137  std::uint32_t ledger_index,
1138  std::string const& status,
1139  Blob&& rawTxn,
1140  Blob&& rawMeta) {
1141  convertBlobsToTxResult(ret, ledger_index, status, rawTxn, rawMeta, app);
1142  };
1143 
1144  /* if databases exists, use it */
1145  if (existsTransaction())
1146  {
1147  auto db = checkoutTransaction();
1148  auto newmarker = ripple::newestAccountTxPage(
1149  *db,
1150  idCache,
1151  onUnsavedLedger,
1152  onTransaction,
1153  options,
1154  0,
1155  page_length)
1156  .first;
1157  return {ret, newmarker};
1158  }
1159 
1160  /* else use shard databases */
1161  AccountTxPageOptions opt = options;
1162  int limit_used = 0;
1163  iterateTransactionBack(
1164  opt.maxLedger != UINT32_MAX ? seqToShardIndex(opt.maxLedger)
1166  [&](soci::session& session, std::uint32_t index) {
1167  if (opt.minLedger && index < seqToShardIndex(opt.minLedger))
1168  return false;
1169  auto [marker, total] = ripple::newestAccountTxPage(
1170  session,
1171  idCache,
1172  onUnsavedLedger,
1173  onTransaction,
1174  opt,
1175  limit_used,
1176  page_length);
1177  opt.marker = marker;
1178  if (total < 0)
1179  return false;
1180  limit_used += total;
1181  return true;
1182  });
1183 
1184  return {ret, opt.marker};
1185 }
1186 
1187 std::pair<
1190 RelationalDBInterfaceSqliteImp::oldestAccountTxPageB(
1191  AccountTxPageOptions const& options)
1192 {
1193  static std::uint32_t const page_length(500);
1194  auto& idCache = app_.accountIDCache();
1195  auto onUnsavedLedger =
1196  std::bind(saveLedgerAsync, std::ref(app_), std::placeholders::_1);
1197  MetaTxsList ret;
1198  auto onTransaction = [&ret](
1199  std::uint32_t ledgerIndex,
1200  std::string const& status,
1201  Blob&& rawTxn,
1202  Blob&& rawMeta) {
1203  ret.emplace_back(std::move(rawTxn), std::move(rawMeta), ledgerIndex);
1204  };
1205 
1206  /* if databases exists, use it */
1207  if (existsTransaction())
1208  {
1209  auto db = checkoutTransaction();
1210  auto newmarker = ripple::oldestAccountTxPage(
1211  *db,
1212  idCache,
1213  onUnsavedLedger,
1214  onTransaction,
1215  options,
1216  0,
1217  page_length)
1218  .first;
1219  return {ret, newmarker};
1220  }
1221 
1222  /* else use shard databases */
1223  AccountTxPageOptions opt = options;
1224  int limit_used = 0;
1225  iterateTransactionForward(
1226  opt.minLedger ? seqToShardIndex(opt.minLedger)
1228  [&](soci::session& session, std::uint32_t index) {
1229  if (opt.maxLedger != UINT32_MAX &&
1230  index > seqToShardIndex(opt.minLedger))
1231  return false;
1232  auto [marker, total] = ripple::oldestAccountTxPage(
1233  session,
1234  idCache,
1235  onUnsavedLedger,
1236  onTransaction,
1237  opt,
1238  limit_used,
1239  page_length);
1240  opt.marker = marker;
1241  if (total < 0)
1242  return false;
1243  limit_used += total;
1244  return true;
1245  });
1246 
1247  return {ret, opt.marker};
1248 }
1249 
1250 std::pair<
1253 RelationalDBInterfaceSqliteImp::newestAccountTxPageB(
1254  AccountTxPageOptions const& options)
1255 {
1256  static std::uint32_t const page_length(500);
1257  auto& idCache = app_.accountIDCache();
1258  auto onUnsavedLedger =
1259  std::bind(saveLedgerAsync, std::ref(app_), std::placeholders::_1);
1260  MetaTxsList ret;
1261  auto onTransaction = [&ret](
1262  std::uint32_t ledgerIndex,
1263  std::string const& status,
1264  Blob&& rawTxn,
1265  Blob&& rawMeta) {
1266  ret.emplace_back(std::move(rawTxn), std::move(rawMeta), ledgerIndex);
1267  };
1268 
1269  /* if databases exists, use it */
1270  if (existsTransaction())
1271  {
1272  auto db = checkoutTransaction();
1273  auto newmarker = ripple::newestAccountTxPage(
1274  *db,
1275  idCache,
1276  onUnsavedLedger,
1277  onTransaction,
1278  options,
1279  0,
1280  page_length)
1281  .first;
1282  return {ret, newmarker};
1283  }
1284 
1285  /* else use shard databases */
1286  AccountTxPageOptions opt = options;
1287  int limit_used = 0;
1288  iterateTransactionBack(
1289  opt.maxLedger != UINT32_MAX ? seqToShardIndex(opt.maxLedger)
1291  [&](soci::session& session, std::uint32_t index) {
1292  if (opt.minLedger && index < seqToShardIndex(opt.minLedger))
1293  return false;
1294  auto [marker, total] = ripple::newestAccountTxPage(
1295  session,
1296  idCache,
1297  onUnsavedLedger,
1298  onTransaction,
1299  opt,
1300  limit_used,
1301  page_length);
1302  opt.marker = marker;
1303  if (total < 0)
1304  return false;
1305  limit_used += total;
1306  return true;
1307  });
1308 
1309  return {ret, opt.marker};
1310 }
1311 
1313 RelationalDBInterfaceSqliteImp::getTransaction(
1314  uint256 const& id,
1316  error_code_i& ec)
1317 {
1318  /* if databases exists, use it */
1319  if (existsTransaction())
1320  {
1321  auto db = checkoutTransaction();
1322  return ripple::getTransaction(*db, app_, id, range, ec);
1323  }
1324 
1325  /* else use shard databases */
1326  std::variant<AccountTx, TxSearched> res(TxSearched::unknown);
1327  iterateTransactionBack(
1328  {}, [&](soci::session& session, std::uint32_t index) {
1330  if (range)
1331  {
1332  uint32_t low = std::max(range->lower(), firstLedgerSeq(index));
1333  uint32_t high = std::min(range->upper(), lastLedgerSeq(index));
1334  if (low <= high)
1335  range1 = ClosedInterval<uint32_t>(low, high);
1336  }
1337  res = ripple::getTransaction(session, app_, id, range1, ec);
1338  /* finish iterations if transaction found or error detected */
1339  return res.index() == 1 &&
1340  std::get<TxSearched>(res) != TxSearched::unknown;
1341  });
1342 
1343  return res;
1344 }
1345 
1346 bool
1347 RelationalDBInterfaceSqliteImp::ledgerDbHasSpace(Config const& config)
1348 {
1349  /* if databases exists, use it */
1350  if (existsLedger())
1351  {
1352  auto db = checkoutLedger();
1353  return ripple::dbHasSpace(*db, config, j_);
1354  }
1355 
1356  /* else use shard databases */
1357  return iterateLedgerBack(
1358  {}, [&](soci::session& session, std::uint32_t index) {
1359  return ripple::dbHasSpace(session, config, j_);
1360  });
1361 }
1362 
1363 bool
1364 RelationalDBInterfaceSqliteImp::transactionDbHasSpace(Config const& config)
1365 {
1366  /* if databases exists, use it */
1367  if (existsTransaction())
1368  {
1369  auto db = checkoutTransaction();
1370  return ripple::dbHasSpace(*db, config, j_);
1371  }
1372 
1373  /* else use shard databases */
1374  return iterateTransactionBack(
1375  {}, [&](soci::session& session, std::uint32_t index) {
1376  return ripple::dbHasSpace(session, config, j_);
1377  });
1378 }
1379 
1380 int
1381 RelationalDBInterfaceSqliteImp::getKBUsedAll()
1382 {
1383  /* if databases exists, use it */
1384  if (existsLedger())
1385  {
1386  return ripple::getKBUsedAll(lgrdb_->getSession());
1387  }
1388 
1389  /* else use shard databases */
1390  int sum = 0;
1391  iterateLedgerBack({}, [&](soci::session& session, std::uint32_t index) {
1392  sum += ripple::getKBUsedAll(session);
1393  return true;
1394  });
1395  return sum;
1396 }
1397 
1398 int
1399 RelationalDBInterfaceSqliteImp::getKBUsedLedger()
1400 {
1401  /* if databases exists, use it */
1402  if (existsLedger())
1403  {
1404  return ripple::getKBUsedDB(lgrdb_->getSession());
1405  }
1406 
1407  /* else use shard databases */
1408  int sum = 0;
1409  iterateLedgerBack({}, [&](soci::session& session, std::uint32_t index) {
1410  sum += ripple::getKBUsedDB(session);
1411  return true;
1412  });
1413  return sum;
1414 }
1415 
1416 int
1417 RelationalDBInterfaceSqliteImp::getKBUsedTransaction()
1418 {
1419  /* if databases exists, use it */
1420  if (existsTransaction())
1421  {
1422  return ripple::getKBUsedDB(txdb_->getSession());
1423  }
1424 
1425  /* else use shard databases */
1426  int sum = 0;
1427  iterateTransactionBack(
1428  {}, [&](soci::session& session, std::uint32_t index) {
1429  sum += ripple::getKBUsedDB(session);
1430  return true;
1431  });
1432  return sum;
1433 }
1434 
1437  Application& app,
1438  Config const& config,
1439  JobQueue& jobQueue)
1440 {
1441  return std::make_unique<RelationalDBInterfaceSqliteImp>(
1442  app, config, jobQueue);
1443 }
1444 
1445 } // namespace ripple
beast::Journal::fatal
Stream fatal() const
Definition: Journal.h:339
ripple::RelationalDBInterfaceSqliteImp::deleteTransactionByLedgerSeq
void deleteTransactionByLedgerSeq(LedgerIndex ledgerSeq) override
deleteTransactionByLedgerSeq Deletes transactions from ledger with given sequence.
Definition: RelationalDBInterfaceSqlite.cpp:478
ripple::getLedgerInfoByIndex
std::optional< LedgerInfo > getLedgerInfoByIndex(soci::session &session, LedgerIndex ledgerSeq, beast::Journal j)
getLedgerInfoByIndex Returns ledger by its sequence.
Definition: RelationalDBInterface_nodes.cpp:453
ripple::Application
Definition: Application.h:102
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::RelationalDBInterfaceSqliteImp::getKBUsedAll
int getKBUsedAll() override
getKBUsedAll Returns space used by all databases.
Definition: RelationalDBInterfaceSqlite.cpp:1381
ripple::HashPrefix::ledgerMaster
@ ledgerMaster
ledger master data for signing
ripple::RelationalDBInterfaceSqliteImp::iterateLedgerForward
bool iterateLedgerForward(std::optional< std::uint32_t > firstIndex, std::function< bool(soci::session &session, std::uint32_t index)> const &callback)
iterateLedgerForward Checkouts ledger databases for all shards in ascending order starting from given...
Definition: RelationalDBInterfaceSqlite.cpp:312
ripple::RelationalDBInterfaceSqliteImp::getKBUsedLedger
int getKBUsedLedger() override
getKBUsedLedger Returns space used by ledger database.
Definition: RelationalDBInterfaceSqlite.cpp:1399
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:613
ripple::RelationalDBInterfaceSqliteImp::iterateLedgerBack
bool iterateLedgerBack(std::optional< std::uint32_t > firstIndex, std::function< bool(soci::session &session, std::uint32_t index)> const &callback)
iterateLedgerBack Checkouts ledger databases for all shards in descending order starting from given s...
Definition: RelationalDBInterfaceSqlite.cpp:354
ripple::getHashByIndex
uint256 getHashByIndex(soci::session &session, LedgerIndex ledgerIndex)
getHashByIndex Returns hash of ledger with given sequence.
Definition: RelationalDBInterface_nodes.cpp:507
ripple::getRelationalDBInterfaceSqlite
std::unique_ptr< RelationalDBInterface > getRelationalDBInterfaceSqlite(Application &app, Config const &config, JobQueue &jobQueue)
Definition: RelationalDBInterfaceSqlite.cpp:1436
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:891
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:1253
ripple::DatabaseCon::Setup
Definition: DatabaseCon.h:84
ripple::getKBUsedDB
size_t getKBUsedDB(soci::session &s)
Definition: SociDB.cpp:139
ripple::getKBUsedAll
size_t getKBUsedAll(soci::session &s)
Definition: SociDB.cpp:130
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:1008
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:1016
ripple::NodeStore::DatabaseShard::seqToShardIndex
virtual std::uint32_t seqToShardIndex(std::uint32_t seq) const =0
Calculates the shard index for a given ledger sequence.
ripple::RelationalDBInterfaceSqliteImp::lgrdb_
std::unique_ptr< DatabaseCon > lgrdb_
Definition: RelationalDBInterfaceSqlite.cpp:177
std::pair
ripple::RelationalDBInterfaceSqliteImp::deleteAccountTransactionsBeforeLedgerSeq
void deleteAccountTransactionsBeforeLedgerSeq(LedgerIndex ledgerSeq) override
deleteAccountTransactionsBeforeLedgerSeq Deletes all account transactions with given ledger sequence ...
Definition: RelationalDBInterfaceSqlite.cpp:540
ripple::LedgerMaster
Definition: LedgerMaster.h:72
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:1063
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:1190
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::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:1237
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:496
ripple::RelationalDBInterfaceSqliteImp::j_
beast::Journal j_
Definition: RelationalDBInterfaceSqlite.cpp:176
ripple::NodeStore::DatabaseShard::lastLedgerSeq
virtual std::uint32_t lastLedgerSeq(std::uint32_t shardIndex) const =0
Calculates the last ledger sequence for a given shard index.
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:438
ripple::RelationalDBInterface::AccountTxPageOptions::marker
std::optional< AccountTxMarker > marker
Definition: RelationalDBInterface.h:79
ripple::RelationalDBInterfaceSqliteImp::checkoutTransaction
auto checkoutTransaction()
checkoutTransaction Checkouts and returns node transaction DB.
Definition: RelationalDBInterfaceSqlite.cpp:261
std::function
ripple::RelationalDBInterfaceSqliteImp::txdb_
std::unique_ptr< DatabaseCon > txdb_
Definition: RelationalDBInterfaceSqlite.cpp:177
ripple::RelationalDBInterfaceSqliteImp::iterateTransactionBack
bool iterateTransactionBack(std::optional< std::uint32_t > firstIndex, std::function< bool(soci::session &session, std::uint32_t index)> const &callback)
iterateTransactionForward Checkouts transaction databases for all shards in descending order starting...
Definition: RelationalDBInterfaceSqlite.cpp:375
ripple::RelationalDBInterfaceSqliteImp::getHashByIndex
uint256 getHashByIndex(LedgerIndex ledgerIndex) override
getHashByIndex Returns hash of ledger with given sequence.
Definition: RelationalDBInterfaceSqlite.cpp:770
ripple::RelationalDBInterfaceSqliteImp::transactionDbHasSpace
bool transactionDbHasSpace(Config const &config) override
transactionDbHasSpace Checks if transaction database has available space.
Definition: RelationalDBInterfaceSqlite.cpp:1364
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:484
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:472
ripple::Application::accountIDCache
virtual AccountIDCache const & accountIDCache() const =0
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:386
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:904
ripple::RelationalDBInterface::CountMinMax
Definition: RelationalDBInterface.h:51
ripple::base_uint
Integers of any length that is a multiple of 32-bits.
Definition: base_uint.h:74
ripple::RelationalDBInterfaceSqliteImp::lastLedgerSeq
LedgerIndex lastLedgerSeq(std::uint32_t shardIndex)
lastLedgerSeq Returns last ledger sequence for given shard.
Definition: RelationalDBInterfaceSqlite.cpp:221
ripple::RelationalDBInterfaceSqliteImp::doTransaction
bool doTransaction(LedgerIndex ledgerSeq, std::function< bool(soci::session &session, std::uint32_t index)> const &callback)
doTransaction Checkouts transaction database for shard containing given ledger and calls given callba...
Definition: RelationalDBInterfaceSqlite.cpp:292
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:971
ripple::saveValidatedLedger
static bool saveValidatedLedger(Application &app, std::shared_ptr< Ledger const > const &ledger, bool current)
Definition: Ledger.cpp:916
ripple::RelationalDBInterfaceSqliteImp::getKBUsedTransaction
int getKBUsedTransaction() override
getKBUsedTransaction Returns space used by transaction database.
Definition: RelationalDBInterfaceSqlite.cpp:1417
ripple::RelationalDBInterfaceSqliteImp::deleteTransactionsBeforeLedgerSeq
void deleteTransactionsBeforeLedgerSeq(LedgerIndex ledgerSeq) override
deleteTransactionsBeforeLedgerSeq Deletes all transactions with given ledger sequence and all sequenc...
Definition: RelationalDBInterfaceSqlite.cpp:518
ripple::Application::getLedgerMaster
virtual LedgerMaster & getLedgerMaster()=0
ripple::Config
Definition: Config.h:67
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:690
ripple::RelationalDBInterfaceSqliteImp::existsLedger
bool existsLedger()
checkoutLedger Checks if node ledger DB exists.
Definition: RelationalDBInterfaceSqlite.cpp:231
ripple::RelationalDBInterfaceSqliteImp::getTransactionCount
std::size_t getTransactionCount() override
getTransactionCount Returns number of transactions.
Definition: RelationalDBInterfaceSqlite.cpp:563
ripple::saveLedgerAsync
void saveLedgerAsync(Application &app, std::uint32_t seq)
Definition: AccountTxPaging.cpp:57
ripple::RelationalDBInterfaceSqliteImp::checkoutLedger
auto checkoutLedger()
checkoutTransaction Checkouts and returns node ledger DB.
Definition: RelationalDBInterfaceSqlite.cpp:251
ripple::RelationalDBInterface::AccountTxOptions::minLedger
std::uint32_t minLedger
Definition: RelationalDBInterface.h:67
ripple::RelationalDBInterfaceSqliteImp
Definition: RelationalDBInterfaceSqlite.cpp:41
ripple::RelationalDBInterfaceSqliteImp::getLedgerInfoByHash
std::optional< LedgerInfo > getLedgerInfoByHash(uint256 const &ledgerHash) override
getLedgerInfoByHash Returns info of ledger with given hash.
Definition: RelationalDBInterfaceSqlite.cpp:746
ripple::RelationalDBInterfaceSqliteImp::getNewestLedgerInfo
std::optional< LedgerInfo > getNewestLedgerInfo() override
getNewestLedgerInfo Returns info of newest saved ledger.
Definition: RelationalDBInterfaceSqlite.cpp:666
ripple::RelationalDBInterfaceSqliteImp::getMinLedgerSeq
std::optional< LedgerIndex > getMinLedgerSeq() override
getMinLedgerSeq Returns minimum ledger sequence in Ledgers table.
Definition: RelationalDBInterfaceSqlite.cpp:399
ripple::RelationalDBInterfaceSqliteImp::deleteBeforeLedgerSeq
void deleteBeforeLedgerSeq(LedgerIndex ledgerSeq) override
deleteBeforeLedgerSeq Deletes all ledgers with given sequence and all sequences below it.
Definition: RelationalDBInterfaceSqlite.cpp:497
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::getTransaction
std::variant< AccountTx, TxSearched > getTransaction(uint256 const &id, std::optional< ClosedInterval< uint32_t >> const &range, error_code_i &ec) override
getTransaction Returns transaction with given hash.
Definition: RelationalDBInterfaceSqlite.cpp:1313
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
ripple::NodeStore::DatabaseShard::callForTransactionSQL
virtual bool callForTransactionSQL(LedgerIndex ledgerSeq, std::function< bool(soci::session &session, std::uint32_t index)> const &callback)=0
callForTransactionSQL Checkouts transaction database for shard containing given ledger and calls give...
std::map
STL class.
ripple::NodeStore::DatabaseShard::firstLedgerSeq
virtual std::uint32_t firstLedgerSeq(std::uint32_t shardIndex) const =0
Calculates the first ledger sequence for a given shard index.
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:603
ripple::TableType::Ledgers
@ Ledgers
ripple::RelationalDBInterfaceSqliteImp::iterateTransactionForward
bool iterateTransactionForward(std::optional< std::uint32_t > firstIndex, std::function< bool(soci::session &session, std::uint32_t index)> const &callback)
iterateTransactionForward Checkouts transaction databases for all shards in ascending order starting ...
Definition: RelationalDBInterfaceSqlite.cpp:333
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:718
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:210
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:1019
ripple::RelationalDBInterfaceSqliteImp::existsTransaction
bool existsTransaction()
checkoutTransaction Checks if node transaction DB exists.
Definition: RelationalDBInterfaceSqlite.cpp:241
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:838
ripple::RelationalDBInterfaceSqliteImp::getLedgerInfoByIndex
std::optional< LedgerInfo > getLedgerInfoByIndex(LedgerIndex ledgerSeq) override
getLedgerInfoByIndex Returns ledger by its sequence.
Definition: RelationalDBInterfaceSqlite.cpp:647
ripple::RelationalDBInterfaceSqliteImp::seqToShardIndex
std::uint32_t seqToShardIndex(LedgerIndex ledgerSeq)
seqToShardIndex Converts ledgers sequence to shard index.
Definition: RelationalDBInterfaceSqlite.cpp:199
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:1260
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::RelationalDBInterfaceSqliteImp::doLedger
bool doLedger(LedgerIndex ledgerSeq, std::function< bool(soci::session &session, std::uint32_t index)> const &callback)
doLedger Checkouts ledger database for shard containing given ledger and calls given callback functio...
Definition: RelationalDBInterfaceSqlite.cpp:275
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:537
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:789
ripple::RelationalDBInterfaceSqliteImp::getNewestAccountTxs
AccountTxs getNewestAccountTxs(AccountTxOptions const &options) override
getNewestAccountTxs Returns newest transactions for given account which match given criteria starting...
Definition: RelationalDBInterfaceSqlite.cpp:922
std::map::insert
T insert(T... args)
ripple::NodeStore::DatabaseShard::iterateLedgerSQLsBack
virtual bool iterateLedgerSQLsBack(std::optional< std::uint32_t > maxShardIndex, std::function< bool(soci::session &session, std::uint32_t index)> const &callback)=0
iterateLedgerSQLsBack Checkouts ledger databases for all shards in descending order starting from giv...
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::NodeStore::DatabaseShard::callForLedgerSQL
virtual bool callForLedgerSQL(LedgerIndex ledgerSeq, std::function< bool(soci::session &session, std::uint32_t index)> const &callback)=0
callForLedgerSQL Checkouts ledger database for shard containing given ledger and calls given callback...
ripple::RelationalDBInterfaceSqliteImp::app_
Application & app_
Definition: RelationalDBInterfaceSqlite.cpp:175
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:1127
ripple::RelationalDBInterfaceSqliteImp::ledgerDbHasSpace
bool ledgerDbHasSpace(Config const &config) override
ledgerDbHasSpace Checks if ledger database has available space.
Definition: RelationalDBInterfaceSqlite.cpp:1347
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:1214
ripple::RelationalDBInterfaceSqliteImp::getAccountTransactionCount
std::size_t getAccountTransactionCount() override
getAccountTransactionCount Returns number of account transactions.
Definition: RelationalDBInterfaceSqlite.cpp:583
std::optional
std::size_t
ripple::RelationalDBInterfaceSqliteImp::getMaxLedgerSeq
std::optional< LedgerIndex > getMaxLedgerSeq() override
getMaxLedgerSeq Returns maximum ledger sequence in Ledgers table.
Definition: RelationalDBInterfaceSqlite.cpp:459
std::vector::end
T end(T... args)
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:1341
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:873
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:629
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:464
ripple::RelationalDBInterfaceSqliteImp::getTransactionsMinLedgerSeq
std::optional< LedgerIndex > getTransactionsMinLedgerSeq() override
getTransactionsMinLedgerSeq Returns minimum ledger sequence among records in the Transactions table.
Definition: RelationalDBInterfaceSqlite.cpp:418
ripple::NodeStore::DatabaseShard::iterateLedgerSQLsForward
virtual bool iterateLedgerSQLsForward(std::optional< std::uint32_t > minShardIndex, std::function< bool(soci::session &session, std::uint32_t index)> const &callback)=0
iterateLedgerSQLsForward Checkouts ledger databases for all shards in ascending order starting from g...
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:44
std::ref
T ref(T... args)
std::variant
ripple::RelationalDBInterface::AccountTxs
std::vector< AccountTx > AccountTxs
Definition: RelationalDBInterface.h:86