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

Signed-off-by: Adrian Sutton <adrian.sutton@consensys.net>
pull/2/head
Trent Mohay 6 years ago committed by GitHub
parent 16c64e64f0
commit 71b3e330b7
  1. 16
      pantheon/src/main/java/tech/pegasys/pantheon/controller/CliquePantheonControllerBuilder.java
  2. 16
      pantheon/src/main/java/tech/pegasys/pantheon/controller/IbftLegacyPantheonControllerBuilder.java
  3. 12
      pantheon/src/main/java/tech/pegasys/pantheon/controller/IbftPantheonControllerBuilder.java
  4. 4
      pantheon/src/main/java/tech/pegasys/pantheon/controller/PantheonControllerBuilder.java

@ -21,6 +21,7 @@ import tech.pegasys.pantheon.consensus.clique.blockcreation.CliqueBlockScheduler
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;
@ -29,6 +30,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.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;
@ -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() {
@ -121,15 +124,24 @@ public class CliquePantheonControllerBuilder extends PantheonControllerBuilder<C
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);
}

@ -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;
@ -25,6 +26,7 @@ import tech.pegasys.pantheon.consensus.ibftlegacy.protocol.Istanbul64ProtocolMan
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;
@ -39,6 +41,7 @@ import org.apache.logging.log4j.Logger;
public class IbftLegacyPantheonControllerBuilder extends PantheonControllerBuilder<IbftContext> {
private static final Logger LOG = LogManager.getLogger();
private final BlockInterface blockInterface = new IbftLegacyBlockInterface();
@Override
protected SubProtocolConfiguration createSubProtocolConfiguration(
@ -72,14 +75,23 @@ public class IbftLegacyPantheonControllerBuilder extends PantheonControllerBuild
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) {

@ -51,6 +51,7 @@ import tech.pegasys.pantheon.ethereum.blockcreation.MiningCoordinator;
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;
@ -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() {
@ -116,7 +118,6 @@ public class IbftPantheonControllerBuilder extends PantheonControllerBuilder<Ibf
miningParameters,
Util.publicKeyToAddress(nodeKeys.getPublicKey()));
final BlockInterface blockInterface = new IbftBlockInterface();
final ProposerSelector proposerSelector =
new ProposerSelector(blockchain, blockInterface, true);
@ -212,6 +213,15 @@ public class IbftPantheonControllerBuilder extends PantheonControllerBuilder<Ibf
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) {

@ -194,6 +194,8 @@ public abstract class PantheonControllerBuilder<C> {
protocolSchedule,
metricsSystem,
this::createConsensusContext);
validateContext(protocolContext);
final MutableBlockchain blockchain = protocolContext.getBlockchain();
final boolean fastSyncEnabled = syncConfig.syncMode().equals(SyncMode.FAST);
@ -299,6 +301,8 @@ public abstract class PantheonControllerBuilder<C> {
protected abstract ProtocolSchedule<C> createProtocolSchedule();
protected void validateContext(final ProtocolContext<C> context) {}
protected abstract C createConsensusContext(
Blockchain blockchain, WorldStateArchive worldStateArchive);

Loading…
Cancel
Save