Relational DB interface

This commit is contained in:
cdy20
2020-06-03 17:57:07 -04:00
committed by manojsdoshi
parent 207e1730e9
commit 6d82fb83a0
66 changed files with 8528 additions and 3593 deletions

View File

@@ -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));
}

View File

@@ -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