mirror of
https://github.com/XRPLF/rippled.git
synced 2025-12-06 17:27:55 +00:00
Relational DB interface
This commit is contained in:
@@ -20,10 +20,10 @@
|
||||
#include <ripple/app/main/DBInit.h>
|
||||
#include <ripple/app/misc/Manifest.h>
|
||||
#include <ripple/app/misc/ValidatorList.h>
|
||||
#include <ripple/app/rdb/RelationalDBInterface_global.h>
|
||||
#include <ripple/basics/StringUtilities.h>
|
||||
#include <ripple/basics/base64.h>
|
||||
#include <ripple/basics/contract.h>
|
||||
#include <ripple/core/DatabaseCon.h>
|
||||
#include <ripple/protocol/STExchange.h>
|
||||
#include <ripple/protocol/SecretKey.h>
|
||||
#include <ripple/protocol/Sign.h>
|
||||
@@ -254,14 +254,12 @@ public:
|
||||
|
||||
std::string const dbName("ManifestCacheTestDB");
|
||||
{
|
||||
jtx::Env env(*this);
|
||||
DatabaseCon::Setup setup;
|
||||
setup.dataDir = getDatabasePath();
|
||||
BEAST_EXPECT(!setup.useGlobalPragma);
|
||||
DatabaseCon dbCon(
|
||||
setup,
|
||||
dbName.data(),
|
||||
std::array<char const*, 0>(),
|
||||
WalletDBInit);
|
||||
assert(!setup.useGlobalPragma);
|
||||
|
||||
auto dbCon = makeTestWalletDB(setup, dbName);
|
||||
|
||||
auto getPopulatedManifests =
|
||||
[](ManifestCache const& cache) -> std::vector<Manifest const*> {
|
||||
@@ -284,7 +282,6 @@ public:
|
||||
std::vector<Manifest const*> const inManifests(
|
||||
sort(getPopulatedManifests(m)));
|
||||
|
||||
jtx::Env env(*this);
|
||||
auto& app = env.app();
|
||||
auto unl = std::make_unique<ValidatorList>(
|
||||
m,
|
||||
@@ -297,7 +294,7 @@ public:
|
||||
// save should not store untrusted master keys to db
|
||||
// except for revocations
|
||||
m.save(
|
||||
dbCon,
|
||||
*dbCon,
|
||||
"ValidatorManifests",
|
||||
[&unl](PublicKey const& pubKey) {
|
||||
return unl->listed(pubKey);
|
||||
@@ -305,7 +302,7 @@ public:
|
||||
|
||||
ManifestCache loaded;
|
||||
|
||||
loaded.load(dbCon, "ValidatorManifests");
|
||||
loaded.load(*dbCon, "ValidatorManifests");
|
||||
|
||||
// check that all loaded manifests are revocations
|
||||
std::vector<Manifest const*> const loadedManifests(
|
||||
@@ -326,13 +323,13 @@ public:
|
||||
unl->load(emptyLocalKey, s1, keys);
|
||||
|
||||
m.save(
|
||||
dbCon,
|
||||
*dbCon,
|
||||
"ValidatorManifests",
|
||||
[&unl](PublicKey const& pubKey) {
|
||||
return unl->listed(pubKey);
|
||||
});
|
||||
ManifestCache loaded;
|
||||
loaded.load(dbCon, "ValidatorManifests");
|
||||
loaded.load(*dbCon, "ValidatorManifests");
|
||||
|
||||
// check that the manifest caches are the same
|
||||
std::vector<Manifest const*> const loadedManifests(
|
||||
@@ -360,7 +357,10 @@ public:
|
||||
|
||||
std::string const badManifest = "bad manifest";
|
||||
BEAST_EXPECT(!loaded.load(
|
||||
dbCon, "ValidatorManifests", badManifest, emptyRevocation));
|
||||
*dbCon,
|
||||
"ValidatorManifests",
|
||||
badManifest,
|
||||
emptyRevocation));
|
||||
|
||||
auto const sk = randomSecretKey();
|
||||
auto const pk = derivePublicKey(KeyType::ed25519, sk);
|
||||
@@ -370,7 +370,10 @@ public:
|
||||
makeManifestString(pk, sk, kp.first, kp.second, 0);
|
||||
|
||||
BEAST_EXPECT(loaded.load(
|
||||
dbCon, "ValidatorManifests", cfgManifest, emptyRevocation));
|
||||
*dbCon,
|
||||
"ValidatorManifests",
|
||||
cfgManifest,
|
||||
emptyRevocation));
|
||||
}
|
||||
{
|
||||
// load config revocation
|
||||
@@ -380,7 +383,10 @@ public:
|
||||
std::vector<std::string> const badRevocation = {
|
||||
"bad revocation"};
|
||||
BEAST_EXPECT(!loaded.load(
|
||||
dbCon, "ValidatorManifests", emptyManifest, badRevocation));
|
||||
*dbCon,
|
||||
"ValidatorManifests",
|
||||
emptyManifest,
|
||||
badRevocation));
|
||||
|
||||
auto const sk = randomSecretKey();
|
||||
auto const keyType = KeyType::ed25519;
|
||||
@@ -390,13 +396,16 @@ public:
|
||||
makeManifestString(pk, sk, kp.first, kp.second, 0)};
|
||||
|
||||
BEAST_EXPECT(!loaded.load(
|
||||
dbCon, "ValidatorManifests", emptyManifest, nonRevocation));
|
||||
*dbCon,
|
||||
"ValidatorManifests",
|
||||
emptyManifest,
|
||||
nonRevocation));
|
||||
BEAST_EXPECT(!loaded.revoked(pk));
|
||||
|
||||
std::vector<std::string> const badSigRevocation = {
|
||||
makeRevocationString(sk, keyType, true)};
|
||||
BEAST_EXPECT(!loaded.load(
|
||||
dbCon,
|
||||
*dbCon,
|
||||
"ValidatorManifests",
|
||||
emptyManifest,
|
||||
badSigRevocation));
|
||||
@@ -405,7 +414,10 @@ public:
|
||||
std::vector<std::string> const cfgRevocation = {
|
||||
makeRevocationString(sk, keyType)};
|
||||
BEAST_EXPECT(loaded.load(
|
||||
dbCon, "ValidatorManifests", emptyManifest, cfgRevocation));
|
||||
*dbCon,
|
||||
"ValidatorManifests",
|
||||
emptyManifest,
|
||||
cfgRevocation));
|
||||
|
||||
BEAST_EXPECT(loaded.revoked(pk));
|
||||
}
|
||||
|
||||
@@ -19,9 +19,8 @@
|
||||
|
||||
#include <ripple/app/main/Application.h>
|
||||
#include <ripple/app/misc/SHAMapStore.h>
|
||||
#include <ripple/app/rdb/backend/RelationalDBInterfaceSqlite.h>
|
||||
#include <ripple/core/ConfigSections.h>
|
||||
#include <ripple/core/DatabaseCon.h>
|
||||
#include <ripple/core/SociDB.h>
|
||||
#include <ripple/protocol/jss.h>
|
||||
#include <test/jtx.h>
|
||||
#include <test/jtx/envconfig.h>
|
||||
@@ -64,31 +63,26 @@ class SHAMapStore_test : public beast::unit_test::suite
|
||||
return good;
|
||||
|
||||
auto const seq = json[jss::result][jss::ledger_index].asUInt();
|
||||
std::string outHash;
|
||||
LedgerIndex outSeq;
|
||||
std::string outParentHash;
|
||||
std::string outDrops;
|
||||
std::uint64_t outCloseTime;
|
||||
std::uint64_t outParentCloseTime;
|
||||
std::uint64_t outCloseTimeResolution;
|
||||
std::uint64_t outCloseFlags;
|
||||
std::string outAccountHash;
|
||||
std::string outTxHash;
|
||||
|
||||
{
|
||||
auto db = env.app().getLedgerDB().checkoutDb();
|
||||
std::optional<LedgerInfo> oinfo =
|
||||
env.app().getRelationalDBInterface().getLedgerInfoByIndex(seq);
|
||||
if (!oinfo)
|
||||
return false;
|
||||
const LedgerInfo& info = oinfo.value();
|
||||
|
||||
*db << "SELECT LedgerHash,LedgerSeq,PrevHash,TotalCoins, "
|
||||
"ClosingTime,PrevClosingTime,CloseTimeRes,CloseFlags, "
|
||||
"AccountSetHash,TransSetHash "
|
||||
"FROM Ledgers "
|
||||
"WHERE LedgerSeq = :seq",
|
||||
soci::use(seq), soci::into(outHash), soci::into(outSeq),
|
||||
soci::into(outParentHash), soci::into(outDrops),
|
||||
soci::into(outCloseTime), soci::into(outParentCloseTime),
|
||||
soci::into(outCloseTimeResolution), soci::into(outCloseFlags),
|
||||
soci::into(outAccountHash), soci::into(outTxHash);
|
||||
}
|
||||
const std::string outHash = to_string(info.hash);
|
||||
const LedgerIndex outSeq = info.seq;
|
||||
const std::string outParentHash = to_string(info.parentHash);
|
||||
const std::string outDrops = to_string(info.drops);
|
||||
const std::uint64_t outCloseTime =
|
||||
info.closeTime.time_since_epoch().count();
|
||||
const std::uint64_t outParentCloseTime =
|
||||
info.parentCloseTime.time_since_epoch().count();
|
||||
const std::uint64_t outCloseTimeResolution =
|
||||
info.closeTimeResolution.count();
|
||||
const std::uint64_t outCloseFlags = info.closeFlags;
|
||||
const std::string outAccountHash = to_string(info.accountHash);
|
||||
const std::string outTxHash = to_string(info.txHash);
|
||||
|
||||
auto const& ledger = json[jss::result][jss::ledger];
|
||||
return outHash == ledger[jss::hash].asString() && outSeq == seq &&
|
||||
@@ -125,15 +119,10 @@ class SHAMapStore_test : public beast::unit_test::suite
|
||||
void
|
||||
ledgerCheck(jtx::Env& env, int const rows, int const first)
|
||||
{
|
||||
auto db = env.app().getLedgerDB().checkoutDb();
|
||||
|
||||
int actualRows, actualFirst, actualLast;
|
||||
*db << "SELECT count(*) AS rows, "
|
||||
"min(LedgerSeq) as first, "
|
||||
"max(LedgerSeq) as last "
|
||||
"FROM Ledgers;",
|
||||
soci::into(actualRows), soci::into(actualFirst),
|
||||
soci::into(actualLast);
|
||||
const auto [actualRows, actualFirst, actualLast] =
|
||||
dynamic_cast<RelationalDBInterfaceSqlite*>(
|
||||
&env.app().getRelationalDBInterface())
|
||||
->getLedgerCountMinMax();
|
||||
|
||||
BEAST_EXPECT(actualRows == rows);
|
||||
BEAST_EXPECT(actualFirst == first);
|
||||
@@ -143,27 +132,19 @@ class SHAMapStore_test : public beast::unit_test::suite
|
||||
void
|
||||
transactionCheck(jtx::Env& env, int const rows)
|
||||
{
|
||||
auto db = env.app().getTxnDB().checkoutDb();
|
||||
|
||||
int actualRows;
|
||||
*db << "SELECT count(*) AS rows "
|
||||
"FROM Transactions;",
|
||||
soci::into(actualRows);
|
||||
|
||||
BEAST_EXPECT(actualRows == rows);
|
||||
BEAST_EXPECT(
|
||||
dynamic_cast<RelationalDBInterfaceSqlite*>(
|
||||
&env.app().getRelationalDBInterface())
|
||||
->getTransactionCount() == rows);
|
||||
}
|
||||
|
||||
void
|
||||
accountTransactionCheck(jtx::Env& env, int const rows)
|
||||
{
|
||||
auto db = env.app().getTxnDB().checkoutDb();
|
||||
|
||||
int actualRows;
|
||||
*db << "SELECT count(*) AS rows "
|
||||
"FROM AccountTransactions;",
|
||||
soci::into(actualRows);
|
||||
|
||||
BEAST_EXPECT(actualRows == rows);
|
||||
BEAST_EXPECT(
|
||||
dynamic_cast<RelationalDBInterfaceSqlite*>(
|
||||
&env.app().getRelationalDBInterface())
|
||||
->getAccountTransactionCount() == rows);
|
||||
}
|
||||
|
||||
int
|
||||
|
||||
@@ -108,7 +108,7 @@ public:
|
||||
|
||||
for (auto const& i : d)
|
||||
{
|
||||
SociConfig sc(c, i.first);
|
||||
DBConfig sc(c, i.first);
|
||||
BEAST_EXPECT(
|
||||
boost::ends_with(sc.connectionString(), i.first + i.second));
|
||||
}
|
||||
@@ -119,7 +119,7 @@ public:
|
||||
testcase("open");
|
||||
BasicConfig c;
|
||||
setupSQLiteConfig(c, getDatabasePath());
|
||||
SociConfig sc(c, "SociTestDB");
|
||||
DBConfig sc(c, "SociTestDB");
|
||||
std::vector<std::string> const stringData(
|
||||
{"String1", "String2", "String3"});
|
||||
std::vector<int> const intData({1, 2, 3});
|
||||
@@ -180,7 +180,7 @@ public:
|
||||
testcase("select");
|
||||
BasicConfig c;
|
||||
setupSQLiteConfig(c, getDatabasePath());
|
||||
SociConfig sc(c, "SociTestDB");
|
||||
DBConfig sc(c, "SociTestDB");
|
||||
std::vector<std::uint64_t> const ubid(
|
||||
{(std::uint64_t)std::numeric_limits<std::int64_t>::max(), 20, 30});
|
||||
std::vector<std::int64_t> const bid({-10, -20, -30});
|
||||
@@ -312,7 +312,7 @@ public:
|
||||
testcase("deleteWithSubselect");
|
||||
BasicConfig c;
|
||||
setupSQLiteConfig(c, getDatabasePath());
|
||||
SociConfig sc(c, "SociTestDB");
|
||||
DBConfig sc(c, "SociTestDB");
|
||||
{
|
||||
soci::session s;
|
||||
sc.open(s);
|
||||
|
||||
@@ -20,7 +20,6 @@
|
||||
#include <ripple/app/ledger/LedgerMaster.h>
|
||||
#include <ripple/app/misc/TxQ.h>
|
||||
#include <ripple/basics/mulDiv.h>
|
||||
#include <ripple/core/DatabaseCon.h>
|
||||
#include <ripple/protocol/ErrorCodes.h>
|
||||
#include <ripple/protocol/jss.h>
|
||||
#include <ripple/rpc/GRPCHandlers.h>
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
*/
|
||||
//==============================================================================
|
||||
|
||||
#include <ripple/app/rdb/RelationalDBInterface_shards.h>
|
||||
#include <ripple/beast/utility/temp_dir.h>
|
||||
#include <ripple/core/ConfigSections.h>
|
||||
#include <ripple/nodestore/DummyScheduler.h>
|
||||
@@ -81,19 +82,14 @@ public:
|
||||
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(handler->m_);
|
||||
|
||||
auto& session{handler->sqliteDB_->getSession()};
|
||||
|
||||
soci::rowset<soci::row> rs =
|
||||
(session.prepare << "SELECT * FROM State;");
|
||||
|
||||
std::uint64_t rowCount = 0;
|
||||
|
||||
for (auto it = rs.begin(); it != rs.end(); ++it, ++rowCount)
|
||||
{
|
||||
BEAST_EXPECT(it->get<int>(0) == 1);
|
||||
BEAST_EXPECT(it->get<std::string>(1) == rawUrl);
|
||||
}
|
||||
readArchiveDB(
|
||||
*handler->sqlDB_, [&](std::string const& url, int state) {
|
||||
BEAST_EXPECT(state == 1);
|
||||
BEAST_EXPECT(url == rawUrl);
|
||||
++rowCount;
|
||||
});
|
||||
|
||||
BEAST_EXPECT(rowCount == 1);
|
||||
}
|
||||
@@ -136,17 +132,14 @@ public:
|
||||
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(handler->m_);
|
||||
|
||||
auto& session{handler->sqliteDB_->getSession()};
|
||||
soci::rowset<soci::row> rs =
|
||||
(session.prepare << "SELECT * FROM State;");
|
||||
|
||||
std::uint64_t pos = 0;
|
||||
for (auto it = rs.begin(); it != rs.end(); ++it, ++pos)
|
||||
{
|
||||
BEAST_EXPECT(it->get<int>(0) == dl[pos].first);
|
||||
BEAST_EXPECT(it->get<std::string>(1) == dl[pos].second);
|
||||
}
|
||||
|
||||
readArchiveDB(
|
||||
*handler->sqlDB_, [&](std::string const& url, int state) {
|
||||
BEAST_EXPECT(state == dl[pos].first);
|
||||
BEAST_EXPECT(url == dl[pos].second);
|
||||
++pos;
|
||||
});
|
||||
|
||||
BEAST_EXPECT(pos == dl.size());
|
||||
}
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
*/
|
||||
//==============================================================================
|
||||
|
||||
#include <ripple/core/DatabaseCon.h>
|
||||
#include <ripple/app/rdb/backend/RelationalDBInterfaceSqlite.h>
|
||||
#include <ripple/protocol/ErrorCodes.h>
|
||||
#include <ripple/protocol/jss.h>
|
||||
#include <test/jtx.h>
|
||||
@@ -119,9 +119,9 @@ class Transaction_test : public beast::unit_test::suite
|
||||
const auto deletedLedger = (startLegSeq + endLegSeq) / 2;
|
||||
{
|
||||
// Remove one of the ledgers from the database directly
|
||||
auto db = env.app().getTxnDB().checkoutDb();
|
||||
*db << "DELETE FROM Transactions WHERE LedgerSeq == "
|
||||
<< deletedLedger << ";";
|
||||
dynamic_cast<RelationalDBInterfaceSqlite*>(
|
||||
&env.app().getRelationalDBInterface())
|
||||
->deleteTransactionByLedgerSeq(deletedLedger);
|
||||
}
|
||||
|
||||
for (int deltaEndSeq = 0; deltaEndSeq < 2; ++deltaEndSeq)
|
||||
|
||||
@@ -19,8 +19,8 @@
|
||||
|
||||
#include <ripple/app/ledger/LedgerMaster.h>
|
||||
#include <ripple/app/misc/TxQ.h>
|
||||
#include <ripple/app/rdb/backend/RelationalDBInterfaceSqlite.h>
|
||||
#include <ripple/basics/mulDiv.h>
|
||||
#include <ripple/core/DatabaseCon.h>
|
||||
#include <ripple/protocol/ErrorCodes.h>
|
||||
#include <ripple/protocol/jss.h>
|
||||
#include <ripple/rpc/impl/RPCHelpers.h>
|
||||
@@ -769,9 +769,9 @@ class Tx_test : public beast::unit_test::suite
|
||||
const auto deletedLedger = (startLegSeq + endLegSeq) / 2;
|
||||
{
|
||||
// Remove one of the ledgers from the database directly
|
||||
auto db = env.app().getTxnDB().checkoutDb();
|
||||
*db << "DELETE FROM Transactions WHERE LedgerSeq == "
|
||||
<< deletedLedger << ";";
|
||||
dynamic_cast<RelationalDBInterfaceSqlite*>(
|
||||
&env.app().getRelationalDBInterface())
|
||||
->deleteTransactionByLedgerSeq(deletedLedger);
|
||||
}
|
||||
|
||||
for (bool b : {false, true})
|
||||
|
||||
Reference in New Issue
Block a user