From f68c7a32905dc6e73c0f306a374881d297199d79 Mon Sep 17 00:00:00 2001 From: Thomas Brady Date: Thu, 22 Aug 2024 17:15:28 -0700 Subject: [PATCH 1/2] Bucket entry counters and metrics --- src/bucket/Bucket.cpp | 24 +++++++++ src/bucket/Bucket.h | 34 ++++++++++++- src/bucket/BucketIndex.h | 5 +- src/bucket/BucketIndexImpl.cpp | 84 +++++++++++++++++++++++++++++++- src/bucket/BucketIndexImpl.h | 7 ++- src/bucket/BucketList.cpp | 16 ++++++ src/bucket/BucketList.h | 2 + src/bucket/BucketManager.h | 1 + src/bucket/BucketManagerImpl.cpp | 70 ++++++++++++++++++++++++++ src/bucket/BucketManagerImpl.h | 8 +++ 10 files changed, 245 insertions(+), 6 deletions(-) diff --git a/src/bucket/Bucket.cpp b/src/bucket/Bucket.cpp index d20a6d82c2..2bb63ec0f3 100644 --- a/src/bucket/Bucket.cpp +++ b/src/bucket/Bucket.cpp @@ -854,4 +854,28 @@ Bucket::getBucketVersion(std::shared_ptr const& bucket) BucketInputIterator it(bucket); return it.getMetadata().ledgerVersion; } + +BucketEntryCounters +Bucket::getBucketEntryCounters() const +{ + if (mIndex) + { + return mIndex->getBucketEntryCounters(); + } + return {}; +} + +BucketEntryCounters& +BucketEntryCounters::operator+=(BucketEntryCounters const& other) +{ + for (auto [type, count] : other.mEntryTypeCounts) + { + this->mEntryTypeCounts[type] += count; + } + for (auto [type, size] : other.mEntryTypeSizes) + { + this->mEntryTypeSizes[type] += size; + } + return *this; +} } diff --git a/src/bucket/Bucket.h b/src/bucket/Bucket.h index 43cb97abfd..12dd577293 100644 --- a/src/bucket/Bucket.h +++ b/src/bucket/Bucket.h @@ -9,6 +9,7 @@ #include "util/ProtocolVersion.h" #include "xdr/Stellar-ledger.h" #include +#include #include #include @@ -43,6 +44,7 @@ class BucketManager; class SearchableBucketListSnapshot; struct EvictionResultEntry; class EvictionStatistics; +struct BucketEntryCounters; class Bucket : public std::enable_shared_from_this, public NonMovableOrCopyable @@ -179,7 +181,37 @@ class Bucket : public std::enable_shared_from_this, static uint32_t getBucketVersion(std::shared_ptr const& bucket); static uint32_t getBucketVersion(std::shared_ptr const& bucket); - + BucketEntryCounters getBucketEntryCounters() const; friend class BucketSnapshot; }; + +enum class LedgerEntryTypeAndDurability : uint32_t +{ + ACCOUNT = 0, + TRUSTLINE = 1, + OFFER = 2, + DATA = 3, + CLAIMABLE_BALANCE = 4, + LIQUIDITY_POOL = 5, + TEMPORARY_CONTRACT_DATA = 6, + PERSISTENT_CONTRACT_DATA = 7, + CONTRACT_CODE = 8, + CONFIG_SETTING = 9, + TTL = 10 +}; + +struct BucketEntryCounters +{ + std::map mEntryTypeCounts; + std::map mEntryTypeSizes; + + BucketEntryCounters& operator+=(BucketEntryCounters const& other); + + template + void + serialize(Archive& ar) const + { + ar(mEntryTypeCounts, mEntryTypeSizes); + } +}; } diff --git a/src/bucket/BucketIndex.h b/src/bucket/BucketIndex.h index 3509fd7dd2..7dd34fc999 100644 --- a/src/bucket/BucketIndex.h +++ b/src/bucket/BucketIndex.h @@ -33,6 +33,7 @@ namespace stellar */ class BucketManager; +struct BucketEntryCounters; // BucketIndex abstract interface class BucketIndex : public NonMovableOrCopyable @@ -74,7 +75,7 @@ class BucketIndex : public NonMovableOrCopyable IndividualIndex::const_iterator>; inline static const std::string DB_BACKEND_STATE = "bl"; - inline static const uint32_t BUCKET_INDEX_VERSION = 3; + inline static const uint32_t BUCKET_INDEX_VERSION = 4; // Returns true if LedgerEntryType not supported by BucketListDB static bool typeNotSupported(LedgerEntryType t); @@ -132,7 +133,7 @@ class BucketIndex : public NonMovableOrCopyable virtual void markBloomMiss() const = 0; virtual void markBloomLookup() const = 0; - + virtual BucketEntryCounters const& getBucketEntryCounters() const = 0; #ifdef BUILD_TESTS virtual bool operator==(BucketIndex const& inRaw) const = 0; #endif diff --git a/src/bucket/BucketIndexImpl.cpp b/src/bucket/BucketIndexImpl.cpp index 029f00b542..05bfb748c0 100644 --- a/src/bucket/BucketIndexImpl.cpp +++ b/src/bucket/BucketIndexImpl.cpp @@ -7,6 +7,7 @@ #include "bucket/BucketManager.h" #include "crypto/Hex.h" #include "crypto/ShortHash.h" +#include "ledger/LedgerTypeUtils.h" #include "main/Config.h" #include "util/BinaryFuseFilter.h" #include "util/Fs.h" @@ -100,6 +101,79 @@ BucketIndexImpl::BucketIndexImpl(BucketManager& bm, std::vector keyHashes; auto seed = shortHash::getShortHashInitKey(); + auto countEntry = [&](BucketEntry const& be) { + auto ledgerEntryToLedgerEntryAndDurabilityType = + [&](LedgerEntryType let, bool isTemporaryEntry) { + switch (let) + { + case ACCOUNT: + return LedgerEntryTypeAndDurability::ACCOUNT; + break; + case TRUSTLINE: + return LedgerEntryTypeAndDurability::TRUSTLINE; + break; + case OFFER: + return LedgerEntryTypeAndDurability::OFFER; + break; + case DATA: + return LedgerEntryTypeAndDurability::DATA; + break; + case CLAIMABLE_BALANCE: + return LedgerEntryTypeAndDurability::CLAIMABLE_BALANCE; + break; + case LIQUIDITY_POOL: + return LedgerEntryTypeAndDurability::LIQUIDITY_POOL; + break; + case CONTRACT_DATA: + return isTemporaryEntry ? LedgerEntryTypeAndDurability:: + TEMPORARY_CONTRACT_DATA + : LedgerEntryTypeAndDurability:: + PERSISTENT_CONTRACT_DATA; + break; + case CONTRACT_CODE: + return LedgerEntryTypeAndDurability::CONTRACT_CODE; + break; + case CONFIG_SETTING: + return LedgerEntryTypeAndDurability::CONFIG_SETTING; + break; + case TTL: + return LedgerEntryTypeAndDurability::TTL; + break; + default: + throw std::runtime_error(fmt::format( + FMT_STRING("Unknown LedgerEntryType {}"), let)); + break; + } + }; + auto bet = be.type(); + LedgerEntryType let; + bool isTemp = false; + if (bet == INITENTRY || bet == LIVEENTRY) + { + let = be.liveEntry().data.type(); + if (let == CONTRACT_DATA) + { + isTemp = isTemporaryEntry(be.liveEntry().data); + } + } + else if (bet == DEADENTRY) + { + let = be.deadEntry().type(); + if (let == CONTRACT_DATA) + { + isTemp = isTemporaryEntry(be.deadEntry()); + } + } + else + { + // Do not count meta entries. + return; + } + auto ledt = ledgerEntryToLedgerEntryAndDurabilityType(let, isTemp); + mData.counters.mEntryTypeCounts[ledt]++; + mData.counters.mEntryTypeSizes[ledt] += xdr::xdr_size(be); + }; + while (in && in.readOne(be)) { // peridocially check if bucket manager is exiting to stop indexing @@ -170,6 +244,7 @@ BucketIndexImpl::BucketIndexImpl(BucketManager& bm, { mData.keysToOffset.emplace_back(key, pos); } + countEntry(be); } pos = in.pos(); @@ -580,4 +655,11 @@ BucketIndexImpl::markBloomLookup() const { mBloomLookupMeter.Mark(); } -} \ No newline at end of file + +template +BucketEntryCounters const& +BucketIndexImpl::getBucketEntryCounters() const +{ + return mData.counters; +} +} diff --git a/src/bucket/BucketIndexImpl.h b/src/bucket/BucketIndexImpl.h index 51bd562342..c0fa4f523a 100644 --- a/src/bucket/BucketIndexImpl.h +++ b/src/bucket/BucketIndexImpl.h @@ -4,6 +4,7 @@ // 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 "bucket/Bucket.h" #include "bucket/BucketIndex.h" #include "medida/meter.h" #include "util/BinaryFuseFilter.h" @@ -15,7 +16,6 @@ namespace stellar { - // Index maps either individual keys or a key range of BucketEntry's to the // associated offset within the bucket file. Index stored as vector of pairs: // First: LedgerKey/Key ranges sorted in the same scheme as LedgerEntryCmp @@ -33,13 +33,15 @@ template class BucketIndexImpl : public BucketIndex std::streamoff pageSize{}; std::unique_ptr filter{}; std::map> assetToPoolID{}; + BucketEntryCounters counters{}; template void save(Archive& ar) const { auto version = BUCKET_INDEX_VERSION; - ar(version, pageSize, assetToPoolID, keysToOffset, filter); + ar(version, pageSize, assetToPoolID, keysToOffset, filter, + counters); } // Note: version and pageSize must be loaded before this function is @@ -111,6 +113,7 @@ template class BucketIndexImpl : public BucketIndex virtual void markBloomMiss() const override; virtual void markBloomLookup() const override; + virtual BucketEntryCounters const& getBucketEntryCounters() const override; #ifdef BUILD_TESTS virtual bool operator==(BucketIndex const& inRaw) const override; diff --git a/src/bucket/BucketList.cpp b/src/bucket/BucketList.cpp index b49ba3a9b3..5424b639d4 100644 --- a/src/bucket/BucketList.cpp +++ b/src/bucket/BucketList.cpp @@ -4,6 +4,7 @@ #include "BucketList.h" #include "bucket/Bucket.h" +#include "bucket/BucketIndexImpl.h" #include "bucket/BucketInputIterator.h" #include "bucket/BucketManager.h" #include "bucket/BucketSnapshot.h" @@ -631,6 +632,21 @@ BucketList::addBatch(Application& app, uint32_t currLedger, } } +BucketEntryCounters +BucketList::sumBucketEntryCounters() const +{ + BucketEntryCounters counters; + for (auto const& lev : mLevels) + { + for (auto const& b : {lev.getCurr(), lev.getSnap()}) + { + auto c = b->getBucketEntryCounters(); + counters += c; + } + } + return counters; +} + void BucketList::updateStartingEvictionIterator(EvictionIterator& iter, uint32_t firstScanLevel, diff --git a/src/bucket/BucketList.h b/src/bucket/BucketList.h index 3e9960aa8b..09549ac1ad 100644 --- a/src/bucket/BucketList.h +++ b/src/bucket/BucketList.h @@ -345,6 +345,7 @@ namespace stellar class AbstractLedgerTxn; class Application; class Bucket; +struct BucketEntryCounters; class Config; struct EvictionCounters; struct InflationWinner; @@ -523,5 +524,6 @@ class BucketList std::vector const& initEntries, std::vector const& liveEntries, std::vector const& deadEntries); + BucketEntryCounters sumBucketEntryCounters() const; }; } diff --git a/src/bucket/BucketManager.h b/src/bucket/BucketManager.h index 94e9580614..b947582f24 100644 --- a/src/bucket/BucketManager.h +++ b/src/bucket/BucketManager.h @@ -382,5 +382,6 @@ class BucketManager : NonMovableOrCopyable scheduleVerifyReferencedBucketsWork() = 0; virtual Config const& getConfig() const = 0; + virtual void reportBucketEntryCountMetrics() = 0; }; } diff --git a/src/bucket/BucketManagerImpl.cpp b/src/bucket/BucketManagerImpl.cpp index f428b50850..485f90cfbf 100644 --- a/src/bucket/BucketManagerImpl.cpp +++ b/src/bucket/BucketManagerImpl.cpp @@ -4,6 +4,7 @@ #include "bucket/BucketManagerImpl.h" #include "bucket/Bucket.h" +#include "bucket/BucketIndexImpl.h" #include "bucket/BucketInputIterator.h" #include "bucket/BucketList.h" #include "bucket/BucketListSnapshot.h" @@ -909,6 +910,7 @@ BucketManagerImpl::addBatch(Application& app, uint32_t currLedger, { mSnapshotManager->updateCurrentSnapshot( std::make_unique(*mBucketList, currLedger)); + reportBucketEntryCountMetrics(); } } @@ -1521,4 +1523,72 @@ BucketManagerImpl::getConfig() const { return mApp.getConfig(); } + +std::string +to_string(LedgerEntryTypeAndDurability const type) +{ + switch (type) + { + case LedgerEntryTypeAndDurability::ACCOUNT: + return "ACCOUNT"; + case LedgerEntryTypeAndDurability::TRUSTLINE: + return "TRUSTLINE"; + case LedgerEntryTypeAndDurability::OFFER: + return "OFFER"; + case LedgerEntryTypeAndDurability::DATA: + return "DATA"; + case LedgerEntryTypeAndDurability::CLAIMABLE_BALANCE: + return "CLAIMABLE_BALANCE"; + case LedgerEntryTypeAndDurability::LIQUIDITY_POOL: + return "LIQUIDITY_POOL"; + case LedgerEntryTypeAndDurability::TEMPORARY_CONTRACT_DATA: + return "TEMPORARY_CONTRACT_DATA"; + case LedgerEntryTypeAndDurability::PERSISTENT_CONTRACT_DATA: + return "PERSISTENT_CONTRACT_DATA"; + case LedgerEntryTypeAndDurability::CONTRACT_CODE: + return "CONTRACT_CODE"; + case LedgerEntryTypeAndDurability::CONFIG_SETTING: + return "CONFIG_SETTING"; + case LedgerEntryTypeAndDurability::TTL: + return "TTL"; + default: + throw std::runtime_error( + fmt::format(FMT_STRING("unknown LedgerEntryTypeAndDurability {:d}"), + static_cast(type))); + } +} + +void +BucketManagerImpl::reportBucketEntryCountMetrics() +{ + auto bucketEntryCounters = mBucketList->sumBucketEntryCounters(); + for (auto& [type, count] : bucketEntryCounters.mEntryTypeCounts) + { + auto countsCounter = mBucketListEntryCounts.find(type); + if (countsCounter == mBucketListEntryCounts.end()) + { + + countsCounter = + mBucketListEntryCounts + .emplace(type, + mApp.getMetrics().NewCounter( + {"bucket", "entryCounts", to_string(type)})) + .first; + } + countsCounter->second.set_count(count); + + auto sizesCounter = mBucketListEntrySizes.find(type); + if (sizesCounter == mBucketListEntrySizes.end()) + { + sizesCounter = + mBucketListEntrySizes + .emplace(type, + mApp.getMetrics().NewCounter( + {"bucket", "entrySizes", to_string(type)})) + .first; + } + sizesCounter->second.set_count( + bucketEntryCounters.mEntryTypeSizes[type]); + } +} } diff --git a/src/bucket/BucketManagerImpl.h b/src/bucket/BucketManagerImpl.h index a347692ca2..45f6831d8f 100644 --- a/src/bucket/BucketManagerImpl.h +++ b/src/bucket/BucketManagerImpl.h @@ -31,6 +31,9 @@ class Application; class Bucket; class BucketList; class BucketSnapshotManager; +struct BucketEntryCounters; +enum class LedgerEntryTypeAndDurability : uint32_t; + struct HistoryArchiveState; class BucketManagerImpl : public BucketManager @@ -59,6 +62,10 @@ class BucketManagerImpl : public BucketManager EvictionCounters mBucketListEvictionCounters; MergeCounters mMergeCounters; std::shared_ptr mEvictionStatistics{}; + std::map + mBucketListEntryCounts; + std::map + mBucketListEntrySizes; std::future mEvictionFuture{}; @@ -188,6 +195,7 @@ class BucketManagerImpl : public BucketManager std::shared_ptr scheduleVerifyReferencedBucketsWork() override; Config const& getConfig() const override; + void reportBucketEntryCountMetrics() override; }; #define SKIP_1 50 From aee8be3d476f824f1afb253d41fa5eb5430e746b Mon Sep 17 00:00:00 2001 From: Thomas Brady Date: Fri, 30 Aug 2024 16:21:41 -0700 Subject: [PATCH 2/2] WIP bucket entry counts in meta --- src/bucket/Bucket.h | 1 - src/bucket/BucketManager.h | 7 ++-- src/bucket/BucketManagerImpl.cpp | 13 +++++-- src/bucket/BucketManagerImpl.h | 6 ++-- src/bucket/BucketSnapshotManager.h | 3 +- src/ledger/LedgerCloseMetaFrame.cpp | 55 +++++++++++++++++++++++++++++ src/ledger/LedgerCloseMetaFrame.h | 4 ++- src/ledger/LedgerManagerImpl.cpp | 3 +- 8 files changed, 81 insertions(+), 11 deletions(-) diff --git a/src/bucket/Bucket.h b/src/bucket/Bucket.h index 12dd577293..9647cb2235 100644 --- a/src/bucket/Bucket.h +++ b/src/bucket/Bucket.h @@ -44,7 +44,6 @@ class BucketManager; class SearchableBucketListSnapshot; struct EvictionResultEntry; class EvictionStatistics; -struct BucketEntryCounters; class Bucket : public std::enable_shared_from_this, public NonMovableOrCopyable diff --git a/src/bucket/BucketManager.h b/src/bucket/BucketManager.h index b947582f24..0b8f55731f 100644 --- a/src/bucket/BucketManager.h +++ b/src/bucket/BucketManager.h @@ -29,6 +29,7 @@ class BasicWork; class BucketList; class BucketSnapshotManager; class Config; +class LedgerCloseMetaFrame; class SearchableBucketListSnapshot; class TmpDirManager; struct HistoryArchiveState; @@ -271,7 +272,8 @@ class BucketManager : NonMovableOrCopyable uint32_t currLedgerProtocol, std::vector const& initEntries, std::vector const& liveEntries, - std::vector const& deadEntries) = 0; + std::vector const& deadEntries, + LedgerCloseMetaFrame* ledgerCloseMeta = nullptr) = 0; // Update the given LedgerHeader's bucketListHash to reflect the current // state of the bucket list. @@ -382,6 +384,7 @@ class BucketManager : NonMovableOrCopyable scheduleVerifyReferencedBucketsWork() = 0; virtual Config const& getConfig() const = 0; - virtual void reportBucketEntryCountMetrics() = 0; + virtual void + reportBucketEntryCountMetrics(LedgerCloseMetaFrame* ledgerCloseMeta) = 0; }; } diff --git a/src/bucket/BucketManagerImpl.cpp b/src/bucket/BucketManagerImpl.cpp index 485f90cfbf..3e506565fd 100644 --- a/src/bucket/BucketManagerImpl.cpp +++ b/src/bucket/BucketManagerImpl.cpp @@ -14,6 +14,7 @@ #include "crypto/Hex.h" #include "history/HistoryManager.h" #include "historywork/VerifyBucketWork.h" +#include "ledger/LedgerCloseMetaFrame.h" #include "ledger/LedgerManager.h" #include "ledger/LedgerTxn.h" #include "ledger/LedgerTypeUtils.h" @@ -889,7 +890,8 @@ BucketManagerImpl::addBatch(Application& app, uint32_t currLedger, uint32_t currLedgerProtocol, std::vector const& initEntries, std::vector const& liveEntries, - std::vector const& deadEntries) + std::vector const& deadEntries, + LedgerCloseMetaFrame* ledgerCloseMeta) { ZoneScoped; releaseAssertOrThrow(app.getConfig().MODE_ENABLES_BUCKETLIST); @@ -910,7 +912,7 @@ BucketManagerImpl::addBatch(Application& app, uint32_t currLedger, { mSnapshotManager->updateCurrentSnapshot( std::make_unique(*mBucketList, currLedger)); - reportBucketEntryCountMetrics(); + reportBucketEntryCountMetrics(ledgerCloseMeta); } } @@ -1559,7 +1561,8 @@ to_string(LedgerEntryTypeAndDurability const type) } void -BucketManagerImpl::reportBucketEntryCountMetrics() +BucketManagerImpl::reportBucketEntryCountMetrics( + LedgerCloseMetaFrame* ledgerCloseMeta) { auto bucketEntryCounters = mBucketList->sumBucketEntryCounters(); for (auto& [type, count] : bucketEntryCounters.mEntryTypeCounts) @@ -1590,5 +1593,9 @@ BucketManagerImpl::reportBucketEntryCountMetrics() sizesCounter->second.set_count( bucketEntryCounters.mEntryTypeSizes[type]); } + if (ledgerCloseMeta) + { + ledgerCloseMeta->setBucketEntryCounts(bucketEntryCounters); + } } } diff --git a/src/bucket/BucketManagerImpl.h b/src/bucket/BucketManagerImpl.h index 45f6831d8f..b713e81066 100644 --- a/src/bucket/BucketManagerImpl.h +++ b/src/bucket/BucketManagerImpl.h @@ -144,7 +144,8 @@ class BucketManagerImpl : public BucketManager uint32_t currLedgerProtocol, std::vector const& initEntries, std::vector const& liveEntries, - std::vector const& deadEntries) override; + std::vector const& deadEntries, + LedgerCloseMetaFrame* ledgerCloseMeta) override; void snapshotLedger(LedgerHeader& currentHeader) override; void maybeSetIndex(std::shared_ptr b, std::unique_ptr&& index) override; @@ -195,7 +196,8 @@ class BucketManagerImpl : public BucketManager std::shared_ptr scheduleVerifyReferencedBucketsWork() override; Config const& getConfig() const override; - void reportBucketEntryCountMetrics() override; + void reportBucketEntryCountMetrics( + LedgerCloseMetaFrame* ledgerCloseMeta) override; }; #define SKIP_1 50 diff --git a/src/bucket/BucketSnapshotManager.h b/src/bucket/BucketSnapshotManager.h index 0a093585d8..50a4eaf8e6 100644 --- a/src/bucket/BucketSnapshotManager.h +++ b/src/bucket/BucketSnapshotManager.h @@ -68,7 +68,8 @@ class BucketSnapshotManager : NonMovableOrCopyable uint32_t currLedgerProtocol, std::vector const& initEntries, std::vector const& liveEntries, - std::vector const& deadEntries); + std::vector const& deadEntries, + LedgerCloseMetaFrame* ledgerCloseMeta); friend void BucketManagerImpl::assumeState(HistoryArchiveState const& has, uint32_t maxProtocolVersion, bool restartMerges); diff --git a/src/ledger/LedgerCloseMetaFrame.cpp b/src/ledger/LedgerCloseMetaFrame.cpp index b4ef7a9429..ee4b5a7112 100644 --- a/src/ledger/LedgerCloseMetaFrame.cpp +++ b/src/ledger/LedgerCloseMetaFrame.cpp @@ -3,6 +3,7 @@ // of this distribution or at http://www.apache.org/licenses/LICENSE-2.0 #include "ledger/LedgerCloseMetaFrame.h" +#include "bucket/Bucket.h" #include "crypto/SHA.h" #include "ledger/LedgerTypeUtils.h" #include "transactions/TransactionMetaFrame.h" @@ -186,6 +187,60 @@ LedgerCloseMetaFrame::setNetworkConfiguration( } } +void +LedgerCloseMetaFrame::setBucketEntryCounts( + BucketEntryCounters const& bucketEntryCounters) +{ + releaseAssert(mVersion == 1); + auto metaCounts = mLedgerCloseMeta.v1().bucketEntryCounters; + auto metaSizes = mLedgerCloseMeta.v1().bucketEntrySizes; + metaCounts.account = bucketEntryCounters.mEntryTypeCounts.at( + LedgerEntryTypeAndDurability::ACCOUNT); + metaCounts.trustline = bucketEntryCounters.mEntryTypeCounts.at( + LedgerEntryTypeAndDurability::TRUSTLINE); + metaCounts.offer = bucketEntryCounters.mEntryTypeCounts.at( + LedgerEntryTypeAndDurability::OFFER); + metaCounts.data = bucketEntryCounters.mEntryTypeCounts.at( + LedgerEntryTypeAndDurability::DATA); + metaCounts.claimableBalance = bucketEntryCounters.mEntryTypeCounts.at( + LedgerEntryTypeAndDurability::CLAIMABLE_BALANCE); + metaCounts.liquidityPool = bucketEntryCounters.mEntryTypeCounts.at( + LedgerEntryTypeAndDurability::LIQUIDITY_POOL); + metaCounts.temporaryContractData = bucketEntryCounters.mEntryTypeCounts.at( + LedgerEntryTypeAndDurability::TEMPORARY_CONTRACT_DATA); + metaCounts.persistentContractData = bucketEntryCounters.mEntryTypeCounts.at( + LedgerEntryTypeAndDurability::PERSISTENT_CONTRACT_DATA); + metaCounts.contractCode = bucketEntryCounters.mEntryTypeCounts.at( + LedgerEntryTypeAndDurability::CONTRACT_CODE); + metaCounts.configSetting = bucketEntryCounters.mEntryTypeCounts.at( + LedgerEntryTypeAndDurability::CONFIG_SETTING); + metaCounts.ttl = bucketEntryCounters.mEntryTypeCounts.at( + LedgerEntryTypeAndDurability::TTL); + + metaSizes.account = bucketEntryCounters.mEntryTypeSizes.at( + LedgerEntryTypeAndDurability::ACCOUNT); + metaSizes.trustline = bucketEntryCounters.mEntryTypeSizes.at( + LedgerEntryTypeAndDurability::TRUSTLINE); + metaSizes.offer = bucketEntryCounters.mEntryTypeSizes.at( + LedgerEntryTypeAndDurability::OFFER); + metaSizes.data = bucketEntryCounters.mEntryTypeSizes.at( + LedgerEntryTypeAndDurability::DATA); + metaSizes.claimableBalance = bucketEntryCounters.mEntryTypeSizes.at( + LedgerEntryTypeAndDurability::CLAIMABLE_BALANCE); + metaSizes.liquidityPool = bucketEntryCounters.mEntryTypeSizes.at( + LedgerEntryTypeAndDurability::LIQUIDITY_POOL); + metaSizes.temporaryContractData = bucketEntryCounters.mEntryTypeSizes.at( + LedgerEntryTypeAndDurability::TEMPORARY_CONTRACT_DATA); + metaSizes.persistentContractData = bucketEntryCounters.mEntryTypeSizes.at( + LedgerEntryTypeAndDurability::PERSISTENT_CONTRACT_DATA); + metaSizes.contractCode = bucketEntryCounters.mEntryTypeSizes.at( + LedgerEntryTypeAndDurability::CONTRACT_CODE); + metaSizes.configSetting = bucketEntryCounters.mEntryTypeSizes.at( + LedgerEntryTypeAndDurability::CONFIG_SETTING); + metaSizes.ttl = bucketEntryCounters.mEntryTypeSizes.at( + LedgerEntryTypeAndDurability::TTL); +} + LedgerCloseMeta const& LedgerCloseMetaFrame::getXDR() const { diff --git a/src/ledger/LedgerCloseMetaFrame.h b/src/ledger/LedgerCloseMetaFrame.h index 60ad7c786a..acccb7ea83 100644 --- a/src/ledger/LedgerCloseMetaFrame.h +++ b/src/ledger/LedgerCloseMetaFrame.h @@ -9,7 +9,7 @@ namespace stellar { - +struct BucketEntryCounters; // Wrapper around LedgerCloseMeta XDR that provides mutable access to fields // in the proper version of meta. class LedgerCloseMetaFrame @@ -35,6 +35,8 @@ class LedgerCloseMetaFrame void setNetworkConfiguration(SorobanNetworkConfig const& networkConfig, bool emitExtV1); + void setBucketEntryCounts(BucketEntryCounters const& bucketEntryCounters); + LedgerCloseMeta const& getXDR() const; private: diff --git a/src/ledger/LedgerManagerImpl.cpp b/src/ledger/LedgerManagerImpl.cpp index e3883c9b0c..8b276666be 100644 --- a/src/ledger/LedgerManagerImpl.cpp +++ b/src/ledger/LedgerManagerImpl.cpp @@ -1702,7 +1702,8 @@ LedgerManagerImpl::transferLedgerEntriesToBucketList( if (blEnabled) { mApp.getBucketManager().addBatch(mApp, ledgerSeq, currLedgerVers, - initEntries, liveEntries, deadEntries); + initEntries, liveEntries, deadEntries, + ledgerCloseMeta.get()); } }