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 1 commit
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
11 changes: 10 additions & 1 deletion src/bucket/BucketManagerImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1120,7 +1120,16 @@ BucketManagerImpl::calculateSkipValues(LedgerHeader& currentHeader)
}
currentHeader.skipList[1] = currentHeader.skipList[0];
}
currentHeader.skipList[0] = currentHeader.bucketListHash;

if (protocolVersionStartsFrom(currentHeader.ledgerVersion,
ProtocolVersion::V_22))
{
currentHeader.skipList[0] = currentHeader.previousLedgerHash;
}
else
{
currentHeader.skipList[0] = currentHeader.bucketListHash;
}
}
}

Expand Down
139 changes: 74 additions & 65 deletions src/bucket/test/BucketManagerTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,71 +119,80 @@ 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;
auto& hashFieldToUse =
protocolVersionIsBefore(header.ledgerVersion,
ProtocolVersion::V_22)
? 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);

header.ledgerSeq = SKIP_1;
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 = SKIP_1 * 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 = SKIP_1 * 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 + SKIP_1;
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 + SKIP_1;
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