Skip to content

Commit

Permalink
Share with RPC tracing methods ethscheduler
Browse files Browse the repository at this point in the history
from Besu Controller.

Signed-off-by: Ameziane H. <[email protected]>
  • Loading branch information
ahamlat committed Jan 7, 2025
1 parent d7babdd commit 6a541e5
Show file tree
Hide file tree
Showing 27 changed files with 194 additions and 151 deletions.
24 changes: 16 additions & 8 deletions besu/src/main/java/org/hyperledger/besu/RunnerBuilder.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright ConsenSys AG.
* Copyright contributors to Besu.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
Expand Down Expand Up @@ -74,6 +74,7 @@
import org.hyperledger.besu.ethereum.core.PrivacyParameters;
import org.hyperledger.besu.ethereum.core.Synchronizer;
import org.hyperledger.besu.ethereum.eth.manager.EthPeers;
import org.hyperledger.besu.ethereum.eth.manager.EthScheduler;
import org.hyperledger.besu.ethereum.eth.transactions.TransactionPool;
import org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule;
import org.hyperledger.besu.ethereum.mainnet.precompiles.privacy.FlexiblePrivacyPrecompiledContract;
Expand Down Expand Up @@ -836,7 +837,8 @@ public Runner build() {
besuPluginContext.getNamedPlugins(),
dataDir,
rpcEndpointServiceImpl,
transactionSimulator);
transactionSimulator,
besuController.getProtocolManager().ethContext().getScheduler());

jsonRpcHttpService =
Optional.of(
Expand Down Expand Up @@ -882,7 +884,8 @@ public Runner build() {
besuPluginContext.getNamedPlugins(),
dataDir,
rpcEndpointServiceImpl,
transactionSimulator);
transactionSimulator,
besuController.getProtocolManager().ethContext().getScheduler());

final Optional<AuthenticationService> authToUse =
engineJsonRpcConfiguration.get().isAuthenticationEnabled()
Expand Down Expand Up @@ -978,7 +981,8 @@ public Runner build() {
besuPluginContext.getNamedPlugins(),
dataDir,
rpcEndpointServiceImpl,
transactionSimulator);
transactionSimulator,
besuController.getProtocolManager().ethContext().getScheduler());

createLogsSubscriptionService(
context.getBlockchain(), subscriptionManager, privacyParameters, blockchainQueries);
Expand Down Expand Up @@ -1059,7 +1063,8 @@ public Runner build() {
besuPluginContext.getNamedPlugins(),
dataDir,
rpcEndpointServiceImpl,
transactionSimulator);
transactionSimulator,
besuController.getProtocolManager().ethContext().getScheduler());

jsonRpcIpcService =
Optional.of(
Expand Down Expand Up @@ -1099,7 +1104,8 @@ public Runner build() {
besuPluginContext.getNamedPlugins(),
dataDir,
rpcEndpointServiceImpl,
transactionSimulator);
transactionSimulator,
besuController.getProtocolManager().ethContext().getScheduler());
} else {
inProcessRpcMethods = Map.of();
}
Expand Down Expand Up @@ -1262,7 +1268,8 @@ private Map<String, JsonRpcMethod> jsonRpcMethods(
final Map<String, BesuPlugin> namedPlugins,
final Path dataDir,
final RpcEndpointServiceImpl rpcEndpointServiceImpl,
final TransactionSimulator transactionSimulator) {
final TransactionSimulator transactionSimulator,
final EthScheduler ethScheduler) {
// sync vertx for engine consensus API, to process requests in FIFO order;
final Vertx consensusEngineServer = Vertx.vertx(new VertxOptions().setWorkerPoolSize(1));

Expand Down Expand Up @@ -1300,7 +1307,8 @@ private Map<String, JsonRpcMethod> jsonRpcMethods(
consensusEngineServer,
apiConfiguration,
enodeDnsConfiguration,
transactionSimulator);
transactionSimulator,
ethScheduler);
methods.putAll(besuController.getAdditionalJsonRpcMethods(jsonRpcApis));

