rippled
Public Types | Public Member Functions | Static Public Member Functions | Private Member Functions | Private Attributes | List of all members
ripple::PostgresDatabaseImp Class Referencefinal
Inheritance diagram for ripple::PostgresDatabaseImp:
Inheritance graph
[legend]
Collaboration diagram for ripple::PostgresDatabaseImp:
Collaboration graph
[legend]

Public Types

using AccountTx = std::pair< std::shared_ptr< Transaction >, std::shared_ptr< TxMeta > >
 
using AccountTxs = std::vector< AccountTx >
 
using txnMetaLedgerType = std::tuple< Blob, Blob, std::uint32_t >
 
using MetaTxsList = std::vector< txnMetaLedgerType >
 
using LedgerSequence = uint32_t
 
using LedgerHash = uint256
 
using LedgerShortcut = RPC::LedgerShortcut
 
using LedgerSpecifier = std::variant< LedgerRange, LedgerShortcut, LedgerSequence, LedgerHash >
 

Public Member Functions

 PostgresDatabaseImp (Application &app, Config const &config, JobQueue &jobQueue)
 
void stop () override
 
void sweep () override
 sweep Sweeps the database. More...
 
std::optional< LedgerIndexgetMinLedgerSeq () override
 getMinLedgerSeq Returns the minimum ledger sequence in the Ledgers table. More...
 
std::optional< LedgerIndexgetMaxLedgerSeq () override
 getMaxLedgerSeq Returns the maximum ledger sequence in the Ledgers table. More...
 
std::string getCompleteLedgers () override
 getCompleteLedgers Returns a string which contains a list of completed ledgers. More...
 
std::chrono::seconds getValidatedLedgerAge () override
 getValidatedLedgerAge Returns the age of the last validated ledger. More...
 
bool writeLedgerAndTransactions (LedgerInfo const &info, std::vector< AccountTransactionsData > const &accountTxData) override
 writeLedgerAndTransactions Writes new ledger and transaction data into the database. More...
 
std::optional< LedgerInfogetLedgerInfoByIndex (LedgerIndex ledgerSeq) override
 getLedgerInfoByIndex Returns a ledger by its sequence. More...
 
std::optional< LedgerInfogetNewestLedgerInfo () override
 getNewestLedgerInfo Returns the info of the newest saved ledger. More...
 
std::optional< LedgerInfogetLedgerInfoByHash (uint256 const &ledgerHash) override
 getLedgerInfoByHash Returns the info of the ledger with given hash. More...
 
uint256 getHashByIndex (LedgerIndex ledgerIndex) override
 getHashByIndex Returns the hash of the ledger with the given sequence. More...
 
std::optional< LedgerHashPairgetHashesByIndex (LedgerIndex ledgerIndex) override
 getHashesByIndex Returns the hashes of the ledger and its parent as specified by the ledgerIndex. More...
 
std::map< LedgerIndex, LedgerHashPairgetHashesByIndex (LedgerIndex minSeq, LedgerIndex maxSeq) override
 getHashesByIndex Returns hashes of each ledger and its parent for all ledgers within the provided range. More...
 
std::vector< uint256getTxHashes (LedgerIndex seq) override
 getTxHashes Returns a vector of the hashes of transactions belonging to the ledger with the provided sequence. More...
 
std::vector< std::shared_ptr< Transaction > > getTxHistory (LedgerIndex startIndex) override
 getTxHistory Returns the 20 most recent transactions starting from the given number. More...
 
std::pair< AccountTxResult, RPC::StatusgetAccountTx (AccountTxArgs const &args) override
 getAccountTx Get the last account transactions specified by the AccountTxArgs struct. More...
 
Transaction::Locator locateTransaction (uint256 const &id) override
 locateTransaction Returns information used to locate a transaction. More...
 
bool ledgerDbHasSpace (Config const &config) override
 ledgerDbHasSpace Checks if the ledger database has available space. More...
 
