Make earliest ledger sequence configurable

This commit is contained in:
Miguel Portilla
2018-02-16 13:28:05 -05:00
committed by Nikolaos D. Bougalis
parent 8d9dffcf84
commit 0b18b36186
22 changed files with 304 additions and 160 deletions

View File

@@ -141,60 +141,104 @@ public:
if (testPersistence)
{
// Re-open the database without the ephemeral DB
std::unique_ptr <Database> db = Manager::instance().make_Database (
"test", scheduler, 2, parent, nodeParams, j);
// Read it back in
Batch copy;
fetchCopyOfBatch (*db, &copy, batch);
// Canonicalize the source and destination batches
std::sort (batch.begin (), batch.end (), LessThan{});
std::sort (copy.begin (), copy.end (), LessThan{});
BEAST_EXPECT(areBatchesEqual (batch, copy));
}
if (type == "memory")
{
// Earliest ledger sequence tests
{
// Re-open the database without the ephemeral DB
std::unique_ptr <Database> db = Manager::instance().make_Database (
"test", scheduler, 2, parent, nodeParams, j);
// Verify default earliest ledger sequence
std::unique_ptr<Database> db =
Manager::instance().make_Database(
"test", scheduler, 2, parent, nodeParams, j);
BEAST_EXPECT(db->earliestSeq() == XRP_LEDGER_EARLIEST_SEQ);
}
// Read it back in
Batch copy;
fetchCopyOfBatch (*db, &copy, batch);
// Set an invalid earliest ledger sequence
try
{
nodeParams.set("earliest_seq", "0");
std::unique_ptr<Database> db =
Manager::instance().make_Database(
"test", scheduler, 2, parent, nodeParams, j);
}
catch (std::runtime_error const& e)
{
BEAST_EXPECT(std::strcmp(e.what(),
"Invalid earliest_seq") == 0);
}
// Canonicalize the source and destination batches
std::sort (batch.begin (), batch.end (), LessThan{});
std::sort (copy.begin (), copy.end (), LessThan{});
BEAST_EXPECT(areBatchesEqual (batch, copy));
{
// Set a valid earliest ledger sequence
nodeParams.set("earliest_seq", "1");
std::unique_ptr<Database> db =
Manager::instance().make_Database(
"test", scheduler, 2, parent, nodeParams, j);
// Verify database uses the earliest ledger sequence setting
BEAST_EXPECT(db->earliestSeq() == 1);
}
// Create another database that attempts to set the value again
try
{
// Set to default earliest ledger sequence
nodeParams.set("earliest_seq",
std::to_string(XRP_LEDGER_EARLIEST_SEQ));
std::unique_ptr<Database> db2 =
Manager::instance().make_Database(
"test", scheduler, 2, parent, nodeParams, j);
}
catch (std::runtime_error const& e)
{
BEAST_EXPECT(std::strcmp(e.what(),
"earliest_seq set more than once") == 0);
}
}
}
//--------------------------------------------------------------------------
void runBackendTests (std::int64_t const seedValue)
{
testNodeStore ("nudb", true, seedValue);
#if RIPPLE_ROCKSDB_AVAILABLE
testNodeStore ("rocksdb", true, seedValue);
#endif
}
//--------------------------------------------------------------------------
void runImportTests (std::int64_t const seedValue)
{
testImport ("nudb", "nudb", seedValue);
#if RIPPLE_ROCKSDB_AVAILABLE
testImport ("rocksdb", "rocksdb", seedValue);
#endif
#if RIPPLE_ENABLE_SQLITE_BACKEND_TESTS
testImport ("sqlite", "sqlite", seedValue);
#endif
}
//--------------------------------------------------------------------------
void run ()
{
std::int64_t const seedValue = 50;
testNodeStore ("memory", false, seedValue);
runBackendTests (seedValue);
// Persistent backend tests
{
testNodeStore ("nudb", true, seedValue);
runImportTests (seedValue);
#if RIPPLE_ROCKSDB_AVAILABLE
testNodeStore ("rocksdb", true, seedValue);
#endif
}
// Import tests
{
testImport ("nudb", "nudb", seedValue);
#if RIPPLE_ROCKSDB_AVAILABLE
testImport ("rocksdb", "rocksdb", seedValue);
#endif
#if RIPPLE_ENABLE_SQLITE_BACKEND_TESTS
testImport ("sqlite", "sqlite", seedValue);
#endif
}
}
};

View File

@@ -195,7 +195,7 @@ public:
db.store (object->getType (),
std::move (data),
object->getHash (),
NodeStore::genesisSeq);
db.earliestSeq());
}
}