diff --git a/besu/src/main/java/org/hyperledger/besu/chainimport/JsonBlockImporter.java b/besu/src/main/java/org/hyperledger/besu/chainimport/JsonBlockImporter.java index 2e9e7fc7d63..6bde34d3519 100644 --- a/besu/src/main/java/org/hyperledger/besu/chainimport/JsonBlockImporter.java +++ b/besu/src/main/java/org/hyperledger/besu/chainimport/JsonBlockImporter.java @@ -17,6 +17,7 @@ import org.hyperledger.besu.chainimport.internal.BlockData; import org.hyperledger.besu.chainimport.internal.ChainData; import org.hyperledger.besu.config.GenesisConfigOptions; +import org.hyperledger.besu.config.PowAlgorithm; import org.hyperledger.besu.controller.BesuController; import org.hyperledger.besu.ethereum.blockcreation.MiningCoordinator; import org.hyperledger.besu.ethereum.core.Address; @@ -119,7 +120,7 @@ private void setOptionalFields( final BlockData blockData, final GenesisConfigOptions genesisConfig) { // Some fields can only be configured for ethash - if (genesisConfig.isEthHash()) { + if (genesisConfig.getPowAlgorithm() != PowAlgorithm.NONE) { // For simplicity only set these for ethash. Other consensus algorithms use these fields for // special purposes or ignore them miner.setCoinbase(blockData.getCoinbase().orElse(Address.ZERO)); diff --git a/besu/src/main/java/org/hyperledger/besu/controller/BesuController.java b/besu/src/main/java/org/hyperledger/besu/controller/BesuController.java index f2ff19e8a9e..eb24c8cd8e0 100644 --- a/besu/src/main/java/org/hyperledger/besu/controller/BesuController.java +++ b/besu/src/main/java/org/hyperledger/besu/controller/BesuController.java @@ -17,6 +17,7 @@ import org.hyperledger.besu.cli.config.EthNetworkConfig; import org.hyperledger.besu.config.GenesisConfigFile; import org.hyperledger.besu.config.GenesisConfigOptions; +import org.hyperledger.besu.config.PowAlgorithm; import org.hyperledger.besu.crypto.NodeKey; import org.hyperledger.besu.ethereum.ProtocolContext; import org.hyperledger.besu.ethereum.api.jsonrpc.RpcApi; @@ -191,7 +192,7 @@ BesuControllerBuilder fromGenesisConfig( genesisConfig.getConfigOptions(genesisConfigOverrides); final BesuControllerBuilder builder; - if (configOptions.isEthHash()) { + if (configOptions.getPowAlgorithm() != PowAlgorithm.NONE) { builder = new MainnetBesuControllerBuilder(); } else if (configOptions.isIbft2()) { builder = new IbftBesuControllerBuilder(); diff --git a/besu/src/main/java/org/hyperledger/besu/controller/MainnetBesuControllerBuilder.java b/besu/src/main/java/org/hyperledger/besu/controller/MainnetBesuControllerBuilder.java index af5e63ecc87..32993045303 100644 --- a/besu/src/main/java/org/hyperledger/besu/controller/MainnetBesuControllerBuilder.java +++ b/besu/src/main/java/org/hyperledger/besu/controller/MainnetBesuControllerBuilder.java @@ -16,9 +16,9 @@ import org.hyperledger.besu.ethereum.ProtocolContext; import org.hyperledger.besu.ethereum.blockcreation.DefaultBlockScheduler; -import org.hyperledger.besu.ethereum.blockcreation.EthHashMinerExecutor; -import org.hyperledger.besu.ethereum.blockcreation.EthHashMiningCoordinator; import org.hyperledger.besu.ethereum.blockcreation.MiningCoordinator; +import org.hyperledger.besu.ethereum.blockcreation.PoWMinerExecutor; +import org.hyperledger.besu.ethereum.blockcreation.PoWMiningCoordinator; import org.hyperledger.besu.ethereum.chain.Blockchain; import org.hyperledger.besu.ethereum.core.MiningParameters; import org.hyperledger.besu.ethereum.eth.manager.EthProtocolManager; @@ -42,8 +42,9 @@ protected MiningCoordinator createMiningCoordinator( final MiningParameters miningParameters, final SyncState syncState, final EthProtocolManager ethProtocolManager) { - final EthHashMinerExecutor executor = - new EthHashMinerExecutor( + + final PoWMinerExecutor executor = + new PoWMinerExecutor( protocolContext, protocolSchedule, transactionPool.getPendingTransactions(), @@ -55,8 +56,8 @@ protected MiningCoordinator createMiningCoordinator( gasLimitCalculator, epochCalculator); - final EthHashMiningCoordinator miningCoordinator = - new EthHashMiningCoordinator( + final PoWMiningCoordinator miningCoordinator = + new PoWMiningCoordinator( protocolContext.getBlockchain(), executor, syncState, diff --git a/config/src/main/java/org/hyperledger/besu/config/GenesisConfigOptions.java b/config/src/main/java/org/hyperledger/besu/config/GenesisConfigOptions.java index c279fe34ae6..b815e86e604 100644 --- a/config/src/main/java/org/hyperledger/besu/config/GenesisConfigOptions.java +++ b/config/src/main/java/org/hyperledger/besu/config/GenesisConfigOptions.java @@ -209,4 +209,11 @@ public interface GenesisConfigOptions { * @return block number to activate Quorum Permissioning */ OptionalLong getQip714BlockNumber(); + + /** + * The PoW algorithm associated with the genesis file. + * + * @return the PoW algorithm in use. + */ + PowAlgorithm getPowAlgorithm(); } diff --git a/config/src/main/java/org/hyperledger/besu/config/JsonGenesisConfigOptions.java b/config/src/main/java/org/hyperledger/besu/config/JsonGenesisConfigOptions.java index 96cd2304c5b..109af498f58 100644 --- a/config/src/main/java/org/hyperledger/besu/config/JsonGenesisConfigOptions.java +++ b/config/src/main/java/org/hyperledger/besu/config/JsonGenesisConfigOptions.java @@ -322,6 +322,11 @@ public OptionalLong getQip714BlockNumber() { return getOptionalLong("qip714block"); } + @Override + public PowAlgorithm getPowAlgorithm() { + return isEthHash() ? PowAlgorithm.ETHASH : PowAlgorithm.NONE; + } + @Override public Map asMap() { final ImmutableMap.Builder builder = ImmutableMap.builder(); diff --git a/config/src/main/java/org/hyperledger/besu/config/PowAlgorithm.java b/config/src/main/java/org/hyperledger/besu/config/PowAlgorithm.java new file mode 100644 index 00000000000..e1ea4394778 --- /dev/null +++ b/config/src/main/java/org/hyperledger/besu/config/PowAlgorithm.java @@ -0,0 +1,16 @@ +package org.hyperledger.besu.config; + +/** An enumeration of supported Proof-of-work algorithms. */ +public enum PowAlgorithm { + ETHASH, + NONE; + + public static PowAlgorithm fromString(final String str) { + for (final PowAlgorithm powAlgorithm : PowAlgorithm.values()) { + if (powAlgorithm.name().equalsIgnoreCase(str)) { + return powAlgorithm; + } + } + return null; + } +} diff --git a/config/src/main/java/org/hyperledger/besu/config/StubGenesisConfigOptions.java b/config/src/main/java/org/hyperledger/besu/config/StubGenesisConfigOptions.java index 5ebe262baac..8bb666a70d6 100644 --- a/config/src/main/java/org/hyperledger/besu/config/StubGenesisConfigOptions.java +++ b/config/src/main/java/org/hyperledger/besu/config/StubGenesisConfigOptions.java @@ -281,6 +281,11 @@ public OptionalLong getQip714BlockNumber() { return OptionalLong.empty(); } + @Override + public PowAlgorithm getPowAlgorithm() { + return isEthHash() ? PowAlgorithm.ETHASH : PowAlgorithm.NONE; + } + @Override public List getForks() { return Collections.emptyList(); diff --git a/consensus/clique/src/main/java/org/hyperledger/besu/consensus/clique/CliqueProtocolSchedule.java b/consensus/clique/src/main/java/org/hyperledger/besu/consensus/clique/CliqueProtocolSchedule.java index edc506b86ae..93da6e4cd9f 100644 --- a/consensus/clique/src/main/java/org/hyperledger/besu/consensus/clique/CliqueProtocolSchedule.java +++ b/consensus/clique/src/main/java/org/hyperledger/besu/consensus/clique/CliqueProtocolSchedule.java @@ -74,7 +74,8 @@ public static ProtocolSchedule create( privacyParameters.getGoQuorumPrivacyParameters().isPresent()), privacyParameters, isRevertReasonEnabled, - config.isQuorum()) + config.isQuorum(), + config.getPowAlgorithm()) .createProtocolSchedule(); } diff --git a/consensus/clique/src/main/java/org/hyperledger/besu/consensus/clique/blockcreation/CliqueMinerExecutor.java b/consensus/clique/src/main/java/org/hyperledger/besu/consensus/clique/blockcreation/CliqueMinerExecutor.java index 2cedf79747d..36a3725ed6b 100644 --- a/consensus/clique/src/main/java/org/hyperledger/besu/consensus/clique/blockcreation/CliqueMinerExecutor.java +++ b/consensus/clique/src/main/java/org/hyperledger/besu/consensus/clique/blockcreation/CliqueMinerExecutor.java @@ -24,8 +24,8 @@ import org.hyperledger.besu.ethereum.blockcreation.AbstractBlockScheduler; import org.hyperledger.besu.ethereum.blockcreation.AbstractMinerExecutor; import org.hyperledger.besu.ethereum.blockcreation.GasLimitCalculator; -import org.hyperledger.besu.ethereum.chain.EthHashObserver; import org.hyperledger.besu.ethereum.chain.MinedBlockObserver; +import org.hyperledger.besu.ethereum.chain.PoWObserver; import org.hyperledger.besu.ethereum.core.Address; import org.hyperledger.besu.ethereum.core.BlockHeader; import org.hyperledger.besu.ethereum.core.MiningParameters; @@ -72,7 +72,7 @@ public CliqueMinerExecutor( @Override public CliqueBlockMiner createMiner( final Subscribers observers, - final Subscribers ethHashObservers, + final Subscribers ethHashObservers, final BlockHeader parentHeader) { final Function blockCreator = (header) -> diff --git a/consensus/common/src/main/java/org/hyperledger/besu/consensus/common/bft/BftProtocolSchedule.java b/consensus/common/src/main/java/org/hyperledger/besu/consensus/common/bft/BftProtocolSchedule.java index 1cb61c18e7f..9bfe9772d7b 100644 --- a/consensus/common/src/main/java/org/hyperledger/besu/consensus/common/bft/BftProtocolSchedule.java +++ b/consensus/common/src/main/java/org/hyperledger/besu/consensus/common/bft/BftProtocolSchedule.java @@ -46,7 +46,8 @@ public static ProtocolSchedule create( builder -> applyBftChanges(config.getBftConfigOptions(), builder, config.isQuorum()), privacyParameters, isRevertReasonEnabled, - config.isQuorum()) + config.isQuorum(), + config.getPowAlgorithm()) .createProtocolSchedule(); } diff --git a/consensus/ibftlegacy/src/main/java/org/hyperledger/besu/consensus/ibftlegacy/IbftProtocolSchedule.java b/consensus/ibftlegacy/src/main/java/org/hyperledger/besu/consensus/ibftlegacy/IbftProtocolSchedule.java index 058f548ba3a..b18cf529754 100644 --- a/consensus/ibftlegacy/src/main/java/org/hyperledger/besu/consensus/ibftlegacy/IbftProtocolSchedule.java +++ b/consensus/ibftlegacy/src/main/java/org/hyperledger/besu/consensus/ibftlegacy/IbftProtocolSchedule.java @@ -47,7 +47,8 @@ public static ProtocolSchedule create( builder -> applyIbftChanges(blockPeriod, builder, config.isQuorum()), privacyParameters, isRevertReasonEnabled, - config.isQuorum()) + config.isQuorum(), + config.getPowAlgorithm()) .createProtocolSchedule(); } diff --git a/ethereum/api/src/integration-test/java/org/hyperledger/besu/ethereum/api/jsonrpc/JsonRpcTestMethodsFactory.java b/ethereum/api/src/integration-test/java/org/hyperledger/besu/ethereum/api/jsonrpc/JsonRpcTestMethodsFactory.java index 439157a5e01..1ff05c7bc96 100644 --- a/ethereum/api/src/integration-test/java/org/hyperledger/besu/ethereum/api/jsonrpc/JsonRpcTestMethodsFactory.java +++ b/ethereum/api/src/integration-test/java/org/hyperledger/besu/ethereum/api/jsonrpc/JsonRpcTestMethodsFactory.java @@ -26,7 +26,7 @@ import org.hyperledger.besu.ethereum.api.jsonrpc.methods.JsonRpcMethodsFactory; import org.hyperledger.besu.ethereum.api.jsonrpc.websocket.WebSocketConfiguration; import org.hyperledger.besu.ethereum.api.query.BlockchainQueries; -import org.hyperledger.besu.ethereum.blockcreation.EthHashMiningCoordinator; +import org.hyperledger.besu.ethereum.blockcreation.PoWMiningCoordinator; import org.hyperledger.besu.ethereum.chain.MutableBlockchain; import org.hyperledger.besu.ethereum.core.Block; import org.hyperledger.besu.ethereum.core.BlockImporter; @@ -90,7 +90,7 @@ public Map methods() { final P2PNetwork peerDiscovery = mock(P2PNetwork.class); final EthPeers ethPeers = mock(EthPeers.class); final TransactionPool transactionPool = mock(TransactionPool.class); - final EthHashMiningCoordinator miningCoordinator = mock(EthHashMiningCoordinator.class); + final PoWMiningCoordinator miningCoordinator = mock(PoWMiningCoordinator.class); final ObservableMetricsSystem metricsSystem = new NoOpMetricsSystem(); final Optional accountWhitelistController = Optional.of(mock(AccountLocalConfigPermissioningController.class)); diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetWork.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetWork.java index dce139c5314..6fa252f2237 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetWork.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetWork.java @@ -23,11 +23,11 @@ import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcResponse; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcSuccessResponse; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.results.Quantity; -import org.hyperledger.besu.ethereum.blockcreation.EthHashMiningCoordinator; import org.hyperledger.besu.ethereum.blockcreation.MiningCoordinator; +import org.hyperledger.besu.ethereum.blockcreation.PoWMiningCoordinator; import org.hyperledger.besu.ethereum.mainnet.DirectAcyclicGraphSeed; import org.hyperledger.besu.ethereum.mainnet.EpochCalculator; -import org.hyperledger.besu.ethereum.mainnet.EthHashSolverInputs; +import org.hyperledger.besu.ethereum.mainnet.PoWSolverInputs; import java.util.Optional; @@ -42,8 +42,8 @@ public class EthGetWork implements JsonRpcMethod { public EthGetWork(final MiningCoordinator miner) { this.miner = miner; - if (miner instanceof EthHashMiningCoordinator) { - this.epochCalculator = ((EthHashMiningCoordinator) miner).getEpochCalculator(); + if (miner instanceof PoWMiningCoordinator) { + this.epochCalculator = ((PoWMiningCoordinator) miner).getEpochCalculator(); } else { this.epochCalculator = new EpochCalculator.DefaultEpochCalculator(); } @@ -56,9 +56,9 @@ public String getName() { @Override public JsonRpcResponse response(final JsonRpcRequestContext requestContext) { - final Optional solver = miner.getWorkDefinition(); + final Optional solver = miner.getWorkDefinition(); if (solver.isPresent()) { - final EthHashSolverInputs rawResult = solver.get(); + final PoWSolverInputs rawResult = solver.get(); final byte[] dagSeed = DirectAcyclicGraphSeed.dagSeed(rawResult.getBlockNumber(), epochCalculator); final String[] result = { diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthSubmitWork.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthSubmitWork.java index 63295c171af..3f95f2cedf4 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthSubmitWork.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthSubmitWork.java @@ -24,8 +24,8 @@ import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcSuccessResponse; import org.hyperledger.besu.ethereum.blockcreation.MiningCoordinator; import org.hyperledger.besu.ethereum.core.Hash; -import org.hyperledger.besu.ethereum.mainnet.EthHashSolution; -import org.hyperledger.besu.ethereum.mainnet.EthHashSolverInputs; +import org.hyperledger.besu.ethereum.mainnet.PoWSolution; +import org.hyperledger.besu.ethereum.mainnet.PoWSolverInputs; import java.util.Optional; @@ -48,10 +48,10 @@ public String getName() { @Override public JsonRpcResponse response(final JsonRpcRequestContext requestContext) { - final Optional solver = miner.getWorkDefinition(); + final Optional solver = miner.getWorkDefinition(); if (solver.isPresent()) { - final EthHashSolution solution = - new EthHashSolution( + final PoWSolution solution = + new PoWSolution( Bytes.fromHexString(requestContext.getRequiredParameter(0, String.class)).getLong(0), requestContext.getRequiredParameter(2, Hash.class), Bytes.fromHexString(requestContext.getRequiredParameter(1, String.class)) diff --git a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/graphql/AbstractEthGraphQLHttpServiceTest.java b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/graphql/AbstractEthGraphQLHttpServiceTest.java index 33c63f0da5e..b510cd2e88a 100644 --- a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/graphql/AbstractEthGraphQLHttpServiceTest.java +++ b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/graphql/AbstractEthGraphQLHttpServiceTest.java @@ -17,7 +17,7 @@ import org.hyperledger.besu.ethereum.ProtocolContext; import org.hyperledger.besu.ethereum.api.ImmutableApiConfiguration; import org.hyperledger.besu.ethereum.api.query.BlockchainQueries; -import org.hyperledger.besu.ethereum.blockcreation.EthHashMiningCoordinator; +import org.hyperledger.besu.ethereum.blockcreation.PoWMiningCoordinator; import org.hyperledger.besu.ethereum.chain.GenesisState; import org.hyperledger.besu.ethereum.chain.MutableBlockchain; import org.hyperledger.besu.ethereum.core.Block; @@ -123,8 +123,7 @@ public void setupTest() throws Exception { final SyncStatus status = new DefaultSyncStatus(1, 2, 3, Optional.of(4L), Optional.of(5L)); Mockito.when(synchronizerMock.getSyncStatus()).thenReturn(Optional.of(status)); - final EthHashMiningCoordinator miningCoordinatorMock = - Mockito.mock(EthHashMiningCoordinator.class); + final PoWMiningCoordinator miningCoordinatorMock = Mockito.mock(PoWMiningCoordinator.class); Mockito.when(miningCoordinatorMock.getMinTransactionGasPrice()).thenReturn(Wei.of(16)); final TransactionPool transactionPoolMock = Mockito.mock(TransactionPool.class); diff --git a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/graphql/GraphQLHttpServiceCorsTest.java b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/graphql/GraphQLHttpServiceCorsTest.java index 78a72691758..801a1977c79 100644 --- a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/graphql/GraphQLHttpServiceCorsTest.java +++ b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/graphql/GraphQLHttpServiceCorsTest.java @@ -15,7 +15,7 @@ package org.hyperledger.besu.ethereum.api.graphql; import org.hyperledger.besu.ethereum.api.query.BlockchainQueries; -import org.hyperledger.besu.ethereum.blockcreation.EthHashMiningCoordinator; +import org.hyperledger.besu.ethereum.blockcreation.PoWMiningCoordinator; import org.hyperledger.besu.ethereum.core.Synchronizer; import org.hyperledger.besu.ethereum.eth.EthProtocol; import org.hyperledger.besu.ethereum.eth.manager.EthScheduler; @@ -210,8 +210,7 @@ private GraphQLHttpService createGraphQLHttpServiceWithAllowedDomains( final BlockchainQueries blockchainQueries = Mockito.mock(BlockchainQueries.class); final Synchronizer synchronizer = Mockito.mock(Synchronizer.class); - final EthHashMiningCoordinator miningCoordinatorMock = - Mockito.mock(EthHashMiningCoordinator.class); + final PoWMiningCoordinator miningCoordinatorMock = Mockito.mock(PoWMiningCoordinator.class); final GraphQLDataFetcherContextImpl dataFetcherContext = Mockito.mock(GraphQLDataFetcherContextImpl.class); diff --git a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/graphql/GraphQLHttpServiceHostWhitelistTest.java b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/graphql/GraphQLHttpServiceHostWhitelistTest.java index 4568ae02307..70b34cdb114 100644 --- a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/graphql/GraphQLHttpServiceHostWhitelistTest.java +++ b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/graphql/GraphQLHttpServiceHostWhitelistTest.java @@ -15,7 +15,7 @@ package org.hyperledger.besu.ethereum.api.graphql; import org.hyperledger.besu.ethereum.api.query.BlockchainQueries; -import org.hyperledger.besu.ethereum.blockcreation.EthHashMiningCoordinator; +import org.hyperledger.besu.ethereum.blockcreation.PoWMiningCoordinator; import org.hyperledger.besu.ethereum.core.Synchronizer; import org.hyperledger.besu.ethereum.eth.EthProtocol; import org.hyperledger.besu.ethereum.eth.manager.EthScheduler; @@ -71,8 +71,7 @@ private GraphQLHttpService createGraphQLHttpService() throws Exception { final BlockchainQueries blockchainQueries = Mockito.mock(BlockchainQueries.class); final Synchronizer synchronizer = Mockito.mock(Synchronizer.class); - final EthHashMiningCoordinator miningCoordinatorMock = - Mockito.mock(EthHashMiningCoordinator.class); + final PoWMiningCoordinator miningCoordinatorMock = Mockito.mock(PoWMiningCoordinator.class); final GraphQLDataFetcherContextImpl dataFetcherContext = Mockito.mock(GraphQLDataFetcherContextImpl.class); diff --git a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/graphql/GraphQLHttpServiceTest.java b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/graphql/GraphQLHttpServiceTest.java index 9e168267546..7fade3547ad 100644 --- a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/graphql/GraphQLHttpServiceTest.java +++ b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/graphql/GraphQLHttpServiceTest.java @@ -19,7 +19,7 @@ import org.hyperledger.besu.ethereum.api.query.BlockWithMetadata; import org.hyperledger.besu.ethereum.api.query.BlockchainQueries; import org.hyperledger.besu.ethereum.api.query.TransactionWithMetadata; -import org.hyperledger.besu.ethereum.blockcreation.EthHashMiningCoordinator; +import org.hyperledger.besu.ethereum.blockcreation.PoWMiningCoordinator; import org.hyperledger.besu.ethereum.core.Hash; import org.hyperledger.besu.ethereum.core.Synchronizer; import org.hyperledger.besu.ethereum.core.Wei; @@ -70,7 +70,7 @@ public class GraphQLHttpServiceTest { private static BlockchainQueries blockchainQueries; private static GraphQL graphQL; private static GraphQLDataFetcherContextImpl dataFetcherContext; - private static EthHashMiningCoordinator miningCoordinatorMock; + private static PoWMiningCoordinator miningCoordinatorMock; private final GraphQLTestHelper testHelper = new GraphQLTestHelper(); @@ -80,7 +80,7 @@ public static void initServerAndClient() throws Exception { final Synchronizer synchronizer = Mockito.mock(Synchronizer.class); graphQL = Mockito.mock(GraphQL.class); - miningCoordinatorMock = Mockito.mock(EthHashMiningCoordinator.class); + miningCoordinatorMock = Mockito.mock(PoWMiningCoordinator.class); dataFetcherContext = Mockito.mock(GraphQLDataFetcherContextImpl.class); Mockito.when(dataFetcherContext.getBlockchainQueries()).thenReturn(blockchainQueries); diff --git a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/AbstractJsonRpcHttpServiceTest.java b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/AbstractJsonRpcHttpServiceTest.java index 771f522c80e..78091405655 100644 --- a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/AbstractJsonRpcHttpServiceTest.java +++ b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/AbstractJsonRpcHttpServiceTest.java @@ -30,7 +30,7 @@ import org.hyperledger.besu.ethereum.api.jsonrpc.methods.JsonRpcMethodsFactory; import org.hyperledger.besu.ethereum.api.jsonrpc.websocket.WebSocketConfiguration; import org.hyperledger.besu.ethereum.api.query.BlockchainQueries; -import org.hyperledger.besu.ethereum.blockcreation.EthHashMiningCoordinator; +import org.hyperledger.besu.ethereum.blockcreation.PoWMiningCoordinator; import org.hyperledger.besu.ethereum.core.BlockchainSetupUtil; import org.hyperledger.besu.ethereum.core.PrivacyParameters; import org.hyperledger.besu.ethereum.core.Synchronizer; @@ -117,7 +117,7 @@ protected Map getRpcMethods( final Synchronizer synchronizerMock = mock(Synchronizer.class); final P2PNetwork peerDiscoveryMock = mock(P2PNetwork.class); final TransactionPool transactionPoolMock = mock(TransactionPool.class); - final EthHashMiningCoordinator miningCoordinatorMock = mock(EthHashMiningCoordinator.class); + final PoWMiningCoordinator miningCoordinatorMock = mock(PoWMiningCoordinator.class); when(transactionPoolMock.addLocalTransaction(any(Transaction.class))) .thenReturn(ValidationResult.valid()); // nonce too low tests uses a tx with nonce=16 diff --git a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/JsonRpcHttpServiceHostWhitelistTest.java b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/JsonRpcHttpServiceHostWhitelistTest.java index 9b330a3801a..374ffee5d13 100644 --- a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/JsonRpcHttpServiceHostWhitelistTest.java +++ b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/JsonRpcHttpServiceHostWhitelistTest.java @@ -25,7 +25,7 @@ import org.hyperledger.besu.ethereum.api.jsonrpc.methods.JsonRpcMethodsFactory; import org.hyperledger.besu.ethereum.api.jsonrpc.websocket.WebSocketConfiguration; import org.hyperledger.besu.ethereum.api.query.BlockchainQueries; -import org.hyperledger.besu.ethereum.blockcreation.EthHashMiningCoordinator; +import org.hyperledger.besu.ethereum.blockcreation.PoWMiningCoordinator; import org.hyperledger.besu.ethereum.core.PrivacyParameters; import org.hyperledger.besu.ethereum.core.Synchronizer; import org.hyperledger.besu.ethereum.eth.EthProtocol; @@ -108,7 +108,7 @@ public void initServerAndClient() throws Exception { new StubGenesisConfigOptions().constantinopleBlock(0).chainId(CHAIN_ID)), mock(FilterManager.class), mock(TransactionPool.class), - mock(EthHashMiningCoordinator.class), + mock(PoWMiningCoordinator.class), new NoOpMetricsSystem(), supportedCapabilities, Optional.of(mock(AccountLocalConfigPermissioningController.class)), diff --git a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/JsonRpcHttpServiceLoginTest.java b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/JsonRpcHttpServiceLoginTest.java index 6eaecf0aea6..4af7172a850 100644 --- a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/JsonRpcHttpServiceLoginTest.java +++ b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/JsonRpcHttpServiceLoginTest.java @@ -34,7 +34,7 @@ import org.hyperledger.besu.ethereum.api.jsonrpc.methods.JsonRpcMethodsFactory; import org.hyperledger.besu.ethereum.api.jsonrpc.websocket.WebSocketConfiguration; import org.hyperledger.besu.ethereum.api.query.BlockchainQueries; -import org.hyperledger.besu.ethereum.blockcreation.EthHashMiningCoordinator; +import org.hyperledger.besu.ethereum.blockcreation.PoWMiningCoordinator; import org.hyperledger.besu.ethereum.core.PrivacyParameters; import org.hyperledger.besu.ethereum.core.Synchronizer; import org.hyperledger.besu.ethereum.eth.EthProtocol; @@ -134,7 +134,7 @@ public static void initServerAndClient() throws Exception { MainnetProtocolSchedule.fromConfig(genesisConfigOptions), mock(FilterManager.class), mock(TransactionPool.class), - mock(EthHashMiningCoordinator.class), + mock(PoWMiningCoordinator.class), new NoOpMetricsSystem(), supportedCapabilities, Optional.empty(), diff --git a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/JsonRpcHttpServiceRpcApisTest.java b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/JsonRpcHttpServiceRpcApisTest.java index 6ba804079b0..0ebcdc9c617 100644 --- a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/JsonRpcHttpServiceRpcApisTest.java +++ b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/JsonRpcHttpServiceRpcApisTest.java @@ -28,7 +28,7 @@ import org.hyperledger.besu.ethereum.api.jsonrpc.methods.JsonRpcMethodsFactory; import org.hyperledger.besu.ethereum.api.jsonrpc.websocket.WebSocketConfiguration; import org.hyperledger.besu.ethereum.api.query.BlockchainQueries; -import org.hyperledger.besu.ethereum.blockcreation.EthHashMiningCoordinator; +import org.hyperledger.besu.ethereum.blockcreation.PoWMiningCoordinator; import org.hyperledger.besu.ethereum.core.InMemoryStorageProvider; import org.hyperledger.besu.ethereum.core.PrivacyParameters; import org.hyperledger.besu.ethereum.core.ProtocolScheduleFixture; @@ -203,7 +203,7 @@ private JsonRpcHttpService createJsonRpcHttpServiceWithRpcApis(final JsonRpcConf ProtocolScheduleFixture.MAINNET, mock(FilterManager.class), mock(TransactionPool.class), - mock(EthHashMiningCoordinator.class), + mock(PoWMiningCoordinator.class), new NoOpMetricsSystem(), supportedCapabilities, Optional.of(mock(AccountLocalConfigPermissioningController.class)), @@ -299,7 +299,7 @@ private JsonRpcHttpService createJsonRpcHttpService( ProtocolScheduleFixture.MAINNET, mock(FilterManager.class), mock(TransactionPool.class), - mock(EthHashMiningCoordinator.class), + mock(PoWMiningCoordinator.class), new NoOpMetricsSystem(), supportedCapabilities, Optional.of(mock(AccountLocalConfigPermissioningController.class)), diff --git a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/JsonRpcHttpServiceTest.java b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/JsonRpcHttpServiceTest.java index b2120d9bff7..58de50b50b2 100644 --- a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/JsonRpcHttpServiceTest.java +++ b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/JsonRpcHttpServiceTest.java @@ -34,7 +34,7 @@ import org.hyperledger.besu.ethereum.api.query.BlockWithMetadata; import org.hyperledger.besu.ethereum.api.query.BlockchainQueries; import org.hyperledger.besu.ethereum.api.query.TransactionWithMetadata; -import org.hyperledger.besu.ethereum.blockcreation.EthHashMiningCoordinator; +import org.hyperledger.besu.ethereum.blockcreation.PoWMiningCoordinator; import org.hyperledger.besu.ethereum.chain.Blockchain; import org.hyperledger.besu.ethereum.chain.ChainHead; import org.hyperledger.besu.ethereum.core.Address; @@ -144,7 +144,7 @@ public static void initServerAndClient() throws Exception { new StubGenesisConfigOptions().constantinopleBlock(0).chainId(CHAIN_ID)), mock(FilterManager.class), mock(TransactionPool.class), - mock(EthHashMiningCoordinator.class), + mock(PoWMiningCoordinator.class), new NoOpMetricsSystem(), supportedCapabilities, Optional.of(mock(AccountLocalConfigPermissioningController.class)), diff --git a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/JsonRpcHttpServiceTlsClientAuthTest.java b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/JsonRpcHttpServiceTlsClientAuthTest.java index 9fd7ad29bf1..d66049d06ab 100644 --- a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/JsonRpcHttpServiceTlsClientAuthTest.java +++ b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/JsonRpcHttpServiceTlsClientAuthTest.java @@ -35,7 +35,7 @@ import org.hyperledger.besu.ethereum.api.tls.FileBasedPasswordProvider; import org.hyperledger.besu.ethereum.api.tls.SelfSignedP12Certificate; import org.hyperledger.besu.ethereum.api.tls.TlsConfiguration; -import org.hyperledger.besu.ethereum.blockcreation.EthHashMiningCoordinator; +import org.hyperledger.besu.ethereum.blockcreation.PoWMiningCoordinator; import org.hyperledger.besu.ethereum.core.PrivacyParameters; import org.hyperledger.besu.ethereum.core.Synchronizer; import org.hyperledger.besu.ethereum.eth.EthProtocol; @@ -126,7 +126,7 @@ public void initServer() throws Exception { new StubGenesisConfigOptions().constantinopleBlock(0).chainId(CHAIN_ID)), mock(FilterManager.class), mock(TransactionPool.class), - mock(EthHashMiningCoordinator.class), + mock(PoWMiningCoordinator.class), new NoOpMetricsSystem(), supportedCapabilities, Optional.of(mock(AccountLocalConfigPermissioningController.class)), diff --git a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/JsonRpcHttpServiceTlsMisconfigurationTest.java b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/JsonRpcHttpServiceTlsMisconfigurationTest.java index bcddf932ff1..f2040f3b3cc 100644 --- a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/JsonRpcHttpServiceTlsMisconfigurationTest.java +++ b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/JsonRpcHttpServiceTlsMisconfigurationTest.java @@ -34,7 +34,7 @@ import org.hyperledger.besu.ethereum.api.tls.FileBasedPasswordProvider; import org.hyperledger.besu.ethereum.api.tls.SelfSignedP12Certificate; import org.hyperledger.besu.ethereum.api.tls.TlsConfiguration; -import org.hyperledger.besu.ethereum.blockcreation.EthHashMiningCoordinator; +import org.hyperledger.besu.ethereum.blockcreation.PoWMiningCoordinator; import org.hyperledger.besu.ethereum.core.PrivacyParameters; import org.hyperledger.besu.ethereum.core.Synchronizer; import org.hyperledger.besu.ethereum.eth.EthProtocol; @@ -114,7 +114,7 @@ public void beforeEach() throws IOException { new StubGenesisConfigOptions().constantinopleBlock(0).chainId(CHAIN_ID)), mock(FilterManager.class), mock(TransactionPool.class), - mock(EthHashMiningCoordinator.class), + mock(PoWMiningCoordinator.class), new NoOpMetricsSystem(), supportedCapabilities, Optional.of(mock(AccountLocalConfigPermissioningController.class)), diff --git a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/JsonRpcHttpServiceTlsTest.java b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/JsonRpcHttpServiceTlsTest.java index ec7c5f33225..9a96d4f2f7e 100644 --- a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/JsonRpcHttpServiceTlsTest.java +++ b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/JsonRpcHttpServiceTlsTest.java @@ -34,7 +34,7 @@ import org.hyperledger.besu.ethereum.api.tls.FileBasedPasswordProvider; import org.hyperledger.besu.ethereum.api.tls.SelfSignedP12Certificate; import org.hyperledger.besu.ethereum.api.tls.TlsConfiguration; -import org.hyperledger.besu.ethereum.blockcreation.EthHashMiningCoordinator; +import org.hyperledger.besu.ethereum.blockcreation.PoWMiningCoordinator; import org.hyperledger.besu.ethereum.core.PrivacyParameters; import org.hyperledger.besu.ethereum.core.Synchronizer; import org.hyperledger.besu.ethereum.eth.EthProtocol; @@ -117,7 +117,7 @@ public void initServer() throws Exception { new StubGenesisConfigOptions().constantinopleBlock(0).chainId(CHAIN_ID)), mock(FilterManager.class), mock(TransactionPool.class), - mock(EthHashMiningCoordinator.class), + mock(PoWMiningCoordinator.class), new NoOpMetricsSystem(), supportedCapabilities, Optional.of(mock(AccountLocalConfigPermissioningController.class)), diff --git a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGasPriceTest.java b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGasPriceTest.java index 5a84dccabf8..ce8479e7cf0 100644 --- a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGasPriceTest.java +++ b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGasPriceTest.java @@ -26,7 +26,7 @@ import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcResponse; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcSuccessResponse; import org.hyperledger.besu.ethereum.api.query.BlockchainQueries; -import org.hyperledger.besu.ethereum.blockcreation.EthHashMiningCoordinator; +import org.hyperledger.besu.ethereum.blockcreation.PoWMiningCoordinator; import org.hyperledger.besu.ethereum.chain.Blockchain; import org.hyperledger.besu.ethereum.core.Address; import org.hyperledger.besu.ethereum.core.Block; @@ -52,7 +52,7 @@ @RunWith(MockitoJUnitRunner.class) public class EthGasPriceTest { - @Mock private EthHashMiningCoordinator miningCoordinator; + @Mock private PoWMiningCoordinator miningCoordinator; @Mock private Blockchain blockchain; private EthGasPrice method; private final String JSON_RPC_VERSION = "2.0"; diff --git a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetTransactionReceiptTest.java b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetTransactionReceiptTest.java index 761687a8dc4..ad6f70f62ca 100644 --- a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetTransactionReceiptTest.java +++ b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetTransactionReceiptTest.java @@ -34,6 +34,7 @@ import org.hyperledger.besu.ethereum.core.Wei; import org.hyperledger.besu.ethereum.core.fees.TransactionGasBudgetCalculator; import org.hyperledger.besu.ethereum.core.fees.TransactionPriceCalculator; +import org.hyperledger.besu.ethereum.mainnet.PoWHasher; import org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule; import org.hyperledger.besu.ethereum.mainnet.ProtocolSpec; @@ -102,7 +103,8 @@ public class EthGetTransactionReceiptTest { TransactionPriceCalculator.frontier(), Optional.empty(), TransactionGasBudgetCalculator.frontier(), - null); + null, + PoWHasher.LIGHT); private final ProtocolSpec statusTransactionTypeSpec = new ProtocolSpec( "status", @@ -127,7 +129,8 @@ public class EthGetTransactionReceiptTest { TransactionPriceCalculator.frontier(), Optional.empty(), TransactionGasBudgetCalculator.frontier(), - null); + null, + PoWHasher.LIGHT); @SuppressWarnings("unchecked") private final ProtocolSchedule protocolSchedule = mock(ProtocolSchedule.class); diff --git a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetWorkTest.java b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetWorkTest.java index 604fe9ca38b..32c6ab99737 100644 --- a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetWorkTest.java +++ b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetWorkTest.java @@ -23,10 +23,10 @@ import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcErrorResponse; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcResponse; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcSuccessResponse; -import org.hyperledger.besu.ethereum.blockcreation.EthHashMiningCoordinator; +import org.hyperledger.besu.ethereum.blockcreation.PoWMiningCoordinator; import org.hyperledger.besu.ethereum.mainnet.DirectAcyclicGraphSeed; import org.hyperledger.besu.ethereum.mainnet.EpochCalculator; -import org.hyperledger.besu.ethereum.mainnet.EthHashSolverInputs; +import org.hyperledger.besu.ethereum.mainnet.PoWSolverInputs; import java.util.Optional; @@ -46,7 +46,7 @@ public class EthGetWorkTest { private final String hexValue = "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"; - @Mock private EthHashMiningCoordinator miningCoordinator; + @Mock private PoWMiningCoordinator miningCoordinator; @Before public void setUp() { @@ -63,8 +63,8 @@ public void shouldReturnCorrectMethodName() { @Test public void shouldReturnCorrectResultOnGenesisDAG() { final JsonRpcRequestContext request = requestWithParams(); - final EthHashSolverInputs values = - new EthHashSolverInputs( + final PoWSolverInputs values = + new PoWSolverInputs( UInt256.fromHexString(hexValue), BaseEncoding.base16().lowerCase().decode(hexValue), 0); final String[] expectedValue = { "0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", @@ -83,8 +83,8 @@ public void shouldReturnCorrectResultOnGenesisDAG() { @Test public void shouldReturnCorrectResultOnHighBlockSeed() { final JsonRpcRequestContext request = requestWithParams(); - final EthHashSolverInputs values = - new EthHashSolverInputs( + final PoWSolverInputs values = + new PoWSolverInputs( UInt256.fromHexString(hexValue), BaseEncoding.base16().lowerCase().decode(hexValue), 30000); @@ -113,8 +113,8 @@ public void shouldReturnCorrectResultOnHighBlockSeedEcip1099() { .thenReturn(new EpochCalculator.Ecip1099EpochCalculator()); method = new EthGetWork(miningCoordinator); final JsonRpcRequestContext request = requestWithParams(); - final EthHashSolverInputs values = - new EthHashSolverInputs( + final PoWSolverInputs values = + new PoWSolverInputs( UInt256.fromHexString(hexValue), BaseEncoding.base16().lowerCase().decode(hexValue), 60000); diff --git a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthHashrateTest.java b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthHashrateTest.java index e8a7ae882fc..915be2cf7ca 100644 --- a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthHashrateTest.java +++ b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthHashrateTest.java @@ -21,7 +21,7 @@ import org.hyperledger.besu.ethereum.api.jsonrpc.internal.JsonRpcRequestContext; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcResponse; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcSuccessResponse; -import org.hyperledger.besu.ethereum.blockcreation.EthHashMiningCoordinator; +import org.hyperledger.besu.ethereum.blockcreation.PoWMiningCoordinator; import java.util.Optional; @@ -34,7 +34,7 @@ @RunWith(MockitoJUnitRunner.class) public class EthHashrateTest { - @Mock private EthHashMiningCoordinator miningCoordinator; + @Mock private PoWMiningCoordinator miningCoordinator; private EthHashrate method; private final String JSON_RPC_VERSION = "2.0"; private final String ETH_METHOD = "eth_hashrate"; diff --git a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthMiningTest.java b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthMiningTest.java index 495e9099d7a..c7525734665 100644 --- a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthMiningTest.java +++ b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthMiningTest.java @@ -23,7 +23,7 @@ import org.hyperledger.besu.ethereum.api.jsonrpc.internal.JsonRpcRequestContext; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcResponse; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcSuccessResponse; -import org.hyperledger.besu.ethereum.blockcreation.EthHashMiningCoordinator; +import org.hyperledger.besu.ethereum.blockcreation.PoWMiningCoordinator; import org.junit.Before; import org.junit.Test; @@ -34,7 +34,7 @@ @RunWith(MockitoJUnitRunner.class) public class EthMiningTest { - @Mock private EthHashMiningCoordinator miningCoordinator; + @Mock private PoWMiningCoordinator miningCoordinator; private EthMining method; private final String JSON_RPC_VERSION = "2.0"; private final String ETH_METHOD = "eth_mining"; diff --git a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthSubmitWorkTest.java b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthSubmitWorkTest.java index 7a2b7ecfcb2..5a8eb162b1d 100644 --- a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthSubmitWorkTest.java +++ b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthSubmitWorkTest.java @@ -25,10 +25,10 @@ import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcErrorResponse; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcResponse; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcSuccessResponse; -import org.hyperledger.besu.ethereum.blockcreation.EthHashMiningCoordinator; +import org.hyperledger.besu.ethereum.blockcreation.PoWMiningCoordinator; import org.hyperledger.besu.ethereum.core.Hash; -import org.hyperledger.besu.ethereum.mainnet.EthHashSolution; -import org.hyperledger.besu.ethereum.mainnet.EthHashSolverInputs; +import org.hyperledger.besu.ethereum.mainnet.PoWSolution; +import org.hyperledger.besu.ethereum.mainnet.PoWSolverInputs; import java.util.Optional; @@ -49,7 +49,7 @@ public class EthSubmitWorkTest { private final String hexValue = "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"; - @Mock private EthHashMiningCoordinator miningCoordinator; + @Mock private PoWMiningCoordinator miningCoordinator; @Before public void setUp() { @@ -73,8 +73,8 @@ public void shouldFailIfNoMiningEnabled() { @Test public void shouldFailIfMissingArguments() { final JsonRpcRequestContext request = requestWithParams(); - final EthHashSolverInputs values = - new EthHashSolverInputs( + final PoWSolverInputs values = + new PoWSolverInputs( UInt256.fromHexString(hexValue), BaseEncoding.base16().lowerCase().decode(hexValue), 0); when(miningCoordinator.getWorkDefinition()).thenReturn(Optional.of(values)); assertThatThrownBy( @@ -84,8 +84,8 @@ public void shouldFailIfMissingArguments() { @Test public void shouldReturnTrueIfGivenCorrectResult() { - final EthHashSolverInputs firstInputs = - new EthHashSolverInputs( + final PoWSolverInputs firstInputs = + new PoWSolverInputs( UInt256.fromHexString( "0x0083126e978d4fdf3b645a1cac083126e978d4fdf3b645a1cac083126e978d4f"), new byte[] { @@ -94,8 +94,8 @@ public void shouldReturnTrueIfGivenCorrectResult() { }, 468); - final EthHashSolution expectedFirstOutput = - new EthHashSolution( + final PoWSolution expectedFirstOutput = + new PoWSolution( -6506032554016940193L, Hash.fromHexString( "0xc5e3c33c86d64d0641dd3c86e8ce4628fe0aac0ef7b4c087c5fcaa45d5046d90"), diff --git a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/miner/MinerStartTest.java b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/miner/MinerStartTest.java index bb5972d2de2..66dab370744 100644 --- a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/miner/MinerStartTest.java +++ b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/miner/MinerStartTest.java @@ -25,7 +25,7 @@ import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcResponse; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcSuccessResponse; import org.hyperledger.besu.ethereum.blockcreation.CoinbaseNotSetException; -import org.hyperledger.besu.ethereum.blockcreation.EthHashMiningCoordinator; +import org.hyperledger.besu.ethereum.blockcreation.PoWMiningCoordinator; import org.junit.Before; import org.junit.Test; @@ -38,7 +38,7 @@ public class MinerStartTest { private MinerStart method; - @Mock private EthHashMiningCoordinator miningCoordinator; + @Mock private PoWMiningCoordinator miningCoordinator; @Before public void before() { diff --git a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/miner/MinerStopTest.java b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/miner/MinerStopTest.java index e80509f6d61..aeb23886e25 100644 --- a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/miner/MinerStopTest.java +++ b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/miner/MinerStopTest.java @@ -21,7 +21,7 @@ import org.hyperledger.besu.ethereum.api.jsonrpc.internal.JsonRpcRequestContext; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcResponse; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcSuccessResponse; -import org.hyperledger.besu.ethereum.blockcreation.EthHashMiningCoordinator; +import org.hyperledger.besu.ethereum.blockcreation.PoWMiningCoordinator; import org.junit.Before; import org.junit.Test; @@ -34,7 +34,7 @@ public class MinerStopTest { private MinerStop method; - @Mock private EthHashMiningCoordinator miningCoordinator; + @Mock private PoWMiningCoordinator miningCoordinator; @Before public void before() { diff --git a/ethereum/blockcreation/src/main/java/org/hyperledger/besu/ethereum/blockcreation/AbstractMinerExecutor.java b/ethereum/blockcreation/src/main/java/org/hyperledger/besu/ethereum/blockcreation/AbstractMinerExecutor.java index 75db3d03648..8faec57542e 100644 --- a/ethereum/blockcreation/src/main/java/org/hyperledger/besu/ethereum/blockcreation/AbstractMinerExecutor.java +++ b/ethereum/blockcreation/src/main/java/org/hyperledger/besu/ethereum/blockcreation/AbstractMinerExecutor.java @@ -15,8 +15,8 @@ package org.hyperledger.besu.ethereum.blockcreation; import org.hyperledger.besu.ethereum.ProtocolContext; -import org.hyperledger.besu.ethereum.chain.EthHashObserver; import org.hyperledger.besu.ethereum.chain.MinedBlockObserver; +import org.hyperledger.besu.ethereum.chain.PoWObserver; import org.hyperledger.besu.ethereum.core.Address; import org.hyperledger.besu.ethereum.core.BlockHeader; import org.hyperledger.besu.ethereum.core.MiningParameters; @@ -72,7 +72,7 @@ protected AbstractMinerExecutor( public Optional startAsyncMining( final Subscribers observers, - final Subscribers ethHashObservers, + final Subscribers ethHashObservers, final BlockHeader parentHeader) { try { final M currentRunningMiner = createMiner(observers, ethHashObservers, parentHeader); @@ -98,7 +98,7 @@ public void awaitShutdown() throws InterruptedException { public abstract M createMiner( final Subscribers subscribers, - final Subscribers ethHashObservers, + final Subscribers ethHashObservers, final BlockHeader parentHeader); public void setExtraData(final Bytes extraData) { diff --git a/ethereum/blockcreation/src/main/java/org/hyperledger/besu/ethereum/blockcreation/AbstractMiningCoordinator.java b/ethereum/blockcreation/src/main/java/org/hyperledger/besu/ethereum/blockcreation/AbstractMiningCoordinator.java index 6c373ad584d..df6a2310933 100644 --- a/ethereum/blockcreation/src/main/java/org/hyperledger/besu/ethereum/blockcreation/AbstractMiningCoordinator.java +++ b/ethereum/blockcreation/src/main/java/org/hyperledger/besu/ethereum/blockcreation/AbstractMiningCoordinator.java @@ -17,8 +17,8 @@ import org.hyperledger.besu.ethereum.chain.BlockAddedEvent; import org.hyperledger.besu.ethereum.chain.BlockAddedObserver; import org.hyperledger.besu.ethereum.chain.Blockchain; -import org.hyperledger.besu.ethereum.chain.EthHashObserver; import org.hyperledger.besu.ethereum.chain.MinedBlockObserver; +import org.hyperledger.besu.ethereum.chain.PoWObserver; import org.hyperledger.besu.ethereum.core.Address; import org.hyperledger.besu.ethereum.core.Block; import org.hyperledger.besu.ethereum.core.BlockHeader; @@ -44,7 +44,7 @@ private enum State { } private final Subscribers minedBlockObservers = Subscribers.create(); - private final Subscribers ethHashObservers = Subscribers.create(); + private final Subscribers ethHashObservers = Subscribers.create(); private final AbstractMinerExecutor executor; private final SyncState syncState; protected final Blockchain blockchain; @@ -189,7 +189,7 @@ public void addMinedBlockObserver(final MinedBlockObserver obs) { } @Override - public void addEthHashObserver(final EthHashObserver obs) { + public void addEthHashObserver(final PoWObserver obs) { ethHashObservers.subscribe(obs); } diff --git a/ethereum/blockcreation/src/main/java/org/hyperledger/besu/ethereum/blockcreation/MiningCoordinator.java b/ethereum/blockcreation/src/main/java/org/hyperledger/besu/ethereum/blockcreation/MiningCoordinator.java index bc56d21e8fe..cba9a73bdbd 100644 --- a/ethereum/blockcreation/src/main/java/org/hyperledger/besu/ethereum/blockcreation/MiningCoordinator.java +++ b/ethereum/blockcreation/src/main/java/org/hyperledger/besu/ethereum/blockcreation/MiningCoordinator.java @@ -14,14 +14,14 @@ */ package org.hyperledger.besu.ethereum.blockcreation; -import org.hyperledger.besu.ethereum.chain.EthHashObserver; +import org.hyperledger.besu.ethereum.chain.PoWObserver; import org.hyperledger.besu.ethereum.core.Address; import org.hyperledger.besu.ethereum.core.Block; import org.hyperledger.besu.ethereum.core.BlockHeader; import org.hyperledger.besu.ethereum.core.Transaction; import org.hyperledger.besu.ethereum.core.Wei; -import org.hyperledger.besu.ethereum.mainnet.EthHashSolution; -import org.hyperledger.besu.ethereum.mainnet.EthHashSolverInputs; +import org.hyperledger.besu.ethereum.mainnet.PoWSolution; +import org.hyperledger.besu.ethereum.mainnet.PoWSolverInputs; import java.util.List; import java.util.Optional; @@ -71,12 +71,12 @@ default Optional hashesPerSecond() { return Optional.empty(); } - default Optional getWorkDefinition() { + default Optional getWorkDefinition() { throw new UnsupportedOperationException( "Current consensus mechanism prevents querying work definition."); } - default boolean submitWork(final EthHashSolution solution) { + default boolean submitWork(final PoWSolution solution) { throw new UnsupportedOperationException( "Current consensus mechanism prevents submission of work solutions."); } @@ -105,7 +105,7 @@ Optional createBlock( final List transactions, final List ommers); - default void addEthHashObserver(final EthHashObserver observer) {} + default void addEthHashObserver(final PoWObserver observer) {} void changeTargetGasLimit(final Long targetGasLimit); } diff --git a/ethereum/blockcreation/src/main/java/org/hyperledger/besu/ethereum/blockcreation/EthHashBlockCreator.java b/ethereum/blockcreation/src/main/java/org/hyperledger/besu/ethereum/blockcreation/PoWBlockCreator.java similarity index 79% rename from ethereum/blockcreation/src/main/java/org/hyperledger/besu/ethereum/blockcreation/EthHashBlockCreator.java rename to ethereum/blockcreation/src/main/java/org/hyperledger/besu/ethereum/blockcreation/PoWBlockCreator.java index 7c0a0a08061..77b469ceda8 100644 --- a/ethereum/blockcreation/src/main/java/org/hyperledger/besu/ethereum/blockcreation/EthHashBlockCreator.java +++ b/ethereum/blockcreation/src/main/java/org/hyperledger/besu/ethereum/blockcreation/PoWBlockCreator.java @@ -22,9 +22,9 @@ import org.hyperledger.besu.ethereum.core.Wei; import org.hyperledger.besu.ethereum.eth.transactions.PendingTransactions; import org.hyperledger.besu.ethereum.mainnet.EthHash; -import org.hyperledger.besu.ethereum.mainnet.EthHashSolution; -import org.hyperledger.besu.ethereum.mainnet.EthHashSolver; -import org.hyperledger.besu.ethereum.mainnet.EthHashSolverInputs; +import org.hyperledger.besu.ethereum.mainnet.PoWSolution; +import org.hyperledger.besu.ethereum.mainnet.PoWSolver; +import org.hyperledger.besu.ethereum.mainnet.PoWSolverInputs; import org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule; import java.math.BigInteger; @@ -34,18 +34,18 @@ import org.apache.tuweni.units.bigints.UInt256; -public class EthHashBlockCreator extends AbstractBlockCreator { +public class PoWBlockCreator extends AbstractBlockCreator { - private final EthHashSolver nonceSolver; + private final PoWSolver nonceSolver; - public EthHashBlockCreator( + public PoWBlockCreator( final Address coinbase, final ExtraDataCalculator extraDataCalculator, final PendingTransactions pendingTransactions, final ProtocolContext protocolContext, final ProtocolSchedule protocolSchedule, final GasLimitCalculator gasLimitCalculator, - final EthHashSolver nonceSolver, + final PoWSolver nonceSolver, final Wei minTransactionGasPrice, final Double minBlockOccupancyRatio, final BlockHeader parentHeader) { @@ -66,11 +66,10 @@ public EthHashBlockCreator( @Override protected BlockHeader createFinalBlockHeader(final SealableBlockHeader sealableBlockHeader) { - final EthHashSolverInputs workDefinition = generateNonceSolverInputs(sealableBlockHeader); - final EthHashSolution solution; + final PoWSolverInputs workDefinition = generateNonceSolverInputs(sealableBlockHeader); + final PoWSolution solution; try { - solution = - nonceSolver.solveFor(EthHashSolver.EthHashSolverJob.createFromInputs(workDefinition)); + solution = nonceSolver.solveFor(PoWSolver.PoWSolverJob.createFromInputs(workDefinition)); } catch (final InterruptedException ex) { throw new CancellationException(); } catch (final ExecutionException ex) { @@ -84,19 +83,18 @@ protected BlockHeader createFinalBlockHeader(final SealableBlockHeader sealableB .buildBlockHeader(); } - private EthHashSolverInputs generateNonceSolverInputs( - final SealableBlockHeader sealableBlockHeader) { + private PoWSolverInputs generateNonceSolverInputs(final SealableBlockHeader sealableBlockHeader) { final BigInteger difficulty = sealableBlockHeader.getDifficulty().toBigInteger(); final UInt256 target = difficulty.equals(BigInteger.ONE) ? UInt256.MAX_VALUE : UInt256.valueOf(EthHash.TARGET_UPPER_BOUND.divide(difficulty)); - return new EthHashSolverInputs( + return new PoWSolverInputs( target, EthHash.hashHeader(sealableBlockHeader), sealableBlockHeader.getNumber()); } - public Optional getWorkDefinition() { + public Optional getWorkDefinition() { return nonceSolver.getWorkDefinition(); } @@ -104,7 +102,7 @@ public Optional getHashesPerSecond() { return nonceSolver.hashesPerSecond(); } - public boolean submitWork(final EthHashSolution solution) { + public boolean submitWork(final PoWSolution solution) { return nonceSolver.submitSolution(solution); } diff --git a/ethereum/blockcreation/src/main/java/org/hyperledger/besu/ethereum/blockcreation/EthHashBlockMiner.java b/ethereum/blockcreation/src/main/java/org/hyperledger/besu/ethereum/blockcreation/PoWBlockMiner.java similarity index 74% rename from ethereum/blockcreation/src/main/java/org/hyperledger/besu/ethereum/blockcreation/EthHashBlockMiner.java rename to ethereum/blockcreation/src/main/java/org/hyperledger/besu/ethereum/blockcreation/PoWBlockMiner.java index 0cd093e7ec3..37e0b553dd0 100644 --- a/ethereum/blockcreation/src/main/java/org/hyperledger/besu/ethereum/blockcreation/EthHashBlockMiner.java +++ b/ethereum/blockcreation/src/main/java/org/hyperledger/besu/ethereum/blockcreation/PoWBlockMiner.java @@ -17,8 +17,8 @@ import org.hyperledger.besu.ethereum.ProtocolContext; import org.hyperledger.besu.ethereum.chain.MinedBlockObserver; import org.hyperledger.besu.ethereum.core.BlockHeader; -import org.hyperledger.besu.ethereum.mainnet.EthHashSolution; -import org.hyperledger.besu.ethereum.mainnet.EthHashSolverInputs; +import org.hyperledger.besu.ethereum.mainnet.PoWSolution; +import org.hyperledger.besu.ethereum.mainnet.PoWSolverInputs; import org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule; import org.hyperledger.besu.util.Subscribers; @@ -26,16 +26,16 @@ import java.util.function.Function; /** - * Provides the EthHash specific aspects of the mining operation - i.e. getting the work definition, - * reporting the hashrate of the miner and accepting work submissions. + * Provides the proof-of-work specific aspects of the mining operation - i.e. getting the work + * definition, reporting the hashrate of the miner and accepting work submissions. * *

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 { +public class PoWBlockMiner extends BlockMiner { - public EthHashBlockMiner( - final Function blockCreator, + public PoWBlockMiner( + final Function blockCreator, final ProtocolSchedule protocolSchedule, final ProtocolContext protocolContext, final Subscribers observers, @@ -44,7 +44,7 @@ public EthHashBlockMiner( super(blockCreator, protocolSchedule, protocolContext, observers, scheduler, parentHeader); } - public Optional getWorkDefinition() { + public Optional getWorkDefinition() { return minerBlockCreator.getWorkDefinition(); } @@ -52,7 +52,7 @@ public Optional getHashesPerSecond() { return minerBlockCreator.getHashesPerSecond(); } - public boolean submitWork(final EthHashSolution solution) { + public boolean submitWork(final PoWSolution solution) { return minerBlockCreator.submitWork(solution); } } diff --git a/ethereum/blockcreation/src/main/java/org/hyperledger/besu/ethereum/blockcreation/EthHashMinerExecutor.java b/ethereum/blockcreation/src/main/java/org/hyperledger/besu/ethereum/blockcreation/PoWMinerExecutor.java similarity index 83% rename from ethereum/blockcreation/src/main/java/org/hyperledger/besu/ethereum/blockcreation/EthHashMinerExecutor.java rename to ethereum/blockcreation/src/main/java/org/hyperledger/besu/ethereum/blockcreation/PoWMinerExecutor.java index 81c2917db36..7e73144516e 100644 --- a/ethereum/blockcreation/src/main/java/org/hyperledger/besu/ethereum/blockcreation/EthHashMinerExecutor.java +++ b/ethereum/blockcreation/src/main/java/org/hyperledger/besu/ethereum/blockcreation/PoWMinerExecutor.java @@ -15,29 +15,28 @@ package org.hyperledger.besu.ethereum.blockcreation; import org.hyperledger.besu.ethereum.ProtocolContext; -import org.hyperledger.besu.ethereum.chain.EthHashObserver; import org.hyperledger.besu.ethereum.chain.MinedBlockObserver; +import org.hyperledger.besu.ethereum.chain.PoWObserver; import org.hyperledger.besu.ethereum.core.Address; import org.hyperledger.besu.ethereum.core.BlockHeader; import org.hyperledger.besu.ethereum.core.MiningParameters; import org.hyperledger.besu.ethereum.eth.transactions.PendingTransactions; import org.hyperledger.besu.ethereum.mainnet.EpochCalculator; -import org.hyperledger.besu.ethereum.mainnet.EthHashSolver; -import org.hyperledger.besu.ethereum.mainnet.EthHasher; +import org.hyperledger.besu.ethereum.mainnet.PoWSolver; import org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule; import org.hyperledger.besu.util.Subscribers; import java.util.Optional; import java.util.function.Function; -public class EthHashMinerExecutor extends AbstractMinerExecutor { +public class PoWMinerExecutor extends AbstractMinerExecutor { protected volatile Optional

coinbase; protected boolean stratumMiningEnabled; protected final Iterable nonceGenerator; protected final EpochCalculator epochCalculator; - public EthHashMinerExecutor( + public PoWMinerExecutor( final ProtocolContext protocolContext, final ProtocolSchedule protocolSchedule, final PendingTransactions pendingTransactions, @@ -58,9 +57,9 @@ public EthHashMinerExecutor( } @Override - public Optional startAsyncMining( + public Optional startAsyncMining( final Subscribers observers, - final Subscribers ethHashObservers, + final Subscribers ethHashObservers, final BlockHeader parentHeader) { if (coinbase.isEmpty()) { throw new CoinbaseNotSetException("Unable to start mining without a coinbase."); @@ -69,20 +68,20 @@ public Optional startAsyncMining( } @Override - public EthHashBlockMiner createMiner( + public PoWBlockMiner createMiner( final Subscribers observers, - final Subscribers ethHashObservers, + final Subscribers ethHashObservers, final BlockHeader parentHeader) { - final EthHashSolver solver = - new EthHashSolver( + final PoWSolver solver = + new PoWSolver( nonceGenerator, - new EthHasher.Light(), + protocolSchedule.getByBlockNumber(parentHeader.getNumber() + 1).getPoWHasher(), stratumMiningEnabled, ethHashObservers, epochCalculator); - final Function blockCreator = + final Function blockCreator = (header) -> - new EthHashBlockCreator( + new PoWBlockCreator( coinbase.get(), parent -> extraData, pendingTransactions, @@ -94,7 +93,7 @@ public EthHashBlockMiner createMiner( minBlockOccupancyRatio, parentHeader); - return new EthHashBlockMiner( + return new PoWBlockMiner( blockCreator, protocolSchedule, protocolContext, observers, blockScheduler, parentHeader); } diff --git a/ethereum/blockcreation/src/main/java/org/hyperledger/besu/ethereum/blockcreation/EthHashMiningCoordinator.java b/ethereum/blockcreation/src/main/java/org/hyperledger/besu/ethereum/blockcreation/PoWMiningCoordinator.java similarity index 85% rename from ethereum/blockcreation/src/main/java/org/hyperledger/besu/ethereum/blockcreation/EthHashMiningCoordinator.java rename to ethereum/blockcreation/src/main/java/org/hyperledger/besu/ethereum/blockcreation/PoWMiningCoordinator.java index 85440437d76..7a5eb69b353 100644 --- a/ethereum/blockcreation/src/main/java/org/hyperledger/besu/ethereum/blockcreation/EthHashMiningCoordinator.java +++ b/ethereum/blockcreation/src/main/java/org/hyperledger/besu/ethereum/blockcreation/PoWMiningCoordinator.java @@ -22,8 +22,8 @@ import org.hyperledger.besu.ethereum.core.BlockHeader; import org.hyperledger.besu.ethereum.eth.sync.state.SyncState; import org.hyperledger.besu.ethereum.mainnet.EpochCalculator; -import org.hyperledger.besu.ethereum.mainnet.EthHashSolution; -import org.hyperledger.besu.ethereum.mainnet.EthHashSolverInputs; +import org.hyperledger.besu.ethereum.mainnet.PoWSolution; +import org.hyperledger.besu.ethereum.mainnet.PoWSolverInputs; import java.util.Optional; import java.util.concurrent.TimeUnit; @@ -36,20 +36,20 @@ * Responsible for determining when a block mining operation should be started/stopped, then * creating an appropriate miner and starting it running in a thread. */ -public class EthHashMiningCoordinator extends AbstractMiningCoordinator +public class PoWMiningCoordinator extends AbstractMiningCoordinator implements BlockAddedObserver { private static final Logger LOG = getLogger(); - private final EthHashMinerExecutor executor; + private final PoWMinerExecutor executor; private final Cache sealerHashRate; private volatile Optional cachedHashesPerSecond = Optional.empty(); - public EthHashMiningCoordinator( + public PoWMiningCoordinator( final Blockchain blockchain, - final EthHashMinerExecutor executor, + final PoWMinerExecutor executor, final SyncState syncState, final int remoteSealersLimit, final long remoteSealersTimeToLive) { @@ -96,7 +96,7 @@ private Optional remoteHashesPerSecond() { private Optional localHashesPerSecond() { final Optional currentHashesPerSecond = - currentRunningMiner.flatMap(EthHashBlockMiner::getHashesPerSecond); + currentRunningMiner.flatMap(PoWBlockMiner::getHashesPerSecond); if (currentHashesPerSecond.isPresent()) { cachedHashesPerSecond = currentHashesPerSecond; @@ -122,19 +122,19 @@ public void changeTargetGasLimit(final Long targetGasLimit) { } @Override - public Optional getWorkDefinition() { - return currentRunningMiner.flatMap(EthHashBlockMiner::getWorkDefinition); + public Optional getWorkDefinition() { + return currentRunningMiner.flatMap(PoWBlockMiner::getWorkDefinition); } @Override - public boolean submitWork(final EthHashSolution solution) { + public boolean submitWork(final PoWSolution solution) { synchronized (this) { return currentRunningMiner.map(miner -> miner.submitWork(solution)).orElse(false); } } @Override - protected void haltMiner(final EthHashBlockMiner miner) { + protected void haltMiner(final PoWBlockMiner miner) { miner.cancel(); miner.getHashesPerSecond().ifPresent(val -> cachedHashesPerSecond = Optional.of(val)); } diff --git a/ethereum/blockcreation/src/test/java/org/hyperledger/besu/ethereum/blockcreation/AbstractMiningCoordinatorTest.java b/ethereum/blockcreation/src/test/java/org/hyperledger/besu/ethereum/blockcreation/AbstractMiningCoordinatorTest.java index 14bb5f66853..a55670ae51e 100644 --- a/ethereum/blockcreation/src/test/java/org/hyperledger/besu/ethereum/blockcreation/AbstractMiningCoordinatorTest.java +++ b/ethereum/blockcreation/src/test/java/org/hyperledger/besu/ethereum/blockcreation/AbstractMiningCoordinatorTest.java @@ -44,9 +44,9 @@ public class AbstractMiningCoordinatorTest { new BlockHeaderTestFixture().buildHeader(), new BlockBody(Collections.emptyList(), Collections.emptyList())); private final Blockchain blockchain = mock(Blockchain.class); - private final EthHashMinerExecutor minerExecutor = mock(EthHashMinerExecutor.class); + private final PoWMinerExecutor minerExecutor = mock(PoWMinerExecutor.class); private final SyncState syncState = mock(SyncState.class); - private final EthHashBlockMiner blockMiner = mock(EthHashBlockMiner.class); + private final PoWBlockMiner blockMiner = mock(PoWBlockMiner.class); private final TestMiningCoordinator miningCoordinator = new TestMiningCoordinator(blockchain, minerExecutor, syncState); @@ -222,11 +222,11 @@ public void shouldNotStartMiningWhenBlockAddedAndInSyncIfStoppedThenStarted() { verifyNoMoreInteractions(minerExecutor, blockMiner); } - public static class TestMiningCoordinator extends AbstractMiningCoordinator { + public static class TestMiningCoordinator extends AbstractMiningCoordinator { public TestMiningCoordinator( final Blockchain blockchain, - final AbstractMinerExecutor executor, + final AbstractMinerExecutor executor, final SyncState syncState) { super(blockchain, executor, syncState); } diff --git a/ethereum/blockcreation/src/test/java/org/hyperledger/besu/ethereum/blockcreation/BlockMinerTest.java b/ethereum/blockcreation/src/test/java/org/hyperledger/besu/ethereum/blockcreation/BlockMinerTest.java index d6fc9a97b57..c9480eb80d3 100644 --- a/ethereum/blockcreation/src/test/java/org/hyperledger/besu/ethereum/blockcreation/BlockMinerTest.java +++ b/ethereum/blockcreation/src/test/java/org/hyperledger/besu/ethereum/blockcreation/BlockMinerTest.java @@ -53,8 +53,8 @@ public void blockCreatedIsAddedToBlockChain() throws InterruptedException { final ProtocolContext protocolContext = new ProtocolContext(null, null, null); - final EthHashBlockCreator blockCreator = mock(EthHashBlockCreator.class); - final Function blockCreatorSupplier = + final PoWBlockCreator blockCreator = mock(PoWBlockCreator.class); + final Function blockCreatorSupplier = (parentHeader) -> blockCreator; when(blockCreator.createBlock(anyLong())).thenReturn(blockToCreate); @@ -69,8 +69,8 @@ public void blockCreatedIsAddedToBlockChain() throws InterruptedException { final MinedBlockObserver observer = mock(MinedBlockObserver.class); final DefaultBlockScheduler scheduler = mock(DefaultBlockScheduler.class); when(scheduler.waitUntilNextBlockCanBeMined(any())).thenReturn(5L); - final BlockMiner miner = - new EthHashBlockMiner( + final BlockMiner miner = + new PoWBlockMiner( blockCreatorSupplier, protocolSchedule, protocolContext, @@ -93,8 +93,8 @@ public void failureToImportDoesNotTriggerObservers() throws InterruptedException final ProtocolContext protocolContext = new ProtocolContext(null, null, null); - final EthHashBlockCreator blockCreator = mock(EthHashBlockCreator.class); - final Function blockCreatorSupplier = + final PoWBlockCreator blockCreator = mock(PoWBlockCreator.class); + final Function blockCreatorSupplier = (parentHeader) -> blockCreator; when(blockCreator.createBlock(anyLong())).thenReturn(blockToCreate); @@ -108,8 +108,8 @@ public void failureToImportDoesNotTriggerObservers() throws InterruptedException final MinedBlockObserver observer = mock(MinedBlockObserver.class); final DefaultBlockScheduler scheduler = mock(DefaultBlockScheduler.class); when(scheduler.waitUntilNextBlockCanBeMined(any())).thenReturn(5L); - final BlockMiner miner = - new EthHashBlockMiner( + final BlockMiner miner = + new PoWBlockMiner( blockCreatorSupplier, protocolSchedule, protocolContext, diff --git a/ethereum/blockcreation/src/test/java/org/hyperledger/besu/ethereum/blockcreation/HashRateMiningCoordinatorTest.java b/ethereum/blockcreation/src/test/java/org/hyperledger/besu/ethereum/blockcreation/HashRateMiningCoordinatorTest.java index 95de4bc1c84..dffe653feec 100644 --- a/ethereum/blockcreation/src/test/java/org/hyperledger/besu/ethereum/blockcreation/HashRateMiningCoordinatorTest.java +++ b/ethereum/blockcreation/src/test/java/org/hyperledger/besu/ethereum/blockcreation/HashRateMiningCoordinatorTest.java @@ -33,7 +33,7 @@ public class HashRateMiningCoordinatorTest { private final Blockchain blockchain = mock(Blockchain.class); private final SyncState syncState = mock(SyncState.class); - private final EthHashMinerExecutor minerExecutor = mock(EthHashMinerExecutor.class); + private final PoWMinerExecutor minerExecutor = mock(PoWMinerExecutor.class); private final String id; private final Long hashRate; private final Long wantTotalHashrate; @@ -66,8 +66,8 @@ public HashRateMiningCoordinatorTest( @Test public void test() { - final EthHashMiningCoordinator miningCoordinator = - new EthHashMiningCoordinator(blockchain, minerExecutor, syncState, 1000, 10); + final PoWMiningCoordinator miningCoordinator = + new PoWMiningCoordinator(blockchain, minerExecutor, syncState, 1000, 10); for (int i = 0; i < startSealersSize; i++) { miningCoordinator.submitHashRate(UUID.randomUUID().toString(), 1L); } diff --git a/ethereum/blockcreation/src/test/java/org/hyperledger/besu/ethereum/blockcreation/EthHashBlockCreatorTest.java b/ethereum/blockcreation/src/test/java/org/hyperledger/besu/ethereum/blockcreation/PoWBlockCreatorTest.java similarity index 90% rename from ethereum/blockcreation/src/test/java/org/hyperledger/besu/ethereum/blockcreation/EthHashBlockCreatorTest.java rename to ethereum/blockcreation/src/test/java/org/hyperledger/besu/ethereum/blockcreation/PoWBlockCreatorTest.java index 7ea143588c6..61da05ee342 100644 --- a/ethereum/blockcreation/src/test/java/org/hyperledger/besu/ethereum/blockcreation/EthHashBlockCreatorTest.java +++ b/ethereum/blockcreation/src/test/java/org/hyperledger/besu/ethereum/blockcreation/PoWBlockCreatorTest.java @@ -31,8 +31,8 @@ import org.hyperledger.besu.ethereum.eth.transactions.PendingTransactions; import org.hyperledger.besu.ethereum.eth.transactions.TransactionPoolConfiguration; import org.hyperledger.besu.ethereum.mainnet.EpochCalculator; -import org.hyperledger.besu.ethereum.mainnet.EthHashSolver; -import org.hyperledger.besu.ethereum.mainnet.EthHasher; +import org.hyperledger.besu.ethereum.mainnet.PoWHasher; +import org.hyperledger.besu.ethereum.mainnet.PoWSolver; import org.hyperledger.besu.ethereum.mainnet.ProtocolScheduleBuilder; import org.hyperledger.besu.ethereum.mainnet.ValidationTestUtils; import org.hyperledger.besu.metrics.noop.NoOpMetricsSystem; @@ -49,7 +49,7 @@ import org.apache.tuweni.bytes.Bytes; import org.junit.Test; -public class EthHashBlockCreatorTest { +public class PoWBlockCreatorTest { private final Address BLOCK_1_COINBASE = Address.fromHexString("0x05a56e2d52c817161883f50c441c3228cfe54d9f"); @@ -74,14 +74,15 @@ public void createMainnetBlock1() throws IOException { Function.identity(), PrivacyParameters.DEFAULT, false, - genesisConfigOptions.isQuorum()) + genesisConfigOptions.isQuorum(), + genesisConfigOptions.getPowAlgorithm()) .createProtocolSchedule()) .build(); - final EthHashSolver solver = - new EthHashSolver( + final PoWSolver solver = + new PoWSolver( Lists.newArrayList(BLOCK_1_NONCE), - new EthHasher.Light(), + PoWHasher.LIGHT, false, Subscribers.none(), new EpochCalculator.DefaultEpochCalculator()); @@ -96,8 +97,8 @@ public void createMainnetBlock1() throws IOException { executionContextTestFixture.getProtocolContext().getBlockchain()::getChainHeadHeader, TransactionPoolConfiguration.DEFAULT_PRICE_BUMP); - final EthHashBlockCreator blockCreator = - new EthHashBlockCreator( + final PoWBlockCreator blockCreator = + new PoWBlockCreator( BLOCK_1_COINBASE, parent -> BLOCK_1_EXTRA_DATA, pendingTransactions, @@ -133,14 +134,15 @@ public void createMainnetBlock1_fixedDifficulty1() { Function.identity(), PrivacyParameters.DEFAULT, false, - genesisConfigOptions.isQuorum()) + genesisConfigOptions.isQuorum(), + genesisConfigOptions.getPowAlgorithm()) .createProtocolSchedule()) .build(); - final EthHashSolver solver = - new EthHashSolver( + final PoWSolver solver = + new PoWSolver( Lists.newArrayList(BLOCK_1_NONCE), - new EthHasher.Light(), + PoWHasher.LIGHT, false, Subscribers.none(), new EpochCalculator.DefaultEpochCalculator()); @@ -155,8 +157,8 @@ public void createMainnetBlock1_fixedDifficulty1() { executionContextTestFixture.getProtocolContext().getBlockchain()::getChainHeadHeader, TransactionPoolConfiguration.DEFAULT_PRICE_BUMP); - final EthHashBlockCreator blockCreator = - new EthHashBlockCreator( + final PoWBlockCreator blockCreator = + new PoWBlockCreator( BLOCK_1_COINBASE, parent -> BLOCK_1_EXTRA_DATA, pendingTransactions, @@ -187,14 +189,15 @@ public void rewardBeneficiary_zeroReward_skipZeroRewardsFalse() { Function.identity(), PrivacyParameters.DEFAULT, false, - genesisConfigOptions.isQuorum()) + genesisConfigOptions.isQuorum(), + genesisConfigOptions.getPowAlgorithm()) .createProtocolSchedule()) .build(); - final EthHashSolver solver = - new EthHashSolver( + final PoWSolver solver = + new PoWSolver( Lists.newArrayList(BLOCK_1_NONCE), - new EthHasher.Light(), + PoWHasher.LIGHT, false, Subscribers.none(), new EpochCalculator.DefaultEpochCalculator()); @@ -209,8 +212,8 @@ public void rewardBeneficiary_zeroReward_skipZeroRewardsFalse() { executionContextTestFixture.getProtocolContext().getBlockchain()::getChainHeadHeader, TransactionPoolConfiguration.DEFAULT_PRICE_BUMP); - final EthHashBlockCreator blockCreator = - new EthHashBlockCreator( + final PoWBlockCreator blockCreator = + new PoWBlockCreator( BLOCK_1_COINBASE, parent -> BLOCK_1_EXTRA_DATA, pendingTransactions, @@ -257,14 +260,15 @@ public void rewardBeneficiary_zeroReward_skipZeroRewardsTrue() { Function.identity(), PrivacyParameters.DEFAULT, false, - genesisConfigOptions.isQuorum()) + genesisConfigOptions.isQuorum(), + genesisConfigOptions.getPowAlgorithm()) .createProtocolSchedule()) .build(); - final EthHashSolver solver = - new EthHashSolver( + final PoWSolver solver = + new PoWSolver( Lists.newArrayList(BLOCK_1_NONCE), - new EthHasher.Light(), + PoWHasher.LIGHT, false, Subscribers.none(), new EpochCalculator.DefaultEpochCalculator()); @@ -279,8 +283,8 @@ public void rewardBeneficiary_zeroReward_skipZeroRewardsTrue() { executionContextTestFixture.getProtocolContext().getBlockchain()::getChainHeadHeader, TransactionPoolConfiguration.DEFAULT_PRICE_BUMP); - final EthHashBlockCreator blockCreator = - new EthHashBlockCreator( + final PoWBlockCreator blockCreator = + new PoWBlockCreator( BLOCK_1_COINBASE, parent -> BLOCK_1_EXTRA_DATA, pendingTransactions, diff --git a/ethereum/blockcreation/src/test/java/org/hyperledger/besu/ethereum/blockcreation/EthHashMinerExecutorTest.java b/ethereum/blockcreation/src/test/java/org/hyperledger/besu/ethereum/blockcreation/PoWMinerExecutorTest.java similarity index 94% rename from ethereum/blockcreation/src/test/java/org/hyperledger/besu/ethereum/blockcreation/EthHashMinerExecutorTest.java rename to ethereum/blockcreation/src/test/java/org/hyperledger/besu/ethereum/blockcreation/PoWMinerExecutorTest.java index 6fde2d92f9d..589ec87f89d 100644 --- a/ethereum/blockcreation/src/test/java/org/hyperledger/besu/ethereum/blockcreation/EthHashMinerExecutorTest.java +++ b/ethereum/blockcreation/src/test/java/org/hyperledger/besu/ethereum/blockcreation/PoWMinerExecutorTest.java @@ -28,7 +28,7 @@ import org.junit.Test; -public class EthHashMinerExecutorTest { +public class PoWMinerExecutorTest { private final MetricsSystem metricsSystem = new NoOpMetricsSystem(); @Test @@ -46,8 +46,8 @@ public void startingMiningWithoutCoinbaseThrowsException() { () -> null, TransactionPoolConfiguration.DEFAULT_PRICE_BUMP); - final EthHashMinerExecutor executor = - new EthHashMinerExecutor( + final PoWMinerExecutor executor = + new PoWMinerExecutor( null, null, pendingTransactions, @@ -75,8 +75,8 @@ public void settingCoinbaseToNullThrowsException() { () -> null, TransactionPoolConfiguration.DEFAULT_PRICE_BUMP); - final EthHashMinerExecutor executor = - new EthHashMinerExecutor( + final PoWMinerExecutor executor = + new PoWMinerExecutor( null, null, pendingTransactions, diff --git a/ethereum/blockcreation/src/test/java/org/hyperledger/besu/ethereum/blockcreation/EthHashMiningCoordinatorTest.java b/ethereum/blockcreation/src/test/java/org/hyperledger/besu/ethereum/blockcreation/PoWMiningCoordinatorTest.java similarity index 85% rename from ethereum/blockcreation/src/test/java/org/hyperledger/besu/ethereum/blockcreation/EthHashMiningCoordinatorTest.java rename to ethereum/blockcreation/src/test/java/org/hyperledger/besu/ethereum/blockcreation/PoWMiningCoordinatorTest.java index 50036baeb73..227dd35f1f2 100644 --- a/ethereum/blockcreation/src/test/java/org/hyperledger/besu/ethereum/blockcreation/EthHashMiningCoordinatorTest.java +++ b/ethereum/blockcreation/src/test/java/org/hyperledger/besu/ethereum/blockcreation/PoWMiningCoordinatorTest.java @@ -24,7 +24,7 @@ import org.hyperledger.besu.ethereum.core.ExecutionContextTestFixture; import org.hyperledger.besu.ethereum.core.Hash; import org.hyperledger.besu.ethereum.eth.sync.state.SyncState; -import org.hyperledger.besu.ethereum.mainnet.EthHashSolution; +import org.hyperledger.besu.ethereum.mainnet.PoWSolution; import java.util.Optional; @@ -32,12 +32,12 @@ import org.junit.Before; import org.junit.Test; -public class EthHashMiningCoordinatorTest { +public class PoWMiningCoordinatorTest { private final ExecutionContextTestFixture executionContext = ExecutionContextTestFixture.create(); private final SyncState syncState = mock(SyncState.class); - private final EthHashMinerExecutor executor = mock(EthHashMinerExecutor.class); - private final EthHashBlockMiner miner = mock(EthHashBlockMiner.class); + private final PoWMinerExecutor executor = mock(PoWMinerExecutor.class); + private final PoWBlockMiner miner = mock(PoWBlockMiner.class); @Before public void setUp() { @@ -46,14 +46,14 @@ public void setUp() { @Test public void miningCoordinatorIsCreatedDisabledWithNoReportableMiningStatistics() { - final EthHashMiningCoordinator miningCoordinator = - new EthHashMiningCoordinator( + final PoWMiningCoordinator miningCoordinator = + new PoWMiningCoordinator( executionContext.getBlockchain(), executor, syncState, DEFAULT_REMOTE_SEALERS_LIMIT, DEFAULT_REMOTE_SEALERS_TTL); - final EthHashSolution solution = new EthHashSolution(1L, Hash.EMPTY, new byte[Bytes32.SIZE]); + final PoWSolution solution = new PoWSolution(1L, Hash.EMPTY, new byte[Bytes32.SIZE]); assertThat(miningCoordinator.isMining()).isFalse(); assertThat(miningCoordinator.hashesPerSecond()).isEqualTo(Optional.empty()); @@ -72,8 +72,8 @@ public void reportedHashRateIsCachedIfNoCurrentDataInMiner() { when(executor.startAsyncMining(any(), any(), any())).thenReturn(Optional.of(miner)); - final EthHashMiningCoordinator miningCoordinator = - new EthHashMiningCoordinator( + final PoWMiningCoordinator miningCoordinator = + new PoWMiningCoordinator( executionContext.getBlockchain(), executor, syncState, diff --git a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/chain/EthHashObserver.java b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/chain/PoWObserver.java similarity index 75% rename from ethereum/core/src/main/java/org/hyperledger/besu/ethereum/chain/EthHashObserver.java rename to ethereum/core/src/main/java/org/hyperledger/besu/ethereum/chain/PoWObserver.java index 402222f9312..09fb049286e 100644 --- a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/chain/EthHashObserver.java +++ b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/chain/PoWObserver.java @@ -14,20 +14,20 @@ */ package org.hyperledger.besu.ethereum.chain; -import org.hyperledger.besu.ethereum.mainnet.EthHashSolution; -import org.hyperledger.besu.ethereum.mainnet.EthHashSolverInputs; +import org.hyperledger.besu.ethereum.mainnet.PoWSolution; +import org.hyperledger.besu.ethereum.mainnet.PoWSolverInputs; import java.util.function.Function; -/** Observer of new work for the EthHash PoW algorithm */ -public interface EthHashObserver { +/** Observer of new work for the PoW algorithm */ +public interface PoWObserver { /** * Send a new proof-of-work job to observers * * @param jobInput the proof-of-work job */ - void newJob(EthHashSolverInputs jobInput); + void newJob(PoWSolverInputs jobInput); /** * Sets a callback for the observer to provide solutions to jobs. @@ -35,5 +35,5 @@ public interface EthHashObserver { * @param submitSolutionCallback the callback to set on the observer, consuming a solution and * returning true if the solution is accepted, false if rejected. */ - void setSubmitWorkCallback(Function submitSolutionCallback); + void setSubmitWorkCallback(Function submitSolutionCallback); } diff --git a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/difficulty/fixed/FixedDifficultyProtocolSchedule.java b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/difficulty/fixed/FixedDifficultyProtocolSchedule.java index 014ea997fa4..505598c6c60 100644 --- a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/difficulty/fixed/FixedDifficultyProtocolSchedule.java +++ b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/difficulty/fixed/FixedDifficultyProtocolSchedule.java @@ -31,7 +31,8 @@ public static ProtocolSchedule create( builder -> builder.difficultyCalculator(FixedDifficultyCalculators.calculator(config)), privacyParameters, isRevertReasonEnabled, - config.isQuorum()) + config.isQuorum(), + config.getPowAlgorithm()) .createProtocolSchedule(); } diff --git a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/ClassicProtocolSpecs.java b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/ClassicProtocolSpecs.java index d13733ddd25..3b7815c65fb 100644 --- a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/ClassicProtocolSpecs.java +++ b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/ClassicProtocolSpecs.java @@ -14,6 +14,9 @@ */ package org.hyperledger.besu.ethereum.mainnet; +import static org.hyperledger.besu.ethereum.mainnet.MainnetProtocolSpecs.powHasher; + +import org.hyperledger.besu.config.PowAlgorithm; import org.hyperledger.besu.ethereum.core.Account; import org.hyperledger.besu.ethereum.core.TransactionReceipt; import org.hyperledger.besu.ethereum.core.Wei; @@ -37,10 +40,12 @@ public class ClassicProtocolSpecs { public static ProtocolSpecBuilder classicRecoveryInitDefinition( final OptionalInt contractSizeLimit, final OptionalInt configStackSizeLimit, - final boolean quorumCompatibilityMode) { + final boolean quorumCompatibilityMode, + final PowAlgorithm powAlgorithm) { return MainnetProtocolSpecs.homesteadDefinition( - contractSizeLimit, configStackSizeLimit, quorumCompatibilityMode) - .blockHeaderValidatorBuilder(MainnetBlockHeaderValidator.createClassicValidator()) + contractSizeLimit, configStackSizeLimit, quorumCompatibilityMode, powAlgorithm) + .blockHeaderValidatorBuilder( + MainnetBlockHeaderValidator.createClassicValidator(powHasher(powAlgorithm))) .name("ClassicRecoveryInit"); } @@ -48,9 +53,10 @@ public static ProtocolSpecBuilder tangerineWhistleDefinition( final Optional chainId, final OptionalInt contractSizeLimit, final OptionalInt configStackSizeLimit, - final boolean quorumCompatibilityMode) { + final boolean quorumCompatibilityMode, + final PowAlgorithm powAlgorithm) { return MainnetProtocolSpecs.homesteadDefinition( - contractSizeLimit, configStackSizeLimit, quorumCompatibilityMode) + contractSizeLimit, configStackSizeLimit, quorumCompatibilityMode, powAlgorithm) .gasCalculator(TangerineWhistleGasCalculator::new) .transactionValidatorBuilder( gasCalculator -> @@ -63,9 +69,14 @@ public static ProtocolSpecBuilder dieHardDefinition( final Optional chainId, final OptionalInt configContractSizeLimit, final OptionalInt configStackSizeLimit, - final boolean quorumCompatibilityMode) { + final boolean quorumCompatibilityMode, + final PowAlgorithm powAlgorithm) { return tangerineWhistleDefinition( - chainId, OptionalInt.empty(), configStackSizeLimit, quorumCompatibilityMode) + chainId, + OptionalInt.empty(), + configStackSizeLimit, + quorumCompatibilityMode, + powAlgorithm) .gasCalculator(DieHardGasCalculator::new) .difficultyCalculator(ClassicDifficultyCalculators.DIFFICULTY_BOMB_PAUSED) .name("DieHard"); @@ -76,9 +87,10 @@ public static ProtocolSpecBuilder gothamDefinition( final OptionalInt contractSizeLimit, final OptionalInt configStackSizeLimit, final OptionalLong ecip1017EraRounds, - final boolean quorumCompatibilityMode) { + final boolean quorumCompatibilityMode, + final PowAlgorithm powAlgorithm) { return dieHardDefinition( - chainId, contractSizeLimit, configStackSizeLimit, quorumCompatibilityMode) + chainId, contractSizeLimit, configStackSizeLimit, quorumCompatibilityMode, powAlgorithm) .blockReward(MAX_BLOCK_REWARD) .difficultyCalculator(ClassicDifficultyCalculators.DIFFICULTY_BOMB_DELAYED) .blockProcessorBuilder( @@ -104,13 +116,15 @@ public static ProtocolSpecBuilder defuseDifficultyBombDefinition( final OptionalInt contractSizeLimit, final OptionalInt configStackSizeLimit, final OptionalLong ecip1017EraRounds, - final boolean quorumCompatibilityMode) { + final boolean quorumCompatibilityMode, + final PowAlgorithm powAlgorithm) { return gothamDefinition( chainId, contractSizeLimit, configStackSizeLimit, ecip1017EraRounds, - quorumCompatibilityMode) + quorumCompatibilityMode, + powAlgorithm) .difficultyCalculator(ClassicDifficultyCalculators.DIFFICULTY_BOMB_REMOVED) .transactionValidatorBuilder( gasCalculator -> @@ -125,7 +139,8 @@ public static ProtocolSpecBuilder atlantisDefinition( final OptionalInt configStackSizeLimit, final boolean enableRevertReason, final OptionalLong ecip1017EraRounds, - final boolean quorumCompatibilityMode) { + final boolean quorumCompatibilityMode, + final PowAlgorithm powAlgorithm) { final int contractSizeLimit = configContractSizeLimit.orElse(MainnetProtocolSpecs.SPURIOUS_DRAGON_CONTRACT_SIZE_LIMIT); final int stackSizeLimit = configStackSizeLimit.orElse(MessageFrame.DEFAULT_MAX_STACK_SIZE); @@ -134,7 +149,8 @@ public static ProtocolSpecBuilder atlantisDefinition( configContractSizeLimit, configStackSizeLimit, ecip1017EraRounds, - quorumCompatibilityMode) + quorumCompatibilityMode, + powAlgorithm) .evmBuilder(MainnetEvmRegistries::byzantium) .gasCalculator(SpuriousDragonGasCalculator::new) .skipZeroBlockRewards(true) @@ -179,14 +195,16 @@ public static ProtocolSpecBuilder aghartaDefinition( final OptionalInt configStackSizeLimit, final boolean enableRevertReason, final OptionalLong ecip1017EraRounds, - final boolean quorumCompatibilityMode) { + final boolean quorumCompatibilityMode, + final PowAlgorithm powAlgorithm) { return atlantisDefinition( chainId, configContractSizeLimit, configStackSizeLimit, enableRevertReason, ecip1017EraRounds, - quorumCompatibilityMode) + quorumCompatibilityMode, + powAlgorithm) .evmBuilder(MainnetEvmRegistries::constantinople) .gasCalculator(PetersburgGasCalculator::new) .evmBuilder(gasCalculator -> MainnetEvmRegistries.constantinople(gasCalculator)) @@ -200,14 +218,16 @@ public static ProtocolSpecBuilder phoenixDefinition( final OptionalInt configStackSizeLimit, final boolean enableRevertReason, final OptionalLong ecip1017EraRounds, - final boolean quorumCompatibilityMode) { + final boolean quorumCompatibilityMode, + final PowAlgorithm powAlgorithm) { return aghartaDefinition( chainId, configContractSizeLimit, configStackSizeLimit, enableRevertReason, ecip1017EraRounds, - quorumCompatibilityMode) + quorumCompatibilityMode, + powAlgorithm) .gasCalculator(IstanbulGasCalculator::new) .evmBuilder( gasCalculator -> @@ -222,20 +242,22 @@ public static ProtocolSpecBuilder thanosDefinition( final OptionalInt configStackSizeLimit, final boolean enableRevertReason, final OptionalLong ecip1017EraRounds, - final boolean quorumCompatibilityMode) { + final boolean quorumCompatibilityMode, + final PowAlgorithm powAlgorithm) { return phoenixDefinition( chainId, configContractSizeLimit, configStackSizeLimit, enableRevertReason, ecip1017EraRounds, - quorumCompatibilityMode) + quorumCompatibilityMode, + powAlgorithm) .blockHeaderValidatorBuilder( MainnetBlockHeaderValidator.createBlockHeaderValidator( - new EpochCalculator.Ecip1099EpochCalculator())) + new EpochCalculator.Ecip1099EpochCalculator(), powHasher(powAlgorithm))) .ommerHeaderValidatorBuilder( MainnetBlockHeaderValidator.createOmmerValidator( - new EpochCalculator.Ecip1099EpochCalculator())) + new EpochCalculator.Ecip1099EpochCalculator(), powHasher(powAlgorithm))) .name("Thanos"); } diff --git a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/MainnetBlockHeaderValidator.java b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/MainnetBlockHeaderValidator.java index 0bf0c716d9e..94a6b5653e5 100644 --- a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/MainnetBlockHeaderValidator.java +++ b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/MainnetBlockHeaderValidator.java @@ -40,19 +40,19 @@ public final class MainnetBlockHeaderValidator { public static final Bytes CLASSIC_FORK_BLOCK_HEADER = Bytes.fromHexString("0x94365e3a8c0b35089c1d1195081fe7489b528a84b22199c916180db8b28ade7f"); - public static BlockHeaderValidator.Builder create() { - return createValidator(); + public static BlockHeaderValidator.Builder create(final PoWHasher hasher) { + return createValidator(hasher); } - public static BlockHeaderValidator.Builder createDaoValidator() { - return createValidator() + public static BlockHeaderValidator.Builder createDaoValidator(final PoWHasher hasher) { + return createValidator(hasher) .addRule( new ConstantFieldValidationRule<>( "extraData", BlockHeader::getExtraData, DAO_EXTRA_DATA)); } - public static BlockHeaderValidator.Builder createClassicValidator() { - return createValidator() + public static BlockHeaderValidator.Builder createClassicValidator(final PoWHasher hasher) { + return createValidator(hasher) .addRule( new ConstantFieldValidationRule<>( "hash", @@ -68,11 +68,12 @@ public static boolean validateHeaderForClassicFork(final BlockHeader header) { return header.getNumber() != 1_920_000 || header.getHash().equals(CLASSIC_FORK_BLOCK_HEADER); } - static BlockHeaderValidator.Builder createOmmerValidator() { - return createOmmerValidator(new EpochCalculator.DefaultEpochCalculator()); + static BlockHeaderValidator.Builder createOmmerValidator(final PoWHasher hasher) { + return createOmmerValidator(new EpochCalculator.DefaultEpochCalculator(), hasher); } - static BlockHeaderValidator.Builder createOmmerValidator(final EpochCalculator epochCalculator) { + static BlockHeaderValidator.Builder createOmmerValidator( + final EpochCalculator epochCalculator, final PoWHasher hasher) { return new BlockHeaderValidator.Builder() .addRule(CalculatedDifficultyValidationRule::new) .addRule(new AncestryValidationRule()) @@ -80,15 +81,15 @@ static BlockHeaderValidator.Builder createOmmerValidator(final EpochCalculator e .addRule(new GasUsageValidationRule()) .addRule(new TimestampMoreRecentThanParent(MINIMUM_SECONDS_SINCE_PARENT)) .addRule(new ExtraDataMaxLengthValidationRule(BlockHeader.MAX_EXTRA_DATA_BYTES)) - .addRule(new ProofOfWorkValidationRule(epochCalculator)); + .addRule(new ProofOfWorkValidationRule(epochCalculator, false, hasher)); } - private static BlockHeaderValidator.Builder createValidator() { - return createBlockHeaderValidator(new EpochCalculator.DefaultEpochCalculator()); + private static BlockHeaderValidator.Builder createValidator(final PoWHasher hasher) { + return createBlockHeaderValidator(new EpochCalculator.DefaultEpochCalculator(), hasher); } static BlockHeaderValidator.Builder createBlockHeaderValidator( - final EpochCalculator epochCalculator) { + final EpochCalculator epochCalculator, final PoWHasher hasher) { return new BlockHeaderValidator.Builder() .addRule(CalculatedDifficultyValidationRule::new) .addRule(new AncestryValidationRule()) @@ -97,10 +98,11 @@ static BlockHeaderValidator.Builder createBlockHeaderValidator( .addRule(new TimestampMoreRecentThanParent(MINIMUM_SECONDS_SINCE_PARENT)) .addRule(new TimestampBoundedByFutureParameter(TIMESTAMP_TOLERANCE_S)) .addRule(new ExtraDataMaxLengthValidationRule(BlockHeader.MAX_EXTRA_DATA_BYTES)) - .addRule(new ProofOfWorkValidationRule(epochCalculator)); + .addRule(new ProofOfWorkValidationRule(epochCalculator, false, hasher)); } - static BlockHeaderValidator.Builder createEip1559Validator(final EIP1559 eip1559) { + static BlockHeaderValidator.Builder createEip1559Validator( + final EIP1559 eip1559, final PoWHasher hasher) { ExperimentalEIPs.eip1559MustBeEnabled(); return new BlockHeaderValidator.Builder() .addRule(CalculatedDifficultyValidationRule::new) @@ -109,11 +111,14 @@ static BlockHeaderValidator.Builder createEip1559Validator(final EIP1559 eip1559 .addRule(new TimestampMoreRecentThanParent(MINIMUM_SECONDS_SINCE_PARENT)) .addRule(new TimestampBoundedByFutureParameter(TIMESTAMP_TOLERANCE_S)) .addRule(new ExtraDataMaxLengthValidationRule(BlockHeader.MAX_EXTRA_DATA_BYTES)) - .addRule(new ProofOfWorkValidationRule(new EpochCalculator.DefaultEpochCalculator(), true)) + .addRule( + new ProofOfWorkValidationRule( + new EpochCalculator.DefaultEpochCalculator(), true, hasher)) .addRule((new EIP1559BlockHeaderGasPriceValidationRule(eip1559))); } - static BlockHeaderValidator.Builder createEip1559OmmerValidator(final EIP1559 eip1559) { + static BlockHeaderValidator.Builder createEip1559OmmerValidator( + final EIP1559 eip1559, final PoWHasher hasher) { ExperimentalEIPs.eip1559MustBeEnabled(); return new BlockHeaderValidator.Builder() .addRule(CalculatedDifficultyValidationRule::new) @@ -121,7 +126,9 @@ static BlockHeaderValidator.Builder createEip1559OmmerValidator(final EIP1559 ei .addRule(new GasUsageValidationRule()) .addRule(new TimestampMoreRecentThanParent(MINIMUM_SECONDS_SINCE_PARENT)) .addRule(new ExtraDataMaxLengthValidationRule(BlockHeader.MAX_EXTRA_DATA_BYTES)) - .addRule(new ProofOfWorkValidationRule(new EpochCalculator.DefaultEpochCalculator(), true)) + .addRule( + new ProofOfWorkValidationRule( + new EpochCalculator.DefaultEpochCalculator(), true, hasher)) .addRule((new EIP1559BlockHeaderGasPriceValidationRule(eip1559))); } } diff --git a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/MainnetProtocolSchedule.java b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/MainnetProtocolSchedule.java index 3fcc0eaf4a4..15c00effd9b 100644 --- a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/MainnetProtocolSchedule.java +++ b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/MainnetProtocolSchedule.java @@ -50,7 +50,8 @@ public static ProtocolSchedule fromConfig( Function.identity(), privacyParameters, isRevertReasonEnabled, - config.isQuorum()) + config.isQuorum(), + config.getPowAlgorithm()) .createProtocolSchedule(); } diff --git a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/MainnetProtocolSpecs.java b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/MainnetProtocolSpecs.java index 3942624153f..5f2138d98a3 100644 --- a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/MainnetProtocolSpecs.java +++ b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/MainnetProtocolSpecs.java @@ -15,6 +15,7 @@ package org.hyperledger.besu.ethereum.mainnet; import org.hyperledger.besu.config.GenesisConfigOptions; +import org.hyperledger.besu.config.PowAlgorithm; import org.hyperledger.besu.config.experimental.ExperimentalEIPs; import org.hyperledger.besu.ethereum.MainnetBlockValidator; import org.hyperledger.besu.ethereum.chain.Blockchain; @@ -86,7 +87,8 @@ private MainnetProtocolSpecs() {} public static ProtocolSpecBuilder frontierDefinition( final OptionalInt configContractSizeLimit, final OptionalInt configStackSizeLimit, - final boolean goQuorumMode) { + final boolean goQuorumMode, + final PowAlgorithm powAlgorithm) { final int contractSizeLimit = configContractSizeLimit.orElse(FRONTIER_CONTRACT_SIZE_LIMIT); final int stackSizeLimit = configStackSizeLimit.orElse(MessageFrame.DEFAULT_MAX_STACK_SIZE); return new ProtocolSpecBuilder() @@ -137,8 +139,9 @@ public static ProtocolSpecBuilder frontierDefinition( Account.DEFAULT_VERSION, new PrivateTransactionValidator(Optional.empty()))) .difficultyCalculator(MainnetDifficultyCalculators.FRONTIER) - .blockHeaderValidatorBuilder(MainnetBlockHeaderValidator.create()) - .ommerHeaderValidatorBuilder(MainnetBlockHeaderValidator.createOmmerValidator()) + .blockHeaderValidatorBuilder(MainnetBlockHeaderValidator.create(powHasher(powAlgorithm))) + .ommerHeaderValidatorBuilder( + MainnetBlockHeaderValidator.createOmmerValidator(powHasher(powAlgorithm))) .blockBodyValidatorBuilder(MainnetBlockBodyValidator::new) .transactionReceiptFactory(MainnetProtocolSpecs::frontierTransactionReceiptFactory) .blockReward(FRONTIER_BLOCK_REWARD) @@ -148,9 +151,23 @@ public static ProtocolSpecBuilder frontierDefinition( .blockImporterBuilder(MainnetBlockImporter::new) .blockHeaderFunctions(new MainnetBlockHeaderFunctions()) .miningBeneficiaryCalculator(BlockHeader::getCoinbase) + .powHasher(powHasher(powAlgorithm)) .name("Frontier"); } + public static PoWHasher powHasher(final PowAlgorithm powAlgorithm) { + if (powAlgorithm == null) { + return PoWHasher.NOOP; + } + switch (powAlgorithm) { + case ETHASH: + return PoWHasher.LIGHT; + case NONE: + default: + return PoWHasher.NOOP; + } + } + public static BlockValidatorBuilder blockValidatorBuilder(final boolean goQuorumMode) { if (goQuorumMode) { return GoQuorumBlockValidator::new; @@ -170,10 +187,11 @@ public static BlockProcessorBuilder blockProcessorBuilder(final boolean goQuorum public static ProtocolSpecBuilder homesteadDefinition( final OptionalInt configContractSizeLimit, final OptionalInt configStackSizeLimit, - final boolean quorumCompatibilityMode) { + final boolean quorumCompatibilityMode, + final PowAlgorithm powAlgorithm) { final int contractSizeLimit = configContractSizeLimit.orElse(FRONTIER_CONTRACT_SIZE_LIMIT); return frontierDefinition( - configContractSizeLimit, configStackSizeLimit, quorumCompatibilityMode) + configContractSizeLimit, configStackSizeLimit, quorumCompatibilityMode, powAlgorithm) .gasCalculator(HomesteadGasCalculator::new) .evmBuilder(MainnetEvmRegistries::homestead) .contractCreationProcessorBuilder( @@ -195,9 +213,12 @@ public static ProtocolSpecBuilder homesteadDefinition( public static ProtocolSpecBuilder daoRecoveryInitDefinition( final OptionalInt contractSizeLimit, final OptionalInt configStackSizeLimit, - final boolean quorumCompatibilityMode) { - return homesteadDefinition(contractSizeLimit, configStackSizeLimit, quorumCompatibilityMode) - .blockHeaderValidatorBuilder(MainnetBlockHeaderValidator.createDaoValidator()) + final boolean quorumCompatibilityMode, + final PowAlgorithm powAlgorithm) { + return homesteadDefinition( + contractSizeLimit, configStackSizeLimit, quorumCompatibilityMode, powAlgorithm) + .blockHeaderValidatorBuilder( + MainnetBlockHeaderValidator.createDaoValidator(powHasher(powAlgorithm))) .blockProcessorBuilder( (transactionProcessor, transactionReceiptFactory, @@ -221,9 +242,10 @@ public static ProtocolSpecBuilder daoRecoveryInitDefinition( public static ProtocolSpecBuilder daoRecoveryTransitionDefinition( final OptionalInt contractSizeLimit, final OptionalInt configStackSizeLimit, - final boolean quorumCompatibilityMode) { + final boolean quorumCompatibilityMode, + final PowAlgorithm powAlgorithm) { return daoRecoveryInitDefinition( - contractSizeLimit, configStackSizeLimit, quorumCompatibilityMode) + contractSizeLimit, configStackSizeLimit, quorumCompatibilityMode, powAlgorithm) .blockProcessorBuilder(MainnetBlockProcessor::new) .name("DaoRecoveryTransition"); } @@ -231,8 +253,10 @@ public static ProtocolSpecBuilder daoRecoveryTransitionDefinition( public static ProtocolSpecBuilder tangerineWhistleDefinition( final OptionalInt contractSizeLimit, final OptionalInt configStackSizeLimit, - final boolean quorumCompatibilityMode) { - return homesteadDefinition(contractSizeLimit, configStackSizeLimit, quorumCompatibilityMode) + final boolean quorumCompatibilityMode, + final PowAlgorithm powAlgorithm) { + return homesteadDefinition( + contractSizeLimit, configStackSizeLimit, quorumCompatibilityMode, powAlgorithm) .gasCalculator(TangerineWhistleGasCalculator::new) .name("TangerineWhistle"); } @@ -241,13 +265,14 @@ public static ProtocolSpecBuilder spuriousDragonDefinition( final Optional chainId, final OptionalInt configContractSizeLimit, final OptionalInt configStackSizeLimit, - final boolean quorumCompatibilityMode) { + final boolean quorumCompatibilityMode, + final PowAlgorithm powAlgorithm) { final int contractSizeLimit = configContractSizeLimit.orElse(SPURIOUS_DRAGON_CONTRACT_SIZE_LIMIT); final int stackSizeLimit = configStackSizeLimit.orElse(MessageFrame.DEFAULT_MAX_STACK_SIZE); return tangerineWhistleDefinition( - OptionalInt.empty(), configStackSizeLimit, quorumCompatibilityMode) + OptionalInt.empty(), configStackSizeLimit, quorumCompatibilityMode, powAlgorithm) .gasCalculator(SpuriousDragonGasCalculator::new) .skipZeroBlockRewards(true) .messageCallProcessorBuilder( @@ -292,10 +317,11 @@ public static ProtocolSpecBuilder byzantiumDefinition( final OptionalInt contractSizeLimit, final OptionalInt configStackSizeLimit, final boolean enableRevertReason, - final boolean quorumCompatibilityMode) { + final boolean quorumCompatibilityMode, + final PowAlgorithm powAlgorithm) { final int stackSizeLimit = configStackSizeLimit.orElse(MessageFrame.DEFAULT_MAX_STACK_SIZE); return spuriousDragonDefinition( - chainId, contractSizeLimit, configStackSizeLimit, quorumCompatibilityMode) + chainId, contractSizeLimit, configStackSizeLimit, quorumCompatibilityMode, powAlgorithm) .gasCalculator(ByzantiumGasCalculator::new) .evmBuilder(MainnetEvmRegistries::byzantium) .precompileContractRegistryBuilder(MainnetPrecompiledContractRegistries::byzantium) @@ -329,13 +355,15 @@ public static ProtocolSpecBuilder constantinopleDefinition( final OptionalInt contractSizeLimit, final OptionalInt configStackSizeLimit, final boolean enableRevertReason, - final boolean quorumCompatibilityMode) { + final boolean quorumCompatibilityMode, + final PowAlgorithm powAlgorithm) { return byzantiumDefinition( chainId, contractSizeLimit, configStackSizeLimit, enableRevertReason, - quorumCompatibilityMode) + quorumCompatibilityMode, + powAlgorithm) .difficultyCalculator(MainnetDifficultyCalculators.CONSTANTINOPLE) .gasCalculator(ConstantinopleGasCalculator::new) .evmBuilder(MainnetEvmRegistries::constantinople) @@ -348,13 +376,15 @@ public static ProtocolSpecBuilder petersburgDefinition( final OptionalInt contractSizeLimit, final OptionalInt configStackSizeLimit, final boolean enableRevertReason, - final boolean quorumCompatibilityMode) { + final boolean quorumCompatibilityMode, + final PowAlgorithm powAlgorithm) { return constantinopleDefinition( chainId, contractSizeLimit, configStackSizeLimit, enableRevertReason, - quorumCompatibilityMode) + quorumCompatibilityMode, + powAlgorithm) .gasCalculator(PetersburgGasCalculator::new) .name("Petersburg"); } @@ -364,7 +394,8 @@ public static ProtocolSpecBuilder istanbulDefinition( final OptionalInt configContractSizeLimit, final OptionalInt configStackSizeLimit, final boolean enableRevertReason, - final boolean quorumCompatibilityMode) { + final boolean quorumCompatibilityMode, + final PowAlgorithm powAlgorithm) { final int contractSizeLimit = configContractSizeLimit.orElse(SPURIOUS_DRAGON_CONTRACT_SIZE_LIMIT); return petersburgDefinition( @@ -372,7 +403,8 @@ public static ProtocolSpecBuilder istanbulDefinition( configContractSizeLimit, configStackSizeLimit, enableRevertReason, - quorumCompatibilityMode) + quorumCompatibilityMode, + powAlgorithm) .gasCalculator(IstanbulGasCalculator::new) .evmBuilder( gasCalculator -> @@ -395,13 +427,15 @@ static ProtocolSpecBuilder muirGlacierDefinition( final OptionalInt contractSizeLimit, final OptionalInt configStackSizeLimit, final boolean enableRevertReason, - final boolean quorumCompatibilityMode) { + final boolean quorumCompatibilityMode, + final PowAlgorithm powAlgorithm) { return istanbulDefinition( chainId, contractSizeLimit, configStackSizeLimit, enableRevertReason, - quorumCompatibilityMode) + quorumCompatibilityMode, + powAlgorithm) .difficultyCalculator(MainnetDifficultyCalculators.MUIR_GLACIER) .name("MuirGlacier"); } @@ -411,7 +445,8 @@ static ProtocolSpecBuilder berlinDefinition( final OptionalInt contractSizeLimit, final OptionalInt configStackSizeLimit, final boolean enableRevertReason, - final boolean quorumCompatibilityMode) { + final boolean quorumCompatibilityMode, + final PowAlgorithm powAlgorithm) { if (!ExperimentalEIPs.berlinEnabled) { throw new RuntimeException("Berlin feature flag must be enabled --Xberlin-enabled"); } @@ -420,7 +455,8 @@ static ProtocolSpecBuilder berlinDefinition( contractSizeLimit, configStackSizeLimit, enableRevertReason, - quorumCompatibilityMode) + quorumCompatibilityMode, + powAlgorithm) .gasCalculator(BerlinGasCalculator::new) .transactionValidatorBuilder( gasCalculator -> @@ -449,7 +485,8 @@ static ProtocolSpecBuilder eip1559Definition( final OptionalInt configStackSizeLimit, final boolean enableRevertReason, final GenesisConfigOptions genesisConfigOptions, - final boolean quorumCompatibilityMode) { + final boolean quorumCompatibilityMode, + final PowAlgorithm powAlgorithm) { ExperimentalEIPs.eip1559MustBeEnabled(); final int stackSizeLimit = configStackSizeLimit.orElse(MessageFrame.DEFAULT_MAX_STACK_SIZE); final EIP1559 eip1559 = new EIP1559(genesisConfigOptions.getEIP1559BlockNumber().orElse(0)); @@ -458,7 +495,8 @@ static ProtocolSpecBuilder eip1559Definition( contractSizeLimit, configStackSizeLimit, enableRevertReason, - quorumCompatibilityMode) + quorumCompatibilityMode, + powAlgorithm) .transactionValidatorBuilder( gasCalculator -> new MainnetTransactionValidator( @@ -487,9 +525,12 @@ static ProtocolSpecBuilder eip1559Definition( .transactionPriceCalculator(transactionPriceCalculator.orElseThrow()) .eip1559(Optional.of(eip1559)) .gasBudgetCalculator(TransactionGasBudgetCalculator.eip1559(eip1559)) - .blockHeaderValidatorBuilder(MainnetBlockHeaderValidator.createEip1559Validator(eip1559)) + .blockHeaderValidatorBuilder( + MainnetBlockHeaderValidator.createEip1559Validator(eip1559, powHasher(powAlgorithm))) .ommerHeaderValidatorBuilder( - MainnetBlockHeaderValidator.createEip1559OmmerValidator(eip1559)); + MainnetBlockHeaderValidator.createEip1559OmmerValidator( + eip1559, powHasher(powAlgorithm))) + .powHasher(powHasher(powAlgorithm)); } private static TransactionReceipt frontierTransactionReceiptFactory( diff --git a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/EthHasher.java b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/PoWHasher.java similarity index 73% rename from ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/EthHasher.java rename to ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/PoWHasher.java index d2792549600..d62105e70d3 100644 --- a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/EthHasher.java +++ b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/PoWHasher.java @@ -14,7 +14,10 @@ */ package org.hyperledger.besu.ethereum.mainnet; -public interface EthHasher { +public interface PoWHasher { + + PoWHasher LIGHT = new Light(); + PoWHasher NOOP = new NoOp(); /** * Hash of a particular block and nonce. @@ -27,10 +30,13 @@ public interface EthHasher { */ void hash(byte[] buffer, long nonce, long number, EpochCalculator epochCalc, byte[] headerHash); - final class Light implements EthHasher { + /** Implementation of Ethash Hashimoto Light Implementation. */ + final class Light implements PoWHasher { private static final EthHashCacheFactory cacheFactory = new EthHashCacheFactory(); + private Light() {} + @Override public void hash( final byte[] buffer, @@ -45,4 +51,20 @@ public void hash( System.arraycopy(hash, 0, buffer, 0, hash.length); } } + + /** Implementation of an inoperative hasher. */ + final class NoOp implements PoWHasher { + + private NoOp() {} + + @Override + public void hash( + final byte[] buffer, + final long nonce, + final long number, + final EpochCalculator epochCalc, + final byte[] headerHash) { + throw new UnsupportedOperationException("Hashing is unsupported"); + } + } } diff --git a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/EthHashSolution.java b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/PoWSolution.java similarity index 90% rename from ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/EthHashSolution.java rename to ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/PoWSolution.java index f1dd18cfdbc..c4022c60f80 100644 --- a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/EthHashSolution.java +++ b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/PoWSolution.java @@ -19,12 +19,12 @@ import java.util.Arrays; import java.util.Objects; -public class EthHashSolution { +public class PoWSolution { private final long nonce; private final Hash mixHash; private final byte[] powHash; - public EthHashSolution(final long nonce, final Hash mixHash, final byte[] powHash) { + public PoWSolution(final long nonce, final Hash mixHash, final byte[] powHash) { this.nonce = nonce; this.mixHash = mixHash; this.powHash = powHash; @@ -46,7 +46,7 @@ public byte[] getPowHash() { public boolean equals(final Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; - EthHashSolution that = (EthHashSolution) o; + PoWSolution that = (PoWSolution) o; return nonce == that.nonce && Objects.equals(mixHash, that.mixHash) && Arrays.equals(powHash, that.powHash); diff --git a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/EthHashSolver.java b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/PoWSolver.java similarity index 71% rename from ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/EthHashSolver.java rename to ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/PoWSolver.java index 302b585396f..a1b102bcafe 100644 --- a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/EthHashSolver.java +++ b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/PoWSolver.java @@ -16,7 +16,7 @@ import static org.apache.logging.log4j.LogManager.getLogger; -import org.hyperledger.besu.ethereum.chain.EthHashObserver; +import org.hyperledger.besu.ethereum.chain.PoWObserver; import org.hyperledger.besu.ethereum.core.Hash; import org.hyperledger.besu.util.Subscribers; @@ -32,26 +32,25 @@ import org.apache.tuweni.bytes.Bytes32; import org.apache.tuweni.units.bigints.UInt256; -public class EthHashSolver { +public class PoWSolver { private static final Logger LOG = getLogger(); - public static class EthHashSolverJob { + public static class PoWSolverJob { - private final EthHashSolverInputs inputs; - private final CompletableFuture nonceFuture; + private final PoWSolverInputs inputs; + private final CompletableFuture nonceFuture; - EthHashSolverJob( - final EthHashSolverInputs inputs, final CompletableFuture nonceFuture) { + PoWSolverJob(final PoWSolverInputs inputs, final CompletableFuture nonceFuture) { this.inputs = inputs; this.nonceFuture = nonceFuture; } - public static EthHashSolverJob createFromInputs(final EthHashSolverInputs inputs) { - return new EthHashSolverJob(inputs, new CompletableFuture<>()); + public static PoWSolverJob createFromInputs(final PoWSolverInputs inputs) { + return new PoWSolverJob(inputs, new CompletableFuture<>()); } - EthHashSolverInputs getInputs() { + PoWSolverInputs getInputs() { return inputs; } @@ -59,7 +58,7 @@ public boolean isDone() { return nonceFuture.isDone(); } - void solvedWith(final EthHashSolution solution) { + void solvedWith(final PoWSolution solution) { nonceFuture.complete(solution); } @@ -71,7 +70,7 @@ public void failed(final Throwable ex) { nonceFuture.completeExceptionally(ex); } - EthHashSolution getSolution() throws InterruptedException, ExecutionException { + PoWSolution getSolution() throws InterruptedException, ExecutionException { return nonceFuture.get(); } } @@ -79,28 +78,28 @@ EthHashSolution getSolution() throws InterruptedException, ExecutionException { private final long NO_MINING_CONDUCTED = -1; private final Iterable nonceGenerator; - private final EthHasher ethHasher; + private final PoWHasher poWHasher; private volatile long hashesPerSecond = NO_MINING_CONDUCTED; private final Boolean stratumMiningEnabled; - private final Subscribers ethHashObservers; + private final Subscribers ethHashObservers; private final EpochCalculator epochCalculator; - private volatile Optional currentJob = Optional.empty(); + private volatile Optional currentJob = Optional.empty(); - public EthHashSolver( + public PoWSolver( final Iterable nonceGenerator, - final EthHasher ethHasher, + final PoWHasher poWHasher, final Boolean stratumMiningEnabled, - final Subscribers ethHashObservers, + final Subscribers ethHashObservers, final EpochCalculator epochCalculator) { this.nonceGenerator = nonceGenerator; - this.ethHasher = ethHasher; + this.poWHasher = poWHasher; this.stratumMiningEnabled = stratumMiningEnabled; this.ethHashObservers = ethHashObservers; ethHashObservers.forEach(observer -> observer.setSubmitWorkCallback(this::submitSolution)); this.epochCalculator = epochCalculator; } - public EthHashSolution solveFor(final EthHashSolverJob job) + public PoWSolution solveFor(final PoWSolverJob job) throws InterruptedException, ExecutionException { currentJob = Optional.of(job); if (stratumMiningEnabled) { @@ -113,7 +112,7 @@ public EthHashSolution solveFor(final EthHashSolverJob job) private void findValidNonce() { final Stopwatch operationTimer = Stopwatch.createStarted(); - final EthHashSolverJob job = currentJob.get(); + final PoWSolverJob job = currentJob.get(); long hashesExecuted = 0; final byte[] hashBuffer = new byte[64]; for (final Long n : nonceGenerator) { @@ -122,7 +121,7 @@ private void findValidNonce() { return; } - final Optional solution = testNonce(job.getInputs(), n, hashBuffer); + final Optional solution = testNonce(job.getInputs(), n, hashBuffer); solution.ifPresent(job::solvedWith); hashesExecuted++; @@ -132,24 +131,24 @@ private void findValidNonce() { job.failed(new IllegalStateException("No valid nonce found.")); } - private Optional testNonce( - final EthHashSolverInputs inputs, final long nonce, final byte[] hashBuffer) { - ethHasher.hash( + private Optional testNonce( + final PoWSolverInputs inputs, final long nonce, final byte[] hashBuffer) { + poWHasher.hash( hashBuffer, nonce, inputs.getBlockNumber(), epochCalculator, inputs.getPrePowHash()); final UInt256 x = UInt256.fromBytes(Bytes32.wrap(hashBuffer, 32)); if (x.compareTo(inputs.getTarget()) <= 0) { final Hash mixedHash = Hash.wrap(Bytes32.leftPad(Bytes.wrap(hashBuffer).slice(0, Bytes32.SIZE))); - return Optional.of(new EthHashSolution(nonce, mixedHash, inputs.getPrePowHash())); + return Optional.of(new PoWSolution(nonce, mixedHash, inputs.getPrePowHash())); } return Optional.empty(); } public void cancel() { - currentJob.ifPresent(EthHashSolverJob::cancel); + currentJob.ifPresent(PoWSolverJob::cancel); } - public Optional getWorkDefinition() { + public Optional getWorkDefinition() { return currentJob.flatMap(job -> Optional.of(job.getInputs())); } @@ -160,21 +159,21 @@ public Optional hashesPerSecond() { return Optional.of(hashesPerSecond); } - public boolean submitSolution(final EthHashSolution solution) { - final Optional jobSnapshot = currentJob; + public boolean submitSolution(final PoWSolution solution) { + final Optional jobSnapshot = currentJob; if (jobSnapshot.isEmpty()) { LOG.debug("No current job, rejecting miner work"); return false; } - final EthHashSolverJob job = jobSnapshot.get(); - final EthHashSolverInputs inputs = job.getInputs(); + final PoWSolverJob job = jobSnapshot.get(); + final PoWSolverInputs inputs = job.getInputs(); if (!Arrays.equals(inputs.getPrePowHash(), solution.getPowHash())) { LOG.debug("Miner's solution does not match current job"); return false; } final byte[] hashBuffer = new byte[64]; - final Optional calculatedSolution = + final Optional calculatedSolution = testNonce(inputs, solution.getNonce(), hashBuffer); if (calculatedSolution.isPresent()) { diff --git a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/EthHashSolverInputs.java b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/PoWSolverInputs.java similarity index 88% rename from ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/EthHashSolverInputs.java rename to ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/PoWSolverInputs.java index 51611a6b3c2..49845fe0ffe 100644 --- a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/EthHashSolverInputs.java +++ b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/PoWSolverInputs.java @@ -18,13 +18,12 @@ import org.apache.tuweni.units.bigints.UInt256; -public class EthHashSolverInputs { +public class PoWSolverInputs { private final UInt256 target; private final byte[] prePowHash; private final long blockNumber; - public EthHashSolverInputs( - final UInt256 target, final byte[] prePowHash, final long blockNumber) { + public PoWSolverInputs(final UInt256 target, final byte[] prePowHash, final long blockNumber) { this.target = target; this.prePowHash = prePowHash; this.blockNumber = blockNumber; @@ -44,7 +43,7 @@ public long getBlockNumber() { @Override public String toString() { - return "EthHashSolverInputs{" + return "MiningSolverInputs{" + "target=" + target + ", prePowHash=" diff --git a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/ProtocolScheduleBuilder.java b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/ProtocolScheduleBuilder.java index fe62a0a4286..9ae009aa519 100644 --- a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/ProtocolScheduleBuilder.java +++ b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/ProtocolScheduleBuilder.java @@ -15,6 +15,7 @@ package org.hyperledger.besu.ethereum.mainnet; import org.hyperledger.besu.config.GenesisConfigOptions; +import org.hyperledger.besu.config.PowAlgorithm; import org.hyperledger.besu.config.experimental.ExperimentalEIPs; import org.hyperledger.besu.ethereum.chain.BadBlockManager; import org.hyperledger.besu.ethereum.core.PrivacyParameters; @@ -39,6 +40,7 @@ public class ProtocolScheduleBuilder { private final boolean isRevertReasonEnabled; private final BadBlockManager badBlockManager = new BadBlockManager(); private final boolean quorumCompatibilityMode; + private final PowAlgorithm powAlgorithm; public ProtocolScheduleBuilder( final GenesisConfigOptions config, @@ -46,14 +48,16 @@ public ProtocolScheduleBuilder( final Function protocolSpecAdapter, final PrivacyParameters privacyParameters, final boolean isRevertReasonEnabled, - final boolean quorumCompatibilityMode) { + final boolean quorumCompatibilityMode, + final PowAlgorithm powAlgorithm) { this( config, Optional.of(defaultChainId), protocolSpecAdapter, privacyParameters, isRevertReasonEnabled, - quorumCompatibilityMode); + quorumCompatibilityMode, + powAlgorithm); } public ProtocolScheduleBuilder( @@ -61,14 +65,16 @@ public ProtocolScheduleBuilder( final Function protocolSpecAdapter, final PrivacyParameters privacyParameters, final boolean isRevertReasonEnabled, - final boolean quorumCompatibilityMode) { + final boolean quorumCompatibilityMode, + final PowAlgorithm powAlgorithm) { this( config, Optional.empty(), protocolSpecAdapter, privacyParameters, isRevertReasonEnabled, - quorumCompatibilityMode); + quorumCompatibilityMode, + powAlgorithm); } private ProtocolScheduleBuilder( @@ -77,13 +83,15 @@ private ProtocolScheduleBuilder( final Function protocolSpecAdapter, final PrivacyParameters privacyParameters, final boolean isRevertReasonEnabled, - final boolean quorumCompatibilityMode) { + final boolean quorumCompatibilityMode, + final PowAlgorithm powAlgorithm) { this.config = config; this.defaultChainId = defaultChainId; this.protocolSpecAdapter = protocolSpecAdapter; this.privacyParameters = privacyParameters; this.isRevertReasonEnabled = isRevertReasonEnabled; this.quorumCompatibilityMode = quorumCompatibilityMode; + this.powAlgorithm = powAlgorithm; } public ProtocolSchedule createProtocolSchedule() { @@ -97,12 +105,18 @@ public ProtocolSchedule createProtocolSchedule() { protocolSchedule, OptionalLong.of(0), MainnetProtocolSpecs.frontierDefinition( - config.getContractSizeLimit(), config.getEvmStackSize(), quorumCompatibilityMode)); + config.getContractSizeLimit(), + config.getEvmStackSize(), + quorumCompatibilityMode, + powAlgorithm)); addProtocolSpec( protocolSchedule, config.getHomesteadBlockNumber(), MainnetProtocolSpecs.homesteadDefinition( - config.getContractSizeLimit(), config.getEvmStackSize(), quorumCompatibilityMode)); + config.getContractSizeLimit(), + config.getEvmStackSize(), + quorumCompatibilityMode, + powAlgorithm)); config .getDaoForkBlock() @@ -116,14 +130,16 @@ public ProtocolSchedule createProtocolSchedule() { MainnetProtocolSpecs.daoRecoveryInitDefinition( config.getContractSizeLimit(), config.getEvmStackSize(), - quorumCompatibilityMode)); + quorumCompatibilityMode, + powAlgorithm)); addProtocolSpec( protocolSchedule, OptionalLong.of(daoBlockNumber + 1), MainnetProtocolSpecs.daoRecoveryTransitionDefinition( config.getContractSizeLimit(), config.getEvmStackSize(), - quorumCompatibilityMode)); + quorumCompatibilityMode, + powAlgorithm)); // Return to the previous protocol spec after the dao fork has completed. protocolSchedule.putMilestone(daoBlockNumber + 10, originalProtocolSpec); @@ -133,7 +149,10 @@ public ProtocolSchedule createProtocolSchedule() { protocolSchedule, config.getTangerineWhistleBlockNumber(), MainnetProtocolSpecs.tangerineWhistleDefinition( - config.getContractSizeLimit(), config.getEvmStackSize(), quorumCompatibilityMode)); + config.getContractSizeLimit(), + config.getEvmStackSize(), + quorumCompatibilityMode, + powAlgorithm)); addProtocolSpec( protocolSchedule, config.getSpuriousDragonBlockNumber(), @@ -141,7 +160,8 @@ public ProtocolSchedule createProtocolSchedule() { chainId, config.getContractSizeLimit(), config.getEvmStackSize(), - quorumCompatibilityMode)); + quorumCompatibilityMode, + powAlgorithm)); addProtocolSpec( protocolSchedule, config.getByzantiumBlockNumber(), @@ -150,7 +170,8 @@ public ProtocolSchedule createProtocolSchedule() { config.getContractSizeLimit(), config.getEvmStackSize(), isRevertReasonEnabled, - quorumCompatibilityMode)); + quorumCompatibilityMode, + powAlgorithm)); addProtocolSpec( protocolSchedule, config.getConstantinopleBlockNumber(), @@ -159,7 +180,8 @@ public ProtocolSchedule createProtocolSchedule() { config.getContractSizeLimit(), config.getEvmStackSize(), isRevertReasonEnabled, - quorumCompatibilityMode)); + quorumCompatibilityMode, + powAlgorithm)); addProtocolSpec( protocolSchedule, config.getPetersburgBlockNumber(), @@ -168,7 +190,8 @@ public ProtocolSchedule createProtocolSchedule() { config.getContractSizeLimit(), config.getEvmStackSize(), isRevertReasonEnabled, - quorumCompatibilityMode)); + quorumCompatibilityMode, + powAlgorithm)); addProtocolSpec( protocolSchedule, config.getIstanbulBlockNumber(), @@ -177,7 +200,8 @@ public ProtocolSchedule createProtocolSchedule() { config.getContractSizeLimit(), config.getEvmStackSize(), isRevertReasonEnabled, - quorumCompatibilityMode)); + quorumCompatibilityMode, + powAlgorithm)); addProtocolSpec( protocolSchedule, config.getMuirGlacierBlockNumber(), @@ -186,7 +210,8 @@ public ProtocolSchedule createProtocolSchedule() { config.getContractSizeLimit(), config.getEvmStackSize(), isRevertReasonEnabled, - quorumCompatibilityMode)); + quorumCompatibilityMode, + powAlgorithm)); if (ExperimentalEIPs.berlinEnabled) { addProtocolSpec( @@ -197,7 +222,8 @@ public ProtocolSchedule createProtocolSchedule() { config.getContractSizeLimit(), config.getEvmStackSize(), isRevertReasonEnabled, - quorumCompatibilityMode)); + quorumCompatibilityMode, + powAlgorithm)); } if (ExperimentalEIPs.eip1559Enabled) { @@ -213,7 +239,8 @@ public ProtocolSchedule createProtocolSchedule() { config.getEvmStackSize(), isRevertReasonEnabled, config, - quorumCompatibilityMode)); + quorumCompatibilityMode, + powAlgorithm)); } // specs for classic network @@ -229,7 +256,8 @@ public ProtocolSchedule createProtocolSchedule() { ClassicProtocolSpecs.classicRecoveryInitDefinition( config.getContractSizeLimit(), config.getEvmStackSize(), - quorumCompatibilityMode)); + quorumCompatibilityMode, + powAlgorithm)); protocolSchedule.putMilestone(classicBlockNumber + 1, originalProtocolSpec); }); @@ -240,7 +268,8 @@ public ProtocolSchedule createProtocolSchedule() { chainId, config.getContractSizeLimit(), config.getEvmStackSize(), - quorumCompatibilityMode)); + quorumCompatibilityMode, + powAlgorithm)); addProtocolSpec( protocolSchedule, config.getDieHardBlockNumber(), @@ -248,7 +277,8 @@ public ProtocolSchedule createProtocolSchedule() { chainId, config.getContractSizeLimit(), config.getEvmStackSize(), - quorumCompatibilityMode)); + quorumCompatibilityMode, + powAlgorithm)); addProtocolSpec( protocolSchedule, config.getGothamBlockNumber(), @@ -257,7 +287,8 @@ public ProtocolSchedule createProtocolSchedule() { config.getContractSizeLimit(), config.getEvmStackSize(), config.getEcip1017EraRounds(), - quorumCompatibilityMode)); + quorumCompatibilityMode, + powAlgorithm)); addProtocolSpec( protocolSchedule, config.getDefuseDifficultyBombBlockNumber(), @@ -266,7 +297,8 @@ public ProtocolSchedule createProtocolSchedule() { config.getContractSizeLimit(), config.getEvmStackSize(), config.getEcip1017EraRounds(), - quorumCompatibilityMode)); + quorumCompatibilityMode, + powAlgorithm)); addProtocolSpec( protocolSchedule, config.getAtlantisBlockNumber(), @@ -276,7 +308,8 @@ public ProtocolSchedule createProtocolSchedule() { config.getEvmStackSize(), isRevertReasonEnabled, config.getEcip1017EraRounds(), - quorumCompatibilityMode)); + quorumCompatibilityMode, + powAlgorithm)); addProtocolSpec( protocolSchedule, config.getAghartaBlockNumber(), @@ -286,7 +319,8 @@ public ProtocolSchedule createProtocolSchedule() { config.getEvmStackSize(), isRevertReasonEnabled, config.getEcip1017EraRounds(), - quorumCompatibilityMode)); + quorumCompatibilityMode, + powAlgorithm)); addProtocolSpec( protocolSchedule, config.getPhoenixBlockNumber(), @@ -296,7 +330,8 @@ public ProtocolSchedule createProtocolSchedule() { config.getEvmStackSize(), isRevertReasonEnabled, config.getEcip1017EraRounds(), - quorumCompatibilityMode)); + quorumCompatibilityMode, + powAlgorithm)); addProtocolSpec( protocolSchedule, config.getThanosBlockNumber(), @@ -306,7 +341,8 @@ public ProtocolSchedule createProtocolSchedule() { config.getEvmStackSize(), isRevertReasonEnabled, config.getEcip1017EraRounds(), - quorumCompatibilityMode)); + quorumCompatibilityMode, + powAlgorithm)); LOG.info("Protocol schedule created with milestones: {}", protocolSchedule.listMilestones()); return protocolSchedule; diff --git a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/ProtocolSpec.java b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/ProtocolSpec.java index 37cfb363141..67b54e28748 100644 --- a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/ProtocolSpec.java +++ b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/ProtocolSpec.java @@ -77,6 +77,8 @@ public class ProtocolSpec { private final BadBlockManager badBlockManager; + private final PoWHasher powHasher; + /** * Creates a new protocol specification instance. * @@ -103,6 +105,7 @@ public class ProtocolSpec { * @param eip1559 an {@link Optional} wrapping {@link EIP1559} manager class if appropriate. * @param gasBudgetCalculator the gas budget calculator to use. * @param badBlockManager the cache to use to keep invalid blocks + * @param powHasher the proof-of-work hasher */ public ProtocolSpec( final String name, @@ -127,7 +130,8 @@ public ProtocolSpec( final TransactionPriceCalculator transactionPriceCalculator, final Optional eip1559, final TransactionGasBudgetCalculator gasBudgetCalculator, - final BadBlockManager badBlockManager) { + final BadBlockManager badBlockManager, + final PoWHasher powHasher) { this.name = name; this.evm = evm; this.transactionValidator = transactionValidator; @@ -151,6 +155,7 @@ public ProtocolSpec( this.eip1559 = eip1559; this.gasBudgetCalculator = gasBudgetCalculator; this.badBlockManager = badBlockManager; + this.powHasher = powHasher; } /** @@ -350,4 +355,13 @@ public TransactionGasBudgetCalculator getGasBudgetCalculator() { public BadBlockManager getBadBlocksManager() { return badBlockManager; } + + /** + * Returns the Proof-of-Work hasher + * + * @return the Proof-of-Work hasher + */ + public PoWHasher getPoWHasher() { + return powHasher; + } } diff --git a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/ProtocolSpecBuilder.java b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/ProtocolSpecBuilder.java index 165880b8ff0..de43689982e 100644 --- a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/ProtocolSpecBuilder.java +++ b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/ProtocolSpecBuilder.java @@ -72,6 +72,7 @@ public class ProtocolSpecBuilder { private TransactionGasBudgetCalculator gasBudgetCalculator = TransactionGasBudgetCalculator.frontier(); private BadBlockManager badBlockManager; + private PoWHasher powHasher; public ProtocolSpecBuilder gasCalculator(final Supplier gasCalculatorBuilder) { this.gasCalculatorBuilder = gasCalculatorBuilder; @@ -238,6 +239,11 @@ public ProtocolSpecBuilder badBlocksManager(final BadBlockManager badBlockManage return this; } + public ProtocolSpecBuilder powHasher(final PoWHasher powHasher) { + this.powHasher = powHasher; + return this; + } + public ProtocolSpec build(final ProtocolSchedule protocolSchedule) { checkNotNull(gasCalculatorBuilder, "Missing gasCalculator"); checkNotNull(evmBuilder, "Missing operation registry"); @@ -264,6 +270,7 @@ public ProtocolSpec build(final ProtocolSchedule protocolSchedule) { checkNotNull(transactionPriceCalculator, "Missing transaction price calculator"); checkNotNull(eip1559, "Missing eip1559 optional wrapper"); checkNotNull(badBlockManager, "Missing bad blocks manager"); + checkNotNull(powHasher, "Missing PoW hasher"); final GasCalculator gasCalculator = gasCalculatorBuilder.get(); final EVM evm = evmBuilder.apply(gasCalculator); @@ -364,7 +371,8 @@ public ProtocolSpec build(final ProtocolSchedule protocolSchedule) { transactionPriceCalculator, eip1559, gasBudgetCalculator, - badBlockManager); + badBlockManager, + powHasher); } public interface TransactionProcessorBuilder { diff --git a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/headervalidationrules/ProofOfWorkValidationRule.java b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/headervalidationrules/ProofOfWorkValidationRule.java index f9f2be91ebc..cc5bc70ef1e 100644 --- a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/headervalidationrules/ProofOfWorkValidationRule.java +++ b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/headervalidationrules/ProofOfWorkValidationRule.java @@ -19,7 +19,7 @@ import org.hyperledger.besu.ethereum.core.Hash; import org.hyperledger.besu.ethereum.mainnet.DetachedBlockHeaderValidationRule; import org.hyperledger.besu.ethereum.mainnet.EpochCalculator; -import org.hyperledger.besu.ethereum.mainnet.EthHasher; +import org.hyperledger.besu.ethereum.mainnet.PoWHasher; import org.hyperledger.besu.ethereum.rlp.BytesValueRLPOutput; import java.math.BigInteger; @@ -36,19 +36,16 @@ public final class ProofOfWorkValidationRule implements DetachedBlockHeaderValid private static final BigInteger ETHASH_TARGET_UPPER_BOUND = BigInteger.valueOf(2).pow(256); - static final EthHasher HASHER = new EthHasher.Light(); + private final PoWHasher hasher; private final EpochCalculator epochCalculator; private final boolean includeBaseFee; - public ProofOfWorkValidationRule(final EpochCalculator epochCalculator) { - this(epochCalculator, false); - } - public ProofOfWorkValidationRule( - final EpochCalculator epochCalculator, final boolean includeBaseFee) { + final EpochCalculator epochCalculator, final boolean includeBaseFee, final PoWHasher hasher) { this.epochCalculator = epochCalculator; this.includeBaseFee = includeBaseFee; + this.hasher = hasher; } @Override @@ -65,7 +62,7 @@ public boolean validate(final BlockHeader header, final BlockHeader parent) { final byte[] hashBuffer = new byte[64]; final Hash headerHash = hashHeader(header); - HASHER.hash( + hasher.hash( hashBuffer, header.getNonce(), header.getNumber(), epochCalculator, headerHash.toArray()); if (header.getDifficulty().isZero()) { diff --git a/ethereum/core/src/test-support/java/org/hyperledger/besu/ethereum/core/ExecutionContextTestFixture.java b/ethereum/core/src/test-support/java/org/hyperledger/besu/ethereum/core/ExecutionContextTestFixture.java index cea7d932d55..78573d065b9 100644 --- a/ethereum/core/src/test-support/java/org/hyperledger/besu/ethereum/core/ExecutionContextTestFixture.java +++ b/ethereum/core/src/test-support/java/org/hyperledger/besu/ethereum/core/ExecutionContextTestFixture.java @@ -119,7 +119,8 @@ public ExecutionContextTestFixture build() { Function.identity(), new PrivacyParameters(), false, - genesisConfigFile.getConfigOptions().isQuorum()) + genesisConfigFile.getConfigOptions().isQuorum(), + genesisConfigFile.getConfigOptions().getPowAlgorithm()) .createProtocolSchedule(); } if (keyValueStorage == null) { diff --git a/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/mainnet/EthHashSolverTest.java b/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/mainnet/PoWSolverTest.java similarity index 82% rename from ethereum/core/src/test/java/org/hyperledger/besu/ethereum/mainnet/EthHashSolverTest.java rename to ethereum/core/src/test/java/org/hyperledger/besu/ethereum/mainnet/PoWSolverTest.java index 072da459ae3..c1db4660aa6 100644 --- a/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/mainnet/EthHashSolverTest.java +++ b/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/mainnet/PoWSolverTest.java @@ -34,15 +34,15 @@ import org.apache.tuweni.units.bigints.UInt256; import org.junit.Test; -public class EthHashSolverTest { +public class PoWSolverTest { @Test public void emptyHashRateAndWorkDefinitionIsReportedPriorToSolverStarting() { final List noncesToTry = Arrays.asList(1L, 1L, 1L, 1L, 1L, 1L, 0L); - final EthHashSolver solver = - new EthHashSolver( + final PoWSolver solver = + new PoWSolver( noncesToTry, - new EthHasher.Light(), + PoWHasher.LIGHT, false, Subscribers.none(), new EpochCalculator.DefaultEpochCalculator()); @@ -55,7 +55,7 @@ public void emptyHashRateAndWorkDefinitionIsReportedPriorToSolverStarting() { public void hashRateIsProducedSuccessfully() throws InterruptedException, ExecutionException { final List noncesToTry = Arrays.asList(1L, 1L, 1L, 1L, 1L, 1L, 0L); - final EthHasher hasher = mock(EthHasher.class); + final PoWHasher hasher = mock(PoWHasher.class); doAnswer( invocation -> { final Object[] args = invocation.getArguments(); @@ -67,8 +67,8 @@ public void hashRateIsProducedSuccessfully() throws InterruptedException, Execut .when(hasher) .hash(any(), anyLong(), anyLong(), any(), any()); - final EthHashSolver solver = - new EthHashSolver( + final PoWSolver solver = + new PoWSolver( noncesToTry, hasher, false, @@ -76,8 +76,8 @@ public void hashRateIsProducedSuccessfully() throws InterruptedException, Execut new EpochCalculator.DefaultEpochCalculator()); final Stopwatch operationTimer = Stopwatch.createStarted(); - final EthHashSolverInputs inputs = new EthHashSolverInputs(UInt256.ONE, new byte[0], 5); - solver.solveFor(EthHashSolver.EthHashSolverJob.createFromInputs(inputs)); + final PoWSolverInputs inputs = new PoWSolverInputs(UInt256.ONE, new byte[0], 5); + solver.solveFor(PoWSolver.PoWSolverJob.createFromInputs(inputs)); final double runtimeSeconds = operationTimer.elapsed(TimeUnit.NANOSECONDS) / 1e9; final long worstCaseHashesPerSecond = (long) (noncesToTry.size() / runtimeSeconds); @@ -93,8 +93,8 @@ public void hashRateIsProducedSuccessfully() throws InterruptedException, Execut public void ifInvokedTwiceProducesCorrectAnswerForSecondInvocation() throws InterruptedException, ExecutionException { - final EthHashSolverInputs firstInputs = - new EthHashSolverInputs( + final PoWSolverInputs firstInputs = + new PoWSolverInputs( UInt256.fromHexString( "0x0083126e978d4fdf3b645a1cac083126e978d4fdf3b645a1cac083126e978d4f"), new byte[] { @@ -103,15 +103,15 @@ public void ifInvokedTwiceProducesCorrectAnswerForSecondInvocation() }, 468); - final EthHashSolution expectedFirstOutput = - new EthHashSolution( + final PoWSolution expectedFirstOutput = + new PoWSolution( -6506032554016940193L, Hash.fromHexString( "0xc5e3c33c86d64d0641dd3c86e8ce4628fe0aac0ef7b4c087c5fcaa45d5046d90"), firstInputs.getPrePowHash()); - final EthHashSolverInputs secondInputs = - new EthHashSolverInputs( + final PoWSolverInputs secondInputs = + new PoWSolverInputs( UInt256.fromHexString( "0x0083126e978d4fdf3b645a1cac083126e978d4fdf3b645a1cac083126e978d4f"), new byte[] { @@ -120,27 +120,26 @@ public void ifInvokedTwiceProducesCorrectAnswerForSecondInvocation() }, 1); - final EthHashSolution expectedSecondOutput = - new EthHashSolution( + final PoWSolution expectedSecondOutput = + new PoWSolution( 8855952212886464488L, Hash.fromHexString( "0x2adb0f375dd2d528689cb9e00473c3c9692737109d547130feafbefb2c6c5244"), firstInputs.getPrePowHash()); // Nonces need to have a 0L inserted, as it is a "wasted" nonce in the solver. - final EthHashSolver solver = - new EthHashSolver( + final PoWSolver solver = + new PoWSolver( Lists.newArrayList(expectedFirstOutput.getNonce(), 0L, expectedSecondOutput.getNonce()), - new EthHasher.Light(), + PoWHasher.LIGHT, false, Subscribers.none(), new EpochCalculator.DefaultEpochCalculator()); - EthHashSolution soln = - solver.solveFor(EthHashSolver.EthHashSolverJob.createFromInputs(firstInputs)); + PoWSolution soln = solver.solveFor(PoWSolver.PoWSolverJob.createFromInputs(firstInputs)); assertThat(soln.getMixHash()).isEqualTo(expectedFirstOutput.getMixHash()); - soln = solver.solveFor(EthHashSolver.EthHashSolverJob.createFromInputs(secondInputs)); + soln = solver.solveFor(PoWSolver.PoWSolverJob.createFromInputs(secondInputs)); assertThat(soln.getMixHash()).isEqualTo(expectedSecondOutput.getMixHash()); } } diff --git a/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/mainnet/headervalidationrules/ProofOfWorkValidationRuleTest.java b/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/mainnet/headervalidationrules/ProofOfWorkValidationRuleTest.java index 6f380122f15..df01e4c7c8a 100644 --- a/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/mainnet/headervalidationrules/ProofOfWorkValidationRuleTest.java +++ b/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/mainnet/headervalidationrules/ProofOfWorkValidationRuleTest.java @@ -23,6 +23,7 @@ import org.hyperledger.besu.ethereum.core.Hash; import org.hyperledger.besu.ethereum.core.ProtocolScheduleFixture; import org.hyperledger.besu.ethereum.mainnet.EpochCalculator; +import org.hyperledger.besu.ethereum.mainnet.PoWHasher; import org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule; import org.hyperledger.besu.ethereum.mainnet.ScheduleBasedBlockHeaderFunctions; import org.hyperledger.besu.ethereum.mainnet.ValidationTestUtils; @@ -51,7 +52,9 @@ public ProofOfWorkValidationRuleTest(final long parentBlockNum, final long block throws IOException { blockHeader = ValidationTestUtils.readHeader(parentBlockNum); parentHeader = ValidationTestUtils.readHeader(blockNum); - validationRule = new ProofOfWorkValidationRule(new EpochCalculator.DefaultEpochCalculator()); + validationRule = + new ProofOfWorkValidationRule( + new EpochCalculator.DefaultEpochCalculator(), false, PoWHasher.LIGHT); } @Parameters(name = "block {1}") @@ -92,7 +95,7 @@ public void passesBlockWithOneValuedDifficulty() { final byte[] hashBuffer = new byte[64]; final Hash headerHash = validationRule.hashHeader(preHeader); - ProofOfWorkValidationRule.HASHER.hash( + PoWHasher.LIGHT.hash( hashBuffer, preHeader.getNonce(), preHeader.getNumber(), diff --git a/ethereum/referencetests/src/main/java/org/hyperledger/besu/ethereum/referencetests/ReferenceTestProtocolSchedules.java b/ethereum/referencetests/src/main/java/org/hyperledger/besu/ethereum/referencetests/ReferenceTestProtocolSchedules.java index ff0f758c6eb..7c6e3a64e6a 100644 --- a/ethereum/referencetests/src/main/java/org/hyperledger/besu/ethereum/referencetests/ReferenceTestProtocolSchedules.java +++ b/ethereum/referencetests/src/main/java/org/hyperledger/besu/ethereum/referencetests/ReferenceTestProtocolSchedules.java @@ -86,7 +86,8 @@ private static ProtocolSchedule createSchedule(final GenesisConfigOptions option Function.identity(), PrivacyParameters.DEFAULT, false, - options.isQuorum()) + options.isQuorum(), + options.getPowAlgorithm()) .createProtocolSchedule(); } diff --git a/ethereum/retesteth/src/main/java/org/hyperledger/besu/ethereum/retesteth/NoRewardProtocolScheduleWrapper.java b/ethereum/retesteth/src/main/java/org/hyperledger/besu/ethereum/retesteth/NoRewardProtocolScheduleWrapper.java index 5c059fdce93..742c34f457c 100644 --- a/ethereum/retesteth/src/main/java/org/hyperledger/besu/ethereum/retesteth/NoRewardProtocolScheduleWrapper.java +++ b/ethereum/retesteth/src/main/java/org/hyperledger/besu/ethereum/retesteth/NoRewardProtocolScheduleWrapper.java @@ -81,7 +81,8 @@ public ProtocolSpec getByBlockNumber(final long number) { original.getTransactionPriceCalculator(), original.getEip1559(), original.getGasBudgetCalculator(), - original.getBadBlocksManager()); + original.getBadBlocksManager(), + null); } @Override diff --git a/ethereum/retesteth/src/main/java/org/hyperledger/besu/ethereum/retesteth/RetestethContext.java b/ethereum/retesteth/src/main/java/org/hyperledger/besu/ethereum/retesteth/RetestethContext.java index de83908ccf7..5a538a6fb53 100644 --- a/ethereum/retesteth/src/main/java/org/hyperledger/besu/ethereum/retesteth/RetestethContext.java +++ b/ethereum/retesteth/src/main/java/org/hyperledger/besu/ethereum/retesteth/RetestethContext.java @@ -43,11 +43,11 @@ import org.hyperledger.besu.ethereum.eth.transactions.TransactionPoolConfiguration; import org.hyperledger.besu.ethereum.eth.transactions.TransactionPoolFactory; import org.hyperledger.besu.ethereum.mainnet.EpochCalculator; -import org.hyperledger.besu.ethereum.mainnet.EthHashSolver; -import org.hyperledger.besu.ethereum.mainnet.EthHasher; import org.hyperledger.besu.ethereum.mainnet.HeaderValidationMode; import org.hyperledger.besu.ethereum.mainnet.MainnetBlockHeaderFunctions; import org.hyperledger.besu.ethereum.mainnet.MainnetProtocolSchedule; +import org.hyperledger.besu.ethereum.mainnet.PoWHasher; +import org.hyperledger.besu.ethereum.mainnet.PoWSolver; import org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule; import org.hyperledger.besu.ethereum.mainnet.ProtocolSpec; import org.hyperledger.besu.ethereum.mainnet.ScheduleBasedBlockHeaderFunctions; @@ -72,7 +72,7 @@ public class RetestethContext { private static final Logger LOG = LogManager.getLogger(); - private static final EthHasher NO_WORK_HASHER = + private static final PoWHasher NO_WORK_HASHER = (final byte[] buffer, final long nonce, final long number, @@ -93,7 +93,7 @@ public class RetestethContext { private TransactionPool transactionPool; private EthScheduler ethScheduler; - private EthHashSolver ethHashSolver; + private PoWSolver poWSolver; public boolean resetContext( final String genesisConfigString, final String sealEngine, final Optional clockTime) { @@ -161,17 +161,17 @@ private boolean buildContext( : HeaderValidationMode.FULL; final Iterable nonceGenerator = new IncrementingNonceGenerator(0); - ethHashSolver = + poWSolver = ("NoProof".equals(sealengine) || "NoReward".equals(sealEngine)) - ? new EthHashSolver( + ? new PoWSolver( nonceGenerator, NO_WORK_HASHER, false, Subscribers.none(), new EpochCalculator.DefaultEpochCalculator()) - : new EthHashSolver( + : new PoWSolver( nonceGenerator, - new EthHasher.Light(), + PoWHasher.LIGHT, false, Subscribers.none(), new EpochCalculator.DefaultEpochCalculator()); @@ -288,7 +288,7 @@ public RetestethClock getRetestethClock() { return retestethClock; } - public EthHashSolver getEthHashSolver() { - return ethHashSolver; + public PoWSolver getEthHashSolver() { + return poWSolver; } } diff --git a/ethereum/retesteth/src/main/java/org/hyperledger/besu/ethereum/retesteth/methods/TestMineBlocks.java b/ethereum/retesteth/src/main/java/org/hyperledger/besu/ethereum/retesteth/methods/TestMineBlocks.java index b66f6ceb7c1..b955d7854c8 100644 --- a/ethereum/retesteth/src/main/java/org/hyperledger/besu/ethereum/retesteth/methods/TestMineBlocks.java +++ b/ethereum/retesteth/src/main/java/org/hyperledger/besu/ethereum/retesteth/methods/TestMineBlocks.java @@ -19,8 +19,8 @@ import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.JsonRpcMethod; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcResponse; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcSuccessResponse; -import org.hyperledger.besu.ethereum.blockcreation.EthHashBlockCreator; import org.hyperledger.besu.ethereum.blockcreation.GasLimitCalculator; +import org.hyperledger.besu.ethereum.blockcreation.PoWBlockCreator; import org.hyperledger.besu.ethereum.chain.MutableBlockchain; import org.hyperledger.besu.ethereum.core.Block; import org.hyperledger.besu.ethereum.core.BlockImporter; @@ -60,8 +60,8 @@ private boolean mineNewBlock() { final ProtocolContext protocolContext = context.getProtocolContext(); final MutableBlockchain blockchain = context.getBlockchain(); final HeaderValidationMode headerValidationMode = context.getHeaderValidationMode(); - final EthHashBlockCreator blockCreator = - new EthHashBlockCreator( + final PoWBlockCreator blockCreator = + new PoWBlockCreator( context.getCoinbase(), header -> context.getExtraData(), context.getTransactionPool().getPendingTransactions(), diff --git a/ethereum/stratum/src/main/java/org/hyperledger/besu/ethereum/stratum/Stratum1EthProxyProtocol.java b/ethereum/stratum/src/main/java/org/hyperledger/besu/ethereum/stratum/Stratum1EthProxyProtocol.java index 6c93572e23f..91202365452 100644 --- a/ethereum/stratum/src/main/java/org/hyperledger/besu/ethereum/stratum/Stratum1EthProxyProtocol.java +++ b/ethereum/stratum/src/main/java/org/hyperledger/besu/ethereum/stratum/Stratum1EthProxyProtocol.java @@ -20,13 +20,13 @@ import org.hyperledger.besu.ethereum.api.jsonrpc.internal.JsonRpcRequest; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.JsonRpcRequestContext; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcSuccessResponse; -import org.hyperledger.besu.ethereum.blockcreation.EthHashMiningCoordinator; import org.hyperledger.besu.ethereum.blockcreation.MiningCoordinator; +import org.hyperledger.besu.ethereum.blockcreation.PoWMiningCoordinator; import org.hyperledger.besu.ethereum.core.Hash; import org.hyperledger.besu.ethereum.mainnet.DirectAcyclicGraphSeed; import org.hyperledger.besu.ethereum.mainnet.EpochCalculator; -import org.hyperledger.besu.ethereum.mainnet.EthHashSolution; -import org.hyperledger.besu.ethereum.mainnet.EthHashSolverInputs; +import org.hyperledger.besu.ethereum.mainnet.PoWSolution; +import org.hyperledger.besu.ethereum.mainnet.PoWSolverInputs; import java.io.IOException; import java.util.Arrays; @@ -49,18 +49,18 @@ public class Stratum1EthProxyProtocol implements StratumProtocol { private static final JsonMapper mapper = new JsonMapper(); private final MiningCoordinator miningCoordinator; - private EthHashSolverInputs currentInput; - private Function submitCallback; + private PoWSolverInputs currentInput; + private Function submitCallback; private final EpochCalculator epochCalculator; public Stratum1EthProxyProtocol(final MiningCoordinator miningCoordinator) { - if (!(miningCoordinator instanceof EthHashMiningCoordinator)) { + if (!(miningCoordinator instanceof PoWMiningCoordinator)) { throw new IllegalArgumentException( "Stratum1 Proxies require an EthHashMiningCoordinator not " + ((miningCoordinator == null) ? "null" : miningCoordinator.getClass().getName())); } this.miningCoordinator = miningCoordinator; - this.epochCalculator = ((EthHashMiningCoordinator) miningCoordinator).getEpochCalculator(); + this.epochCalculator = ((PoWMiningCoordinator) miningCoordinator).getEpochCalculator(); } @Override @@ -128,8 +128,8 @@ private void handleMiningSubmit(final StratumConnection conn, final JsonRpcReque throws IOException { LOG.debug("Miner submitted solution {}", req); boolean result = false; - final EthHashSolution solution = - new EthHashSolution( + final PoWSolution solution = + new PoWSolution( Bytes.fromHexString(req.getRequiredParameter(0, String.class)).getLong(0), req.getRequiredParameter(2, Hash.class), Bytes.fromHexString(req.getRequiredParameter(1, String.class)).toArrayUnsafe()); @@ -142,12 +142,12 @@ private void handleMiningSubmit(final StratumConnection conn, final JsonRpcReque } @Override - public void setCurrentWorkTask(final EthHashSolverInputs input) { + public void setCurrentWorkTask(final PoWSolverInputs input) { this.currentInput = input; } @Override - public void setSubmitCallback(final Function submitSolutionCallback) { + public void setSubmitCallback(final Function submitSolutionCallback) { this.submitCallback = submitSolutionCallback; } } diff --git a/ethereum/stratum/src/main/java/org/hyperledger/besu/ethereum/stratum/Stratum1Protocol.java b/ethereum/stratum/src/main/java/org/hyperledger/besu/ethereum/stratum/Stratum1Protocol.java index 5189ca18870..d0fde592a5d 100644 --- a/ethereum/stratum/src/main/java/org/hyperledger/besu/ethereum/stratum/Stratum1Protocol.java +++ b/ethereum/stratum/src/main/java/org/hyperledger/besu/ethereum/stratum/Stratum1Protocol.java @@ -19,13 +19,13 @@ import org.hyperledger.besu.ethereum.api.jsonrpc.RpcMethod; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.JsonRpcRequest; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcSuccessResponse; -import org.hyperledger.besu.ethereum.blockcreation.EthHashMiningCoordinator; import org.hyperledger.besu.ethereum.blockcreation.MiningCoordinator; +import org.hyperledger.besu.ethereum.blockcreation.PoWMiningCoordinator; import org.hyperledger.besu.ethereum.core.Hash; import org.hyperledger.besu.ethereum.mainnet.DirectAcyclicGraphSeed; import org.hyperledger.besu.ethereum.mainnet.EpochCalculator; -import org.hyperledger.besu.ethereum.mainnet.EthHashSolution; -import org.hyperledger.besu.ethereum.mainnet.EthHashSolverInputs; +import org.hyperledger.besu.ethereum.mainnet.PoWSolution; +import org.hyperledger.besu.ethereum.mainnet.PoWSolverInputs; import java.io.IOException; import java.time.Instant; @@ -60,8 +60,8 @@ private static String createSubscriptionID() { private final MiningCoordinator miningCoordinator; private final String extranonce; - private EthHashSolverInputs currentInput; - private Function submitCallback; + private PoWSolverInputs currentInput; + private Function submitCallback; private final Supplier jobIdSupplier; private final Supplier subscriptionIdCreator; private final List activeConnections = new ArrayList<>(); @@ -83,7 +83,7 @@ public Stratum1Protocol(final String extranonce, final MiningCoordinator miningC final MiningCoordinator miningCoordinator, final Supplier jobIdSupplier, final Supplier subscriptionIdCreator) { - if (!(miningCoordinator instanceof EthHashMiningCoordinator)) { + if (!(miningCoordinator instanceof PoWMiningCoordinator)) { throw new IllegalArgumentException( "Stratum1 requires an EthHashMiningCoordinator not " + ((miningCoordinator == null) ? "null" : miningCoordinator.getClass().getName())); @@ -92,7 +92,7 @@ public Stratum1Protocol(final String extranonce, final MiningCoordinator miningC this.miningCoordinator = miningCoordinator; this.jobIdSupplier = jobIdSupplier; this.subscriptionIdCreator = subscriptionIdCreator; - this.epochCalculator = ((EthHashMiningCoordinator) miningCoordinator).getEpochCalculator(); + this.epochCalculator = ((PoWMiningCoordinator) miningCoordinator).getEpochCalculator(); } @Override @@ -180,8 +180,8 @@ private void handleMiningSubmit(final StratumConnection conn, final JsonRpcReque throws IOException { LOG.debug("Miner submitted solution {}", message); boolean result = false; - final EthHashSolution solution = - new EthHashSolution( + final PoWSolution solution = + new PoWSolution( Bytes.fromHexString(message.getRequiredParameter(2, String.class)).getLong(0), Hash.fromHexString(message.getRequiredParameter(4, String.class)), Bytes.fromHexString(message.getRequiredParameter(3, String.class)).toArrayUnsafe()); @@ -205,7 +205,7 @@ private void handleMiningAuthorize(final StratumConnection conn, final JsonRpcRe } @Override - public void setCurrentWorkTask(final EthHashSolverInputs input) { + public void setCurrentWorkTask(final PoWSolverInputs input) { this.currentInput = input; LOG.debug("Sending new work to miners: {}", input); for (StratumConnection conn : activeConnections) { @@ -214,7 +214,7 @@ public void setCurrentWorkTask(final EthHashSolverInputs input) { } @Override - public void setSubmitCallback(final Function submitSolutionCallback) { + public void setSubmitCallback(final Function submitSolutionCallback) { this.submitCallback = submitSolutionCallback; } } diff --git a/ethereum/stratum/src/main/java/org/hyperledger/besu/ethereum/stratum/StratumProtocol.java b/ethereum/stratum/src/main/java/org/hyperledger/besu/ethereum/stratum/StratumProtocol.java index d5482ad5a7e..7cd40f7ad7d 100644 --- a/ethereum/stratum/src/main/java/org/hyperledger/besu/ethereum/stratum/StratumProtocol.java +++ b/ethereum/stratum/src/main/java/org/hyperledger/besu/ethereum/stratum/StratumProtocol.java @@ -17,8 +17,8 @@ import org.hyperledger.besu.ethereum.api.jsonrpc.internal.JsonRpcRequest; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcSuccessResponse; import org.hyperledger.besu.ethereum.blockcreation.MiningCoordinator; -import org.hyperledger.besu.ethereum.mainnet.EthHashSolution; -import org.hyperledger.besu.ethereum.mainnet.EthHashSolverInputs; +import org.hyperledger.besu.ethereum.mainnet.PoWSolution; +import org.hyperledger.besu.ethereum.mainnet.PoWSolverInputs; import java.io.IOException; import java.util.function.Function; @@ -63,9 +63,9 @@ public interface StratumProtocol { * * @param input the new proof-of-work job to send to miners */ - void setCurrentWorkTask(EthHashSolverInputs input); + void setCurrentWorkTask(PoWSolverInputs input); - void setSubmitCallback(Function submitSolutionCallback); + void setSubmitCallback(Function submitSolutionCallback); default void handleHashrateSubmit( final JsonMapper mapper, diff --git a/ethereum/stratum/src/main/java/org/hyperledger/besu/ethereum/stratum/StratumServer.java b/ethereum/stratum/src/main/java/org/hyperledger/besu/ethereum/stratum/StratumServer.java index ff6f6a223fd..fdad1ab0796 100644 --- a/ethereum/stratum/src/main/java/org/hyperledger/besu/ethereum/stratum/StratumServer.java +++ b/ethereum/stratum/src/main/java/org/hyperledger/besu/ethereum/stratum/StratumServer.java @@ -17,9 +17,9 @@ import static org.apache.logging.log4j.LogManager.getLogger; import org.hyperledger.besu.ethereum.blockcreation.MiningCoordinator; -import org.hyperledger.besu.ethereum.chain.EthHashObserver; -import org.hyperledger.besu.ethereum.mainnet.EthHashSolution; -import org.hyperledger.besu.ethereum.mainnet.EthHashSolverInputs; +import org.hyperledger.besu.ethereum.chain.PoWObserver; +import org.hyperledger.besu.ethereum.mainnet.PoWSolution; +import org.hyperledger.besu.ethereum.mainnet.PoWSolverInputs; import java.util.concurrent.CompletableFuture; import java.util.concurrent.atomic.AtomicBoolean; @@ -36,7 +36,7 @@ * TCP server allowing miners to connect to the client over persistent TCP connections, using the * various Stratum protocols. */ -public class StratumServer implements EthHashObserver { +public class StratumServer implements PoWObserver { private static final Logger logger = getLogger(); @@ -118,19 +118,18 @@ public CompletableFuture stop() { } @Override - public void newJob(final EthHashSolverInputs ethHashSolverInputs) { + public void newJob(final PoWSolverInputs poWSolverInputs) { if (!started.get()) { - logger.debug("Discarding {} as stratum server is not started", ethHashSolverInputs); + logger.debug("Discarding {} as stratum server is not started", poWSolverInputs); return; } for (StratumProtocol protocol : protocols) { - protocol.setCurrentWorkTask(ethHashSolverInputs); + protocol.setCurrentWorkTask(poWSolverInputs); } } @Override - public void setSubmitWorkCallback( - final Function submitSolutionCallback) { + public void setSubmitWorkCallback(final Function submitSolutionCallback) { for (StratumProtocol protocol : protocols) { protocol.setSubmitCallback(submitSolutionCallback); } diff --git a/ethereum/stratum/src/test/java/org/hyperledger/besu/ethereum/stratum/StratumConnectionTest.java b/ethereum/stratum/src/test/java/org/hyperledger/besu/ethereum/stratum/StratumConnectionTest.java index 13a112cf1cb..74b69ed2f18 100644 --- a/ethereum/stratum/src/test/java/org/hyperledger/besu/ethereum/stratum/StratumConnectionTest.java +++ b/ethereum/stratum/src/test/java/org/hyperledger/besu/ethereum/stratum/StratumConnectionTest.java @@ -17,9 +17,9 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Mockito.when; -import org.hyperledger.besu.ethereum.blockcreation.EthHashMiningCoordinator; +import org.hyperledger.besu.ethereum.blockcreation.PoWMiningCoordinator; import org.hyperledger.besu.ethereum.mainnet.EpochCalculator; -import org.hyperledger.besu.ethereum.mainnet.EthHashSolverInputs; +import org.hyperledger.besu.ethereum.mainnet.PoWSolverInputs; import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicReference; @@ -34,11 +34,11 @@ public class StratumConnectionTest { - @Mock EthHashMiningCoordinator miningCoordinator; + @Mock PoWMiningCoordinator miningCoordinator; @Before public void setup() { - miningCoordinator = Mockito.mock(EthHashMiningCoordinator.class); + miningCoordinator = Mockito.mock(PoWMiningCoordinator.class); when(miningCoordinator.getEpochCalculator()) .thenReturn(new EpochCalculator.DefaultEpochCalculator()); } @@ -128,7 +128,7 @@ public void testStratum1SendWork() { assertThat(called.get()).isFalse(); // now send work without waiting. protocol.setCurrentWorkTask( - new EthHashSolverInputs( + new PoWSolverInputs( UInt256.valueOf(3), Bytes.fromHexString("deadbeef").toArrayUnsafe(), 42)); assertThat(message.get())