bool transactionDbHasSpace (Config const &config) override
 transactionDbHasSpace Checks if the transaction database has available space. More...
 
bool isCaughtUp (std::string &reason) override
 isCaughtUp returns whether the database is caught up with the network More...
 

Static Public Member Functions

static std::unique_ptr< RelationalDatabaseinit (Application &app, Config const &config, JobQueue &jobQueue)
 init Creates and returns an appropriate RelationalDatabase instance based on configuration. More...
 

Private Member Functions

bool dbHasSpace (Config const &config)
 

Private Attributes

Applicationapp_
 
beast::Journal j_
 
std::shared_ptr< PgPool > pgPool_
 

Detailed Description

Definition at line 49 of file PostgresDatabase.cpp.

Member Typedef Documentation

◆ AccountTx

Definition at line 85 of file RelationalDatabase.h.

◆ AccountTxs

Definition at line 86 of file RelationalDatabase.h.

◆ txnMetaLedgerType

Definition at line 87 of file RelationalDatabase.h.

◆ MetaTxsList

Definition at line 88 of file RelationalDatabase.h.

◆ LedgerSequence

using ripple::RelationalDatabase::LedgerSequence = uint32_t
inherited

Definition at line 90 of file RelationalDatabase.h.

◆ LedgerHash

Definition at line 91 of file RelationalDatabase.h.

◆ LedgerShortcut

Definition at line 92 of file RelationalDatabase.h.

◆ LedgerSpecifier

Definition at line 94 of file RelationalDatabase.h.

Constructor & Destructor Documentation

◆ PostgresDatabaseImp()

ripple::PostgresDatabaseImp::PostgresDatabaseImp ( Application app,
Config const &  config,
JobQueue jobQueue 
)

Definition at line 52 of file PostgresDatabase.cpp.

Member Function Documentation

◆ stop()

void ripple::PostgresDatabaseImp::stop ( )
overridevirtual

Implements ripple::PostgresDatabase.

Definition at line 74 of file PostgresDatabase.cpp.

◆ sweep()

void ripple::PostgresDatabaseImp::sweep ( )
overridevirtual

sweep Sweeps the database.

Implements ripple::PostgresDatabase.

Definition at line 484 of file PostgresDatabase.cpp.

◆ getMinLedgerSeq()

std::optional< LedgerIndex > ripple::PostgresDatabaseImp::getMinLedgerSeq ( )
overridevirtual

getMinLedgerSeq Returns the minimum ledger sequence in the Ledgers table.

Returns
Ledger sequence or no value if no ledgers exist.

Implements ripple::RelationalDatabase.

Definition at line 492 of file PostgresDatabase.cpp.

◆ getMaxLedgerSeq()

std::optional< LedgerIndex > ripple::PostgresDatabaseImp::getMaxLedgerSeq ( )
overridevirtual

getMaxLedgerSeq Returns the maximum ledger sequence in the Ledgers table.

Returns
Ledger sequence or none if no ledgers exist.

Implements ripple::RelationalDatabase.

Definition at line 507 of file PostgresDatabase.cpp.

◆ getCompleteLedgers()

std::string ripple::PostgresDatabaseImp::getCompleteLedgers ( )
overridevirtual

getCompleteLedgers Returns a string which contains a list of completed ledgers.

Returns
String with completed ledger sequences

Implements ripple::PostgresDatabase.

Definition at line 518 of file PostgresDatabase.cpp.

◆ getValidatedLedgerAge()

std::chrono::seconds ripple::PostgresDatabaseImp::getValidatedLedgerAge ( )
overridevirtual

getValidatedLedgerAge Returns the age of the last validated ledger.

Returns
Age of the last validated ledger in seconds

Implements ripple::PostgresDatabase.

Definition at line 529 of file PostgresDatabase.cpp.

◆ writeLedgerAndTransactions()

