Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix skip list starting from protocol 22 #4470

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 16 additions & 5 deletions src/bucket/BucketManagerImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1101,16 +1101,19 @@ BucketManagerImpl::getBloomLookupMeter() const
void
BucketManagerImpl::calculateSkipValues(LedgerHeader& currentHeader)
{
bool startsFromV22 = protocolVersionStartsFrom(currentHeader.ledgerVersion,
ProtocolVersion::V_22);
auto skip1 = startsFromV22 ? SKIP_1_V22 : SKIP_1;

if ((currentHeader.ledgerSeq % SKIP_1) == 0)
if ((currentHeader.ledgerSeq % skip1) == 0)
{
int v = currentHeader.ledgerSeq - SKIP_1;
int v = currentHeader.ledgerSeq - skip1;
if (v > 0 && (v % SKIP_2) == 0)
{
v = currentHeader.ledgerSeq - SKIP_2 - SKIP_1;
v = currentHeader.ledgerSeq - SKIP_2 - skip1;
if (v > 0 && (v % SKIP_3) == 0)
{
v = currentHeader.ledgerSeq - SKIP_3 - SKIP_2 - SKIP_1;
v = currentHeader.ledgerSeq - SKIP_3 - SKIP_2 - skip1;
if (v > 0 && (v % SKIP_4) == 0)
{

Expand All @@ -1120,7 +1123,15 @@ BucketManagerImpl::calculateSkipValues(LedgerHeader& currentHeader)
}
currentHeader.skipList[1] = currentHeader.skipList[0];
}
currentHeader.skipList[0] = currentHeader.bucketListHash;

if (startsFromV22)
{
currentHeader.skipList[0] = currentHeader.previousLedgerHash;
}
else
{
currentHeader.skipList[0] = currentHeader.bucketListHash;
}
}
}

Expand Down
2 changes: 2 additions & 0 deletions src/bucket/BucketManagerImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,8 @@ class BucketManagerImpl : public BucketManager
};

#define SKIP_1 50
#define SKIP_1_V22 500

#define SKIP_2 5000
#define SKIP_3 50000
#define SKIP_4 500000
Expand Down
142 changes: 77 additions & 65 deletions src/bucket/test/BucketManagerTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,71 +119,83 @@ TEST_CASE("skip list", "[bucket][bucketmanager]")
Hash h6 = HashUtils::pseudoRandomForTesting();
Hash h7 = HashUtils::pseudoRandomForTesting();

// up first entry
LedgerHeader header;
header.ledgerSeq = 5;
header.bucketListHash = h1;
calculateSkipValues(header);
REQUIRE(header.skipList[0] == h0);
REQUIRE(header.skipList[1] == h0);
REQUIRE(header.skipList[2] == h0);
REQUIRE(header.skipList[3] == h0);

header.ledgerSeq = SKIP_1;
header.bucketListHash = h2;
calculateSkipValues(header);
REQUIRE(header.skipList[0] == h2);
REQUIRE(header.skipList[1] == h0);
REQUIRE(header.skipList[2] == h0);
REQUIRE(header.skipList[3] == h0);

header.ledgerSeq = SKIP_1 * 2;
header.bucketListHash = h3;
calculateSkipValues(header);
REQUIRE(header.skipList[0] == h3);
REQUIRE(header.skipList[1] == h0);
REQUIRE(header.skipList[2] == h0);
REQUIRE(header.skipList[3] == h0);

header.ledgerSeq = SKIP_1 * 2 + 1;
header.bucketListHash = h2;
calculateSkipValues(header);
REQUIRE(header.skipList[0] == h3);
REQUIRE(header.skipList[1] == h0);
REQUIRE(header.skipList[2] == h0);
REQUIRE(header.skipList[3] == h0);

header.ledgerSeq = SKIP_2;
header.bucketListHash = h4;
calculateSkipValues(header);
REQUIRE(header.skipList[0] == h4);
REQUIRE(header.skipList[1] == h0);
REQUIRE(header.skipList[2] == h0);
REQUIRE(header.skipList[3] == h0);

