Search in sources :

Example 1 with PoWMiningCoordinator

use of org.hyperledger.besu.ethereum.blockcreation.PoWMiningCoordinator in project besu by hyperledger.

the class MainnetBesuControllerBuilder method createMiningCoordinator.

@Override
protected MiningCoordinator createMiningCoordinator(final ProtocolSchedule protocolSchedule, final ProtocolContext protocolContext, final TransactionPool transactionPool, final MiningParameters miningParameters, final SyncState syncState, final EthProtocolManager ethProtocolManager) {
    final PoWMinerExecutor executor = new PoWMinerExecutor(protocolContext, protocolSchedule, transactionPool.getPendingTransactions(), miningParameters, new DefaultBlockScheduler(MainnetBlockHeaderValidator.MINIMUM_SECONDS_SINCE_PARENT, MainnetBlockHeaderValidator.TIMESTAMP_TOLERANCE_S, clock), epochCalculator, miningParameters.getPowJobTimeToLive(), miningParameters.getMaxOmmerDepth());
    final PoWMiningCoordinator miningCoordinator = new PoWMiningCoordinator(protocolContext.getBlockchain(), executor, syncState, miningParameters.getRemoteSealersLimit(), miningParameters.getRemoteSealersTimeToLive());
    miningCoordinator.addMinedBlockObserver(ethProtocolManager);
    miningCoordinator.setStratumMiningEnabled(miningParameters.isStratumMiningEnabled());
    if (miningParameters.isMiningEnabled()) {
        miningCoordinator.enable();
    }
    return miningCoordinator;
}
Also used : DefaultBlockScheduler(org.hyperledger.besu.ethereum.blockcreation.DefaultBlockScheduler) PoWMiningCoordinator(org.hyperledger.besu.ethereum.blockcreation.PoWMiningCoordinator) PoWMinerExecutor(org.hyperledger.besu.ethereum.blockcreation.PoWMinerExecutor)

Example 2 with PoWMiningCoordinator

use of org.hyperledger.besu.ethereum.blockcreation.PoWMiningCoordinator in project besu by hyperledger.

the class AbstractJsonRpcHttpServiceTest method getRpcMethods.

