diff --git a/.claude/skills/pruning-headers/SKILL.md b/.claude/skills/pruning-headers/SKILL.md new file mode 100644 index 0000000000..2348b01b21 --- /dev/null +++ b/.claude/skills/pruning-headers/SKILL.md @@ -0,0 +1,241 @@ +```skill +--- +name: "pruning-headers" +description: "How to prune unnecessary #include directives from C++ headers and source files in stellar-core, using clangd diagnostics." +--- + +# Pruning Headers in stellar-core + +## Overview + +Unnecessary `#include` directives increase compile times and create hidden +coupling between translation units. This skill describes how to systematically +remove them using clangd's Include Cleaner diagnostics, forward declarations, +and moving implementations out of headers. + +## Prerequisites + +1. **clangd-lsp plugin**: If you are running as Claude Code You MUST have the + `clangd-lsp` Claude Code plugin installed. If it is not installed, prompt + the user to install it: + ``` + /install-plugin clangd-lsp@claude-plugins-official + ``` + Do NOT attempt to invoke clangd manually via subprocess or script. The plugin + provides diagnostics automatically after each Edit tool call. Similarly if + you are running as copilot in VS Code, you must have the clangd extension + installed and configured and the `graydon/lsp-lm-tools` extension to expose + diagnostics in the editor. + +2. **Homebrew clangd**: The plugin needs clangd on `$PATH`. The recommended + version is Homebrew's (`/opt/homebrew/opt/llvm/bin/clangd`, version 21+) + which has Include Cleaner support. Apple's system clangd may be too old. + +3. **`compile_commands.json`**: clangd needs this in the project root to + understand build flags. Generate it with: + ``` + bear -- make -j $(nproc) + ``` + (`bear` is at `/opt/homebrew/bin/bear`). Ask the user to generate this if + it does not exist. + +## How the Plugin Works + +The clangd-lsp plugin reports diagnostics as `` blocks in +system reminders **after Edit tool calls**. Diagnostics are NOT produced on +Read tool calls. To trigger diagnostics for a file you must make an edit to it. + +The relevant diagnostic code is `[unused-includes]` from clangd. Example: + +``` +⚠ [Line 6:1] Included header Hex.h is not used directly (fix available) [unused-includes] (clangd) +``` + +**Important**: diagnostics sometimes lag by one edit. The diagnostics you see +after edit N may actually correspond to the state after edit N-1. Always check +whether reported line numbers and filenames match your current edit. + +## Approach: Three Passes + +### Pass 1 — Remove Unused Includes + +For each `.cpp` and `.h` file in the target directory: + +1. Read the file to understand its includes. +2. Make a trivial edit (e.g., remove then re-add a blank line after the + copyright header) to trigger clangd diagnostics. +3. Read the `[unused-includes]` diagnostics from the system reminder. +4. Remove the flagged includes. +5. Revert the trivial formatting change (restore the blank line). + +After processing all files, do a full build from the **top-level repo +directory**: +``` +make -j $(nproc) +``` + +If a file fails to compile, the removal was a false positive. Add the include +back and rebuild. + +### Pass 2 — Move Implementations from Headers to Source Files + +Headers should ideally contain only declarations, not implementations. Moving +function bodies, static data, and complex inline code out of `.h` files and +into `.cpp` files is one of the most effective ways to reduce transitive +include load — it often makes entire heavy includes unnecessary in the header. + +**What to move:** + +- Non-template function bodies (move to `.cpp`, leave declaration in `.h`) +- Static/global variable definitions (move to `.cpp`, leave `extern` decl or + accessor function in `.h`) +- Complex inline functions that pull in heavy headers (move to `.cpp`) +- Private implementation details that callers don't need to see + +**What must stay in headers:** + +- Template definitions — UNLESS you use explicit instantiation in the `.cpp` + file, which is encouraged when the set of template arguments is known and + finite (e.g., `template class BinaryFuseFilter;`) +- `constexpr` / `consteval` functions +- Truly trivial inline accessors (e.g., `int size() const { return mSize; }`) +- Type definitions, enums, constants needed by callers + +**Creating new `.cpp` files:** If a header has no corresponding `.cpp` file, +create one. Add it to git (`git add`), then run `./make-mks` from the +top-level repo directory — this script populates the source list variables +used by automake. Do NOT modify `Makefile.am` or other automake files +yourself. + +**Workflow:** + +1. Read the header and identify function bodies that can move to `.cpp`. +2. Move the bodies, leaving only declarations in the header. +3. Remove any includes from the header that were only needed for the moved + implementations. +4. Add those includes to the `.cpp` file instead. +5. Rebuild and fix any transitive-inclusion breakage in other files. + +**Example — before:** +```cpp +// Foo.h +#include "Bar.h" // heavy header +#include + +class Foo { + public: + void doWork() { + Bar b; + std::sort(b.begin(), b.end()); // needs Bar.h + algorithm + } +}; +``` + +**Example — after:** +```cpp +// Foo.h +class Bar; // forward declaration suffices now +class Foo { + public: + void doWork(); +}; + +// Foo.cpp +#include "Foo.h" +#include "Bar.h" +#include + +void Foo::doWork() { + Bar b; + std::sort(b.begin(), b.end()); +} +``` + +### Pass 3 — Replace Remaining Header Includes with Forward Declarations + +After moving implementations out, examine what remains in each header. For any +included type that is now only used in a pointer, reference, or function +declaration context, replace the `#include` with a forward declaration. + +**When to forward-declare vs. include:** + +- **Forward-declare** when the header only uses a type as: + - A pointer or reference (`Foo*`, `Foo&`, `std::unique_ptr`) + - A function parameter or return type (by pointer/reference) + - A template parameter where the template doesn't need the full definition + - A friend declaration + +- **Must include** when the header: + - Inherits from the type (`class Bar : public Foo`) + - Has a member of that type by value (`Foo mFoo;`) + - Calls methods on the type inline + - Uses `sizeof(Foo)` or accesses members + - Uses the type as a template argument where the template needs the full + definition (e.g., `std::vector` needs the full type) + +**Workflow:** + +1. Replace the `#include` with a forward declaration of the needed type. +2. Add the removed `#include` to every `.cpp` file that was relying on the + transitive inclusion (these will show up as compilation errors). +3. Rebuild to verify. + +**Prefer changing return types over keeping includes.** If a function in a +header returns a type by value and that's the only reason for a heavy include, +consider whether the return type can be changed to a standard type. For +example, if `VirtualClock::duration` is really just +`std::chrono::steady_clock::duration`, use the latter directly to avoid +pulling in `Timer.h`. + +**Common forward-declaration patterns in stellar-core:** + +```cpp +// Forward-declare XDR types +struct LedgerEntry; +struct LedgerKey; +struct TransactionMeta; + +// Forward-declare project classes +class Application; +class Config; +class VirtualClock; + +// Forward-declare in namespaces +namespace medida { class MetricsRegistry; } +``` + +## Known False Positives + +clangd's Include Cleaner sometimes flags includes that are actually needed: + +- **`util/asio.h`** in headers that use `asio::` types — clangd may not see + the usage if it's in platform-specific `#ifdef` blocks. +- **`util/SpdlogTweaks.h`** in `Logging.h` — this defines macros that must + be set before including spdlog headers. clangd doesn't track macro deps. +- **XDR headers** like `Stellar-ledger.h` — types may be used through + transitive XDR includes that clangd doesn't fully resolve. +- **`medida/metrics_registry.h`** — may provide base classes that clangd + doesn't always trace through inheritance. + +When in doubt, remove the include, rebuild, and re-add if it fails. + +## Build Verification + +Always build from the **top-level of the repo** (not a subdirectory): + +``` +make -j $(nproc) +``` + +Do NOT use bare `make -j` (no job count) as it may spawn too many processes. + +If the build fails due to a missing type after a header include was removed, +this means some other file was relying on transitive inclusion. Fix it by +adding the needed `#include` directly to the file that uses the type. + +## Scope Conventions + +- Process one directory at a time (e.g., `src/util/`, `src/crypto/`). +- Skip `test/` subdirectories in the initial pass. +- Commit after each directory is clean. +``` diff --git a/src/bucket/BucketApplicator.cpp b/src/bucket/BucketApplicator.cpp index aba334044a..fb5bd623f0 100644 --- a/src/bucket/BucketApplicator.cpp +++ b/src/bucket/BucketApplicator.cpp @@ -7,7 +7,6 @@ #include "bucket/LiveBucket.h" #include "bucket/LiveBucketList.h" #include "ledger/LedgerTxn.h" -#include "ledger/LedgerTxnEntry.h" #include "main/Application.h" #include "util/GlobalChecks.h" #include "util/Logging.h" diff --git a/src/bucket/BucketBase.cpp b/src/bucket/BucketBase.cpp index 4d80327a72..cdd6dea0dd 100644 --- a/src/bucket/BucketBase.cpp +++ b/src/bucket/BucketBase.cpp @@ -18,7 +18,6 @@ #include "bucket/MergeKey.h" #include "crypto/Hex.h" #include "crypto/Random.h" -#include "main/Application.h" #include "medida/timer.h" #include "util/Fs.h" #include "util/GlobalChecks.h" diff --git a/src/bucket/BucketBase.h b/src/bucket/BucketBase.h index 84f55d0096..690a3f1e74 100644 --- a/src/bucket/BucketBase.h +++ b/src/bucket/BucketBase.h @@ -4,8 +4,8 @@ #pragma once -#include "bucket/BucketInputIterator.h" #include "bucket/BucketUtils.h" +#include "util/GlobalChecks.h" #include "util/NonCopyable.h" #include "util/ProtocolVersion.h" #include "xdr/Stellar-types.h" diff --git a/src/bucket/BucketIndexUtils.h b/src/bucket/BucketIndexUtils.h index f18ad45e92..dd3044b619 100644 --- a/src/bucket/BucketIndexUtils.h +++ b/src/bucket/BucketIndexUtils.h @@ -4,7 +4,6 @@ #pragma once -#include "crypto/SHA.h" #include "util/GlobalChecks.h" #include "util/XDROperators.h" // IWYU pragma: keep #include "xdr/Stellar-ledger-entries.h" @@ -29,6 +28,7 @@ namespace stellar class BucketManager; class Config; +class SHA256; using AssetPoolIDMap = std::map>; using IndexPtrT = std::shared_ptr; diff --git a/src/bucket/BucketListBase.cpp b/src/bucket/BucketListBase.cpp index 55dad3fe7f..972f22ea99 100644 --- a/src/bucket/BucketListBase.cpp +++ b/src/bucket/BucketListBase.cpp @@ -3,12 +3,10 @@ // of this distribution or at http://www.apache.org/licenses/LICENSE-2.0 #include "bucket/BucketListBase.h" -#include "bucket/BucketInputIterator.h" #include "bucket/BucketManager.h" #include "bucket/HotArchiveBucket.h" #include "bucket/LiveBucket.h" #include "crypto/SHA.h" -#include "ledger/LedgerTxn.h" #include "main/Application.h" #include "util/GlobalChecks.h" #include "util/Logging.h" diff --git a/src/bucket/BucketListSnapshot.cpp b/src/bucket/BucketListSnapshot.cpp index eae919bc06..d7fee43855 100644 --- a/src/bucket/BucketListSnapshot.cpp +++ b/src/bucket/BucketListSnapshot.cpp @@ -7,7 +7,6 @@ #include "bucket/BucketInputIterator.h" #include "bucket/BucketListBase.h" #include "bucket/LiveBucketList.h" -#include "ledger/LedgerTxn.h" #include "ledger/LedgerTypeUtils.h" #include "util/GlobalChecks.h" #include "util/MetricsRegistry.h" diff --git a/src/bucket/BucketManager.cpp b/src/bucket/BucketManager.cpp index 99dc31ca37..3d36c8f4fa 100644 --- a/src/bucket/BucketManager.cpp +++ b/src/bucket/BucketManager.cpp @@ -4,7 +4,6 @@ #include "bucket/BucketManager.h" #include "bucket/BucketInputIterator.h" -#include "bucket/BucketManager.h" #include "bucket/BucketOutputIterator.h" #include "bucket/BucketSnapshotManager.h" #include "bucket/BucketUtils.h" @@ -16,7 +15,6 @@ #include "crypto/Hex.h" #include "history/HistoryManager.h" #include "historywork/VerifyBucketWork.h" -#include "invariant/InvariantManager.h" #include "ledger/LedgerManager.h" #include "ledger/LedgerTxn.h" #include "ledger/LedgerTypeUtils.h" @@ -33,9 +31,8 @@ #include "util/MetricsRegistry.h" #include "util/ProtocolVersion.h" #include "util/TmpDir.h" -#include "util/UnorderedMap.h" #include "util/types.h" -#include "xdr/Stellar-ledger.h" +#include "work/WorkSequence.h" #include #include #include @@ -45,7 +42,6 @@ #include #include -#include "history/FileTransferInfo.h" #include "medida/counter.h" #include "medida/meter.h" #include "medida/timer.h" diff --git a/src/bucket/BucketManager.h b/src/bucket/BucketManager.h index 24da0e171c..5f06fabed1 100644 --- a/src/bucket/BucketManager.h +++ b/src/bucket/BucketManager.h @@ -12,14 +12,12 @@ #include "util/TmpDir.h" #include "util/UnorderedMap.h" #include "util/types.h" -#include "work/BasicWork.h" #include "xdr/Stellar-ledger.h" #include #include #include #include -#include #include #include @@ -36,6 +34,7 @@ namespace stellar class TmpDir; class AbstractLedgerTxn; class AppConnector; +class BasicWork; class Bucket; class LiveBucketList; class HotArchiveBucketList; diff --git a/src/bucket/BucketOutputIterator.h b/src/bucket/BucketOutputIterator.h index a76e1c6bb7..4b9a7fe287 100644 --- a/src/bucket/BucketOutputIterator.h +++ b/src/bucket/BucketOutputIterator.h @@ -4,9 +4,9 @@ #pragma once -#include "bucket/BucketManager.h" #include "bucket/BucketUtils.h" #include "bucket/LedgerCmp.h" +#include "crypto/SHA.h" #include "util/XDRStream.h" #include @@ -17,6 +17,7 @@ namespace stellar class Bucket; class BucketManager; +struct MergeKey; // Helper class that writes new elements to a file and returns a bucket // when finished. diff --git a/src/bucket/BucketSnapshotManager.h b/src/bucket/BucketSnapshotManager.h index 09fbaf1575..819d53796b 100644 --- a/src/bucket/BucketSnapshotManager.h +++ b/src/bucket/BucketSnapshotManager.h @@ -5,8 +5,6 @@ // of this distribution or at http://www.apache.org/licenses/LICENSE-2.0 #include "bucket/BucketListSnapshot.h" -#include "bucket/HotArchiveBucket.h" -#include "bucket/LiveBucket.h" #include "util/NonCopyable.h" #include "util/ThreadAnnotations.h" diff --git a/src/bucket/BucketUtils.cpp b/src/bucket/BucketUtils.cpp index bc0358e683..815a1d983e 100644 --- a/src/bucket/BucketUtils.cpp +++ b/src/bucket/BucketUtils.cpp @@ -7,7 +7,6 @@ #include "bucket/LiveBucket.h" #include "ledger/LedgerTypeUtils.h" #include "main/AppConnector.h" -#include "main/Application.h" #include "util/MetricsRegistry.h" #include "util/types.h" #include "xdr/Stellar-ledger-entries.h" diff --git a/src/bucket/HotArchiveBucket.cpp b/src/bucket/HotArchiveBucket.cpp index 7aa98be461..c0bd2443d1 100644 --- a/src/bucket/HotArchiveBucket.cpp +++ b/src/bucket/HotArchiveBucket.cpp @@ -4,6 +4,7 @@ #include "bucket/HotArchiveBucket.h" #include "bucket/BucketInputIterator.h" +#include "bucket/BucketManager.h" #include "bucket/BucketMergeAdapter.h" #include "bucket/BucketOutputIterator.h" #include "bucket/BucketUtils.h" diff --git a/src/bucket/LiveBucket.cpp b/src/bucket/LiveBucket.cpp index 8101c9d183..c64f28037c 100644 --- a/src/bucket/LiveBucket.cpp +++ b/src/bucket/LiveBucket.cpp @@ -6,10 +6,12 @@ #include "bucket/BucketApplicator.h" #include "bucket/BucketBase.h" #include "bucket/BucketInputIterator.h" +#include "bucket/BucketManager.h" #include "bucket/BucketMergeAdapter.h" #include "bucket/BucketOutputIterator.h" #include "bucket/BucketUtils.h" #include "bucket/LedgerCmp.h" +#include "main/Application.h" #include namespace stellar diff --git a/src/catchup/ApplyBucketsWork.cpp b/src/catchup/ApplyBucketsWork.cpp index fee35aa919..a495544605 100644 --- a/src/catchup/ApplyBucketsWork.cpp +++ b/src/catchup/ApplyBucketsWork.cpp @@ -6,19 +6,16 @@ #include "bucket/BucketApplicator.h" #include "bucket/BucketManager.h" #include "bucket/LiveBucket.h" -#include "bucket/LiveBucketList.h" #include "catchup/AssumeStateWork.h" #include "catchup/IndexBucketsWork.h" #include "catchup/LedgerApplyManager.h" #include "crypto/Hex.h" -#include "crypto/SecretKey.h" -#include "historywork/Progress.h" #include "invariant/InvariantManager.h" #include "ledger/LedgerManager.h" #include "ledger/LedgerTxn.h" #include "main/Application.h" -#include "transactions/TransactionUtils.h" #include "util/GlobalChecks.h" +#include "util/types.h" #include #include diff --git a/src/catchup/ApplyBucketsWork.h b/src/catchup/ApplyBucketsWork.h index a5d210157c..98c922d97e 100644 --- a/src/catchup/ApplyBucketsWork.h +++ b/src/catchup/ApplyBucketsWork.h @@ -5,7 +5,6 @@ #pragma once #include "bucket/BucketApplicator.h" -#include "ledger/LedgerHashUtils.h" #include "work/Work.h" namespace stellar diff --git a/src/catchup/ApplyBufferedLedgersWork.h b/src/catchup/ApplyBufferedLedgersWork.h index 19e143b860..5fe30b5791 100644 --- a/src/catchup/ApplyBufferedLedgersWork.h +++ b/src/catchup/ApplyBufferedLedgersWork.h @@ -4,7 +4,6 @@ #pragma once -#include "herder/LedgerCloseData.h" #include "work/BasicWork.h" #include "work/ConditionalWork.h" diff --git a/src/catchup/ApplyCheckpointWork.cpp b/src/catchup/ApplyCheckpointWork.cpp index 55baac03cb..db031e0d6c 100644 --- a/src/catchup/ApplyCheckpointWork.cpp +++ b/src/catchup/ApplyCheckpointWork.cpp @@ -9,8 +9,6 @@ #include "history/FileTransferInfo.h" #include "history/HistoryManager.h" #include "history/HistoryUtils.h" -#include "historywork/Progress.h" -#include "ledger/CheckpointRange.h" #include "ledger/LedgerManager.h" #include "main/Application.h" #include "util/GlobalChecks.h" diff --git a/src/catchup/ApplyCheckpointWork.h b/src/catchup/ApplyCheckpointWork.h index f85f8c52bd..79b286bf54 100644 --- a/src/catchup/ApplyCheckpointWork.h +++ b/src/catchup/ApplyCheckpointWork.h @@ -11,7 +11,6 @@ #include "util/XDRStream.h" #include "work/ConditionalWork.h" #include "work/Work.h" -#include "xdr/Stellar-SCP.h" #include "xdr/Stellar-ledger.h" namespace stellar diff --git a/src/catchup/CatchupConfiguration.h b/src/catchup/CatchupConfiguration.h index b197af9edf..dc737751d0 100644 --- a/src/catchup/CatchupConfiguration.h +++ b/src/catchup/CatchupConfiguration.h @@ -4,7 +4,6 @@ #pragma once -#include "history/HistoryArchive.h" #include "ledger/LedgerRange.h" #include #include diff --git a/src/catchup/CatchupRange.cpp b/src/catchup/CatchupRange.cpp index df39acb050..cecfc134d2 100644 --- a/src/catchup/CatchupRange.cpp +++ b/src/catchup/CatchupRange.cpp @@ -7,8 +7,7 @@ #include "history/HistoryManager.h" #include "ledger/LedgerManager.h" #include "util/GlobalChecks.h" -#include "util/Logging.h" -#include +#include namespace { @@ -129,6 +128,69 @@ CatchupRange::CatchupRange(uint32_t lastClosedLedger, checkInvariants(); } +LedgerRange +CatchupRange::getFullRangeIncludingBucketApply() const +{ + if (mApplyBuckets) + { + return LedgerRange(mApplyBucketsAtLedger, mReplayRange.mCount + 1); + } + else + { + return mReplayRange; + } +} + +uint32_t +CatchupRange::count() const +{ + if (mApplyBuckets) + { + return mReplayRange.mCount + 1; + } + return mReplayRange.mCount; +} + +uint32_t +CatchupRange::first() const +{ + if (mApplyBuckets) + { + return mApplyBucketsAtLedger; + } + else + { + return mReplayRange.mFirst; + } +} + +uint32_t +CatchupRange::last() const +{ + if (mReplayRange.mCount != 0) + { + return mReplayRange.last(); + } + else + { + // If we're not doing any ledger replay, we should at least be + // applying buckets. + releaseAssert(mApplyBuckets); + return mApplyBucketsAtLedger; + } +} + +uint32_t +CatchupRange::getBucketApplyLedger() const +{ + if (!mApplyBuckets) + { + throw std::logic_error("getBucketApplyLedger() cannot be called on " + "CatchupRange when mApplyBuckets == false"); + } + return mApplyBucketsAtLedger; +} + void CatchupRange::checkInvariants() { diff --git a/src/catchup/CatchupRange.h b/src/catchup/CatchupRange.h index 4b1e9d5163..5aea403ec6 100644 --- a/src/catchup/CatchupRange.h +++ b/src/catchup/CatchupRange.h @@ -6,8 +6,6 @@ #include "catchup/CatchupConfiguration.h" #include "ledger/LedgerRange.h" -#include "util/GlobalChecks.h" -#include namespace stellar { @@ -50,57 +48,11 @@ class CatchupRange public: // Return a LedgerRange spanning both the apply-buckets phase (if it // exists) and the replay phase. - LedgerRange - getFullRangeIncludingBucketApply() const - { - if (mApplyBuckets) - { - return LedgerRange(mApplyBucketsAtLedger, mReplayRange.mCount + 1); - } - else - { - return mReplayRange; - } - } - - uint32_t - count() const - { - if (mApplyBuckets) - { - return mReplayRange.mCount + 1; - } - return mReplayRange.mCount; - } - - uint32_t - first() const - { - if (mApplyBuckets) - { - return mApplyBucketsAtLedger; - } - else - { - return mReplayRange.mFirst; - } - } + LedgerRange getFullRangeIncludingBucketApply() const; - uint32_t - last() const - { - if (mReplayRange.mCount != 0) - { - return mReplayRange.last(); - } - else - { - // If we're not doing any ledger replay, we should at least be - // applying buckets. - releaseAssert(mApplyBuckets); - return mApplyBucketsAtLedger; - } - } + uint32_t count() const; + uint32_t first() const; + uint32_t last() const; // Return the LedgerRange that covers the ledger-replay part of this // catchup. @@ -150,16 +102,7 @@ class CatchupRange return mApplyBuckets; } - uint32_t - getBucketApplyLedger() const - { - if (!mApplyBuckets) - { - throw std::logic_error("getBucketApplyLedger() cannot be called on " - "CatchupRange when mApplyBuckets == false"); - } - return mApplyBucketsAtLedger; - } + uint32_t getBucketApplyLedger() const; /** * Preconditions: diff --git a/src/catchup/CatchupWork.cpp b/src/catchup/CatchupWork.cpp index 5866af3780..c6d413088d 100644 --- a/src/catchup/CatchupWork.cpp +++ b/src/catchup/CatchupWork.cpp @@ -3,10 +3,8 @@ // of this distribution or at http://www.apache.org/licenses/LICENSE-2.0 #include "catchup/CatchupWork.h" -#include "bucket/BucketManager.h" #include "catchup/ApplyBucketsWork.h" #include "catchup/ApplyBufferedLedgersWork.h" -#include "catchup/ApplyCheckpointWork.h" #include "catchup/CatchupConfiguration.h" #include "catchup/CatchupRange.h" #include "catchup/DownloadApplyTxsWork.h" @@ -17,13 +15,14 @@ #include "historywork/BatchDownloadWork.h" #include "historywork/DownloadBucketsWork.h" #include "historywork/DownloadVerifyTxResultsWork.h" -#include "historywork/GetAndUnzipRemoteFileWork.h" #include "historywork/GetHistoryArchiveStateWork.h" #include "ledger/LedgerManager.h" #include "main/Application.h" #include "main/PersistentState.h" #include "util/GlobalChecks.h" #include "util/Logging.h" +#include "util/Thread.h" +#include "util/XDRStream.h" #include "work/WorkWithCallback.h" #include #include @@ -118,6 +117,16 @@ CatchupWork::getStatus() const : Work::getStatus()); } +bool +CatchupWork::fatalFailure() +{ + if (futureIsReady(mFatalFailureFuture)) + { + return mFatalFailureFuture.get(); + } + return false; +} + void CatchupWork::doReset() { diff --git a/src/catchup/CatchupWork.h b/src/catchup/CatchupWork.h index 34c4330da4..8b8d8bf72f 100644 --- a/src/catchup/CatchupWork.h +++ b/src/catchup/CatchupWork.h @@ -8,7 +8,6 @@ #include "catchup/VerifyLedgerChainWork.h" #include "history/HistoryArchive.h" #include "historywork/GetHistoryArchiveStateWork.h" -#include "util/Thread.h" #include "work/Work.h" #include "work/WorkSequence.h" @@ -76,15 +75,7 @@ class CatchupWork : public Work return mCatchupConfiguration; } - bool - fatalFailure() - { - if (futureIsReady(mFatalFailureFuture)) - { - return mFatalFailureFuture.get(); - } - return false; - } + bool fatalFailure(); private: LedgerNumHashPair mLastClosedLedgerHashPair; diff --git a/src/catchup/DownloadApplyTxsWork.cpp b/src/catchup/DownloadApplyTxsWork.cpp index ca13047e7c..de880f8666 100644 --- a/src/catchup/DownloadApplyTxsWork.cpp +++ b/src/catchup/DownloadApplyTxsWork.cpp @@ -6,6 +6,7 @@ #include "bucket/BucketManager.h" #include "bucket/LiveBucketList.h" #include "catchup/ApplyCheckpointWork.h" +#include "catchup/CatchupWork.h" #include "history/FileTransferInfo.h" #include "history/HistoryManager.h" #include "historywork/GetAndUnzipRemoteFileWork.h" diff --git a/src/catchup/DownloadApplyTxsWork.h b/src/catchup/DownloadApplyTxsWork.h index 8f7216a6e9..9439a1ef33 100644 --- a/src/catchup/DownloadApplyTxsWork.h +++ b/src/catchup/DownloadApplyTxsWork.h @@ -5,9 +5,7 @@ #pragma once #include "ledger/LedgerRange.h" -#include "util/XDRStream.h" #include "work/BatchWork.h" -#include "xdr/Stellar-ledger.h" namespace medida { diff --git a/src/catchup/LedgerApplyManager.h b/src/catchup/LedgerApplyManager.h index 038a060480..b9aab3f125 100644 --- a/src/catchup/LedgerApplyManager.h +++ b/src/catchup/LedgerApplyManager.h @@ -4,10 +4,10 @@ #pragma once -#include "catchup/CatchupWork.h" +#include "catchup/CatchupConfiguration.h" #include "herder/LedgerCloseData.h" #include "history/FileTransferInfo.h" -#include +#include "work/BasicWork.h" #include #include @@ -23,6 +23,7 @@ namespace stellar class Application; class CatchupMetrics; class FileTransferInfo; +class HistoryArchive; class LedgerApplyManager { diff --git a/src/catchup/LedgerApplyManagerImpl.cpp b/src/catchup/LedgerApplyManagerImpl.cpp index 1193d02ba3..efc6776c53 100644 --- a/src/catchup/LedgerApplyManagerImpl.cpp +++ b/src/catchup/LedgerApplyManagerImpl.cpp @@ -8,11 +8,9 @@ #include "util/asio.h" #include "catchup/LedgerApplyManagerImpl.h" #include "catchup/CatchupConfiguration.h" -#include "herder/Herder.h" #include "history/FileTransferInfo.h" #include "ledger/LedgerManager.h" #include "main/Application.h" -#include "medida/meter.h" #include "util/GlobalChecks.h" #include "util/Logging.h" #include "util/MetricsRegistry.h" @@ -611,4 +609,13 @@ LedgerApplyManagerImpl::fileDownloaded(FileType type, uint32_t num) } } +#ifdef BUILD_TESTS +uint32_t +LedgerApplyManagerImpl::getMaxExternalizeApplyBuffer() +{ + return mMaxExternalizeApplyBuffer ? *mMaxExternalizeApplyBuffer + : MAX_EXTERNALIZE_LEDGER_APPLY_DRIFT; +} +#endif + } diff --git a/src/catchup/LedgerApplyManagerImpl.h b/src/catchup/LedgerApplyManagerImpl.h index 0b635963ce..64fc894372 100644 --- a/src/catchup/LedgerApplyManagerImpl.h +++ b/src/catchup/LedgerApplyManagerImpl.h @@ -127,12 +127,7 @@ class LedgerApplyManagerImpl : public LedgerApplyManager } std::optional mMaxExternalizeApplyBuffer; - uint32_t - getMaxExternalizeApplyBuffer() - { - return mMaxExternalizeApplyBuffer ? *mMaxExternalizeApplyBuffer - : MAX_EXTERNALIZE_LEDGER_APPLY_DRIFT; - } + uint32_t getMaxExternalizeApplyBuffer(); #endif }; } diff --git a/src/catchup/ReplayDebugMetaWork.cpp b/src/catchup/ReplayDebugMetaWork.cpp index 5e62438912..fa28956559 100644 --- a/src/catchup/ReplayDebugMetaWork.cpp +++ b/src/catchup/ReplayDebugMetaWork.cpp @@ -3,8 +3,7 @@ // of this distribution or at http://www.apache.org/licenses/LICENSE-2.0 #include "catchup/ReplayDebugMetaWork.h" -#include "catchup/CatchupWork.h" -#include "work/WorkScheduler.h" +#include "work/WorkSequence.h" #include "work/WorkWithCallback.h" #include "catchup/ApplyLedgerWork.h" diff --git a/src/catchup/ReplayDebugMetaWork.h b/src/catchup/ReplayDebugMetaWork.h index 5f7ad96fb3..e154db3f11 100644 --- a/src/catchup/ReplayDebugMetaWork.h +++ b/src/catchup/ReplayDebugMetaWork.h @@ -4,7 +4,6 @@ #pragma once -#include "main/Application.h" #include "work/Work.h" #include diff --git a/src/crypto/BLAKE2.cpp b/src/crypto/BLAKE2.cpp index 956d611763..8bb49a6157 100644 --- a/src/crypto/BLAKE2.cpp +++ b/src/crypto/BLAKE2.cpp @@ -5,7 +5,6 @@ #include "crypto/BLAKE2.h" #include "crypto/ByteSlice.h" #include "crypto/CryptoError.h" -#include "util/NonCopyable.h" #include #include diff --git a/src/crypto/BLAKE2.h b/src/crypto/BLAKE2.h index b656d69e1c..c0d34777e8 100644 --- a/src/crypto/BLAKE2.h +++ b/src/crypto/BLAKE2.h @@ -8,7 +8,6 @@ #include "crypto/XDRHasher.h" #include "sodium/crypto_generichash.h" #include "xdr/Stellar-types.h" -#include namespace stellar { diff --git a/src/crypto/CryptoError.h b/src/crypto/CryptoError.h index e7459f434a..a37f4fd431 100644 --- a/src/crypto/CryptoError.h +++ b/src/crypto/CryptoError.h @@ -4,7 +4,6 @@ #pragma once -#include #include #include diff --git a/src/crypto/Curve25519.h b/src/crypto/Curve25519.h index db8395da5c..c1bc8ad822 100644 --- a/src/crypto/Curve25519.h +++ b/src/crypto/Curve25519.h @@ -5,7 +5,6 @@ #pragma once #include "ByteSlice.h" -#include "util/Logging.h" #include "xdr/Stellar-types.h" #include #include diff --git a/src/crypto/SHA.cpp b/src/crypto/SHA.cpp index 67abe2608b..1b882946c0 100644 --- a/src/crypto/SHA.cpp +++ b/src/crypto/SHA.cpp @@ -5,8 +5,6 @@ #include "crypto/SHA.h" #include "crypto/ByteSlice.h" #include "crypto/CryptoError.h" -#include "crypto/Curve25519.h" -#include "util/NonCopyable.h" #include #include diff --git a/src/crypto/SHA.h b/src/crypto/SHA.h index e00cfd8c66..d575fff689 100644 --- a/src/crypto/SHA.h +++ b/src/crypto/SHA.h @@ -8,7 +8,6 @@ #include "crypto/XDRHasher.h" #include "sodium/crypto_hash_sha256.h" #include "xdr/Stellar-types.h" -#include namespace stellar { diff --git a/src/crypto/SecretKey.cpp b/src/crypto/SecretKey.cpp index 1c92d1c090..813b5ca393 100644 --- a/src/crypto/SecretKey.cpp +++ b/src/crypto/SecretKey.cpp @@ -5,12 +5,10 @@ #include "crypto/SecretKey.h" #include "crypto/BLAKE2.h" #include "crypto/CryptoError.h" -#include "crypto/Curve25519.h" #include "crypto/Hex.h" #include "crypto/KeyUtils.h" #include "crypto/Random.h" #include "crypto/StrKey.h" -#include "main/Config.h" #include "rust/RustBridge.h" #include "transactions/SignatureUtils.h" #include "util/GlobalChecks.h" @@ -19,10 +17,8 @@ #include "util/RandomEvictionCache.h" #include #include -#include #include #include -#include #ifdef MSAN_ENABLED #include diff --git a/src/crypto/SecretKey.h b/src/crypto/SecretKey.h index 9c3c96aeba..93d00a3a21 100644 --- a/src/crypto/SecretKey.h +++ b/src/crypto/SecretKey.h @@ -8,7 +8,6 @@ #include "util/XDROperators.h" #include "xdr/Stellar-types.h" -#include #include #include diff --git a/src/herder/QuorumIntersectionChecker.h b/src/herder/QuorumIntersectionChecker.h index 807a8bdf1f..188c7aeafb 100644 --- a/src/herder/QuorumIntersectionChecker.h +++ b/src/herder/QuorumIntersectionChecker.h @@ -7,6 +7,7 @@ #include "herder/QuorumTracker.h" #include "herder/RustQuorumCheckerAdaptor.h" #include "rust/RustBridge.h" +#include "util/Math.h" #include "util/TmpDir.h" #include #include diff --git a/src/history/CheckpointBuilder.h b/src/history/CheckpointBuilder.h index 63aa22b2c7..67ffea5839 100644 --- a/src/history/CheckpointBuilder.h +++ b/src/history/CheckpointBuilder.h @@ -5,11 +5,11 @@ #pragma once #include "herder/TxSetFrame.h" -#include "util/XDRStream.h" namespace stellar { class Application; +class XDROutputFileStream; /* * CheckpointBuilder manages the ACID transactional appending of confirmed diff --git a/src/history/FileTransferInfo.cpp b/src/history/FileTransferInfo.cpp index b5c1f0dc9a..5b69c4451b 100644 --- a/src/history/FileTransferInfo.cpp +++ b/src/history/FileTransferInfo.cpp @@ -3,6 +3,9 @@ // of this distribution or at http://www.apache.org/licenses/LICENSE-2.0 #include "FileTransferInfo.h" +#include "main/Config.h" +#include "util/Fs.h" +#include "util/TmpDir.h" #include #include @@ -73,4 +76,61 @@ getPublishHistoryDir(FileType type, Config const& cfg) std::filesystem::path root = cfg.BUCKET_DIR_PATH; return root / HISTORY_LOCAL_DIR_NAME / typeString(type); } + +FileTransferInfo::FileTransferInfo(TmpDir const& snapDir, + FileType const& snapType, + uint32_t checkpointLedger) + : mType(snapType) + , mHexDigits(fs::hexStr(checkpointLedger)) + , mLocalPath(getLocalDir(snapDir) + "/" + baseName_nogz()) +{ +} + +FileTransferInfo::FileTransferInfo(FileType const& snapType, + uint32_t checkpointLedger, Config const& cfg) + : mType(snapType) + , mHexDigits(fs::hexStr(checkpointLedger)) + , mLocalPath(getPublishHistoryDir(snapType, cfg).string() + "/" + + baseName_nogz()) +{ +} + +FileTransferInfo::FileTransferInfo(TmpDir const& snapDir, + FileType const& snapType, + std::string const& hexDigits) + : mType(snapType) + , mHexDigits(hexDigits) + , mLocalPath(getLocalDir(snapDir) + "/" + baseName_nogz()) +{ +} + +std::string +FileTransferInfo::baseName_nogz() const +{ + return fs::baseName(getTypeString(), mHexDigits, "xdr"); +} + +std::string +FileTransferInfo::baseName_gz() const +{ + return baseName_nogz() + ".gz"; +} + +std::string +FileTransferInfo::baseName_gz_tmp() const +{ + return baseName_nogz() + ".gz.tmp"; +} + +std::string +FileTransferInfo::remoteDir() const +{ + return fs::remoteDir(getTypeString(), mHexDigits); +} + +std::string +FileTransferInfo::remoteName() const +{ + return fs::remoteName(getTypeString(), mHexDigits, "xdr.gz"); +} } diff --git a/src/history/FileTransferInfo.h b/src/history/FileTransferInfo.h index 60cd9c2d00..836792d5a8 100644 --- a/src/history/FileTransferInfo.h +++ b/src/history/FileTransferInfo.h @@ -4,17 +4,18 @@ #pragma once -#include "bucket/LiveBucket.h" +#include "bucket/BucketUtils.h" #include "crypto/Hex.h" -#include "main/Config.h" -#include "util/Fs.h" -#include "util/TmpDir.h" +#include #include namespace stellar { -std::string const HISTORY_LOCAL_DIR_NAME = "history"; +class Config; +class TmpDir; + +inline std::string const HISTORY_LOCAL_DIR_NAME = "history"; enum class FileType { HISTORY_FILE_TYPE_BUCKET, @@ -47,29 +48,13 @@ class FileTransferInfo } FileTransferInfo(TmpDir const& snapDir, FileType const& snapType, - uint32_t checkpointLedger) - : mType(snapType) - , mHexDigits(fs::hexStr(checkpointLedger)) - , mLocalPath(getLocalDir(snapDir) + "/" + baseName_nogz()) - { - } + uint32_t checkpointLedger); FileTransferInfo(FileType const& snapType, uint32_t checkpointLedger, - Config const& cfg) - : mType(snapType) - , mHexDigits(fs::hexStr(checkpointLedger)) - , mLocalPath(getPublishHistoryDir(snapType, cfg).string() + "/" + - baseName_nogz()) - { - } + Config const& cfg); FileTransferInfo(TmpDir const& snapDir, FileType const& snapType, - std::string const& hexDigits) - : mType(snapType) - , mHexDigits(hexDigits) - , mLocalPath(getLocalDir(snapDir) + "/" + baseName_nogz()) - { - } + std::string const& hexDigits); FileType getType() const @@ -106,31 +91,10 @@ class FileTransferInfo return mLocalPath + ".gz.tmp"; } - std::string - baseName_nogz() const - { - return fs::baseName(getTypeString(), mHexDigits, "xdr"); - } - std::string - baseName_gz() const - { - return baseName_nogz() + ".gz"; - } - std::string - baseName_gz_tmp() const - { - return baseName_nogz() + ".gz.tmp"; - } - - std::string - remoteDir() const - { - return fs::remoteDir(getTypeString(), mHexDigits); - } - std::string - remoteName() const - { - return fs::remoteName(getTypeString(), mHexDigits, "xdr.gz"); - } + std::string baseName_nogz() const; + std::string baseName_gz() const; + std::string baseName_gz_tmp() const; + std::string remoteDir() const; + std::string remoteName() const; }; } diff --git a/src/history/HistoryArchive.cpp b/src/history/HistoryArchive.cpp index 8fe966d390..2c75eb69d7 100644 --- a/src/history/HistoryArchive.cpp +++ b/src/history/HistoryArchive.cpp @@ -27,8 +27,6 @@ #include #include #include -#include -#include #include #include diff --git a/src/history/HistoryArchiveReportWork.cpp b/src/history/HistoryArchiveReportWork.cpp index 5cd0691849..9cc6e64378 100644 --- a/src/history/HistoryArchiveReportWork.cpp +++ b/src/history/HistoryArchiveReportWork.cpp @@ -6,10 +6,6 @@ #include "history/HistoryArchive.h" #include "historywork/GetHistoryArchiveStateWork.h" #include "util/Logging.h" -#include "work/WorkSequence.h" -#include -#include -#include namespace stellar { diff --git a/src/history/HistoryManager.h b/src/history/HistoryManager.h index d910901b31..a6d9fc203e 100644 --- a/src/history/HistoryManager.h +++ b/src/history/HistoryManager.h @@ -6,9 +6,6 @@ #include "herder/TxSetFrame.h" #include "history/HistoryArchive.h" -#include "overlay/StellarXDR.h" -#include "util/GlobalChecks.h" -#include #include /** @@ -219,94 +216,41 @@ class HistoryManager // Return checkpoint that contains given ledger. Checkpoint is identified // by last ledger in range. This does not consult the network nor take // account of manual checkpoints. - static uint32_t - checkpointContainingLedger(uint32_t ledger, Config const& cfg) - { - uint32_t freq = getCheckpointFrequency(cfg); - // Round-up to next multiple of freq, then subtract 1 since checkpoints - // are numbered for (and cover ledgers up to) the last ledger in them, - // which is one-before the next multiple of freq. - return (((ledger / freq) + 1) * freq) - 1; - } + static uint32_t checkpointContainingLedger(uint32_t ledger, + Config const& cfg); // Return true iff closing `ledger` should cause publishing a checkpoint. // Equivalent to `ledger == checkpointContainingLedger(ledger)` but a little // more obviously named. - static bool - publishCheckpointOnLedgerClose(uint32_t ledger, Config const& cfg) - { - return checkpointContainingLedger(ledger, cfg) == ledger; - } + static bool publishCheckpointOnLedgerClose(uint32_t ledger, + Config const& cfg); - static bool - isFirstLedgerInCheckpoint(uint32_t ledger, Config const& cfg) - { - return firstLedgerInCheckpointContaining(ledger, cfg) == ledger; - } + static bool isFirstLedgerInCheckpoint(uint32_t ledger, Config const& cfg); - static bool - isLastLedgerInCheckpoint(uint32_t ledger, Config const& cfg) - { - return checkpointContainingLedger(ledger, cfg) == ledger; - } + static bool isLastLedgerInCheckpoint(uint32_t ledger, Config const& cfg); // Return the number of ledgers in the checkpoint containing a given ledger. - static uint32_t - sizeOfCheckpointContaining(uint32_t ledger, Config const& cfg) - { - uint32_t freq = getCheckpointFrequency(cfg); - if (ledger < freq) - { - return freq - 1; - } - return freq; - } + static uint32_t sizeOfCheckpointContaining(uint32_t ledger, + Config const& cfg); // Return the first ledger in the checkpoint containing a given ledger. - static uint32_t - firstLedgerInCheckpointContaining(uint32_t ledger, Config const& cfg) - { - uint32_t last = - checkpointContainingLedger(ledger, cfg); // == 63, 127, 191 - uint32_t size = - sizeOfCheckpointContaining(ledger, cfg); // == 63, 64, 64 - return last - (size - 1); // == 1, 64, 128 - } + static uint32_t firstLedgerInCheckpointContaining(uint32_t ledger, + Config const& cfg); // Return the first ledger after the checkpoint containing a given ledger. - static uint32_t - firstLedgerAfterCheckpointContaining(uint32_t ledger, Config const& cfg) - { - uint32_t first = - firstLedgerInCheckpointContaining(ledger, cfg); // == 1, 64, 128 - uint32_t size = - sizeOfCheckpointContaining(ledger, cfg); // == 63, 64, 64 - return first + size; // == 64, 128, 192 - } + static uint32_t firstLedgerAfterCheckpointContaining(uint32_t ledger, + Config const& cfg); // Return the last ledger before the checkpoint containing a given ledger, // or zero if `ledger` is contained inside the first checkpoint. - static uint32_t - lastLedgerBeforeCheckpointContaining(uint32_t ledger, Config const& cfg) - { - uint32_t last = - checkpointContainingLedger(ledger, cfg); // == 63, 127, 191 - uint32_t size = - sizeOfCheckpointContaining(ledger, cfg); // == 63, 64, 64 - releaseAssert(last >= size); - return last - size; // == 0, 63, 127 - } + static uint32_t lastLedgerBeforeCheckpointContaining(uint32_t ledger, + Config const& cfg); // Return the ledger to trigger the catchup machinery on, given a ledger // that is the start of a checkpoint buffered in the catchup manager. static uint32_t ledgerToTriggerCatchup(uint32_t firstLedgerOfBufferedCheckpoint, - Config const& cfg) - { - releaseAssert( - isFirstLedgerInCheckpoint(firstLedgerOfBufferedCheckpoint, cfg)); - return firstLedgerOfBufferedCheckpoint + 1; - } + Config const& cfg); // Return the length of the current publishing queue. static size_t publishQueueLength(Config const& cfg); diff --git a/src/history/HistoryManagerImpl.cpp b/src/history/HistoryManagerImpl.cpp index 2e20e5f98e..14b316bd11 100644 --- a/src/history/HistoryManagerImpl.cpp +++ b/src/history/HistoryManagerImpl.cpp @@ -10,7 +10,6 @@ #include "bucket/BucketManager.h" #include "bucket/LiveBucket.h" #include "bucket/LiveBucketList.h" -#include "herder/HerderImpl.h" #include #include #include @@ -19,12 +18,10 @@ #include "history/HistoryArchiveManager.h" #include "history/HistoryManagerImpl.h" #include "history/StateSnapshot.h" -#include "historywork/FetchRecentQsetsWork.h" #include "historywork/PublishWork.h" #include "historywork/PutSnapshotFilesWork.h" #include "historywork/ResolveSnapshotWork.h" #include "historywork/WriteSnapshotWork.h" -#include "ledger/LedgerManager.h" #include "main/Application.h" #include "main/Config.h" #include "medida/meter.h" @@ -60,6 +57,84 @@ HistoryManager::createPublishQueueDir(Config const& cfg) fs::mkpath(HistoryManager::publishQueuePath(cfg).string()); } +uint32_t +HistoryManager::checkpointContainingLedger(uint32_t ledger, Config const& cfg) +{ + uint32_t freq = getCheckpointFrequency(cfg); + // Round-up to next multiple of freq, then subtract 1 since checkpoints + // are numbered for (and cover ledgers up to) the last ledger in them, + // which is one-before the next multiple of freq. + return (((ledger / freq) + 1) * freq) - 1; +} + +bool +HistoryManager::publishCheckpointOnLedgerClose(uint32_t ledger, + Config const& cfg) +{ + return checkpointContainingLedger(ledger, cfg) == ledger; +} + +bool +HistoryManager::isFirstLedgerInCheckpoint(uint32_t ledger, Config const& cfg) +{ + return firstLedgerInCheckpointContaining(ledger, cfg) == ledger; +} + +bool +HistoryManager::isLastLedgerInCheckpoint(uint32_t ledger, Config const& cfg) +{ + return checkpointContainingLedger(ledger, cfg) == ledger; +} + +uint32_t +HistoryManager::sizeOfCheckpointContaining(uint32_t ledger, Config const& cfg) +{ + uint32_t freq = getCheckpointFrequency(cfg); + if (ledger < freq) + { + return freq - 1; + } + return freq; +} + +uint32_t +HistoryManager::firstLedgerInCheckpointContaining(uint32_t ledger, + Config const& cfg) +{ + uint32_t last = checkpointContainingLedger(ledger, cfg); // == 63, 127, 191 + uint32_t size = sizeOfCheckpointContaining(ledger, cfg); // == 63, 64, 64 + return last - (size - 1); // == 1, 64, 128 +} + +uint32_t +HistoryManager::firstLedgerAfterCheckpointContaining(uint32_t ledger, + Config const& cfg) +{ + uint32_t first = + firstLedgerInCheckpointContaining(ledger, cfg); // == 1, 64, 128 + uint32_t size = sizeOfCheckpointContaining(ledger, cfg); // == 63, 64, 64 + return first + size; // == 64, 128, 192 +} + +uint32_t +HistoryManager::lastLedgerBeforeCheckpointContaining(uint32_t ledger, + Config const& cfg) +{ + uint32_t last = checkpointContainingLedger(ledger, cfg); // == 63, 127, 191 + uint32_t size = sizeOfCheckpointContaining(ledger, cfg); // == 63, 64, 64 + releaseAssert(last >= size); + return last - size; // == 0, 63, 127 +} + +uint32_t +HistoryManager::ledgerToTriggerCatchup(uint32_t firstLedgerOfBufferedCheckpoint, + Config const& cfg) +{ + releaseAssert( + isFirstLedgerInCheckpoint(firstLedgerOfBufferedCheckpoint, cfg)); + return firstLedgerOfBufferedCheckpoint + 1; +} + namespace { std::filesystem::path diff --git a/src/history/HistoryManagerImpl.h b/src/history/HistoryManagerImpl.h index db3253cd70..56d2d2dbd7 100644 --- a/src/history/HistoryManagerImpl.h +++ b/src/history/HistoryManagerImpl.h @@ -7,7 +7,6 @@ #include "history/CheckpointBuilder.h" #include "history/HistoryManager.h" #include "util/TmpDir.h" -#include "work/Work.h" #include namespace medida @@ -20,7 +19,7 @@ namespace stellar { class Application; -class Work; +class BasicWork; class HistoryManagerImpl : public HistoryManager { diff --git a/src/history/StateSnapshot.h b/src/history/StateSnapshot.h index 588442c987..9827484761 100644 --- a/src/history/StateSnapshot.h +++ b/src/history/StateSnapshot.h @@ -5,10 +5,8 @@ #pragma once #include "history/HistoryArchive.h" -#include "util/Timer.h" #include "util/TmpDir.h" -#include #include #include diff --git a/src/history/test/HistoryTestsUtils.cpp b/src/history/test/HistoryTestsUtils.cpp index 219c3fbebc..8d241425ea 100644 --- a/src/history/test/HistoryTestsUtils.cpp +++ b/src/history/test/HistoryTestsUtils.cpp @@ -8,6 +8,7 @@ #include "bucket/HotArchiveBucket.h" #include "bucket/HotArchiveBucketList.h" #include "catchup/CatchupRange.h" +#include "catchup/CatchupWork.h" #include "crypto/Hex.h" #include "crypto/Random.h" #include "herder/TxSetFrame.h" diff --git a/src/historywork/CheckSingleLedgerHeaderWork.cpp b/src/historywork/CheckSingleLedgerHeaderWork.cpp index 2d887bceee..b548e84881 100644 --- a/src/historywork/CheckSingleLedgerHeaderWork.cpp +++ b/src/historywork/CheckSingleLedgerHeaderWork.cpp @@ -8,6 +8,7 @@ #include "history/HistoryManager.h" #include "historywork/GetAndUnzipRemoteFileWork.h" #include "main/ErrorMessages.h" +#include "util/FileSystemException.h" #include "util/GlobalChecks.h" #include "util/Logging.h" #include "util/MetricsRegistry.h" diff --git a/src/historywork/DownloadBucketsWork.cpp b/src/historywork/DownloadBucketsWork.cpp index a689a043e2..f773a86645 100644 --- a/src/historywork/DownloadBucketsWork.cpp +++ b/src/historywork/DownloadBucketsWork.cpp @@ -10,9 +10,11 @@ #include "history/HistoryArchive.h" #include "historywork/GetAndUnzipRemoteFileWork.h" #include "historywork/VerifyBucketWork.h" +#include "work/WorkSequence.h" #include "work/WorkWithCallback.h" #include #include +#include #include namespace stellar diff --git a/src/historywork/WriteVerifiedCheckpointHashesWork.cpp b/src/historywork/WriteVerifiedCheckpointHashesWork.cpp index 7317e3b059..3c57dfdc02 100644 --- a/src/historywork/WriteVerifiedCheckpointHashesWork.cpp +++ b/src/historywork/WriteVerifiedCheckpointHashesWork.cpp @@ -14,6 +14,7 @@ #include "util/GlobalChecks.h" #include "util/Logging.h" #include "work/ConditionalWork.h" +#include "work/WorkSequence.h" #include #include #include diff --git a/src/ledger/CheckpointRange.cpp b/src/ledger/CheckpointRange.cpp index cd1203a21a..51ed94fee6 100644 --- a/src/ledger/CheckpointRange.cpp +++ b/src/ledger/CheckpointRange.cpp @@ -4,10 +4,11 @@ #include "ledger/CheckpointRange.h" #include "history/HistoryManager.h" -#include "ledger/LedgerRange.h" #include "util/GlobalChecks.h" #include +#include +#include namespace stellar { @@ -20,6 +21,35 @@ CheckpointRange::CheckpointRange(uint32_t first, uint32_t count, releaseAssert((mFirst + 1) % mFrequency == 0); } +CheckpointRange +CheckpointRange::inclusive(uint32_t first, uint32_t last, uint32_t frequency) +{ + // CheckpointRange is half-open: in exchange for being able to represent + // empty ranges, it can't represent ranges that include UINT32_MAX. + releaseAssert(last < std::numeric_limits::max()); + + // First and last must both be ledgers identifying checkpoints (i.e. one + // less than multiples of frequency), and last must be >= first. The + // resulting count will always be 1 or more since this is an inclusive + // range. + releaseAssert(last >= first); + releaseAssert((first + 1) % frequency == 0); + releaseAssert((last + 1) % frequency == 0); + uint32_t count = 1 + ((last - first) / frequency); + return CheckpointRange(first, count, frequency); +} + +uint32_t +CheckpointRange::last() const +{ + if (mCount == 0) + { + throw std::logic_error("last() cannot be called on " + "CheckpointRange when mCount == 0"); + } + return mFirst + ((mCount - 1) * mFrequency); +} + namespace { uint32_t diff --git a/src/ledger/CheckpointRange.h b/src/ledger/CheckpointRange.h index 3d3436034d..297b56c979 100644 --- a/src/ledger/CheckpointRange.h +++ b/src/ledger/CheckpointRange.h @@ -5,9 +5,7 @@ #pragma once #include "ledger/LedgerRange.h" -#include "util/GlobalChecks.h" #include -#include #include namespace stellar @@ -24,23 +22,8 @@ struct CheckpointRange final uint32_t const mFrequency; CheckpointRange(uint32_t first, uint32_t count, uint32_t frequency); - static CheckpointRange - inclusive(uint32_t first, uint32_t last, uint32_t frequency) - { - // CheckpointRange is half-open: in exchange for being able to represent - // empty ranges, it can't represent ranges that include UINT32_MAX. - releaseAssert(last < std::numeric_limits::max()); - - // First and last must both be ledgers identifying checkpoints (i.e. one - // less than multiples of frequency), and last must be >= first. The - // resulting count will always be 1 or more since this is an inclusive - // range. - releaseAssert(last >= first); - releaseAssert((first + 1) % frequency == 0); - releaseAssert((last + 1) % frequency == 0); - uint32_t count = 1 + ((last - first) / frequency); - return CheckpointRange(first, count, frequency); - } + static CheckpointRange inclusive(uint32_t first, uint32_t last, + uint32_t frequency); CheckpointRange(LedgerRange const& ledgerRange, HistoryManager const& historyManager); friend bool operator==(CheckpointRange const& x, CheckpointRange const& y); @@ -64,16 +47,7 @@ struct CheckpointRange final return mFirst + getLedgerCount(); } - uint32_t - last() const - { - if (mCount == 0) - { - throw std::logic_error("last() cannot be called on " - "CheckpointRange when mCount == 0"); - } - return mFirst + ((mCount - 1) * mFrequency); - } + uint32_t last() const; std::string toString() const; }; diff --git a/src/ledger/FlushAndRotateMetaDebugWork.cpp b/src/ledger/FlushAndRotateMetaDebugWork.cpp index a1ee4cbb4a..0fd7a2d5e1 100644 --- a/src/ledger/FlushAndRotateMetaDebugWork.cpp +++ b/src/ledger/FlushAndRotateMetaDebugWork.cpp @@ -4,9 +4,10 @@ #include "ledger/FlushAndRotateMetaDebugWork.h" #include "bucket/BucketManager.h" +#include "historywork/GzipFileWork.h" #include "util/DebugMetaUtils.h" -#include "util/Fs.h" #include "util/GlobalChecks.h" +#include "util/XDRStream.h" #include #include #include diff --git a/src/ledger/FlushAndRotateMetaDebugWork.h b/src/ledger/FlushAndRotateMetaDebugWork.h index 2b300fdf50..f26628d9eb 100644 --- a/src/ledger/FlushAndRotateMetaDebugWork.h +++ b/src/ledger/FlushAndRotateMetaDebugWork.h @@ -4,13 +4,16 @@ #pragma once -#include "historywork/GzipFileWork.h" -#include "util/XDRStream.h" +#include "work/Work.h" #include +#include namespace stellar { +class GzipFileWork; +class XDROutputFileStream; + class FlushAndRotateMetaDebugWork : public Work { std::filesystem::path mMetaDebugPath; diff --git a/src/ledger/InMemorySorobanState.cpp b/src/ledger/InMemorySorobanState.cpp index c7d1b40565..869ea7ecdd 100644 --- a/src/ledger/InMemorySorobanState.cpp +++ b/src/ledger/InMemorySorobanState.cpp @@ -4,10 +4,9 @@ #include "ledger/InMemorySorobanState.h" #include "bucket/BucketListSnapshot.h" -#include "ledger/LedgerTypeUtils.h" +#include "ledger/NetworkConfig.h" #include "ledger/SorobanMetrics.h" #include "util/GlobalChecks.h" -#include #include namespace stellar diff --git a/src/ledger/InMemorySorobanState.h b/src/ledger/InMemorySorobanState.h index 385e494841..51cc028b95 100644 --- a/src/ledger/InMemorySorobanState.h +++ b/src/ledger/InMemorySorobanState.h @@ -11,7 +11,6 @@ #include #include "bucket/BucketSnapshotManager.h" -#include "invariant/InvariantManagerImpl.h" #include "ledger/LedgerTypeUtils.h" #include "util/types.h" #include "xdr/Stellar-ledger-entries.h" diff --git a/src/ledger/LedgerCloseMetaFrame.cpp b/src/ledger/LedgerCloseMetaFrame.cpp index 1956e1b6ca..da34707d4d 100644 --- a/src/ledger/LedgerCloseMetaFrame.cpp +++ b/src/ledger/LedgerCloseMetaFrame.cpp @@ -3,8 +3,10 @@ // of this distribution or at http://www.apache.org/licenses/LICENSE-2.0 #include "ledger/LedgerCloseMetaFrame.h" -#include "crypto/SHA.h" +#include "bucket/BucketUtils.h" +#include "herder/TxSetFrame.h" #include "ledger/LedgerTypeUtils.h" +#include "ledger/NetworkConfig.h" #include "transactions/TransactionMeta.h" #include "util/GlobalChecks.h" #include "util/ProtocolVersion.h" diff --git a/src/ledger/LedgerCloseMetaFrame.h b/src/ledger/LedgerCloseMetaFrame.h index 423eb017c0..2cfed0e8d0 100644 --- a/src/ledger/LedgerCloseMetaFrame.h +++ b/src/ledger/LedgerCloseMetaFrame.h @@ -4,12 +4,15 @@ #pragma once -#include "herder/TxSetFrame.h" #include "xdr/Stellar-ledger.h" namespace stellar { +class TxSetXDRFrame; +struct EvictedStateVectors; +class SorobanNetworkConfig; + // Wrapper around LedgerCloseMeta XDR that provides mutable access to fields // in the proper version of meta. class LedgerCloseMetaFrame diff --git a/src/ledger/LedgerEntryScope.cpp b/src/ledger/LedgerEntryScope.cpp index 9d9fde38e0..2070f99225 100644 --- a/src/ledger/LedgerEntryScope.cpp +++ b/src/ledger/LedgerEntryScope.cpp @@ -3,8 +3,7 @@ // of this distribution or at http://www.apache.org/licenses/LICENSE-2.0 #include "ledger/LedgerEntryScope.h" -#include "ledger/LedgerHashUtils.h" -#include "util/types.h" +#include "util/XDROperators.h" #include "xdr/Stellar-ledger-entries.h" #include #include diff --git a/src/ledger/LedgerHeaderUtils.h b/src/ledger/LedgerHeaderUtils.h index 3ab4e4f469..a7e19f069b 100644 --- a/src/ledger/LedgerHeaderUtils.h +++ b/src/ledger/LedgerHeaderUtils.h @@ -5,12 +5,22 @@ #pragma once #include "xdr/Stellar-ledger.h" +#include +#include + +namespace soci +{ +class session; +} namespace stellar { class Database; class SessionWrapper; +class Database; +class SessionWrapper; + namespace LedgerHeaderUtils { diff --git a/src/ledger/LedgerManagerImpl.cpp b/src/ledger/LedgerManagerImpl.cpp index 8b5fddc220..635012a85c 100644 --- a/src/ledger/LedgerManagerImpl.cpp +++ b/src/ledger/LedgerManagerImpl.cpp @@ -63,7 +63,6 @@ #ifdef BUILD_TESTS #include "test/TxTests.h" #endif -#include "xdr/Stellar-ledger-entries.h" #include "xdr/Stellar-ledger.h" #include "xdr/Stellar-transaction.h" #include "xdrpp/types.h" diff --git a/src/ledger/LedgerRange.cpp b/src/ledger/LedgerRange.cpp index 5a203f07f2..88b36dc786 100644 --- a/src/ledger/LedgerRange.cpp +++ b/src/ledger/LedgerRange.cpp @@ -6,6 +6,8 @@ #include "util/GlobalChecks.h" #include +#include +#include namespace stellar { @@ -16,6 +18,26 @@ LedgerRange::LedgerRange(uint32_t first, uint32_t count) releaseAssert(count == 0 || mFirst > 0); } +LedgerRange +LedgerRange::inclusive(uint32_t first, uint32_t last) +{ + // LedgerRange is half-open: in exchange for being able to represent + // empty ranges, it can't represent ranges that include UINT32_MAX. + releaseAssert(last < std::numeric_limits::max()); + return LedgerRange(first, last - first + 1); +} + +uint32_t +LedgerRange::last() const +{ + if (mCount == 0) + { + throw std::logic_error("last() cannot be called on " + "LedgerRange when mCount == 0"); + } + return limit() - 1; +} + std::string LedgerRange::toString() const { diff --git a/src/ledger/LedgerRange.h b/src/ledger/LedgerRange.h index fd4f06422e..6354a75a23 100644 --- a/src/ledger/LedgerRange.h +++ b/src/ledger/LedgerRange.h @@ -4,11 +4,9 @@ #pragma once -#include "util/GlobalChecks.h" #include "xdr/Stellar-types.h" #include #include -#include namespace stellar { @@ -25,14 +23,7 @@ struct LedgerRange final uint32_t const mCount; LedgerRange(uint32_t first, uint32_t count); - static LedgerRange - inclusive(uint32_t first, uint32_t last) - { - // LedgerRange is half-open: in exchange for being able to represent - // empty ranges, it can't represent ranges that include UINT32_MAX. - releaseAssert(last < std::numeric_limits::max()); - return LedgerRange(first, last - first + 1); - } + static LedgerRange inclusive(uint32_t first, uint32_t last); std::string toString() const; // Return first+count, which is the _exclusive_ range limit. @@ -45,16 +36,7 @@ struct LedgerRange final // Return first+count-1 unless count == 0, in which case throw. // This is the _inclusive_ range limit, meaningful iff count != 0. - uint32_t - last() const - { - if (mCount == 0) - { - throw std::logic_error("last() cannot be called on " - "LedgerRange when mCount == 0"); - } - return limit() - 1; - } + uint32_t last() const; friend bool operator==(LedgerRange const& x, LedgerRange const& y); friend bool operator!=(LedgerRange const& x, LedgerRange const& y); diff --git a/src/ledger/LedgerStateSnapshot.cpp b/src/ledger/LedgerStateSnapshot.cpp index c1a78b9ef2..5c81a2010d 100644 --- a/src/ledger/LedgerStateSnapshot.cpp +++ b/src/ledger/LedgerStateSnapshot.cpp @@ -3,7 +3,6 @@ // of this distribution or at http://www.apache.org/licenses/LICENSE-2.0 #include "ledger/LedgerStateSnapshot.h" -#include "bucket/BucketManager.h" #include "bucket/BucketSnapshotManager.h" #include "ledger/LedgerManager.h" #include "ledger/LedgerTxn.h" diff --git a/src/ledger/LedgerTxn.cpp b/src/ledger/LedgerTxn.cpp index f28eafe5fb..fef0de33b8 100644 --- a/src/ledger/LedgerTxn.cpp +++ b/src/ledger/LedgerTxn.cpp @@ -8,7 +8,6 @@ #include "crypto/KeyUtils.h" #include "database/Database.h" #include "ledger/InMemorySorobanState.h" -#include "ledger/LedgerManager.h" #include "ledger/LedgerRange.h" #include "ledger/LedgerTxnEntry.h" #include "ledger/LedgerTxnHeader.h" diff --git a/src/ledger/LedgerTxnEntry.cpp b/src/ledger/LedgerTxnEntry.cpp index efb1d34259..473e88b470 100644 --- a/src/ledger/LedgerTxnEntry.cpp +++ b/src/ledger/LedgerTxnEntry.cpp @@ -5,9 +5,6 @@ #include "ledger/LedgerTxnEntry.h" #include "ledger/InternalLedgerEntry.h" #include "ledger/LedgerTxn.h" -#include "util/XDROperators.h" -#include "util/types.h" -#include "xdr/Stellar-ledger-entries.h" namespace stellar { diff --git a/src/ledger/LedgerTxnOfferSQL.cpp b/src/ledger/LedgerTxnOfferSQL.cpp index 0c400e97c8..86a7aed2a6 100644 --- a/src/ledger/LedgerTxnOfferSQL.cpp +++ b/src/ledger/LedgerTxnOfferSQL.cpp @@ -10,7 +10,6 @@ #include "ledger/LedgerTypeUtils.h" #include "main/Application.h" #include "main/Config.h" -#include "transactions/TransactionUtils.h" #include "util/Decoder.h" #include "util/GlobalChecks.h" #include "util/Logging.h" diff --git a/src/ledger/LedgerTypeUtils.cpp b/src/ledger/LedgerTypeUtils.cpp index 8d8e3b286e..c9acc1a050 100644 --- a/src/ledger/LedgerTypeUtils.cpp +++ b/src/ledger/LedgerTypeUtils.cpp @@ -8,8 +8,6 @@ #include "rust/RustBridge.h" #include "util/GlobalChecks.h" #include "util/types.h" -#include "xdr/Stellar-types.h" -#include namespace stellar { diff --git a/src/ledger/NetworkConfig.cpp b/src/ledger/NetworkConfig.cpp index f127ea2dc2..0d8ce7afd3 100644 --- a/src/ledger/NetworkConfig.cpp +++ b/src/ledger/NetworkConfig.cpp @@ -5,7 +5,6 @@ #include "ledger/NetworkConfig.h" #include "bucket/BucketManager.h" #include "bucket/LiveBucketList.h" -#include "bucket/test/BucketTestUtils.h" #include "ledger/LedgerStateSnapshot.h" #include "main/Application.h" #include "util/ProtocolVersion.h" diff --git a/src/ledger/NetworkConfig.h b/src/ledger/NetworkConfig.h index 0999d57311..402f3b33ef 100644 --- a/src/ledger/NetworkConfig.h +++ b/src/ledger/NetworkConfig.h @@ -5,11 +5,9 @@ #pragma once #include "ledger/LedgerTxn.h" -#include "main/Config.h" #include "rust/RustBridge.h" #include "util/TxResource.h" #include -#include namespace stellar { diff --git a/src/ledger/P23HotArchiveBug.cpp b/src/ledger/P23HotArchiveBug.cpp index 6a6d66f09a..bd776b5893 100644 --- a/src/ledger/P23HotArchiveBug.cpp +++ b/src/ledger/P23HotArchiveBug.cpp @@ -12,7 +12,6 @@ #include "bucket/BucketUtils.h" #include "ledger/LedgerTxn.h" #include "ledger/LedgerTxnImpl.h" -#include "ledger/LedgerTypeUtils.h" #include "main/AppConnector.h" #include "main/Application.h" #include diff --git a/src/main/ApplicationImpl.cpp b/src/main/ApplicationImpl.cpp index 4c6529048b..8f2279d3b2 100644 --- a/src/main/ApplicationImpl.cpp +++ b/src/main/ApplicationImpl.cpp @@ -5,6 +5,7 @@ #include "ApplicationImpl.h" #include "util/Fs.h" #include "work/ConditionalWork.h" +#include "work/WorkSequence.h" #include "work/WorkWithCallback.h" #include "xdr/Stellar-ledger-entries.h" #include diff --git a/src/overlay/OverlayManager.h b/src/overlay/OverlayManager.h index bd2f453799..fa01e6b54f 100644 --- a/src/overlay/OverlayManager.h +++ b/src/overlay/OverlayManager.h @@ -4,7 +4,6 @@ #pragma once -#include "crypto/BLAKE2.h" #include "overlay/Peer.h" /** @@ -86,11 +85,7 @@ class OverlayManager // fills msgID with msg's hash virtual bool recvFloodedMsgID(Peer::pointer peer, Hash const& msgID) = 0; - bool - recvFloodedMsg(StellarMessage const& msg, Peer::pointer peer) - { - return recvFloodedMsgID(peer, xdrBlake2(msg)); - } + bool recvFloodedMsg(StellarMessage const& msg, Peer::pointer peer); // Process incoming transaction, pass it down to the transaction queue virtual void recvTransaction(TransactionFrameBasePtr transaction, diff --git a/src/overlay/OverlayManagerImpl.cpp b/src/overlay/OverlayManagerImpl.cpp index 3cf558029e..2efc1e405b 100644 --- a/src/overlay/OverlayManagerImpl.cpp +++ b/src/overlay/OverlayManagerImpl.cpp @@ -4,12 +4,12 @@ #include "overlay/OverlayManagerImpl.h" #include "bucket/BucketManager.h" +#include "crypto/BLAKE2.h" #include "crypto/Hex.h" #include "crypto/SecretKey.h" #include "crypto/ShortHash.h" #include "database/Database.h" #include "herder/Herder.h" -#include "ledger/LedgerManager.h" #include "lib/util/finally.h" #include "lib/util/stdrandom.h" #include "main/Application.h" @@ -20,6 +20,7 @@ #include "overlay/PeerManager.h" #include "overlay/RandomPeerSource.h" #include "overlay/SurveyDataManager.h" +#include "overlay/SurveyManager.h" #include "overlay/TCPPeer.h" #include "overlay/TxDemandsManager.h" #include "util/GlobalChecks.h" @@ -1116,6 +1117,12 @@ OverlayManager::createTxBatch() return msg; } +bool +OverlayManager::recvFloodedMsg(StellarMessage const& msg, Peer::pointer peer) +{ + return recvFloodedMsgID(peer, xdrBlake2(msg)); +} + bool OverlayManager::isFloodMessage(StellarMessage const& msg) { diff --git a/src/overlay/OverlayManagerImpl.h b/src/overlay/OverlayManagerImpl.h index 3a62ddd45e..a2e729b345 100644 --- a/src/overlay/OverlayManagerImpl.h +++ b/src/overlay/OverlayManagerImpl.h @@ -8,12 +8,9 @@ #include "PeerAuth.h" #include "PeerDoor.h" #include "PeerManager.h" -#include "herder/TxSetFrame.h" -#include "ledger/LedgerTxn.h" #include "overlay/Floodgate.h" #include "overlay/OverlayManager.h" #include "overlay/OverlayMetrics.h" -#include "overlay/SurveyManager.h" #include "overlay/TxDemandsManager.h" #include "util/Timer.h" @@ -35,6 +32,8 @@ Maintain the set of peers we are connected to namespace stellar { +class SurveyManager; + class OverlayManagerImpl : public OverlayManager { protected: diff --git a/src/overlay/Peer.h b/src/overlay/Peer.h index fcba076869..d161c6abba 100644 --- a/src/overlay/Peer.h +++ b/src/overlay/Peer.h @@ -5,7 +5,6 @@ #pragma once #include "util/asio.h" // IWYU pragma: keep -#include "database/Database.h" #include "lib/json/json.h" #include "main/AppConnector.h" #include "medida/timer.h" @@ -16,7 +15,6 @@ #include "util/ThreadAnnotations.h" #include "util/Timer.h" #include "xdrpp/message.h" -#include namespace stellar { diff --git a/src/overlay/PeerManager.cpp b/src/overlay/PeerManager.cpp index f204a5beb8..cc2aa2cfb4 100644 --- a/src/overlay/PeerManager.cpp +++ b/src/overlay/PeerManager.cpp @@ -13,7 +13,6 @@ #include #include -#include #include #include #include diff --git a/src/overlay/SurveyDataManager.cpp b/src/overlay/SurveyDataManager.cpp index 67ffa0ce2b..a73fbdab97 100644 --- a/src/overlay/SurveyDataManager.cpp +++ b/src/overlay/SurveyDataManager.cpp @@ -3,8 +3,6 @@ // of this distribution or at http://www.apache.org/licenses/LICENSE-2.0 #include "overlay/SurveyDataManager.h" - -#include "crypto/SecretKey.h" #include "overlay/OverlayUtils.h" #include "overlay/Peer.h" #include "util/Logging.h" diff --git a/src/overlay/SurveyDataManager.h b/src/overlay/SurveyDataManager.h index 99f40b9d55..d45f7d9e2a 100644 --- a/src/overlay/SurveyDataManager.h +++ b/src/overlay/SurveyDataManager.h @@ -16,7 +16,6 @@ #include "xdr/Stellar-types.h" #include -#include #include #include diff --git a/src/overlay/SurveyManager.cpp b/src/overlay/SurveyManager.cpp index 1933ef2239..873f81085b 100644 --- a/src/overlay/SurveyManager.cpp +++ b/src/overlay/SurveyManager.cpp @@ -5,7 +5,6 @@ #include "SurveyManager.h" #include "crypto/Curve25519.h" #include "herder/Herder.h" -#include "ledger/LedgerManager.h" #include "main/Application.h" #include "main/ErrorMessages.h" #include "overlay/OverlayManager.h" diff --git a/src/overlay/TCPPeer.cpp b/src/overlay/TCPPeer.cpp index fd33d85ef1..712068e0a1 100644 --- a/src/overlay/TCPPeer.cpp +++ b/src/overlay/TCPPeer.cpp @@ -7,7 +7,6 @@ #include "database/Database.h" #include "main/Application.h" #include "main/Config.h" -#include "main/ErrorMessages.h" #include "medida/meter.h" #include "overlay/FlowControl.h" #include "overlay/OverlayManager.h" diff --git a/src/overlay/TCPPeer.h b/src/overlay/TCPPeer.h index 14755665f9..4acd8eb90c 100644 --- a/src/overlay/TCPPeer.h +++ b/src/overlay/TCPPeer.h @@ -5,7 +5,6 @@ #pragma once #include "overlay/Peer.h" -#include "util/Timer.h" #include namespace medida diff --git a/src/overlay/TxAdverts.h b/src/overlay/TxAdverts.h index 166946a4d7..78a8aad919 100644 --- a/src/overlay/TxAdverts.h +++ b/src/overlay/TxAdverts.h @@ -6,7 +6,10 @@ #include "util/HashOfHash.h" // IWYU pragma: keep #include "util/RandomEvictionCache.h" +#include "util/Timer.h" #include "xdr/Stellar-overlay.h" +#include +#include #include namespace stellar diff --git a/src/overlay/test/ItemFetcherTests.cpp b/src/overlay/test/ItemFetcherTests.cpp index 908f6e27c4..150628fbc4 100644 --- a/src/overlay/test/ItemFetcherTests.cpp +++ b/src/overlay/test/ItemFetcherTests.cpp @@ -3,6 +3,7 @@ // of this distribution or at http://www.apache.org/licenses/LICENSE-2.0 #include "util/asio.h" +#include "crypto/BLAKE2.h" #include "crypto/Hex.h" #include "crypto/SHA.h" #include "herder/Herder.h" diff --git a/src/simulation/Simulation.cpp b/src/simulation/Simulation.cpp index 98736d72fc..5cbd5a4430 100644 --- a/src/simulation/Simulation.cpp +++ b/src/simulation/Simulation.cpp @@ -9,6 +9,7 @@ #include "main/Application.h" #include "overlay/OverlayManager.h" #include "overlay/PeerManager.h" +#include "overlay/SurveyManager.h" #include "scp/LocalNode.h" #include "test/TestUtils.h" #include "test/test.h" diff --git a/src/transactions/AllowTrustOpFrame.cpp b/src/transactions/AllowTrustOpFrame.cpp index 22d2c3c932..2042f859f7 100644 --- a/src/transactions/AllowTrustOpFrame.cpp +++ b/src/transactions/AllowTrustOpFrame.cpp @@ -3,13 +3,9 @@ // of this distribution or at http://www.apache.org/licenses/LICENSE-2.0 #include "transactions/AllowTrustOpFrame.h" -#include "database/Database.h" -#include "ledger/LedgerManager.h" #include "ledger/LedgerTxn.h" #include "ledger/LedgerTxnEntry.h" #include "ledger/LedgerTxnHeader.h" -#include "ledger/TrustLineWrapper.h" -#include "main/Application.h" #include "transactions/TransactionUtils.h" #include "util/ProtocolVersion.h" #include diff --git a/src/transactions/BeginSponsoringFutureReservesOpFrame.cpp b/src/transactions/BeginSponsoringFutureReservesOpFrame.cpp index 328b66a03e..f7a75f8b55 100644 --- a/src/transactions/BeginSponsoringFutureReservesOpFrame.cpp +++ b/src/transactions/BeginSponsoringFutureReservesOpFrame.cpp @@ -5,7 +5,6 @@ #include "transactions/BeginSponsoringFutureReservesOpFrame.h" #include "ledger/InternalLedgerEntry.h" #include "ledger/LedgerTxn.h" -#include "ledger/LedgerTxnEntry.h" #include "transactions/TransactionUtils.h" #include "util/ProtocolVersion.h" #include diff --git a/src/transactions/BumpSequenceOpFrame.cpp b/src/transactions/BumpSequenceOpFrame.cpp index 140202afce..265ae99abc 100644 --- a/src/transactions/BumpSequenceOpFrame.cpp +++ b/src/transactions/BumpSequenceOpFrame.cpp @@ -3,13 +3,8 @@ // of this distribution or at http://www.apache.org/licenses/LICENSE-2.0 #include "transactions/BumpSequenceOpFrame.h" -#include "crypto/SignerKey.h" -#include "database/Database.h" -#include "main/Application.h" -#include "transactions/TransactionFrame.h" #include "transactions/TransactionUtils.h" #include "util/ProtocolVersion.h" -#include "util/XDROperators.h" #include namespace stellar diff --git a/src/transactions/BumpSequenceOpFrame.h b/src/transactions/BumpSequenceOpFrame.h index beddc077fa..86b50d1c1c 100644 --- a/src/transactions/BumpSequenceOpFrame.h +++ b/src/transactions/BumpSequenceOpFrame.h @@ -4,9 +4,6 @@ #pragma once -#include "ledger/LedgerTxn.h" -#include "ledger/LedgerTxnEntry.h" -#include "ledger/LedgerTxnHeader.h" #include "transactions/OperationFrame.h" namespace stellar diff --git a/src/transactions/ChangeTrustOpFrame.cpp b/src/transactions/ChangeTrustOpFrame.cpp index b9482a33ba..988bbcbdf3 100644 --- a/src/transactions/ChangeTrustOpFrame.cpp +++ b/src/transactions/ChangeTrustOpFrame.cpp @@ -3,13 +3,9 @@ // of this distribution or at http://www.apache.org/licenses/LICENSE-2.0 #include "ChangeTrustOpFrame.h" -#include "database/Database.h" -#include "ledger/LedgerManager.h" #include "ledger/LedgerTxn.h" #include "ledger/LedgerTxnEntry.h" #include "ledger/LedgerTxnHeader.h" -#include "ledger/TrustLineWrapper.h" -#include "main/Application.h" #include "transactions/SponsorshipUtils.h" #include "transactions/TransactionUtils.h" #include "util/ProtocolVersion.h" diff --git a/src/transactions/ClaimClaimableBalanceOpFrame.cpp b/src/transactions/ClaimClaimableBalanceOpFrame.cpp index fec0d4c458..8297ced7d7 100644 --- a/src/transactions/ClaimClaimableBalanceOpFrame.cpp +++ b/src/transactions/ClaimClaimableBalanceOpFrame.cpp @@ -3,7 +3,6 @@ // of this distribution or at http://www.apache.org/licenses/LICENSE-2.0 #include "transactions/ClaimClaimableBalanceOpFrame.h" -#include "crypto/SHA.h" #include "ledger/LedgerTxn.h" #include "ledger/LedgerTxnEntry.h" #include "ledger/LedgerTxnHeader.h" diff --git a/src/transactions/CreateAccountOpFrame.cpp b/src/transactions/CreateAccountOpFrame.cpp index b8f38af991..7ca7a1b545 100644 --- a/src/transactions/CreateAccountOpFrame.cpp +++ b/src/transactions/CreateAccountOpFrame.cpp @@ -2,23 +2,15 @@ // 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 "util/asio.h" #include "transactions/CreateAccountOpFrame.h" -#include "OfferExchange.h" -#include "database/Database.h" #include "ledger/LedgerTxn.h" #include "ledger/LedgerTxnEntry.h" #include "ledger/LedgerTxnHeader.h" #include "transactions/SponsorshipUtils.h" #include "transactions/TransactionUtils.h" #include "util/GlobalChecks.h" -#include "util/Logging.h" #include "util/ProtocolVersion.h" -#include "util/XDROperators.h" #include -#include - -#include "main/Application.h" namespace stellar { diff --git a/src/transactions/CreateClaimableBalanceOpFrame.cpp b/src/transactions/CreateClaimableBalanceOpFrame.cpp index cf6953017a..e63274b63e 100644 --- a/src/transactions/CreateClaimableBalanceOpFrame.cpp +++ b/src/transactions/CreateClaimableBalanceOpFrame.cpp @@ -9,6 +9,7 @@ #include "ledger/LedgerTxnHeader.h" #include "ledger/TrustLineWrapper.h" #include "transactions/SponsorshipUtils.h" +#include "transactions/TransactionFrame.h" #include "transactions/TransactionUtils.h" #include "util/GlobalChecks.h" #include "util/ProtocolVersion.h" diff --git a/src/transactions/EndSponsoringFutureReservesOpFrame.cpp b/src/transactions/EndSponsoringFutureReservesOpFrame.cpp index 3664ea96b8..3b316f266f 100644 --- a/src/transactions/EndSponsoringFutureReservesOpFrame.cpp +++ b/src/transactions/EndSponsoringFutureReservesOpFrame.cpp @@ -4,7 +4,6 @@ #include "transactions/EndSponsoringFutureReservesOpFrame.h" #include "ledger/LedgerTxn.h" -#include "ledger/LedgerTxnEntry.h" #include "transactions/TransactionUtils.h" #include "util/ProtocolVersion.h" #include diff --git a/src/transactions/ExtendFootprintTTLOpFrame.cpp b/src/transactions/ExtendFootprintTTLOpFrame.cpp index b671bbdd6f..51c120a2f9 100644 --- a/src/transactions/ExtendFootprintTTLOpFrame.cpp +++ b/src/transactions/ExtendFootprintTTLOpFrame.cpp @@ -4,7 +4,6 @@ #include "transactions/ExtendFootprintTTLOpFrame.h" #include "TransactionUtils.h" -#include "ledger/LedgerEntryScope.h" #include "ledger/LedgerManagerImpl.h" #include "ledger/LedgerTypeUtils.h" #include "medida/meter.h" diff --git a/src/transactions/FeeBumpTransactionFrame.cpp b/src/transactions/FeeBumpTransactionFrame.cpp index cdc038333b..59a58921c7 100644 --- a/src/transactions/FeeBumpTransactionFrame.cpp +++ b/src/transactions/FeeBumpTransactionFrame.cpp @@ -3,16 +3,13 @@ // of this distribution or at http://www.apache.org/licenses/LICENSE-2.0 #include "transactions/FeeBumpTransactionFrame.h" -#include "crypto/Hex.h" #include "crypto/SHA.h" #include "crypto/SignerKey.h" #include "crypto/SignerKeyUtils.h" -#include "ledger/LedgerManager.h" #include "ledger/LedgerTxn.h" #include "ledger/LedgerTxnEntry.h" #include "ledger/LedgerTxnHeader.h" #include "main/AppConnector.h" -#include "main/Application.h" #include "transactions/EventManager.h" #include "transactions/MutableTransactionResult.h" #include "transactions/SignatureChecker.h" @@ -26,8 +23,6 @@ #include "xdrpp/depth_checker.h" #include "xdrpp/marshal.h" -#include - namespace stellar { diff --git a/src/transactions/FeeBumpTransactionFrame.h b/src/transactions/FeeBumpTransactionFrame.h index a4cd0feeec..ee6efd1a84 100644 --- a/src/transactions/FeeBumpTransactionFrame.h +++ b/src/transactions/FeeBumpTransactionFrame.h @@ -4,7 +4,6 @@ #pragma once -#include "transactions/ParallelApplyUtils.h" #include "transactions/TransactionFrame.h" #include "transactions/TransactionMeta.h" diff --git a/src/transactions/InflationOpFrame.cpp b/src/transactions/InflationOpFrame.cpp index 37639b1eec..82ecdd7167 100644 --- a/src/transactions/InflationOpFrame.cpp +++ b/src/transactions/InflationOpFrame.cpp @@ -3,12 +3,9 @@ // of this distribution or at http://www.apache.org/licenses/LICENSE-2.0 #include "transactions/InflationOpFrame.h" -#include "ledger/LedgerManager.h" #include "ledger/LedgerTxn.h" #include "ledger/LedgerTxnEntry.h" #include "ledger/LedgerTxnHeader.h" -#include "main/Application.h" -#include "overlay/StellarXDR.h" #include "transactions/TransactionUtils.h" #include "util/ProtocolVersion.h" diff --git a/src/transactions/LumenEventReconciler.cpp b/src/transactions/LumenEventReconciler.cpp index 8e0639defd..75004f4b59 100644 --- a/src/transactions/LumenEventReconciler.cpp +++ b/src/transactions/LumenEventReconciler.cpp @@ -5,7 +5,6 @@ #include "transactions/LumenEventReconciler.h" #include "ledger/LedgerTxn.h" #include "transactions/TransactionUtils.h" -#include "util/Logging.h" #include namespace stellar diff --git a/src/transactions/LumenEventReconciler.h b/src/transactions/LumenEventReconciler.h index 2fe9bbb70f..7724d89191 100644 --- a/src/transactions/LumenEventReconciler.h +++ b/src/transactions/LumenEventReconciler.h @@ -4,15 +4,14 @@ #pragma once -#include "ledger/LedgerTxn.h" #include "transactions/EventManager.h" -#include "xdr/Stellar-ledger.h" #include "xdr/Stellar-transaction.h" -#include namespace stellar { +struct LedgerTxnDelta; + // This method is for handling a pre-protocol 8 bug where XLM could be minted or // burned. It will add additional events to reflect the actual behaviour of the // protocol then. diff --git a/src/transactions/ManageDataOpFrame.cpp b/src/transactions/ManageDataOpFrame.cpp index 7c8c6076e0..27bda4f8c5 100644 --- a/src/transactions/ManageDataOpFrame.cpp +++ b/src/transactions/ManageDataOpFrame.cpp @@ -2,18 +2,13 @@ // 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 "util/asio.h" #include "transactions/ManageDataOpFrame.h" -#include "database/Database.h" #include "ledger/LedgerTxn.h" #include "ledger/LedgerTxnEntry.h" #include "ledger/LedgerTxnHeader.h" -#include "main/Application.h" #include "transactions/SponsorshipUtils.h" #include "transactions/TransactionUtils.h" -#include "util/Logging.h" #include "util/ProtocolVersion.h" -#include "util/XDROperators.h" #include "util/types.h" #include diff --git a/src/transactions/ManageSellOfferOpFrame.cpp b/src/transactions/ManageSellOfferOpFrame.cpp index aeee3e96a0..26bc11058e 100644 --- a/src/transactions/ManageSellOfferOpFrame.cpp +++ b/src/transactions/ManageSellOfferOpFrame.cpp @@ -2,19 +2,9 @@ // 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 "util/asio.h" #include "transactions/ManageSellOfferOpFrame.h" #include "OfferExchange.h" -#include "database/Database.h" -#include "ledger/LedgerTxn.h" -#include "ledger/LedgerTxnEntry.h" -#include "ledger/LedgerTxnHeader.h" -#include "ledger/TrustLineWrapper.h" -#include "main/Application.h" #include "transactions/TransactionUtils.h" -#include "util/Logging.h" -#include "util/XDROperators.h" -#include "util/types.h" // convert from sheep to wheat // selling sheep diff --git a/src/transactions/MergeOpFrame.cpp b/src/transactions/MergeOpFrame.cpp index 55e7820298..5fddd9e8a1 100644 --- a/src/transactions/MergeOpFrame.cpp +++ b/src/transactions/MergeOpFrame.cpp @@ -3,20 +3,14 @@ // of this distribution or at http://www.apache.org/licenses/LICENSE-2.0 #include "transactions/MergeOpFrame.h" -#include "database/Database.h" #include "ledger/LedgerTxn.h" #include "ledger/LedgerTxnEntry.h" #include "ledger/LedgerTxnHeader.h" -#include "main/Application.h" #include "transactions/SponsorshipUtils.h" #include "transactions/TransactionUtils.h" -#include "util/Logging.h" #include "util/ProtocolVersion.h" -#include "util/XDROperators.h" #include -using namespace soci; - namespace stellar { diff --git a/src/transactions/MutableTransactionResult.cpp b/src/transactions/MutableTransactionResult.cpp index 368efee7a2..178d7470c3 100644 --- a/src/transactions/MutableTransactionResult.cpp +++ b/src/transactions/MutableTransactionResult.cpp @@ -6,9 +6,6 @@ #include "transactions/OperationFrame.h" #include "transactions/TransactionFrame.h" #include "transactions/TransactionUtils.h" -#include "xdr/Stellar-transaction.h" - -#include "MutableTransactionResult.h" #include namespace stellar diff --git a/src/transactions/MutableTransactionResult.h b/src/transactions/MutableTransactionResult.h index 2882fbc54f..79bbe57a5a 100644 --- a/src/transactions/MutableTransactionResult.h +++ b/src/transactions/MutableTransactionResult.h @@ -5,13 +5,15 @@ #pragma once #include "transactions/EventManager.h" -#include "transactions/TransactionFrame.h" #include namespace stellar { +class SorobanNetworkConfig; +class TransactionFrame; + // This class tracks the refundable resources and corresponding fees for a // transaction. // This can not be instantiated directly and is only accessible through diff --git a/src/transactions/OfferExchange.cpp b/src/transactions/OfferExchange.cpp index ce514622e3..f05ffe77ed 100644 --- a/src/transactions/OfferExchange.cpp +++ b/src/transactions/OfferExchange.cpp @@ -4,8 +4,6 @@ #include "OfferExchange.h" #include "crypto/SHA.h" -#include "database/Database.h" -#include "ledger/LedgerManager.h" #include "ledger/LedgerTxn.h" #include "ledger/LedgerTxnEntry.h" #include "ledger/LedgerTxnHeader.h" diff --git a/src/transactions/OfferExchange.h b/src/transactions/OfferExchange.h index a3ebc13249..038e8cf838 100644 --- a/src/transactions/OfferExchange.h +++ b/src/transactions/OfferExchange.h @@ -4,7 +4,7 @@ #pragma once -#include "transactions/OperationFrame.h" +#include "overlay/StellarXDR.h" #include #include diff --git a/src/transactions/OperationFrame.cpp b/src/transactions/OperationFrame.cpp index c883ec1aea..59a39eb529 100644 --- a/src/transactions/OperationFrame.cpp +++ b/src/transactions/OperationFrame.cpp @@ -3,7 +3,6 @@ // of this distribution or at http://www.apache.org/licenses/LICENSE-2.0 #include "transactions/OperationFrame.h" -#include "ledger/LedgerTypeUtils.h" #include "transactions/AllowTrustOpFrame.h" #include "transactions/BeginSponsoringFutureReservesOpFrame.h" #include "transactions/BumpSequenceOpFrame.h" diff --git a/src/transactions/OperationFrame.h b/src/transactions/OperationFrame.h index a97cfed47b..421bbddbb1 100644 --- a/src/transactions/OperationFrame.h +++ b/src/transactions/OperationFrame.h @@ -5,18 +5,15 @@ #pragma once #include "ledger/LedgerHashUtils.h" -#include "ledger/LedgerManager.h" #include "ledger/NetworkConfig.h" #include "main/AppConnector.h" #include "overlay/StellarXDR.h" #include "transactions/ParallelApplyUtils.h" -#include "util/types.h" #include namespace stellar { class AbstractLedgerTxn; -class LedgerManager; class LedgerTxnEntry; class LedgerTxnHeader; diff --git a/src/transactions/ParallelApplyStage.h b/src/transactions/ParallelApplyStage.h index 4760384637..199831867c 100644 --- a/src/transactions/ParallelApplyStage.h +++ b/src/transactions/ParallelApplyStage.h @@ -5,6 +5,7 @@ #pragma once #include "ledger/LedgerTxn.h" +#include "transactions/TransactionFrameBase.h" #include "transactions/TransactionMeta.h" namespace stellar diff --git a/src/transactions/PathPaymentOpFrameBase.cpp b/src/transactions/PathPaymentOpFrameBase.cpp index a201daf683..9dae19bb7d 100644 --- a/src/transactions/PathPaymentOpFrameBase.cpp +++ b/src/transactions/PathPaymentOpFrameBase.cpp @@ -10,7 +10,6 @@ #include "transactions/TransactionUtils.h" #include "util/GlobalChecks.h" #include "util/ProtocolVersion.h" -#include "util/XDROperators.h" namespace stellar { diff --git a/src/transactions/PaymentOpFrame.cpp b/src/transactions/PaymentOpFrame.cpp index bf1e852ff0..3b9c6a7dfa 100644 --- a/src/transactions/PaymentOpFrame.cpp +++ b/src/transactions/PaymentOpFrame.cpp @@ -2,7 +2,6 @@ // 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 "util/asio.h" #include "transactions/PaymentOpFrame.h" #include "ledger/LedgerTxn.h" #include "ledger/LedgerTxnEntry.h" diff --git a/src/transactions/SetOptionsOpFrame.cpp b/src/transactions/SetOptionsOpFrame.cpp index f3089e5f12..973b6e5682 100644 --- a/src/transactions/SetOptionsOpFrame.cpp +++ b/src/transactions/SetOptionsOpFrame.cpp @@ -4,15 +4,12 @@ #include "transactions/SetOptionsOpFrame.h" #include "crypto/SignerKey.h" -#include "database/Database.h" #include "ledger/LedgerTxn.h" #include "ledger/LedgerTxnEntry.h" #include "ledger/LedgerTxnHeader.h" -#include "main/Application.h" #include "transactions/SponsorshipUtils.h" #include "transactions/TransactionUtils.h" #include "util/ProtocolVersion.h" -#include "util/XDROperators.h" #include namespace stellar diff --git a/src/transactions/SetTrustLineFlagsOpFrame.cpp b/src/transactions/SetTrustLineFlagsOpFrame.cpp index 41256ac282..d200d198c6 100644 --- a/src/transactions/SetTrustLineFlagsOpFrame.cpp +++ b/src/transactions/SetTrustLineFlagsOpFrame.cpp @@ -6,7 +6,6 @@ #include "ledger/LedgerTxn.h" #include "ledger/LedgerTxnEntry.h" #include "ledger/LedgerTxnHeader.h" -#include "main/Application.h" #include "transactions/TransactionUtils.h" #include "util/ProtocolVersion.h" #include diff --git a/src/transactions/SponsorshipUtils.cpp b/src/transactions/SponsorshipUtils.cpp index 352ddfdb8a..e13fd92555 100644 --- a/src/transactions/SponsorshipUtils.cpp +++ b/src/transactions/SponsorshipUtils.cpp @@ -6,12 +6,10 @@ #include "ledger/LedgerTxn.h" #include "ledger/LedgerTxnEntry.h" #include "ledger/LedgerTxnHeader.h" -#include "overlay/StellarXDR.h" #include "transactions/TransactionUtils.h" #include "util/ProtocolVersion.h" #include "util/XDROperators.h" #include "util/types.h" -#include "xdr/Stellar-ledger-entries.h" using namespace stellar; diff --git a/src/transactions/TransactionFrame.cpp b/src/transactions/TransactionFrame.cpp index ac72451617..be24d200a6 100644 --- a/src/transactions/TransactionFrame.cpp +++ b/src/transactions/TransactionFrame.cpp @@ -2,26 +2,21 @@ // 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 "util/asio.h" #include "TransactionFrame.h" #include "OperationFrame.h" #include "crypto/Hex.h" #include "crypto/SHA.h" #include "crypto/SignerKey.h" #include "crypto/SignerKeyUtils.h" -#include "database/Database.h" -#include "database/DatabaseUtils.h" -#include "herder/TxSetFrame.h" #include "invariant/InvariantDoesNotHold.h" #include "invariant/InvariantManager.h" -#include "ledger/LedgerEntryScope.h" +#include "ledger/LedgerManager.h" #include "ledger/LedgerTxn.h" #include "ledger/LedgerTxnEntry.h" #include "ledger/LedgerTxnHeader.h" #include "ledger/LedgerTypeUtils.h" #include "ledger/SorobanMetrics.h" #include "main/AppConnector.h" -#include "main/Application.h" #include "transactions/EventManager.h" #include "transactions/LumenEventReconciler.h" #include "transactions/MutableTransactionResult.h" @@ -33,15 +28,11 @@ #include "transactions/TransactionFrameBase.h" #include "transactions/TransactionMeta.h" #include "transactions/TransactionUtils.h" -#include "util/Decoder.h" #include "util/GlobalChecks.h" #include "util/Logging.h" #include "util/MetricsRegistry.h" #include "util/ProtocolVersion.h" #include "util/XDROperators.h" -#include "util/XDRStream.h" -#include "xdr/Stellar-contract.h" -#include "xdr/Stellar-ledger.h" #include "xdrpp/depth_checker.h" #include "xdrpp/marshal.h" #include "xdrpp/printer.h" diff --git a/src/transactions/TransactionFrame.h b/src/transactions/TransactionFrame.h index d619dbc970..be7ea3a1c0 100644 --- a/src/transactions/TransactionFrame.h +++ b/src/transactions/TransactionFrame.h @@ -10,9 +10,6 @@ #include "overlay/StellarXDR.h" #include "rust/RustBridge.h" #include "transactions/TransactionFrameBase.h" -#include "util/GlobalChecks.h" -#include "util/types.h" -#include "xdr/Stellar-ledger.h" #include #include diff --git a/src/transactions/TransactionFrameBase.h b/src/transactions/TransactionFrameBase.h index daad2eb950..750007ca69 100644 --- a/src/transactions/TransactionFrameBase.h +++ b/src/transactions/TransactionFrameBase.h @@ -14,8 +14,6 @@ #include "overlay/StellarXDR.h" #include "util/TxResource.h" #include "util/UnorderedSet.h" -#include "util/types.h" -#include #include "ledger/SorobanMetrics.h" diff --git a/src/transactions/TransactionUtils.cpp b/src/transactions/TransactionUtils.cpp index 64eb2afe50..9e54824947 100644 --- a/src/transactions/TransactionUtils.cpp +++ b/src/transactions/TransactionUtils.cpp @@ -5,6 +5,7 @@ #include "transactions/TransactionUtils.h" #include "crypto/SHA.h" #include "ledger/InternalLedgerEntry.h" +#include "ledger/LedgerManager.h" #include "ledger/LedgerTxn.h" #include "ledger/LedgerTxnEntry.h" #include "ledger/LedgerTxnHeader.h" diff --git a/src/transactions/TrustFlagsOpFrameBase.cpp b/src/transactions/TrustFlagsOpFrameBase.cpp index b60b1b8867..d23f1ab6e5 100644 --- a/src/transactions/TrustFlagsOpFrameBase.cpp +++ b/src/transactions/TrustFlagsOpFrameBase.cpp @@ -4,6 +4,7 @@ #include "transactions/TrustFlagsOpFrameBase.h" #include "ledger/LedgerTxn.h" +#include "transactions/TransactionFrame.h" #include "transactions/TransactionUtils.h" #include "util/ProtocolVersion.h" #include diff --git a/src/util/Backtrace.cpp b/src/util/Backtrace.cpp index 17e7ba65ee..f5726be310 100644 --- a/src/util/Backtrace.cpp +++ b/src/util/Backtrace.cpp @@ -7,7 +7,6 @@ #include "util/GlobalChecks.h" #include #include -#include namespace stellar { diff --git a/src/util/BitSet.h b/src/util/BitSet.h index 18fee11e90..ad7903795e 100644 --- a/src/util/BitSet.h +++ b/src/util/BitSet.h @@ -8,7 +8,6 @@ #include "util/Logging.h" #include -#include #include #include #include diff --git a/src/util/FileSystemException.cpp b/src/util/FileSystemException.cpp index e228c48f13..ec54ac605e 100644 --- a/src/util/FileSystemException.cpp +++ b/src/util/FileSystemException.cpp @@ -3,6 +3,9 @@ // of this distribution or at http://www.apache.org/licenses/LICENSE-2.0 #include "FileSystemException.h" +#include "util/Logging.h" +#include +#include #include #ifdef _WIN32 @@ -12,6 +15,19 @@ namespace stellar { +void +FileSystemException::failWith(std::string msg) +{ + CLOG_FATAL(Fs, "{}", msg); + throw FileSystemException(msg); +} + +void +FileSystemException::failWithErrno(std::string msg) +{ + failWith(msg + std::strerror(errno)); +} + #ifdef _WIN32 std::string diff --git a/src/util/FileSystemException.h b/src/util/FileSystemException.h index 330b17ebcd..4e41dbf410 100644 --- a/src/util/FileSystemException.h +++ b/src/util/FileSystemException.h @@ -4,10 +4,8 @@ #pragma once -#include "util/Logging.h" -#include -#include #include +#include namespace stellar { @@ -15,17 +13,8 @@ namespace stellar class FileSystemException : public std::runtime_error { public: - static void - failWith(std::string msg) - { - CLOG_FATAL(Fs, "{}", msg); - throw FileSystemException(msg); - } - static void - failWithErrno(std::string msg) - { - failWith(msg + std::strerror(errno)); - } + static void failWith(std::string msg); + static void failWithErrno(std::string msg); #ifdef _WIN32 static std::string getLastErrorString(); static void failWithGetLastError(std::string msg); diff --git a/src/util/Fs.cpp b/src/util/Fs.cpp index ada28d9ec9..bd1d085e61 100644 --- a/src/util/Fs.cpp +++ b/src/util/Fs.cpp @@ -3,7 +3,6 @@ // of this distribution or at http://www.apache.org/licenses/LICENSE-2.0 #include "util/Fs.h" -#include "crypto/Hex.h" #include "util/FileSystemException.h" #include "util/GlobalChecks.h" #include "util/Logging.h" @@ -12,7 +11,6 @@ #include #include -#include #include #include diff --git a/src/util/Fs.h b/src/util/Fs.h index 44800ea55b..8ff7f06e41 100644 --- a/src/util/Fs.h +++ b/src/util/Fs.h @@ -6,7 +6,6 @@ #include "util/asio.h" -#include #include #include #include diff --git a/src/util/GlobalChecks.cpp b/src/util/GlobalChecks.cpp index ef57118a65..6a1950b8e9 100644 --- a/src/util/GlobalChecks.cpp +++ b/src/util/GlobalChecks.cpp @@ -10,7 +10,6 @@ #endif #include #include -#include #include #include diff --git a/src/util/GlobalChecks.h b/src/util/GlobalChecks.h index 0e8b51b7b2..e145cc8300 100644 --- a/src/util/GlobalChecks.h +++ b/src/util/GlobalChecks.h @@ -6,7 +6,6 @@ #include "util/ThreadAnnotations.h" #include -#include namespace stellar { diff --git a/src/util/Math.cpp b/src/util/Math.cpp index 9bdc4f12c6..40156d4a5f 100644 --- a/src/util/Math.cpp +++ b/src/util/Math.cpp @@ -65,7 +65,7 @@ closest_cluster(double p, std::set const& centers) return bestCenter; } -VirtualClock::duration +std::chrono::steady_clock::duration exponentialBackoff(uint64_t n) { // Cap to 512 sec or ~8 minutes diff --git a/src/util/Math.h b/src/util/Math.h index 93f53bcef9..bfe4ebfc7a 100644 --- a/src/util/Math.h +++ b/src/util/Math.h @@ -5,7 +5,7 @@ #pragma once #include "lib/util/stdrandom.h" -#include "util/Timer.h" +#include #include #include #include @@ -19,7 +19,7 @@ std::set k_means(std::vector const& points, uint32_t k); double closest_cluster(double p, std::set const& centers); -VirtualClock::duration exponentialBackoff(uint64_t n); +std::chrono::steady_clock::duration exponentialBackoff(uint64_t n); bool rand_flip(); diff --git a/src/util/MetaUtils.cpp b/src/util/MetaUtils.cpp index 036765cd06..fd88e6a199 100644 --- a/src/util/MetaUtils.cpp +++ b/src/util/MetaUtils.cpp @@ -4,9 +4,7 @@ #include "util/MetaUtils.h" #include "crypto/SHA.h" -#include "overlay/StellarXDR.h" #include "util/GlobalChecks.h" -#include "util/XDROperators.h" #include "util/types.h" #include "xdr/Stellar-ledger.h" #include diff --git a/src/util/RandHasher.cpp b/src/util/RandHasher.cpp index 521fe39321..48ac76d6c8 100644 --- a/src/util/RandHasher.cpp +++ b/src/util/RandHasher.cpp @@ -4,7 +4,6 @@ #include "RandHasher.h" #include "Math.h" -#include "fmt/format.h" #include namespace stellar diff --git a/src/util/RandHasher.h b/src/util/RandHasher.h index 12656a6121..29af11939c 100644 --- a/src/util/RandHasher.h +++ b/src/util/RandHasher.h @@ -5,9 +5,7 @@ #pragma once #include "util/GlobalChecks.h" -#include "util/Math.h" #include -#include namespace stellar { diff --git a/src/util/RandomEvictionCache.h b/src/util/RandomEvictionCache.h index b503297f74..701a0951b0 100644 --- a/src/util/RandomEvictionCache.h +++ b/src/util/RandomEvictionCache.h @@ -7,7 +7,7 @@ #include "util/Math.h" #include "util/NonCopyable.h" -#include +#include #include #include diff --git a/src/util/Scheduler.h b/src/util/Scheduler.h index 7fb25aa527..c5c72e4842 100644 --- a/src/util/Scheduler.h +++ b/src/util/Scheduler.h @@ -10,7 +10,6 @@ #include #include #include -#include #include // This class implements a multi-queue scheduler for "actions" (deferred-work diff --git a/src/util/StatusManager.cpp b/src/util/StatusManager.cpp index 339c163bb3..e63ac4a150 100644 --- a/src/util/StatusManager.cpp +++ b/src/util/StatusManager.cpp @@ -4,8 +4,6 @@ #include "StatusManager.h" -#include - namespace stellar { diff --git a/src/util/Thread.h b/src/util/Thread.h index 96bf527caf..c69c5e9712 100644 --- a/src/util/Thread.h +++ b/src/util/Thread.h @@ -6,7 +6,6 @@ #include #include -#include namespace stellar { diff --git a/src/util/Timer.cpp b/src/util/Timer.cpp index 9f46b26e1e..0e4de06711 100644 --- a/src/util/Timer.cpp +++ b/src/util/Timer.cpp @@ -5,7 +5,6 @@ #include "util/Timer.h" #include "main/Application.h" #include "util/GlobalChecks.h" -#include "util/Logging.h" #include "util/Scheduler.h" #include #include diff --git a/src/util/Timer.h b/src/util/Timer.h index 8ac82fc4d9..dd7fb3e79b 100644 --- a/src/util/Timer.h +++ b/src/util/Timer.h @@ -14,7 +14,6 @@ #include #include #include -#include #include #include #include diff --git a/src/util/TmpDir.cpp b/src/util/TmpDir.cpp index 2926b913d7..0ab32f39f6 100644 --- a/src/util/TmpDir.cpp +++ b/src/util/TmpDir.cpp @@ -6,7 +6,6 @@ #include "crypto/Hex.h" #include "crypto/Random.h" #include "main/Application.h" -#include "main/Config.h" #include "util/Fs.h" #include "util/Logging.h" diff --git a/src/util/TxResource.cpp b/src/util/TxResource.cpp index 425556747e..b12c43e2b3 100644 --- a/src/util/TxResource.cpp +++ b/src/util/TxResource.cpp @@ -1,14 +1,111 @@ - // Copyright 2023 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 "util/TxResource.h" #include "util/GlobalChecks.h" +#include "util/numeric.h" +#include +#include namespace stellar { +std::string +Resource::getStringFromType(Type type) +{ + switch (type) + { + case Type::OPERATIONS: + return "Operations"; + case Type::INSTRUCTIONS: + return "Instructions"; + case Type::TX_BYTE_SIZE: + return "TxByteSize"; + case Type::DISK_READ_BYTES: + return "DiskReadBytes"; + case Type::WRITE_BYTES: + return "WriteBytes"; + case Type::READ_LEDGER_ENTRIES: + return "ReadLedgerEntries"; + case Type::WRITE_LEDGER_ENTRIES: + return "WriteLedgerEntries"; + } + return "Unknown"; +} + +Resource::Resource(std::vector args) +{ + if (args.size() != NUM_CLASSIC_TX_RESOURCES && + args.size() != NUM_SOROBAN_TX_RESOURCES && + args.size() != NUM_CLASSIC_TX_BYTES_RESOURCES) + { + throw std::runtime_error("Invalid number of resources"); + } + mResources = args; +} + +Resource::Resource(int64_t arg) +{ + mResources = std::vector(1, arg); +} + +bool +Resource::isZero() const +{ + return std::all_of(mResources.begin(), mResources.end(), + [](int64_t x) { return x == 0; }); +} + +bool +Resource::anyPositive() const +{ + return std::any_of(mResources.begin(), mResources.end(), + [](int64_t x) { return x > 0; }); +} + +size_t +Resource::size() const +{ + return mResources.size(); +} + +std::string +Resource::toString() const +{ + std::string res = ""; + for (auto const& r : mResources) + { + res += std::to_string(r) + ", "; + } + return res; +} + +Resource +Resource::makeEmptySoroban() +{ + return makeEmpty(NUM_SOROBAN_TX_RESOURCES); +} + +Resource +Resource::makeEmpty(size_t numRes) +{ + std::vector res(numRes, 0); + return Resource(res); +} + +int64_t +Resource::getVal(Resource::Type valType) const +{ + return mResources.at(static_cast(valType)); +} + +void +Resource::setVal(Resource::Type valType, int64_t val) +{ + mResources.at(static_cast(valType)) = val; +} + Resource subtractNonNegative(Resource const& lhs, Resource const& rhs) { diff --git a/src/util/TxResource.h b/src/util/TxResource.h index 52a1aa7472..edbf0695cd 100644 --- a/src/util/TxResource.h +++ b/src/util/TxResource.h @@ -5,8 +5,7 @@ #pragma once #include "util/numeric.h" -#include -#include +#include #include #include @@ -33,103 +32,24 @@ class Resource WRITE_LEDGER_ENTRIES = 6 }; - static std::string - getStringFromType(Type type) - { - switch (type) - { - case Type::OPERATIONS: - return "Operations"; - case Type::INSTRUCTIONS: - return "Instructions"; - case Type::TX_BYTE_SIZE: - return "TxByteSize"; - case Type::DISK_READ_BYTES: - return "DiskReadBytes"; - case Type::WRITE_BYTES: - return "WriteBytes"; - case Type::READ_LEDGER_ENTRIES: - return "ReadLedgerEntries"; - case Type::WRITE_LEDGER_ENTRIES: - return "WriteLedgerEntries"; - } - return "Unknown"; - } + static std::string getStringFromType(Type type); - Resource(std::vector args) - { - if (args.size() != NUM_CLASSIC_TX_RESOURCES && - args.size() != NUM_SOROBAN_TX_RESOURCES && - args.size() != NUM_CLASSIC_TX_BYTES_RESOURCES) - { - throw std::runtime_error("Invalid number of resources"); - } - mResources = args; - } + Resource(std::vector args); + Resource(int64_t arg); - Resource(int64_t arg) - { - mResources = std::vector(1, arg); - } - - bool - isZero() const - { - return std::all_of(mResources.begin(), mResources.end(), - [](int64_t x) { return x == 0; }); - } - - bool - anyPositive() const - { - return std::any_of(mResources.begin(), mResources.end(), - [](int64_t x) { return x > 0; }); - } - - size_t - size() const - { - return mResources.size(); - } - - std::string - toString() const - { - std::string res = ""; - for (auto const& r : mResources) - { - res += std::to_string(r) + ", "; - } - return res; - } + bool isZero() const; + bool anyPositive() const; + size_t size() const; + std::string toString() const; Resource& operator+=(Resource const& other); Resource& operator-=(Resource const& other); - static Resource - makeEmptySoroban() - { - return makeEmpty(NUM_SOROBAN_TX_RESOURCES); - } - - static Resource - makeEmpty(size_t numRes) - { - std::vector res(numRes, 0); - return Resource(res); - } - - int64_t - getVal(Resource::Type valType) const - { - return mResources.at(static_cast(valType)); - } + static Resource makeEmptySoroban(); + static Resource makeEmpty(size_t numRes); - void - setVal(Resource::Type valType, int64_t val) - { - mResources.at(static_cast(valType)) = val; - } + int64_t getVal(Resource::Type valType) const; + void setVal(Resource::Type valType, int64_t val); bool canAdd(Resource const& other) const; diff --git a/src/util/XDRStream.cpp b/src/util/XDRStream.cpp new file mode 100644 index 0000000000..c149fb4eb0 --- /dev/null +++ b/src/util/XDRStream.cpp @@ -0,0 +1,268 @@ +// Copyright 2015 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 "util/XDRStream.h" +#include "util/FileSystemException.h" +#include "util/Logging.h" +#include +#include + +namespace stellar +{ + +// XDRInputFileStream + +void +XDRInputFileStream::close() +{ + ZoneScoped; + mIn.close(); +} + +void +XDRInputFileStream::open(std::string const& filename) +{ + ZoneScoped; + mIn.open(filename, std::ifstream::binary); + if (!mIn) + { + std::string msg("failed to open XDR file: "); + msg += filename; + msg += ", reason: "; + msg += std::to_string(errno); + CLOG_ERROR(Fs, "{}", msg); + throw FileSystemException(msg); + } + mIn.exceptions(std::ios::badbit); + mSize = fs::size(mIn); +} + +void +XDRInputFileStream::open(std::filesystem::path const& filename) +{ + open(filename.string()); +} + +XDRInputFileStream:: +operator bool() const +{ + return mIn.good(); +} + +size_t +XDRInputFileStream::size() const +{ + return mSize; +} + +std::streamoff +XDRInputFileStream::pos() +{ + releaseAssertOrThrow(!mIn.fail()); + return mIn.tellg(); +} + +void +XDRInputFileStream::seek(size_t pos) +{ + releaseAssertOrThrow(!mIn.fail()); + mIn.seekg(pos); +} + +uint32_t +XDRInputFileStream::getXDRSize(char* buf) +{ + // Read 4 bytes of size, big-endian, with last-fragment flag bit cleared + // (high bit of high byte). + uint32_t sz = 0; + sz |= static_cast(buf[0] & '\x7f'); + sz <<= 8; + sz |= static_cast(buf[1]); + sz <<= 8; + sz |= static_cast(buf[2]); + sz <<= 8; + sz |= static_cast(buf[3]); + return sz; +} + +// OutputFileStream + +OutputFileStream::OutputFileStream(asio::io_context& ctx, bool fsyncOnClose) + : mFsyncOnClose(fsyncOnClose) +#ifndef WIN32 + , mBufferedWriteStream(ctx, stellar::fs::bufsz()) +#endif +{ +} + +OutputFileStream::~OutputFileStream() +{ + if (isOpen()) + { + close(); + } +} + +bool +OutputFileStream::isOpen() +{ +#ifdef WIN32 + return mOut != nullptr; +#else + return mBufferedWriteStream.next_layer().is_open(); +#endif +} + +fs::native_handle_t +OutputFileStream::getHandle() +{ +#ifdef WIN32 + return mHandle; +#else + return mBufferedWriteStream.next_layer().native_handle(); +#endif +} + +void +OutputFileStream::close() +{ + ZoneScoped; + if (!isOpen()) + { + FileSystemException::failWith( + "XDROutputFileStream::close() on non-open FILE*"); + } + flush(); + if (mFsyncOnClose) + { + fs::flushFileChanges(getHandle()); + } +#ifdef WIN32 + fclose(mOut); + mOut = nullptr; +#else + mBufferedWriteStream.close(); +#endif +} + +void +OutputFileStream::fdopen(int fd) +{ +#ifdef WIN32 + FileSystemException::failWith( + "XDROutputFileStream::fdopen() not supported on windows"); +#else + if (isOpen()) + { + FileSystemException::failWith( + "XDROutputFileStream::fdopen() on already-open stream"); + } + mBufferedWriteStream.next_layer().assign(fd); + if (!isOpen()) + { + FileSystemException::failWith("XDROutputFileStream::fdopen() failed"); + } +#endif +} + +void +OutputFileStream::flush() +{ + ZoneScoped; + if (!isOpen()) + { + FileSystemException::failWith( + "XDROutputFileStream::flush() on non-open stream"); + } +#ifdef WIN32 + fflush(mOut); +#else + asio::error_code ec; + do + { + mBufferedWriteStream.flush(ec); + if (ec && ec != asio::error::interrupted) + { + FileSystemException::failWith( + std::string("XDROutputFileStream::flush() failed: ") + + ec.message()); + } + } while (ec); +#endif +} + +void +OutputFileStream::open(std::string const& filename) +{ + ZoneScoped; + if (isOpen()) + { + FileSystemException::failWith( + "XDROutputFileStream::open() on already-open stream"); + } + fs::native_handle_t handle = fs::openFileToWrite(filename); +#ifdef WIN32 + mOut = fs::fdOpen(handle); + if (mOut != NULL) + { + mHandle = handle; + } + else + { + FileSystemException::failWith( + "XDROutputFileStream::open() could not open file"); + } +#else + mBufferedWriteStream.next_layer().assign(handle); +#endif +} + +OutputFileStream:: +operator bool() +{ + return isOpen(); +} + +void +OutputFileStream::writeBytes(char const* buf, size_t const sizeBytes) +{ + ZoneScoped; + if (!isOpen()) + { + FileSystemException::failWith( + "OutputFileStream::writeBytes() on non-open stream"); + } + + size_t written = 0; + while (written < sizeBytes) + { +#ifdef WIN32 + auto w = fwrite(buf + written, 1, sizeBytes - written, mOut); + if (w == 0) + { + FileSystemException::failWith( + std::string("XDROutputFileStream::writeOne() failed")); + } + written += w; +#else + asio::error_code ec; + auto asioBuf = asio::buffer(buf + written, sizeBytes - written); + written += asio::write(mBufferedWriteStream, asioBuf, ec); + if (ec) + { + if (ec == asio::error::interrupted) + { + continue; + } + else + { + FileSystemException::failWith( + std::string("XDROutputFileStream::writeOne() failed: ") + + ec.message()); + } + } +#endif + } +} +} diff --git a/src/util/XDRStream.h b/src/util/XDRStream.h index 5af0825f47..69bc0d8581 100644 --- a/src/util/XDRStream.h +++ b/src/util/XDRStream.h @@ -6,10 +6,8 @@ #include "crypto/ByteSlice.h" #include "crypto/SHA.h" -#include "util/FileSystemException.h" #include "util/Fs.h" #include "util/GlobalChecks.h" -#include "util/Logging.h" #include "util/types.h" #include "xdrpp/marshal.h" #include @@ -49,79 +47,17 @@ class XDRInputFileStream { } - void - close() - { - ZoneScoped; - mIn.close(); - } - - void - open(std::string const& filename) - { - ZoneScoped; - mIn.open(filename, std::ifstream::binary); - if (!mIn) - { - std::string msg("failed to open XDR file: "); - msg += filename; - msg += ", reason: "; - msg += std::to_string(errno); - CLOG_ERROR(Fs, "{}", msg); - throw FileSystemException(msg); - } - mIn.exceptions(std::ios::badbit); - mSize = fs::size(mIn); - } - - void - open(std::filesystem::path const& filename) - { - open(filename.string()); - } - - operator bool() const - { - return mIn.good(); - } - - size_t - size() const - { - return mSize; - } - - std::streamoff - pos() - { - releaseAssertOrThrow(!mIn.fail()); - return mIn.tellg(); - } - - void - seek(size_t pos) - { - releaseAssertOrThrow(!mIn.fail()); - mIn.seekg(pos); - } + void close(); + void open(std::string const& filename); + void open(std::filesystem::path const& filename); + operator bool() const; + size_t size() const; + std::streamoff pos(); + void seek(size_t pos); // Reads the fragment header, clears the last-fragment flag bit, and // returns the length. See the class comment for the header format. - static inline uint32_t - getXDRSize(char* buf) - { - // Read 4 bytes of size, big-endian, with last-fragment flag bit cleared - // (high bit of high byte). - uint32_t sz = 0; - sz |= static_cast(buf[0] & '\x7f'); - sz <<= 8; - sz |= static_cast(buf[1]); - sz <<= 8; - sz |= static_cast(buf[2]); - sz <<= 8; - sz |= static_cast(buf[3]); - return sz; - } + static uint32_t getXDRSize(char* buf); // If a hasher is provided, it will be updated with the raw XDR bytes // read from the stream. @@ -268,184 +204,17 @@ class OutputFileStream #endif public: - OutputFileStream(asio::io_context& ctx, bool fsyncOnClose) - : mFsyncOnClose(fsyncOnClose) -#ifndef WIN32 - , mBufferedWriteStream(ctx, stellar::fs::bufsz()) -#endif - { - } - - ~OutputFileStream() - { - if (isOpen()) - { - close(); - } - } - - bool - isOpen() - { -#ifdef WIN32 - return mOut != nullptr; -#else - return mBufferedWriteStream.next_layer().is_open(); -#endif - } - - fs::native_handle_t - getHandle() - { -#ifdef WIN32 - return mHandle; -#else - return mBufferedWriteStream.next_layer().native_handle(); -#endif - } - - void - close() - { - ZoneScoped; - if (!isOpen()) - { - FileSystemException::failWith( - "XDROutputFileStream::close() on non-open FILE*"); - } - flush(); - if (mFsyncOnClose) - { - fs::flushFileChanges(getHandle()); - } -#ifdef WIN32 - fclose(mOut); - mOut = nullptr; -#else - mBufferedWriteStream.close(); -#endif - } - - void - fdopen(int fd) - { -#ifdef WIN32 - FileSystemException::failWith( - "XDROutputFileStream::fdopen() not supported on windows"); -#else - if (isOpen()) - { - FileSystemException::failWith( - "XDROutputFileStream::fdopen() on already-open stream"); - } - mBufferedWriteStream.next_layer().assign(fd); - if (!isOpen()) - { - FileSystemException::failWith( - "XDROutputFileStream::fdopen() failed"); - } -#endif - } - - void - flush() - { - ZoneScoped; - if (!isOpen()) - { - FileSystemException::failWith( - "XDROutputFileStream::flush() on non-open stream"); - } -#ifdef WIN32 - fflush(mOut); -#else - asio::error_code ec; - do - { - mBufferedWriteStream.flush(ec); - if (ec && ec != asio::error::interrupted) - { - FileSystemException::failWith( - std::string("XDROutputFileStream::flush() failed: ") + - ec.message()); - } - } while (ec); -#endif - } - - void - open(std::string const& filename) - { - ZoneScoped; - if (isOpen()) - { - FileSystemException::failWith( - "XDROutputFileStream::open() on already-open stream"); - } - fs::native_handle_t handle = fs::openFileToWrite(filename); -#ifdef WIN32 - mOut = fs::fdOpen(handle); - if (mOut != NULL) - { - mHandle = handle; - } - else - { - FileSystemException::failWith( - "XDROutputFileStream::open() could not open file"); - } -#else - mBufferedWriteStream.next_layer().assign(handle); -#endif - } - - operator bool() - { - return isOpen(); - } - - void - writeBytes(char const* buf, size_t const sizeBytes) - { - ZoneScoped; - if (!isOpen()) - { - FileSystemException::failWith( - "OutputFileStream::writeBytes() on non-open stream"); - } - - size_t written = 0; - while (written < sizeBytes) - { -#ifdef WIN32 - auto w = fwrite(buf + written, 1, sizeBytes - written, mOut); - if (w == 0) - { - FileSystemException::failWith( - std::string("XDROutputFileStream::writeOne() failed")); - } - written += w; -#else - asio::error_code ec; - auto asioBuf = asio::buffer(buf + written, sizeBytes - written); - written += asio::write(mBufferedWriteStream, asioBuf, ec); - if (ec) - { - if (ec == asio::error::interrupted) - { - continue; - } - else - { - FileSystemException::failWith( - std::string( - "XDROutputFileStream::writeOne() failed: ") + - ec.message()); - } - } -#endif - } - } + OutputFileStream(asio::io_context& ctx, bool fsyncOnClose); + ~OutputFileStream(); + + bool isOpen(); + fs::native_handle_t getHandle(); + void close(); + void fdopen(int fd); + void flush(); + void open(std::string const& filename); + operator bool(); + void writeBytes(char const* buf, size_t sizeBytes); }; /** diff --git a/src/util/types.cpp b/src/util/types.cpp index 6b3af28325..8c5288cfc6 100644 --- a/src/util/types.cpp +++ b/src/util/types.cpp @@ -6,13 +6,11 @@ #include "lib/util/uint128_t.h" #include "util/GlobalChecks.h" #include "util/ProtocolVersion.h" -#include "util/XDROperators.h" #include "xdr/Stellar-ledger-entries.h" #include #include #include -#include namespace stellar { @@ -246,6 +244,59 @@ compareAsset(T const& first, Asset const& second) template bool compareAsset(Asset const&, Asset const&); template bool compareAsset(TrustLineAsset const&, Asset const&); +std::string +assetToString(Asset const& asset) +{ + auto r = std::string{}; + switch (asset.type()) + { + case stellar::ASSET_TYPE_NATIVE: + r = std::string{"XLM"}; + break; + case stellar::ASSET_TYPE_CREDIT_ALPHANUM4: + assetCodeToStr(asset.alphaNum4().assetCode, r); + break; + case stellar::ASSET_TYPE_CREDIT_ALPHANUM12: + assetCodeToStr(asset.alphaNum12().assetCode, r); + break; + case stellar::ASSET_TYPE_POOL_SHARE: + throw std::runtime_error( + "ASSET_TYPE_POOL_SHARE is not a valid Asset type"); + } + return r; +} + +LedgerKey +getBucketLedgerKey(HotArchiveBucketEntry const& be) +{ + switch (be.type()) + { + case HOT_ARCHIVE_LIVE: + return be.key(); + case HOT_ARCHIVE_ARCHIVED: + return LedgerEntryKey(be.archivedEntry()); + case HOT_ARCHIVE_METAENTRY: + default: + throw std::invalid_argument("Tried to get key for METAENTRY"); + } +} + +LedgerKey +getBucketLedgerKey(BucketEntry const& be) +{ + switch (be.type()) + { + case LIVEENTRY: + case INITENTRY: + return LedgerEntryKey(be.liveEntry()); + case DEADENTRY: + return be.deadEntry(); + case METAENTRY: + default: + throw std::invalid_argument("Tried to get key for METAENTRY"); + } +} + int32_t unsignedToSigned(uint32_t v) { diff --git a/src/util/types.h b/src/util/types.h index 2f95ff40eb..535a933145 100644 --- a/src/util/types.h +++ b/src/util/types.h @@ -106,58 +106,10 @@ strToAssetCode(xdr::opaque_array& ret, std::string const& str) std::copy(str.begin(), str.begin() + n, ret.begin()); } -inline std::string -assetToString(Asset const& asset) -{ - auto r = std::string{}; - switch (asset.type()) - { - case stellar::ASSET_TYPE_NATIVE: - r = std::string{"XLM"}; - break; - case stellar::ASSET_TYPE_CREDIT_ALPHANUM4: - assetCodeToStr(asset.alphaNum4().assetCode, r); - break; - case stellar::ASSET_TYPE_CREDIT_ALPHANUM12: - assetCodeToStr(asset.alphaNum12().assetCode, r); - break; - case stellar::ASSET_TYPE_POOL_SHARE: - throw std::runtime_error( - "ASSET_TYPE_POOL_SHARE is not a valid Asset type"); - } - return r; -}; - -inline LedgerKey -getBucketLedgerKey(HotArchiveBucketEntry const& be) -{ - switch (be.type()) - { - case HOT_ARCHIVE_LIVE: - return be.key(); - case HOT_ARCHIVE_ARCHIVED: - return LedgerEntryKey(be.archivedEntry()); - case HOT_ARCHIVE_METAENTRY: - default: - throw std::invalid_argument("Tried to get key for METAENTRY"); - } -} +std::string assetToString(Asset const& asset); -inline LedgerKey -getBucketLedgerKey(BucketEntry const& be) -{ - switch (be.type()) - { - case LIVEENTRY: - case INITENTRY: - return LedgerEntryKey(be.liveEntry()); - case DEADENTRY: - return be.deadEntry(); - case METAENTRY: - default: - throw std::invalid_argument("Tried to get key for METAENTRY"); - } -} +LedgerKey getBucketLedgerKey(HotArchiveBucketEntry const& be); +LedgerKey getBucketLedgerKey(BucketEntry const& be); // Round value v down to largest multiple of m, m must be power of 2 template diff --git a/src/work/test/WorkTests.cpp b/src/work/test/WorkTests.cpp index 81c99ebeb9..7805123345 100644 --- a/src/work/test/WorkTests.cpp +++ b/src/work/test/WorkTests.cpp @@ -13,6 +13,7 @@ #include "historywork/RunCommandWork.h" #include "work/BatchWork.h" #include "work/ConditionalWork.h" +#include "work/WorkSequence.h" #include