Skip to content

Commit

Permalink
fixed write verified checkpoint hashes test
Browse files Browse the repository at this point in the history
  • Loading branch information
ThomasBrady committed Sep 25, 2024
1 parent 7ca9e9c commit 170ea58
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 28 deletions.
14 changes: 4 additions & 10 deletions src/historywork/WriteVerifiedCheckpointHashesWork.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -140,21 +140,15 @@ WriteVerifiedCheckpointHashesWork::yieldMoreWork()
std::make_optional<Hash>(lclHe.hash));
uint32_t const span = mNestedBatchSize * freq;
uint32_t const last = mCurrCheckpoint;
uint32_t first;
uint32_t first = last <= span
? LedgerManager::GENESIS_LEDGER_SEQ
: hm.firstLedgerInCheckpointContaining(last - span);
// If the latest trusted ledger is greater than the first ledger in the
// range then the range should start at the trusted ledger.
if (first < mLatestTrustedHashPair.first)
{
first = mLatestTrustedHashPair.first;
}
else if (last <= span)
{
first = LedgerManager::GENESIS_LEDGER_SEQ;
}
else
{
first = hm.firstLedgerInCheckpointContaining(last - span);
}

LedgerRange const ledgerRange = LedgerRange::inclusive(first, last);
CheckpointRange const checkpointRange(ledgerRange, hm);
Expand Down Expand Up @@ -255,7 +249,7 @@ WriteVerifiedCheckpointHashesWork::endOutputFile()
// Append the rest of the lines to mOutputFile.
while (std::getline(trustedHashFile, line))
{
(*mOutputFile) << line << "\n";
(*mOutputFile) << "\n" << line;
}
trustedHashFile.close();
}
Expand Down
20 changes: 2 additions & 18 deletions src/historywork/test/HistoryWorkTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,8 @@ TEST_CASE("write verified checkpoint hashes", "[historywork]")
REQUIRE(w->getState() == BasicWork::State::WORK_SUCCESS);
}

std::map<uint32_t, Hash> first_set;

for (auto const& p : pairs)
{
first_set.emplace(p.first, *p.second);
LOG_DEBUG(DEFAULT_LOG, "Verified {} with hash {}", p.first,
hexAbbrev(*p.second));
Hash h = WriteVerifiedCheckpointHashesWork::loadHashFromJsonOutput(
Expand All @@ -64,34 +61,21 @@ TEST_CASE("write verified checkpoint hashes", "[historywork]")
catchupSimulation.ensureOnlineCatchupPossible(secondCheckpointLedger,
5 * nestedBatchSize);
pairs = catchupSimulation.getAllPublishedCheckpoints();
pair = pairs.back();

// Run work again with existing file.
{
auto w = wm.executeWork<WriteVerifiedCheckpointHashesWork>(
pairs.back(), file, nestedBatchSize);
REQUIRE(w->getState() == BasicWork::State::WORK_SUCCESS);
}
std::map<uint32_t, Hash> second_set;
for (auto const& p : pairs)
{
second_set.emplace(p.first, *p.second);
}

// Ensure the file contains all pairs, from the first run and the second.
int counter = 0;
for (auto const& p : pairs)
{
counter++;
LOG_DEBUG(DEFAULT_LOG, "Verified {} with hash {}", p.first,
hexAbbrev(*p.second));
Hash h = WriteVerifiedCheckpointHashesWork::loadHashFromJsonOutput(
p.first, file);
if (h != *p.second)
{
std::cout << "Hash mismatch for ledger " << p.first
<< ", counter=" << counter << std::endl;
Hash h = WriteVerifiedCheckpointHashesWork::loadHashFromJsonOutput(
p.first, file);
}
REQUIRE(h == *p.second);
}
// Check that the "latest" ledger in the file is the same as the last
Expand Down

0 comments on commit 170ea58

Please sign in to comment.