protected Map<String, JsonRpcMethod> getRpcMethods(final JsonRpcConfiguration config, final BlockchainSetupUtil blockchainSetupUtil) {
    final ProtocolContext protocolContext = mock(ProtocolContext.class);
    final Synchronizer synchronizerMock = mock(Synchronizer.class);
    final P2PNetwork peerDiscoveryMock = mock(P2PNetwork.class);
    final TransactionPool transactionPoolMock = mock(TransactionPool.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
    when(transactionPoolMock.addLocalTransaction(argThat(tx -> tx.getNonce() == 16))).thenReturn(ValidationResult.invalid(TransactionInvalidReason.NONCE_TOO_LOW));
    final GasPricePendingTransactionsSorter pendingTransactionsMock = mock(GasPricePendingTransactionsSorter.class);
    when(transactionPoolMock.getPendingTransactions()).thenReturn(pendingTransactionsMock);
    final PrivacyParameters privacyParameters = mock(PrivacyParameters.class);
    final BlockchainQueries blockchainQueries = new BlockchainQueries(blockchainSetupUtil.getBlockchain(), blockchainSetupUtil.getWorldArchive());
    final FilterIdGenerator filterIdGenerator = mock(FilterIdGenerator.class);
    final FilterRepository filterRepository = new FilterRepository();
    when(filterIdGenerator.nextId()).thenReturn("0x1");
    filterManager = new FilterManagerBuilder().blockchainQueries(blockchainQueries).transactionPool(transactionPoolMock).filterIdGenerator(filterIdGenerator).filterRepository(filterRepository).build();
    final Set<Capability> supportedCapabilities = new HashSet<>();
    supportedCapabilities.add(EthProtocol.ETH62);
    supportedCapabilities.add(EthProtocol.ETH63);
    final NatService natService = new NatService(Optional.empty());
    return new JsonRpcMethodsFactory().methods(CLIENT_VERSION, NETWORK_ID, new StubGenesisConfigOptions(), peerDiscoveryMock, blockchainQueries, synchronizerMock, blockchainSetupUtil.getProtocolSchedule(), protocolContext, filterManager, transactionPoolMock, miningCoordinatorMock, new NoOpMetricsSystem(), supportedCapabilities, Optional.empty(), Optional.empty(), JSON_RPC_APIS, privacyParameters, config, mock(WebSocketConfiguration.class), mock(MetricsConfiguration.class), natService, new HashMap<>(), folder.getRoot().toPath(), mock(EthPeers.class));
}
Also used : ValidationResult(org.hyperledger.besu.ethereum.mainnet.ValidationResult) Arrays(java.util.Arrays) ArgumentMatchers.argThat(org.mockito.ArgumentMatchers.argThat) URL(java.net.URL) FilterRepository(org.hyperledger.besu.ethereum.api.jsonrpc.internal.filter.FilterRepository) WebSocketConfiguration(org.hyperledger.besu.ethereum.api.jsonrpc.websocket.WebSocketConfiguration) Preconditions.checkArgument(com.google.common.base.Preconditions.checkArgument) BlockchainSetupUtil(org.hyperledger.besu.ethereum.core.BlockchainSetupUtil) DataStorageFormat(org.hyperledger.besu.ethereum.worldstate.DataStorageFormat) Synchronizer(org.hyperledger.besu.ethereum.core.Synchronizer) FilterManagerBuilder(org.hyperledger.besu.ethereum.api.jsonrpc.internal.filter.FilterManagerBuilder) Map(java.util.Map) After(org.junit.After) BigInteger(java.math.BigInteger) PoWMiningCoordinator(org.hyperledger.besu.ethereum.blockcreation.PoWMiningCoordinator) ClassRule(org.junit.ClassRule) GasPricePendingTransactionsSorter(org.hyperledger.besu.ethereum.eth.transactions.sorter.GasPricePendingTransactionsSorter) MediaType(okhttp3.MediaType) BlockchainQueries(org.hyperledger.besu.ethereum.api.query.BlockchainQueries) Collection(java.util.Collection) Set(java.util.Set) P2PNetwork(org.hyperledger.besu.ethereum.p2p.network.P2PNetwork) EthPeers(org.hyperledger.besu.ethereum.eth.manager.EthPeers) Optional(java.util.Optional) Capability(org.hyperledger.besu.ethereum.p2p.rlpx.wire.Capability) Mockito.mock(org.mockito.Mockito.mock) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) ChainResources(org.hyperledger.besu.testutil.BlockTestUtil.ChainResources) HashMap(java.util.HashMap) NoOpMetricsSystem(org.hyperledger.besu.metrics.noop.NoOpMetricsSystem) EthProtocol(org.hyperledger.besu.ethereum.eth.EthProtocol) HashSet(java.util.HashSet) FilterManager(org.hyperledger.besu.ethereum.api.jsonrpc.internal.filter.FilterManager) HealthService(org.hyperledger.besu.ethereum.api.jsonrpc.health.HealthService) JsonRpcMethodsFactory(org.hyperledger.besu.ethereum.api.jsonrpc.methods.JsonRpcMethodsFactory) TransactionInvalidReason(org.hyperledger.besu.ethereum.transaction.TransactionInvalidReason) Before(org.junit.Before) TransactionPool(org.hyperledger.besu.ethereum.eth.transactions.TransactionPool) Vertx(io.vertx.core.Vertx) StubGenesisConfigOptions(org.hyperledger.besu.config.StubGenesisConfigOptions) Mockito.when(org.mockito.Mockito.when) MetricsConfiguration(org.hyperledger.besu.metrics.prometheus.MetricsConfiguration) OkHttpClient(okhttp3.OkHttpClient) ProtocolContext(org.hyperledger.besu.ethereum.ProtocolContext) FilterIdGenerator(org.hyperledger.besu.ethereum.api.jsonrpc.internal.filter.FilterIdGenerator) Transaction(org.hyperledger.besu.ethereum.core.Transaction) JsonRpcMethod(org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.JsonRpcMethod) PrivacyParameters(org.hyperledger.besu.ethereum.core.PrivacyParameters) NatService(org.hyperledger.besu.nat.NatService) TemporaryFolder(org.junit.rules.TemporaryFolder) Synchronizer(org.hyperledger.besu.ethereum.core.Synchronizer) TransactionPool(org.hyperledger.besu.ethereum.eth.transactions.TransactionPool) Capability(org.hyperledger.besu.ethereum.p2p.rlpx.wire.Capability) WebSocketConfiguration(org.hyperledger.besu.ethereum.api.jsonrpc.websocket.WebSocketConfiguration) NatService(org.hyperledger.besu.nat.NatService) P2PNetwork(org.hyperledger.besu.ethereum.p2p.network.P2PNetwork) FilterManagerBuilder(org.hyperledger.besu.ethereum.api.jsonrpc.internal.filter.FilterManagerBuilder) EthPeers(org.hyperledger.besu.ethereum.eth.manager.EthPeers) PrivacyParameters(org.hyperledger.besu.ethereum.core.PrivacyParameters) JsonRpcMethodsFactory(org.hyperledger.besu.ethereum.api.jsonrpc.methods.JsonRpcMethodsFactory) Transaction(org.hyperledger.besu.ethereum.core.Transaction) MetricsConfiguration(org.hyperledger.besu.metrics.prometheus.MetricsConfiguration) BlockchainQueries(org.hyperledger.besu.ethereum.api.query.BlockchainQueries) FilterRepository(org.hyperledger.besu.ethereum.api.jsonrpc.internal.filter.FilterRepository) FilterIdGenerator(org.hyperledger.besu.ethereum.api.jsonrpc.internal.filter.FilterIdGenerator) NoOpMetricsSystem(org.hyperledger.besu.metrics.noop.NoOpMetricsSystem) ProtocolContext(org.hyperledger.besu.ethereum.ProtocolContext) PoWMiningCoordinator(org.hyperledger.besu.ethereum.blockcreation.PoWMiningCoordinator) GasPricePendingTransactionsSorter(org.hyperledger.besu.ethereum.eth.transactions.sorter.GasPricePendingTransactionsSorter) StubGenesisConfigOptions(org.hyperledger.besu.config.StubGenesisConfigOptions) HashSet(java.util.HashSet)

