rippled
RelationalDBInterface.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_CORE_RELATIONALDBINTERFACE_H_INCLUDED
21 #define RIPPLE_CORE_RELATIONALDBINTERFACE_H_INCLUDED
22 
23 #include <ripple/app/ledger/Ledger.h>
24 #include <ripple/app/main/Application.h>
25 #include <ripple/app/misc/Transaction.h>
26 #include <ripple/core/Config.h>
27 #include <ripple/core/DatabaseCon.h>
28 #include <ripple/peerfinder/impl/Store.h>
29 #include <ripple/rpc/impl/RPCHelpers.h>
30 #include <boost/filesystem.hpp>
31 #include <boost/optional.hpp>
32 #include <boost/variant.hpp>
33 
34 namespace ripple {
35 
37 {
40 };
41 
43 {
44  uint32_t min;
45  uint32_t max;
46 };
47 
49 {
50 public:
51  struct CountMinMax
52  {
56  };
57 
59  {
62  };
63 
65  {
71  bool bUnlimited;
72  };
73 
75  {
81  bool bAdmin;
82  };
83 
84  using AccountTx =
89 
90  using LedgerSequence = uint32_t;
93  using LedgerSpecifier =
95 
97  {
100  bool binary = false;
101  bool forward = false;
102  uint32_t limit = 0;
104  };
105 
107  {
110  uint32_t limit;
112  };
113 
117  {
118  boost::container::flat_set<AccountID> accounts;
119  uint32_t ledgerSequence;
123 
125  TxMeta const& meta,
126  uint256 const& nodestoreHash,
127  beast::Journal j)
128  : accounts(meta.getAffectedAccounts(j))
129  , ledgerSequence(meta.getLgrSeq())
130  , transactionIndex(meta.getIndex())
131  , txHash(meta.getTxID())
133  {
134  }
135  };
136 
145  init(Application& app, Config const& config, JobQueue& jobQueue);
146 
147  virtual ~RelationalDBInterface() = default;
148 
154  getMinLedgerSeq() = 0;
155 
161  getMaxLedgerSeq() = 0;
162 
169  getLedgerInfoByIndex(LedgerIndex ledgerSeq) = 0;
170 
176  getNewestLedgerInfo() = 0;
177 
184  getLedgerInfoByHash(uint256 const& ledgerHash) = 0;
185 
191  virtual uint256
192  getHashByIndex(LedgerIndex ledgerIndex) = 0;
193 
202  getHashesByIndex(LedgerIndex ledgerIndex) = 0;
203 
214  getHashesByIndex(LedgerIndex minSeq, LedgerIndex maxSeq) = 0;
215 
224  getTxHistory(LedgerIndex startIndex) = 0;
225 
231  virtual bool
232  ledgerDbHasSpace(Config const& config) = 0;
233 
240  virtual bool
241  transactionDbHasSpace(Config const& config) = 0;
242 };
243 
244 template <class T, class C>
245 T
247 {
248  if ((c > std::numeric_limits<T>::max()) ||
249  (!std::numeric_limits<T>::is_signed && c < 0) ||
253  {
254  /* This should never happen */
255  assert(0);
256  JLOG(debugLog().error())
257  << "rangeCheckedCast domain error:"
258  << " value = " << c << " min = " << std::numeric_limits<T>::lowest()
259  << " max: " << std::numeric_limits<T>::max();
260  }
261 
262  return static_cast<T>(c);
263 }
264 
265 } // namespace ripple
266 
267 #endif
ripple::RelationalDBInterface::LedgerSequence
uint32_t LedgerSequence
Definition: RelationalDBInterface.h:90
ripple::Application
Definition: Application.h:115
ripple::RelationalDBInterface::AccountTransactionsData::accounts
boost::container::flat_set< AccountID > accounts
Definition: RelationalDBInterface.h:118
ripple::RelationalDBInterface::AccountTxArgs
Definition: RelationalDBInterface.h:96
std::shared_ptr
STL class.
ripple::RelationalDBInterface::AccountTransactionsData::txHash
uint256 txHash
Definition: RelationalDBInterface.h:121
std::pair
ripple::RPC::LedgerShortcut
LedgerShortcut
Definition: RPCHelpers.h:109
ripple::rangeCheckedCast
T rangeCheckedCast(C c)
Definition: RelationalDBInterface.h:246
ripple::RelationalDBInterface::AccountTxOptions::maxLedger
std::uint32_t maxLedger
Definition: RelationalDBInterface.h:68
ripple::RelationalDBInterface::AccountTransactionsData
Struct used to keep track of what to write to transactions and account_transactions tables in Postgre...
Definition: RelationalDBInterface.h:116
ripple::RelationalDBInterface::AccountTransactionsData::ledgerSequence
uint32_t ledgerSequence
Definition: RelationalDBInterface.h:119
std::vector
STL class.
ripple::RelationalDBInterface::AccountTxResult
Definition: RelationalDBInterface.h:106
ripple::RelationalDBInterface::AccountTxArgs::marker
std::optional< AccountTxMarker > marker
Definition: RelationalDBInterface.h:103
std::tuple
ripple::RelationalDBInterface::getHashByIndex
virtual uint256 getHashByIndex(LedgerIndex ledgerIndex)=0
getHashByIndex Returns hash of ledger with given sequence.
ripple::RelationalDBInterface::AccountTxPageOptions::marker
std::optional< AccountTxMarker > marker
Definition: RelationalDBInterface.h:79
ripple::RelationalDBInterface::AccountTxOptions::bUnlimited
bool bUnlimited
Definition: RelationalDBInterface.h:71
ripple::RelationalDBInterface::AccountTxArgs::ledger
std::optional< LedgerSpecifier > ledger
Definition: RelationalDBInterface.h:99
ripple::RelationalDBInterface
Definition: RelationalDBInterface.h:48
ripple::RelationalDBInterface::AccountTxPageOptions::limit
std::uint32_t limit
Definition: RelationalDBInterface.h:80
ripple::RelationalDBInterface::init
static std::unique_ptr< RelationalDBInterface > init(Application &app, Config const &config, JobQueue &jobQueue)
init Creates and returns appropriate interface based on config.
Definition: RelationalDBInterface.cpp:40
ripple::debugLog
beast::Journal debugLog()
Returns a debug journal.
Definition: Log.cpp:452
ripple::RelationalDBInterface::getMinLedgerSeq
virtual std::optional< LedgerIndex > getMinLedgerSeq()=0
getMinLedgerSeq Returns minimum ledger sequence in Ledgers table.
ripple::RelationalDBInterface::AccountTxArgs::binary
bool binary
Definition: RelationalDBInterface.h:100
std::numeric_limits::lowest
T lowest(T... args)
ripple::uint256
base_uint< 256 > uint256
Definition: base_uint.h:529
ripple::TxMeta
Definition: TxMeta.h:32
ripple::RelationalDBInterface::AccountTxOptions::offset
std::uint32_t offset
Definition: RelationalDBInterface.h:69
ripple::RelationalDBInterface::CountMinMax
Definition: RelationalDBInterface.h:51
ripple::RelationalDBInterface::AccountTxMarker::txnSeq
std::uint32_t txnSeq
Definition: RelationalDBInterface.h:61
ripple::RelationalDBInterface::AccountTxResult::transactions
std::variant< AccountTxs, MetaTxsList > transactions
Definition: RelationalDBInterface.h:108
ripple::base_uint< 256 >
ripple::RelationalDBInterface::getTxHistory
virtual std::vector< std::shared_ptr< Transaction > > getTxHistory(LedgerIndex startIndex)=0
getTxHistory Returns most recent 20 transactions starting from given number or entry.
ripple::RelationalDBInterface::AccountTxPageOptions::account
AccountID const & account
Definition: RelationalDBInterface.h:76
ripple::RelationalDBInterface::AccountTxResult::ledgerRange
LedgerRange ledgerRange
Definition: RelationalDBInterface.h:109
ripple::RelationalDBInterface::getMaxLedgerSeq
virtual std::optional< LedgerIndex > getMaxLedgerSeq()=0
getMaxLedgerSeq Returns maximum ledger sequence in Ledgers table.
ripple::RelationalDBInterface::getLedgerInfoByIndex
virtual std::optional< LedgerInfo > getLedgerInfoByIndex(LedgerIndex ledgerSeq)=0
getLedgerInfoByIndex Returns ledger by its sequence.
ripple::LedgerHashPair::ledgerHash
uint256 ledgerHash
Definition: RelationalDBInterface.h:38
ripple::RelationalDBInterface::transactionDbHasSpace
virtual bool transactionDbHasSpace(Config const &config)=0
transactionDbHasSpace Checks if transaction database has available space.
ripple::Config
Definition: Config.h:68
ripple::RelationalDBInterface::getLedgerInfoByHash
virtual std::optional< LedgerInfo > getLedgerInfoByHash(uint256 const &ledgerHash)=0
getLedgerInfoByHash Returns info of ledger with given hash.
ripple::LedgerHashPair
Definition: RelationalDBInterface.h:36
ripple::RelationalDBInterface::AccountTransactionsData::nodestoreHash
uint256 nodestoreHash
Definition: RelationalDBInterface.h:122
ripple::RelationalDBInterface::AccountTxOptions::minLedger
std::uint32_t minLedger
Definition: RelationalDBInterface.h:67
ripple::RelationalDBInterface::AccountTxOptions::account
AccountID const & account
Definition: RelationalDBInterface.h:66
ripple::RelationalDBInterface::AccountTransactionsData::transactionIndex
uint32_t transactionIndex
Definition: RelationalDBInterface.h:120
ripple::RelationalDBInterface::AccountTxMarker::ledgerSeq
std::uint32_t ledgerSeq
Definition: RelationalDBInterface.h:60
beast::Journal
A generic endpoint for log messages.
Definition: Journal.h:58
std::uint32_t
std::map
STL class.
ripple::RelationalDBInterface::AccountTxOptions::limit
std::uint32_t limit
Definition: RelationalDBInterface.h:70
ripple::RelationalDBInterface::AccountTxPageOptions::maxLedger
std::uint32_t maxLedger
Definition: RelationalDBInterface.h:78
ripple::RelationalDBInterface::~RelationalDBInterface
virtual ~RelationalDBInterface()=default
ripple::RelationalDBInterface::CountMinMax::maxLedgerSequence
LedgerIndex maxLedgerSequence
Definition: RelationalDBInterface.h:55
ripple::RelationalDBInterface::AccountTxPageOptions::minLedger
std::uint32_t minLedger
Definition: RelationalDBInterface.h:77
ripple::JobQueue
A pool of threads to perform work.
Definition: JobQueue.h:55
ripple::RelationalDBInterface::AccountTxArgs::limit
uint32_t limit
Definition: RelationalDBInterface.h:102
ripple
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition: RCLCensorshipDetector.h:29
ripple::RelationalDBInterface::AccountTxArgs::account
AccountID account
Definition: RelationalDBInterface.h:98
ripple::RelationalDBInterface::AccountTxPageOptions::bAdmin
bool bAdmin
Definition: RelationalDBInterface.h:81
ripple::RelationalDBInterface::CountMinMax::minLedgerSequence
LedgerIndex minLedgerSequence
Definition: RelationalDBInterface.h:54
ripple::LedgerRange::max
uint32_t max
Definition: RelationalDBInterface.h:45
ripple::RelationalDBInterface::AccountTransactionsData::AccountTransactionsData
AccountTransactionsData(TxMeta const &meta, uint256 const &nodestoreHash, beast::Journal j)
Definition: RelationalDBInterface.h:124
ripple::RelationalDBInterface::AccountTxResult::limit
uint32_t limit
Definition: RelationalDBInterface.h:110
ripple::LedgerHashPair::parentHash
uint256 parentHash
Definition: RelationalDBInterface.h:39
ripple::RelationalDBInterface::AccountTxResult::marker
std::optional< AccountTxMarker > marker
Definition: RelationalDBInterface.h:111
ripple::RelationalDBInterface::getNewestLedgerInfo
virtual std::optional< LedgerInfo > getNewestLedgerInfo()=0
getNewestLedgerInfo Returns info of newest saved ledger.
std::optional
std::size_t
ripple::RelationalDBInterface::AccountTxPageOptions
Definition: RelationalDBInterface.h:74
ripple::RelationalDBInterface::ledgerDbHasSpace
virtual bool ledgerDbHasSpace(Config const &config)=0
ledgerDbHasSpace Checks if ledger database has available space.
ripple::RelationalDBInterface::CountMinMax::numberOfRows
std::size_t numberOfRows
Definition: RelationalDBInterface.h:53
ripple::LedgerRange
Definition: RelationalDBInterface.h:42
std::numeric_limits::max
T max(T... args)
ripple::RelationalDBInterface::getHashesByIndex
virtual std::optional< LedgerHashPair > getHashesByIndex(LedgerIndex ledgerIndex)=0
getHashesByIndex Returns hash of the ledger and hash of parent ledger for the ledger of given sequenc...
ripple::RelationalDBInterface::AccountTxArgs::forward
bool forward
Definition: RelationalDBInterface.h:101
ripple::RelationalDBInterface::AccountTxMarker
Definition: RelationalDBInterface.h:58
ripple::LedgerRange::min
uint32_t min
Definition: RelationalDBInterface.h:44
std::unique_ptr
STL class.
ripple::RelationalDBInterface::AccountTxOptions
Definition: RelationalDBInterface.h:64
std::numeric_limits
std::variant