2
2
// under the Apache License, Version 2.0. See the COPYING file at the root
3
3
// of this distribution or at http://www.apache.org/licenses/LICENSE-2.0
4
4
5
- #include " bucket/SearchableBucketListSnapshot .h"
5
+ #include " bucket/BucketListSnapshot .h"
6
6
#include " bucket/BucketInputIterator.h"
7
7
#include " crypto/SecretKey.h"
8
8
#include " ledger/LedgerTxn.h"
13
13
namespace stellar
14
14
{
15
15
16
+ BucketListSnapshot::BucketListSnapshot (BucketList const & bl, uint32_t ledgerSeq)
17
+ : mLedgerSeq (ledgerSeq)
18
+ {
19
+ releaseAssert (threadIsMain ());
20
+
21
+ for (uint32_t i = 0 ; i < BucketList::kNumLevels ; ++i)
22
+ {
23
+ auto const & level = bl.getLevel (i);
24
+ mLevels .emplace_back (BucketLevelSnapshot (level));
25
+ }
26
+ }
27
+
28
+ std::vector<BucketLevelSnapshot> const &
29
+ BucketListSnapshot::getLevels () const
30
+ {
31
+ return mLevels ;
32
+ }
33
+
34
+ uint32_t
35
+ BucketListSnapshot::getLedgerSeq () const
36
+ {
37
+ return mLedgerSeq ;
38
+ }
39
+
16
40
void
17
41
SearchableBucketListSnapshot::loopAllBuckets (
18
- std::function<bool (SearchableBucketSnapshot const &)> f) const
42
+ std::function<bool (BucketSnapshot const &)> f) const
19
43
{
20
- for (auto const & lev : mLevels )
44
+ releaseAssert (mSnapshot );
45
+
46
+ for (auto const & lev : mSnapshot ->getLevels ())
21
47
{
22
48
// Return true if we should exit loop early
23
- auto processBucket = [f](SearchableBucketSnapshot const & b) {
49
+ auto processBucket = [f](BucketSnapshot const & b) {
24
50
if (b.isEmpty ())
25
51
{
26
52
return false ;
@@ -40,7 +66,7 @@ std::shared_ptr<LedgerEntry>
40
66
SearchableBucketListSnapshot::getLedgerEntry (LedgerKey const & k)
41
67
{
42
68
ZoneScoped;
43
- mSnapshotManager .maybeUpdateSnapshot (* this );
69
+ mSnapshotManager .maybeUpdateSnapshot (mSnapshot );
44
70
45
71
if (threadIsMain ())
46
72
{
@@ -58,7 +84,7 @@ SearchableBucketListSnapshot::getLedgerEntryInternal(LedgerKey const& k)
58
84
{
59
85
std::shared_ptr<LedgerEntry> result{};
60
86
61
- auto f = [&](SearchableBucketSnapshot const & b) {
87
+ auto f = [&](BucketSnapshot const & b) {
62
88
auto be = b.getBucketEntry (k);
63
89
if (be.has_value ())
64
90
{
@@ -86,7 +112,7 @@ SearchableBucketListSnapshot::loadKeysInternal(
86
112
87
113
// Make a copy of the key set, this loop is destructive
88
114
auto keys = inKeys;
89
- auto f = [&](SearchableBucketSnapshot const & b) {
115
+ auto f = [&](BucketSnapshot const & b) {
90
116
b.loadKeys (keys, entries);
91
117
return keys.empty ();
92
118
};
@@ -100,7 +126,7 @@ SearchableBucketListSnapshot::loadKeys(
100
126
std::set<LedgerKey, LedgerEntryIdCmp> const & inKeys)
101
127
{
102
128
ZoneScoped;
103
- mSnapshotManager .maybeUpdateSnapshot (* this );
129
+ mSnapshotManager .maybeUpdateSnapshot (mSnapshot );
104
130
105
131
if (threadIsMain ())
106
132
{
@@ -128,11 +154,11 @@ SearchableBucketListSnapshot::loadPoolShareTrustLinesByAccountAndAsset(
128
154
129
155
// This query should only be called during TX apply
130
156
releaseAssert (threadIsMain ());
131
- mSnapshotManager .maybeUpdateSnapshot (* this );
157
+ mSnapshotManager .maybeUpdateSnapshot (mSnapshot );
132
158
133
159
LedgerKeySet trustlinesToLoad;
134
160
135
- auto trustLineLoop = [&](SearchableBucketSnapshot const & b) {
161
+ auto trustLineLoop = [&](BucketSnapshot const & b) {
136
162
for (auto const & poolID : b.getPoolIDsByAsset (asset))
137
163
{
138
164
LedgerKey trustlineKey (TRUSTLINE);
@@ -159,7 +185,7 @@ SearchableBucketListSnapshot::loadInflationWinners(size_t maxWinners,
159
185
int64_t minBalance)
160
186
{
161
187
ZoneScoped;
162
- mSnapshotManager .maybeUpdateSnapshot (* this );
188
+ mSnapshotManager .maybeUpdateSnapshot (mSnapshot );
163
189
164
190
// This is a legacy query, should only be called by main thread during
165
191
// catchup
@@ -170,7 +196,7 @@ SearchableBucketListSnapshot::loadInflationWinners(size_t maxWinners,
170
196
UnorderedMap<AccountID, int64_t > voteCount;
171
197
UnorderedSet<AccountID> seen;
172
198
173
- auto countVotesInBucket = [&](SearchableBucketSnapshot const & b) {
199
+ auto countVotesInBucket = [&](BucketSnapshot const & b) {
174
200
for (BucketInputIterator in (b.getRawBucket ()); in; ++in)
175
201
{
176
202
BucketEntry const & be = *in;
@@ -246,22 +272,16 @@ SearchableBucketListSnapshot::loadInflationWinners(size_t maxWinners,
246
272
return winners;
247
273
}
248
274
249
- SearchableBucketLevelSnapshot::SearchableBucketLevelSnapshot (
250
- BucketLevel const & level)
275
+ BucketLevelSnapshot::BucketLevelSnapshot (BucketLevel const & level)
251
276
: curr(level.getCurr()), snap(level.getSnap())
252
277
{
253
278
}
254
279
255
- // This is not thread safe, must call while holding
256
- // BucketManager::mBucketListMutex.
257
280
SearchableBucketListSnapshot::SearchableBucketListSnapshot (
258
- BucketSnapshotManager const & snapshotManager, BucketList const & bl )
281
+ BucketSnapshotManager const & snapshotManager)
259
282
: mSnapshotManager (snapshotManager)
260
283
{
261
- for (uint32_t i = 0 ; i < BucketList::kNumLevels ; ++i)
262
- {
263
- auto const & level = bl.getLevel (i);
264
- mLevels .emplace_back (SearchableBucketLevelSnapshot (level));
265
- }
284
+ // Initialize snapshot from SnapshotManager
285
+ mSnapshotManager .maybeUpdateSnapshot (mSnapshot );
266
286
}
267
287
}
0 commit comments