Example 3 with PoWMiningCoordinator

use of org.hyperledger.besu.ethereum.blockcreation.PoWMiningCoordinator in project besu by hyperledger.

the class GraphQLHttpServiceHostWhitelistTest method createGraphQLHttpService.

private GraphQLHttpService createGraphQLHttpService() throws Exception {
    final BlockchainQueries blockchainQueries = Mockito.mock(BlockchainQueries.class);
    final Synchronizer synchronizer = Mockito.mock(Synchronizer.class);
    final PoWMiningCoordinator miningCoordinatorMock = Mockito.mock(PoWMiningCoordinator.class);
    final Map<GraphQLContextType, Object> graphQLContextMap = Map.of(GraphQLContextType.BLOCKCHAIN_QUERIES, blockchainQueries, GraphQLContextType.TRANSACTION_POOL, Mockito.mock(TransactionPool.class), GraphQLContextType.MINING_COORDINATOR, miningCoordinatorMock, GraphQLContextType.SYNCHRONIZER, synchronizer);
    final Set<Capability> supportedCapabilities = new HashSet<>();
    supportedCapabilities.add(EthProtocol.ETH62);
    supportedCapabilities.add(EthProtocol.ETH63);
    final GraphQLDataFetchers dataFetchers = new GraphQLDataFetchers(supportedCapabilities);
    final GraphQL graphQL = GraphQLProvider.buildGraphQL(dataFetchers);
    return new GraphQLHttpService(vertx, folder.newFolder().toPath(), graphQLConfig, graphQL, graphQLContextMap, Mockito.mock(EthScheduler.class));
}
Also used : Synchronizer(org.hyperledger.besu.ethereum.core.Synchronizer) TransactionPool(org.hyperledger.besu.ethereum.eth.transactions.TransactionPool) Capability(org.hyperledger.besu.ethereum.p2p.rlpx.wire.Capability) GraphQL(graphql.GraphQL) EthScheduler(org.hyperledger.besu.ethereum.eth.manager.EthScheduler) BlockchainQueries(org.hyperledger.besu.ethereum.api.query.BlockchainQueries) PoWMiningCoordinator(org.hyperledger.besu.ethereum.blockcreation.PoWMiningCoordinator) HashSet(java.util.HashSet)