header.ledgerSeq = SKIP_2 + SKIP_1;
header.bucketListHash = h5;
calculateSkipValues(header);
REQUIRE(header.skipList[0] == h5);
REQUIRE(header.skipList[1] == h4);
REQUIRE(header.skipList[2] == h0);
REQUIRE(header.skipList[3] == h0);

header.ledgerSeq = SKIP_3 + SKIP_2;
header.bucketListHash = h6;
calculateSkipValues(header);
REQUIRE(header.skipList[0] == h6);
REQUIRE(header.skipList[1] == h4);
REQUIRE(header.skipList[2] == h0);
REQUIRE(header.skipList[3] == h0);

header.ledgerSeq = SKIP_3 + SKIP_2 + SKIP_1;
header.bucketListHash = h7;
calculateSkipValues(header);
REQUIRE(header.skipList[0] == h7);
REQUIRE(header.skipList[1] == h6);
REQUIRE(header.skipList[2] == h4);
REQUIRE(header.skipList[3] == h0);
for (size_t i = 21; i <= 22; ++i)
{
// up first entry
LedgerHeader header;
header.ledgerSeq = 5;
header.ledgerVersion = i;

bool isBeforeV22 = protocolVersionIsBefore(
header.ledgerVersion, ProtocolVersion::V_22);

auto& hashFieldToUse = isBeforeV22 ? header.bucketListHash
: header.previousLedgerHash;

calculateSkipValues(header);
REQUIRE(header.skipList[0] == h0);
REQUIRE(header.skipList[1] == h0);
REQUIRE(header.skipList[2] == h0);
REQUIRE(header.skipList[3] == h0);

auto skip1 = isBeforeV22 ? SKIP_1 : SKIP_1_V22;

header.ledgerSeq = skip1;
hashFieldToUse = h2;
calculateSkipValues(header);
REQUIRE(header.skipList[0] == h2);
REQUIRE(header.skipList[1] == h0);
REQUIRE(header.skipList[2] == h0);
REQUIRE(header.skipList[3] == h0);

header.ledgerSeq = skip1 * 2;
hashFieldToUse = h3;
calculateSkipValues(header);
REQUIRE(header.skipList[0] == h3);
REQUIRE(header.skipList[1] == h0);
REQUIRE(header.skipList[2] == h0);
REQUIRE(header.skipList[3] == h0);

header.ledgerSeq = skip1 * 2 + 1;
hashFieldToUse = h2;
calculateSkipValues(header);
REQUIRE(header.skipList[0] == h3);
REQUIRE(header.skipList[1] == h0);
REQUIRE(header.skipList[2] == h0);
REQUIRE(header.skipList[3] == h0);

header.ledgerSeq = SKIP_2;
hashFieldToUse = h4;
calculateSkipValues(header);
REQUIRE(header.skipList[0] == h4);
REQUIRE(header.skipList[1] == h0);
REQUIRE(header.skipList[2] == h0);
REQUIRE(header.skipList[3] == h0);

header.ledgerSeq = SKIP_2 + skip1;
hashFieldToUse = h5;
calculateSkipValues(header);
REQUIRE(header.skipList[0] == h5);
REQUIRE(header.skipList[1] == h4);
REQUIRE(header.skipList[2] == h0);
REQUIRE(header.skipList[3] == h0);

header.ledgerSeq = SKIP_3 + SKIP_2;
hashFieldToUse = h6;
calculateSkipValues(header);
REQUIRE(header.skipList[0] == h6);
REQUIRE(header.skipList[1] == h4);
REQUIRE(header.skipList[2] == h0);
REQUIRE(header.skipList[3] == h0);

header.ledgerSeq = SKIP_3 + SKIP_2 + skip1;
hashFieldToUse = h7;
calculateSkipValues(header);
REQUIRE(header.skipList[0] == h7);
REQUIRE(header.skipList[1] == h6);
REQUIRE(header.skipList[2] == h4);
REQUIRE(header.skipList[3] == h0);
}
}
};

Expand Down
Loading