rippled
Public Types | Public Member Functions | Static Public Member Functions | Private Member Functions | Private Attributes | List of all members
ripple::RelationalDBInterfacePostgresImp Class Referenceabstract
Inheritance diagram for ripple::RelationalDBInterfacePostgresImp:
Inheritance graph
[legend]
Collaboration diagram for ripple::RelationalDBInterfacePostgresImp:
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

 RelationalDBInterfacePostgresImp (Application &app, Config const &config, JobQueue &jobQueue)
 
void stop () override
 There is only one implementation of this interface: RelationalDBInterfacePostgresImp. More...
 
void sweep () override
 sweep Sweep the database. More...
 
std::optional< LedgerIndexgetMinLedgerSeq () override
 getMinLedgerSeq Returns minimum ledger sequence in Ledgers table. More...
 
std::optional< LedgerIndexgetMaxLedgerSeq () override
 getMaxLedgerSeq Returns maximum ledger sequence in Ledgers table. More...
 
std::string getCompleteLedgers () override
 getCompleteLedgers Returns string which contains list of completed ledgers. More...
 
std::chrono::seconds getValidatedLedgerAge () override
 getValidatedLedgerAge Returns age of last validated ledger. More...
 
bool writeLedgerAndTransactions (LedgerInfo const &info, std::vector< AccountTransactionsData > const &accountTxData) override
 writeLedgerAndTransactions Write new ledger and transaction data into database. More...
 
std::optional< LedgerInfogetLedgerInfoByIndex (LedgerIndex ledgerSeq) override
 getLedgerInfoByIndex Returns ledger by its sequence. More...
 
std::optional< LedgerInfogetNewestLedgerInfo () override
 getNewestLedgerInfo Returns info of newest saved ledger. More...
 
std::optional< LedgerInfogetLedgerInfoByHash (uint256 const &ledgerHash) override
 
uint256 getHashByIndex (LedgerIndex ledgerIndex) override
 getHashByIndex Returns hash of ledger with given sequence. More...
 
std::optional< LedgerHashPairgetHashesByIndex (LedgerIndex ledgerIndex) override
 getHashesByIndex Returns hash of the ledger and hash of parent ledger for the ledger of given sequence. More...
 
std::map< LedgerIndex, LedgerHashPairgetHashesByIndex (LedgerIndex minSeq, LedgerIndex maxSeq) override
 getHashesByIndex Returns hash of the ledger and hash of parent ledger for all ledgers with sequences from given minimum limit to given maximum limit. More...
 
std::vector< uint256getTxHashes (LedgerIndex seq) override
 getTxHashes Returns vector of tx hashes by given ledger sequence. More...
 
std::vector< std::shared_ptr< Transaction > > getTxHistory (LedgerIndex startIndex) override
 getTxHistory Returns most recent 20 transactions starting from given number or entry. More...
 
std::pair< AccountTxResult, RPC::StatusgetAccountTx (AccountTxArgs const &args) override
 getAccountTx Get last account transactions specifies by passed argumenrs structure. 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 ledger database has available space. More...
 
bool transactionDbHasSpace (Config const &config) override
 transactionDbHasSpace Checks if transaction database has available space. More...
 
bool isCaughtUp (std::string &reason) override
 isCaughtUp returns whether the database is caught up with the network More...
 
virtual std::optional< LedgerInfogetLedgerInfoByHash (uint256 const &ledgerHash)=0
 getLedgerInfoByHash Returns info of ledger with given hash. More...
 

Static Public Member Functions

static std::unique_ptr< RelationalDBInterfaceinit (Application &app, Config const &config, JobQueue &jobQueue)
 init Creates and returns appropriate interface based on config. 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 43 of file RelationalDBInterfacePostgres.cpp.

Member Typedef Documentation

◆ AccountTx

Definition at line 85 of file RelationalDBInterface.h.

◆ AccountTxs

Definition at line 86 of file RelationalDBInterface.h.

◆ txnMetaLedgerType

Definition at line 87 of file RelationalDBInterface.h.

◆ MetaTxsList

