Skip to content

Commit

Permalink
fix bounds on --from-ledger output
Browse files Browse the repository at this point in the history
  • Loading branch information
ThomasBrady committed Oct 1, 2024
1 parent e94e613 commit c4810de
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
20 changes: 16 additions & 4 deletions src/historywork/WriteVerifiedCheckpointHashesWork.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ WriteVerifiedCheckpointHashesWork::hasNext() const
{
if (mFromLedger)
{
return mCurrCheckpoint > *mFromLedger;
return mCurrCheckpoint >= *mFromLedger;
}
else if (mLatestTrustedHashPair)
{
Expand Down Expand Up @@ -152,15 +152,27 @@ WriteVerifiedCheckpointHashesWork::yieldMoreWork()
uint32_t first = last <= span
? LedgerManager::GENESIS_LEDGER_SEQ
: hm.firstLedgerInCheckpointContaining(last - span);
// If the latest trusted ledger or mFromLedger is greater than the first
// ledger in the range then the range should start at the trusted ledger.
// If the first ledger in the range is less than mFromLedger then the
// range should be constrained to start at mFromLedger, or the checkpoint
// immediately before it if mFromLedger is not a checkpoint boundary.
if (mFromLedger && first < *mFromLedger)
{
first = *mFromLedger;
if (hm.isLastLedgerInCheckpoint(*mFromLedger))
{
first = *mFromLedger;
}
else
{
first = hm.lastLedgerBeforeCheckpointContaining(*mFromLedger);
}
releaseAssert(first <= *mFromLedger);
}
// If the latest trusted ledger is greater than the first
// ledger in the range then the range should start at the trusted ledger.
else if (mLatestTrustedHashPair && first < mLatestTrustedHashPair->first)
{
first = mLatestTrustedHashPair->first;
releaseAssert(hm.isLastLedgerInCheckpoint(first));
}

LedgerRange const ledgerRange = LedgerRange::inclusive(first, last);
Expand Down
1 change: 1 addition & 0 deletions src/main/CommandLine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1047,6 +1047,7 @@ runWriteVerifiedCheckpointHashes(CommandLineArgs const& args)
{
LOG_ERROR(DEFAULT_LOG, "Cannot specify both --from-ledger and "
"--trusted-hash-file");
return 1;
}
VirtualClock clock(VirtualClock::REAL_TIME);
auto cfg = configOption.getConfig();
Expand Down

0 comments on commit c4810de

Please sign in to comment.