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

Rework IbftRoundFactory #784

Merged
merged 1 commit into from
Feb 6, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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