mirror of
https://github.com/XRPLF/rippled.git
synced 2025-12-06 17:27:55 +00:00
Remove SQLite Validations table
This commit is contained in:
committed by
Nik Bougalis
parent
e1adbd7ddd
commit
c5a95f1eb5
@@ -125,18 +125,6 @@ class SHAMapStore_test : public beast::unit_test::suite
|
||||
return json[jss::result][jss::ledger][jss::hash].asString();
|
||||
}
|
||||
|
||||
void validationCheck(jtx::Env& env, int const expected)
|
||||
{
|
||||
auto db = env.app().getLedgerDB().checkoutDb();
|
||||
|
||||
int actual;
|
||||
*db << "SELECT count(*) AS rows FROM Validations;",
|
||||
soci::into(actual);
|
||||
|
||||
BEAST_EXPECT(actual == expected);
|
||||
|
||||
}
|
||||
|
||||
void ledgerCheck(jtx::Env& env, int const rows,
|
||||
int const first)
|
||||
{
|
||||
@@ -214,7 +202,6 @@ public:
|
||||
auto& store = env.app().getSHAMapStore();
|
||||
env.fund(XRP(10000), noripple("alice"));
|
||||
|
||||
validationCheck(env, 0);
|
||||
ledgerCheck(env, 1, 2);
|
||||
transactionCheck(env, 0);
|
||||
accountTransactionCheck(env, 0);
|
||||
@@ -260,67 +247,6 @@ public:
|
||||
getHash(ledgers[i]).length());
|
||||
}
|
||||
|
||||
validationCheck(env, 0);
|
||||
ledgerCheck(env, deleteInterval + 1, 2);
|
||||
transactionCheck(env, deleteInterval);
|
||||
accountTransactionCheck(env, 2 * deleteInterval);
|
||||
|
||||
{
|
||||
// Since standalone doesn't _do_ validations, manually
|
||||
// insert some into the table. Create some with the
|
||||
// hashes from our real ledgers, and some with fake
|
||||
// hashes to represent validations that never ended up
|
||||
// in a validated ledger.
|
||||
char lh[65];
|
||||
memset(lh, 'a', 64);
|
||||
lh[64] = '\0';
|
||||
std::vector<std::string> preSeqLedgerHashes({
|
||||
lh
|
||||
});
|
||||
std::vector<std::string> badLedgerHashes;
|
||||
std::vector<LedgerIndex> badLedgerSeqs;
|
||||
std::vector<std::string> ledgerHashes;
|
||||
std::vector<LedgerIndex> ledgerSeqs;
|
||||
for (auto const& lgr : ledgers)
|
||||
{
|
||||
ledgerHashes.emplace_back(getHash(lgr.second));
|
||||
ledgerSeqs.emplace_back(lgr.second[jss::result][jss::ledger_index].asUInt());
|
||||
}
|
||||
for (auto i = 0; i < 10; ++i)
|
||||
{
|
||||
++lh[30];
|
||||
preSeqLedgerHashes.emplace_back(lh);
|
||||
++lh[20];
|
||||
badLedgerHashes.emplace_back(lh);
|
||||
badLedgerSeqs.emplace_back(i + 1);
|
||||
}
|
||||
|
||||
auto db = env.app().getLedgerDB().checkoutDb();
|
||||
|
||||
// Pre-migration validation - no sequence numbers.
|
||||
*db << "INSERT INTO Validations "
|
||||
"(LedgerHash) "
|
||||
"VALUES "
|
||||
"(:ledgerHash);",
|
||||
soci::use(preSeqLedgerHashes);
|
||||
// Post-migration orphan validation - InitalSeq,
|
||||
// but no LedgerSeq
|
||||
*db << "INSERT INTO Validations "
|
||||
"(LedgerHash, InitialSeq) "
|
||||
"VALUES "
|
||||
"(:ledgerHash, :initialSeq);",
|
||||
soci::use(badLedgerHashes),
|
||||
soci::use(badLedgerSeqs);
|
||||
// Post-migration validated ledger.
|
||||
*db << "INSERT INTO Validations "
|
||||
"(LedgerHash, LedgerSeq) "
|
||||
"VALUES "
|
||||
"(:ledgerHash, :ledgerSeq);",
|
||||
soci::use(ledgerHashes),
|
||||
soci::use(ledgerSeqs);
|
||||
}
|
||||
|
||||
validationCheck(env, deleteInterval + 23);
|
||||
ledgerCheck(env, deleteInterval + 1, 2);
|
||||
transactionCheck(env, deleteInterval);
|
||||
accountTransactionCheck(env, 2 * deleteInterval);
|
||||
@@ -340,7 +266,6 @@ public:
|
||||
BEAST_EXPECT(lastRotated == 11);
|
||||
|
||||
// That took care of the fake hashes
|
||||
validationCheck(env, deleteInterval + 8);
|
||||
ledgerCheck(env, deleteInterval + 1, 3);
|
||||
transactionCheck(env, deleteInterval);
|
||||
accountTransactionCheck(env, 2 * deleteInterval);
|
||||
@@ -348,8 +273,6 @@ public:
|
||||
// The last iteration of this loop should trigger a rotate
|
||||
for (auto i = lastRotated - 1; i < lastRotated + deleteInterval - 1; ++i)
|
||||
{
|
||||
validationCheck(env, deleteInterval + i + 1 - lastRotated + 8);
|
||||
|
||||
env.close();
|
||||
|
||||
ledgerTmp = env.rpc("ledger", "current");
|
||||
@@ -361,28 +284,12 @@ public:
|
||||
i == lastRotated + deleteInterval - 2);
|
||||
BEAST_EXPECT(goodLedger(env, ledgers[i], to_string(i), true) &&
|
||||
getHash(ledgers[i]).length());
|
||||
|
||||
std::vector<std::string> ledgerHashes({
|
||||
getHash(ledgers[i])
|
||||
});
|
||||
std::vector<LedgerIndex> ledgerSeqs({
|
||||
ledgers[i][jss::result][jss::ledger_index].asUInt()
|
||||
});
|
||||
auto db = env.app().getLedgerDB().checkoutDb();
|
||||
|
||||
*db << "INSERT INTO Validations "
|
||||
"(LedgerHash, LedgerSeq) "
|
||||
"VALUES "
|
||||
"(:ledgerHash, :ledgerSeq);",
|
||||
soci::use(ledgerHashes),
|
||||
soci::use(ledgerSeqs);
|
||||
}
|
||||
|
||||
store.rendezvous();
|
||||
|
||||
BEAST_EXPECT(store.getLastRotated() == deleteInterval + lastRotated);
|
||||
|
||||
validationCheck(env, deleteInterval - 1);
|
||||
ledgerCheck(env, deleteInterval + 1, lastRotated);
|
||||
transactionCheck(env, 0);
|
||||
accountTransactionCheck(env, 0);
|
||||
@@ -421,7 +328,6 @@ public:
|
||||
|
||||
// The database will always have back to ledger 2,
|
||||
// regardless of lastRotated.
|
||||
validationCheck(env, 0);
|
||||
ledgerCheck(env, ledgerSeq - 2, 2);
|
||||
BEAST_EXPECT(lastRotated == store.getLastRotated());
|
||||
|
||||
@@ -435,7 +341,6 @@ public:
|
||||
|
||||
store.rendezvous();
|
||||
|
||||
validationCheck(env, 0);
|
||||
ledgerCheck(env, ledgerSeq - lastRotated, lastRotated);
|
||||
BEAST_EXPECT(lastRotated != store.getLastRotated());
|
||||
|
||||
@@ -452,7 +357,6 @@ public:
|
||||
|
||||
store.rendezvous();
|
||||
|
||||
validationCheck(env, 0);
|
||||
ledgerCheck(env, deleteInterval + 1, lastRotated);
|
||||
BEAST_EXPECT(lastRotated != store.getLastRotated());
|
||||
}
|
||||
@@ -491,7 +395,6 @@ public:
|
||||
|
||||
store.rendezvous();
|
||||
|
||||
validationCheck(env, 0);
|
||||
ledgerCheck(env, ledgerSeq - 2, 2);
|
||||
BEAST_EXPECT(lastRotated == store.getLastRotated());
|
||||
|
||||
@@ -504,7 +407,6 @@ public:
|
||||
|
||||
store.rendezvous();
|
||||
|
||||
validationCheck(env, 0);
|
||||
ledgerCheck(env, ledgerSeq - 2, 2);
|
||||
BEAST_EXPECT(store.getLastRotated() == lastRotated);
|
||||
|
||||
@@ -518,7 +420,6 @@ public:
|
||||
|
||||
store.rendezvous();
|
||||
|
||||
validationCheck(env, 0);
|
||||
ledgerCheck(env, ledgerSeq - lastRotated, lastRotated);
|
||||
|
||||
BEAST_EXPECT(store.getLastRotated() == ledgerSeq - 1);
|
||||
@@ -547,7 +448,6 @@ public:
|
||||
|
||||
store.rendezvous();
|
||||
|
||||
validationCheck(env, 0);
|
||||
ledgerCheck(env, ledgerSeq - firstBatch, firstBatch);
|
||||
|
||||
BEAST_EXPECT(store.getLastRotated() == ledgerSeq - 1);
|
||||
@@ -582,7 +482,6 @@ public:
|
||||
|
||||
store.rendezvous();
|
||||
|
||||
validationCheck(env, 0);
|
||||
ledgerCheck(env, ledgerSeq - lastRotated, lastRotated);
|
||||
|
||||
BEAST_EXPECT(store.getLastRotated() == ledgerSeq - 1);
|
||||
@@ -616,7 +515,6 @@ public:
|
||||
|
||||
store.rendezvous();
|
||||
|
||||
validationCheck(env, 0);
|
||||
ledgerCheck(env, ledgerSeq - lastRotated, lastRotated);
|
||||
|
||||
BEAST_EXPECT(store.getLastRotated() == ledgerSeq - 1);
|
||||
|
||||
@@ -165,18 +165,9 @@ class Validations_test : public beast::unit_test::suite
|
||||
}
|
||||
};
|
||||
|
||||
// Saved StaleData for inspection in test
|
||||
struct StaleData
|
||||
{
|
||||
std::vector<Validation> stale;
|
||||
hash_map<PeerID, Validation> flushed;
|
||||
};
|
||||
|
||||
// Generic Validations adaptor that saves stale/flushed data into
|
||||
// a StaleData instance.
|
||||
// Generic Validations adaptor
|
||||
class Adaptor
|
||||
{
|
||||
StaleData& staleData_;
|
||||
clock_type& c_;
|
||||
LedgerOracle& oracle_;
|
||||
|
||||
@@ -198,8 +189,8 @@ class Validations_test : public beast::unit_test::suite
|
||||
using Validation = csf::Validation;
|
||||
using Ledger = csf::Ledger;
|
||||
|
||||
Adaptor(StaleData& sd, clock_type& c, LedgerOracle& o)
|
||||
: staleData_{sd}, c_{c}, oracle_{o}
|
||||
Adaptor(clock_type& c, LedgerOracle& o)
|
||||
: c_{c}, oracle_{o}
|
||||
{
|
||||
}
|
||||
|
||||
@@ -209,18 +200,6 @@ class Validations_test : public beast::unit_test::suite
|
||||
return toNetClock(c_);
|
||||
}
|
||||
|
||||
void
|
||||
onStale(Validation&& v)
|
||||
{
|
||||
staleData_.stale.emplace_back(std::move(v));
|
||||
}
|
||||
|
||||
void
|
||||
flush(hash_map<PeerID, Validation>&& remaining)
|
||||
{
|
||||
staleData_.flushed = std::move(remaining);
|
||||
}
|
||||
|
||||
boost::optional<Ledger>
|
||||
acquire(Ledger::ID const& id)
|
||||
{
|
||||
@@ -235,7 +214,6 @@ class Validations_test : public beast::unit_test::suite
|
||||
// accessors for simplifying test logic
|
||||
class TestHarness
|
||||
{
|
||||
StaleData staleData_;
|
||||
ValidationParms p_;
|
||||
beast::manual_clock<std::chrono::steady_clock> clock_;
|
||||
TestValidations tv_;
|
||||
@@ -243,7 +221,7 @@ class Validations_test : public beast::unit_test::suite
|
||||
|
||||
public:
|
||||
explicit TestHarness(LedgerOracle& o)
|
||||
: tv_(p_, clock_, staleData_, clock_, o)
|
||||
: tv_(p_, clock_, clock_, o)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -276,18 +254,6 @@ class Validations_test : public beast::unit_test::suite
|
||||
{
|
||||
return clock_;
|
||||
}
|
||||
|
||||
std::vector<Validation> const&
|
||||
stale() const
|
||||
{
|
||||
return staleData_.stale;
|
||||
}
|
||||
|
||||
hash_map<PeerID, Validation> const&
|
||||
flushed() const
|
||||
{
|
||||
return staleData_.flushed;
|
||||
}
|
||||
};
|
||||
|
||||
Ledger const genesisLedger{Ledger::MakeGenesis{}};
|
||||
@@ -320,16 +286,10 @@ class Validations_test : public beast::unit_test::suite
|
||||
BEAST_EXPECT(ValStatus::badSeq == harness.add(v));
|
||||
|
||||
harness.clock().advance(1s);
|
||||
// Replace with a new validation and ensure the old one is stale
|
||||
BEAST_EXPECT(harness.stale().empty());
|
||||
|
||||
BEAST_EXPECT(
|
||||
ValStatus::current == harness.add(n.validate(ledgerAB)));
|
||||
|
||||
BEAST_EXPECT(harness.stale().size() == 1);
|
||||
|
||||
BEAST_EXPECT(harness.stale()[0].ledgerID() == ledgerA.id());
|
||||
|
||||
// Test the node changing signing key
|
||||
|
||||
// Confirm old ledger on hand, but not new ledger
|
||||
@@ -476,14 +436,11 @@ class Validations_test : public beast::unit_test::suite
|
||||
BEAST_EXPECT(
|
||||
harness.vals().getPreferred(genesisLedger) ==
|
||||
std::make_pair(ledgerAB.seq(), ledgerAB.id()));
|
||||
BEAST_EXPECT(harness.stale().empty());
|
||||
harness.clock().advance(harness.parms().validationCURRENT_LOCAL);
|
||||
|
||||
// trigger check for stale
|
||||
trigger(harness.vals());
|
||||
|
||||
BEAST_EXPECT(harness.stale().size() == 1);
|
||||
BEAST_EXPECT(harness.stale()[0].ledgerID() == ledgerAB.id());
|
||||
BEAST_EXPECT(
|
||||
harness.vals().getNodesAfter(ledgerA, ledgerA.id()) == 0);
|
||||
BEAST_EXPECT(
|
||||
@@ -780,7 +737,6 @@ class Validations_test : public beast::unit_test::suite
|
||||
BEAST_EXPECT(ValStatus::current == harness.add(val));
|
||||
expected.emplace(node.nodeID(), val);
|
||||
}
|
||||
Validation staleA = expected.find(a.nodeID())->second;
|
||||
|
||||
// Send in a new validation for a, saving the new one into the expected
|
||||
// map after setting the proper prior ledger ID it replaced
|
||||
@@ -788,18 +744,6 @@ class Validations_test : public beast::unit_test::suite
|
||||
auto newVal = a.validate(ledgerAB);
|
||||
BEAST_EXPECT(ValStatus::current == harness.add(newVal));
|
||||
expected.find(a.nodeID())->second = newVal;
|
||||
|
||||
// Now flush
|
||||
harness.vals().flush();
|
||||
|
||||
// Original a validation was stale
|
||||
BEAST_EXPECT(harness.stale().size() == 1);
|
||||
BEAST_EXPECT(harness.stale()[0] == staleA);
|
||||
BEAST_EXPECT(harness.stale()[0].nodeID() == a.nodeID());
|
||||
|
||||
auto const& flushed = harness.flushed();
|
||||
|
||||
BEAST_EXPECT(flushed == expected);
|
||||
}
|
||||
|
||||
void
|
||||
|
||||
@@ -310,14 +310,7 @@ public:
|
||||
LedgerHash CHARACTER(64) PRIMARY KEY, \
|
||||
LedgerSeq BIGINT UNSIGNED \
|
||||
);",
|
||||
"CREATE INDEX SeqLedger ON Ledgers(LedgerSeq);",
|
||||
|
||||
"CREATE TABLE Validations ( \
|
||||
LedgerHash CHARACTER(64) \
|
||||
);",
|
||||
"CREATE INDEX ValidationsByHash ON \
|
||||
Validations(LedgerHash);",
|
||||
"END TRANSACTION;"};
|
||||
"CREATE INDEX SeqLedger ON Ledgers(LedgerSeq);"};
|
||||
int dbInitCount = std::extent<decltype(dbInit)>::value;
|
||||
for (int i = 0; i < dbInitCount; ++i)
|
||||
{
|
||||
@@ -343,16 +336,10 @@ public:
|
||||
s << "INSERT INTO Ledgers (LedgerHash, LedgerSeq) VALUES "
|
||||
"(:lh, :li);",
|
||||
soci::use (ledgerHashes), soci::use (ledgerIndexes);
|
||||
s << "INSERT INTO Validations (LedgerHash) VALUES "
|
||||
"(:lh);", soci::use (ledgerHashes);
|
||||
|
||||
std::vector<int> ledgersLS (numRows * 2);
|
||||
std::vector<std::string> validationsLH (numRows * 2);
|
||||
s << "SELECT LedgerSeq FROM Ledgers;", soci::into (ledgersLS);
|
||||
s << "SELECT LedgerHash FROM Validations;",
|
||||
soci::into (validationsLH);
|
||||
BEAST_EXPECT(ledgersLS.size () == numRows &&
|
||||
validationsLH.size () == numRows);
|
||||
BEAST_EXPECT(ledgersLS.size () == numRows);
|
||||
}
|
||||
namespace bfs = boost::filesystem;
|
||||
// Remove the database
|
||||
|
||||
@@ -144,16 +144,6 @@ struct Peer
|
||||
return p_.now();
|
||||
}
|
||||
|
||||
void
|
||||
onStale(Validation&& v)
|
||||
{
|
||||
}
|
||||
|
||||
void
|
||||
flush(hash_map<PeerID, Validation>&& remaining)
|
||||
{
|
||||
}
|
||||
|
||||
boost::optional<Ledger>
|
||||
acquire(Ledger::ID const & id)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user