mirror of
https://github.com/XRPLF/rippled.git
synced 2026-02-01 20:45:22 +00:00
Compare commits
13 Commits
develop
...
a1q123456/
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
922752a516 | ||
|
|
7278f85d1f | ||
|
|
12e5129c64 | ||
|
|
2db165a94c | ||
|
|
f420b2ed37 | ||
|
|
cf67641730 | ||
|
|
525338022e | ||
|
|
65a85aeee9 | ||
|
|
c9dbea137d | ||
|
|
755ba319cd | ||
|
|
4e554cc530 | ||
|
|
5ff7222230 | ||
|
|
1156fa261d |
@@ -11,7 +11,7 @@ Loop: xrpld.app xrpld.overlay
|
||||
xrpld.overlay > xrpld.app
|
||||
|
||||
Loop: xrpld.app xrpld.peerfinder
|
||||
xrpld.peerfinder ~= xrpld.app
|
||||
xrpld.peerfinder == xrpld.app
|
||||
|
||||
Loop: xrpld.app xrpld.rpc
|
||||
xrpld.rpc > xrpld.app
|
||||
|
||||
@@ -17,12 +17,15 @@ libxrpl.nodestore > xrpl.protocol
|
||||
libxrpl.protocol > xrpl.basics
|
||||
libxrpl.protocol > xrpl.json
|
||||
libxrpl.protocol > xrpl.protocol
|
||||
libxrpl.rdb > xrpl.basics
|
||||
libxrpl.rdb > xrpl.rdb
|
||||
libxrpl.resource > xrpl.basics
|
||||
libxrpl.resource > xrpl.json
|
||||
libxrpl.resource > xrpl.resource
|
||||
libxrpl.server > xrpl.basics
|
||||
libxrpl.server > xrpl.json
|
||||
libxrpl.server > xrpl.protocol
|
||||
libxrpl.server > xrpl.rdb
|
||||
libxrpl.server > xrpl.server
|
||||
libxrpl.shamap > xrpl.basics
|
||||
libxrpl.shamap > xrpl.protocol
|
||||
@@ -41,7 +44,9 @@ test.app > xrpl.json
|
||||
test.app > xrpl.ledger
|
||||
test.app > xrpl.nodestore
|
||||
test.app > xrpl.protocol
|
||||
test.app > xrpl.rdb
|
||||
test.app > xrpl.resource
|
||||
test.app > xrpl.server
|
||||
test.basics > test.jtx
|
||||
test.basics > test.unit_test
|
||||
test.basics > xrpl.basics
|
||||
@@ -67,6 +72,7 @@ test.core > xrpl.basics
|
||||
test.core > xrpl.core
|
||||
test.core > xrpld.core
|
||||
test.core > xrpl.json
|
||||
test.core > xrpl.rdb
|
||||
test.core > xrpl.server
|
||||
test.csf > xrpl.basics
|
||||
test.csf > xrpld.consensus
|
||||
@@ -95,8 +101,8 @@ test.nodestore > test.jtx
|
||||
test.nodestore > test.toplevel
|
||||
test.nodestore > test.unit_test
|
||||
test.nodestore > xrpl.basics
|
||||
test.nodestore > xrpld.core
|
||||
test.nodestore > xrpl.nodestore
|
||||
test.nodestore > xrpl.rdb
|
||||
test.overlay > test.jtx
|
||||
test.overlay > test.toplevel
|
||||
test.overlay > test.unit_test
|
||||
@@ -152,6 +158,8 @@ tests.libxrpl > xrpl.json
|
||||
tests.libxrpl > xrpl.net
|
||||
xrpl.core > xrpl.basics
|
||||
xrpl.core > xrpl.json
|
||||
xrpl.core > xrpl.ledger
|
||||
xrpl.core > xrpl.protocol
|
||||
xrpl.json > xrpl.basics
|
||||
xrpl.ledger > xrpl.basics
|
||||
xrpl.ledger > xrpl.protocol
|
||||
@@ -160,12 +168,17 @@ xrpl.nodestore > xrpl.basics
|
||||
xrpl.nodestore > xrpl.protocol
|
||||
xrpl.protocol > xrpl.basics
|
||||
xrpl.protocol > xrpl.json
|
||||
xrpl.rdb > xrpl.basics
|
||||
xrpl.rdb > xrpl.core
|
||||
xrpl.rdb > xrpl.protocol
|
||||
xrpl.resource > xrpl.basics
|
||||
xrpl.resource > xrpl.json
|
||||
xrpl.resource > xrpl.protocol
|
||||
xrpl.server > xrpl.basics
|
||||
xrpl.server > xrpl.core
|
||||
xrpl.server > xrpl.json
|
||||
xrpl.server > xrpl.protocol
|
||||
xrpl.server > xrpl.rdb
|
||||
xrpl.shamap > xrpl.basics
|
||||
xrpl.shamap > xrpl.nodestore
|
||||
xrpl.shamap > xrpl.protocol
|
||||
@@ -179,7 +192,9 @@ xrpld.app > xrpl.ledger
|
||||
xrpld.app > xrpl.net
|
||||
xrpld.app > xrpl.nodestore
|
||||
xrpld.app > xrpl.protocol
|
||||
xrpld.app > xrpl.rdb
|
||||
xrpld.app > xrpl.resource
|
||||
xrpld.app > xrpl.server
|
||||
xrpld.app > xrpl.shamap
|
||||
xrpld.conditions > xrpl.basics
|
||||
xrpld.conditions > xrpl.protocol
|
||||
@@ -191,17 +206,20 @@ xrpld.core > xrpl.core
|
||||
xrpld.core > xrpl.json
|
||||
xrpld.core > xrpl.net
|
||||
xrpld.core > xrpl.protocol
|
||||
xrpld.core > xrpl.rdb
|
||||
xrpld.overlay > xrpl.basics
|
||||
xrpld.overlay > xrpl.core
|
||||
xrpld.overlay > xrpld.core
|
||||
xrpld.overlay > xrpld.peerfinder
|
||||
xrpld.overlay > xrpl.json
|
||||
xrpld.overlay > xrpl.protocol
|
||||
xrpld.overlay > xrpl.rdb
|
||||
xrpld.overlay > xrpl.resource
|
||||
xrpld.overlay > xrpl.server
|
||||
xrpld.peerfinder > xrpl.basics
|
||||
xrpld.peerfinder > xrpld.core
|
||||
xrpld.peerfinder > xrpl.protocol
|
||||
xrpld.peerfinder > xrpl.rdb
|
||||
xrpld.perflog > xrpl.basics
|
||||
xrpld.perflog > xrpl.core
|
||||
xrpld.perflog > xrpld.rpc
|
||||
@@ -214,6 +232,7 @@ xrpld.rpc > xrpl.ledger
|
||||
xrpld.rpc > xrpl.net
|
||||
xrpld.rpc > xrpl.nodestore
|
||||
xrpld.rpc > xrpl.protocol
|
||||
xrpld.rpc > xrpl.rdb
|
||||
xrpld.rpc > xrpl.resource
|
||||
xrpld.rpc > xrpl.server
|
||||
xrpld.shamap > xrpl.shamap
|
||||
|
||||
@@ -114,22 +114,32 @@ target_link_libraries(xrpl.libxrpl.net PUBLIC
|
||||
xrpl.libxrpl.resource
|
||||
)
|
||||
|
||||
add_module(xrpl server)
|
||||
target_link_libraries(xrpl.libxrpl.server PUBLIC xrpl.libxrpl.protocol)
|
||||
|
||||
add_module(xrpl nodestore)
|
||||
target_link_libraries(xrpl.libxrpl.nodestore PUBLIC
|
||||
xrpl.libxrpl.basics
|
||||
xrpl.libxrpl.json
|
||||
xrpl.libxrpl.protocol
|
||||
xrpl.libxrpl.basics
|
||||
xrpl.libxrpl.json
|
||||
xrpl.libxrpl.protocol
|
||||
)
|
||||
|
||||
add_module(xrpl shamap)
|
||||
target_link_libraries(xrpl.libxrpl.shamap PUBLIC
|
||||
xrpl.libxrpl.basics
|
||||
xrpl.libxrpl.crypto
|
||||
xrpl.libxrpl.protocol
|
||||
xrpl.libxrpl.nodestore
|
||||
xrpl.libxrpl.basics
|
||||
xrpl.libxrpl.crypto
|
||||
xrpl.libxrpl.protocol
|
||||
xrpl.libxrpl.nodestore
|
||||
)
|
||||
|
||||
add_module(xrpl rdb)
|
||||
target_link_libraries(xrpl.libxrpl.rdb PUBLIC
|
||||
xrpl.libxrpl.basics
|
||||
xrpl.libxrpl.core
|
||||
)
|
||||
|
||||
add_module(xrpl server)
|
||||
target_link_libraries(xrpl.libxrpl.server PUBLIC
|
||||
xrpl.libxrpl.protocol
|
||||
xrpl.libxrpl.core
|
||||
xrpl.libxrpl.rdb
|
||||
)
|
||||
|
||||
add_module(xrpl ledger)
|
||||
@@ -137,6 +147,7 @@ target_link_libraries(xrpl.libxrpl.ledger PUBLIC
|
||||
xrpl.libxrpl.basics
|
||||
xrpl.libxrpl.json
|
||||
xrpl.libxrpl.protocol
|
||||
xrpl.libxrpl.rdb
|
||||
)
|
||||
|
||||
add_library(xrpl.libxrpl)
|
||||
@@ -152,15 +163,16 @@ target_sources(xrpl.libxrpl PRIVATE ${sources})
|
||||
target_link_modules(xrpl PUBLIC
|
||||
basics
|
||||
beast
|
||||
core
|
||||
crypto
|
||||
json
|
||||
protocol
|
||||
core
|
||||
resource
|
||||
server
|
||||
net
|
||||
nodestore
|
||||
shamap
|
||||
net
|
||||
rdb
|
||||
server
|
||||
ledger
|
||||
)
|
||||
|
||||
|
||||
@@ -19,6 +19,7 @@ install (
|
||||
xrpl.libxrpl.core
|
||||
xrpl.libxrpl.crypto
|
||||
xrpl.libxrpl.json
|
||||
xrpl.libxrpl.rdb
|
||||
xrpl.libxrpl.ledger
|
||||
xrpl.libxrpl.net
|
||||
xrpl.libxrpl.nodestore
|
||||
|
||||
228
include/xrpl/core/ServiceRegistry.h
Normal file
228
include/xrpl/core/ServiceRegistry.h
Normal file
@@ -0,0 +1,228 @@
|
||||
#ifndef XRPL_CORE_SERVICEREGISTRY_H_INCLUDED
|
||||
#define XRPL_CORE_SERVICEREGISTRY_H_INCLUDED
|
||||
|
||||
#include <xrpl/basics/Blob.h>
|
||||
#include <xrpl/basics/SHAMapHash.h>
|
||||
#include <xrpl/basics/TaggedCache.h>
|
||||
#include <xrpl/ledger/CachedSLEs.h>
|
||||
#include <xrpl/protocol/Protocol.h>
|
||||
|
||||
#include <boost/asio.hpp>
|
||||
|
||||
#include <cstdint>
|
||||
#include <memory>
|
||||
|
||||
namespace xrpl {
|
||||
|
||||
// Forward declarations
|
||||
namespace NodeStore {
|
||||
class Database;
|
||||
}
|
||||
namespace Resource {
|
||||
class Manager;
|
||||
}
|
||||
namespace perf {
|
||||
class PerfLog;
|
||||
}
|
||||
|
||||
class AcceptedLedger;
|
||||
class AmendmentTable;
|
||||
class Application;
|
||||
class Cluster;
|
||||
class CollectorManager;
|
||||
class DatabaseCon;
|
||||
class Family;
|
||||
class HashRouter;
|
||||
class InboundLedgers;
|
||||
class InboundTransactions;
|
||||
class JobQueue;
|
||||
class LedgerCleaner;
|
||||
class LedgerMaster;
|
||||
class LedgerReplayer;
|
||||
class LoadFeeTrack;
|
||||
class LoadManager;
|
||||
class ManifestCache;
|
||||
class NetworkOPs;
|
||||
class OpenLedger;
|
||||
class OrderBookDB;
|
||||
class Overlay;
|
||||
class PathRequests;
|
||||
class PeerReservationTable;
|
||||
class PendingSaves;
|
||||
class RelationalDatabase;
|
||||
class ServerHandler;
|
||||
class SHAMapStore;
|
||||
class TimeKeeper;
|
||||
class TransactionMaster;
|
||||
class TxQ;
|
||||
class ValidatorList;
|
||||
class ValidatorSite;
|
||||
|
||||
template <class Adaptor>
|
||||
class Validations;
|
||||
class RCLValidationsAdaptor;
|
||||
using RCLValidations = Validations<RCLValidationsAdaptor>;
|
||||
|
||||
using NodeCache = TaggedCache<SHAMapHash, Blob>;
|
||||
|
||||
/** Service registry for dependency injection.
|
||||
|
||||
This abstract interface provides access to various services and components
|
||||
used throughout the application. It separates the service locator pattern
|
||||
from the Application lifecycle management.
|
||||
|
||||
Components that need access to services can hold a reference to
|
||||
ServiceRegistry rather than Application when they only need service
|
||||
access and not lifecycle management.
|
||||
|
||||
The implementation (ServiceRegistryImpl) is provided in xrpld.
|
||||
*/
|
||||
class ServiceRegistry
|
||||
{
|
||||
public:
|
||||
ServiceRegistry() = default;
|
||||
virtual ~ServiceRegistry() = default;
|
||||
|
||||
// Core infrastructure services
|
||||
virtual CollectorManager&
|
||||
getCollectorManager() = 0;
|
||||
|
||||
virtual Family&
|
||||
getNodeFamily() = 0;
|
||||
|
||||
virtual TimeKeeper&
|
||||
timeKeeper() = 0;
|
||||
|
||||
virtual JobQueue&
|
||||
getJobQueue() = 0;
|
||||
|
||||
virtual NodeCache&
|
||||
getTempNodeCache() = 0;
|
||||
|
||||
virtual CachedSLEs&
|
||||
cachedSLEs() = 0;
|
||||
|
||||
// Protocol and validation services
|
||||
virtual AmendmentTable&
|
||||
getAmendmentTable() = 0;
|
||||
|
||||
virtual HashRouter&
|
||||
getHashRouter() = 0;
|
||||
|
||||
virtual LoadFeeTrack&
|
||||
getFeeTrack() = 0;
|
||||
|
||||
virtual LoadManager&
|
||||
getLoadManager() = 0;
|
||||
|
||||
virtual RCLValidations&
|
||||
getValidations() = 0;
|
||||
|
||||
virtual ValidatorList&
|
||||
validators() = 0;
|
||||
|
||||
virtual ValidatorSite&
|
||||
validatorSites() = 0;
|
||||
|
||||
virtual ManifestCache&
|
||||
validatorManifests() = 0;
|
||||
|
||||
virtual ManifestCache&
|
||||
publisherManifests() = 0;
|
||||
|
||||
// Network services
|
||||
virtual Overlay&
|
||||
overlay() = 0;
|
||||
|
||||
virtual Cluster&
|
||||
cluster() = 0;
|
||||
|
||||
virtual PeerReservationTable&
|
||||
peerReservations() = 0;
|
||||
|
||||
virtual Resource::Manager&
|
||||
getResourceManager() = 0;
|
||||
|
||||
// Storage services
|
||||
virtual NodeStore::Database&
|
||||
getNodeStore() = 0;
|
||||
|
||||
virtual SHAMapStore&
|
||||
getSHAMapStore() = 0;
|
||||
|
||||
virtual RelationalDatabase&
|
||||
getRelationalDatabase() = 0;
|
||||
|
||||
// Ledger services
|
||||
virtual InboundLedgers&
|
||||
getInboundLedgers() = 0;
|
||||
|
||||
virtual InboundTransactions&
|
||||
getInboundTransactions() = 0;
|
||||
|
||||
virtual TaggedCache<uint256, AcceptedLedger>&
|
||||
getAcceptedLedgerCache() = 0;
|
||||
|
||||
virtual LedgerMaster&
|
||||
getLedgerMaster() = 0;
|
||||
|
||||
virtual LedgerCleaner&
|
||||
getLedgerCleaner() = 0;
|
||||
|
||||
virtual LedgerReplayer&
|
||||
getLedgerReplayer() = 0;
|
||||
|
||||
virtual PendingSaves&
|
||||
pendingSaves() = 0;
|
||||
|
||||
virtual OpenLedger&
|
||||
openLedger() = 0;
|
||||
|
||||
virtual OpenLedger const&
|
||||
openLedger() const = 0;
|
||||
|
||||
// Transaction and operation services
|
||||
virtual NetworkOPs&
|
||||
getOPs() = 0;
|
||||
|
||||
virtual OrderBookDB&
|
||||
getOrderBookDB() = 0;
|
||||
|
||||
virtual TransactionMaster&
|
||||
getMasterTransaction() = 0;
|
||||
|
||||
virtual TxQ&
|
||||
getTxQ() = 0;
|
||||
|
||||
virtual PathRequests&
|
||||
getPathRequests() = 0;
|
||||
|
||||
// Server services
|
||||
virtual ServerHandler&
|
||||
getServerHandler() = 0;
|
||||
|
||||
virtual perf::PerfLog&
|
||||
getPerfLog() = 0;
|
||||
|
||||
// Configuration and state
|
||||
virtual bool
|
||||
isStopping() const = 0;
|
||||
|
||||
virtual beast::Journal
|
||||
journal(std::string const& name) = 0;
|
||||
|
||||
virtual boost::asio::io_context&
|
||||
getIOContext() = 0;
|
||||
|
||||
virtual Logs&
|
||||
logs() = 0;
|
||||
|
||||
// Temporary: Get the underlying Application for functions that haven't
|
||||
// been migrated yet. This should be removed once all code is migrated.
|
||||
virtual Application&
|
||||
app() = 0;
|
||||
};
|
||||
|
||||
} // namespace xrpl
|
||||
|
||||
#endif
|
||||
18
include/xrpl/core/StartUpType.h
Normal file
18
include/xrpl/core/StartUpType.h
Normal file
@@ -0,0 +1,18 @@
|
||||
#ifndef XRPL_STARTUPTYPE_H
|
||||
#define XRPL_STARTUPTYPE_H
|
||||
#include <iosfwd>
|
||||
#include <type_traits>
|
||||
|
||||
namespace xrpl {
|
||||
|
||||
enum class StartUpType { FRESH, NORMAL, LOAD, LOAD_FILE, REPLAY, NETWORK };
|
||||
|
||||
inline std::ostream&
|
||||
operator<<(std::ostream& os, StartUpType const& type)
|
||||
{
|
||||
return os << static_cast<std::underlying_type_t<StartUpType>>(type);
|
||||
}
|
||||
|
||||
} // namespace xrpl
|
||||
|
||||
#endif // XRPL_STARTUPTYPE_H
|
||||
25
include/xrpl/protocol/LedgerShortcut.h
Normal file
25
include/xrpl/protocol/LedgerShortcut.h
Normal file
@@ -0,0 +1,25 @@
|
||||
#ifndef XRPL_PROTOCOL_LEDGERSHORTCUT_H_INCLUDED
|
||||
#define XRPL_PROTOCOL_LEDGERSHORTCUT_H_INCLUDED
|
||||
|
||||
namespace xrpl {
|
||||
|
||||
/**
|
||||
* @brief Enumeration of ledger shortcuts for specifying which ledger to use.
|
||||
*
|
||||
* These shortcuts provide a convenient way to reference commonly used ledgers
|
||||
* without needing to specify their exact hash or sequence number.
|
||||
*/
|
||||
enum class LedgerShortcut {
|
||||
/** The current working ledger (open, not yet closed) */
|
||||
Current,
|
||||
|
||||
/** The most recently closed ledger (may not be validated) */
|
||||
Closed,
|
||||
|
||||
/** The most recently validated ledger */
|
||||
Validated
|
||||
};
|
||||
|
||||
} // namespace xrpl
|
||||
|
||||
#endif
|
||||
10
include/xrpl/protocol/TxSearched.h
Normal file
10
include/xrpl/protocol/TxSearched.h
Normal file
@@ -0,0 +1,10 @@
|
||||
#ifndef XRPL_APP_TX_TX_SEARCHED_H_INCLUDED
|
||||
#define XRPL_APP_TX_TX_SEARCHED_H_INCLUDED
|
||||
|
||||
namespace xrpl {
|
||||
|
||||
enum class TxSearched { all, some, unknown };
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -1,11 +1,10 @@
|
||||
#ifndef XRPL_APP_DATA_DATABASECON_H_INCLUDED
|
||||
#define XRPL_APP_DATA_DATABASECON_H_INCLUDED
|
||||
|
||||
#include <xrpld/app/main/DBInit.h>
|
||||
#include <xrpld/core/Config.h>
|
||||
#include <xrpld/core/SociDB.h>
|
||||
|
||||
#include <xrpl/core/PerfLog.h>
|
||||
#include <xrpl/core/StartUpType.h>
|
||||
#include <xrpl/rdb/DBInit.h>
|
||||
#include <xrpl/rdb/SociDB.h>
|
||||
|
||||
#include <boost/filesystem/path.hpp>
|
||||
|
||||
@@ -71,7 +70,7 @@ public:
|
||||
{
|
||||
explicit Setup() = default;
|
||||
|
||||
Config::StartUpType startUp = Config::NORMAL;
|
||||
StartUpType startUp = StartUpType::NORMAL;
|
||||
bool standAlone = false;
|
||||
boost::filesystem::path dataDir;
|
||||
// Indicates whether or not to return the `globalPragma`
|
||||
@@ -109,9 +108,9 @@ public:
|
||||
beast::Journal journal)
|
||||
// Use temporary files or regular DB files?
|
||||
: DatabaseCon(
|
||||
setup.standAlone && setup.startUp != Config::LOAD &&
|
||||
setup.startUp != Config::LOAD_FILE &&
|
||||
setup.startUp != Config::REPLAY
|
||||
setup.standAlone && setup.startUp != StartUpType::LOAD &&
|
||||
setup.startUp != StartUpType::LOAD_FILE &&
|
||||
setup.startUp != StartUpType::REPLAY
|
||||
? ""
|
||||
: (setup.dataDir / dbName),
|
||||
setup.commonPragma(),
|
||||
@@ -237,11 +236,6 @@ private:
|
||||
std::shared_ptr<Checkpointer>
|
||||
checkpointerFromId(std::uintptr_t id);
|
||||
|
||||
DatabaseCon::Setup
|
||||
setup_DatabaseCon(
|
||||
Config const& c,
|
||||
std::optional<beast::Journal> j = std::nullopt);
|
||||
|
||||
} // namespace xrpl
|
||||
|
||||
#endif
|
||||
488
include/xrpl/rdb/RelationalDatabase.h
Normal file
488
include/xrpl/rdb/RelationalDatabase.h
Normal file
@@ -0,0 +1,488 @@
|
||||
#ifndef XRPL_APP_RDB_RELATIONALDATABASE_H_INCLUDED
|
||||
#define XRPL_APP_RDB_RELATIONALDATABASE_H_INCLUDED
|
||||
|
||||
#include <xrpl/basics/RangeSet.h>
|
||||
#include <xrpl/beast/utility/instrumentation.h>
|
||||
#include <xrpl/core/ServiceRegistry.h>
|
||||
#include <xrpl/protocol/ErrorCodes.h>
|
||||
#include <xrpl/protocol/LedgerHeader.h>
|
||||
#include <xrpl/protocol/LedgerShortcut.h>
|
||||
#include <xrpl/protocol/TxMeta.h>
|
||||
#include <xrpl/protocol/TxSearched.h>
|
||||
#include <xrpl/rdb/DatabaseCon.h>
|
||||
|
||||
#include <boost/filesystem.hpp>
|
||||
#include <boost/variant.hpp>
|
||||
|
||||
namespace xrpl {
|
||||
|
||||
class Transaction;
|
||||
class Ledger;
|
||||
|
||||
struct LedgerHashPair
|
||||
{
|
||||
uint256 ledgerHash;
|
||||
uint256 parentHash;
|
||||
};
|
||||
|
||||
struct LedgerRange
|
||||
{
|
||||
uint32_t min;
|
||||
uint32_t max;
|
||||
};
|
||||
|
||||
class RelationalDatabase
|
||||
{
|
||||
public:
|
||||
struct CountMinMax
|
||||
{
|
||||
std::size_t numberOfRows;
|
||||
LedgerIndex minLedgerSequence;
|
||||
LedgerIndex maxLedgerSequence;
|
||||
};
|
||||
|
||||
struct AccountTxMarker
|
||||
{
|
||||
std::uint32_t ledgerSeq = 0;
|
||||
std::uint32_t txnSeq = 0;
|
||||
};
|
||||
|
||||
struct AccountTxOptions
|
||||
{
|
||||
AccountID const& account;
|
||||
std::uint32_t minLedger;
|
||||
std::uint32_t maxLedger;
|
||||
std::uint32_t offset;
|
||||
std::uint32_t limit;
|
||||
bool bUnlimited;
|
||||
};
|
||||
|
||||
struct AccountTxPageOptions
|
||||
{
|
||||
AccountID const& account;
|
||||
std::uint32_t minLedger;
|
||||
std::uint32_t maxLedger;
|
||||
std::optional<AccountTxMarker> marker;
|
||||
std::uint32_t limit;
|
||||
bool bAdmin;
|
||||
};
|
||||
|
||||
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 LedgerSpecifier =
|
||||
std::variant<LedgerRange, LedgerShortcut, LedgerSequence, LedgerHash>;
|
||||
|
||||
struct AccountTxArgs
|
||||
{
|
||||
AccountID account;
|
||||
std::optional<LedgerSpecifier> ledger;
|
||||
bool binary = false;
|
||||
bool forward = false;
|
||||
uint32_t limit = 0;
|
||||
std::optional<AccountTxMarker> marker;
|
||||
};
|
||||
|
||||
struct AccountTxResult
|
||||
{
|
||||
std::variant<AccountTxs, MetaTxsList> transactions;
|
||||
LedgerRange ledgerRange;
|
||||
uint32_t limit;
|
||||
std::optional<AccountTxMarker> marker;
|
||||
};
|
||||
|
||||
virtual ~RelationalDatabase() = default;
|
||||
|
||||
/**
|
||||
* @brief getMinLedgerSeq Returns the minimum ledger sequence in the Ledgers
|
||||
* table.
|
||||
* @return Ledger sequence or no value if no ledgers exist.
|
||||
*/
|
||||
virtual std::optional<LedgerIndex>
|
||||
getMinLedgerSeq() = 0;
|
||||
|
||||
/**
|
||||
* @brief getMaxLedgerSeq Returns the maximum ledger sequence in the Ledgers
|
||||
* table.
|
||||
* @return Ledger sequence or none if no ledgers exist.
|
||||
*/
|
||||
virtual std::optional<LedgerIndex>
|
||||
getMaxLedgerSeq() = 0;
|
||||
|
||||
/**
|
||||
* @brief getLedgerInfoByIndex Returns a ledger by its sequence.
|
||||
* @param ledgerSeq Ledger sequence.
|
||||
* @return The ledger if found, otherwise no value.
|
||||
*/
|
||||
virtual std::optional<LedgerHeader>
|
||||
getLedgerInfoByIndex(LedgerIndex ledgerSeq) = 0;
|
||||
|
||||
/**
|
||||
* @brief getNewestLedgerInfo Returns the info of the newest saved ledger.
|
||||
* @return Ledger info if found, otherwise no value.
|
||||
*/
|
||||
virtual std::optional<LedgerHeader>
|
||||
getNewestLedgerInfo() = 0;
|
||||
|
||||
/**
|
||||
* @brief getLedgerInfoByHash Returns the info of the ledger with given
|
||||
* hash.
|
||||
* @param ledgerHash Hash of the ledger.
|
||||
* @return Ledger if found, otherwise no value.
|
||||
*/
|
||||
virtual std::optional<LedgerHeader>
|
||||
getLedgerInfoByHash(uint256 const& ledgerHash) = 0;
|
||||
|
||||
/**
|
||||
* @brief getHashByIndex Returns the hash of the ledger with the given
|
||||
* sequence.
|
||||
* @param ledgerIndex Ledger sequence.
|
||||
* @return Hash of the ledger.
|
||||
*/
|
||||
virtual uint256
|
||||
getHashByIndex(LedgerIndex ledgerIndex) = 0;
|
||||
|
||||
/**
|
||||
* @brief getHashesByIndex Returns the hashes of the ledger and its parent
|
||||
* as specified by the ledgerIndex.
|
||||
* @param ledgerIndex Ledger sequence.
|
||||
* @return Struct LedgerHashPair which contains hashes of the ledger and
|
||||
* its parent.
|
||||
*/
|
||||
virtual std::optional<LedgerHashPair>
|
||||
getHashesByIndex(LedgerIndex ledgerIndex) = 0;
|
||||
|
||||
/**
|
||||
* @brief getHashesByIndex Returns hashes of each ledger and its parent for
|
||||
* all ledgers within the provided range.
|
||||
* @param minSeq Minimum ledger sequence.
|
||||
* @param maxSeq Maximum ledger sequence.
|
||||
* @return Container that maps the sequence number of a found ledger to the
|
||||
* struct LedgerHashPair which contains the hashes of the ledger and
|
||||
* its parent.
|
||||
*/
|
||||
virtual std::map<LedgerIndex, LedgerHashPair>
|
||||
getHashesByIndex(LedgerIndex minSeq, LedgerIndex maxSeq) = 0;
|
||||
|
||||
/**
|
||||
* @brief getTxHistory Returns the 20 most recent transactions starting from
|
||||
* the given number.
|
||||
* @param startIndex First number of returned entry.
|
||||
* @return Vector of shared pointers to transactions sorted in
|
||||
* descending order by ledger sequence.
|
||||
*/
|
||||
virtual std::vector<std::shared_ptr<Transaction>>
|
||||
getTxHistory(LedgerIndex startIndex) = 0;
|
||||
|
||||
/**
|
||||
* @brief getTransactionsMinLedgerSeq Returns the minimum ledger sequence
|
||||
* stored in the Transactions table.
|
||||
* @return Ledger sequence or no value if no ledgers exist.
|
||||
*/
|
||||
virtual std::optional<LedgerIndex>
|
||||
getTransactionsMinLedgerSeq() = 0;
|
||||
|
||||
/**
|
||||
* @brief getAccountTransactionsMinLedgerSeq Returns the minimum ledger
|
||||
* sequence stored in the AccountTransactions table.
|
||||
* @return Ledger sequence or no value if no ledgers exist.
|
||||
*/
|
||||
virtual std::optional<LedgerIndex>
|
||||
getAccountTransactionsMinLedgerSeq() = 0;
|
||||
|
||||
/**
|
||||
* @brief deleteTransactionByLedgerSeq Deletes transactions from the ledger
|
||||
* with the given sequence.
|
||||
* @param ledgerSeq Ledger sequence.
|
||||
*/
|
||||
virtual void
|
||||
deleteTransactionByLedgerSeq(LedgerIndex ledgerSeq) = 0;
|
||||
|
||||
/**
|
||||
* @brief deleteBeforeLedgerSeq Deletes all ledgers with a sequence number
|
||||
* less than or equal to the given ledger sequence.
|
||||
* @param ledgerSeq Ledger sequence.
|
||||
*/
|
||||
virtual void
|
||||
deleteBeforeLedgerSeq(LedgerIndex ledgerSeq) = 0;
|
||||
|
||||
/**
|
||||
* @brief deleteTransactionsBeforeLedgerSeq Deletes all transactions with
|
||||
* a sequence number less than or equal to the given ledger
|
||||
* sequence.
|
||||
* @param ledgerSeq Ledger sequence.
|
||||
*/
|
||||
virtual void
|
||||
deleteTransactionsBeforeLedgerSeq(LedgerIndex ledgerSeq) = 0;
|
||||
|
||||
/**
|
||||
* @brief deleteAccountTransactionsBeforeLedgerSeq Deletes all account
|
||||
* transactions with a sequence number less than or equal to the
|
||||
* given ledger sequence.
|
||||
* @param ledgerSeq Ledger sequence.
|
||||
*/
|
||||
virtual void
|
||||
deleteAccountTransactionsBeforeLedgerSeq(LedgerIndex ledgerSeq) = 0;
|
||||
|
||||
/**
|
||||
* @brief getTransactionCount Returns the number of transactions.
|
||||
* @return Number of transactions.
|
||||
*/
|
||||
virtual std::size_t
|
||||
getTransactionCount() = 0;
|
||||
|
||||
/**
|
||||
* @brief getAccountTransactionCount Returns the number of account
|
||||
* transactions.
|
||||
* @return Number of account transactions.
|
||||
*/
|
||||
virtual std::size_t
|
||||
getAccountTransactionCount() = 0;
|
||||
|
||||
/**
|
||||
* @brief getLedgerCountMinMax Returns the minimum ledger sequence,
|
||||
* maximum ledger sequence and total number of saved ledgers.
|
||||
* @return Struct CountMinMax which contains the minimum sequence,
|
||||
* maximum sequence and number of ledgers.
|
||||
*/
|
||||
virtual struct CountMinMax
|
||||
getLedgerCountMinMax() = 0;
|
||||
|
||||
/**
|
||||
* @brief saveValidatedLedger Saves a ledger into the database.
|
||||
* @param ledger The ledger.
|
||||
* @param current True if the ledger is current.
|
||||
* @return True if saving was successful.
|
||||
*/
|
||||
virtual bool
|
||||
saveValidatedLedger(
|
||||
std::shared_ptr<Ledger const> const& ledger,
|
||||
bool current) = 0;
|
||||
|
||||
/**
|
||||
* @brief getLimitedOldestLedgerInfo Returns the info of the oldest ledger
|
||||
* whose sequence number is greater than or equal to the given
|
||||
* sequence number.
|
||||
* @param ledgerFirstIndex Minimum ledger sequence.
|
||||
* @return Ledger info if found, otherwise no value.
|
||||
*/
|
||||
virtual std::optional<LedgerHeader>
|
||||
getLimitedOldestLedgerInfo(LedgerIndex ledgerFirstIndex) = 0;
|
||||
|
||||
/**
|
||||
* @brief getLimitedNewestLedgerInfo Returns the info of the newest ledger
|
||||
* whose sequence number is greater than or equal to the given
|
||||
* sequence number.
|
||||
* @param ledgerFirstIndex Minimum ledger sequence.
|
||||
* @return Ledger info if found, otherwise no value.
|
||||
*/
|
||||
virtual std::optional<LedgerHeader>
|
||||
getLimitedNewestLedgerInfo(LedgerIndex ledgerFirstIndex) = 0;
|
||||
|
||||
/**
|
||||
* @brief getOldestAccountTxs Returns the oldest transactions for the
|
||||
* account that matches the given criteria starting from the provided
|
||||
* offset.
|
||||
* @param options Struct AccountTxOptions which contains the criteria to
|
||||
* match: the account, ledger search range, the offset of the first
|
||||
* entry to return, the number of transactions to return, a flag if
|
||||
* this number is unlimited.
|
||||
* @return Vector of pairs of found transactions and their metadata
|
||||
* sorted in ascending order by account sequence.
|
||||
*/
|
||||
virtual AccountTxs
|
||||
getOldestAccountTxs(AccountTxOptions const& options) = 0;
|
||||
|
||||
/**
|
||||
* @brief getNewestAccountTxs Returns the newest transactions for the
|
||||
* account that matches the given criteria starting from the provided
|
||||
* offset.
|
||||
* @param options Struct AccountTxOptions which contains the criteria to
|
||||
* match: the account, the ledger search range, the offset of the
|
||||
* first entry to return, the number of transactions to return, a
|
||||
* flag if this number unlimited.
|
||||
* @return Vector of pairs of found transactions and their metadata
|
||||
* sorted in descending order by account sequence.
|
||||
*/
|
||||
virtual AccountTxs
|
||||
getNewestAccountTxs(AccountTxOptions const& options) = 0;
|
||||
|
||||
/**
|
||||
* @brief getOldestAccountTxsB Returns the oldest transactions in binary
|
||||
* form for the account that matches the given criteria starting from
|
||||
* the provided offset.
|
||||
* @param options Struct AccountTxOptions which contains the criteria to
|
||||
* match: the account, the ledger search range, the offset of the
|
||||
* first entry to return, the number of transactions to return, a
|
||||
* flag if this number unlimited.
|
||||
* @return Vector of tuples of found transactions, their metadata and
|
||||
* account sequences sorted in ascending order by account sequence.
|
||||
*/
|
||||
virtual MetaTxsList
|
||||
getOldestAccountTxsB(AccountTxOptions const& options) = 0;
|
||||
|
||||
/**
|
||||
* @brief getNewestAccountTxsB Returns the newest transactions in binary
|
||||
* form for the account that matches the given criteria starting from
|
||||
* the provided offset.
|
||||
* @param options Struct AccountTxOptions which contains the criteria to
|
||||
* match: the account, the ledger search range, the offset of the
|
||||
* first entry to return, the number of transactions to return, a
|
||||
* flag if this number is unlimited.
|
||||
* @return Vector of tuples of found transactions, their metadata and
|
||||
* account sequences sorted in descending order by account
|
||||
* sequence.
|
||||
*/
|
||||
virtual MetaTxsList
|
||||
getNewestAccountTxsB(AccountTxOptions const& options) = 0;
|
||||
|
||||
/**
|
||||
* @brief oldestAccountTxPage Returns the oldest transactions for the
|
||||
* account that matches the given criteria starting from the
|
||||
* provided marker.
|
||||
* @param options Struct AccountTxPageOptions which contains the criteria to
|
||||
* match: the account, the ledger search range, the marker of first
|
||||
* returned entry, the number of transactions to return, a flag if
|
||||
* this number is unlimited.
|
||||
* @return Vector of pairs of found transactions and their metadata
|
||||
* sorted in ascending order by account sequence and a marker
|
||||
* for the next search if the search was not finished.
|
||||
*/
|
||||
virtual std::pair<AccountTxs, std::optional<AccountTxMarker>>
|
||||
oldestAccountTxPage(AccountTxPageOptions const& options) = 0;
|
||||
|
||||
/**
|
||||
* @brief newestAccountTxPage Returns the newest transactions for the
|
||||
* account that matches the given criteria starting from the provided
|
||||
* marker.
|
||||
* @param options Struct AccountTxPageOptions which contains the criteria to
|
||||
* match: the account, the ledger search range, the marker of the
|
||||
* first returned entry, the number of transactions to return, a flag
|
||||
* if this number unlimited.
|
||||
* @return Vector of pairs of found transactions and their metadata
|
||||
* sorted in descending order by account sequence and a marker
|
||||
* for the next search if the search was not finished.
|
||||
*/
|
||||
virtual std::pair<AccountTxs, std::optional<AccountTxMarker>>
|
||||
newestAccountTxPage(AccountTxPageOptions const& options) = 0;
|
||||
|
||||
/**
|
||||
* @brief oldestAccountTxPageB Returns the oldest transactions in binary
|
||||
* form for the account that matches the given criteria starting from
|
||||
* the provided marker.
|
||||
* @param options Struct AccountTxPageOptions which contains criteria to
|
||||
* match: the account, the ledger search range, the marker of the
|
||||
* first returned entry, the number of transactions to return, a flag
|
||||
* if this number unlimited.
|
||||
* @return Vector of tuples of found transactions, their metadata and
|
||||
* account sequences sorted in ascending order by account
|
||||
* sequence and a marker for the next search if the search was not
|
||||
* finished.
|
||||
*/
|
||||
virtual std::pair<MetaTxsList, std::optional<AccountTxMarker>>
|
||||
oldestAccountTxPageB(AccountTxPageOptions const& options) = 0;
|
||||
|
||||
/**
|
||||
* @brief newestAccountTxPageB Returns the newest transactions in binary
|
||||
* form for the account that matches the given criteria starting from
|
||||
* the provided marker.
|
||||
* @param options Struct AccountTxPageOptions which contains the criteria to
|
||||
* match: the account, the ledger search range, the marker of the
|
||||
* first returned entry, the number of transactions to return, a flag
|
||||
* if this number is unlimited.
|
||||
* @return Vector of tuples of found transactions, their metadata and
|
||||
* account sequences sorted in descending order by account
|
||||
* sequence and a marker for the next search if the search was not
|
||||
* finished.
|
||||
*/
|
||||
virtual std::pair<MetaTxsList, std::optional<AccountTxMarker>>
|
||||
newestAccountTxPageB(AccountTxPageOptions const& options) = 0;
|
||||
|
||||
/**
|
||||
* @brief getTransaction Returns the transaction with the given hash. If a
|
||||
* range is provided but the transaction is not found, then check if
|
||||
* all ledgers in the range are present in the database.
|
||||
* @param id Hash of the transaction.
|
||||
* @param range Range of ledgers to check, if present.
|
||||
* @param ec Default error code value.
|
||||
* @return Transaction and its metadata if found, otherwise TxSearched::all
|
||||
* if a range is provided and all ledgers from the range are present
|
||||
* in the database, TxSearched::some if a range is provided and not
|
||||
* all ledgers are present, TxSearched::unknown if the range is not
|
||||
* provided or a deserializing error occurred. In the last case the
|
||||
* error code is returned via the ec parameter, in other cases the
|
||||
* default error code is not changed.
|
||||
*/
|
||||
virtual std::variant<AccountTx, TxSearched>
|
||||
getTransaction(
|
||||
uint256 const& id,
|
||||
std::optional<ClosedInterval<uint32_t>> const& range,
|
||||
error_code_i& ec) = 0;
|
||||
|
||||
/**
|
||||
* @brief getKBUsedAll Returns the amount of space used by all databases.
|
||||
* @return Space in kilobytes.
|
||||
*/
|
||||
virtual uint32_t
|
||||
getKBUsedAll() = 0;
|
||||
|
||||
/**
|
||||
* @brief getKBUsedLedger Returns the amount of space space used by the
|
||||
* ledger database.
|
||||
* @return Space in kilobytes.
|
||||
*/
|
||||
virtual uint32_t
|
||||
getKBUsedLedger() = 0;
|
||||
|
||||
/**
|
||||
* @brief getKBUsedTransaction Returns the amount of space used by the
|
||||
* transaction database.
|
||||
* @return Space in kilobytes.
|
||||
*/
|
||||
virtual uint32_t
|
||||
getKBUsedTransaction() = 0;
|
||||
|
||||
/**
|
||||
* @brief Closes the ledger database
|
||||
*/
|
||||
virtual void
|
||||
closeLedgerDB() = 0;
|
||||
|
||||
/**
|
||||
* @brief Closes the transaction database
|
||||
*/
|
||||
virtual void
|
||||
closeTransactionDB() = 0;
|
||||
};
|
||||
|
||||
template <class T, class C>
|
||||
T
|
||||
rangeCheckedCast(C c)
|
||||
{
|
||||
if ((c > std::numeric_limits<T>::max()) ||
|
||||
(!std::numeric_limits<T>::is_signed && c < 0) ||
|
||||
(std::numeric_limits<T>::is_signed &&
|
||||
std::numeric_limits<C>::is_signed &&
|
||||
c < std::numeric_limits<T>::lowest()))
|
||||
{
|
||||
// This should never happen
|
||||
// LCOV_EXCL_START
|
||||
UNREACHABLE("xrpl::rangeCheckedCast : domain error");
|
||||
JLOG(debugLog().error())
|
||||
<< "rangeCheckedCast domain error:"
|
||||
<< " value = " << c << " min = " << std::numeric_limits<T>::lowest()
|
||||
<< " max: " << std::numeric_limits<T>::max();
|
||||
// LCOV_EXCL_STOP
|
||||
}
|
||||
|
||||
return static_cast<T>(c);
|
||||
}
|
||||
|
||||
} // namespace xrpl
|
||||
|
||||
#endif
|
||||
@@ -1,11 +1,9 @@
|
||||
#ifndef XRPL_APP_RDB_STATE_H_INCLUDED
|
||||
#define XRPL_APP_RDB_STATE_H_INCLUDED
|
||||
|
||||
#include <xrpld/app/ledger/Ledger.h>
|
||||
#include <xrpld/app/misc/Manifest.h>
|
||||
#include <xrpld/core/Config.h>
|
||||
#include <xrpld/core/DatabaseCon.h>
|
||||
#include <xrpld/peerfinder/detail/Store.h>
|
||||
#include <xrpl/protocol/Protocol.h>
|
||||
#include <xrpl/rdb/DatabaseCon.h>
|
||||
#include <xrpl/server/Manifest.h>
|
||||
|
||||
#include <boost/filesystem.hpp>
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#ifndef XRPL_APP_RDB_VACUUM_H_INCLUDED
|
||||
#define XRPL_APP_RDB_VACUUM_H_INCLUDED
|
||||
|
||||
#include <xrpld/core/DatabaseCon.h>
|
||||
#include <xrpl/rdb/DatabaseCon.h>
|
||||
|
||||
namespace xrpl {
|
||||
|
||||
@@ -1,10 +1,9 @@
|
||||
#ifndef XRPL_APP_RDB_WALLET_H_INCLUDED
|
||||
#define XRPL_APP_RDB_WALLET_H_INCLUDED
|
||||
|
||||
#include <xrpld/app/misc/Manifest.h>
|
||||
#include <xrpld/core/Config.h>
|
||||
#include <xrpld/core/DatabaseCon.h>
|
||||
#include <xrpld/overlay/PeerReservationTable.h>
|
||||
#include <xrpl/core/PeerReservationTable.h>
|
||||
#include <xrpl/rdb/DatabaseCon.h>
|
||||
#include <xrpl/server/Manifest.h>
|
||||
|
||||
namespace xrpl {
|
||||
|
||||
97
src/libxrpl/rdb/DatabaseCon.cpp
Normal file
97
src/libxrpl/rdb/DatabaseCon.cpp
Normal file
@@ -0,0 +1,97 @@
|
||||
#include <xrpl/basics/Log.h>
|
||||
#include <xrpl/basics/contract.h>
|
||||
#include <xrpl/rdb/DatabaseCon.h>
|
||||
#include <xrpl/rdb/SociDB.h>
|
||||
|
||||
#include <boost/algorithm/string.hpp>
|
||||
#include <boost/format.hpp>
|
||||
|
||||
#include <memory>
|
||||
#include <unordered_map>
|
||||
|
||||
namespace xrpl {
|
||||
|
||||
class CheckpointersCollection
|
||||
{
|
||||
std::uintptr_t nextId_{0};
|
||||
// Mutex protects the CheckpointersCollection
|
||||
std::mutex mutex_;
|
||||
// Each checkpointer is given a unique id. All the checkpointers that are
|
||||
// part of a DatabaseCon are part of this collection. When the DatabaseCon
|
||||
// is destroyed, its checkpointer is removed from the collection
|
||||
std::unordered_map<std::uintptr_t, std::shared_ptr<Checkpointer>>
|
||||
checkpointers_;
|
||||
|
||||
public:
|
||||
std::shared_ptr<Checkpointer>
|
||||
fromId(std::uintptr_t id)
|
||||
{
|
||||
std::lock_guard l{mutex_};
|
||||
auto it = checkpointers_.find(id);
|
||||
if (it != checkpointers_.end())
|
||||
return it->second;
|
||||
return {};
|
||||
}
|
||||
|
||||
void
|
||||
erase(std::uintptr_t id)
|
||||
{
|
||||
std::lock_guard lock{mutex_};
|
||||
checkpointers_.erase(id);
|
||||
}
|
||||
|
||||
std::shared_ptr<Checkpointer>
|
||||
create(
|
||||
std::shared_ptr<soci::session> const& session,
|
||||
JobQueue& jobQueue,
|
||||
Logs& logs)
|
||||
{
|
||||
std::lock_guard lock{mutex_};
|
||||
auto const id = nextId_++;
|
||||
auto const r = makeCheckpointer(id, session, jobQueue, logs);
|
||||
checkpointers_[id] = r;
|
||||
return r;
|
||||
}
|
||||
};
|
||||
|
||||
CheckpointersCollection checkpointers;
|
||||
|
||||
std::shared_ptr<Checkpointer>
|
||||
checkpointerFromId(std::uintptr_t id)
|
||||
{
|
||||
return checkpointers.fromId(id);
|
||||
}
|
||||
|
||||
DatabaseCon::~DatabaseCon()
|
||||
{
|
||||
if (checkpointer_)
|
||||
{
|
||||
checkpointers.erase(checkpointer_->id());
|
||||
|
||||
std::weak_ptr<Checkpointer> wk(checkpointer_);
|
||||
checkpointer_.reset();
|
||||
|
||||
// The references to our Checkpointer held by 'checkpointer_' and
|
||||
// 'checkpointers' have been removed, so if the use count is nonzero, a
|
||||
// checkpoint is currently in progress. Wait for it to end, otherwise
|
||||
// creating a new DatabaseCon to the same database may fail due to the
|
||||
// database being locked by our (now old) Checkpointer.
|
||||
while (wk.use_count())
|
||||
{
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(100));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
std::unique_ptr<std::vector<std::string> const>
|
||||
DatabaseCon::Setup::globalPragma;
|
||||
|
||||
void
|
||||
DatabaseCon::setupCheckpointing(JobQueue* q, Logs& l)
|
||||
{
|
||||
if (!q)
|
||||
Throw<std::logic_error>("No JobQueue");
|
||||
checkpointer_ = checkpointers.create(session_, *q, l);
|
||||
}
|
||||
|
||||
} // namespace xrpl
|
||||
@@ -3,12 +3,10 @@
|
||||
#pragma clang diagnostic ignored "-Wdeprecated"
|
||||
#endif
|
||||
|
||||
#include <xrpld/core/Config.h>
|
||||
#include <xrpld/core/DatabaseCon.h>
|
||||
#include <xrpld/core/SociDB.h>
|
||||
|
||||
#include <xrpl/basics/ByteUtilities.h>
|
||||
#include <xrpl/basics/contract.h>
|
||||
#include <xrpl/rdb/DatabaseCon.h>
|
||||
#include <xrpl/rdb/SociDB.h>
|
||||
|
||||
#include <boost/filesystem.hpp>
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#include <xrpld/app/rdb/State.h>
|
||||
#include <xrpl/server/State.h>
|
||||
|
||||
namespace xrpl {
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
#include <xrpld/app/rdb/Vacuum.h>
|
||||
#include <xrpl/server/Vacuum.h>
|
||||
|
||||
#include <boost/format.hpp>
|
||||
|
||||
#include <iostream>
|
||||
|
||||
namespace xrpl {
|
||||
|
||||
bool
|
||||
@@ -1,4 +1,5 @@
|
||||
#include <xrpld/app/rdb/Wallet.h>
|
||||
#include <xrpl/rdb/DBInit.h>
|
||||
#include <xrpl/server/Wallet.h>
|
||||
|
||||
#include <boost/format.hpp>
|
||||
|
||||
@@ -21,7 +21,7 @@ class LedgerLoad_test : public beast::unit_test::suite
|
||||
std::unique_ptr<Config> cfg,
|
||||
std::string const& dbPath,
|
||||
std::string const& ledger,
|
||||
Config::StartUpType type,
|
||||
StartUpType type,
|
||||
std::optional<uint256> trapTxHash)
|
||||
{
|
||||
cfg->START_LEDGER = ledger;
|
||||
@@ -113,7 +113,7 @@ class LedgerLoad_test : public beast::unit_test::suite
|
||||
ledgerConfig,
|
||||
sd.dbPath,
|
||||
sd.ledgerFile,
|
||||
Config::LOAD_FILE,
|
||||
StartUpType::LOAD_FILE,
|
||||
std::nullopt),
|
||||
nullptr,
|
||||
beast::severities::kDisabled);
|
||||
@@ -138,7 +138,7 @@ class LedgerLoad_test : public beast::unit_test::suite
|
||||
ledgerConfig,
|
||||
sd.dbPath,
|
||||
"",
|
||||
Config::LOAD_FILE,
|
||||
StartUpType::LOAD_FILE,
|
||||
std::nullopt),
|
||||
nullptr,
|
||||
beast::severities::kDisabled);
|
||||
@@ -152,7 +152,7 @@ class LedgerLoad_test : public beast::unit_test::suite
|
||||
ledgerConfig,
|
||||
sd.dbPath,
|
||||
"badfile.json",
|
||||
Config::LOAD_FILE,
|
||||
StartUpType::LOAD_FILE,
|
||||
std::nullopt),
|
||||
nullptr,
|
||||
beast::severities::kDisabled);
|
||||
@@ -183,7 +183,7 @@ class LedgerLoad_test : public beast::unit_test::suite
|
||||
ledgerConfig,
|
||||
sd.dbPath,
|
||||
ledgerFileCorrupt.string(),
|
||||
Config::LOAD_FILE,
|
||||
StartUpType::LOAD_FILE,
|
||||
std::nullopt),
|
||||
nullptr,
|
||||
beast::severities::kDisabled);
|
||||
@@ -205,7 +205,7 @@ class LedgerLoad_test : public beast::unit_test::suite
|
||||
ledgerConfig,
|
||||
sd.dbPath,
|
||||
ledgerHash,
|
||||
Config::LOAD,
|
||||
StartUpType::LOAD,
|
||||
std::nullopt),
|
||||
nullptr,
|
||||
beast::severities::kDisabled);
|
||||
@@ -231,7 +231,7 @@ class LedgerLoad_test : public beast::unit_test::suite
|
||||
ledgerConfig,
|
||||
sd.dbPath,
|
||||
ledgerHash,
|
||||
Config::REPLAY,
|
||||
StartUpType::REPLAY,
|
||||
std::nullopt),
|
||||
nullptr,
|
||||
beast::severities::kDisabled);
|
||||
@@ -262,7 +262,7 @@ class LedgerLoad_test : public beast::unit_test::suite
|
||||
ledgerConfig,
|
||||
sd.dbPath,
|
||||
ledgerHash,
|
||||
Config::REPLAY,
|
||||
StartUpType::REPLAY,
|
||||
sd.trapTxHash),
|
||||
nullptr,
|
||||
beast::severities::kDisabled);
|
||||
@@ -297,7 +297,7 @@ class LedgerLoad_test : public beast::unit_test::suite
|
||||
ledgerConfig,
|
||||
sd.dbPath,
|
||||
ledgerHash,
|
||||
Config::REPLAY,
|
||||
StartUpType::REPLAY,
|
||||
~sd.trapTxHash),
|
||||
nullptr,
|
||||
beast::severities::kDisabled);
|
||||
@@ -323,7 +323,11 @@ class LedgerLoad_test : public beast::unit_test::suite
|
||||
Env env(
|
||||
*this,
|
||||
envconfig(
|
||||
ledgerConfig, sd.dbPath, "latest", Config::LOAD, std::nullopt),
|
||||
ledgerConfig,
|
||||
sd.dbPath,
|
||||
"latest",
|
||||
StartUpType::LOAD,
|
||||
std::nullopt),
|
||||
nullptr,
|
||||
beast::severities::kDisabled);
|
||||
auto jrb = env.rpc("ledger", "current", "full")[jss::result];
|
||||
@@ -342,7 +346,7 @@ class LedgerLoad_test : public beast::unit_test::suite
|
||||
Env env(
|
||||
*this,
|
||||
envconfig(
|
||||
ledgerConfig, sd.dbPath, "43", Config::LOAD, std::nullopt),
|
||||
ledgerConfig, sd.dbPath, "43", StartUpType::LOAD, std::nullopt),
|
||||
nullptr,
|
||||
beast::severities::kDisabled);
|
||||
auto jrb = env.rpc("ledger", "current", "full")[jss::result];
|
||||
|
||||
@@ -1,15 +1,15 @@
|
||||
#include <test/jtx.h>
|
||||
|
||||
#include <xrpld/app/main/DBInit.h>
|
||||
#include <xrpld/app/misc/Manifest.h>
|
||||
#include <xrpld/app/misc/ValidatorList.h>
|
||||
#include <xrpld/app/rdb/Wallet.h>
|
||||
|
||||
#include <xrpl/basics/base64.h>
|
||||
#include <xrpl/basics/contract.h>
|
||||
#include <xrpl/protocol/STExchange.h>
|
||||
#include <xrpl/protocol/SecretKey.h>
|
||||
#include <xrpl/protocol/Sign.h>
|
||||
#include <xrpl/rdb/DBInit.h>
|
||||
#include <xrpl/server/Manifest.h>
|
||||
#include <xrpl/server/Wallet.h>
|
||||
|
||||
#include <boost/algorithm/string.hpp>
|
||||
#include <boost/filesystem.hpp>
|
||||
|
||||
@@ -106,8 +106,7 @@ class SHAMapStore_test : public beast::unit_test::suite
|
||||
ledgerCheck(jtx::Env& env, int const rows, int const first)
|
||||
{
|
||||
auto const [actualRows, actualFirst, actualLast] =
|
||||
dynamic_cast<SQLiteDatabase*>(&env.app().getRelationalDatabase())
|
||||
->getLedgerCountMinMax();
|
||||
env.app().getRelationalDatabase().getLedgerCountMinMax();
|
||||
|
||||
BEAST_EXPECT(actualRows == rows);
|
||||
BEAST_EXPECT(actualFirst == first);
|
||||
@@ -118,16 +117,15 @@ class SHAMapStore_test : public beast::unit_test::suite
|
||||
transactionCheck(jtx::Env& env, int const rows)
|
||||
{
|
||||
BEAST_EXPECT(
|
||||
dynamic_cast<SQLiteDatabase*>(&env.app().getRelationalDatabase())
|
||||
->getTransactionCount() == rows);
|
||||
env.app().getRelationalDatabase().getTransactionCount() == rows);
|
||||
}
|
||||
|
||||
void
|
||||
accountTransactionCheck(jtx::Env& env, int const rows)
|
||||
{
|
||||
BEAST_EXPECT(
|
||||
dynamic_cast<SQLiteDatabase*>(&env.app().getRelationalDatabase())
|
||||
->getAccountTransactionCount() == rows);
|
||||
env.app().getRelationalDatabase().getAccountTransactionCount() ==
|
||||
rows);
|
||||
}
|
||||
|
||||
int
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
#include <test/jtx/Env.h>
|
||||
|
||||
#include <xrpld/app/misc/Manifest.h>
|
||||
#include <xrpld/app/misc/ValidatorKeys.h>
|
||||
#include <xrpld/core/Config.h>
|
||||
#include <xrpld/core/ConfigSections.h>
|
||||
|
||||
#include <xrpl/basics/base64.h>
|
||||
#include <xrpl/beast/unit_test.h>
|
||||
#include <xrpl/server/Manifest.h>
|
||||
|
||||
#include <string>
|
||||
|
||||
|
||||
@@ -1,9 +1,8 @@
|
||||
#include <test/jtx/TestSuite.h>
|
||||
|
||||
#include <xrpld/core/SociDB.h>
|
||||
|
||||
#include <xrpl/basics/BasicConfig.h>
|
||||
#include <xrpl/basics/contract.h>
|
||||
#include <xrpl/rdb/SociDB.h>
|
||||
|
||||
#include <boost/algorithm/string.hpp>
|
||||
#include <boost/filesystem.hpp>
|
||||
|
||||
@@ -4,11 +4,10 @@
|
||||
#include <test/nodestore/TestBase.h>
|
||||
#include <test/unit_test/SuiteJournal.h>
|
||||
|
||||
#include <xrpld/core/DatabaseCon.h>
|
||||
|
||||
#include <xrpl/beast/utility/temp_dir.h>
|
||||
#include <xrpl/nodestore/DummyScheduler.h>
|
||||
#include <xrpl/nodestore/Manager.h>
|
||||
#include <xrpl/rdb/DatabaseCon.h>
|
||||
|
||||
namespace xrpl {
|
||||
|
||||
|
||||
@@ -119,8 +119,8 @@ class Transaction_test : public beast::unit_test::suite
|
||||
auto const deletedLedger = (startLegSeq + endLegSeq) / 2;
|
||||
{
|
||||
// Remove one of the ledgers from the database directly
|
||||
dynamic_cast<SQLiteDatabase*>(&env.app().getRelationalDatabase())
|
||||
->deleteTransactionByLedgerSeq(deletedLedger);
|
||||
env.app().getRelationalDatabase().deleteTransactionByLedgerSeq(
|
||||
deletedLedger);
|
||||
}
|
||||
|
||||
for (int deltaEndSeq = 0; deltaEndSeq < 2; ++deltaEndSeq)
|
||||
@@ -376,8 +376,8 @@ class Transaction_test : public beast::unit_test::suite
|
||||
auto const deletedLedger = (startLegSeq + endLegSeq) / 2;
|
||||
{
|
||||
// Remove one of the ledgers from the database directly
|
||||
dynamic_cast<SQLiteDatabase*>(&env.app().getRelationalDatabase())
|
||||
->deleteTransactionByLedgerSeq(deletedLedger);
|
||||
env.app().getRelationalDatabase().deleteTransactionByLedgerSeq(
|
||||
deletedLedger);
|
||||
}
|
||||
|
||||
for (int deltaEndSeq = 0; deltaEndSeq < 2; ++deltaEndSeq)
|
||||
|
||||
@@ -4,10 +4,8 @@
|
||||
#include <xrpld/app/ledger/PendingSaves.h>
|
||||
#include <xrpld/app/main/Application.h>
|
||||
#include <xrpld/app/misc/HashRouter.h>
|
||||
#include <xrpld/app/rdb/backend/SQLiteDatabase.h>
|
||||
#include <xrpld/consensus/LedgerTiming.h>
|
||||
#include <xrpld/core/Config.h>
|
||||
#include <xrpld/core/SociDB.h>
|
||||
|
||||
#include <xrpl/basics/Log.h>
|
||||
#include <xrpl/basics/contract.h>
|
||||
@@ -23,6 +21,7 @@
|
||||
#include <xrpl/protocol/SecretKey.h>
|
||||
#include <xrpl/protocol/digest.h>
|
||||
#include <xrpl/protocol/jss.h>
|
||||
#include <xrpl/rdb/RelationalDatabase.h>
|
||||
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
@@ -962,11 +961,9 @@ saveValidatedLedger(
|
||||
return true;
|
||||
}
|
||||
|
||||
auto const db = dynamic_cast<SQLiteDatabase*>(&app.getRelationalDatabase());
|
||||
if (!db)
|
||||
Throw<std::runtime_error>("Failed to get relational database");
|
||||
auto& db = app.getRelationalDatabase();
|
||||
|
||||
auto const res = db->saveValidatedLedger(ledger, current);
|
||||
auto const res = db.saveValidatedLedger(ledger, current);
|
||||
|
||||
// Clients can now trust the database for
|
||||
// information about this ledger sequence.
|
||||
|
||||
@@ -14,7 +14,6 @@
|
||||
#include <xrpld/app/misc/TxQ.h>
|
||||
#include <xrpld/app/misc/ValidatorList.h>
|
||||
#include <xrpld/app/paths/PathRequests.h>
|
||||
#include <xrpld/app/rdb/RelationalDatabase.h>
|
||||
#include <xrpld/core/TimeKeeper.h>
|
||||
#include <xrpld/overlay/Overlay.h>
|
||||
#include <xrpld/overlay/Peer.h>
|
||||
@@ -29,6 +28,7 @@
|
||||
#include <xrpl/protocol/BuildInfo.h>
|
||||
#include <xrpl/protocol/HashPrefix.h>
|
||||
#include <xrpl/protocol/digest.h>
|
||||
#include <xrpl/rdb/RelationalDatabase.h>
|
||||
#include <xrpl/resource/Fees.h>
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
@@ -11,7 +11,6 @@
|
||||
#include <xrpld/app/ledger/TransactionMaster.h>
|
||||
#include <xrpld/app/main/Application.h>
|
||||
#include <xrpld/app/main/BasicApp.h>
|
||||
#include <xrpld/app/main/DBInit.h>
|
||||
#include <xrpld/app/main/GRPCServer.h>
|
||||
#include <xrpld/app/main/LoadManager.h>
|
||||
#include <xrpld/app/main/NodeIdentity.h>
|
||||
@@ -25,12 +24,10 @@
|
||||
#include <xrpld/app/misc/ValidatorKeys.h>
|
||||
#include <xrpld/app/misc/ValidatorSite.h>
|
||||
#include <xrpld/app/paths/PathRequests.h>
|
||||
#include <xrpld/app/rdb/RelationalDatabase.h>
|
||||
#include <xrpld/app/rdb/Wallet.h>
|
||||
#include <xrpld/app/rdb/backend/SQLiteDatabase.h>
|
||||
#include <xrpld/app/tx/apply.h>
|
||||
#include <xrpld/core/DatabaseCon.h>
|
||||
#include <xrpld/core/ServiceRegistryImpl.h>
|
||||
#include <xrpld/overlay/Cluster.h>
|
||||
#include <xrpld/overlay/PeerReservationTable.h>
|
||||
#include <xrpld/overlay/PeerSet.h>
|
||||
#include <xrpld/overlay/make_Overlay.h>
|
||||
#include <xrpld/shamap/NodeFamily.h>
|
||||
@@ -40,6 +37,7 @@
|
||||
#include <xrpl/basics/random.h>
|
||||
#include <xrpl/beast/asio/io_latency_probe.h>
|
||||
#include <xrpl/beast/core/LexicalCast.h>
|
||||
#include <xrpl/core/PeerReservationTable.h>
|
||||
#include <xrpl/core/PerfLog.h>
|
||||
#include <xrpl/crypto/csprng.h>
|
||||
#include <xrpl/json/json_reader.h>
|
||||
@@ -49,7 +47,9 @@
|
||||
#include <xrpl/protocol/Feature.h>
|
||||
#include <xrpl/protocol/Protocol.h>
|
||||
#include <xrpl/protocol/STParsedJSON.h>
|
||||
#include <xrpl/rdb/DatabaseCon.h>
|
||||
#include <xrpl/resource/Fees.h>
|
||||
#include <xrpl/server/Wallet.h>
|
||||
|
||||
#include <boost/algorithm/string/predicate.hpp>
|
||||
#include <boost/asio/steady_timer.hpp>
|
||||
@@ -150,6 +150,10 @@ public:
|
||||
std::unique_ptr<perf::PerfLog> perfLog_;
|
||||
Application::MutexType m_masterMutex;
|
||||
|
||||
// ServiceRegistry implementation that delegates to this Application
|
||||
// Must be declared before m_txMaster since TransactionMaster needs it
|
||||
std::unique_ptr<ServiceRegistryImpl> serviceRegistry_;
|
||||
|
||||
// Required by the SHAMapStore
|
||||
TransactionMaster m_txMaster;
|
||||
|
||||
@@ -196,7 +200,7 @@ public:
|
||||
boost::asio::steady_timer sweepTimer_;
|
||||
boost::asio::steady_timer entropyTimer_;
|
||||
|
||||
std::unique_ptr<RelationalDatabase> mRelationalDatabase;
|
||||
std::unique_ptr<SQLiteDatabase> relationalDatabase_;
|
||||
std::unique_ptr<DatabaseCon> mWalletDB;
|
||||
std::unique_ptr<Overlay> overlay_;
|
||||
std::optional<uint256> trapTxID_;
|
||||
@@ -267,6 +271,8 @@ public:
|
||||
logs_->journal("PerfLog"),
|
||||
[this] { signalStop("PerfLog"); }))
|
||||
|
||||
, serviceRegistry_(std::make_unique<ServiceRegistryImpl>(*this))
|
||||
|
||||
, m_txMaster(*this)
|
||||
|
||||
, m_collectorManager(make_CollectorManager(
|
||||
@@ -793,10 +799,10 @@ public:
|
||||
getRelationalDatabase() override
|
||||
{
|
||||
XRPL_ASSERT(
|
||||
mRelationalDatabase,
|
||||
relationalDatabase_,
|
||||
"xrpl::ApplicationImp::getRelationalDatabase : non-null "
|
||||
"relational database");
|
||||
return *mRelationalDatabase;
|
||||
return *relationalDatabase_;
|
||||
}
|
||||
|
||||
DatabaseCon&
|
||||
@@ -808,6 +814,16 @@ public:
|
||||
return *mWalletDB;
|
||||
}
|
||||
|
||||
ServiceRegistry&
|
||||
getServiceRegistry() override
|
||||
{
|
||||
XRPL_ASSERT(
|
||||
serviceRegistry_,
|
||||
"xrpl::ApplicationImp::getServiceRegistry : non-null service "
|
||||
"registry");
|
||||
return *serviceRegistry_;
|
||||
}
|
||||
|
||||
bool
|
||||
serverOkay(std::string& reason) override;
|
||||
|
||||
@@ -826,8 +842,8 @@ public:
|
||||
|
||||
try
|
||||
{
|
||||
mRelationalDatabase =
|
||||
RelationalDatabase::init(*this, *config_, *m_jobQueue);
|
||||
relationalDatabase_ = setup_RelationalDatabase(
|
||||
getServiceRegistry(), *config_, *m_jobQueue);
|
||||
|
||||
// wallet database
|
||||
auto setup = setup_DatabaseCon(*config_, m_journal);
|
||||
@@ -953,7 +969,7 @@ public:
|
||||
doSweep()
|
||||
{
|
||||
if (!config_->standalone() &&
|
||||
!getRelationalDatabase().transactionDbHasSpace(*config_))
|
||||
!relationalDatabase_->transactionDbHasSpace(*config_))
|
||||
{
|
||||
signalStop("Out of transaction DB space");
|
||||
}
|
||||
@@ -1247,22 +1263,22 @@ ApplicationImp::setup(boost::program_options::variables_map const& cmdline)
|
||||
|
||||
auto const startUp = config_->START_UP;
|
||||
JLOG(m_journal.debug()) << "startUp: " << startUp;
|
||||
if (startUp == Config::FRESH)
|
||||
if (startUp == StartUpType::FRESH)
|
||||
{
|
||||
JLOG(m_journal.info()) << "Starting new Ledger";
|
||||
|
||||
startGenesisLedger();
|
||||
}
|
||||
else if (
|
||||
startUp == Config::LOAD || startUp == Config::LOAD_FILE ||
|
||||
startUp == Config::REPLAY)
|
||||
startUp == StartUpType::LOAD || startUp == StartUpType::LOAD_FILE ||
|
||||
startUp == StartUpType::REPLAY)
|
||||
{
|
||||
JLOG(m_journal.info()) << "Loading specified Ledger";
|
||||
|
||||
if (!loadOldLedger(
|
||||
config_->START_LEDGER,
|
||||
startUp == Config::REPLAY,
|
||||
startUp == Config::LOAD_FILE,
|
||||
startUp == StartUpType::REPLAY,
|
||||
startUp == StartUpType::LOAD_FILE,
|
||||
config_->TRAP_TX_HASH))
|
||||
{
|
||||
JLOG(m_journal.error())
|
||||
@@ -1279,7 +1295,7 @@ ApplicationImp::setup(boost::program_options::variables_map const& cmdline)
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (startUp == Config::NETWORK)
|
||||
else if (startUp == StartUpType::NETWORK)
|
||||
{
|
||||
// This should probably become the default once we have a stable
|
||||
// network.
|
||||
@@ -1687,8 +1703,9 @@ void
|
||||
ApplicationImp::startGenesisLedger()
|
||||
{
|
||||
std::vector<uint256> const initialAmendments =
|
||||
(config_->START_UP == Config::FRESH) ? m_amendmentTable->getDesired()
|
||||
: std::vector<uint256>{};
|
||||
(config_->START_UP == StartUpType::FRESH)
|
||||
? m_amendmentTable->getDesired()
|
||||
: std::vector<uint256>{};
|
||||
|
||||
std::shared_ptr<Ledger> const genesis = std::make_shared<Ledger>(
|
||||
create_genesis, *config_, initialAmendments, nodeFamily_);
|
||||
|
||||
@@ -2,10 +2,11 @@
|
||||
#define XRPL_APP_MAIN_APPLICATION_H_INCLUDED
|
||||
|
||||
#include <xrpld/core/Config.h>
|
||||
#include <xrpld/overlay/PeerReservationTable.h>
|
||||
|
||||
#include <xrpl/basics/TaggedCache.h>
|
||||
#include <xrpl/beast/utility/PropertyStream.h>
|
||||
#include <xrpl/core/PeerReservationTable.h>
|
||||
#include <xrpl/core/ServiceRegistry.h>
|
||||
#include <xrpl/protocol/Protocol.h>
|
||||
#include <xrpl/shamap/TreeNodeCache.h>
|
||||
|
||||
@@ -256,6 +257,9 @@ public:
|
||||
|
||||
virtual std::optional<uint256> const&
|
||||
trapTxID() const = 0;
|
||||
|
||||
virtual ServiceRegistry&
|
||||
getServiceRegistry() = 0;
|
||||
};
|
||||
|
||||
std::unique_ptr<Application>
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
#include <xrpld/app/main/Application.h>
|
||||
#include <xrpld/app/rdb/Vacuum.h>
|
||||
#include <xrpld/core/Config.h>
|
||||
#include <xrpld/core/ConfigSections.h>
|
||||
#include <xrpld/core/TimeKeeper.h>
|
||||
@@ -8,6 +7,7 @@
|
||||
#include <xrpl/basics/Log.h>
|
||||
#include <xrpl/beast/core/CurrentThreadName.h>
|
||||
#include <xrpl/protocol/BuildInfo.h>
|
||||
#include <xrpl/server/Vacuum.h>
|
||||
|
||||
#include <boost/asio/io_context.hpp>
|
||||
#include <boost/process/v1/args.hpp>
|
||||
@@ -642,7 +642,7 @@ run(int argc, char** argv)
|
||||
|
||||
if (vm.count("start"))
|
||||
{
|
||||
config->START_UP = Config::FRESH;
|
||||
config->START_UP = StartUpType::FRESH;
|
||||
}
|
||||
|
||||
if (vm.count("import"))
|
||||
@@ -653,7 +653,7 @@ run(int argc, char** argv)
|
||||
config->START_LEDGER = vm["ledger"].as<std::string>();
|
||||
if (vm.count("replay"))
|
||||
{
|
||||
config->START_UP = Config::REPLAY;
|
||||
config->START_UP = StartUpType::REPLAY;
|
||||
if (vm.count("trap_tx_hash"))
|
||||
{
|
||||
uint256 tmp = {};
|
||||
@@ -672,16 +672,16 @@ run(int argc, char** argv)
|
||||
}
|
||||
}
|
||||
else
|
||||
config->START_UP = Config::LOAD;
|
||||
config->START_UP = StartUpType::LOAD;
|
||||
}
|
||||
else if (vm.count("ledgerfile"))
|
||||
{
|
||||
config->START_LEDGER = vm["ledgerfile"].as<std::string>();
|
||||
config->START_UP = Config::LOAD_FILE;
|
||||
config->START_UP = StartUpType::LOAD_FILE;
|
||||
}
|
||||
else if (vm.count("load") || config->FAST_LOAD)
|
||||
{
|
||||
config->START_UP = Config::LOAD;
|
||||
config->START_UP = StartUpType::LOAD;
|
||||
}
|
||||
|
||||
if (vm.count("trap_tx_hash") && vm.count("replay") == 0)
|
||||
@@ -693,15 +693,15 @@ run(int argc, char** argv)
|
||||
|
||||
if (vm.count("net") && !config->FAST_LOAD)
|
||||
{
|
||||
if ((config->START_UP == Config::LOAD) ||
|
||||
(config->START_UP == Config::REPLAY))
|
||||
if ((config->START_UP == StartUpType::LOAD) ||
|
||||
(config->START_UP == StartUpType::REPLAY))
|
||||
{
|
||||
std::cerr << "Net and load/replay options are incompatible"
|
||||
<< std::endl;
|
||||
return -1;
|
||||
}
|
||||
|
||||
config->START_UP = Config::NETWORK;
|
||||
config->START_UP = StartUpType::NETWORK;
|
||||
}
|
||||
|
||||
if (vm.count("valid"))
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
#include <xrpld/app/main/Application.h>
|
||||
#include <xrpld/app/main/NodeIdentity.h>
|
||||
#include <xrpld/app/rdb/Wallet.h>
|
||||
#include <xrpld/core/Config.h>
|
||||
#include <xrpld/core/ConfigSections.h>
|
||||
|
||||
#include <xrpl/server/Wallet.h>
|
||||
|
||||
namespace xrpl {
|
||||
|
||||
std::pair<PublicKey, SecretKey>
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
#include <xrpld/app/ledger/TransactionMaster.h>
|
||||
#include <xrpld/app/misc/NetworkOPs.h>
|
||||
#include <xrpld/app/misc/SHAMapStoreImp.h>
|
||||
#include <xrpld/app/rdb/State.h>
|
||||
#include <xrpld/app/rdb/backend/SQLiteDatabase.h>
|
||||
#include <xrpld/core/ConfigSections.h>
|
||||
|
||||
#include <xrpl/beast/core/CurrentThreadName.h>
|
||||
#include <xrpl/nodestore/Scheduler.h>
|
||||
#include <xrpl/nodestore/detail/DatabaseRotatingImp.h>
|
||||
#include <xrpl/server/State.h>
|
||||
#include <xrpl/shamap/SHAMapMissingNode.h>
|
||||
|
||||
#include <boost/algorithm/string/predicate.hpp>
|
||||
@@ -570,17 +570,13 @@ SHAMapStoreImp::clearPrior(LedgerIndex lastRotated)
|
||||
if (healthWait() == stopping)
|
||||
return;
|
||||
|
||||
SQLiteDatabase* const db =
|
||||
dynamic_cast<SQLiteDatabase*>(&app_.getRelationalDatabase());
|
||||
|
||||
if (!db)
|
||||
Throw<std::runtime_error>("Failed to get relational database");
|
||||
auto& db = app_.getRelationalDatabase();
|
||||
|
||||
clearSql(
|
||||
lastRotated,
|
||||
"Ledgers",
|
||||
[db]() -> std::optional<LedgerIndex> { return db->getMinLedgerSeq(); },
|
||||
[db](LedgerIndex min) -> void { db->deleteBeforeLedgerSeq(min); });
|
||||
[&db]() -> std::optional<LedgerIndex> { return db.getMinLedgerSeq(); },
|
||||
[&db](LedgerIndex min) -> void { db.deleteBeforeLedgerSeq(min); });
|
||||
if (healthWait() == stopping)
|
||||
return;
|
||||
|
||||
@@ -591,10 +587,10 @@ SHAMapStoreImp::clearPrior(LedgerIndex lastRotated)
|
||||
lastRotated,
|
||||
"Transactions",
|
||||
[&db]() -> std::optional<LedgerIndex> {
|
||||
return db->getTransactionsMinLedgerSeq();
|
||||
return db.getTransactionsMinLedgerSeq();
|
||||
},
|
||||
[&db](LedgerIndex min) -> void {
|
||||
db->deleteTransactionsBeforeLedgerSeq(min);
|
||||
db.deleteTransactionsBeforeLedgerSeq(min);
|
||||
});
|
||||
if (healthWait() == stopping)
|
||||
return;
|
||||
@@ -603,10 +599,10 @@ SHAMapStoreImp::clearPrior(LedgerIndex lastRotated)
|
||||
lastRotated,
|
||||
"AccountTransactions",
|
||||
[&db]() -> std::optional<LedgerIndex> {
|
||||
return db->getAccountTransactionsMinLedgerSeq();
|
||||
return db.getAccountTransactionsMinLedgerSeq();
|
||||
},
|
||||
[&db](LedgerIndex min) -> void {
|
||||
db->deleteAccountTransactionsBeforeLedgerSeq(min);
|
||||
db.deleteAccountTransactionsBeforeLedgerSeq(min);
|
||||
});
|
||||
if (healthWait() == stopping)
|
||||
return;
|
||||
|
||||
@@ -3,11 +3,11 @@
|
||||
|
||||
#include <xrpld/app/ledger/LedgerMaster.h>
|
||||
#include <xrpld/app/misc/SHAMapStore.h>
|
||||
#include <xrpld/app/rdb/State.h>
|
||||
#include <xrpld/core/DatabaseCon.h>
|
||||
|
||||
#include <xrpl/nodestore/DatabaseRotating.h>
|
||||
#include <xrpl/nodestore/Scheduler.h>
|
||||
#include <xrpl/rdb/DatabaseCon.h>
|
||||
#include <xrpl/server/State.h>
|
||||
|
||||
#include <atomic>
|
||||
#include <chrono>
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
#include <xrpl/protocol/STTx.h>
|
||||
#include <xrpl/protocol/TER.h>
|
||||
#include <xrpl/protocol/TxMeta.h>
|
||||
#include <xrpl/protocol/TxSearched.h>
|
||||
|
||||
#include <optional>
|
||||
#include <variant>
|
||||
@@ -36,8 +37,6 @@ enum TransStatus {
|
||||
INCOMPLETE = 8 // needs more signatures
|
||||
};
|
||||
|
||||
enum class TxSearched { all, some, unknown };
|
||||
|
||||
// This class is for constructing and examining transactions.
|
||||
// Transactions are static so manipulation functions are unnecessary.
|
||||
class Transaction : public std::enable_shared_from_this<Transaction>,
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
#ifndef XRPL_APP_MISC_VALIDATORLIST_H_INCLUDED
|
||||
#define XRPL_APP_MISC_VALIDATORLIST_H_INCLUDED
|
||||
|
||||
#include <xrpld/app/misc/Manifest.h>
|
||||
#include <xrpld/core/TimeKeeper.h>
|
||||
#include <xrpld/overlay/Message.h>
|
||||
|
||||
@@ -10,6 +9,7 @@
|
||||
#include <xrpl/crypto/csprng.h>
|
||||
#include <xrpl/json/json_value.h>
|
||||
#include <xrpl/protocol/PublicKey.h>
|
||||
#include <xrpl/server/Manifest.h>
|
||||
|
||||
#include <boost/thread/shared_mutex.hpp>
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#ifndef XRPL_APP_MISC_IMPL_ACCOUNTTXPAGING_H_INCLUDED
|
||||
#define XRPL_APP_MISC_IMPL_ACCOUNTTXPAGING_H_INCLUDED
|
||||
|
||||
#include <xrpld/app/rdb/RelationalDatabase.h>
|
||||
#include <xrpl/rdb/RelationalDatabase.h>
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
#include <xrpld/app/main/Application.h>
|
||||
#include <xrpld/app/misc/AmendmentTable.h>
|
||||
#include <xrpld/app/rdb/Wallet.h>
|
||||
#include <xrpld/core/ConfigSections.h>
|
||||
|
||||
#include <xrpl/protocol/Feature.h>
|
||||
#include <xrpl/protocol/STValidation.h>
|
||||
#include <xrpl/protocol/TxFlags.h>
|
||||
#include <xrpl/protocol/jss.h>
|
||||
#include <xrpl/server/Wallet.h>
|
||||
|
||||
#include <boost/algorithm/string.hpp>
|
||||
#include <boost/format.hpp>
|
||||
|
||||
@@ -1,13 +1,12 @@
|
||||
#include <xrpld/app/misc/Manifest.h>
|
||||
#include <xrpld/app/rdb/Wallet.h>
|
||||
#include <xrpld/core/DatabaseCon.h>
|
||||
|
||||
#include <xrpl/basics/Log.h>
|
||||
#include <xrpl/basics/StringUtilities.h>
|
||||
#include <xrpl/basics/base64.h>
|
||||
#include <xrpl/json/json_reader.h>
|
||||
#include <xrpl/protocol/PublicKey.h>
|
||||
#include <xrpl/protocol/Sign.h>
|
||||
#include <xrpl/rdb/DatabaseCon.h>
|
||||
#include <xrpl/server/Manifest.h>
|
||||
#include <xrpl/server/Wallet.h>
|
||||
|
||||
#include <boost/algorithm/string/trim.hpp>
|
||||
|
||||
|
||||
@@ -2,13 +2,13 @@
|
||||
#include <xrpld/app/main/Application.h>
|
||||
#include <xrpld/app/misc/HashRouter.h>
|
||||
#include <xrpld/app/misc/Transaction.h>
|
||||
#include <xrpld/app/rdb/backend/SQLiteDatabase.h>
|
||||
#include <xrpld/app/tx/apply.h>
|
||||
#include <xrpld/rpc/CTID.h>
|
||||
|
||||
#include <xrpl/basics/safe_cast.h>
|
||||
#include <xrpl/protocol/ErrorCodes.h>
|
||||
#include <xrpl/protocol/jss.h>
|
||||
#include <xrpl/rdb/RelationalDatabase.h>
|
||||
|
||||
namespace xrpl {
|
||||
|
||||
@@ -127,14 +127,9 @@ Transaction::load(
|
||||
std::optional<ClosedInterval<uint32_t>> const& range,
|
||||
error_code_i& ec)
|
||||
{
|
||||
auto const db = dynamic_cast<SQLiteDatabase*>(&app.getRelationalDatabase());
|
||||
auto& db = app.getRelationalDatabase();
|
||||
|
||||
if (!db)
|
||||
{
|
||||
Throw<std::runtime_error>("Failed to get relational database");
|
||||
}
|
||||
|
||||
return db->getTransaction(id, range, ec);
|
||||
return db.getTransaction(id, range, ec);
|
||||
}
|
||||
|
||||
// options 1 to include the date of the transaction
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
#include <xrpld/app/misc/Manifest.h>
|
||||
#include <xrpld/app/misc/ValidatorKeys.h>
|
||||
#include <xrpld/core/Config.h>
|
||||
#include <xrpld/core/ConfigSections.h>
|
||||
|
||||
#include <xrpl/basics/Log.h>
|
||||
#include <xrpl/basics/base64.h>
|
||||
#include <xrpl/server/Manifest.h>
|
||||
|
||||
namespace xrpl {
|
||||
ValidatorKeys::ValidatorKeys(Config const& config, beast::Journal j)
|
||||
|
||||
@@ -2,9 +2,10 @@
|
||||
#define XRPL_APP_RDB_PEERFINDER_H_INCLUDED
|
||||
|
||||
#include <xrpld/core/Config.h>
|
||||
#include <xrpld/core/DatabaseCon.h>
|
||||
#include <xrpld/peerfinder/detail/Store.h>
|
||||
|
||||
#include <xrpl/rdb/DatabaseCon.h>
|
||||
|
||||
namespace xrpl {
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,234 +0,0 @@
|
||||
#ifndef XRPL_APP_RDB_RELATIONALDATABASE_H_INCLUDED
|
||||
#define XRPL_APP_RDB_RELATIONALDATABASE_H_INCLUDED
|
||||
|
||||
#include <xrpld/app/ledger/Ledger.h>
|
||||
#include <xrpld/app/main/Application.h>
|
||||
#include <xrpld/app/misc/Transaction.h>
|
||||
#include <xrpld/core/Config.h>
|
||||
#include <xrpld/core/DatabaseCon.h>
|
||||
#include <xrpld/rpc/detail/RPCLedgerHelpers.h>
|
||||
|
||||
#include <xrpl/beast/utility/instrumentation.h>
|
||||
|
||||
#include <boost/filesystem.hpp>
|
||||
#include <boost/variant.hpp>
|
||||
|
||||
namespace xrpl {
|
||||
|
||||
struct LedgerHashPair
|
||||
{
|
||||
uint256 ledgerHash;
|
||||
uint256 parentHash;
|
||||
};
|
||||
|
||||
struct LedgerRange
|
||||
{
|
||||
uint32_t min;
|
||||
uint32_t max;
|
||||
};
|
||||
|
||||
class RelationalDatabase
|
||||
{
|
||||
public:
|
||||
struct CountMinMax
|
||||
{
|
||||
std::size_t numberOfRows;
|
||||
LedgerIndex minLedgerSequence;
|
||||
LedgerIndex maxLedgerSequence;
|
||||
};
|
||||
|
||||
struct AccountTxMarker
|
||||
{
|
||||
std::uint32_t ledgerSeq = 0;
|
||||
std::uint32_t txnSeq = 0;
|
||||
};
|
||||
|
||||
struct AccountTxOptions
|
||||
{
|
||||
AccountID const& account;
|
||||
std::uint32_t minLedger;
|
||||
std::uint32_t maxLedger;
|
||||
std::uint32_t offset;
|
||||
std::uint32_t limit;
|
||||
bool bUnlimited;
|
||||
};
|
||||
|
||||
struct AccountTxPageOptions
|
||||
{
|
||||
AccountID const& account;
|
||||
std::uint32_t minLedger;
|
||||
std::uint32_t maxLedger;
|
||||
std::optional<AccountTxMarker> marker;
|
||||
std::uint32_t limit;
|
||||
bool bAdmin;
|
||||
};
|
||||
|
||||
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>;
|
||||
|
||||
struct AccountTxArgs
|
||||
{
|
||||
AccountID account;
|
||||
std::optional<LedgerSpecifier> ledger;
|
||||
bool binary = false;
|
||||
bool forward = false;
|
||||
uint32_t limit = 0;
|
||||
std::optional<AccountTxMarker> marker;
|
||||
};
|
||||
|
||||
struct AccountTxResult
|
||||
{
|
||||
std::variant<AccountTxs, MetaTxsList> transactions;
|
||||
LedgerRange ledgerRange;
|
||||
uint32_t limit;
|
||||
std::optional<AccountTxMarker> marker;
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief init Creates and returns an appropriate RelationalDatabase
|
||||
* instance based on configuration.
|
||||
* @param app Application object.
|
||||
* @param config Config object.
|
||||
* @param jobQueue JobQueue object.
|
||||
* @return Unique pointer to the interface.
|
||||
*/
|
||||
static std::unique_ptr<RelationalDatabase>
|
||||
init(Application& app, Config const& config, JobQueue& jobQueue);
|
||||
|
||||
virtual ~RelationalDatabase() = default;
|
||||
|
||||
/**
|
||||
* @brief getMinLedgerSeq Returns the minimum ledger sequence in the Ledgers
|
||||
* table.
|
||||
* @return Ledger sequence or no value if no ledgers exist.
|
||||
*/
|
||||
virtual std::optional<LedgerIndex>
|
||||
getMinLedgerSeq() = 0;
|
||||
|
||||
/**
|
||||
* @brief getMaxLedgerSeq Returns the maximum ledger sequence in the Ledgers
|
||||
* table.
|
||||
* @return Ledger sequence or none if no ledgers exist.
|
||||
*/
|
||||
virtual std::optional<LedgerIndex>
|
||||
getMaxLedgerSeq() = 0;
|
||||
|
||||
/**
|
||||
* @brief getLedgerInfoByIndex Returns a ledger by its sequence.
|
||||
* @param ledgerSeq Ledger sequence.
|
||||
* @return The ledger if found, otherwise no value.
|
||||
*/
|
||||
virtual std::optional<LedgerHeader>
|
||||
getLedgerInfoByIndex(LedgerIndex ledgerSeq) = 0;
|
||||
|
||||
/**
|
||||
* @brief getNewestLedgerInfo Returns the info of the newest saved ledger.
|
||||
* @return Ledger info if found, otherwise no value.
|
||||
*/
|
||||
virtual std::optional<LedgerHeader>
|
||||
getNewestLedgerInfo() = 0;
|
||||
|
||||
/**
|
||||
* @brief getLedgerInfoByHash Returns the info of the ledger with given
|
||||
* hash.
|
||||
* @param ledgerHash Hash of the ledger.
|
||||
* @return Ledger if found, otherwise no value.
|
||||
*/
|
||||
virtual std::optional<LedgerHeader>
|
||||
getLedgerInfoByHash(uint256 const& ledgerHash) = 0;
|
||||
|
||||
/**
|
||||
* @brief getHashByIndex Returns the hash of the ledger with the given
|
||||
* sequence.
|
||||
* @param ledgerIndex Ledger sequence.
|
||||
* @return Hash of the ledger.
|
||||
*/
|
||||
virtual uint256
|
||||
getHashByIndex(LedgerIndex ledgerIndex) = 0;
|
||||
|
||||
/**
|
||||
* @brief getHashesByIndex Returns the hashes of the ledger and its parent
|
||||
* as specified by the ledgerIndex.
|
||||
* @param ledgerIndex Ledger sequence.
|
||||
* @return Struct LedgerHashPair which contains hashes of the ledger and
|
||||
* its parent.
|
||||
*/
|
||||
virtual std::optional<LedgerHashPair>
|
||||
getHashesByIndex(LedgerIndex ledgerIndex) = 0;
|
||||
|
||||
/**
|
||||
* @brief getHashesByIndex Returns hashes of each ledger and its parent for
|
||||
* all ledgers within the provided range.
|
||||
* @param minSeq Minimum ledger sequence.
|
||||
* @param maxSeq Maximum ledger sequence.
|
||||
* @return Container that maps the sequence number of a found ledger to the
|
||||
* struct LedgerHashPair which contains the hashes of the ledger and
|
||||
* its parent.
|
||||
*/
|
||||
virtual std::map<LedgerIndex, LedgerHashPair>
|
||||
getHashesByIndex(LedgerIndex minSeq, LedgerIndex maxSeq) = 0;
|
||||
|
||||
/**
|
||||
* @brief getTxHistory Returns the 20 most recent transactions starting from
|
||||
* the given number.
|
||||
* @param startIndex First number of returned entry.
|
||||
* @return Vector of shared pointers to transactions sorted in
|
||||
* descending order by ledger sequence.
|
||||
*/
|
||||
virtual std::vector<std::shared_ptr<Transaction>>
|
||||
getTxHistory(LedgerIndex startIndex) = 0;
|
||||
|
||||
/**
|
||||
* @brief ledgerDbHasSpace Checks if the ledger database has available
|
||||
* space.
|
||||
* @param config Config object.
|
||||
* @return True if space is available.
|
||||
*/
|
||||
virtual bool
|
||||
ledgerDbHasSpace(Config const& config) = 0;
|
||||
|
||||
/**
|
||||
* @brief transactionDbHasSpace Checks if the transaction database has
|
||||
* available space.
|
||||
* @param config Config object.
|
||||
* @return True if space is available.
|
||||
*/
|
||||
virtual bool
|
||||
transactionDbHasSpace(Config const& config) = 0;
|
||||
};
|
||||
|
||||
template <class T, class C>
|
||||
T
|
||||
rangeCheckedCast(C c)
|
||||
{
|
||||
if ((c > std::numeric_limits<T>::max()) ||
|
||||
(!std::numeric_limits<T>::is_signed && c < 0) ||
|
||||
(std::numeric_limits<T>::is_signed &&
|
||||
std::numeric_limits<C>::is_signed &&
|
||||
c < std::numeric_limits<T>::lowest()))
|
||||
{
|
||||
// This should never happen
|
||||
// LCOV_EXCL_START
|
||||
UNREACHABLE("xrpl::rangeCheckedCast : domain error");
|
||||
JLOG(debugLog().error())
|
||||
<< "rangeCheckedCast domain error:"
|
||||
<< " value = " << c << " min = " << std::numeric_limits<T>::lowest()
|
||||
<< " max: " << std::numeric_limits<T>::max();
|
||||
// LCOV_EXCL_STOP
|
||||
}
|
||||
|
||||
return static_cast<T>(c);
|
||||
}
|
||||
|
||||
} // namespace xrpl
|
||||
|
||||
#endif
|
||||
@@ -1,11 +1,17 @@
|
||||
#ifndef XRPL_APP_RDB_BACKEND_SQLITEDATABASE_H_INCLUDED
|
||||
#define XRPL_APP_RDB_BACKEND_SQLITEDATABASE_H_INCLUDED
|
||||
|
||||
#include <xrpld/app/rdb/RelationalDatabase.h>
|
||||
#include <xrpl/rdb/RelationalDatabase.h>
|
||||
|
||||
#include <memory>
|
||||
|
||||
namespace xrpl {
|
||||
|
||||
class SQLiteDatabase : public RelationalDatabase
|
||||
class Config;
|
||||
class JobQueue;
|
||||
class ServiceRegistry;
|
||||
|
||||
class SQLiteDatabase final : public RelationalDatabase
|
||||
{
|
||||
public:
|
||||
/**
|
||||
@@ -13,32 +19,32 @@ public:
|
||||
* stored in the Transactions table.
|
||||
* @return Ledger sequence or no value if no ledgers exist.
|
||||
*/
|
||||
virtual std::optional<LedgerIndex>
|
||||
getTransactionsMinLedgerSeq() = 0;
|
||||
std::optional<LedgerIndex>
|
||||
getTransactionsMinLedgerSeq() override;
|
||||
|
||||
/**
|
||||
* @brief getAccountTransactionsMinLedgerSeq Returns the minimum ledger
|
||||
* sequence stored in the AccountTransactions table.
|
||||
* @return Ledger sequence or no value if no ledgers exist.
|
||||
*/
|
||||
virtual std::optional<LedgerIndex>
|
||||
getAccountTransactionsMinLedgerSeq() = 0;
|
||||
std::optional<LedgerIndex>
|
||||
getAccountTransactionsMinLedgerSeq() override;
|
||||
|
||||
/**
|
||||
* @brief deleteTransactionByLedgerSeq Deletes transactions from the ledger
|
||||
* with the given sequence.
|
||||
* @param ledgerSeq Ledger sequence.
|
||||
*/
|
||||
virtual void
|
||||
deleteTransactionByLedgerSeq(LedgerIndex ledgerSeq) = 0;
|
||||
void
|
||||
deleteTransactionByLedgerSeq(LedgerIndex ledgerSeq) override;
|
||||
|
||||
/**
|
||||
* @brief deleteBeforeLedgerSeq Deletes all ledgers with a sequence number
|
||||
* less than or equal to the given ledger sequence.
|
||||
* @param ledgerSeq Ledger sequence.
|
||||
*/
|
||||
virtual void
|
||||
deleteBeforeLedgerSeq(LedgerIndex ledgerSeq) = 0;
|
||||
void
|
||||
deleteBeforeLedgerSeq(LedgerIndex ledgerSeq) override;
|
||||
|
||||
/**
|
||||
* @brief deleteTransactionsBeforeLedgerSeq Deletes all transactions with
|
||||
@@ -46,8 +52,8 @@ public:
|
||||
* sequence.
|
||||
* @param ledgerSeq Ledger sequence.
|
||||
*/
|
||||
virtual void
|
||||
deleteTransactionsBeforeLedgerSeq(LedgerIndex ledgerSeq) = 0;
|
||||
void
|
||||
deleteTransactionsBeforeLedgerSeq(LedgerIndex ledgerSeq) override;
|
||||
|
||||
/**
|
||||
* @brief deleteAccountTransactionsBeforeLedgerSeq Deletes all account
|
||||
@@ -55,23 +61,23 @@ public:
|
||||
* given ledger sequence.
|
||||
* @param ledgerSeq Ledger sequence.
|
||||
*/
|
||||
virtual void
|
||||
deleteAccountTransactionsBeforeLedgerSeq(LedgerIndex ledgerSeq) = 0;
|
||||
void
|
||||
deleteAccountTransactionsBeforeLedgerSeq(LedgerIndex ledgerSeq) override;
|
||||
|
||||
/**
|
||||
* @brief getTransactionCount Returns the number of transactions.
|
||||
* @return Number of transactions.
|
||||
*/
|
||||
virtual std::size_t
|
||||
getTransactionCount() = 0;
|
||||
std::size_t
|
||||
getTransactionCount() override;
|
||||
|
||||
/**
|
||||
* @brief getAccountTransactionCount Returns the number of account
|
||||
* transactions.
|
||||
* @return Number of account transactions.
|
||||
*/
|
||||
virtual std::size_t
|
||||
getAccountTransactionCount() = 0;
|
||||
std::size_t
|
||||
getAccountTransactionCount() override;
|
||||
|
||||
/**
|
||||
* @brief getLedgerCountMinMax Returns the minimum ledger sequence,
|
||||
@@ -79,8 +85,8 @@ public:
|
||||
* @return Struct CountMinMax which contains the minimum sequence,
|
||||
* maximum sequence and number of ledgers.
|
||||
*/
|
||||
virtual struct CountMinMax
|
||||
getLedgerCountMinMax() = 0;
|
||||
RelationalDatabase::CountMinMax
|
||||
getLedgerCountMinMax() override;
|
||||
|
||||
/**
|
||||
* @brief saveValidatedLedger Saves a ledger into the database.
|
||||
@@ -88,10 +94,10 @@ public:
|
||||
* @param current True if the ledger is current.
|
||||
* @return True if saving was successful.
|
||||
*/
|
||||
virtual bool
|
||||
bool
|
||||
saveValidatedLedger(
|
||||
std::shared_ptr<Ledger const> const& ledger,
|
||||
bool current) = 0;
|
||||
bool current) override;
|
||||
|
||||
/**
|
||||
* @brief getLimitedOldestLedgerInfo Returns the info of the oldest ledger
|
||||
@@ -100,8 +106,8 @@ public:
|
||||
* @param ledgerFirstIndex Minimum ledger sequence.
|
||||
* @return Ledger info if found, otherwise no value.
|
||||
*/
|
||||
virtual std::optional<LedgerHeader>
|
||||
getLimitedOldestLedgerInfo(LedgerIndex ledgerFirstIndex) = 0;
|
||||
std::optional<LedgerHeader>
|
||||
getLimitedOldestLedgerInfo(LedgerIndex ledgerFirstIndex) override;
|
||||
|
||||
/**
|
||||
* @brief getLimitedNewestLedgerInfo Returns the info of the newest ledger
|
||||
@@ -110,8 +116,8 @@ public:
|
||||
* @param ledgerFirstIndex Minimum ledger sequence.
|
||||
* @return Ledger info if found, otherwise no value.
|
||||
*/
|
||||
virtual std::optional<LedgerHeader>
|
||||
getLimitedNewestLedgerInfo(LedgerIndex ledgerFirstIndex) = 0;
|
||||
std::optional<LedgerHeader>
|
||||
getLimitedNewestLedgerInfo(LedgerIndex ledgerFirstIndex) override;
|
||||
|
||||
/**
|
||||
* @brief getOldestAccountTxs Returns the oldest transactions for the
|
||||
@@ -124,8 +130,8 @@ public:
|
||||
* @return Vector of pairs of found transactions and their metadata
|
||||
* sorted in ascending order by account sequence.
|
||||
*/
|
||||
virtual AccountTxs
|
||||
getOldestAccountTxs(AccountTxOptions const& options) = 0;
|
||||
AccountTxs
|
||||
getOldestAccountTxs(AccountTxOptions const& options) override;
|
||||
|
||||
/**
|
||||
* @brief getNewestAccountTxs Returns the newest transactions for the
|
||||
@@ -138,8 +144,8 @@ public:
|
||||
* @return Vector of pairs of found transactions and their metadata
|
||||
* sorted in descending order by account sequence.
|
||||
*/
|
||||
virtual AccountTxs
|
||||
getNewestAccountTxs(AccountTxOptions const& options) = 0;
|
||||
AccountTxs
|
||||
getNewestAccountTxs(AccountTxOptions const& options) override;
|
||||
|
||||
/**
|
||||
* @brief getOldestAccountTxsB Returns the oldest transactions in binary
|
||||
@@ -152,8 +158,8 @@ public:
|
||||
* @return Vector of tuples of found transactions, their metadata and
|
||||
* account sequences sorted in ascending order by account sequence.
|
||||
*/
|
||||
virtual MetaTxsList
|
||||
getOldestAccountTxsB(AccountTxOptions const& options) = 0;
|
||||
MetaTxsList
|
||||
getOldestAccountTxsB(AccountTxOptions const& options) override;
|
||||
|
||||
/**
|
||||
* @brief getNewestAccountTxsB Returns the newest transactions in binary
|
||||
@@ -167,8 +173,8 @@ public:
|
||||
* account sequences sorted in descending order by account
|
||||
* sequence.
|
||||
*/
|
||||
virtual MetaTxsList
|
||||
getNewestAccountTxsB(AccountTxOptions const& options) = 0;
|
||||
MetaTxsList
|
||||
getNewestAccountTxsB(AccountTxOptions const& options) override;
|
||||
|
||||
/**
|
||||
* @brief oldestAccountTxPage Returns the oldest transactions for the
|
||||
@@ -182,8 +188,8 @@ public:
|
||||
* sorted in ascending order by account sequence and a marker
|
||||
* for the next search if the search was not finished.
|
||||
*/
|
||||
virtual std::pair<AccountTxs, std::optional<AccountTxMarker>>
|
||||
oldestAccountTxPage(AccountTxPageOptions const& options) = 0;
|
||||
std::pair<AccountTxs, std::optional<AccountTxMarker>>
|
||||
oldestAccountTxPage(AccountTxPageOptions const& options) override;
|
||||
|
||||
/**
|
||||
* @brief newestAccountTxPage Returns the newest transactions for the
|
||||
@@ -197,8 +203,8 @@ public:
|
||||
* sorted in descending order by account sequence and a marker
|
||||
* for the next search if the search was not finished.
|
||||
*/
|
||||
virtual std::pair<AccountTxs, std::optional<AccountTxMarker>>
|
||||
newestAccountTxPage(AccountTxPageOptions const& options) = 0;
|
||||
std::pair<AccountTxs, std::optional<AccountTxMarker>>
|
||||
newestAccountTxPage(AccountTxPageOptions const& options) override;
|
||||
|
||||
/**
|
||||
* @brief oldestAccountTxPageB Returns the oldest transactions in binary
|
||||
@@ -213,8 +219,8 @@ public:
|
||||
* sequence and a marker for the next search if the search was not
|
||||
* finished.
|
||||
*/
|
||||
virtual std::pair<MetaTxsList, std::optional<AccountTxMarker>>
|
||||
oldestAccountTxPageB(AccountTxPageOptions const& options) = 0;
|
||||
std::pair<MetaTxsList, std::optional<AccountTxMarker>>
|
||||
oldestAccountTxPageB(AccountTxPageOptions const& options) override;
|
||||
|
||||
/**
|
||||
* @brief newestAccountTxPageB Returns the newest transactions in binary
|
||||
@@ -229,8 +235,8 @@ public:
|
||||
* sequence and a marker for the next search if the search was not
|
||||
* finished.
|
||||
*/
|
||||
virtual std::pair<MetaTxsList, std::optional<AccountTxMarker>>
|
||||
newestAccountTxPageB(AccountTxPageOptions const& options) = 0;
|
||||
std::pair<MetaTxsList, std::optional<AccountTxMarker>>
|
||||
newestAccountTxPageB(AccountTxPageOptions const& options) override;
|
||||
|
||||
/**
|
||||
* @brief getTransaction Returns the transaction with the given hash. If a
|
||||
@@ -247,48 +253,192 @@ public:
|
||||
* error code is returned via the ec parameter, in other cases the
|
||||
* default error code is not changed.
|
||||
*/
|
||||
virtual std::variant<AccountTx, TxSearched>
|
||||
std::variant<AccountTx, TxSearched>
|
||||
getTransaction(
|
||||
uint256 const& id,
|
||||
std::optional<ClosedInterval<uint32_t>> const& range,
|
||||
error_code_i& ec) = 0;
|
||||
std::optional<ClosedInterval<std::uint32_t>> const& range,
|
||||
error_code_i& ec) override;
|
||||
|
||||
/**
|
||||
* @brief getKBUsedAll Returns the amount of space used by all databases.
|
||||
* @return Space in kilobytes.
|
||||
*/
|
||||
virtual uint32_t
|
||||
getKBUsedAll() = 0;
|
||||
std::uint32_t
|
||||
getKBUsedAll() override;
|
||||
|
||||
/**
|
||||
* @brief getKBUsedLedger Returns the amount of space space used by the
|
||||
* ledger database.
|
||||
* @return Space in kilobytes.
|
||||
*/
|
||||
virtual uint32_t
|
||||
getKBUsedLedger() = 0;
|
||||
std::uint32_t
|
||||
getKBUsedLedger() override;
|
||||
|
||||
/**
|
||||
* @brief getKBUsedTransaction Returns the amount of space used by the
|
||||
* transaction database.
|
||||
* @return Space in kilobytes.
|
||||
*/
|
||||
virtual uint32_t
|
||||
getKBUsedTransaction() = 0;
|
||||
std::uint32_t
|
||||
getKBUsedTransaction() override;
|
||||
|
||||
/**
|
||||
* @brief Closes the ledger database
|
||||
*/
|
||||
virtual void
|
||||
closeLedgerDB() = 0;
|
||||
void
|
||||
closeLedgerDB() override;
|
||||
|
||||
/**
|
||||
* @brief Closes the transaction database
|
||||
*/
|
||||
virtual void
|
||||
closeTransactionDB() = 0;
|
||||
void
|
||||
closeTransactionDB() override;
|
||||
|
||||
std::optional<LedgerHeader>
|
||||
getLedgerInfoByIndex(LedgerIndex ledgerSeq) override;
|
||||
|
||||
std::optional<LedgerHeader>
|
||||
getLedgerInfoByHash(uint256 const& ledgerHash) override;
|
||||
|
||||
uint256
|
||||
getHashByIndex(LedgerIndex ledgerIndex) override;
|
||||
|
||||
std::optional<LedgerHashPair>
|
||||
getHashesByIndex(LedgerIndex ledgerIndex) override;
|
||||
|
||||
std::map<LedgerIndex, LedgerHashPair>
|
||||
getHashesByIndex(LedgerIndex minSeq, LedgerIndex maxSeq) override;
|
||||
|
||||
std::vector<std::shared_ptr<Transaction>>
|
||||
getTxHistory(LedgerIndex startIndex) override;
|
||||
|
||||
std::optional<LedgerHeader>
|
||||
getNewestLedgerInfo() override;
|
||||
|
||||
SQLiteDatabase(
|
||||
ServiceRegistry& registry,
|
||||
Config const& config,
|
||||
JobQueue& jobQueue)
|
||||
: registry_(registry)
|
||||
, useTxTables_(config.useTxTables())
|
||||
, j_(registry.journal("SQLiteDatabase"))
|
||||
{
|
||||
DatabaseCon::Setup const setup = setup_DatabaseCon(config, j_);
|
||||
if (!makeLedgerDBs(
|
||||
config,
|
||||
setup,
|
||||
DatabaseCon::CheckpointerSetup{&jobQueue, ®istry_.logs()}))
|
||||
{
|
||||
std::string_view constexpr error =
|
||||
"Failed to create ledger databases";
|
||||
|
||||
JLOG(j_.fatal()) << error;
|
||||
Throw<std::runtime_error>(error.data());
|
||||
}
|
||||
}
|
||||
|
||||
std::optional<LedgerIndex>
|
||||
getMinLedgerSeq() override;
|
||||
|
||||
std::optional<LedgerIndex>
|
||||
getMaxLedgerSeq() override;
|
||||
|
||||
/**
|
||||
* @brief ledgerDbHasSpace Checks if the ledger database has available
|
||||
* space.
|
||||
* @param config Config object.
|
||||
* @return True if space is available.
|
||||
*/
|
||||
bool
|
||||
ledgerDbHasSpace(Config const& config);
|
||||
|
||||
/**
|
||||
* @brief transactionDbHasSpace Checks if the transaction database has
|
||||
* available space.
|
||||
* @param config Config object.
|
||||
* @return True if space is available.
|
||||
*/
|
||||
bool
|
||||
transactionDbHasSpace(Config const& config);
|
||||
|
||||
private:
|
||||
ServiceRegistry& registry_;
|
||||
bool const useTxTables_;
|
||||
beast::Journal j_;
|
||||
std::unique_ptr<DatabaseCon> ledgerDb_, txdb_;
|
||||
|
||||
/**
|
||||
* @brief makeLedgerDBs Opens ledger and transaction databases for the node
|
||||
* store, and stores their descriptors in private member variables.
|
||||
* @param config Config object.
|
||||
* @param setup Path to the databases and other opening parameters.
|
||||
* @param checkpointerSetup Checkpointer parameters.
|
||||
* @return True if node databases opened successfully.
|
||||
*/
|
||||
bool
|
||||
makeLedgerDBs(
|
||||
Config const& config,
|
||||
DatabaseCon::Setup const& setup,
|
||||
DatabaseCon::CheckpointerSetup const& checkpointerSetup);
|
||||
|
||||
/**
|
||||
* @brief existsLedger Checks if the node store ledger database exists.
|
||||
* @return True if the node store ledger database exists.
|
||||
*/
|
||||
bool
|
||||
existsLedger()
|
||||
{
|
||||
return static_cast<bool>(ledgerDb_);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief existsTransaction Checks if the node store transaction database
|
||||
* exists.
|
||||
* @return True if the node store transaction database exists.
|
||||
*/
|
||||
bool
|
||||
existsTransaction()
|
||||
{
|
||||
return static_cast<bool>(txdb_);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief checkoutTransaction Checks out and returns node store ledger
|
||||
* database.
|
||||
* @return Session to the node store ledger database.
|
||||
*/
|
||||
auto
|
||||
checkoutLedger()
|
||||
{
|
||||
return ledgerDb_->checkoutDb();
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief checkoutTransaction Checks out and returns the node store
|
||||
* transaction database.
|
||||
* @return Session to the node store transaction database.
|
||||
*/
|
||||
auto
|
||||
checkoutTransaction()
|
||||
{
|
||||
return txdb_->checkoutDb();
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief setup_RelationalDatabase Creates and returns a SQLiteDatabase
|
||||
* instance based on configuration.
|
||||
* @param registry The service registry.
|
||||
* @param config Config object.
|
||||
* @param jobQueue JobQueue object.
|
||||
* @return Unique pointer to the SQLiteDatabase implementation.
|
||||
*/
|
||||
std::unique_ptr<SQLiteDatabase>
|
||||
setup_RelationalDatabase(
|
||||
ServiceRegistry& registry,
|
||||
Config const& config,
|
||||
JobQueue& jobQueue);
|
||||
|
||||
} // namespace xrpl
|
||||
|
||||
#endif
|
||||
|
||||
@@ -3,14 +3,14 @@
|
||||
#include <xrpld/app/ledger/LedgerToJson.h>
|
||||
#include <xrpld/app/ledger/PendingSaves.h>
|
||||
#include <xrpld/app/ledger/TransactionMaster.h>
|
||||
#include <xrpld/app/rdb/RelationalDatabase.h>
|
||||
#include <xrpld/app/rdb/backend/detail/Node.h>
|
||||
#include <xrpld/core/DatabaseCon.h>
|
||||
#include <xrpld/core/SociDB.h>
|
||||
|
||||
#include <xrpl/basics/BasicConfig.h>
|
||||
#include <xrpl/basics/StringUtilities.h>
|
||||
#include <xrpl/json/to_string.h>
|
||||
#include <xrpl/rdb/DatabaseCon.h>
|
||||
#include <xrpl/rdb/RelationalDatabase.h>
|
||||
#include <xrpl/rdb/SociDB.h>
|
||||
|
||||
#include <boost/range/adaptor/transformed.hpp>
|
||||
|
||||
@@ -70,9 +70,9 @@ makeLedgerDBs(
|
||||
boost::format("PRAGMA cache_size=-%d;") %
|
||||
kilobytes(config.getValueFor(SizedItem::txnDBCache)));
|
||||
|
||||
if (!setup.standAlone || setup.startUp == Config::LOAD ||
|
||||
setup.startUp == Config::LOAD_FILE ||
|
||||
setup.startUp == Config::REPLAY)
|
||||
if (!setup.standAlone || setup.startUp == StartUpType::LOAD ||
|
||||
setup.startUp == StartUpType::LOAD_FILE ||
|
||||
setup.startUp == StartUpType::REPLAY)
|
||||
{
|
||||
// Check if AccountTransactions has primary key
|
||||
std::string cid, name, type;
|
||||
|
||||
@@ -2,9 +2,10 @@
|
||||
#define XRPL_APP_RDB_BACKEND_DETAIL_NODE_H_INCLUDED
|
||||
|
||||
#include <xrpld/app/ledger/Ledger.h>
|
||||
#include <xrpld/app/rdb/RelationalDatabase.h>
|
||||
#include <xrpld/core/Config.h>
|
||||
|
||||
#include <xrpl/rdb/RelationalDatabase.h>
|
||||
|
||||
namespace xrpl {
|
||||
namespace detail {
|
||||
|
||||
|
||||
@@ -3,220 +3,15 @@
|
||||
#include <xrpld/app/misc/detail/AccountTxPaging.h>
|
||||
#include <xrpld/app/rdb/backend/SQLiteDatabase.h>
|
||||
#include <xrpld/app/rdb/backend/detail/Node.h>
|
||||
#include <xrpld/core/DatabaseCon.h>
|
||||
#include <xrpld/core/SociDB.h>
|
||||
|
||||
#include <xrpl/basics/StringUtilities.h>
|
||||
#include <xrpl/rdb/DatabaseCon.h>
|
||||
#include <xrpl/rdb/SociDB.h>
|
||||
|
||||
namespace xrpl {
|
||||
|
||||
class SQLiteDatabaseImp final : public SQLiteDatabase
|
||||
{
|
||||
public:
|
||||
SQLiteDatabaseImp(
|
||||
Application& app,
|
||||
Config const& config,
|
||||
JobQueue& jobQueue)
|
||||
: app_(app)
|
||||
, useTxTables_(config.useTxTables())
|
||||
, j_(app_.journal("SQLiteDatabaseImp"))
|
||||
{
|
||||
DatabaseCon::Setup const setup = setup_DatabaseCon(config, j_);
|
||||
if (!makeLedgerDBs(
|
||||
config,
|
||||
setup,
|
||||
DatabaseCon::CheckpointerSetup{&jobQueue, &app_.logs()}))
|
||||
{
|
||||
std::string_view constexpr error =
|
||||
"Failed to create ledger databases";
|
||||
|
||||
JLOG(j_.fatal()) << error;
|
||||
Throw<std::runtime_error>(error.data());
|
||||
}
|
||||
}
|
||||
|
||||
std::optional<LedgerIndex>
|
||||
getMinLedgerSeq() override;
|
||||
|
||||
std::optional<LedgerIndex>
|
||||
getTransactionsMinLedgerSeq() override;
|
||||
|
||||
std::optional<LedgerIndex>
|
||||
getAccountTransactionsMinLedgerSeq() override;
|
||||
|
||||
std::optional<LedgerIndex>
|
||||
getMaxLedgerSeq() override;
|
||||
|
||||
void
|
||||
deleteTransactionByLedgerSeq(LedgerIndex ledgerSeq) override;
|
||||
|
||||
void
|
||||
deleteBeforeLedgerSeq(LedgerIndex ledgerSeq) override;
|
||||
|
||||
void
|
||||
deleteTransactionsBeforeLedgerSeq(LedgerIndex ledgerSeq) override;
|
||||
|
||||
void
|
||||
deleteAccountTransactionsBeforeLedgerSeq(LedgerIndex ledgerSeq) override;
|
||||
|
||||
std::size_t
|
||||
getTransactionCount() override;
|
||||
|
||||
std::size_t
|
||||
getAccountTransactionCount() override;
|
||||
|
||||
RelationalDatabase::CountMinMax
|
||||
getLedgerCountMinMax() override;
|
||||
|
||||
bool
|
||||
saveValidatedLedger(
|
||||
std::shared_ptr<Ledger const> const& ledger,
|
||||
bool current) override;
|
||||
|
||||
std::optional<LedgerHeader>
|
||||
getLedgerInfoByIndex(LedgerIndex ledgerSeq) override;
|
||||
|
||||
std::optional<LedgerHeader>
|
||||
getNewestLedgerInfo() override;
|
||||
|
||||
std::optional<LedgerHeader>
|
||||
getLimitedOldestLedgerInfo(LedgerIndex ledgerFirstIndex) override;
|
||||
|
||||
std::optional<LedgerHeader>
|
||||
getLimitedNewestLedgerInfo(LedgerIndex ledgerFirstIndex) override;
|
||||
|
||||
std::optional<LedgerHeader>
|
||||
getLedgerInfoByHash(uint256 const& ledgerHash) override;
|
||||
|
||||
uint256
|
||||
getHashByIndex(LedgerIndex ledgerIndex) override;
|
||||
|
||||
std::optional<LedgerHashPair>
|
||||
getHashesByIndex(LedgerIndex ledgerIndex) override;
|
||||
|
||||
std::map<LedgerIndex, LedgerHashPair>
|
||||
getHashesByIndex(LedgerIndex minSeq, LedgerIndex maxSeq) override;
|
||||
|
||||
std::vector<std::shared_ptr<Transaction>>
|
||||
getTxHistory(LedgerIndex startIndex) override;
|
||||
|
||||
AccountTxs
|
||||
getOldestAccountTxs(AccountTxOptions const& options) override;
|
||||
|
||||
AccountTxs
|
||||
getNewestAccountTxs(AccountTxOptions const& options) override;
|
||||
|
||||
MetaTxsList
|
||||
getOldestAccountTxsB(AccountTxOptions const& options) override;
|
||||
|
||||
MetaTxsList
|
||||
getNewestAccountTxsB(AccountTxOptions const& options) override;
|
||||
|
||||
std::pair<AccountTxs, std::optional<AccountTxMarker>>
|
||||
oldestAccountTxPage(AccountTxPageOptions const& options) override;
|
||||
|
||||
std::pair<AccountTxs, std::optional<AccountTxMarker>>
|
||||
newestAccountTxPage(AccountTxPageOptions const& options) override;
|
||||
|
||||
std::pair<MetaTxsList, std::optional<AccountTxMarker>>
|
||||
oldestAccountTxPageB(AccountTxPageOptions const& options) override;
|
||||
|
||||
std::pair<MetaTxsList, std::optional<AccountTxMarker>>
|
||||
newestAccountTxPageB(AccountTxPageOptions const& options) override;
|
||||
|
||||
std::variant<AccountTx, TxSearched>
|
||||
getTransaction(
|
||||
uint256 const& id,
|
||||
std::optional<ClosedInterval<std::uint32_t>> const& range,
|
||||
error_code_i& ec) override;
|
||||
|
||||
bool
|
||||
ledgerDbHasSpace(Config const& config) override;
|
||||
|
||||
bool
|
||||
transactionDbHasSpace(Config const& config) override;
|
||||
|
||||
std::uint32_t
|
||||
getKBUsedAll() override;
|
||||
|
||||
std::uint32_t
|
||||
getKBUsedLedger() override;
|
||||
|
||||
std::uint32_t
|
||||
getKBUsedTransaction() override;
|
||||
|
||||
void
|
||||
closeLedgerDB() override;
|
||||
|
||||
void
|
||||
closeTransactionDB() override;
|
||||
|
||||
private:
|
||||
Application& app_;
|
||||
bool const useTxTables_;
|
||||
beast::Journal j_;
|
||||
std::unique_ptr<DatabaseCon> ledgerDb_, txdb_;
|
||||
|
||||
/**
|
||||
* @brief makeLedgerDBs Opens ledger and transaction databases for the node
|
||||
* store, and stores their descriptors in private member variables.
|
||||
* @param config Config object.
|
||||
* @param setup Path to the databases and other opening parameters.
|
||||
* @param checkpointerSetup Checkpointer parameters.
|
||||
* @return True if node databases opened successfully.
|
||||
*/
|
||||
bool
|
||||
makeLedgerDBs(
|
||||
Config const& config,
|
||||
DatabaseCon::Setup const& setup,
|
||||
DatabaseCon::CheckpointerSetup const& checkpointerSetup);
|
||||
|
||||
/**
|
||||
* @brief existsLedger Checks if the node store ledger database exists.
|
||||
* @return True if the node store ledger database exists.
|
||||
*/
|
||||
bool
|
||||
existsLedger()
|
||||
{
|
||||
return static_cast<bool>(ledgerDb_);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief existsTransaction Checks if the node store transaction database
|
||||
* exists.
|
||||
* @return True if the node store transaction database exists.
|
||||
*/
|
||||
bool
|
||||
existsTransaction()
|
||||
{
|
||||
return static_cast<bool>(txdb_);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief checkoutTransaction Checks out and returns node store ledger
|
||||
* database.
|
||||
* @return Session to the node store ledger database.
|
||||
*/
|
||||
auto
|
||||
checkoutLedger()
|
||||
{
|
||||
return ledgerDb_->checkoutDb();
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief checkoutTransaction Checks out and returns the node store
|
||||
* transaction database.
|
||||
* @return Session to the node store transaction database.
|
||||
*/
|
||||
auto
|
||||
checkoutTransaction()
|
||||
{
|
||||
return txdb_->checkoutDb();
|
||||
}
|
||||
};
|
||||
|
||||
bool
|
||||
SQLiteDatabaseImp::makeLedgerDBs(
|
||||
SQLiteDatabase::makeLedgerDBs(
|
||||
Config const& config,
|
||||
DatabaseCon::Setup const& setup,
|
||||
DatabaseCon::CheckpointerSetup const& checkpointerSetup)
|
||||
@@ -229,7 +24,7 @@ SQLiteDatabaseImp::makeLedgerDBs(
|
||||
}
|
||||
|
||||
std::optional<LedgerIndex>
|
||||
SQLiteDatabaseImp::getMinLedgerSeq()
|
||||
SQLiteDatabase::getMinLedgerSeq()
|
||||
{
|
||||
/* if databases exists, use it */
|
||||
if (existsLedger())
|
||||
@@ -243,7 +38,7 @@ SQLiteDatabaseImp::getMinLedgerSeq()
|
||||
}
|
||||
|
||||
std::optional<LedgerIndex>
|
||||
SQLiteDatabaseImp::getTransactionsMinLedgerSeq()
|
||||
SQLiteDatabase::getTransactionsMinLedgerSeq()
|
||||
{
|
||||
if (!useTxTables_)
|
||||
return {};
|
||||
@@ -258,7 +53,7 @@ SQLiteDatabaseImp::getTransactionsMinLedgerSeq()
|
||||
}
|
||||
|
||||
std::optional<LedgerIndex>
|
||||
SQLiteDatabaseImp::getAccountTransactionsMinLedgerSeq()
|
||||
SQLiteDatabase::getAccountTransactionsMinLedgerSeq()
|
||||
{
|
||||
if (!useTxTables_)
|
||||
return {};
|
||||
@@ -274,7 +69,7 @@ SQLiteDatabaseImp::getAccountTransactionsMinLedgerSeq()
|
||||
}
|
||||
|
||||
std::optional<LedgerIndex>
|
||||
SQLiteDatabaseImp::getMaxLedgerSeq()
|
||||
SQLiteDatabase::getMaxLedgerSeq()
|
||||
{
|
||||
if (existsLedger())
|
||||
{
|
||||
@@ -286,7 +81,7 @@ SQLiteDatabaseImp::getMaxLedgerSeq()
|
||||
}
|
||||
|
||||
void
|
||||
SQLiteDatabaseImp::deleteTransactionByLedgerSeq(LedgerIndex ledgerSeq)
|
||||
SQLiteDatabase::deleteTransactionByLedgerSeq(LedgerIndex ledgerSeq)
|
||||
{
|
||||
if (!useTxTables_)
|
||||
return;
|
||||
@@ -301,7 +96,7 @@ SQLiteDatabaseImp::deleteTransactionByLedgerSeq(LedgerIndex ledgerSeq)
|
||||
}
|
||||
|
||||
void
|
||||
SQLiteDatabaseImp::deleteBeforeLedgerSeq(LedgerIndex ledgerSeq)
|
||||
SQLiteDatabase::deleteBeforeLedgerSeq(LedgerIndex ledgerSeq)
|
||||
{
|
||||
if (existsLedger())
|
||||
{
|
||||
@@ -313,7 +108,7 @@ SQLiteDatabaseImp::deleteBeforeLedgerSeq(LedgerIndex ledgerSeq)
|
||||
}
|
||||
|
||||
void
|
||||
SQLiteDatabaseImp::deleteTransactionsBeforeLedgerSeq(LedgerIndex ledgerSeq)
|
||||
SQLiteDatabase::deleteTransactionsBeforeLedgerSeq(LedgerIndex ledgerSeq)
|
||||
{
|
||||
if (!useTxTables_)
|
||||
return;
|
||||
@@ -328,8 +123,7 @@ SQLiteDatabaseImp::deleteTransactionsBeforeLedgerSeq(LedgerIndex ledgerSeq)
|
||||
}
|
||||
|
||||
void
|
||||
SQLiteDatabaseImp::deleteAccountTransactionsBeforeLedgerSeq(
|
||||
LedgerIndex ledgerSeq)
|
||||
SQLiteDatabase::deleteAccountTransactionsBeforeLedgerSeq(LedgerIndex ledgerSeq)
|
||||
{
|
||||
if (!useTxTables_)
|
||||
return;
|
||||
@@ -344,7 +138,7 @@ SQLiteDatabaseImp::deleteAccountTransactionsBeforeLedgerSeq(
|
||||
}
|
||||
|
||||
std::size_t
|
||||
SQLiteDatabaseImp::getTransactionCount()
|
||||
SQLiteDatabase::getTransactionCount()
|
||||
{
|
||||
if (!useTxTables_)
|
||||
return 0;
|
||||
@@ -359,7 +153,7 @@ SQLiteDatabaseImp::getTransactionCount()
|
||||
}
|
||||
|
||||
std::size_t
|
||||
SQLiteDatabaseImp::getAccountTransactionCount()
|
||||
SQLiteDatabase::getAccountTransactionCount()
|
||||
{
|
||||
if (!useTxTables_)
|
||||
return 0;
|
||||
@@ -374,7 +168,7 @@ SQLiteDatabaseImp::getAccountTransactionCount()
|
||||
}
|
||||
|
||||
RelationalDatabase::CountMinMax
|
||||
SQLiteDatabaseImp::getLedgerCountMinMax()
|
||||
SQLiteDatabase::getLedgerCountMinMax()
|
||||
{
|
||||
if (existsLedger())
|
||||
{
|
||||
@@ -386,14 +180,14 @@ SQLiteDatabaseImp::getLedgerCountMinMax()
|
||||
}
|
||||
|
||||
bool
|
||||
SQLiteDatabaseImp::saveValidatedLedger(
|
||||
SQLiteDatabase::saveValidatedLedger(
|
||||
std::shared_ptr<Ledger const> const& ledger,
|
||||
bool current)
|
||||
{
|
||||
if (existsLedger())
|
||||
{
|
||||
if (!detail::saveValidatedLedger(
|
||||
*ledgerDb_, txdb_, app_, ledger, current))
|
||||
*ledgerDb_, txdb_, registry_.app(), ledger, current))
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -401,7 +195,7 @@ SQLiteDatabaseImp::saveValidatedLedger(
|
||||
}
|
||||
|
||||
std::optional<LedgerHeader>
|
||||
SQLiteDatabaseImp::getLedgerInfoByIndex(LedgerIndex ledgerSeq)
|
||||
SQLiteDatabase::getLedgerInfoByIndex(LedgerIndex ledgerSeq)
|
||||
{
|
||||
if (existsLedger())
|
||||
{
|
||||
@@ -416,7 +210,7 @@ SQLiteDatabaseImp::getLedgerInfoByIndex(LedgerIndex ledgerSeq)
|
||||
}
|
||||
|
||||
std::optional<LedgerHeader>
|
||||
SQLiteDatabaseImp::getNewestLedgerInfo()
|
||||
SQLiteDatabase::getNewestLedgerInfo()
|
||||
{
|
||||
if (existsLedger())
|
||||
{
|
||||
@@ -431,7 +225,7 @@ SQLiteDatabaseImp::getNewestLedgerInfo()
|
||||
}
|
||||
|
||||
std::optional<LedgerHeader>
|
||||
SQLiteDatabaseImp::getLimitedOldestLedgerInfo(LedgerIndex ledgerFirstIndex)
|
||||
SQLiteDatabase::getLimitedOldestLedgerInfo(LedgerIndex ledgerFirstIndex)
|
||||
{
|
||||
if (existsLedger())
|
||||
{
|
||||
@@ -447,7 +241,7 @@ SQLiteDatabaseImp::getLimitedOldestLedgerInfo(LedgerIndex ledgerFirstIndex)
|
||||
}
|
||||
|
||||
std::optional<LedgerHeader>
|
||||
SQLiteDatabaseImp::getLimitedNewestLedgerInfo(LedgerIndex ledgerFirstIndex)
|
||||
SQLiteDatabase::getLimitedNewestLedgerInfo(LedgerIndex ledgerFirstIndex)
|
||||
{
|
||||
if (existsLedger())
|
||||
{
|
||||
@@ -463,7 +257,7 @@ SQLiteDatabaseImp::getLimitedNewestLedgerInfo(LedgerIndex ledgerFirstIndex)
|
||||
}
|
||||
|
||||
std::optional<LedgerHeader>
|
||||
SQLiteDatabaseImp::getLedgerInfoByHash(uint256 const& ledgerHash)
|
||||
SQLiteDatabase::getLedgerInfoByHash(uint256 const& ledgerHash)
|
||||
{
|
||||
if (existsLedger())
|
||||
{
|
||||
@@ -478,7 +272,7 @@ SQLiteDatabaseImp::getLedgerInfoByHash(uint256 const& ledgerHash)
|
||||
}
|
||||
|
||||
uint256
|
||||
SQLiteDatabaseImp::getHashByIndex(LedgerIndex ledgerIndex)
|
||||
SQLiteDatabase::getHashByIndex(LedgerIndex ledgerIndex)
|
||||
{
|
||||
if (existsLedger())
|
||||
{
|
||||
@@ -493,7 +287,7 @@ SQLiteDatabaseImp::getHashByIndex(LedgerIndex ledgerIndex)
|
||||
}
|
||||
|
||||
std::optional<LedgerHashPair>
|
||||
SQLiteDatabaseImp::getHashesByIndex(LedgerIndex ledgerIndex)
|
||||
SQLiteDatabase::getHashesByIndex(LedgerIndex ledgerIndex)
|
||||
{
|
||||
if (existsLedger())
|
||||
{
|
||||
@@ -508,7 +302,7 @@ SQLiteDatabaseImp::getHashesByIndex(LedgerIndex ledgerIndex)
|
||||
}
|
||||
|
||||
std::map<LedgerIndex, LedgerHashPair>
|
||||
SQLiteDatabaseImp::getHashesByIndex(LedgerIndex minSeq, LedgerIndex maxSeq)
|
||||
SQLiteDatabase::getHashesByIndex(LedgerIndex minSeq, LedgerIndex maxSeq)
|
||||
{
|
||||
if (existsLedger())
|
||||
{
|
||||
@@ -523,7 +317,7 @@ SQLiteDatabaseImp::getHashesByIndex(LedgerIndex minSeq, LedgerIndex maxSeq)
|
||||
}
|
||||
|
||||
std::vector<std::shared_ptr<Transaction>>
|
||||
SQLiteDatabaseImp::getTxHistory(LedgerIndex startIndex)
|
||||
SQLiteDatabase::getTxHistory(LedgerIndex startIndex)
|
||||
{
|
||||
if (!useTxTables_)
|
||||
return {};
|
||||
@@ -531,7 +325,8 @@ SQLiteDatabaseImp::getTxHistory(LedgerIndex startIndex)
|
||||
if (existsTransaction())
|
||||
{
|
||||
auto db = checkoutTransaction();
|
||||
auto const res = detail::getTxHistory(*db, app_, startIndex, 20).first;
|
||||
auto const res =
|
||||
detail::getTxHistory(*db, registry_.app(), startIndex, 20).first;
|
||||
|
||||
if (!res.empty())
|
||||
return res;
|
||||
@@ -541,17 +336,18 @@ SQLiteDatabaseImp::getTxHistory(LedgerIndex startIndex)
|
||||
}
|
||||
|
||||
RelationalDatabase::AccountTxs
|
||||
SQLiteDatabaseImp::getOldestAccountTxs(AccountTxOptions const& options)
|
||||
SQLiteDatabase::getOldestAccountTxs(AccountTxOptions const& options)
|
||||
{
|
||||
if (!useTxTables_)
|
||||
return {};
|
||||
|
||||
LedgerMaster& ledgerMaster = app_.getLedgerMaster();
|
||||
LedgerMaster& ledgerMaster = registry_.getLedgerMaster();
|
||||
|
||||
if (existsTransaction())
|
||||
{
|
||||
auto db = checkoutTransaction();
|
||||
return detail::getOldestAccountTxs(*db, app_, ledgerMaster, options, j_)
|
||||
return detail::getOldestAccountTxs(
|
||||
*db, registry_.app(), ledgerMaster, options, j_)
|
||||
.first;
|
||||
}
|
||||
|
||||
@@ -559,17 +355,18 @@ SQLiteDatabaseImp::getOldestAccountTxs(AccountTxOptions const& options)
|
||||
}
|
||||
|
||||
RelationalDatabase::AccountTxs
|
||||
SQLiteDatabaseImp::getNewestAccountTxs(AccountTxOptions const& options)
|
||||
SQLiteDatabase::getNewestAccountTxs(AccountTxOptions const& options)
|
||||
{
|
||||
if (!useTxTables_)
|
||||
return {};
|
||||
|
||||
LedgerMaster& ledgerMaster = app_.getLedgerMaster();
|
||||
LedgerMaster& ledgerMaster = registry_.getLedgerMaster();
|
||||
|
||||
if (existsTransaction())
|
||||
{
|
||||
auto db = checkoutTransaction();
|
||||
return detail::getNewestAccountTxs(*db, app_, ledgerMaster, options, j_)
|
||||
return detail::getNewestAccountTxs(
|
||||
*db, registry_.app(), ledgerMaster, options, j_)
|
||||
.first;
|
||||
}
|
||||
|
||||
@@ -577,7 +374,7 @@ SQLiteDatabaseImp::getNewestAccountTxs(AccountTxOptions const& options)
|
||||
}
|
||||
|
||||
RelationalDatabase::MetaTxsList
|
||||
SQLiteDatabaseImp::getOldestAccountTxsB(AccountTxOptions const& options)
|
||||
SQLiteDatabase::getOldestAccountTxsB(AccountTxOptions const& options)
|
||||
{
|
||||
if (!useTxTables_)
|
||||
return {};
|
||||
@@ -585,14 +382,15 @@ SQLiteDatabaseImp::getOldestAccountTxsB(AccountTxOptions const& options)
|
||||
if (existsTransaction())
|
||||
{
|
||||
auto db = checkoutTransaction();
|
||||
return detail::getOldestAccountTxsB(*db, app_, options, j_).first;
|
||||
return detail::getOldestAccountTxsB(*db, registry_.app(), options, j_)
|
||||
.first;
|
||||
}
|
||||
|
||||
return {};
|
||||
}
|
||||
|
||||
RelationalDatabase::MetaTxsList
|
||||
SQLiteDatabaseImp::getNewestAccountTxsB(AccountTxOptions const& options)
|
||||
SQLiteDatabase::getNewestAccountTxsB(AccountTxOptions const& options)
|
||||
{
|
||||
if (!useTxTables_)
|
||||
return {};
|
||||
@@ -600,7 +398,8 @@ SQLiteDatabaseImp::getNewestAccountTxsB(AccountTxOptions const& options)
|
||||
if (existsTransaction())
|
||||
{
|
||||
auto db = checkoutTransaction();
|
||||
return detail::getNewestAccountTxsB(*db, app_, options, j_).first;
|
||||
return detail::getNewestAccountTxsB(*db, registry_.app(), options, j_)
|
||||
.first;
|
||||
}
|
||||
|
||||
return {};
|
||||
@@ -609,17 +408,16 @@ SQLiteDatabaseImp::getNewestAccountTxsB(AccountTxOptions const& options)
|
||||
std::pair<
|
||||
RelationalDatabase::AccountTxs,
|
||||
std::optional<RelationalDatabase::AccountTxMarker>>
|
||||
SQLiteDatabaseImp::oldestAccountTxPage(AccountTxPageOptions const& options)
|
||||
SQLiteDatabase::oldestAccountTxPage(AccountTxPageOptions const& options)
|
||||
{
|
||||
if (!useTxTables_)
|
||||
return {};
|
||||
|
||||
static std::uint32_t const page_length(200);
|
||||
auto onUnsavedLedger =
|
||||
std::bind(saveLedgerAsync, std::ref(app_), std::placeholders::_1);
|
||||
auto onUnsavedLedger = std::bind(
|
||||
saveLedgerAsync, std::ref(registry_.app()), std::placeholders::_1);
|
||||
AccountTxs ret;
|
||||
Application& app = app_;
|
||||
auto onTransaction = [&ret, &app](
|
||||
auto onTransaction = [&ret, &app = registry_.app()](
|
||||
std::uint32_t ledger_index,
|
||||
std::string const& status,
|
||||
Blob&& rawTxn,
|
||||
@@ -643,17 +441,16 @@ SQLiteDatabaseImp::oldestAccountTxPage(AccountTxPageOptions const& options)
|
||||
std::pair<
|
||||
RelationalDatabase::AccountTxs,
|
||||
std::optional<RelationalDatabase::AccountTxMarker>>
|
||||
SQLiteDatabaseImp::newestAccountTxPage(AccountTxPageOptions const& options)
|
||||
SQLiteDatabase::newestAccountTxPage(AccountTxPageOptions const& options)
|
||||
{
|
||||
if (!useTxTables_)
|
||||
return {};
|
||||
|
||||
static std::uint32_t const page_length(200);
|
||||
auto onUnsavedLedger =
|
||||
std::bind(saveLedgerAsync, std::ref(app_), std::placeholders::_1);
|
||||
auto onUnsavedLedger = std::bind(
|
||||
saveLedgerAsync, std::ref(registry_.app()), std::placeholders::_1);
|
||||
AccountTxs ret;
|
||||
Application& app = app_;
|
||||
auto onTransaction = [&ret, &app](
|
||||
auto onTransaction = [&ret, &app = registry_.app()](
|
||||
std::uint32_t ledger_index,
|
||||
std::string const& status,
|
||||
Blob&& rawTxn,
|
||||
@@ -677,14 +474,14 @@ SQLiteDatabaseImp::newestAccountTxPage(AccountTxPageOptions const& options)
|
||||
std::pair<
|
||||
RelationalDatabase::MetaTxsList,
|
||||
std::optional<RelationalDatabase::AccountTxMarker>>
|
||||
SQLiteDatabaseImp::oldestAccountTxPageB(AccountTxPageOptions const& options)
|
||||
SQLiteDatabase::oldestAccountTxPageB(AccountTxPageOptions const& options)
|
||||
{
|
||||
if (!useTxTables_)
|
||||
return {};
|
||||
|
||||
static std::uint32_t const page_length(500);
|
||||
auto onUnsavedLedger =
|
||||
std::bind(saveLedgerAsync, std::ref(app_), std::placeholders::_1);
|
||||
auto onUnsavedLedger = std::bind(
|
||||
saveLedgerAsync, std::ref(registry_.app()), std::placeholders::_1);
|
||||
MetaTxsList ret;
|
||||
auto onTransaction = [&ret](
|
||||
std::uint32_t ledgerIndex,
|
||||
@@ -710,14 +507,14 @@ SQLiteDatabaseImp::oldestAccountTxPageB(AccountTxPageOptions const& options)
|
||||
std::pair<
|
||||
RelationalDatabase::MetaTxsList,
|
||||
std::optional<RelationalDatabase::AccountTxMarker>>
|
||||
SQLiteDatabaseImp::newestAccountTxPageB(AccountTxPageOptions const& options)
|
||||
SQLiteDatabase::newestAccountTxPageB(AccountTxPageOptions const& options)
|
||||
{
|
||||
if (!useTxTables_)
|
||||
return {};
|
||||
|
||||
static std::uint32_t const page_length(500);
|
||||
auto onUnsavedLedger =
|
||||
std::bind(saveLedgerAsync, std::ref(app_), std::placeholders::_1);
|
||||
auto onUnsavedLedger = std::bind(
|
||||
saveLedgerAsync, std::ref(registry_.app()), std::placeholders::_1);
|
||||
MetaTxsList ret;
|
||||
auto onTransaction = [&ret](
|
||||
std::uint32_t ledgerIndex,
|
||||
@@ -741,7 +538,7 @@ SQLiteDatabaseImp::newestAccountTxPageB(AccountTxPageOptions const& options)
|
||||
}
|
||||
|
||||
std::variant<RelationalDatabase::AccountTx, TxSearched>
|
||||
SQLiteDatabaseImp::getTransaction(
|
||||
SQLiteDatabase::getTransaction(
|
||||
uint256 const& id,
|
||||
std::optional<ClosedInterval<std::uint32_t>> const& range,
|
||||
error_code_i& ec)
|
||||
@@ -752,14 +549,14 @@ SQLiteDatabaseImp::getTransaction(
|
||||
if (existsTransaction())
|
||||
{
|
||||
auto db = checkoutTransaction();
|
||||
return detail::getTransaction(*db, app_, id, range, ec);
|
||||
return detail::getTransaction(*db, registry_.app(), id, range, ec);
|
||||
}
|
||||
|
||||
return TxSearched::unknown;
|
||||
}
|
||||
|
||||
bool
|
||||
SQLiteDatabaseImp::ledgerDbHasSpace(Config const& config)
|
||||
SQLiteDatabase::ledgerDbHasSpace(Config const& config)
|
||||
{
|
||||
if (existsLedger())
|
||||
{
|
||||
@@ -771,7 +568,7 @@ SQLiteDatabaseImp::ledgerDbHasSpace(Config const& config)
|
||||
}
|
||||
|
||||
bool
|
||||
SQLiteDatabaseImp::transactionDbHasSpace(Config const& config)
|
||||
SQLiteDatabase::transactionDbHasSpace(Config const& config)
|
||||
{
|
||||
if (!useTxTables_)
|
||||
return true;
|
||||
@@ -786,7 +583,7 @@ SQLiteDatabaseImp::transactionDbHasSpace(Config const& config)
|
||||
}
|
||||
|
||||
std::uint32_t
|
||||
SQLiteDatabaseImp::getKBUsedAll()
|
||||
SQLiteDatabase::getKBUsedAll()
|
||||
{
|
||||
if (existsLedger())
|
||||
{
|
||||
@@ -797,7 +594,7 @@ SQLiteDatabaseImp::getKBUsedAll()
|
||||
}
|
||||
|
||||
std::uint32_t
|
||||
SQLiteDatabaseImp::getKBUsedLedger()
|
||||
SQLiteDatabase::getKBUsedLedger()
|
||||
{
|
||||
if (existsLedger())
|
||||
{
|
||||
@@ -808,7 +605,7 @@ SQLiteDatabaseImp::getKBUsedLedger()
|
||||
}
|
||||
|
||||
std::uint32_t
|
||||
SQLiteDatabaseImp::getKBUsedTransaction()
|
||||
SQLiteDatabase::getKBUsedTransaction()
|
||||
{
|
||||
if (!useTxTables_)
|
||||
return 0;
|
||||
@@ -822,21 +619,24 @@ SQLiteDatabaseImp::getKBUsedTransaction()
|
||||
}
|
||||
|
||||
void
|
||||
SQLiteDatabaseImp::closeLedgerDB()
|
||||
SQLiteDatabase::closeLedgerDB()
|
||||
{
|
||||
ledgerDb_.reset();
|
||||
}
|
||||
|
||||
void
|
||||
SQLiteDatabaseImp::closeTransactionDB()
|
||||
SQLiteDatabase::closeTransactionDB()
|
||||
{
|
||||
txdb_.reset();
|
||||
}
|
||||
|
||||
std::unique_ptr<RelationalDatabase>
|
||||
getSQLiteDatabase(Application& app, Config const& config, JobQueue& jobQueue)
|
||||
std::unique_ptr<SQLiteDatabase>
|
||||
setup_RelationalDatabase(
|
||||
ServiceRegistry& registry,
|
||||
Config const& config,
|
||||
JobQueue& jobQueue)
|
||||
{
|
||||
return std::make_unique<SQLiteDatabaseImp>(app, config, jobQueue);
|
||||
return std::make_unique<SQLiteDatabase>(registry, config, jobQueue);
|
||||
}
|
||||
|
||||
} // namespace xrpl
|
||||
|
||||
@@ -1,45 +0,0 @@
|
||||
#include <xrpld/app/main/Application.h>
|
||||
#include <xrpld/app/rdb/RelationalDatabase.h>
|
||||
#include <xrpld/core/ConfigSections.h>
|
||||
|
||||
namespace xrpl {
|
||||
|
||||
extern std::unique_ptr<RelationalDatabase>
|
||||
getSQLiteDatabase(Application& app, Config const& config, JobQueue& jobQueue);
|
||||
|
||||
std::unique_ptr<RelationalDatabase>
|
||||
RelationalDatabase::init(
|
||||
Application& app,
|
||||
Config const& config,
|
||||
JobQueue& jobQueue)
|
||||
{
|
||||
bool use_sqlite = false;
|
||||
|
||||
Section const& rdb_section{config.section(SECTION_RELATIONAL_DB)};
|
||||
if (!rdb_section.empty())
|
||||
{
|
||||
if (boost::iequals(get(rdb_section, "backend"), "sqlite"))
|
||||
{
|
||||
use_sqlite = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
Throw<std::runtime_error>(
|
||||
"Invalid rdb_section backend value: " +
|
||||
get(rdb_section, "backend"));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
use_sqlite = true;
|
||||
}
|
||||
|
||||
if (use_sqlite)
|
||||
{
|
||||
return getSQLiteDatabase(app, config, jobQueue);
|
||||
}
|
||||
|
||||
return std::unique_ptr<RelationalDatabase>();
|
||||
}
|
||||
|
||||
} // namespace xrpl
|
||||
@@ -5,7 +5,9 @@
|
||||
#include <xrpl/basics/base_uint.h>
|
||||
#include <xrpl/beast/net/IPEndpoint.h>
|
||||
#include <xrpl/beast/utility/Journal.h>
|
||||
#include <xrpl/core/StartUpType.h>
|
||||
#include <xrpl/protocol/SystemParameters.h> // VFALCO Breaks levelization
|
||||
#include <xrpl/rdb/DatabaseCon.h>
|
||||
|
||||
#include <boost/filesystem.hpp> // VFALCO FIX: This include should not be here
|
||||
|
||||
@@ -125,8 +127,7 @@ public:
|
||||
// Entries from [ips_fixed] config stanza
|
||||
std::vector<std::string> IPS_FIXED;
|
||||
|
||||
enum StartUpType { FRESH, NORMAL, LOAD, LOAD_FILE, REPLAY, NETWORK };
|
||||
StartUpType START_UP = NORMAL;
|
||||
StartUpType START_UP = StartUpType::NORMAL;
|
||||
|
||||
bool START_VALID = false;
|
||||
|
||||
@@ -363,6 +364,11 @@ public:
|
||||
FeeSetup
|
||||
setup_FeeVote(Section const& section);
|
||||
|
||||
DatabaseCon::Setup
|
||||
setup_DatabaseCon(
|
||||
Config const& c,
|
||||
std::optional<beast::Journal> j = std::nullopt);
|
||||
|
||||
} // namespace xrpl
|
||||
|
||||
#endif
|
||||
|
||||
174
src/xrpld/core/ServiceRegistryImpl.h
Normal file
174
src/xrpld/core/ServiceRegistryImpl.h
Normal file
@@ -0,0 +1,174 @@
|
||||
#ifndef XRPLD_CORE_SERVICEREGISTRYIMPL_H_INCLUDED
|
||||
#define XRPLD_CORE_SERVICEREGISTRYIMPL_H_INCLUDED
|
||||
|
||||
#include <xrpl/core/ServiceRegistry.h>
|
||||
|
||||
namespace xrpl {
|
||||
|
||||
// Forward declaration
|
||||
class Application;
|
||||
|
||||
/** Implementation of ServiceRegistry that delegates to Application.
|
||||
|
||||
This class provides a ServiceRegistry interface that wraps an Application
|
||||
reference. It allows components to depend on ServiceRegistry instead of
|
||||
Application, enabling gradual migration and better separation of concerns.
|
||||
|
||||
Usage:
|
||||
Application& app = ...;
|
||||
ServiceRegistry& registry = app.getServiceRegistry();
|
||||
// or
|
||||
ServiceRegistryImpl registry(app);
|
||||
*/
|
||||
class ServiceRegistryImpl : public ServiceRegistry
|
||||
{
|
||||
public:
|
||||
explicit ServiceRegistryImpl(Application& app);
|
||||
|
||||
~ServiceRegistryImpl() override = default;
|
||||
|
||||
// Core infrastructure services
|
||||
CollectorManager&
|
||||
getCollectorManager() override;
|
||||
|
||||
Family&
|
||||
getNodeFamily() override;
|
||||
|
||||
TimeKeeper&
|
||||
timeKeeper() override;
|
||||
|
||||
JobQueue&
|
||||
getJobQueue() override;
|
||||
|
||||
NodeCache&
|
||||
getTempNodeCache() override;
|
||||
|
||||
CachedSLEs&
|
||||
cachedSLEs() override;
|
||||
|
||||
// Protocol and validation services
|
||||
AmendmentTable&
|
||||
getAmendmentTable() override;
|
||||
|
||||
HashRouter&
|
||||
getHashRouter() override;
|
||||
|
||||
LoadFeeTrack&
|
||||
getFeeTrack() override;
|
||||
|
||||
LoadManager&
|
||||
getLoadManager() override;
|
||||
|
||||
RCLValidations&
|
||||
getValidations() override;
|
||||
|
||||
ValidatorList&
|
||||
validators() override;
|
||||
|
||||
ValidatorSite&
|
||||
validatorSites() override;
|
||||
|
||||
ManifestCache&
|
||||
validatorManifests() override;
|
||||
|
||||
ManifestCache&
|
||||
publisherManifests() override;
|
||||
|
||||
// Network services
|
||||
Overlay&
|
||||
overlay() override;
|
||||
|
||||
Cluster&
|
||||
cluster() override;
|
||||
|
||||
PeerReservationTable&
|
||||
peerReservations() override;
|
||||
|
||||
Resource::Manager&
|
||||
getResourceManager() override;
|
||||
|
||||
// Storage services
|
||||
NodeStore::Database&
|
||||
getNodeStore() override;
|
||||
|
||||
SHAMapStore&
|
||||
getSHAMapStore() override;
|
||||
|
||||
RelationalDatabase&
|
||||
getRelationalDatabase() override;
|
||||
|
||||
// Ledger services
|
||||
InboundLedgers&
|
||||
getInboundLedgers() override;
|
||||
|
||||
InboundTransactions&
|
||||
getInboundTransactions() override;
|
||||
|
||||
TaggedCache<uint256, AcceptedLedger>&
|
||||
getAcceptedLedgerCache() override;
|
||||
|
||||
LedgerMaster&
|
||||
getLedgerMaster() override;
|
||||
|
||||
LedgerCleaner&
|
||||
getLedgerCleaner() override;
|
||||
|
||||
LedgerReplayer&
|
||||
getLedgerReplayer() override;
|
||||
|
||||
PendingSaves&
|
||||
pendingSaves() override;
|
||||
|
||||
OpenLedger&
|
||||
openLedger() override;
|
||||
|
||||
OpenLedger const&
|
||||
openLedger() const override;
|
||||
|
||||
// Transaction and operation services
|
||||
NetworkOPs&
|
||||
getOPs() override;
|
||||
|
||||
OrderBookDB&
|
||||
getOrderBookDB() override;
|
||||
|
||||
TransactionMaster&
|
||||
getMasterTransaction() override;
|
||||
|
||||
TxQ&
|
||||
getTxQ() override;
|
||||
|
||||
PathRequests&
|
||||
getPathRequests() override;
|
||||
|
||||
// Server services
|
||||
ServerHandler&
|
||||
getServerHandler() override;
|
||||
|
||||
perf::PerfLog&
|
||||
getPerfLog() override;
|
||||
|
||||
// Configuration and state
|
||||
bool
|
||||
isStopping() const override;
|
||||
|
||||
beast::Journal
|
||||
journal(std::string const& name) override;
|
||||
|
||||
boost::asio::io_context&
|
||||
getIOContext() override;
|
||||
|
||||
Logs&
|
||||
logs() override;
|
||||
|
||||
// Temporary: Get the underlying Application
|
||||
Application&
|
||||
app() override;
|
||||
|
||||
private:
|
||||
Application& app_;
|
||||
};
|
||||
|
||||
} // namespace xrpl
|
||||
|
||||
#endif
|
||||
@@ -1126,4 +1126,173 @@ setup_FeeVote(Section const& section)
|
||||
return setup;
|
||||
}
|
||||
|
||||
DatabaseCon::Setup
|
||||
setup_DatabaseCon(Config const& c, std::optional<beast::Journal> j)
|
||||
{
|
||||
DatabaseCon::Setup setup;
|
||||
|
||||
setup.startUp = c.START_UP;
|
||||
setup.standAlone = c.standalone();
|
||||
setup.dataDir = c.legacy("database_path");
|
||||
if (!setup.standAlone && setup.dataDir.empty())
|
||||
{
|
||||
Throw<std::runtime_error>("database_path must be set.");
|
||||
}
|
||||
|
||||
if (!setup.globalPragma)
|
||||
{
|
||||
setup.globalPragma = [&c, &j]() {
|
||||
auto const& sqlite = c.section("sqlite");
|
||||
auto result = std::make_unique<std::vector<std::string>>();
|
||||
result->reserve(3);
|
||||
|
||||
// defaults
|
||||
std::string safety_level;
|
||||
std::string journal_mode = "wal";
|
||||
std::string synchronous = "normal";
|
||||
std::string temp_store = "file";
|
||||
bool showRiskWarning = false;
|
||||
|
||||
if (set(safety_level, "safety_level", sqlite))
|
||||
{
|
||||
if (boost::iequals(safety_level, "low"))
|
||||
{
|
||||
// low safety defaults
|
||||
journal_mode = "memory";
|
||||
synchronous = "off";
|
||||
temp_store = "memory";
|
||||
showRiskWarning = true;
|
||||
}
|
||||
else if (!boost::iequals(safety_level, "high"))
|
||||
{
|
||||
Throw<std::runtime_error>(
|
||||
"Invalid safety_level value: " + safety_level);
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
// #journal_mode Valid values : delete, truncate, persist,
|
||||
// memory, wal, off
|
||||
if (set(journal_mode, "journal_mode", sqlite) &&
|
||||
!safety_level.empty())
|
||||
{
|
||||
Throw<std::runtime_error>(
|
||||
"Configuration file may not define both "
|
||||
"\"safety_level\" and \"journal_mode\"");
|
||||
}
|
||||
bool higherRisk = boost::iequals(journal_mode, "memory") ||
|
||||
boost::iequals(journal_mode, "off");
|
||||
showRiskWarning = showRiskWarning || higherRisk;
|
||||
if (higherRisk || boost::iequals(journal_mode, "delete") ||
|
||||
boost::iequals(journal_mode, "truncate") ||
|
||||
boost::iequals(journal_mode, "persist") ||
|
||||
boost::iequals(journal_mode, "wal"))
|
||||
{
|
||||
result->emplace_back(boost::str(
|
||||
boost::format(CommonDBPragmaJournal) % journal_mode));
|
||||
}
|
||||
else
|
||||
{
|
||||
Throw<std::runtime_error>(
|
||||
"Invalid journal_mode value: " + journal_mode);
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
// #synchronous Valid values : off, normal, full, extra
|
||||
if (set(synchronous, "synchronous", sqlite) &&
|
||||
!safety_level.empty())
|
||||
{
|
||||
Throw<std::runtime_error>(
|
||||
"Configuration file may not define both "
|
||||
"\"safety_level\" and \"synchronous\"");
|
||||
}
|
||||
bool higherRisk = boost::iequals(synchronous, "off");
|
||||
showRiskWarning = showRiskWarning || higherRisk;
|
||||
if (higherRisk || boost::iequals(synchronous, "normal") ||
|
||||
boost::iequals(synchronous, "full") ||
|
||||
boost::iequals(synchronous, "extra"))
|
||||
{
|
||||
result->emplace_back(boost::str(
|
||||
boost::format(CommonDBPragmaSync) % synchronous));
|
||||
}
|
||||
else
|
||||
{
|
||||
Throw<std::runtime_error>(
|
||||
"Invalid synchronous value: " + synchronous);
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
// #temp_store Valid values : default, file, memory
|
||||
if (set(temp_store, "temp_store", sqlite) &&
|
||||
!safety_level.empty())
|
||||
{
|
||||
Throw<std::runtime_error>(
|
||||
"Configuration file may not define both "
|
||||
"\"safety_level\" and \"temp_store\"");
|
||||
}
|
||||
bool higherRisk = boost::iequals(temp_store, "memory");
|
||||
showRiskWarning = showRiskWarning || higherRisk;
|
||||
if (higherRisk || boost::iequals(temp_store, "default") ||
|
||||
boost::iequals(temp_store, "file"))
|
||||
{
|
||||
result->emplace_back(boost::str(
|
||||
boost::format(CommonDBPragmaTemp) % temp_store));
|
||||
}
|
||||
else
|
||||
{
|
||||
Throw<std::runtime_error>(
|
||||
"Invalid temp_store value: " + temp_store);
|
||||
}
|
||||
}
|
||||
|
||||
if (showRiskWarning && j && c.LEDGER_HISTORY > SQLITE_TUNING_CUTOFF)
|
||||
{
|
||||
JLOG(j->warn())
|
||||
<< "reducing the data integrity guarantees from the "
|
||||
"default [sqlite] behavior is not recommended for "
|
||||
"nodes storing large amounts of history, because of the "
|
||||
"difficulty inherent in rebuilding corrupted data.";
|
||||
}
|
||||
XRPL_ASSERT(
|
||||
result->size() == 3,
|
||||
"xrpl::setup_DatabaseCon::globalPragma : result size is 3");
|
||||
return result;
|
||||
}();
|
||||
}
|
||||
setup.useGlobalPragma = true;
|
||||
|
||||
auto setPragma =
|
||||
[](std::string& pragma, std::string const& key, int64_t value) {
|
||||
pragma = "PRAGMA " + key + "=" + std::to_string(value) + ";";
|
||||
};
|
||||
|
||||
// Lgr Pragma
|
||||
setPragma(setup.lgrPragma[0], "journal_size_limit", 1582080);
|
||||
|
||||
// TX Pragma
|
||||
int64_t page_size = 4096;
|
||||
int64_t journal_size_limit = 1582080;
|
||||
if (c.exists("sqlite"))
|
||||
{
|
||||
auto& s = c.section("sqlite");
|
||||
set(journal_size_limit, "journal_size_limit", s);
|
||||
set(page_size, "page_size", s);
|
||||
if (page_size < 512 || page_size > 65536)
|
||||
Throw<std::runtime_error>(
|
||||
"Invalid page_size. Must be between 512 and 65536.");
|
||||
|
||||
if (page_size & (page_size - 1))
|
||||
Throw<std::runtime_error>(
|
||||
"Invalid page_size. Must be a power of 2.");
|
||||
}
|
||||
|
||||
setPragma(setup.txPragma[0], "page_size", page_size);
|
||||
setPragma(setup.txPragma[1], "journal_size_limit", journal_size_limit);
|
||||
setPragma(setup.txPragma[2], "max_page_count", 4294967294);
|
||||
setPragma(setup.txPragma[3], "mmap_size", 17179869184);
|
||||
|
||||
return setup;
|
||||
}
|
||||
} // namespace xrpl
|
||||
|
||||
@@ -1,268 +0,0 @@
|
||||
#include <xrpld/core/DatabaseCon.h>
|
||||
#include <xrpld/core/SociDB.h>
|
||||
|
||||
#include <xrpl/basics/Log.h>
|
||||
#include <xrpl/basics/contract.h>
|
||||
|
||||
#include <boost/algorithm/string.hpp>
|
||||
#include <boost/format.hpp>
|
||||
|
||||
#include <memory>
|
||||
#include <unordered_map>
|
||||
|
||||
namespace xrpl {
|
||||
|
||||
class CheckpointersCollection
|
||||
{
|
||||
std::uintptr_t nextId_{0};
|
||||
// Mutex protects the CheckpointersCollection
|
||||
std::mutex mutex_;
|
||||
// Each checkpointer is given a unique id. All the checkpointers that are
|
||||
// part of a DatabaseCon are part of this collection. When the DatabaseCon
|
||||
// is destroyed, its checkpointer is removed from the collection
|
||||
std::unordered_map<std::uintptr_t, std::shared_ptr<Checkpointer>>
|
||||
checkpointers_;
|
||||
|
||||
public:
|
||||
std::shared_ptr<Checkpointer>
|
||||
fromId(std::uintptr_t id)
|
||||
{
|
||||
std::lock_guard l{mutex_};
|
||||
auto it = checkpointers_.find(id);
|
||||
if (it != checkpointers_.end())
|
||||
return it->second;
|
||||
return {};
|
||||
}
|
||||
|
||||
void
|
||||
erase(std::uintptr_t id)
|
||||
{
|
||||
std::lock_guard lock{mutex_};
|
||||
checkpointers_.erase(id);
|
||||
}
|
||||
|
||||
std::shared_ptr<Checkpointer>
|
||||
create(
|
||||
std::shared_ptr<soci::session> const& session,
|
||||
JobQueue& jobQueue,
|
||||
Logs& logs)
|
||||
{
|
||||
std::lock_guard lock{mutex_};
|
||||
auto const id = nextId_++;
|
||||
auto const r = makeCheckpointer(id, session, jobQueue, logs);
|
||||
checkpointers_[id] = r;
|
||||
return r;
|
||||
}
|
||||
};
|
||||
|
||||
CheckpointersCollection checkpointers;
|
||||
|
||||
std::shared_ptr<Checkpointer>
|
||||
checkpointerFromId(std::uintptr_t id)
|
||||
{
|
||||
return checkpointers.fromId(id);
|
||||
}
|
||||
|
||||
DatabaseCon::~DatabaseCon()
|
||||
{
|
||||
if (checkpointer_)
|
||||
{
|
||||
checkpointers.erase(checkpointer_->id());
|
||||
|
||||
std::weak_ptr<Checkpointer> wk(checkpointer_);
|
||||
checkpointer_.reset();
|
||||
|
||||
// The references to our Checkpointer held by 'checkpointer_' and
|
||||
// 'checkpointers' have been removed, so if the use count is nonzero, a
|
||||
// checkpoint is currently in progress. Wait for it to end, otherwise
|
||||
// creating a new DatabaseCon to the same database may fail due to the
|
||||
// database being locked by our (now old) Checkpointer.
|
||||
while (wk.use_count())
|
||||
{
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(100));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
DatabaseCon::Setup
|
||||
setup_DatabaseCon(Config const& c, std::optional<beast::Journal> j)
|
||||
{
|
||||
DatabaseCon::Setup setup;
|
||||
|
||||
setup.startUp = c.START_UP;
|
||||
setup.standAlone = c.standalone();
|
||||
setup.dataDir = c.legacy("database_path");
|
||||
if (!setup.standAlone && setup.dataDir.empty())
|
||||
{
|
||||
Throw<std::runtime_error>("database_path must be set.");
|
||||
}
|
||||
|
||||
if (!setup.globalPragma)
|
||||
{
|
||||
setup.globalPragma = [&c, &j]() {
|
||||
auto const& sqlite = c.section("sqlite");
|
||||
auto result = std::make_unique<std::vector<std::string>>();
|
||||
result->reserve(3);
|
||||
|
||||
// defaults
|
||||
std::string safety_level;
|
||||
std::string journal_mode = "wal";
|
||||
std::string synchronous = "normal";
|
||||
std::string temp_store = "file";
|
||||
bool showRiskWarning = false;
|
||||
|
||||
if (set(safety_level, "safety_level", sqlite))
|
||||
{
|
||||
if (boost::iequals(safety_level, "low"))
|
||||
{
|
||||
// low safety defaults
|
||||
journal_mode = "memory";
|
||||
synchronous = "off";
|
||||
temp_store = "memory";
|
||||
showRiskWarning = true;
|
||||
}
|
||||
else if (!boost::iequals(safety_level, "high"))
|
||||
{
|
||||
Throw<std::runtime_error>(
|
||||
"Invalid safety_level value: " + safety_level);
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
// #journal_mode Valid values : delete, truncate, persist,
|
||||
// memory, wal, off
|
||||
if (set(journal_mode, "journal_mode", sqlite) &&
|
||||
!safety_level.empty())
|
||||
{
|
||||
Throw<std::runtime_error>(
|
||||
"Configuration file may not define both "
|
||||
"\"safety_level\" and \"journal_mode\"");
|
||||
}
|
||||
bool higherRisk = boost::iequals(journal_mode, "memory") ||
|
||||
boost::iequals(journal_mode, "off");
|
||||
showRiskWarning = showRiskWarning || higherRisk;
|
||||
if (higherRisk || boost::iequals(journal_mode, "delete") ||
|
||||
boost::iequals(journal_mode, "truncate") ||
|
||||
boost::iequals(journal_mode, "persist") ||
|
||||
boost::iequals(journal_mode, "wal"))
|
||||
{
|
||||
result->emplace_back(boost::str(
|
||||
boost::format(CommonDBPragmaJournal) % journal_mode));
|
||||
}
|
||||
else
|
||||
{
|
||||
Throw<std::runtime_error>(
|
||||
"Invalid journal_mode value: " + journal_mode);
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
// #synchronous Valid values : off, normal, full, extra
|
||||
if (set(synchronous, "synchronous", sqlite) &&
|
||||
!safety_level.empty())
|
||||
{
|
||||
Throw<std::runtime_error>(
|
||||
"Configuration file may not define both "
|
||||
"\"safety_level\" and \"synchronous\"");
|
||||
}
|
||||
bool higherRisk = boost::iequals(synchronous, "off");
|
||||
showRiskWarning = showRiskWarning || higherRisk;
|
||||
if (higherRisk || boost::iequals(synchronous, "normal") ||
|
||||
boost::iequals(synchronous, "full") ||
|
||||
boost::iequals(synchronous, "extra"))
|
||||
{
|
||||
result->emplace_back(boost::str(
|
||||
boost::format(CommonDBPragmaSync) % synchronous));
|
||||
}
|
||||
else
|
||||
{
|
||||
Throw<std::runtime_error>(
|
||||
"Invalid synchronous value: " + synchronous);
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
// #temp_store Valid values : default, file, memory
|
||||
if (set(temp_store, "temp_store", sqlite) &&
|
||||
!safety_level.empty())
|
||||
{
|
||||
Throw<std::runtime_error>(
|
||||
"Configuration file may not define both "
|
||||
"\"safety_level\" and \"temp_store\"");
|
||||
}
|
||||
bool higherRisk = boost::iequals(temp_store, "memory");
|
||||
showRiskWarning = showRiskWarning || higherRisk;
|
||||
if (higherRisk || boost::iequals(temp_store, "default") ||
|
||||
boost::iequals(temp_store, "file"))
|
||||
{
|
||||
result->emplace_back(boost::str(
|
||||
boost::format(CommonDBPragmaTemp) % temp_store));
|
||||
}
|
||||
else
|
||||
{
|
||||
Throw<std::runtime_error>(
|
||||
"Invalid temp_store value: " + temp_store);
|
||||
}
|
||||
}
|
||||
|
||||
if (showRiskWarning && j && c.LEDGER_HISTORY > SQLITE_TUNING_CUTOFF)
|
||||
{
|
||||
JLOG(j->warn())
|
||||
<< "reducing the data integrity guarantees from the "
|
||||
"default [sqlite] behavior is not recommended for "
|
||||
"nodes storing large amounts of history, because of the "
|
||||
"difficulty inherent in rebuilding corrupted data.";
|
||||
}
|
||||
XRPL_ASSERT(
|
||||
result->size() == 3,
|
||||
"xrpl::setup_DatabaseCon::globalPragma : result size is 3");
|
||||
return result;
|
||||
}();
|
||||
}
|
||||
setup.useGlobalPragma = true;
|
||||
|
||||
auto setPragma =
|
||||
[](std::string& pragma, std::string const& key, int64_t value) {
|
||||
pragma = "PRAGMA " + key + "=" + std::to_string(value) + ";";
|
||||
};
|
||||
|
||||
// Lgr Pragma
|
||||
setPragma(setup.lgrPragma[0], "journal_size_limit", 1582080);
|
||||
|
||||
// TX Pragma
|
||||
int64_t page_size = 4096;
|
||||
int64_t journal_size_limit = 1582080;
|
||||
if (c.exists("sqlite"))
|
||||
{
|
||||
auto& s = c.section("sqlite");
|
||||
set(journal_size_limit, "journal_size_limit", s);
|
||||
set(page_size, "page_size", s);
|
||||
if (page_size < 512 || page_size > 65536)
|
||||
Throw<std::runtime_error>(
|
||||
"Invalid page_size. Must be between 512 and 65536.");
|
||||
|
||||
if (page_size & (page_size - 1))
|
||||
Throw<std::runtime_error>(
|
||||
"Invalid page_size. Must be a power of 2.");
|
||||
}
|
||||
|
||||
setPragma(setup.txPragma[0], "page_size", page_size);
|
||||
setPragma(setup.txPragma[1], "journal_size_limit", journal_size_limit);
|
||||
setPragma(setup.txPragma[2], "max_page_count", 4294967294);
|
||||
setPragma(setup.txPragma[3], "mmap_size", 17179869184);
|
||||
|
||||
return setup;
|
||||
}
|
||||
|
||||
std::unique_ptr<std::vector<std::string> const>
|
||||
DatabaseCon::Setup::globalPragma;
|
||||
|
||||
void
|
||||
DatabaseCon::setupCheckpointing(JobQueue* q, Logs& l)
|
||||
{
|
||||
if (!q)
|
||||
Throw<std::logic_error>("No JobQueue");
|
||||
checkpointer_ = checkpointers.create(session_, *q, l);
|
||||
}
|
||||
|
||||
} // namespace xrpl
|
||||
276
src/xrpld/core/detail/ServiceRegistryImpl.cpp
Normal file
276
src/xrpld/core/detail/ServiceRegistryImpl.cpp
Normal file
@@ -0,0 +1,276 @@
|
||||
#include <xrpld/app/main/Application.h>
|
||||
#include <xrpld/core/ServiceRegistryImpl.h>
|
||||
|
||||
namespace xrpl {
|
||||
|
||||
ServiceRegistryImpl::ServiceRegistryImpl(Application& app) : app_(app)
|
||||
{
|
||||
}
|
||||
|
||||
// Core infrastructure services
|
||||
CollectorManager&
|
||||
ServiceRegistryImpl::getCollectorManager()
|
||||
{
|
||||
return app_.getCollectorManager();
|
||||
}
|
||||
|
||||
Family&
|
||||
ServiceRegistryImpl::getNodeFamily()
|
||||
{
|
||||
return app_.getNodeFamily();
|
||||
}
|
||||
|
||||
TimeKeeper&
|
||||
ServiceRegistryImpl::timeKeeper()
|
||||
{
|
||||
return app_.timeKeeper();
|
||||
}
|
||||
|
||||
JobQueue&
|
||||
ServiceRegistryImpl::getJobQueue()
|
||||
{
|
||||
return app_.getJobQueue();
|
||||
}
|
||||
|
||||
NodeCache&
|
||||
ServiceRegistryImpl::getTempNodeCache()
|
||||
{
|
||||
return app_.getTempNodeCache();
|
||||
}
|
||||
|
||||
CachedSLEs&
|
||||
ServiceRegistryImpl::cachedSLEs()
|
||||
{
|
||||
return app_.cachedSLEs();
|
||||
}
|
||||
|
||||
// Protocol and validation services
|
||||
AmendmentTable&
|
||||
ServiceRegistryImpl::getAmendmentTable()
|
||||
{
|
||||
return app_.getAmendmentTable();
|
||||
}
|
||||
|
||||
HashRouter&
|
||||
ServiceRegistryImpl::getHashRouter()
|
||||
{
|
||||
return app_.getHashRouter();
|
||||
}
|
||||
|
||||
LoadFeeTrack&
|
||||
ServiceRegistryImpl::getFeeTrack()
|
||||
{
|
||||
return app_.getFeeTrack();
|
||||
}
|
||||
|
||||
LoadManager&
|
||||
ServiceRegistryImpl::getLoadManager()
|
||||
{
|
||||
return app_.getLoadManager();
|
||||
}
|
||||
|
||||
RCLValidations&
|
||||
ServiceRegistryImpl::getValidations()
|
||||
{
|
||||
return app_.getValidations();
|
||||
}
|
||||
|
||||
ValidatorList&
|
||||
ServiceRegistryImpl::validators()
|
||||
{
|
||||
return app_.validators();
|
||||
}
|
||||
|
||||
ValidatorSite&
|
||||
ServiceRegistryImpl::validatorSites()
|
||||
{
|
||||
return app_.validatorSites();
|
||||
}
|
||||
|
||||
ManifestCache&
|
||||
ServiceRegistryImpl::validatorManifests()
|
||||
{
|
||||
return app_.validatorManifests();
|
||||
}
|
||||
|
||||
ManifestCache&
|
||||
ServiceRegistryImpl::publisherManifests()
|
||||
{
|
||||
return app_.publisherManifests();
|
||||
}
|
||||
|
||||
// Network services
|
||||
Overlay&
|
||||
ServiceRegistryImpl::overlay()
|
||||
{
|
||||
return app_.overlay();
|
||||
}
|
||||
|
||||
Cluster&
|
||||
ServiceRegistryImpl::cluster()
|
||||
{
|
||||
return app_.cluster();
|
||||
}
|
||||
|
||||
PeerReservationTable&
|
||||
ServiceRegistryImpl::peerReservations()
|
||||
{
|
||||
return app_.peerReservations();
|
||||
}
|
||||
|
||||
Resource::Manager&
|
||||
ServiceRegistryImpl::getResourceManager()
|
||||
{
|
||||
return app_.getResourceManager();
|
||||
}
|
||||
|
||||
// Storage services
|
||||
NodeStore::Database&
|
||||
ServiceRegistryImpl::getNodeStore()
|
||||
{
|
||||
return app_.getNodeStore();
|
||||
}
|
||||
|
||||
SHAMapStore&
|
||||
ServiceRegistryImpl::getSHAMapStore()
|
||||
{
|
||||
return app_.getSHAMapStore();
|
||||
}
|
||||
|
||||
RelationalDatabase&
|
||||
ServiceRegistryImpl::getRelationalDatabase()
|
||||
{
|
||||
return app_.getRelationalDatabase();
|
||||
}
|
||||
|
||||
// Ledger services
|
||||
InboundLedgers&
|
||||
ServiceRegistryImpl::getInboundLedgers()
|
||||
{
|
||||
return app_.getInboundLedgers();
|
||||
}
|
||||
|
||||
InboundTransactions&
|
||||
ServiceRegistryImpl::getInboundTransactions()
|
||||
{
|
||||
return app_.getInboundTransactions();
|
||||
}
|
||||
|
||||
TaggedCache<uint256, AcceptedLedger>&
|
||||
ServiceRegistryImpl::getAcceptedLedgerCache()
|
||||
{
|
||||
return app_.getAcceptedLedgerCache();
|
||||
}
|
||||
|
||||
LedgerMaster&
|
||||
ServiceRegistryImpl::getLedgerMaster()
|
||||
{
|
||||
return app_.getLedgerMaster();
|
||||
}
|
||||
|
||||
LedgerCleaner&
|
||||
ServiceRegistryImpl::getLedgerCleaner()
|
||||
{
|
||||
return app_.getLedgerCleaner();
|
||||
}
|
||||
|
||||
LedgerReplayer&
|
||||
ServiceRegistryImpl::getLedgerReplayer()
|
||||
{
|
||||
return app_.getLedgerReplayer();
|
||||
}
|
||||
|
||||
PendingSaves&
|
||||
ServiceRegistryImpl::pendingSaves()
|
||||
{
|
||||
return app_.pendingSaves();
|
||||
}
|
||||
|
||||
OpenLedger&
|
||||
ServiceRegistryImpl::openLedger()
|
||||
{
|
||||
return app_.openLedger();
|
||||
}
|
||||
|
||||
OpenLedger const&
|
||||
ServiceRegistryImpl::openLedger() const
|
||||
{
|
||||
return app_.openLedger();
|
||||
}
|
||||
|
||||
// Transaction and operation services
|
||||
NetworkOPs&
|
||||
ServiceRegistryImpl::getOPs()
|
||||
{
|
||||
return app_.getOPs();
|
||||
}
|
||||
|
||||
OrderBookDB&
|
||||
ServiceRegistryImpl::getOrderBookDB()
|
||||
{
|
||||
return app_.getOrderBookDB();
|
||||
}
|
||||
|
||||
TransactionMaster&
|
||||
ServiceRegistryImpl::getMasterTransaction()
|
||||
{
|
||||
return app_.getMasterTransaction();
|
||||
}
|
||||
|
||||
TxQ&
|
||||
ServiceRegistryImpl::getTxQ()
|
||||
{
|
||||
return app_.getTxQ();
|
||||
}
|
||||
|
||||
PathRequests&
|
||||
ServiceRegistryImpl::getPathRequests()
|
||||
{
|
||||
return app_.getPathRequests();
|
||||
}
|
||||
|
||||
// Server services
|
||||
ServerHandler&
|
||||
ServiceRegistryImpl::getServerHandler()
|
||||
{
|
||||
return app_.getServerHandler();
|
||||
}
|
||||
|
||||
perf::PerfLog&
|
||||
ServiceRegistryImpl::getPerfLog()
|
||||
{
|
||||
return app_.getPerfLog();
|
||||
}
|
||||
|
||||
// Configuration and state
|
||||
bool
|
||||
ServiceRegistryImpl::isStopping() const
|
||||
{
|
||||
return app_.isStopping();
|
||||
}
|
||||
|
||||
beast::Journal
|
||||
ServiceRegistryImpl::journal(std::string const& name)
|
||||
{
|
||||
return app_.journal(name);
|
||||
}
|
||||
|
||||
boost::asio::io_context&
|
||||
ServiceRegistryImpl::getIOContext()
|
||||
{
|
||||
return app_.getIOContext();
|
||||
}
|
||||
|
||||
Logs&
|
||||
ServiceRegistryImpl::logs()
|
||||
{
|
||||
return app_.logs();
|
||||
}
|
||||
|
||||
Application&
|
||||
ServiceRegistryImpl::app()
|
||||
{
|
||||
return app_;
|
||||
}
|
||||
|
||||
} // namespace xrpl
|
||||
@@ -2,8 +2,6 @@
|
||||
#include <xrpld/app/misc/NetworkOPs.h>
|
||||
#include <xrpld/app/misc/ValidatorList.h>
|
||||
#include <xrpld/app/misc/ValidatorSite.h>
|
||||
#include <xrpld/app/rdb/RelationalDatabase.h>
|
||||
#include <xrpld/app/rdb/Wallet.h>
|
||||
#include <xrpld/overlay/Cluster.h>
|
||||
#include <xrpld/overlay/detail/ConnectAttempt.h>
|
||||
#include <xrpld/overlay/detail/PeerImp.h>
|
||||
@@ -19,7 +17,9 @@
|
||||
#include <xrpl/basics/random.h>
|
||||
#include <xrpl/beast/core/LexicalCast.h>
|
||||
#include <xrpl/protocol/STTx.h>
|
||||
#include <xrpl/rdb/RelationalDatabase.h>
|
||||
#include <xrpl/server/SimpleWriter.h>
|
||||
#include <xrpl/server/Wallet.h>
|
||||
|
||||
#include <boost/algorithm/string/predicate.hpp>
|
||||
#include <boost/asio/executor_work_guard.hpp>
|
||||
|
||||
@@ -1,10 +1,9 @@
|
||||
#include <xrpld/app/rdb/RelationalDatabase.h>
|
||||
#include <xrpld/app/rdb/Wallet.h>
|
||||
#include <xrpld/overlay/PeerReservationTable.h>
|
||||
|
||||
#include <xrpl/core/PeerReservationTable.h>
|
||||
#include <xrpl/json/json_value.h>
|
||||
#include <xrpl/protocol/PublicKey.h>
|
||||
#include <xrpl/protocol/jss.h>
|
||||
#include <xrpl/rdb/RelationalDatabase.h>
|
||||
#include <xrpl/server/Wallet.h>
|
||||
|
||||
#include <algorithm>
|
||||
#include <iterator>
|
||||
|
||||
@@ -2,9 +2,10 @@
|
||||
#define XRPL_PEERFINDER_STORESQDB_H_INCLUDED
|
||||
|
||||
#include <xrpld/app/rdb/PeerFinder.h>
|
||||
#include <xrpld/core/SociDB.h>
|
||||
#include <xrpld/peerfinder/detail/Store.h>
|
||||
|
||||
#include <xrpl/rdb/SociDB.h>
|
||||
|
||||
namespace xrpl {
|
||||
namespace PeerFinder {
|
||||
|
||||
|
||||
@@ -1,13 +1,12 @@
|
||||
#ifndef XRPL_NET_INFOSUB_H_INCLUDED
|
||||
#define XRPL_NET_INFOSUB_H_INCLUDED
|
||||
|
||||
#include <xrpld/app/misc/Manifest.h>
|
||||
|
||||
#include <xrpl/basics/CountedObject.h>
|
||||
#include <xrpl/json/json_value.h>
|
||||
#include <xrpl/protocol/Book.h>
|
||||
#include <xrpl/protocol/ErrorCodes.h>
|
||||
#include <xrpl/resource/Consumer.h>
|
||||
#include <xrpl/server/Manifest.h>
|
||||
|
||||
namespace xrpl {
|
||||
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
#include <xrpld/app/misc/Transaction.h>
|
||||
#include <xrpld/app/paths/TrustLine.h>
|
||||
#include <xrpld/app/rdb/RelationalDatabase.h>
|
||||
#include <xrpld/app/tx/detail/NFTokenUtils.h>
|
||||
#include <xrpld/rpc/Context.h>
|
||||
#include <xrpld/rpc/DeliveredAmount.h>
|
||||
@@ -10,6 +9,7 @@
|
||||
#include <xrpl/protocol/AccountID.h>
|
||||
#include <xrpl/protocol/RPCErr.h>
|
||||
#include <xrpl/protocol/nftPageMask.h>
|
||||
#include <xrpl/rdb/RelationalDatabase.h>
|
||||
#include <xrpl/resource/Fees.h>
|
||||
|
||||
#include <boost/algorithm/string/case_conv.hpp>
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
#include <xrpld/rpc/detail/Tuning.h>
|
||||
|
||||
#include <xrpl/proto/org/xrpl/rpc/v1/xrp_ledger.pb.h>
|
||||
#include <xrpl/protocol/LedgerShortcut.h>
|
||||
|
||||
#include <optional>
|
||||
|
||||
@@ -20,8 +21,6 @@ namespace RPC {
|
||||
|
||||
struct JsonContext;
|
||||
|
||||
enum class LedgerShortcut { Current, Closed, Validated };
|
||||
|
||||
/**
|
||||
* @brief Retrieves a ledger by its hash.
|
||||
*
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
#include <xrpld/rpc/MPTokenIssuanceID.h>
|
||||
#include <xrpld/rpc/Role.h>
|
||||
#include <xrpld/rpc/detail/RPCHelpers.h>
|
||||
#include <xrpld/rpc/detail/RPCLedgerHelpers.h>
|
||||
#include <xrpld/rpc/detail/Tuning.h>
|
||||
|
||||
#include <xrpl/json/json_value.h>
|
||||
@@ -26,8 +27,6 @@ using TxnsDataBinary = RelationalDatabase::MetaTxsList;
|
||||
using TxnDataBinary = RelationalDatabase::txnMetaLedgerType;
|
||||
using AccountTxArgs = RelationalDatabase::AccountTxArgs;
|
||||
using AccountTxResult = RelationalDatabase::AccountTxResult;
|
||||
|
||||
using LedgerShortcut = RelationalDatabase::LedgerShortcut;
|
||||
using LedgerSpecifier = RelationalDatabase::LedgerSpecifier;
|
||||
|
||||
// parses args into a ledger specifier, or returns a Json object on error
|
||||
@@ -220,23 +219,19 @@ doAccountTxHelp(RPC::Context& context, AccountTxArgs const& args)
|
||||
args.limit,
|
||||
isUnlimited(context.role)};
|
||||
|
||||
auto const db =
|
||||
dynamic_cast<SQLiteDatabase*>(&context.app.getRelationalDatabase());
|
||||
|
||||
if (!db)
|
||||
Throw<std::runtime_error>("Failed to get relational database");
|
||||
auto& db = context.app.getRelationalDatabase();
|
||||
|
||||
if (args.binary)
|
||||
{
|
||||
if (args.forward)
|
||||
{
|
||||
auto [tx, marker] = db->oldestAccountTxPageB(options);
|
||||
auto [tx, marker] = db.oldestAccountTxPageB(options);
|
||||
result.transactions = tx;
|
||||
result.marker = marker;
|
||||
}
|
||||
else
|
||||
{
|
||||
auto [tx, marker] = db->newestAccountTxPageB(options);
|
||||
auto [tx, marker] = db.newestAccountTxPageB(options);
|
||||
result.transactions = tx;
|
||||
result.marker = marker;
|
||||
}
|
||||
@@ -245,13 +240,13 @@ doAccountTxHelp(RPC::Context& context, AccountTxArgs const& args)
|
||||
{
|
||||
if (args.forward)
|
||||
{
|
||||
auto [tx, marker] = db->oldestAccountTxPage(options);
|
||||
auto [tx, marker] = db.oldestAccountTxPage(options);
|
||||
result.transactions = tx;
|
||||
result.marker = marker;
|
||||
}
|
||||
else
|
||||
{
|
||||
auto [tx, marker] = db->newestAccountTxPage(options);
|
||||
auto [tx, marker] = db.newestAccountTxPage(options);
|
||||
result.transactions = tx;
|
||||
result.marker = marker;
|
||||
}
|
||||
|
||||
@@ -53,23 +53,19 @@ getCountsJson(Application& app, int minObjectCount)
|
||||
|
||||
if (app.config().useTxTables())
|
||||
{
|
||||
auto const db =
|
||||
dynamic_cast<SQLiteDatabase*>(&app.getRelationalDatabase());
|
||||
auto& db = app.getRelationalDatabase();
|
||||
|
||||
if (!db)
|
||||
Throw<std::runtime_error>("Failed to get relational database");
|
||||
|
||||
auto dbKB = db->getKBUsedAll();
|
||||
auto dbKB = db.getKBUsedAll();
|
||||
|
||||
if (dbKB > 0)
|
||||
ret[jss::dbKBTotal] = dbKB;
|
||||
|
||||
dbKB = db->getKBUsedLedger();
|
||||
dbKB = db.getKBUsedLedger();
|
||||
|
||||
if (dbKB > 0)
|
||||
ret[jss::dbKBLedger] = dbKB;
|
||||
|
||||
dbKB = db->getKBUsedTransaction();
|
||||
dbKB = db.getKBUsedTransaction();
|
||||
|
||||
if (dbKB > 0)
|
||||
ret[jss::dbKBTransaction] = dbKB;
|
||||
|
||||
@@ -3,18 +3,19 @@
|
||||
#include <xrpld/app/misc/DeliverMax.h>
|
||||
#include <xrpld/app/misc/NetworkOPs.h>
|
||||
#include <xrpld/app/misc/Transaction.h>
|
||||
#include <xrpld/app/rdb/RelationalDatabase.h>
|
||||
#include <xrpld/rpc/CTID.h>
|
||||
#include <xrpld/rpc/Context.h>
|
||||
#include <xrpld/rpc/DeliveredAmount.h>
|
||||
#include <xrpld/rpc/GRPCHandlers.h>
|
||||
#include <xrpld/rpc/MPTokenIssuanceID.h>
|
||||
#include <xrpld/rpc/Status.h>
|
||||
|
||||
#include <xrpl/basics/ToString.h>
|
||||
#include <xrpl/protocol/ErrorCodes.h>
|
||||
#include <xrpl/protocol/NFTSyntheticSerializer.h>
|
||||
#include <xrpl/protocol/RPCErr.h>
|
||||
#include <xrpl/protocol/jss.h>
|
||||
#include <xrpl/rdb/RelationalDatabase.h>
|
||||
|
||||
#include <regex>
|
||||
|
||||
|
||||
@@ -2,13 +2,13 @@
|
||||
#include <xrpld/app/main/Application.h>
|
||||
#include <xrpld/app/misc/DeliverMax.h>
|
||||
#include <xrpld/app/misc/Transaction.h>
|
||||
#include <xrpld/app/rdb/RelationalDatabase.h>
|
||||
#include <xrpld/rpc/Context.h>
|
||||
#include <xrpld/rpc/Role.h>
|
||||
|
||||
#include <xrpl/protocol/ErrorCodes.h>
|
||||
#include <xrpl/protocol/RPCErr.h>
|
||||
#include <xrpl/protocol/jss.h>
|
||||
#include <xrpl/rdb/RelationalDatabase.h>
|
||||
#include <xrpl/resource/Fees.h>
|
||||
|
||||
namespace xrpl {
|
||||
|
||||
Reference in New Issue
Block a user