Definition at line 88 of file RelationalDBInterface.h.

◆ LedgerSequence

Definition at line 90 of file RelationalDBInterface.h.

◆ LedgerHash

Definition at line 91 of file RelationalDBInterface.h.

◆ LedgerShortcut

Definition at line 92 of file RelationalDBInterface.h.

◆ LedgerSpecifier

Definition at line 94 of file RelationalDBInterface.h.

Constructor & Destructor Documentation

◆ RelationalDBInterfacePostgresImp()

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

Definition at line 46 of file RelationalDBInterfacePostgres.cpp.

Member Function Documentation

◆ stop()

void ripple::RelationalDBInterfacePostgresImp::stop ( )
overridevirtual

There is only one implementation of this interface: RelationalDBInterfacePostgresImp.

It wraps a stoppable object (PgPool) that does not follow RAII, and it does not go through the effort of following RAII either. The owner of the only object of that type (ApplicationImp) holds it by the type of its interface instead of its implementation, and thus the lifetime management methods need to be part of the interface.

Implements ripple::RelationalDBInterfacePostgres.

Definition at line 68 of file RelationalDBInterfacePostgres.cpp.

◆ sweep()

void ripple::RelationalDBInterfacePostgresImp::sweep ( )
overridevirtual

sweep Sweep the database.

Method is specific for postgres backend.

Implements ripple::RelationalDBInterfacePostgres.

Definition at line 144 of file RelationalDBInterfacePostgres.cpp.

◆ getMinLedgerSeq()

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

getMinLedgerSeq Returns minimum ledger sequence in Ledgers table.

Returns
Ledger sequence or none if no ledgers exist.

Implements ripple::RelationalDBInterface.

Definition at line 152 of file RelationalDBInterfacePostgres.cpp.

◆ getMaxLedgerSeq()

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

getMaxLedgerSeq Returns maximum ledger sequence in Ledgers table.

Returns
Ledger sequence or none if no ledgers exist.

Implements ripple::RelationalDBInterface.

Definition at line 158 of file RelationalDBInterfacePostgres.cpp.

◆ getCompleteLedgers()

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

getCompleteLedgers Returns string which contains list of completed ledgers.

Method is specific for postgres backend.

Returns
String with completed ledger numbers

Implements ripple::RelationalDBInterfacePostgres.

Definition at line 164 of file RelationalDBInterfacePostgres.cpp.

◆ getValidatedLedgerAge()

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

getValidatedLedgerAge Returns age of last validated ledger.

Method is specific for postgres backend.

Returns
Age of last validated ledger in seconds

Implements ripple::RelationalDBInterfacePostgres.

Definition at line 170 of file RelationalDBInterfacePostgres.cpp.

◆ writeLedgerAndTransactions()

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

writeLedgerAndTransactions Write new ledger and transaction data into database.

Method is specific for Postgres backend.

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

Implements ripple::RelationalDBInterfacePostgres.

Definition at line 176 of file RelationalDBInterfacePostgres.cpp.

◆ getLedgerInfoByIndex()

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

getLedgerInfoByIndex Returns ledger by its sequence.

Parameters
ledgerSeqLedger sequence.
Returns
Ledger or none if ledger not found.

Implements ripple::RelationalDBInterface.

Definition at line 184 of file RelationalDBInterfacePostgres.cpp.

◆ getNewestLedgerInfo()

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

getNewestLedgerInfo Returns info of newest saved ledger.

Returns
Ledger info or none if ledger not found.

Implements ripple::RelationalDBInterface.

Definition at line 190 of file RelationalDBInterfacePostgres.cpp.

◆ getLedgerInfoByHash() [1/2]

std::optional< LedgerInfo > ripple::RelationalDBInterfacePostgresImp::getLedgerInfoByHash ( uint256 const &  ledgerHash)
override

Definition at line 196 of file RelationalDBInterfacePostgres.cpp.

◆ getHashByIndex()

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

getHashByIndex Returns hash of ledger with given sequence.

Parameters
ledgerIndexLedger sequence.
Returns
Hash of the ledger.

