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

Log error if clique or ibft have 0 validators in genesis #1509

Merged
merged 5 commits into from
May 30, 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 @@ -21,6 +21,7 @@
import tech.pegasys.pantheon.consensus.clique.blockcreation.CliqueMinerExecutor;
import tech.pegasys.pantheon.consensus.clique.blockcreation.CliqueMiningCoordinator;
import tech.pegasys.pantheon.consensus.clique.jsonrpc.CliqueJsonRpcMethodsFactory;
import tech.pegasys.pantheon.consensus.common.BlockInterface;
import tech.pegasys.pantheon.consensus.common.EpochManager;
import tech.pegasys.pantheon.consensus.common.VoteProposer;
import tech.pegasys.pantheon.consensus.common.VoteTallyCache;
Expand All @@ -29,6 +30,7 @@
import tech.pegasys.pantheon.ethereum.blockcreation.MiningCoordinator;
import tech.pegasys.pantheon.ethereum.chain.Blockchain;
import tech.pegasys.pantheon.ethereum.core.Address;
import tech.pegasys.pantheon.ethereum.core.BlockHeader;
import tech.pegasys.pantheon.ethereum.core.MiningParameters;
import tech.pegasys.pantheon.ethereum.core.Util;
import tech.pegasys.pantheon.ethereum.eth.manager.EthProtocolManager;
Expand All @@ -51,6 +53,7 @@ public class CliquePantheonControllerBuilder extends PantheonControllerBuilder<C
private Address localAddress;
private EpochManager epochManager;
private long secondsBetweenBlocks;
private final BlockInterface blockInterface = new CliqueBlockInterface();

@Override
protected void prepForBuild() {
Expand Down Expand Up @@ -121,15 +124,24 @@ protected ProtocolSchedule<CliqueContext> createProtocolSchedule() {
genesisConfig.getConfigOptions(), nodeKeys, privacyParameters);
}

@Override
protected void validateContext(final ProtocolContext<CliqueContext> context) {
final BlockHeader genesisBlockHeader = context.getBlockchain().getGenesisBlock().getHeader();

if (blockInterface.validatorsInBlock(genesisBlockHeader).isEmpty()) {
LOG.warn("Genesis block contains no signers - chain will not progress.");
}
}

@Override
protected CliqueContext createConsensusContext(
final Blockchain blockchain, final WorldStateArchive worldStateArchive) {
return new CliqueContext(
new VoteTallyCache(
blockchain,
new VoteTallyUpdater(epochManager, new CliqueBlockInterface()),
new VoteTallyUpdater(epochManager, blockInterface),
epochManager,
new CliqueBlockInterface()),
blockInterface),
new VoteProposer(),
epochManager);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
package tech.pegasys.pantheon.controller;

