From 71b3e330b70a6a305d2c7cb91023b4fd963f97c9 Mon Sep 17 00:00:00 2001 From: Trent Mohay <37158202+rain-on@users.noreply.github.com> Date: Thu, 30 May 2019 15:12:26 +1000 Subject: [PATCH] Log error if clique or ibft have 0 validators in genesis (#1509) Signed-off-by: Adrian Sutton --- .../CliquePantheonControllerBuilder.java | 16 ++++++++++++++-- .../IbftLegacyPantheonControllerBuilder.java | 16 ++++++++++++++-- .../IbftPantheonControllerBuilder.java | 12 +++++++++++- .../controller/PantheonControllerBuilder.java | 4 ++++ 4 files changed, 43 insertions(+), 5 deletions(-) diff --git a/pantheon/src/main/java/tech/pegasys/pantheon/controller/CliquePantheonControllerBuilder.java b/pantheon/src/main/java/tech/pegasys/pantheon/controller/CliquePantheonControllerBuilder.java index bdd068e933..392b570285 100644 --- a/pantheon/src/main/java/tech/pegasys/pantheon/controller/CliquePantheonControllerBuilder.java +++ b/pantheon/src/main/java/tech/pegasys/pantheon/controller/CliquePantheonControllerBuilder.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 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); } diff --git a/pantheon/src/main/java/tech/pegasys/pantheon/controller/IbftLegacyPantheonControllerBuilder.java b/pantheon/src/main/java/tech/pegasys/pantheon/controller/IbftLegacyPantheonControllerBuilder.java index 0fd426c913..19aad47024 100644 --- a/pantheon/src/main/java/tech/pegasys/pantheon/controller/IbftLegacyPantheonControllerBuilder.java +++ b/pantheon/src/main/java/tech/pegasys/pantheon/controller/IbftLegacyPantheonControllerBuilder.java @@ -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 { 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 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 protocolContext, final boolean fastSyncEnabled) { diff --git a/pantheon/src/main/java/tech/pegasys/pantheon/controller/IbftPantheonControllerBuilder.java b/pantheon/src/main/java/tech/pegasys/pantheon/controller/IbftPantheonControllerBuilder.java index 511a8c740a..f35183f9fd 100644 --- a/pantheon/src/main/java/tech/pegasys/pantheon/controller/IbftPantheonControllerBuilder.java +++ b/pantheon/src/main/java/tech/pegasys/pantheon/controller/IbftPantheonControllerBuilder.java @@ -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 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) { diff --git a/pantheon/src/main/java/tech/pegasys/pantheon/controller/PantheonControllerBuilder.java b/pantheon/src/main/java/tech/pegasys/pantheon/controller/PantheonControllerBuilder.java index 36e83f48a7..19349e3b8b 100644 --- a/pantheon/src/main/java/tech/pegasys/pantheon/controller/PantheonControllerBuilder.java +++ b/pantheon/src/main/java/tech/pegasys/pantheon/controller/PantheonControllerBuilder.java @@ -194,6 +194,8 @@ public abstract class PantheonControllerBuilder { 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 { protected abstract ProtocolSchedule createProtocolSchedule(); + protected void validateContext(final ProtocolContext context) {} + protected abstract C createConsensusContext( Blockchain blockchain, WorldStateArchive worldStateArchive);