final var pluginMethods =
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright ConsenSys AG.
* Copyright contributors to Besu.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
Expand Down Expand Up @@ -38,6 +38,7 @@
import org.hyperledger.besu.ethereum.core.PrivacyParameters;
import org.hyperledger.besu.ethereum.core.Synchronizer;
import org.hyperledger.besu.ethereum.eth.manager.EthPeers;
import org.hyperledger.besu.ethereum.eth.manager.EthScheduler;
import org.hyperledger.besu.ethereum.eth.transactions.TransactionPool;
import org.hyperledger.besu.ethereum.mainnet.HeaderValidationMode;
import org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule;
Expand Down Expand Up @@ -228,6 +229,7 @@ public Map<String, JsonRpcMethod> methods() {
Vertx.vertx(new VertxOptions().setWorkerPoolSize(1)),
ImmutableApiConfiguration.builder().build(),
Optional.empty(),
transactionSimulator);
transactionSimulator,
new EthScheduler(1,1,1,new NoOpMetricsSystem()));
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright ConsenSys AG.
* Copyright contributors to Besu.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,15 @@
import org.hyperledger.besu.ethereum.vm.DebugOperationTracer;
import org.hyperledger.besu.metrics.BesuMetricCategory;
import org.hyperledger.besu.metrics.ObservableMetricsSystem;
import org.hyperledger.besu.metrics.noop.NoOpMetricsSystem;
import org.hyperledger.besu.plugin.services.metrics.Counter;
import org.hyperledger.besu.plugin.services.metrics.LabelledMetric;
import org.hyperledger.besu.services.pipeline.Pipeline;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Optional;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.concurrent.ExecutionException;
import java.util.function.Supplier;