import tech.pegasys.pantheon.config.IbftConfigOptions;
import tech.pegasys.pantheon.consensus.common.BlockInterface;
import tech.pegasys.pantheon.consensus.common.EpochManager;
import tech.pegasys.pantheon.consensus.common.VoteProposer;
import tech.pegasys.pantheon.consensus.common.VoteTallyCache;
Expand All @@ -25,6 +26,7 @@
import tech.pegasys.pantheon.ethereum.ProtocolContext;
import tech.pegasys.pantheon.ethereum.blockcreation.MiningCoordinator;
import tech.pegasys.pantheon.ethereum.chain.Blockchain;
import tech.pegasys.pantheon.ethereum.core.BlockHeader;
import tech.pegasys.pantheon.ethereum.core.MiningParameters;
import tech.pegasys.pantheon.ethereum.eth.manager.EthProtocolManager;
import tech.pegasys.pantheon.ethereum.eth.sync.state.SyncState;
Expand All @@ -39,6 +41,7 @@
public class IbftLegacyPantheonControllerBuilder extends PantheonControllerBuilder<IbftContext> {

private static final Logger LOG = LogManager.getLogger();
private final BlockInterface blockInterface = new IbftLegacyBlockInterface();

@Override
protected SubProtocolConfiguration createSubProtocolConfiguration(
Expand Down Expand Up @@ -72,14 +75,23 @@ protected IbftContext createConsensusContext(
final VoteTallyCache voteTallyCache =
new VoteTallyCache(
blockchain,
new VoteTallyUpdater(epochManager, new IbftLegacyBlockInterface()),
new VoteTallyUpdater(epochManager, blockInterface),
epochManager,
new IbftLegacyBlockInterface());
blockInterface);

final VoteProposer voteProposer = new VoteProposer();
return new IbftContext(voteTallyCache, voteProposer);
}

@Override
protected void validateContext(final ProtocolContext<IbftContext> context) {
final BlockHeader genesisBlockHeader = context.getBlockchain().getGenesisBlock().getHeader();

if (blockInterface.validatorsInBlock(genesisBlockHeader).isEmpty()) {
LOG.warn("Genesis block contains no signers - chain will not progress.");
}
}

@Override
protected EthProtocolManager createEthProtocolManager(
final ProtocolContext<IbftContext> protocolContext, final boolean fastSyncEnabled) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
import tech.pegasys.pantheon.ethereum.chain.Blockchain;
import tech.pegasys.pantheon.ethereum.chain.MinedBlockObserver;
import tech.pegasys.pantheon.ethereum.chain.MutableBlockchain;
import tech.pegasys.pantheon.ethereum.core.BlockHeader;
import tech.pegasys.pantheon.ethereum.core.MiningParameters;
import tech.pegasys.pantheon.ethereum.core.Util;
import tech.pegasys.pantheon.ethereum.eth.EthProtocol;
Expand All @@ -76,6 +77,7 @@ public class IbftPantheonControllerBuilder extends PantheonControllerBuilder<Ibf
private IbftEventQueue ibftEventQueue;
private IbftConfigOptions ibftConfig;
private ValidatorPeers peers;
private final BlockInterface blockInterface = new IbftBlockInterface();

@Override
protected void prepForBuild() {
Expand Down Expand Up @@ -116,7 +118,6 @@ protected MiningCoordinator createMiningCoordinator(
miningParameters,
Util.publicKeyToAddress(nodeKeys.getPublicKey()));

final BlockInterface blockInterface = new IbftBlockInterface();
final ProposerSelector proposerSelector =
new ProposerSelector(blockchain, blockInterface, true);

Expand Down Expand Up @@ -212,6 +213,15 @@ protected ProtocolSchedule<IbftContext> createProtocolSchedule() {
return IbftProtocolSchedule.create(genesisConfig.getConfigOptions(), privacyParameters);
}

@Override
protected void validateContext(final ProtocolContext<IbftContext> context) {
final BlockHeader genesisBlockHeader = context.getBlockchain().getGenesisBlock().getHeader();

if (blockInterface.validatorsInBlock(genesisBlockHeader).isEmpty()) {
LOG.warn("Genesis block contains no signers - chain will not progress.");
}
}

@Override
protected IbftContext createConsensusContext(
final Blockchain blockchain, final WorldStateArchive worldStateArchive) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,8 @@ public PantheonController<C> build() throws IOException {
protocolSchedule,
metricsSystem,
this::createConsensusContext);
validateContext(protocolContext);

final MutableBlockchain blockchain = protocolContext.getBlockchain();

final boolean fastSyncEnabled = syncConfig.syncMode().equals(SyncMode.FAST);
Expand Down Expand Up @@ -299,6 +301,8 @@ protected abstract MiningCoordinator createMiningCoordinator(

protected abstract ProtocolSchedule<C> createProtocolSchedule();

protected void validateContext(final ProtocolContext<C> context) {}

protected abstract C createConsensusContext(
Blockchain blockchain, WorldStateArchive worldStateArchive);

Expand Down