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

Commit

Permalink
Rework Ibft's MessageValidatorFactory (#785)
Browse files Browse the repository at this point in the history
With a prior change swapping header validation for block
validation in the IBFT messages, the necessity to pass in the block
header was removed - though the code remained.

This change simplifies the MessageValidatorFactory interface to only
take the chain height (rather than the full parent header).
  • Loading branch information
rain-on authored Feb 6, 2019
1 parent 718ce9e commit 53cddb6
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public IbftBlockHeightManager(
this.roundChangeManager = roundChangeManager;
this.finalState = finalState;

newRoundMessageValidator = messageValidatorFactory.createNewRoundValidator(parentHeader);
newRoundMessageValidator = messageValidatorFactory.createNewRoundValidator(getChainHeight());

roundStateCreator =
(roundIdentifier) ->
Expand Down Expand Up @@ -255,7 +255,7 @@ public void handleNewRoundPayload(final NewRound newRound) {

@Override
public long getChainHeight() {
return currentRound.getRoundIdentifier().getSequenceNumber();
return parentHeader.getNumber() + 1;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ private BlockHeightManager createFullBlockHeightManager(final BlockHeader parent
finalState,
new RoundChangeManager(
IbftHelpers.calculateRequiredValidatorQuorum(finalState.getValidators().size()),
messageValidatorFactory.createRoundChangeMessageValidator(parentHeader)),
messageValidatorFactory.createRoundChangeMessageValidator(
parentHeader.getNumber() + 1L)),
roundFactory,
finalState.getClock(),
messageValidatorFactory);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import tech.pegasys.pantheon.ethereum.BlockValidator;
import tech.pegasys.pantheon.ethereum.ProtocolContext;
import tech.pegasys.pantheon.ethereum.core.Address;
import tech.pegasys.pantheon.ethereum.core.BlockHeader;
import tech.pegasys.pantheon.ethereum.mainnet.ProtocolSchedule;

import java.util.Collection;
Expand Down Expand Up @@ -58,20 +57,20 @@ public MessageValidator createMessageValidator(final ConsensusRoundIdentifier ro
return new MessageValidator(createSignedDataValidator(roundIdentifier));
}

public RoundChangeMessageValidator createRoundChangeMessageValidator(
final BlockHeader parentHeader) {
public RoundChangeMessageValidator createRoundChangeMessageValidator(final long chainHeight) {
final Collection<Address> validators =
protocolContext.getConsensusState().getVoteTally().getValidators();

return new RoundChangeMessageValidator(
new RoundChangePayloadValidator(
this::createSignedDataValidator,
validators,
prepareMessageCountForQuorum(
IbftHelpers.calculateRequiredValidatorQuorum(validators.size())),
parentHeader.getNumber() + 1));
chainHeight));
}

public NewRoundMessageValidator createNewRoundValidator(final BlockHeader parentHeader) {
public NewRoundMessageValidator createNewRoundValidator(final long chainHeight) {
final Collection<Address> validators =
protocolContext.getConsensusState().getVoteTally().getValidators();
return new NewRoundMessageValidator(
Expand All @@ -80,6 +79,6 @@ public NewRoundMessageValidator createNewRoundValidator(final BlockHeader parent
proposerSelector,
this::createSignedDataValidator,
IbftHelpers.calculateRequiredValidatorQuorum(validators.size()),
parentHeader.getNumber() + 1));
chainHeight));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ public void setup() {
when(finalState.getMessageFactory()).thenReturn(messageFactory);
when(blockCreator.createBlock(anyLong())).thenReturn(createdBlock);
when(newRoundPayloadValidator.validateNewRoundMessage(any())).thenReturn(true);
when(messageValidatorFactory.createNewRoundValidator(any()))
when(messageValidatorFactory.createNewRoundValidator(anyLong()))
.thenReturn(newRoundPayloadValidator);
when(messageValidatorFactory.createMessageValidator(any())).thenReturn(messageValidator);

Expand Down

0 comments on commit 53cddb6

Please sign in to comment.