Skip to content
This repository has been archived by the owner on Sep 26, 2019. It is now read-only.

[PAN-2325] Fix IndexOutOfBoundsException in DetermineCommonAncestorTask #1038

Merged
merged 9 commits into from
Mar 5, 2019

Conversation

mbaxter
Copy link
Contributor

@mbaxter mbaxter commented Mar 4, 2019

PR description

Fix issue where DetermineCommonAncestorTask could throw an IndexOutOfBoundsException when receiving an empty headers response.

Additionally, clean up tests a bit by deduplicating some setup code. Remove tests that were validating undefined behavior (what happens when we try to find an ancestor with a peer on a different chain altogether). Remove generic param from DetermineCommonAncestorTask. Add a few utility methods.

@@ -220,7 +220,7 @@ public int getWorldStateMaxRequestsWithoutProgress() {
private Range<Long> blockPropagationRange = Range.closed(-10L, 30L);
private long downloaderChangeTargetThresholdByHeight = 20L;
private UInt256 downloaderChangeTargetThresholdByTd = UInt256.of(1_000_000_000L);
private int downloaderHeaderRequestSize = 10;
private int downloaderHeaderRequestSize = 200;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Somewhat unrelated, but I see no reason not to bump up this value.

This will mean we request larger chunks of headers when running DetermineCommonAncestorTask. We'll also request a larger number of checkpoint headers when downloading.

public void shouldFailIfPeerDisconnects() {
final Block block = blockDataGenerator.nextBlock(localBlockchain.getChainHeadBlock());
localBlockchain.appendBlock(block, blockDataGenerator.receipts(block));
public void shouldHandleEmptyResponses() {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added this test to validate the bug fix.

@@ -57,57 +58,34 @@

public class DetermineCommonAncestorTaskTest {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file looks pretty messy, but in summary: 1 test was added for the bug fix, 2 tests for undefined behavior were removed, the generic param on this task was removed, and otherwise there's just a little bit of cleanup / reorganization.

final WorldStateArchive worldStateArchive = createInMemoryWorldStateArchive();
ethProtocolManager = EthProtocolManagerTestUtil.create(localBlockchain, worldStateArchive);
ethContext = ethProtocolManager.ethContext();
protocolContext = new ProtocolContext<>(localBlockchain, worldStateArchive, null);
}

@Test
public void shouldThrowExceptionNoCommonBlock() {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed this test.

@@ -184,104 +160,24 @@ public void shouldCorrectlyCalculateSkipIntervalAndCount() {
assertThat(skipInterval).isEqualTo(9);
}

@Test
public void shouldGracefullyHandleExecutionsForNoCommonAncestor() {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed this test.

@@ -142,8 +148,13 @@ static int calculateCount(final double range, final int skipInterval) {

private CompletableFuture<Void> processHeaders(
final AbstractPeerTask.PeerTaskResult<List<BlockHeader>> headersResult) {
final CompletableFuture<Void> processingResult = CompletableFuture.completedFuture(null);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

optional nit: do we need to hold a variable for this? we can call CompletableFuture.completedFuture(null) in both returns and never use it more than once. Feels like too much normalization.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I think it does end up being a bit confusing. I'll clean this up.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

@mbaxter mbaxter merged commit 4576e55 into PegaSysEng:master Mar 5, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants