@@ -61,6 +61,26 @@ SearchableBucketListSnapshot::isWithinAllowedLedgerDrift(
61
61
return mLCL >= minimumLCL;
62
62
}
63
63
64
+ void
65
+ SearchableBucketListSnapshot::maybeUpdateSnapshot ()
66
+ {
67
+ auto currLCL = mApp .getLedgerManager ().getLastClosedLedgerNum ();
68
+ if (currLCL != mLCL )
69
+ {
70
+ mLCL = currLCL;
71
+ mLevels .clear ();
72
+
73
+ std::lock_guard<std::recursive_mutex> lock (
74
+ mApp .getBucketManager ().getBucketSnapshotMutex ());
75
+ auto & bl = mApp .getBucketManager ().getBucketList ();
76
+ for (uint32_t i = 0 ; i < BucketList::kNumLevels ; ++i)
77
+ {
78
+ auto const & level = bl.getLevel (i);
79
+ mLevels .emplace_back (SearchableBucketLevelSnapshot (level));
80
+ }
81
+ }
82
+ }
83
+
64
84
void
65
85
SearchableBucketListSnapshot::loopAllBuckets (
66
86
std::function<bool (SearchableBucketSnapshot const &)> f) const
@@ -85,13 +105,11 @@ SearchableBucketListSnapshot::loopAllBuckets(
85
105
}
86
106
87
107
std::shared_ptr<LedgerEntry>
88
- SearchableBucketListSnapshot::getLedgerEntry (LedgerKey const & k) const
108
+ SearchableBucketListSnapshot::getLedgerEntry (LedgerKey const & k)
89
109
{
90
110
ZoneScoped;
91
111
auto timer = getPointLoadTimer (k.type ()).TimeScope ();
92
-
93
- // Snapshots not currently supported, all access must be up to date
94
- releaseAssert (isWithinAllowedLedgerDrift (0 ));
112
+ maybeUpdateSnapshot ();
95
113
96
114
std::shared_ptr<LedgerEntry> result{};
97
115
@@ -117,13 +135,11 @@ SearchableBucketListSnapshot::getLedgerEntry(LedgerKey const& k) const
117
135
118
136
std::vector<LedgerEntry>
119
137
SearchableBucketListSnapshot::loadKeys (
120
- std::set<LedgerKey, LedgerEntryIdCmp> const & inKeys) const
138
+ std::set<LedgerKey, LedgerEntryIdCmp> const & inKeys)
121
139
{
122
140
ZoneScoped;
123
141
auto timer = recordBulkLoadMetrics (" prefetch" , inKeys.size ()).TimeScope ();
124
-
125
- // Snapshots not currently supported, all access must be up to date
126
- releaseAssert (isWithinAllowedLedgerDrift (0 ));
142
+ maybeUpdateSnapshot ();
127
143
128
144
std::vector<LedgerEntry> entries;
129
145
@@ -140,13 +156,11 @@ SearchableBucketListSnapshot::loadKeys(
140
156
141
157
std::vector<LedgerEntry>
142
158
SearchableBucketListSnapshot::loadPoolShareTrustLinesByAccountAndAsset (
143
- AccountID const & accountID, Asset const & asset) const
159
+ AccountID const & accountID, Asset const & asset)
144
160
{
145
161
ZoneScoped;
146
162
auto timer = recordBulkLoadMetrics (" poolshareTrustlines" , 0 ).TimeScope ();
147
-
148
- // Snapshots not currently supported, all access must be up to date
149
- releaseAssert (isWithinAllowedLedgerDrift (0 ));
163
+ maybeUpdateSnapshot ();
150
164
151
165
UnorderedMap<LedgerKey, LedgerEntry> liquidityPoolToTrustline;
152
166
UnorderedSet<LedgerKey> deadTrustlines;
@@ -189,13 +203,11 @@ SearchableBucketListSnapshot::loadPoolShareTrustLinesByAccountAndAsset(
189
203
190
204
std::vector<InflationWinner>
191
205
SearchableBucketListSnapshot::loadInflationWinners (size_t maxWinners,
192
- int64_t minBalance) const
206
+ int64_t minBalance)
193
207
{
194
208
ZoneScoped;
195
209
auto timer = recordBulkLoadMetrics (" inflationWinners" , 0 ).TimeScope ();
196
-
197
- // Snapshots not currently supported, all access must be up to date
198
- releaseAssert (isWithinAllowedLedgerDrift (0 ));
210
+ maybeUpdateSnapshot ();
199
211
200
212
UnorderedMap<AccountID, int64_t > voteCount;
201
213
UnorderedSet<AccountID> seen;
0 commit comments