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

Commit

Permalink
Rework IbftRoundFactory (#784)
Browse files Browse the repository at this point in the history
The IbftRoundFactory creates a MessageValidator for use within the
newly created round, however it does this bypassing the established
factory classes (MessageValidatorFactory).

This commit updates the IbftRoundFactory to use the correct API for
creating the message validator.
  • Loading branch information
rain-on authored Feb 6, 2019
1 parent e4291e6 commit 6535d78
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,11 @@ private static ControllerAndState createControllerAndFinalState(
new IbftBlockHeightManagerFactory(
finalState,
new IbftRoundFactory(
finalState, protocolContext, protocolSchedule, minedBlockObservers),
finalState,
protocolContext,
protocolSchedule,
minedBlockObservers,
messageValidatorFactory),
messageValidatorFactory),
gossiper,
new HashMap<>());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@
import tech.pegasys.pantheon.consensus.ibft.IbftContext;
import tech.pegasys.pantheon.consensus.ibft.blockcreation.IbftBlockCreator;
import tech.pegasys.pantheon.consensus.ibft.blockcreation.IbftBlockCreatorFactory;
import tech.pegasys.pantheon.consensus.ibft.validation.MessageValidator;
import tech.pegasys.pantheon.consensus.ibft.validation.SignedDataValidator;
import tech.pegasys.pantheon.ethereum.BlockValidator;
import tech.pegasys.pantheon.consensus.ibft.validation.MessageValidatorFactory;
import tech.pegasys.pantheon.ethereum.ProtocolContext;
import tech.pegasys.pantheon.ethereum.chain.MinedBlockObserver;
import tech.pegasys.pantheon.ethereum.core.BlockHeader;
Expand All @@ -31,38 +29,32 @@ public class IbftRoundFactory {
private final ProtocolContext<IbftContext> protocolContext;
private final ProtocolSchedule<IbftContext> protocolSchedule;
private final Subscribers<MinedBlockObserver> minedBlockObservers;
private final MessageValidatorFactory messageValidatorFactory;

public IbftRoundFactory(
final IbftFinalState finalState,
final ProtocolContext<IbftContext> protocolContext,
final ProtocolSchedule<IbftContext> protocolSchedule,
final Subscribers<MinedBlockObserver> minedBlockObservers) {
final Subscribers<MinedBlockObserver> minedBlockObservers,
final MessageValidatorFactory messageValidatorFactory) {
this.finalState = finalState;
this.blockCreatorFactory = finalState.getBlockCreatorFactory();
this.protocolContext = protocolContext;
this.protocolSchedule = protocolSchedule;
this.minedBlockObservers = minedBlockObservers;
this.messageValidatorFactory = messageValidatorFactory;
}

public IbftRound createNewRound(final BlockHeader parentHeader, final int round) {
long nextBlockHeight = parentHeader.getNumber() + 1;
final ConsensusRoundIdentifier roundIdentifier =
new ConsensusRoundIdentifier(nextBlockHeight, round);

BlockValidator<IbftContext> blockValidator =
protocolSchedule.getByBlockNumber(nextBlockHeight).getBlockValidator();

final RoundState roundState =
new RoundState(
roundIdentifier,
finalState.getQuorum(),
new MessageValidator(
new SignedDataValidator(
finalState.getValidators(),
finalState.getProposerForRound(roundIdentifier),
roundIdentifier,
blockValidator,
protocolContext)));
messageValidatorFactory.createMessageValidator(roundIdentifier));

return createNewRoundWithState(parentHeader, roundState);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,11 @@ public static PantheonController<IbftContext> init(
new IbftBlockHeightManagerFactory(
finalState,
new IbftRoundFactory(
finalState, protocolContext, protocolSchedule, minedBlockObservers),
finalState,
protocolContext,
protocolSchedule,
minedBlockObservers,
messageValidatorFactory),
messageValidatorFactory),
gossiper);
ibftController.start();
Expand Down

0 comments on commit 6535d78

Please sign in to comment.