Example 4 with PoWMiningCoordinator

use of org.hyperledger.besu.ethereum.blockcreation.PoWMiningCoordinator in project besu by hyperledger.

the class StratumServerTest method stratumServerWithMocks.

private StratumServer stratumServerWithMocks(final ObservableMetricsSystem metrics) {
    PoWMiningCoordinator mockPoW = Mockito.when(Mockito.mock(PoWMiningCoordinator.class).getEpochCalculator()).thenReturn(new EpochCalculator.DefaultEpochCalculator()).getMock();
    StratumServer ss = new StratumServer(null, mockPoW, 0, "lo", "", metrics) {

        @Override
        public CompletableFuture<?> start() {
            this.started.set(true);
            return null;
        }
    };
    ss.start();
    return ss;
}
Also used : PoWMiningCoordinator(org.hyperledger.besu.ethereum.blockcreation.PoWMiningCoordinator)

Example 5 with PoWMiningCoordinator

use of org.hyperledger.besu.ethereum.blockcreation.PoWMiningCoordinator in project besu by hyperledger.

the class JsonRpcTestMethodsFactory method methods.

public Map<String, JsonRpcMethod> methods() {
    final P2PNetwork peerDiscovery = mock(P2PNetwork.class);
    final EthPeers ethPeers = mock(EthPeers.class);
    final TransactionPool transactionPool = mock(TransactionPool.class);
    final PoWMiningCoordinator miningCoordinator = mock(PoWMiningCoordinator.class);
    final ObservableMetricsSystem metricsSystem = new NoOpMetricsSystem();
    final Optional<AccountLocalConfigPermissioningController> accountWhitelistController = Optional.of(mock(AccountLocalConfigPermissioningController.class));
    final Optional<NodeLocalConfigPermissioningController> nodeWhitelistController = Optional.of(mock(NodeLocalConfigPermissioningController.class));
    final PrivacyParameters privacyParameters = mock(PrivacyParameters.class);
    final FilterManager filterManager = new FilterManagerBuilder().blockchainQueries(blockchainQueries).transactionPool(transactionPool).privacyParameters(privacyParameters).build();
    final JsonRpcConfiguration jsonRpcConfiguration = mock(JsonRpcConfiguration.class);
    final WebSocketConfiguration webSocketConfiguration = mock(WebSocketConfiguration.class);
    final MetricsConfiguration metricsConfiguration = mock(MetricsConfiguration.class);
    final NatService natService = new NatService(Optional.empty());
    final List<String> apis = new ArrayList<>();
    apis.add(RpcApis.ETH.name());
    apis.add(RpcApis.NET.name());
    apis.add(RpcApis.WEB3.name());
    apis.add(RpcApis.PRIV.name());
    apis.add(RpcApis.DEBUG.name());
    final Path dataDir = mock(Path.class);
    return new JsonRpcMethodsFactory().methods(CLIENT_VERSION, NETWORK_ID, new StubGenesisConfigOptions(), peerDiscovery, blockchainQueries, synchronizer, importer.getProtocolSchedule(), context, filterManager, transactionPool, miningCoordinator, metricsSystem, new HashSet<>(), accountWhitelistController, nodeWhitelistController, apis, privacyParameters, jsonRpcConfiguration, webSocketConfiguration, metricsConfiguration, natService, new HashMap<>(), dataDir, ethPeers);
}
Also used : NodeLocalConfigPermissioningController(org.hyperledger.besu.ethereum.permissioning.NodeLocalConfigPermissioningController) ArrayList(java.util.ArrayList) AccountLocalConfigPermissioningController(org.hyperledger.besu.ethereum.permissioning.AccountLocalConfigPermissioningController) EthPeers(org.hyperledger.besu.ethereum.eth.manager.EthPeers) FilterManager(org.hyperledger.besu.ethereum.api.jsonrpc.internal.filter.FilterManager) MetricsConfiguration(org.hyperledger.besu.metrics.prometheus.MetricsConfiguration) Path(java.nio.file.Path) TransactionPool(org.hyperledger.besu.ethereum.eth.transactions.TransactionPool) WebSocketConfiguration(org.hyperledger.besu.ethereum.api.jsonrpc.websocket.WebSocketConfiguration) NatService(org.hyperledger.besu.nat.NatService) P2PNetwork(org.hyperledger.besu.ethereum.p2p.network.P2PNetwork) FilterManagerBuilder(org.hyperledger.besu.ethereum.api.jsonrpc.internal.filter.FilterManagerBuilder) PrivacyParameters(org.hyperledger.besu.ethereum.core.PrivacyParameters) JsonRpcMethodsFactory(org.hyperledger.besu.ethereum.api.jsonrpc.methods.JsonRpcMethodsFactory) ObservableMetricsSystem(org.hyperledger.besu.metrics.ObservableMetricsSystem) NoOpMetricsSystem(org.hyperledger.besu.metrics.noop.NoOpMetricsSystem) PoWMiningCoordinator(org.hyperledger.besu.ethereum.blockcreation.PoWMiningCoordinator) StubGenesisConfigOptions(org.hyperledger.besu.config.StubGenesisConfigOptions)