Expand All @@ -52,11 +53,13 @@ public abstract class AbstractDebugTraceBlock implements JsonRpcMethod {
private final ProtocolSchedule protocolSchedule;
private final LabelledMetric<Counter> outputCounter;
private final Supplier<BlockchainQueries> blockchainQueriesSupplier;
private final EthScheduler ethScheduler;

public AbstractDebugTraceBlock(
final ProtocolSchedule protocolSchedule,
final BlockchainQueries blockchainQueries,
final ObservableMetricsSystem metricsSystem) {
final ObservableMetricsSystem metricsSystem,
final EthScheduler ethScheduler) {
this.blockchainQueriesSupplier = Suppliers.ofInstance(blockchainQueries);
this.protocolSchedule = protocolSchedule;
this.outputCounter =
Expand All @@ -66,6 +69,7 @@ public AbstractDebugTraceBlock(
"Number of transactions processed for each block",
"step",
"action");
this.ethScheduler = ethScheduler;
}

protected BlockchainQueries getBlockchainQueries() {
Expand Down Expand Up @@ -100,8 +104,8 @@ protected Collection<DebugTraceTransactionResult> getTraces(
getBlockchainQueries(),
block.getHash(),
traceableState -> {
Collection<DebugTraceTransactionResult> tracesList =
new CopyOnWriteArrayList<>();
List<DebugTraceTransactionResult> tracesList =
Collections.synchronizedList(new ArrayList<>());
final ProtocolSpec protocolSpec =
protocolSchedule.getByBlockHeader(block.getHeader());
final MainnetTransactionProcessor transactionProcessor =
Expand Down Expand Up @@ -136,17 +140,7 @@ protected Collection<DebugTraceTransactionResult> getTraces(
.andFinishWith("collect_results", tracesList::add);

try {
if (getBlockchainQueries().getEthScheduler().isPresent()) {
getBlockchainQueries()
.getEthScheduler()
.get()
.startPipeline(traceBlockPipeline)
.get();
} else {
EthScheduler ethScheduler =
new EthScheduler(1, 1, 1, 1, new NoOpMetricsSystem());
ethScheduler.startPipeline(traceBlockPipeline).get();
}
ethScheduler.startPipeline(traceBlockPipeline).get();
} catch (InterruptedException | ExecutionException e) {
throw new RuntimeException(e);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright ConsenSys AG.
* Copyright contributors to Besu.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
Expand Down Expand Up @@ -27,6 +27,7 @@
import org.hyperledger.besu.ethereum.core.Block;
import org.hyperledger.besu.ethereum.core.BlockHeaderFunctions;
import org.hyperledger.besu.ethereum.debug.TraceOptions;
import org.hyperledger.besu.ethereum.eth.manager.EthScheduler;
import org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule;
import org.hyperledger.besu.ethereum.mainnet.ScheduleBasedBlockHeaderFunctions;
import org.hyperledger.besu.ethereum.rlp.RLP;
Expand All @@ -48,8 +49,9 @@ public class DebugTraceBlock extends AbstractDebugTraceBlock {
public DebugTraceBlock(
final ProtocolSchedule protocolSchedule,
final BlockchainQueries blockchainQueries,
final ObservableMetricsSystem metricsSystem) {
super(protocolSchedule, blockchainQueries, metricsSystem);
final ObservableMetricsSystem metricsSystem,
final EthScheduler ethScheduler) {
super(protocolSchedule, blockchainQueries, metricsSystem, ethScheduler);
this.blockHeaderFunctions = ScheduleBasedBlockHeaderFunctions.create(protocolSchedule);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright ConsenSys AG.
* Copyright contributors to Besu.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
Expand All @@ -26,6 +26,7 @@
import org.hyperledger.besu.ethereum.api.query.BlockchainQueries;
import org.hyperledger.besu.ethereum.core.Block;
import org.hyperledger.besu.ethereum.debug.TraceOptions;
import org.hyperledger.besu.ethereum.eth.manager.EthScheduler;
import org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule;
import org.hyperledger.besu.metrics.ObservableMetricsSystem;

Expand All @@ -37,8 +38,9 @@ public class DebugTraceBlockByHash extends AbstractDebugTraceBlock {
public DebugTraceBlockByHash(
final ProtocolSchedule protocolSchedule,
final BlockchainQueries blockchainQueries,
final ObservableMetricsSystem metricsSystem) {
super(protocolSchedule, blockchainQueries, metricsSystem);
final ObservableMetricsSystem metricsSystem,
final EthScheduler ethScheduler) {
super(protocolSchedule, blockchainQueries, metricsSystem, ethScheduler);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright contributors to Hyperledger Besu.
* Copyright contributors to Besu.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
Expand Down Expand Up @@ -36,34 +36,37 @@
import org.hyperledger.besu.ethereum.vm.DebugOperationTracer;
import org.hyperledger.besu.metrics.BesuMetricCategory;
import org.hyperledger.besu.metrics.ObservableMetricsSystem;
import org.hyperledger.besu.metrics.noop.NoOpMetricsSystem;
import org.hyperledger.besu.plugin.services.metrics.Counter;
import org.hyperledger.besu.plugin.services.metrics.LabelledMetric;
import org.hyperledger.besu.services.pipeline.Pipeline;

import java.util.Collection;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Optional;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.concurrent.ExecutionException;

public class DebugTraceBlockByNumber extends AbstractBlockParameterMethod {

protected final ProtocolSchedule protocolSchedule;
private final LabelledMetric<Counter> outputCounter;
private final EthScheduler ethScheduler;

public DebugTraceBlockByNumber(
final ProtocolSchedule protocolSchedule,
final BlockchainQueries blockchainQueries,
final ObservableMetricsSystem metricsSystem) {
final ObservableMetricsSystem metricsSystem,
final EthScheduler ethScheduler) {
super(blockchainQueries);
this.protocolSchedule = protocolSchedule;
this.outputCounter =
metricsSystem.createLabelledCounter(
BesuMetricCategory.BLOCKCHAIN,
"transactions_debugTraceblock_pipeline_processed_total",
"transactions_debugtraceblock_pipeline_processed_total",
"Number of transactions processed for each block",
"step",
"action");
this.ethScheduler = ethScheduler;
}

@Override
Expand Down Expand Up @@ -108,8 +111,8 @@ protected Object resultByBlockNumber(
getBlockchainQueries(),
Optional.of(block.getHeader()),
traceableState -> {
Collection<DebugTraceTransactionResult> tracesList =
new CopyOnWriteArrayList<>();
List<DebugTraceTransactionResult> tracesList =
Collections.synchronizedList(new ArrayList<>());
final ProtocolSpec protocolSpec =
protocolSchedule.getByBlockHeader(block.getHeader());
final MainnetTransactionProcessor transactionProcessor =
Expand Down Expand Up @@ -144,17 +147,7 @@ protected Object resultByBlockNumber(
.andFinishWith("collect_results", tracesList::add);

try {
if (getBlockchainQueries().getEthScheduler().isPresent()) {
getBlockchainQueries()
.getEthScheduler()
.get()
.startPipeline(traceBlockPipeline)
.get();
} else {
EthScheduler ethScheduler =
new EthScheduler(1, 1, 1, 1, new NoOpMetricsSystem());
ethScheduler.startPipeline(traceBlockPipeline).get();
}
ethScheduler.startPipeline(traceBlockPipeline).get();
} catch (InterruptedException | ExecutionException e) {
throw new RuntimeException(e);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright ConsenSys AG.
* Copyright contributors to Besu.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
Expand Down Expand Up @@ -39,7 +39,6 @@
import org.hyperledger.besu.ethereum.vm.DebugOperationTracer;
import org.hyperledger.besu.evm.worldstate.WorldUpdater;
import org.hyperledger.besu.metrics.BesuMetricCategory;
import org.hyperledger.besu.metrics.noop.NoOpMetricsSystem;
import org.hyperledger.besu.plugin.services.MetricsSystem;
import org.hyperledger.besu.plugin.services.metrics.Counter;
import org.hyperledger.besu.plugin.services.metrics.LabelledMetric;
Expand All @@ -57,11 +56,13 @@ public class TraceBlock extends AbstractBlockParameterMethod {
private static final ObjectMapper MAPPER = new ObjectMapper();
protected final ProtocolSchedule protocolSchedule;
private final LabelledMetric<Counter> outputCounter;
protected final EthScheduler ethScheduler;

public TraceBlock(
final ProtocolSchedule protocolSchedule,
final BlockchainQueries queries,
final MetricsSystem metricsSystem) {
final MetricsSystem metricsSystem,
final EthScheduler ethScheduler) {
super(queries);
this.protocolSchedule = protocolSchedule;
this.outputCounter =
Expand All @@ -71,6 +72,7 @@ public TraceBlock(
"Number of transactions processed for each block",
"step",
"action");
this.ethScheduler = ethScheduler;
}

@Override
Expand Down Expand Up @@ -153,16 +155,7 @@ protected ArrayNodeWrapper traceBlock(
traceStream -> traceStream.forEachOrdered(buildArrayNodeStep));

try {
if (getBlockchainQueries().getEthScheduler().isPresent()) {
getBlockchainQueries()
.getEthScheduler()
.get()
.startPipeline(traceBlockPipeline)
.get();
} else {
EthScheduler ethScheduler = new EthScheduler(1, 1, 1, 1, new NoOpMetricsSystem());
ethScheduler.startPipeline(traceBlockPipeline).get();
}
ethScheduler.startPipeline(traceBlockPipeline).get();
} catch (InterruptedException | ExecutionException e) {
throw new RuntimeException(e);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright contributors to Hyperledger Besu.
* Copyright contributors to Besu.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
Expand Down
Loading

0 comments on commit 6a541e5

Please sign in to comment.