bool ripple::PostgresDatabaseImp::writeLedgerAndTransactions ( LedgerInfo const &  info,
std::vector< AccountTransactionsData > const &  accountTxData 
)
overridevirtual

writeLedgerAndTransactions Writes new ledger and transaction data into the database.

Parameters
infoLedger info to write.
accountTxDataTransaction data to write
Returns
True on success, false on failure.

Implements ripple::PostgresDatabase.

Definition at line 543 of file PostgresDatabase.cpp.

◆ getLedgerInfoByIndex()

std::optional< LedgerInfo > ripple::PostgresDatabaseImp::getLedgerInfoByIndex ( LedgerIndex  ledgerSeq)
overridevirtual

getLedgerInfoByIndex Returns a ledger by its sequence.

Parameters
ledgerSeqLedger sequence.
Returns
The ledger if found, otherwise no value.

Implements ripple::RelationalDatabase.

Definition at line 628 of file PostgresDatabase.cpp.

◆ getNewestLedgerInfo()

std::optional< LedgerInfo > ripple::PostgresDatabaseImp::getNewestLedgerInfo ( )
overridevirtual

getNewestLedgerInfo Returns the info of the newest saved ledger.

Returns
Ledger info if found, otherwise no value.

Implements ripple::RelationalDatabase.

Definition at line 634 of file PostgresDatabase.cpp.

◆ getLedgerInfoByHash()

std::optional< LedgerInfo > ripple::PostgresDatabaseImp::getLedgerInfoByHash ( uint256 const &  ledgerHash)
overridevirtual

getLedgerInfoByHash Returns the info of the ledger with given hash.

Parameters
ledgerHashHash of the ledger.
Returns
Ledger if found, otherwise no value.

Implements ripple::RelationalDatabase.

Definition at line 640 of file PostgresDatabase.cpp.

◆ getHashByIndex()

uint256 ripple::PostgresDatabaseImp::getHashByIndex ( LedgerIndex  ledgerIndex)
overridevirtual

getHashByIndex Returns the hash of the ledger with the given sequence.

Parameters
ledgerIndexLedger sequence.
Returns
Hash of the ledger.

Implements ripple::RelationalDatabase.

Definition at line 646 of file PostgresDatabase.cpp.

◆ getHashesByIndex() [1/2]

std::optional< LedgerHashPair > ripple::PostgresDatabaseImp::getHashesByIndex ( LedgerIndex  ledgerIndex)
overridevirtual

getHashesByIndex Returns the hashes of the ledger and its parent as specified by the ledgerIndex.

Parameters
ledgerIndexLedger sequence.
Returns
Struct LedgerHashPair which contains hashes of the ledger and its parent.

Implements ripple::RelationalDatabase.

Definition at line 656 of file PostgresDatabase.cpp.

◆ getHashesByIndex() [2/2]

std::map< LedgerIndex, LedgerHashPair > ripple::PostgresDatabaseImp::getHashesByIndex ( LedgerIndex  minSeq,
LedgerIndex  maxSeq 
)
overridevirtual

getHashesByIndex Returns hashes of each ledger and its parent for all ledgers within the provided range.

Parameters
minSeqMinimum ledger sequence.
maxSeqMaximum ledger sequence.
Returns
Container that maps the sequence number of a found ledger to the struct LedgerHashPair which contains the hashes of the ledger and its parent.

Implements ripple::RelationalDatabase.

Definition at line 671 of file PostgresDatabase.cpp.

◆ getTxHashes()

std::vector< uint256 > ripple::PostgresDatabaseImp::getTxHashes ( LedgerIndex  seq)
overridevirtual

getTxHashes Returns a vector of the hashes of transactions belonging to the ledger with the provided sequence.

Parameters
seqLedger sequence
Returns
Vector of transaction hashes

Implements ripple::PostgresDatabase.

Definition at line 683 of file PostgresDatabase.cpp.