Aggregations

PoWMiningCoordinator (org.hyperledger.besu.ethereum.blockcreation.PoWMiningCoordinator)7 TransactionPool (org.hyperledger.besu.ethereum.eth.transactions.TransactionPool)5 HashSet (java.util.HashSet)4 BlockchainQueries (org.hyperledger.besu.ethereum.api.query.BlockchainQueries)4 Synchronizer (org.hyperledger.besu.ethereum.core.Synchronizer)4 Capability (org.hyperledger.besu.ethereum.p2p.rlpx.wire.Capability)4 GraphQL (graphql.GraphQL)3 Vertx (io.vertx.core.Vertx)2 URL (java.net.URL)2 ArrayList (java.util.ArrayList)2 Map (java.util.Map)2 Optional (java.util.Optional)2 Set (java.util.Set)2 MediaType (okhttp3.MediaType)2 OkHttpClient (okhttp3.OkHttpClient)2 StubGenesisConfigOptions (org.hyperledger.besu.config.StubGenesisConfigOptions)2 ProtocolContext (org.hyperledger.besu.ethereum.ProtocolContext)2 FilterManager (org.hyperledger.besu.ethereum.api.jsonrpc.internal.filter.FilterManager)2 FilterManagerBuilder (org.hyperledger.besu.ethereum.api.jsonrpc.internal.filter.FilterManagerBuilder)2 JsonRpcMethodsFactory (org.hyperledger.besu.ethereum.api.jsonrpc.methods.JsonRpcMethodsFactory)2