Skip to content

Commit d7adda1

Browse files
committed
Fix off by one and rebase
1 parent 69d1658 commit d7adda1

4 files changed

+20
-6
lines changed

src/bucket/BucketApplicator.cpp

+17-4
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,18 @@ BucketApplicator::BucketApplicator(Application& app,
4545
if (newOffersOnly && !bucket->isEmpty())
4646
{
4747
releaseAssertOrThrow(mApp.getConfig().isUsingBucketListDB());
48-
auto [lowOffset, highOffset] = bucket->getOfferRange();
49-
mBucketIter.seek(lowOffset);
50-
mUpperBoundOffset = highOffset;
48+
auto offsetOp = bucket->getOfferRange();
49+
if (offsetOp)
50+
{
51+
auto [lowOffset, highOffset] = *offsetOp;
52+
mBucketIter.seek(lowOffset);
53+
mUpperBoundOffset = highOffset;
54+
}
55+
else
56+
{
57+
// No offers in Bucket
58+
mOffersRemaining = false;
59+
}
5160
}
5261
}
5362

@@ -112,7 +121,11 @@ BucketApplicator::advance(BucketApplicator::Counters& counters)
112121

113122
for (; mBucketIter; ++mBucketIter)
114123
{
115-
if (mNewOffersOnly && mBucketIter.pos() >= mUpperBoundOffset)
124+
// Note: mUpperBoundOffset is not inclusive. However, mBucketIter.pos()
125+
// returns the file offset at the end of the currently loaded entry.
126+
// This means we must read until pos is strictly greater than the upper
127+
// bound so that we don't skip the last offer in the range.
128+
if (mNewOffersOnly && mBucketIter.pos() > mUpperBoundOffset)
116129
{
117130
mOffersRemaining = false;
118131
break;

src/bucket/BucketIndexImpl.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -485,6 +485,7 @@ BucketIndexImpl<IndexT>::getPoolIDsByAsset(Asset const& asset) const
485485
return iter->second;
486486
}
487487

488+
template <class IndexT>
488489
std::optional<std::pair<std::streamoff, std::streamoff>>
489490
BucketIndexImpl<IndexT>::getPoolshareTrustlineRange(
490491
AccountID const& accountID) const

src/bucket/BucketInputIterator.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ BucketInputIterator::loadEntry()
5252
}
5353
}
5454

55-
size_t
55+
std::streamoff
5656
BucketInputIterator::pos()
5757
{
5858
return mIn.pos();

src/bucket/BucketInputIterator.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ class BucketInputIterator
5252

5353
BucketInputIterator& operator++();
5454

55-
size_t pos();
55+
std::streamoff pos();
5656
size_t size() const;
5757
void seek(std::streamoff offset);
5858
};

0 commit comments

Comments
 (0)