From c573704aa36686447d470d005015c9314a196dc5 Mon Sep 17 00:00:00 2001 From: marta-lokhova Date: Fri, 13 Sep 2024 17:34:37 -0700 Subject: [PATCH] Rotate ledger headers if needed in SearchableBucketListSnapshot::getLedgerHeader --- src/bucket/BucketListSnapshot.cpp | 8 ++++++++ src/bucket/BucketListSnapshot.h | 6 +----- src/ledger/LedgerManagerImpl.cpp | 1 - src/ledger/LedgerStateSnapshot.h | 4 ++++ 4 files changed, 13 insertions(+), 6 deletions(-) diff --git a/src/bucket/BucketListSnapshot.cpp b/src/bucket/BucketListSnapshot.cpp index e5adfb56bb..5d26fd8296 100644 --- a/src/bucket/BucketListSnapshot.cpp +++ b/src/bucket/BucketListSnapshot.cpp @@ -127,6 +127,14 @@ SearchableBucketListSnapshot::getLedgerSeq() const return mSnapshot->getLedgerSeq(); } +LedgerHeader const& +SearchableBucketListSnapshot::getLedgerHeader() +{ + releaseAssert(mSnapshot); + mSnapshotManager.maybeUpdateSnapshot(mSnapshot, mHistoricalSnapshots); + return mSnapshot->getLedgerHeader(); +} + EvictionResult SearchableBucketListSnapshot::scanForEviction( uint32_t ledgerSeq, EvictionCounters& counters, diff --git a/src/bucket/BucketListSnapshot.h b/src/bucket/BucketListSnapshot.h index 9b6fd5dcf8..ea14869f3a 100644 --- a/src/bucket/BucketListSnapshot.h +++ b/src/bucket/BucketListSnapshot.h @@ -102,10 +102,6 @@ class SearchableBucketListSnapshot : public NonMovableOrCopyable std::shared_ptr stats, StateArchivalSettings const& sas); uint32_t getLedgerSeq() const; - LedgerHeader const& - getLedgerHeader() const - { - return mSnapshot->getLedgerHeader(); - } + LedgerHeader const& getLedgerHeader(); }; } \ No newline at end of file diff --git a/src/ledger/LedgerManagerImpl.cpp b/src/ledger/LedgerManagerImpl.cpp index a5a7f33d88..2b7f328671 100644 --- a/src/ledger/LedgerManagerImpl.cpp +++ b/src/ledger/LedgerManagerImpl.cpp @@ -5,7 +5,6 @@ #include "ledger/LedgerManagerImpl.h" #include "bucket/BucketList.h" #include "bucket/BucketManager.h" -#include "bucket/test/BucketTestUtils.h" #include "catchup/AssumeStateWork.h" #include "crypto/Hex.h" #include "crypto/KeyUtils.h" diff --git a/src/ledger/LedgerStateSnapshot.h b/src/ledger/LedgerStateSnapshot.h index d60e5eb1ae..7a57b1c771 100644 --- a/src/ledger/LedgerStateSnapshot.h +++ b/src/ledger/LedgerStateSnapshot.h @@ -130,6 +130,10 @@ class BucketSnapshotState : public AbstractLedgerStateSnapshot // A helper class to create and query read-only snapshots // Automatically decides whether to create a BucketList (recommended), or SQL // snapshot (deprecated, but currently supported) +// NOTE: LedgerSnapshot is meant to be short-lived, and should not be persisted +// across _different_ ledgers, as the state under the hood might change. Users +// are expected to construct a new LedgerSnapshot each time they want to query +// ledger state. class LedgerSnapshot : public NonMovableOrCopyable { std::unique_ptr mGetter;