From d7adda1c0ed932aebd5f3426e4239fb4cbd5dc1f Mon Sep 17 00:00:00 2001 From: Garand Tyson Date: Wed, 14 Feb 2024 11:38:13 -0800 Subject: [PATCH] Fix off by one and rebase --- src/bucket/BucketApplicator.cpp | 21 +++++++++++++++++---- src/bucket/BucketIndexImpl.cpp | 1 + src/bucket/BucketInputIterator.cpp | 2 +- src/bucket/BucketInputIterator.h | 2 +- 4 files changed, 20 insertions(+), 6 deletions(-) diff --git a/src/bucket/BucketApplicator.cpp b/src/bucket/BucketApplicator.cpp index d93cf63a1a..bdfba04cb7 100644 --- a/src/bucket/BucketApplicator.cpp +++ b/src/bucket/BucketApplicator.cpp @@ -45,9 +45,18 @@ BucketApplicator::BucketApplicator(Application& app, if (newOffersOnly && !bucket->isEmpty()) { releaseAssertOrThrow(mApp.getConfig().isUsingBucketListDB()); - auto [lowOffset, highOffset] = bucket->getOfferRange(); - mBucketIter.seek(lowOffset); - mUpperBoundOffset = highOffset; + auto offsetOp = bucket->getOfferRange(); + if (offsetOp) + { + auto [lowOffset, highOffset] = *offsetOp; + mBucketIter.seek(lowOffset); + mUpperBoundOffset = highOffset; + } + else + { + // No offers in Bucket + mOffersRemaining = false; + } } } @@ -112,7 +121,11 @@ BucketApplicator::advance(BucketApplicator::Counters& counters) for (; mBucketIter; ++mBucketIter) { - if (mNewOffersOnly && mBucketIter.pos() >= mUpperBoundOffset) + // Note: mUpperBoundOffset is not inclusive. However, mBucketIter.pos() + // returns the file offset at the end of the currently loaded entry. + // This means we must read until pos is strictly greater than the upper + // bound so that we don't skip the last offer in the range. + if (mNewOffersOnly && mBucketIter.pos() > mUpperBoundOffset) { mOffersRemaining = false; break; diff --git a/src/bucket/BucketIndexImpl.cpp b/src/bucket/BucketIndexImpl.cpp index bb6259d4e0..72258c5335 100644 --- a/src/bucket/BucketIndexImpl.cpp +++ b/src/bucket/BucketIndexImpl.cpp @@ -485,6 +485,7 @@ BucketIndexImpl::getPoolIDsByAsset(Asset const& asset) const return iter->second; } +template std::optional> BucketIndexImpl::getPoolshareTrustlineRange( AccountID const& accountID) const diff --git a/src/bucket/BucketInputIterator.cpp b/src/bucket/BucketInputIterator.cpp index 79f65e3dc8..7a3673b7f4 100644 --- a/src/bucket/BucketInputIterator.cpp +++ b/src/bucket/BucketInputIterator.cpp @@ -52,7 +52,7 @@ BucketInputIterator::loadEntry() } } -size_t +std::streamoff BucketInputIterator::pos() { return mIn.pos(); diff --git a/src/bucket/BucketInputIterator.h b/src/bucket/BucketInputIterator.h index 43e815e376..b9280ecad8 100644 --- a/src/bucket/BucketInputIterator.h +++ b/src/bucket/BucketInputIterator.h @@ -52,7 +52,7 @@ class BucketInputIterator BucketInputIterator& operator++(); - size_t pos(); + std::streamoff pos(); size_t size() const; void seek(std::streamoff offset); };