This repository has been archived by the owner on Sep 26, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 130
IBFT Integration Tests - Future Height #591
Merged
Merged
Changes from 2 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
7ffa88a
IBFT Integration Tests - Future Height
4d1e7af
Update IbftController tests
961ddb0
Extended ibftcontroller tests
e43f4be
Added test to ensure the correct height buffered msgs are used
21c2cd0
Merge branch 'master' into int_test_futureHeight
rain-on 91ac880
Merge branch 'master' into int_test_futureHeight
rain-on File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
175 changes: 175 additions & 0 deletions
175
...rc/integration-test/java/tech/pegasys/pantheon/consensus/ibft/tests/FutureHeightTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,175 @@ | ||
/* | ||
* Copyright 2019 ConsenSys AG. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on | ||
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations under the License. | ||
*/ | ||
package tech.pegasys.pantheon.consensus.ibft.tests; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static org.assertj.core.util.Lists.emptyList; | ||
import static tech.pegasys.pantheon.consensus.ibft.support.MessageReceptionHelpers.assertPeersReceivedExactly; | ||
import static tech.pegasys.pantheon.consensus.ibft.support.MessageReceptionHelpers.assertPeersReceivedNoMessages; | ||
import static tech.pegasys.pantheon.consensus.ibft.support.TestHelpers.createSignedCommentPayload; | ||
|
||
import tech.pegasys.pantheon.consensus.ibft.ConsensusRoundIdentifier; | ||
import tech.pegasys.pantheon.consensus.ibft.IbftHelpers; | ||
import tech.pegasys.pantheon.consensus.ibft.ibftevent.NewChainHead; | ||
import tech.pegasys.pantheon.consensus.ibft.payload.CommitPayload; | ||
import tech.pegasys.pantheon.consensus.ibft.payload.MessageFactory; | ||
import tech.pegasys.pantheon.consensus.ibft.payload.PreparePayload; | ||
import tech.pegasys.pantheon.consensus.ibft.payload.SignedData; | ||
import tech.pegasys.pantheon.consensus.ibft.support.RoundSpecificNodeRoles; | ||
import tech.pegasys.pantheon.consensus.ibft.support.TestContext; | ||
import tech.pegasys.pantheon.consensus.ibft.support.TestContextFactory; | ||
import tech.pegasys.pantheon.ethereum.core.Block; | ||
|
||
import java.time.Clock; | ||
import java.time.Instant; | ||
import java.time.ZoneId; | ||
import java.util.stream.Collectors; | ||
|
||
import org.junit.Before; | ||
import org.junit.Test; | ||
|
||
public class FutureHeightTest { | ||
|
||
private final long blockTimeStamp = 100; | ||
private final Clock fixedClock = | ||
Clock.fixed(Instant.ofEpochSecond(blockTimeStamp), ZoneId.systemDefault()); | ||
|
||
private final int NETWORK_SIZE = 5; | ||
|
||
// Local node is not the first proposer for the current round. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this message correct? where or what is local node ...I don't see a field with that name There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not sure how to handle this - but all integration tests are exercising the ibftController embedded in the TestContext - which I treat/consider the localNode. Would love better nomenclature. |
||
private final TestContext context = | ||
TestContextFactory.createTestEnvironment(NETWORK_SIZE, 0, fixedClock); | ||
|
||
private final ConsensusRoundIdentifier roundId = new ConsensusRoundIdentifier(1, 0); | ||
private final RoundSpecificNodeRoles roles = context.getRoundSpecificRoles(roundId); | ||
|
||
private final ConsensusRoundIdentifier futureHeightRoundId = new ConsensusRoundIdentifier(2, 0); | ||
|
||
private final MessageFactory localNodeMessageFactory = context.getLocalNodeMessageFactory(); | ||
|
||
@Before | ||
public void setup() { | ||
context.getController().start(); | ||
} | ||
|
||
@Test | ||
public void messagesForFutureHeightAreBufferedUntilChainHeightCatchesUp() { | ||
jframe marked this conversation as resolved.
Show resolved
Hide resolved
|
||
final Block currentHeightBlock = context.createBlockForProposalFromChainHead(0, 30); | ||
final Block signedCurrentHeightBlock = | ||
IbftHelpers.createSealedBlock( | ||
currentHeightBlock, | ||
roles | ||
.getAllPeers() | ||
.stream() | ||
.map(peer -> peer.getBlockSignature(currentHeightBlock.getHash())) | ||
.collect(Collectors.toList())); | ||
|
||
final Block futureHeightBlock = | ||
context.createBlockForProposal(signedCurrentHeightBlock.getHeader(), 0, 60); | ||
|
||
roles.getProposer().injectProposal(futureHeightRoundId, futureHeightBlock); | ||
assertPeersReceivedNoMessages(roles.getAllPeers()); | ||
|
||
// Inject prepares and commits from all peers | ||
roles | ||
.getNonProposingPeers() | ||
.forEach( | ||
p -> { | ||
p.injectPrepare(futureHeightRoundId, futureHeightBlock.getHash()); | ||
p.injectCommit(futureHeightRoundId, futureHeightBlock.getHash()); | ||
}); | ||
assertPeersReceivedNoMessages(roles.getAllPeers()); | ||
assertThat(context.getCurrentChainHeight()).isEqualTo(0); | ||
|
||
// Add block to chain, and notify system of its arrival. | ||
context.getBlockchain().appendBlock(signedCurrentHeightBlock, emptyList()); | ||
assertThat(context.getCurrentChainHeight()).isEqualTo(1); | ||
context | ||
.getController() | ||
.handleNewBlockEvent(new NewChainHead(signedCurrentHeightBlock.getHeader())); | ||
|
||
final SignedData<PreparePayload> expectedPrepareMessage = | ||
localNodeMessageFactory.createSignedPreparePayload( | ||
futureHeightRoundId, futureHeightBlock.getHash()); | ||
|
||
final SignedData<CommitPayload> expectedCommitMessage = | ||
createSignedCommentPayload( | ||
futureHeightRoundId, futureHeightBlock, context.getLocalNodeParams().getNodeKeyPair()); | ||
|
||
assertPeersReceivedExactly(roles.getAllPeers(), expectedPrepareMessage, expectedCommitMessage); | ||
assertThat(context.getCurrentChainHeight()).isEqualTo(2); | ||
} | ||
|
||
@Test | ||
public void messagesFromPreviousHeightAreDiscarded() { | ||
final Block currentHeightBlock = context.createBlockForProposalFromChainHead(0, 30); | ||
final Block signedCurrentHeightBlock = | ||
IbftHelpers.createSealedBlock( | ||
currentHeightBlock, | ||
roles | ||
.getAllPeers() | ||
.stream() | ||
.map(peer -> peer.getBlockSignature(currentHeightBlock.getHash())) | ||
.collect(Collectors.toList())); | ||
|
||
roles.getProposer().injectProposal(roundId, currentHeightBlock); | ||
roles.getNonProposingPeer(0).injectPrepare(roundId, currentHeightBlock.getHash()); | ||
|
||
final SignedData<PreparePayload> expectedPrepareMessage = | ||
localNodeMessageFactory.createSignedPreparePayload(roundId, currentHeightBlock.getHash()); | ||
|
||
assertPeersReceivedExactly(roles.getAllPeers(), expectedPrepareMessage); | ||
|
||
// Add block to chain, and notify system of its arrival. | ||
context.getBlockchain().appendBlock(signedCurrentHeightBlock, emptyList()); | ||
assertThat(context.getCurrentChainHeight()).isEqualTo(1); | ||
context | ||
.getController() | ||
.handleNewBlockEvent(new NewChainHead(signedCurrentHeightBlock.getHeader())); | ||
|
||
// Inject prepares and commits from all peers for the 'previous' round (i.e. the height | ||
// from before the block arrived). | ||
roles | ||
.getNonProposingPeers() | ||
.forEach( | ||
p -> { | ||
p.injectPrepare(roundId, currentHeightBlock.getHash()); | ||
p.injectCommit(roundId, currentHeightBlock.getHash()); | ||
}); | ||
assertPeersReceivedNoMessages(roles.getAllPeers()); | ||
assertThat(context.getCurrentChainHeight()).isEqualTo(1); | ||
} | ||
|
||
@Test | ||
public void multipleNewChainHeadEventsDoesNotRestartCurrentHeightManager() { | ||
final Block currentHeightBlock = context.createBlockForProposalFromChainHead(0, 30); | ||
|
||
roles.getProposer().injectProposal(roundId, currentHeightBlock); | ||
roles.getNonProposingPeer(0).injectPrepare(roundId, currentHeightBlock.getHash()); | ||
|
||
roles.getAllPeers().forEach(peer -> peer.clearReceivedMessages()); | ||
|
||
// inject a NewHeight FOR THE CURRENT HEIGHT | ||
context | ||
.getController() | ||
.handleNewBlockEvent(new NewChainHead(context.getBlockchain().getChainHeadHeader())); | ||
|
||
// Should only require 1 more prepare to close it out | ||
roles.getNonProposingPeer(1).injectPrepare(roundId, currentHeightBlock.getHash()); | ||
|
||
final SignedData<CommitPayload> expectedCommitMessage = | ||
createSignedCommentPayload( | ||
roundId, currentHeightBlock, context.getLocalNodeParams().getNodeKeyPair()); | ||
assertPeersReceivedExactly(roles.getAllPeers(), expectedCommitMessage); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like the consistency with other methods 👍