From 0cd445f73696506126f2f1a34e461d34e4ec9566 Mon Sep 17 00:00:00 2001 From: tmohay <37158202+rain-on@users.noreply.github.com> Date: Wed, 10 Oct 2018 11:36:21 +1100 Subject: [PATCH] Extract common functions from EthHasBlockMiner (#8) The EthHashBlockMiner contains both the generic mining capabilities and the EthHash JSON specific API. The generic capabilities have been extracted into a base class which can be reused for Clique (or other) consensus mechanisms. Signed-off-by: Adrian Sutton --- .../ethereum/blockcreation/BlockMiner.java | 17 +++++++++-------- .../blockcreation/EthHashBlockMiner.java | 5 +---- 2 files changed, 10 insertions(+), 12 deletions(-) diff --git a/ethereum/core/src/main/java/net/consensys/pantheon/ethereum/blockcreation/BlockMiner.java b/ethereum/core/src/main/java/net/consensys/pantheon/ethereum/blockcreation/BlockMiner.java index 2fb128c005..0c26dd20e7 100755 --- a/ethereum/core/src/main/java/net/consensys/pantheon/ethereum/blockcreation/BlockMiner.java +++ b/ethereum/core/src/main/java/net/consensys/pantheon/ethereum/blockcreation/BlockMiner.java @@ -24,19 +24,20 @@ import org.apache.logging.log4j.Logger; *

This class is responsible for mining a single block only - the AbstractBlockCreator maintains * state so must be destroyed between block mining activities. */ -public class BlockMiner implements Runnable { +public class BlockMiner> implements Runnable { private static final Logger LOG = LogManager.getLogger(); - private final AbstractBlockCreator blockCreator; - private final ProtocolContext protocolContext; + protected final M blockCreator; + protected final ProtocolContext protocolContext; + protected final BlockHeader parentHeader; + private final ProtocolSchedule protocolSchedule; private final Subscribers observers; private final AbstractBlockScheduler scheduler; - private final BlockHeader parentHeader; public BlockMiner( - final AbstractBlockCreator blockCreator, + final M blockCreator, final ProtocolSchedule protocolSchedule, final ProtocolContext protocolContext, final Subscribers observers, @@ -67,13 +68,13 @@ public class BlockMiner implements Runnable { } } - private boolean mineBlock() throws InterruptedException { + protected boolean mineBlock() throws InterruptedException { // Ensure the block is allowed to be mined - i.e. the timestamp on the new block is sufficiently // ahead of the parent, and still within allowable clock tolerance. - LOG.trace("Waiting for next block timestamp to be valid."); + LOG.trace("Started a mining operation."); long newBlockTimestamp = scheduler.waitUntilNextBlockCanBeMined(parentHeader); - LOG.trace("Started a mining operation."); + LOG.trace("Mining a new block with timestamp {}", newBlockTimestamp); Block block = blockCreator.createBlock(newBlockTimestamp); LOG.info( "Block created, importing to local chain, block includes {} transactions", diff --git a/ethereum/core/src/main/java/net/consensys/pantheon/ethereum/blockcreation/EthHashBlockMiner.java b/ethereum/core/src/main/java/net/consensys/pantheon/ethereum/blockcreation/EthHashBlockMiner.java index b83311f6c1..4eb2903cca 100755 --- a/ethereum/core/src/main/java/net/consensys/pantheon/ethereum/blockcreation/EthHashBlockMiner.java +++ b/ethereum/core/src/main/java/net/consensys/pantheon/ethereum/blockcreation/EthHashBlockMiner.java @@ -18,9 +18,7 @@ import java.util.Optional; *

All other aspects of mining (i.e. pre-block delays, block creation and importing to the chain) * are all conducted by the parent class. */ -public class EthHashBlockMiner extends BlockMiner { - - private final EthHashBlockCreator blockCreator; +public class EthHashBlockMiner extends BlockMiner { public EthHashBlockMiner( final EthHashBlockCreator blockCreator, @@ -30,7 +28,6 @@ public class EthHashBlockMiner extends BlockMiner { final AbstractBlockScheduler scheduler, final BlockHeader parentHeader) { super(blockCreator, protocolSchedule, protocolContext, observers, scheduler, parentHeader); - this.blockCreator = blockCreator; } public Optional getWorkDefinition() {