Implements ripple::RelationalDBInterface.

Definition at line 202 of file RelationalDBInterfacePostgres.cpp.

◆ getHashesByIndex() [1/2]

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

getHashesByIndex Returns hash of the ledger and hash of parent ledger for the ledger of given sequence.

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

Implements ripple::RelationalDBInterface.

Definition at line 208 of file RelationalDBInterfacePostgres.cpp.

◆ getHashesByIndex() [2/2]

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

getHashesByIndex Returns hash of the ledger and hash of parent ledger for all ledgers with sequences from given minimum limit to given maximum limit.

Parameters
minSeqMinimum ledger sequence.
maxSeqMaximum ledger sequence.
Returns
Map which points sequence number of found ledger to the struct LedgerHashPair which contains ledger hash and its parent hash.

Implements ripple::RelationalDBInterface.

Definition at line 218 of file RelationalDBInterfacePostgres.cpp.

◆ getTxHashes()

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

getTxHashes Returns vector of tx hashes by given ledger sequence.

Method is specific to postgres backend.

Parameters
seqLedger sequence
Returns
Vector of tx hashes

Implements ripple::RelationalDBInterfacePostgres.

Definition at line 226 of file RelationalDBInterfacePostgres.cpp.

◆ getTxHistory()

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

getTxHistory Returns most recent 20 transactions starting from given number or entry.

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

Implements ripple::RelationalDBInterface.

Definition at line 232 of file RelationalDBInterfacePostgres.cpp.

◆ getAccountTx()

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

getAccountTx Get last account transactions specifies by passed argumenrs structure.

Function if specific to postgres backend.

Parameters
argsArguments which specify account and whose tx to return.
appApplication
jJournal
Returns
Vector of account transactions and RPC status of responce.

Implements ripple::RelationalDBInterfacePostgres.

Definition at line 238 of file RelationalDBInterfacePostgres.cpp.

◆ locateTransaction()

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

locateTransaction Returns information used to locate a transaction.

Function is specific to postgres backend.

Parameters
idHash of the transaction.
Returns
Information used to locate a transaction. Contains a nodestore hash and 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::RelationalDBInterfacePostgres.

Definition at line 244 of file RelationalDBInterfacePostgres.cpp.

◆ ledgerDbHasSpace()

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

ledgerDbHasSpace Checks if ledger database has available space.

Parameters
configConfig object.
Returns
True if space is available.

Implements ripple::RelationalDBInterface.

Definition at line 258 of file RelationalDBInterfacePostgres.cpp.

◆ transactionDbHasSpace()

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

transactionDbHasSpace Checks if transaction database has available space.

Parameters
configConfig object.
Returns
True if space is available.

Implements ripple::RelationalDBInterface.

Definition at line 264 of file RelationalDBInterfacePostgres.cpp.

◆ isCaughtUp()

bool ripple::RelationalDBInterfacePostgresImp::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::RelationalDBInterfacePostgres.

Definition at line 279 of file RelationalDBInterfacePostgres.cpp.

◆ dbHasSpace()

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

Definition at line 250 of file RelationalDBInterfacePostgres.cpp.

◆ init()

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

init Creates and returns appropriate interface based on config.

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

Definition at line 40 of file RelationalDBInterface.cpp.

◆ getLedgerInfoByHash() [2/2]

virtual std::optional<LedgerInfo> ripple::RelationalDBInterface::getLedgerInfoByHash ( uint256 const &  ledgerHash)
pure virtualinherited

getLedgerInfoByHash Returns info of ledger with given hash.

Parameters
ledgerHashHash of the ledger.
Returns
Ledger or none if ledger not found.

Member Data Documentation

◆ app_

Application& ripple::RelationalDBInterfacePostgresImp::app_
private

Definition at line 135 of file RelationalDBInterfacePostgres.cpp.

◆ j_

beast::Journal ripple::RelationalDBInterfacePostgresImp::j_
private

Definition at line 136 of file RelationalDBInterfacePostgres.cpp.

◆ pgPool_

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

Definition at line 137 of file RelationalDBInterfacePostgres.cpp.