-
Notifications
You must be signed in to change notification settings - Fork 988
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Unified iterating through txset history entries (#4655)
# Description Resolves #4567. # Checklist - [ ] Reviewed the [contributing](https://github.com/stellar/stellar-core/blob/master/CONTRIBUTING.md#submitting-changes) document - [ ] Rebased on top of master (no merge commits) - [ ] Ran `clang-format` v8.0.0 (via `make format` or the Visual Studio extension) - [ ] Compiles - [ ] Ran all tests - [ ] If change impacts performance, include supporting evidence per the [performance document](https://github.com/stellar/stellar-core/blob/master/performance-eval/performance-eval.md)
- Loading branch information
Showing
4 changed files
with
126 additions
and
80 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
// Copyright 2025 Stellar Development Foundation and contributors. Licensed | ||
// under the Apache License, Version 2.0. See the COPYING file at the root | ||
// of this distribution or at http://www.apache.org/licenses/LICENSE-2.0 | ||
|
||
#include "history/HistoryUtils.h" | ||
#include "util/Logging.h" | ||
#include "util/XDRStream.h" | ||
#include "xdr/Stellar-ledger.h" | ||
#include <Tracy.hpp> | ||
|
||
namespace stellar | ||
{ | ||
|
||
template <typename T> | ||
bool | ||
getHistoryEntryForLedger(XDRInputFileStream& stream, T& currentEntry, | ||
uint32_t targetLedger, | ||
std::function<void(uint32_t ledgerSeq)> validateFn) | ||
{ | ||
ZoneScoped; | ||
|
||
auto readNextWithValidation = [&]() { | ||
auto res = stream.readOne(currentEntry); | ||
if (res && validateFn) | ||
{ | ||
validateFn(currentEntry.ledgerSeq); | ||
} | ||
return res; | ||
}; | ||
|
||
do | ||
{ | ||
if (currentEntry.ledgerSeq < targetLedger) | ||
{ | ||
CLOG_DEBUG(History, "Advancing past txhistory entry for ledger {}", | ||
currentEntry.ledgerSeq); | ||
} | ||
else if (currentEntry.ledgerSeq > targetLedger) | ||
{ | ||
// No entry for this ledger | ||
break; | ||
} | ||
else | ||
{ | ||
// Found the entry for our target ledger | ||
return true; | ||
} | ||
} while (stream && readNextWithValidation()); | ||
|
||
return false; | ||
} | ||
|
||
template bool getHistoryEntryForLedger<TransactionHistoryEntry>( | ||
XDRInputFileStream& stream, TransactionHistoryEntry& currentEntry, | ||
uint32_t targetLedger, std::function<void(uint32_t ledgerSeq)> validateFn); | ||
|
||
template bool getHistoryEntryForLedger<TransactionHistoryResultEntry>( | ||
XDRInputFileStream& stream, TransactionHistoryResultEntry& currentEntry, | ||
uint32_t targetLedger, std::function<void(uint32_t ledgerSeq)> validateFn); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
// Copyright 2025 Stellar Development Foundation and contributors. Licensed | ||
// under the Apache License, Version 2.0. See the COPYING file at the root | ||
// of this distribution or at http://www.apache.org/licenses/LICENSE-2.0 | ||
|
||
#pragma once | ||
|
||
#include <cstdint> | ||
#include <functional> | ||
|
||
namespace stellar | ||
{ | ||
|
||
class XDRInputFileStream; | ||
|
||
// This function centralizes the logic for iterating through | ||
// history archive tx set entries (TransactionHistoryEntry, | ||
// TransactionHistoryResultEntry) that may have gaps. Reads an entry from the | ||
// stream into currentEntry until eof or an entry is found with ledgerSeq >= | ||
// targetLedger. Returns true if targetLedger found (currentEntry will be set to | ||
// the target ledger). Otherwise returns false, where currentEntry is the last | ||
// entry read from the stream. | ||
template <typename T> | ||
bool getHistoryEntryForLedger( | ||
XDRInputFileStream& stream, T& currentEntry, uint32_t targetLedger, | ||
std::function<void(uint32_t ledgerSeq)> validateFn = nullptr); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters