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/main/Application.h>
25 #include <ripple/app/misc/Manifest.h>
26 #include <ripple/app/misc/impl/AccountTxPaging.h>
27 #include <ripple/app/rdb/RelationalDBInterface_nodes.h>
28 #include <ripple/app/rdb/RelationalDBInterface_postgres.h>
29 #include <ripple/app/rdb/backend/RelationalDBInterfacePostgres.h>
30 #include <ripple/basics/BasicConfig.h>
31 #include <ripple/basics/StringUtilities.h>
32 #include <ripple/core/DatabaseCon.h>
33 #include <ripple/core/Pg.h>
34 #include <ripple/core/SociDB.h>
35 #include <ripple/json/to_string.h>
36 #include <ripple/nodestore/DatabaseShard.h>
37 #include <boost/algorithm/string.hpp>
38 #include <boost/range/adaptor/transformed.hpp>
39 #include <soci/sqlite3/soci-sqlite3.h>
51 ,
j_(
app_.journal(
"PgPool"))
53 #ifdef RIPPLED_REPORTING
54 make_PgPool(config.section(
"ledger_tx_tables"),
j_)
59 #ifdef RIPPLED_REPORTING
70 #ifdef RIPPLED_REPORTING
146 #ifdef RIPPLED_REPORTING
275 return std::make_unique<RelationalDBInterfacePostgresImp>(
276 app, config, jobQueue);
281 #ifdef RIPPLED_REPORTING
282 using namespace std::chrono_literals;
283 auto age = PgQuery(
pgPool_)(
"SELECT age()");
284 if (!age || age.isNull())
286 reason =
"No ledgers in database";
291 reason =
"No recently-published ledger";
Transaction::Locator locateTransaction(uint256 const &id) override
locateTransaction Returns information used to locate a transaction.
std::optional< LedgerInfo > getLedgerInfoByIndex(soci::session &session, LedgerIndex ledgerSeq, beast::Journal j)
getLedgerInfoByIndex Returns ledger by its sequence.
bool ledgerDbHasSpace(Config const &config) override
ledgerDbHasSpace Checks if ledger database has available space.
bool dbHasSpace(Config const &config)
std::pair< AccountTxResult, RPC::Status > getAccountTx(std::shared_ptr< PgPool > const &pgPool, AccountTxArgs const &args, Application &app, beast::Journal j)
getAccountTx Get last account transactions specifies by passed argumenrs structure.
std::pair< std::vector< std::shared_ptr< Transaction > >, int > getTxHistory(soci::session &session, Application &app, LedgerIndex startIndex, int quantity, bool count)
getTxHistory Returns given number of most recent transactions starting from given number of entry.
uint256 getHashByIndex(soci::session &session, LedgerIndex ledgerIndex)
getHashByIndex Returns hash of ledger with given sequence.
std::optional< LedgerInfo > getNewestLedgerInfo() override
getNewestLedgerInfo Returns info of newest saved ledger.
RelationalDBInterfacePostgresImp(Application &app, Config const &config, JobQueue &jobQueue)
std::optional< LedgerInfo > getLedgerInfoByHash(soci::session &session, uint256 const &ledgerHash, beast::Journal j)
getLedgerInfoByHash Returns info of ledger with given hash.
Transaction::Locator locateTransaction(std::shared_ptr< PgPool > const &pgPool, uint256 const &id, Application &app)
locateTransaction Returns information used to locate a transaction.
std::pair< AccountTxResult, RPC::Status > getAccountTx(AccountTxArgs const &args) override
getAccountTx Get last account transactions specifies by passed argumenrs structure.
std::unique_ptr< RelationalDBInterface > getRelationalDBInterfacePostgres(Application &app, Config const &config, JobQueue &jobQueue)
std::string getCompleteLedgers(std::shared_ptr< PgPool > const &pgPool)
getCompleteLedgers Returns string which contains list of completed ledgers
std::vector< std::shared_ptr< Transaction > > getTxHistory(LedgerIndex startIndex) override
getTxHistory Returns most recent 20 transactions starting from given number or entry.
Integers of any length that is a multiple of 32-bits.
bool writeLedgerAndTransactions(std::shared_ptr< PgPool > const &pgPool, LedgerInfo const &info, std::vector< AccountTransactionsData > const &accountTxData, beast::Journal &j)
writeLedgerAndTransactions Write new ledger and transaction data to Postgres.
std::chrono::seconds getValidatedLedgerAge(std::shared_ptr< PgPool > const &pgPool, beast::Journal j)
getValidatedLedgerAge Returns age of last validated ledger
void stop() override
There is only one implementation of this interface: RelationalDBInterfacePostgresImp.
A generic endpoint for log messages.
std::optional< LedgerInfo > getLedgerInfoByHash(uint256 const &ledgerHash) override
std::vector< uint256 > getTxHashes(LedgerIndex seq) override
getTxHashes Returns vector of tx hashes by given ledger sequence.
std::optional< LedgerIndex > getMaxLedgerSeq() override
getMaxLedgerSeq Returns maximum ledger sequence in Ledgers table.
A pool of threads to perform work.
std::chrono::seconds getValidatedLedgerAge() override
getValidatedLedgerAge Returns age of last validated ledger.
std::string getCompleteLedgers() override
getCompleteLedgers Returns string which contains list of completed ledgers.
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
void sweep() override
sweep Sweep the database.
std::optional< LedgerInfo > getLedgerInfoByIndex(LedgerIndex ledgerSeq) override
getLedgerInfoByIndex Returns ledger by its sequence.
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...
bool transactionDbHasSpace(Config const &config) override
transactionDbHasSpace Checks if transaction database has available space.
bool isCaughtUp(std::string &reason) override
isCaughtUp returns whether the database is caught up with the network
Information about the notional ledger backing the view.
bool reportingReadOnly() const
std::optional< LedgerIndex > getMinLedgerSeq(soci::session &session, TableType type)
getMinLedgerSeq Returns minimum ledger sequence in given table.
std::optional< LedgerHashPair > getHashesByIndex(LedgerIndex ledgerIndex) override
getHashesByIndex Returns hash of the ledger and hash of parent ledger for the ledger of given sequenc...
std::optional< LedgerInfo > getNewestLedgerInfo(soci::session &session, beast::Journal j)
getNewestLedgerInfo Returns info of newest saved ledger.
bool writeLedgerAndTransactions(LedgerInfo const &info, std::vector< AccountTransactionsData > const &accountTxData) override
writeLedgerAndTransactions Write new ledger and transaction data into database.
std::optional< LedgerIndex > getMaxLedgerSeq(soci::session &session, TableType type)
getMaxLedgerSeq Returns maximum ledger sequence in given table.
uint256 getHashByIndex(LedgerIndex ledgerIndex) override
getHashByIndex Returns hash of ledger with given sequence.
std::shared_ptr< PgPool > pgPool_
std::optional< LedgerIndex > getMinLedgerSeq() override
getMinLedgerSeq Returns minimum ledger sequence in Ledgers table.
std::vector< uint256 > getTxHashes(std::shared_ptr< PgPool > const &pgPool, LedgerIndex seq, Application &app)
getTxHashes Returns vector of tx hashes by given ledger sequence