9
9
#include " bucket/BucketManager.h"
10
10
#include " catchup/AssumeStateWork.h"
11
11
#include " catchup/CatchupManager.h"
12
+ #include " catchup/IndexBucketsWork.h"
12
13
#include " crypto/Hex.h"
13
14
#include " crypto/SecretKey.h"
14
15
#include " historywork/Progress.h"
@@ -108,7 +109,7 @@ ApplyBucketsWork::getBucketLevel(uint32_t level)
108
109
return mApp .getBucketManager ().getBucketList ().getLevel (level);
109
110
}
110
111
111
- std::shared_ptr<Bucket const >
112
+ std::shared_ptr<Bucket>
112
113
ApplyBucketsWork::getBucket (std::string const & hash)
113
114
{
114
115
auto i = mBuckets .find (hash);
@@ -134,17 +135,18 @@ ApplyBucketsWork::doReset()
134
135
mLastPos = 0 ;
135
136
mMinProtocolVersionSeen = UINT32_MAX;
136
137
mSeenKeys .clear ();
137
-
138
- if (mOffersOnly )
139
- {
140
- // The current size of this set is 1.6 million during BucketApply (as of
141
- // 12/20/23). There's not a great way to estimate this, so reserving
142
- // with some extra wiggle room
143
- mSeenKeys .reserve (2'000'000 );
144
- }
138
+ mBucketsToIndex .clear ();
145
139
146
140
if (!isAborting ())
147
141
{
142
+ if (mOffersOnly )
143
+ {
144
+ // The current size of this set is 1.6 million during BucketApply
145
+ // (as of 12/20/23). There's not a great way to estimate this, so
146
+ // reserving with some extra wiggle room
147
+ mSeenKeys .reserve (2'000'000 );
148
+ }
149
+
148
150
// When applying buckets with accounts, we have to make sure that the
149
151
// root account has been removed. This comes into play, for example,
150
152
// when applying buckets from genesis the root account already exists.
@@ -164,12 +166,17 @@ ApplyBucketsWork::doReset()
164
166
}
165
167
}
166
168
167
- auto addBucket = [this ](std::shared_ptr<Bucket const > const & bucket) {
169
+ auto addBucket = [this ](std::shared_ptr<Bucket> const & bucket) {
168
170
if (bucket->getSize () > 0 )
169
171
{
170
172
mTotalBuckets ++;
171
173
mTotalSize += bucket->getSize ();
172
174
}
175
+
176
+ if (mOffersOnly )
177
+ {
178
+ mBucketsToIndex .emplace_back (bucket);
179
+ }
173
180
};
174
181
175
182
for (auto const & hsb : mApplyState .currentBuckets )
@@ -280,7 +287,34 @@ ApplyBucketsWork::doWork()
280
287
{
281
288
ZoneScoped;
282
289
283
- // Step 1: apply buckets. Step 2: assume state
290
+ // Step 1: index buckets. Step 2: apply buckets. Step 3: assume state
291
+ if (!mSpawnedIndexBucketsWork )
292
+ {
293
+ if (mOffersOnly )
294
+ {
295
+ addWork<IndexBucketsWork>(mBucketsToIndex );
296
+ }
297
+ else
298
+ {
299
+ mFinishedIndexBucketsWork = true ;
300
+ }
301
+
302
+ mSpawnedIndexBucketsWork = true ;
303
+ }
304
+
305
+ if (!mFinishedIndexBucketsWork )
306
+ {
307
+ auto status = checkChildrenStatus ();
308
+ if (status == BasicWork::State::WORK_SUCCESS)
309
+ {
310
+ mFinishedIndexBucketsWork = true ;
311
+ }
312
+ else
313
+ {
314
+ return status;
315
+ }
316
+ }
317
+
284
318
if (!mSpawnedAssumeStateWork )
285
319
{
286
320
if (mApp .getLedgerManager ().rebuildingInMemoryState () && !mDelayChecked )
@@ -319,8 +353,8 @@ ApplyBucketsWork::doWork()
319
353
return State::WORK_RUNNING;
320
354
}
321
355
mApp .getInvariantManager ().checkOnBucketApply (
322
- mFirstBucket , mApplyState .currentLedger , mLevel , false ,
323
- mEntryTypeFilter );
356
+ mFirstBucket , mApplyState .currentLedger , mLevel ,
357
+ /* isCurr= */ mOffersOnly , mEntryTypeFilter );
324
358
mFirstBucketApplicator .reset ();
325
359
mFirstBucket .reset ();
326
360
mApp .getCatchupManager ().bucketsApplied ();
@@ -335,8 +369,8 @@ ApplyBucketsWork::doWork()
335
369
return State::WORK_RUNNING;
336
370
}
337
371
mApp .getInvariantManager ().checkOnBucketApply (
338
- mSecondBucket , mApplyState .currentLedger , mLevel , true ,
339
- mEntryTypeFilter );
372
+ mSecondBucket , mApplyState .currentLedger , mLevel ,
373
+ /* isCurr= */ ! mOffersOnly , mEntryTypeFilter );
340
374
mSecondBucketApplicator .reset ();
341
375
mSecondBucket .reset ();
342
376
mApp .getCatchupManager ().bucketsApplied ();
@@ -412,7 +446,9 @@ ApplyBucketsWork::isLevelComplete()
412
446
std::string
413
447
ApplyBucketsWork::getStatus () const
414
448
{
415
- if (!mSpawnedAssumeStateWork )
449
+ // This status string only applies to step 2 when we actually apply the
450
+ // buckets.
451
+ if (mFinishedIndexBucketsWork && !mSpawnedAssumeStateWork )
416
452
{
417
453
auto size = mTotalSize == 0 ? 0 : (100 * mAppliedSize / mTotalSize );
418
454
return fmt::format (
0 commit comments