◆ getTxHistory()

std::vector< std::shared_ptr< Transaction > > ripple::PostgresDatabaseImp::getTxHistory ( LedgerIndex  startIndex)
overridevirtual

getTxHistory Returns the 20 most recent transactions starting from the given number.

Parameters
startIndexFirst number of returned entry.
Returns
Vector of shared pointers to transactions sorted in descending order by ledger sequence.

Implements ripple::RelationalDatabase.

Definition at line 753 of file PostgresDatabase.cpp.

◆ getAccountTx()

std::pair< AccountTxResult, RPC::Status > ripple::PostgresDatabaseImp::getAccountTx ( AccountTxArgs const &  args)
overridevirtual

getAccountTx Get the last account transactions specified by the AccountTxArgs struct.

Parameters
argsArguments which specify the account and which transactions to return.
Returns
Vector of account transactions and the RPC status response.

Implements ripple::PostgresDatabase.

Definition at line 844 of file PostgresDatabase.cpp.

◆ locateTransaction()

Transaction::Locator ripple::PostgresDatabaseImp::locateTransaction ( uint256 const &  id)
overridevirtual

locateTransaction Returns information used to locate a transaction.

Parameters
idHash of the transaction.
Returns
Information used to locate a transaction. Contains a nodestore hash and a ledger sequence pair if the transaction was found. Otherwise, contains the range of ledgers present in the database at the time of search.

Implements ripple::PostgresDatabase.

Definition at line 955 of file PostgresDatabase.cpp.

◆ ledgerDbHasSpace()

bool ripple::PostgresDatabaseImp::ledgerDbHasSpace ( Config const &  config)
overridevirtual

ledgerDbHasSpace Checks if the ledger database has available space.

Parameters
configConfig object.
Returns
True if space is available.

Implements ripple::RelationalDatabase.

Definition at line 1040 of file PostgresDatabase.cpp.

◆ transactionDbHasSpace()

bool ripple::PostgresDatabaseImp::transactionDbHasSpace ( Config const &  config)
overridevirtual

transactionDbHasSpace Checks if the transaction database has available space.

Parameters
configConfig object.
Returns
True if space is available.

Implements ripple::RelationalDatabase.

Definition at line 1046 of file PostgresDatabase.cpp.

◆ isCaughtUp()

bool ripple::PostgresDatabaseImp::isCaughtUp ( std::string reason)
overridevirtual

isCaughtUp returns whether the database is caught up with the network

Parameters
[out]reasonif the database is not caught up, reason contains a helpful message describing why
Returns
false if the most recently written ledger has a close time over 3 minutes ago, or if there are no ledgers in the database. true otherwise

Implements ripple::PostgresDatabase.

Definition at line 1058 of file PostgresDatabase.cpp.

◆ dbHasSpace()

bool ripple::PostgresDatabaseImp::dbHasSpace ( Config const &  config)
private

Definition at line 1032 of file PostgresDatabase.cpp.

◆ init()

std::unique_ptr< RelationalDatabase > ripple::RelationalDatabase::init ( Application app,
Config const &  config,
JobQueue jobQueue 
)
staticinherited

init Creates and returns an appropriate RelationalDatabase instance based on configuration.

Parameters
appApplication object.
configConfig object.
jobQueueJobQueue object.
Returns
Unique pointer to the interface.

Definition at line 34 of file RelationalDatabase.cpp.

Member Data Documentation

◆ app_

Application& ripple::PostgresDatabaseImp::app_
private

Definition at line 141 of file PostgresDatabase.cpp.

◆ j_

beast::Journal ripple::PostgresDatabaseImp::j_
private

Definition at line 142 of file PostgresDatabase.cpp.

◆ pgPool_

std::shared_ptr<PgPool> ripple::PostgresDatabaseImp::pgPool_
private

Definition at line 143 of file PostgresDatabase.cpp.