Skip to content

Commit

Permalink
QBFT out of early access (hyperledger#3475)
Browse files Browse the repository at this point in the history
* QBFT out of early access
* Fixing typo IBFT -> QBFT (fixes hyperledger#3452)

Signed-off-by: Lucas Saldanha <lucascrsaldanha@gmail.com>
  • Loading branch information
lucassaldanha authored Feb 22, 2022
1 parent d48ad35 commit fb70ba4
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 38 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
- Add header validation rules needed to validate The Merge blocks [#3454](https://github.com/hyperledger/besu/pull/3454)
- Add core components: controller builder, protocol scheduler, coordinator, block creator and processor. [#3461](https://github.com/hyperledger/besu/pull/3461)
- Execution specific RPC endpoint [#2914](https://github.com/hyperledger/besu/issues/2914), [#3350](https://github.com/hyperledger/besu/pull/3350)
- QBFT consensus algorithm is production ready

### Bug Fixes

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,12 @@ public class IntegrationTestHelpers {
public static SignedData<CommitPayload> createSignedCommitPayload(
final ConsensusRoundIdentifier roundId, final Block block, final NodeKey nodeKey) {

final QbftExtraDataCodec ibftExtraDataEncoder = new QbftExtraDataCodec();
final QbftExtraDataCodec qbftExtraDataEncoder = new QbftExtraDataCodec();

final Block commitBlock = createCommitBlockFromProposalBlock(block, roundId.getRoundNumber());
final SECPSignature commitSeal =
nodeKey.sign(
new BftBlockHashing(ibftExtraDataEncoder)
new BftBlockHashing(qbftExtraDataEncoder)
.calculateDataHashForCommittedSeal(commitBlock.getHeader()));

final MessageFactory messageFactory = new MessageFactory(nodeKey);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -448,7 +448,7 @@ private static ControllerAndState createControllerAndFinalState(
final Address localAddress = Util.publicKeyToAddress(nodeKey.getPublicKey());
final BftBlockCreatorFactory blockCreatorFactory =
new QbftBlockCreatorFactory(
pendingTransactions, // changed from IbftBesuController
pendingTransactions, // changed from QbftBesuController
protocolContext,
protocolSchedule,
miningParams,
Expand Down Expand Up @@ -512,7 +512,7 @@ private static ControllerAndState createControllerAndFinalState(
BFT_EXTRA_DATA_ENCODER);

final EventMultiplexer eventMultiplexer = new EventMultiplexer(qbftController);
//////////////////////////// END IBFT BesuController ////////////////////////////
//////////////////////////// END QBFT BesuController ////////////////////////////

return new ControllerAndState(
bftExecutors,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@

import com.google.common.collect.Lists;

/** Class responsible for rebroadcasting IBFT messages to known validators */
/** Class responsible for rebroadcasting QBFT messages to known validators */
public class QbftGossip implements Gossiper {

private final ValidatorMulticaster multicaster;
Expand Down Expand Up @@ -74,7 +74,7 @@ public void send(final Message message) {
break;
default:
throw new IllegalArgumentException(
"Received message does not conform to any recognised IBFT message structure.");
"Received message does not conform to any recognised QBFT message structure.");
}
final List<Address> excludeAddressesList =
Lists.newArrayList(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ public void setup() {
setupContextWithBftExtraDataEncoder(
QbftContext.class, validators, new QbftExtraDataCodec()));

// Ensure the created IbftRound has the valid ConsensusRoundIdentifier;
// Ensure the created QbftRound has the valid ConsensusRoundIdentifier;
when(roundFactory.createNewRound(any(), anyInt()))
.thenAnswer(
invocation -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ public class QbftControllerTest {
private final ConsensusRoundIdentifier futureRoundIdentifier = new ConsensusRoundIdentifier(5, 0);
private final ConsensusRoundIdentifier roundIdentifier = new ConsensusRoundIdentifier(4, 0);
private final ConsensusRoundIdentifier pastRoundIdentifier = new ConsensusRoundIdentifier(3, 0);
@Mock private QbftGossip ibftGossip;
@Mock private QbftGossip qbftGossip;
@Mock private FutureMessageBuffer futureMessageBuffer;
private QbftController qbftController;

Expand All @@ -119,13 +119,13 @@ public void setup() {
when(messageTracker.hasSeenMessage(any())).thenReturn(false);
}

private void constructIbftController() {
private void constructQbftController() {
qbftController =
new QbftController(
blockChain,
bftFinalState,
blockHeightManagerFactory,
ibftGossip,
qbftGossip,
messageTracker,
futureMessageBuffer,
mock(EthSynchronizerUpdater.class),
Expand All @@ -134,7 +134,7 @@ private void constructIbftController() {

@Test
public void createsNewBlockHeightManagerWhenStarted() {
constructIbftController();
constructQbftController();
verify(blockHeightManagerFactory, never()).create(chainHeadBlockHeader);
qbftController.start();

Expand All @@ -155,7 +155,7 @@ public void startsNewBlockHeightManagerAndReplaysFutureMessages() {
when(blockHeightManager.getChainHeight()).thenReturn(5L);
when(futureMessageBuffer.retrieveMessagesForHeight(5L)).thenReturn(height2Msgs);

constructIbftController();
constructQbftController();
qbftController.start();

verify(futureMessageBuffer).retrieveMessagesForHeight(5L);
Expand All @@ -164,11 +164,11 @@ public void startsNewBlockHeightManagerAndReplaysFutureMessages() {
verify(blockHeightManager, atLeastOnce()).getChainHeight();
verify(blockHeightManager, never()).handleProposalPayload(proposal);
verify(blockHeightManager).handlePreparePayload(prepare);
verify(ibftGossip).send(prepareMessage);
verify(qbftGossip).send(prepareMessage);
verify(blockHeightManager).handleCommitPayload(commit);
verify(ibftGossip).send(commitMessage);
verify(qbftGossip).send(commitMessage);
verify(blockHeightManager).handleRoundChangePayload(roundChange);
verify(ibftGossip).send(roundChangeMessage);
verify(qbftGossip).send(roundChangeMessage);
}

@Test
Expand All @@ -184,7 +184,7 @@ public void createsNewBlockHeightManagerAndReplaysFutureMessagesOnNewChainHeadEv
.thenReturn(emptyList());
when(blockHeightManager.getChainHeight()).thenReturn(5L);

constructIbftController();
constructQbftController();
qbftController.start();
final NewChainHead newChainHead = new NewChainHead(nextBlock);
qbftController.handleNewBlockEvent(newChainHead);
Expand All @@ -193,18 +193,18 @@ public void createsNewBlockHeightManagerAndReplaysFutureMessagesOnNewChainHeadEv
verify(blockHeightManager, atLeastOnce()).getChainHeight();
verify(futureMessageBuffer, times(2)).retrieveMessagesForHeight(5L);
verify(blockHeightManager).handleProposalPayload(proposal);
verify(ibftGossip).send(proposalMessage);
verify(qbftGossip).send(proposalMessage);
verify(blockHeightManager).handlePreparePayload(prepare);
verify(ibftGossip).send(prepareMessage);
verify(qbftGossip).send(prepareMessage);
verify(blockHeightManager).handleCommitPayload(commit);
verify(ibftGossip).send(commitMessage);
verify(qbftGossip).send(commitMessage);
verify(blockHeightManager).handleRoundChangePayload(roundChange);
verify(ibftGossip).send(roundChangeMessage);
verify(qbftGossip).send(roundChangeMessage);
}

@Test
public void newBlockForCurrentOrPreviousHeightTriggersNoChange() {
constructIbftController();
constructQbftController();
qbftController.start();
long chainHeadHeight = chainHeadBlockHeader.getNumber();
when(nextBlock.getNumber()).thenReturn(chainHeadHeight);
Expand All @@ -223,7 +223,7 @@ public void newBlockForCurrentOrPreviousHeightTriggersNoChange() {
public void handlesRoundExpiry() {
final RoundExpiry roundExpiry = new RoundExpiry(roundIdentifier);

constructIbftController();
constructQbftController();
qbftController.start();
qbftController.handleRoundExpiry(roundExpiry);

Expand All @@ -234,7 +234,7 @@ public void handlesRoundExpiry() {
public void handlesBlockTimerExpiry() {
final BlockTimerExpiry blockTimerExpiry = new BlockTimerExpiry(roundIdentifier);

constructIbftController();
constructQbftController();
qbftController.start();
qbftController.handleBlockTimerExpiry(blockTimerExpiry);

Expand All @@ -244,55 +244,55 @@ public void handlesBlockTimerExpiry() {
@Test
public void proposalForCurrentHeightIsPassedToBlockHeightManager() {
setupProposal(roundIdentifier, validator);
constructIbftController();
constructQbftController();
qbftController.start();
qbftController.handleMessageEvent(new BftReceivedMessageEvent(proposalMessage));

verify(futureMessageBuffer, never()).addMessage(anyLong(), any());
verify(blockHeightManager).handleProposalPayload(proposal);
verify(ibftGossip).send(proposalMessage);
verify(qbftGossip).send(proposalMessage);
verify(blockHeightManager, atLeastOnce()).getChainHeight();
verifyNoMoreInteractions(blockHeightManager);
}

@Test
public void prepareForCurrentHeightIsPassedToBlockHeightManager() {
setupPrepare(roundIdentifier, validator);
constructIbftController();
constructQbftController();
qbftController.start();
qbftController.handleMessageEvent(new BftReceivedMessageEvent(prepareMessage));

verify(futureMessageBuffer, never()).addMessage(anyLong(), any());
verify(blockHeightManager).handlePreparePayload(prepare);
verify(ibftGossip).send(prepareMessage);
verify(qbftGossip).send(prepareMessage);
verify(blockHeightManager, atLeastOnce()).getChainHeight();
verifyNoMoreInteractions(blockHeightManager);
}

@Test
public void commitForCurrentHeightIsPassedToBlockHeightManager() {
setupCommit(roundIdentifier, validator);
constructIbftController();
constructQbftController();
qbftController.start();
qbftController.handleMessageEvent(new BftReceivedMessageEvent(commitMessage));

verify(futureMessageBuffer, never()).addMessage(anyLong(), any());
verify(blockHeightManager).handleCommitPayload(commit);
verify(ibftGossip).send(commitMessage);
verify(qbftGossip).send(commitMessage);
verify(blockHeightManager, atLeastOnce()).getChainHeight();
verifyNoMoreInteractions(blockHeightManager);
}

@Test
public void roundChangeForCurrentHeightIsPassedToBlockHeightManager() {
setupRoundChange(roundIdentifier, validator);
constructIbftController();
constructQbftController();
qbftController.start();
qbftController.handleMessageEvent(new BftReceivedMessageEvent(roundChangeMessage));

verify(futureMessageBuffer, never()).addMessage(anyLong(), any());
verify(blockHeightManager).handleRoundChangePayload(roundChange);
verify(ibftGossip).send(roundChangeMessage);
verify(qbftGossip).send(roundChangeMessage);
verify(blockHeightManager, atLeastOnce()).getChainHeight();
verifyNoMoreInteractions(blockHeightManager);
}
Expand Down Expand Up @@ -324,7 +324,7 @@ public void roundChangeForPastHeightIsDiscarded() {
@Test
public void roundExpiryForPastHeightIsDiscarded() {
final RoundExpiry roundExpiry = new RoundExpiry(pastRoundIdentifier);
constructIbftController();
constructQbftController();
qbftController.start();
qbftController.handleRoundExpiry(roundExpiry);
verify(futureMessageBuffer, never()).addMessage(anyLong(), any());
Expand All @@ -334,7 +334,7 @@ public void roundExpiryForPastHeightIsDiscarded() {
@Test
public void blockTimerForPastHeightIsDiscarded() {
final BlockTimerExpiry blockTimerExpiry = new BlockTimerExpiry(pastRoundIdentifier);
constructIbftController();
constructQbftController();
qbftController.start();
qbftController.handleBlockTimerExpiry(blockTimerExpiry);
verify(futureMessageBuffer, never()).addMessage(anyLong(), any());
Expand Down Expand Up @@ -401,7 +401,7 @@ public void duplicatedMessagesAreNotProcessed() {
public void uniqueMessagesAreAddedAsSeen() {
when(messageTracker.hasSeenMessage(proposalMessageData)).thenReturn(false);
setupProposal(roundIdentifier, validator);
constructIbftController();
constructQbftController();
qbftController.start();
qbftController.handleMessageEvent(new BftReceivedMessageEvent(proposalMessage));

Expand All @@ -411,7 +411,7 @@ public void uniqueMessagesAreAddedAsSeen() {
@Test
public void messagesWhichAreAboveHeightManagerButBelowBlockChainLengthAreDiscarded() {
// NOTE: for this to occur, the system would need to be synchronising - i.e. blockchain is
// moving up faster than ibft loop is handling NewBlock messages
// moving up faster than qbft loop is handling NewBlock messages
final long blockchainLength = 10L;
final long blockHeightManagerTargettingBlock = 6L;
final long messageHeight = 8L;
Expand All @@ -422,15 +422,15 @@ public void messagesWhichAreAboveHeightManagerButBelowBlockChainLengthAreDiscard
when(blockHeightManagerFactory.create(any())).thenReturn(blockHeightManager);
when(blockHeightManager.getChainHeight()).thenReturn(blockHeightManagerTargettingBlock);

constructIbftController();
constructQbftController();
qbftController.start();
qbftController.handleMessageEvent(new BftReceivedMessageEvent(proposalMessage));
verify(futureMessageBuffer, never()).addMessage(anyLong(), any());
verify(blockHeightManager, never()).handleProposalPayload(any());
}

private void verifyNotHandledAndNoFutureMsgs(final BftReceivedMessageEvent msg) {
constructIbftController();
constructQbftController();
qbftController.start();
qbftController.handleMessageEvent(msg);

Expand All @@ -440,7 +440,7 @@ private void verifyNotHandledAndNoFutureMsgs(final BftReceivedMessageEvent msg)
}

private void verifyHasFutureMessages(final long msgHeight, final Message message) {
constructIbftController();
constructQbftController();
qbftController.start();
qbftController.handleMessageEvent(new BftReceivedMessageEvent(message));

Expand Down

0 comments on commit fb70ba4

Please sign in to comment.