rippled
Node.h
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 #ifndef RIPPLE_APP_RDB_BACKEND_DETAIL_NODE_H_INCLUDED
21 #define RIPPLE_APP_RDB_BACKEND_DETAIL_NODE_H_INCLUDED
22 
23 #include <ripple/app/ledger/Ledger.h>
24 #include <ripple/app/misc/Manifest.h>
25 #include <ripple/app/rdb/RelationalDatabase.h>
26 #include <ripple/core/Config.h>
27 #include <ripple/overlay/PeerReservationTable.h>
28 #include <ripple/peerfinder/impl/Store.h>
29 #include <boost/filesystem.hpp>
30 
31 namespace ripple {
32 namespace detail {
33 
34 /* Need to change TableTypeCount if TableType is modified. */
36 constexpr int TableTypeCount = 3;
37 
39 {
42  bool valid;
43 };
44 
55  Config const& config,
56  DatabaseCon::Setup const& setup,
57  DatabaseCon::CheckpointerSetup const& checkpointerSetup);
58 
66 getMinLedgerSeq(soci::session& session, TableType type);
67 
75 getMaxLedgerSeq(soci::session& session, TableType type);
76 
84 void
86  soci::session& session,
87  TableType type,
88  LedgerIndex ledgerSeq);
89 
97 void
99  soci::session& session,
100  TableType type,
101  LedgerIndex ledgerSeq);
102 
110 getRows(soci::session& session, TableType type);
111 
121 getRowsMinMax(soci::session& session, TableType type);
122 
132 bool
134  DatabaseCon& ldgDB,
135  DatabaseCon& txnDB,
136  Application& app,
137  std::shared_ptr<Ledger const> const& ledger,
138  bool current);
139 
149  soci::session& session,
150  LedgerIndex ledgerSeq,
151  beast::Journal j);
152 
160 getNewestLedgerInfo(soci::session& session, beast::Journal j);
161 
172  soci::session& session,
173  LedgerIndex ledgerFirstIndex,
174  beast::Journal j);
175 
186  soci::session& session,
187  LedgerIndex ledgerFirstIndex,
188  beast::Journal j);
189 
199  soci::session& session,
200  uint256 const& ledgerHash,
201  beast::Journal j);
202 
209 uint256
210 getHashByIndex(soci::session& session, LedgerIndex ledgerIndex);
211 
223  soci::session& session,
224  LedgerIndex ledgerIndex,
225  beast::Journal j);
226 
240  soci::session& session,
241  LedgerIndex minSeq,
242  LedgerIndex maxSeq,
243  beast::Journal j);
244 
259  soci::session& session,
260  Application& app,
261  LedgerIndex startIndex,
262  int quantity,
263  bool count);
264 
289  soci::session& session,
290  Application& app,
291  LedgerMaster& ledgerMaster,
293  std::optional<int> const& limit_used,
294  beast::Journal j);
295 
320  soci::session& session,
321  Application& app,
322  LedgerMaster& ledgerMaster,
324  std::optional<int> const& limit_used,
325  beast::Journal j);
326 
351  soci::session& session,
352  Application& app,
354  std::optional<int> const& limit_used,
355  beast::Journal j);
356 
381  soci::session& session,
382  Application& app,
384  std::optional<int> const& limit_used,
385  beast::Journal j);
386 
409  soci::session& session,
410  std::function<void(std::uint32_t)> const& onUnsavedLedger,
412  void(std::uint32_t, std::string const&, Blob&&, Blob&&)> const&
413  onTransaction,
415  int limit_used,
416  std::uint32_t page_length);
417 
440  soci::session& session,
441  std::function<void(std::uint32_t)> const& onUnsavedLedger,
443  void(std::uint32_t, std::string const&, Blob&&, Blob&&)> const&
444  onTransaction,
446  int limit_used,
447  std::uint32_t page_length);
448 
467  soci::session& session,
468  Application& app,
469  uint256 const& id,
471  error_code_i& ec);
472 
480 bool
481 dbHasSpace(soci::session& session, Config const& config, beast::Journal j);
482 
483 } // namespace detail
484 } // namespace ripple
485 
486 #endif
ripple::detail::deleteByLedgerSeq
void deleteByLedgerSeq(soci::session &session, TableType type, LedgerIndex ledgerSeq)
deleteByLedgerSeq Deletes all entries in given table for the ledger with given sequence.
Definition: Node.cpp:143
ripple::Application
Definition: Application.h:115
ripple::detail::TableType::Ledgers
@ Ledgers
ripple::detail::getNewestLedgerInfo
std::optional< LedgerInfo > getNewestLedgerInfo(soci::session &session, beast::Journal j)
getNewestLedgerInfo Returns info of newest saved ledger.
Definition: Node.cpp:467
ripple::detail::newestAccountTxPage
std::pair< std::optional< RelationalDatabase::AccountTxMarker >, int > newestAccountTxPage(soci::session &session, std::function< void(std::uint32_t)> const &onUnsavedLedger, std::function< void(std::uint32_t, std::string const &, Blob &&, Blob &&)> const &onTransaction, RelationalDatabase::AccountTxPageOptions const &options, int limit_used, std::uint32_t page_length)
newestAccountTxPage Searches newest transactions for given account which match given criteria startin...
Definition: Node.cpp:1245
ripple::detail::dbHasSpace
bool dbHasSpace(soci::session &session, Config const &config, beast::Journal j)
dbHasSpace Checks if given database has available space.
Definition: Node.cpp:1347
std::string
STL class.
std::shared_ptr
STL class.
ripple::detail::TableType
TableType
Definition: Node.h:35
ripple::DatabaseCon::Setup
Definition: DatabaseCon.h:84
ripple::detail::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: Node.cpp:150
std::pair
ripple::LedgerMaster
Definition: LedgerMaster.h:70
std::vector
STL class.
ripple::detail::getRowsMinMax
RelationalDatabase::CountMinMax getRowsMinMax(soci::session &session, TableType type)
getRowsMinMax Returns minimum ledger sequence, maximum ledger sequence and total number of rows in gi...
Definition: Node.cpp:172
ripple::detail::getNewestAccountTxsB
std::pair< std::vector< RelationalDatabase::txnMetaLedgerType >, int > getNewestAccountTxsB(soci::session &session, Application &app, RelationalDatabase::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: Node.cpp:1031
ripple::DatabaseCon::CheckpointerSetup
Definition: DatabaseCon.h:107
ripple::detail::TableType::Transactions
@ Transactions
ripple::RelationalDatabase::AccountTxOptions
Definition: RelationalDatabase.h:64
std::function
ripple::detail::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: Node.cpp:475
ripple::detail::getHashByIndex
uint256 getHashByIndex(soci::session &session, LedgerIndex ledgerIndex)
getHashByIndex Returns hash of ledger with given sequence.
Definition: Node.cpp:510
ripple::detail::getLedgerInfoByHash
std::optional< LedgerInfo > getLedgerInfoByHash(soci::session &session, uint256 const &ledgerHash, beast::Journal j)
getLedgerInfoByHash Returns info of ledger with given hash.
Definition: Node.cpp:499
ripple::error_code_i
error_code_i
Definition: ErrorCodes.h:40
ripple::detail::getTransaction
std::variant< RelationalDatabase::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: Node.cpp:1266
ripple::detail::DatabasePairValid
Definition: Node.h:38
ripple::detail::saveValidatedLedger
bool saveValidatedLedger(DatabaseCon &ldgDB, DatabaseCon &txnDB, Application &app, std::shared_ptr< Ledger const > const &ledger, bool current)
saveValidatedLedger Saves ledger into database.
Definition: Node.cpp:187
ripple::detail::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: Node.cpp:487
ripple::RelationalDatabase::CountMinMax
Definition: RelationalDatabase.h:51
ripple::base_uint< 256 >
ripple::detail::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: Node.cpp:616
ripple::detail::DatabasePairValid::transactionDb
std::unique_ptr< DatabaseCon > transactionDb
Definition: Node.h:41
ripple::detail::DatabasePairValid::ledgerDb
std::unique_ptr< DatabaseCon > ledgerDb
Definition: Node.h:40
ripple::Config
Definition: Config.h:89
ripple::detail::makeLedgerDBs
DatabasePairValid makeLedgerDBs(Config const &config, DatabaseCon::Setup const &setup, DatabaseCon::CheckpointerSetup const &checkpointerSetup)
makeLedgerDBs Opens ledger and transactions databases.
Definition: Node.cpp:67
beast::Journal
A generic endpoint for log messages.
Definition: Journal.h:58
std::uint32_t
ripple::detail::oldestAccountTxPage
std::pair< std::optional< RelationalDatabase::AccountTxMarker >, int > oldestAccountTxPage(soci::session &session, std::function< void(std::uint32_t)> const &onUnsavedLedger, std::function< void(std::uint32_t, std::string const &, Blob &&, Blob &&)> const &onTransaction, RelationalDatabase::AccountTxPageOptions const &options, int limit_used, std::uint32_t page_length)
oldestAccountTxPage Searches oldest transactions for given account which match given criteria startin...
Definition: Node.cpp:1224
std::map
STL class.
ripple::range
ClosedInterval< T > range(T low, T high)
Create a closed range interval.
Definition: RangeSet.h:53
ripple::detail::getRows
std::size_t getRows(soci::session &session, TableType type)
getRows Returns number of rows in given table.
Definition: Node.cpp:160
ripple::detail::getOldestAccountTxsB
std::pair< std::vector< RelationalDatabase::txnMetaLedgerType >, int > getOldestAccountTxsB(soci::session &session, Application &app, RelationalDatabase::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: Node.cpp:1020
ripple::detail::DatabasePairValid::valid
bool valid
Definition: Node.h:42
ripple::detail::getLedgerInfoByIndex
std::optional< LedgerInfo > getLedgerInfoByIndex(soci::session &session, LedgerIndex ledgerSeq, beast::Journal j)
getLedgerInfoByIndex Returns ledger by its sequence.
Definition: Node.cpp:456
ripple
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition: RCLCensorshipDetector.h:29
ripple::detail::getMinLedgerSeq
std::optional< LedgerIndex > getMinLedgerSeq(soci::session &session, TableType type)
getMinLedgerSeq Returns minimum ledger sequence in given table.
Definition: Node.cpp:123
ripple::detail::TableTypeCount
constexpr int TableTypeCount
Definition: Node.h:36
ripple::detail::TableType::AccountTransactions
@ AccountTransactions
ripple::DatabaseCon
Definition: DatabaseCon.h:81
std::optional
std::size_t
ripple::ClosedInterval
boost::icl::closed_interval< T > ClosedInterval
A closed interval over the domain T.
Definition: RangeSet.h:44
ripple::detail::getOldestAccountTxs
std::pair< RelationalDatabase::AccountTxs, int > getOldestAccountTxs(soci::session &session, Application &app, LedgerMaster &ledgerMaster, RelationalDatabase::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: Node.cpp:899
ripple::detail::getMaxLedgerSeq
std::optional< LedgerIndex > getMaxLedgerSeq(soci::session &session, TableType type)
getMaxLedgerSeq Returns maximum ledger sequence in given table.
Definition: Node.cpp:133
std::unique_ptr
STL class.
ripple::detail::getNewestAccountTxs
std::pair< RelationalDatabase::AccountTxs, int > getNewestAccountTxs(soci::session &session, Application &app, LedgerMaster &ledgerMaster, RelationalDatabase::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: Node.cpp:912
ripple::detail::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: Node.cpp:540
ripple::RelationalDatabase::AccountTxPageOptions
Definition: RelationalDatabase.h:74
std::variant