Extract common functionality from EthHashMinerExecutor (#12)

The EthHashMinerExecutor is comprised of both EthHash specific
functions as well as common functions which will be useful to other
consensus mechanisms.

As such the common functionality has been extracted to a parent class,
leaving ethhash specific functionality in the child.
tmohay 6 years ago committed by GitHub
parent a67b026181
commit d2641d472e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 56
      ethereum/core/src/main/java/net/consensys/pantheon/ethereum/blockcreation/AbstractMinerExecutor.java
  2. 38
      ethereum/core/src/main/java/net/consensys/pantheon/ethereum/blockcreation/EthHashMinerExecutor.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<C, ? extends AbstractBlockCreator<C>>> {
protected final ProtocolContext<C> protocolContext;
protected final ExecutorService executorService;
protected final ProtocolSchedule<C> protocolSchedule;
protected final PendingTransactions pendingTransactions;
protected final AbstractBlockScheduler blockScheduler;
protected volatile BytesValue extraData;
protected volatile Wei minTransactionGasPrice;
public AbstractMinerExecutor(
final ProtocolContext<C> protocolContext,
final ExecutorService executorService,
final ProtocolSchedule<C> 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<MinedBlockObserver> 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;
}
}

@ -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<Void, EthHashBlockMiner> {
private final ProtocolContext<Void> protocolContext;
private final ExecutorService executorService;
private final ProtocolSchedule<Void> protocolSchedule;
private final PendingTransactions pendingTransactions;
private volatile BytesValue extraData;
private volatile Optional<Address> coinbase;
private volatile Wei minTransactionGasPrice;
private final AbstractBlockScheduler blockScheduler;
public EthHashMinerExecutor(
final ProtocolContext<Void> 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<MinedBlockObserver> 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<Address> getCoinbase() {
return coinbase;
}
public void setMinTransactionGasPrice(final Wei minTransactionGasPrice) {
this.minTransactionGasPrice = minTransactionGasPrice.copy();
}
public Wei getMinTransactionGasPrice() {
return minTransactionGasPrice;
}
}

Loading…
Cancel
Save