Skip to content

Commit

Permalink
Add some thread names for debugging clarity (#3476)
Browse files Browse the repository at this point in the history
BFT executor threads include IBFT or QBFT to help with the IBFT -> QBFT migration.

Signed-off-by: Simon Dudley <simon.dudley@consensys.net>
  • Loading branch information
siladu committed Feb 22, 2022
1 parent fb70ba4 commit d30b776
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 11 deletions.
3 changes: 2 additions & 1 deletion besu/src/main/java/org/hyperledger/besu/cli/BesuCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -2648,7 +2648,8 @@ private void addShutdownHook(final Runner runner) {
} catch (final Exception e) {
logger.error("Failed to stop Besu");
}
}));
},
"BesuCommand-Shutdown-Hook"));
}

// Used to discover the default IP of the client.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,8 @@ protected MiningCoordinator createMiningCoordinator(
final SyncState syncState,
final EthProtocolManager ethProtocolManager) {
final MutableBlockchain blockchain = protocolContext.getBlockchain();
final BftExecutors bftExecutors = BftExecutors.create(metricsSystem);
final BftExecutors bftExecutors =
BftExecutors.create(metricsSystem, BftExecutors.ConsensusType.IBFT);

final Address localAddress = Util.publicKeyToAddress(nodeKey.getPublicKey());
final BftBlockCreatorFactory blockCreatorFactory =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,8 @@ protected MiningCoordinator createMiningCoordinator(
final SyncState syncState,
final EthProtocolManager ethProtocolManager) {
final MutableBlockchain blockchain = protocolContext.getBlockchain();
final BftExecutors bftExecutors = BftExecutors.create(metricsSystem);
final BftExecutors bftExecutors =
BftExecutors.create(metricsSystem, BftExecutors.ConsensusType.QBFT);

final Address localAddress = Util.publicKeyToAddress(nodeKey.getPublicKey());
final BftBlockCreatorFactory blockCreatorFactory =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,10 @@
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.ThreadFactory;
import java.util.concurrent.TimeUnit;

import com.google.common.util.concurrent.ThreadFactoryBuilder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand All @@ -36,21 +38,29 @@ private enum State {
STOPPED
}

public enum ConsensusType {
IBFT,
QBFT
}

private static final Logger LOG = LoggerFactory.getLogger(BftExecutors.class);

private final Duration shutdownTimeout = Duration.ofSeconds(30);
private final MetricsSystem metricsSystem;
private final ConsensusType consensusType;

private volatile ScheduledExecutorService timerExecutor;
private volatile ExecutorService bftProcessorExecutor;
private volatile State state = State.IDLE;

private BftExecutors(final MetricsSystem metricsSystem) {
private BftExecutors(final MetricsSystem metricsSystem, final ConsensusType consensusType) {
this.metricsSystem = metricsSystem;
this.consensusType = consensusType;
}

public static BftExecutors create(final MetricsSystem metricsSystem) {
return new BftExecutors(metricsSystem);
public static BftExecutors create(
final MetricsSystem metricsSystem, final ConsensusType consensusType) {
return new BftExecutors(metricsSystem, consensusType);
}

public synchronized void start() {
Expand All @@ -59,8 +69,14 @@ public synchronized void start() {
return;
}
state = State.RUNNING;
bftProcessorExecutor = Executors.newSingleThreadExecutor();
timerExecutor = MonitoredExecutors.newScheduledThreadPool("BftTimerExecutor", 1, metricsSystem);
final ThreadFactory namedThreadFactory =
new ThreadFactoryBuilder()
.setNameFormat("BftProcessorExecutor-" + consensusType.name() + "-%d")
.build();
bftProcessorExecutor = Executors.newSingleThreadExecutor(namedThreadFactory);
timerExecutor =
MonitoredExecutors.newScheduledThreadPool(
"BftTimerExecutor-" + consensusType.name(), 1, metricsSystem);
}

public void stop() {
Expand All @@ -70,7 +86,6 @@ public void stop() {
}
state = State.STOPPED;
}

timerExecutor.shutdownNow();
bftProcessorExecutor.shutdownNow();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,8 @@ private static ControllerAndState createControllerAndFinalState(
final ProposerSelector proposerSelector =
new ProposerSelector(blockChain, blockInterface, true, validatorProvider);

final BftExecutors bftExecutors = BftExecutors.create(new NoOpMetricsSystem());
final BftExecutors bftExecutors =
BftExecutors.create(new NoOpMetricsSystem(), BftExecutors.ConsensusType.IBFT);
final BftFinalState finalState =
new BftFinalState(
protocolContext.getConsensusContext(BftContext.class).getValidatorProvider(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -460,7 +460,8 @@ private static ControllerAndState createControllerAndFinalState(
final ProposerSelector proposerSelector =
new ProposerSelector(blockChain, blockInterface, true, validatorProvider);

final BftExecutors bftExecutors = BftExecutors.create(new NoOpMetricsSystem());
final BftExecutors bftExecutors =
BftExecutors.create(new NoOpMetricsSystem(), BftExecutors.ConsensusType.QBFT);
final BftFinalState finalState =
new BftFinalState(
protocolContext.getConsensusContext(BftContext.class).getValidatorProvider(),
Expand Down

0 comments on commit d30b776

Please sign in to comment.