diff --git a/ethereum/core/src/main/java/net/consensys/pantheon/ethereum/blockcreation/AbstractMinerExecutor.java b/ethereum/core/src/main/java/net/consensys/pantheon/ethereum/blockcreation/AbstractMinerExecutor.java new file mode 100644 index 0000000000..729dcd37c0 --- /dev/null +++ b/ethereum/core/src/main/java/net/consensys/pantheon/ethereum/blockcreation/AbstractMinerExecutor.java @@ -0,0 +1,56 @@ +package net.consensys.pantheon.ethereum.blockcreation; + +import net.consensys.pantheon.ethereum.ProtocolContext; +import net.consensys.pantheon.ethereum.blockcreation.MiningCoordinator.MinedBlockObserver; +import net.consensys.pantheon.ethereum.core.BlockHeader; +import net.consensys.pantheon.ethereum.core.PendingTransactions; +import net.consensys.pantheon.ethereum.core.Wei; +import net.consensys.pantheon.ethereum.mainnet.ProtocolSchedule; +import net.consensys.pantheon.util.Subscribers; +import net.consensys.pantheon.util.bytes.BytesValue; + +import java.util.concurrent.ExecutorService; + +public abstract class AbstractMinerExecutor< + C, M extends BlockMiner>> { + + protected final ProtocolContext protocolContext; + protected final ExecutorService executorService; + protected final ProtocolSchedule protocolSchedule; + protected final PendingTransactions pendingTransactions; + protected final AbstractBlockScheduler blockScheduler; + + protected volatile BytesValue extraData; + protected volatile Wei minTransactionGasPrice; + + public AbstractMinerExecutor( + final ProtocolContext protocolContext, + final ExecutorService executorService, + final ProtocolSchedule protocolSchedule, + final PendingTransactions pendingTransactions, + final MiningParameters miningParams, + final AbstractBlockScheduler blockScheduler) { + this.protocolContext = protocolContext; + this.executorService = executorService; + this.protocolSchedule = protocolSchedule; + this.pendingTransactions = pendingTransactions; + this.extraData = miningParams.getExtraData(); + this.minTransactionGasPrice = miningParams.getMinTransactionGasPrice(); + this.blockScheduler = blockScheduler; + } + + public abstract M startAsyncMining( + final Subscribers observers, final BlockHeader parentHeader); + + public void setExtraData(final BytesValue extraData) { + this.extraData = extraData.copy(); + } + + public void setMinTransactionGasPrice(final Wei minTransactionGasPrice) { + this.minTransactionGasPrice = minTransactionGasPrice.copy(); + } + + public Wei getMinTransactionGasPrice() { + return minTransactionGasPrice; + } +} diff --git a/ethereum/core/src/main/java/net/consensys/pantheon/ethereum/blockcreation/EthHashMinerExecutor.java b/ethereum/core/src/main/java/net/consensys/pantheon/ethereum/blockcreation/EthHashMinerExecutor.java index 7692a29b09..addce21836 100644 --- a/ethereum/core/src/main/java/net/consensys/pantheon/ethereum/blockcreation/EthHashMinerExecutor.java +++ b/ethereum/core/src/main/java/net/consensys/pantheon/ethereum/blockcreation/EthHashMinerExecutor.java @@ -5,27 +5,18 @@ import net.consensys.pantheon.ethereum.blockcreation.MiningCoordinator.MinedBloc import net.consensys.pantheon.ethereum.core.Address; import net.consensys.pantheon.ethereum.core.BlockHeader; import net.consensys.pantheon.ethereum.core.PendingTransactions; -import net.consensys.pantheon.ethereum.core.Wei; import net.consensys.pantheon.ethereum.mainnet.EthHashBlockCreator; import net.consensys.pantheon.ethereum.mainnet.EthHashSolver; import net.consensys.pantheon.ethereum.mainnet.EthHasher; import net.consensys.pantheon.ethereum.mainnet.ProtocolSchedule; import net.consensys.pantheon.util.Subscribers; -import net.consensys.pantheon.util.bytes.BytesValue; import java.util.Optional; import java.util.concurrent.ExecutorService; -public class EthHashMinerExecutor { +public class EthHashMinerExecutor extends AbstractMinerExecutor { - private final ProtocolContext protocolContext; - private final ExecutorService executorService; - private final ProtocolSchedule protocolSchedule; - private final PendingTransactions pendingTransactions; - private volatile BytesValue extraData; private volatile Optional
coinbase; - private volatile Wei minTransactionGasPrice; - private final AbstractBlockScheduler blockScheduler; public EthHashMinerExecutor( final ProtocolContext protocolContext, @@ -34,16 +25,17 @@ public class EthHashMinerExecutor { final PendingTransactions pendingTransactions, final MiningParameters miningParams, final AbstractBlockScheduler blockScheduler) { - this.protocolContext = protocolContext; - this.executorService = executorService; - this.protocolSchedule = protocolSchedule; - this.pendingTransactions = pendingTransactions; + super( + protocolContext, + executorService, + protocolSchedule, + pendingTransactions, + miningParams, + blockScheduler); this.coinbase = miningParams.getCoinbase(); - this.extraData = miningParams.getExtraData(); - this.minTransactionGasPrice = miningParams.getMinTransactionGasPrice(); - this.blockScheduler = blockScheduler; } + @Override public EthHashBlockMiner startAsyncMining( final Subscribers observers, final BlockHeader parentHeader) { if (!coinbase.isPresent()) { @@ -76,10 +68,6 @@ public class EthHashMinerExecutor { } } - public void setExtraData(final BytesValue extraData) { - this.extraData = extraData.copy(); - } - public void setCoinbase(final Address coinbase) { if (coinbase == null) { throw new IllegalArgumentException("Coinbase cannot be unset."); @@ -91,12 +79,4 @@ public class EthHashMinerExecutor { public Optional
getCoinbase() { return coinbase; } - - public void setMinTransactionGasPrice(final Wei minTransactionGasPrice) { - this.minTransactionGasPrice = minTransactionGasPrice.copy(); - } - - public Wei getMinTransactionGasPrice() { - return minTransactionGasPrice; - } }