Skip to content

Commit

Permalink
Merge branch 'hyperledger:main' into add-acceptance-test-engine-cancun
Browse files Browse the repository at this point in the history
  • Loading branch information
Gabriel-Trintinalia authored Sep 18, 2023
2 parents 66846fd + 80d9ada commit 84f3dea
Show file tree
Hide file tree
Showing 8 changed files with 71 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
package org.hyperledger.besu.cli.util;

import org.hyperledger.besu.datatypes.Wei;
import org.hyperledger.besu.util.number.Fraction;
import org.hyperledger.besu.util.number.Percentage;

import java.io.File;
Expand Down Expand Up @@ -92,6 +93,8 @@ private String getConfigurationValue(final OptionSpec optionSpec) {
defaultValue = getNumericEntryAsString(optionSpec);
} else if (optionSpec.type().equals(Percentage.class)) {
defaultValue = getNumericEntryAsString(optionSpec);
} else if (optionSpec.type().equals(Fraction.class)) {
defaultValue = getNumericEntryAsString(optionSpec);
} else { // else will be treated as String
defaultValue = getEntryAsString(optionSpec);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@
import org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule;
import org.hyperledger.besu.ethereum.p2p.config.SubProtocolConfiguration;
import org.hyperledger.besu.ethereum.worldstate.WorldStateArchive;
import org.hyperledger.besu.plugin.services.BesuEvents;
import org.hyperledger.besu.util.Subscribers;

import java.util.HashMap;
Expand Down Expand Up @@ -231,7 +232,30 @@ protected MiningCoordinator createMiningCoordinator(
blockCreatorFactory,
blockchain,
bftEventQueue);
ibftMiningCoordinator.enable();

if (syncState.isInitialSyncPhaseDone()) {
LOG.info("Starting IBFT mining coordinator");
ibftMiningCoordinator.enable();
ibftMiningCoordinator.start();
} else {
LOG.info("IBFT mining coordinator not starting while initial sync in progress");
}

syncState.subscribeCompletionReached(
new BesuEvents.InitialSyncCompletionListener() {
@Override
public void onInitialSyncCompleted() {
LOG.info("Starting IBFT mining coordinator following initial sync");
ibftMiningCoordinator.enable();
ibftMiningCoordinator.start();
}

@Override
public void onInitialSyncRestart() {
// Nothing to do. The mining coordinator won't be started until
// sync has completed.
}
});

return ibftMiningCoordinator;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@
import org.hyperledger.besu.ethereum.p2p.config.SubProtocolConfiguration;
import org.hyperledger.besu.ethereum.transaction.TransactionSimulator;
import org.hyperledger.besu.ethereum.worldstate.WorldStateArchive;
import org.hyperledger.besu.plugin.services.BesuEvents;
import org.hyperledger.besu.util.Subscribers;

import java.util.HashMap;
Expand Down Expand Up @@ -271,7 +272,30 @@ protected MiningCoordinator createMiningCoordinator(
blockCreatorFactory,
blockchain,
bftEventQueue);
miningCoordinator.enable();

if (syncState.isInitialSyncPhaseDone()) {
LOG.info("Starting QBFT mining coordinator");
miningCoordinator.enable();
miningCoordinator.start();
} else {
LOG.info("QBFT mining coordinator not starting while initial sync in progress");
}

syncState.subscribeCompletionReached(
new BesuEvents.InitialSyncCompletionListener() {
@Override
public void onInitialSyncCompleted() {
LOG.info("Starting QBFT mining coordinator following initial sync");
miningCoordinator.enable();
miningCoordinator.start();
}

@Override
public void onInitialSyncRestart() {
// Nothing to do. The mining coordinator won't be started until
// sync has completed.
}
});

return miningCoordinator;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ public void start() {
}

private void startActiveMiningCoordinator() {
activeMiningCoordinator.enable();
activeMiningCoordinator.start();
if (activeMiningCoordinator instanceof BlockAddedObserver) {
((BlockAddedObserver) activeMiningCoordinator).removeObserver();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,9 @@ private enum State {
/** Running state. */
RUNNING,
/** Stopped state. */
STOPPED
STOPPED,
/** Paused state. */
PAUSED,
}

private static final Logger LOG = LoggerFactory.getLogger(BftMiningCoordinator.class);
Expand All @@ -61,7 +63,7 @@ private enum State {
private final BftExecutors bftExecutors;

private long blockAddedObserverId;
private final AtomicReference<State> state = new AtomicReference<>(State.IDLE);
private final AtomicReference<State> state = new AtomicReference<>(State.PAUSED);

/**
* Instantiates a new Bft mining coordinator.
Expand Down Expand Up @@ -122,7 +124,13 @@ public void awaitStop() throws InterruptedException {

@Override
public boolean enable() {
return true;
// Return true if we're already running or idle, or successfully switch to idle
if (state.get() == State.RUNNING
|| state.get() == State.IDLE
|| state.compareAndSet(State.PAUSED, State.IDLE)) {
return true;
}
return false;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ public void stopsMining() {
bftMiningCoordinator.stop();
verify(bftProcessor, never()).stop();

bftMiningCoordinator.enable();
bftMiningCoordinator.start();
bftMiningCoordinator.stop();
verify(bftProcessor).stop();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ private static Stream<Arguments> provideOpaqueBytesNoBlobsWithCommitments() {
createArgument(
"0x03f89d850120b996ed3685012a1a646085012a1a64608303345094ffb38a7a99e3e2335be83fc74b7faa19d55312418308a80280c085012a1a6460e1a00153a6a1e053cf4c5a09e84088ed8ad7cb53d76c8168f1b82f7cfebfcd06da1a01a007785223eec68459d72265f10bdb30ec3415252a63100605a03142fa211ebbe9a07dbbf9e081fa7b9a01202e4d9ee0e0e513f80efbbab6c784635429905389ce86"),
createArgument(
"0x03f889850120b996ed81f0847735940084b2d05e158307a1208001855f495f4955c084b2d05e15e1a001d343d3cd62abd9c5754cbe5128c25ea90786a8ae75fb79c8cf95f4dcdd08ec80a014103732b5a9789bbf5ea859ed904155398abbef343f8fd63007efb70795d382a07272e847382789a092eadf08e2b9002e727376f8466fff0e4d4639fd60a528f2"),
"0x03f89d850120b996ed81f0847735940084b2d05e158307a12094000000000000000000000000000000000010101001855f495f4955c084b2d05e15e1a001d343d3cd62abd9c5754cbe5128c25ea90786a8ae75fb79c8cf95f4dcdd08ec80a014103732b5a9789bbf5ea859ed904155398abbef343f8fd63007efb70795d382a07272e847382789a092eadf08e2b9002e727376f8466fff0e4d4639fd60a528f2"),
createArgument(
"0x03f889850120b996ed81f1843b9aca00847735940e8307a1208001855f495f4955c0847735940ee1a001d552e24560ec2f168be1d4a6385df61c70afe4288f00a3ad172da1a6f2b4f280a0b6690786e5fe79df67dcb60e8a9e8555142c3c96ffd5097c838717f0a7f64129a0112f01ed0cd3b86495f01736fbbc1b793f71565223aa26f093471a4d8605d198"),
"0x03f89d850120b996ed81f1843b9aca00847735940e8307a12094000000000000000000000000000000000010101001855f495f4955c0847735940ee1a001d552e24560ec2f168be1d4a6385df61c70afe4288f00a3ad172da1a6f2b4f280a0b6690786e5fe79df67dcb60e8a9e8555142c3c96ffd5097c838717f0a7f64129a0112f01ed0cd3b86495f01736fbbc1b793f71565223aa26f093471a4d8605d198"),
createArgument(
"0x03f897850120b996ed80840bebc200843b9aca078303345094c8d369b164361a8961286cfbab3bc10f962185a88080c08411e1a300e1a0011df88a2971c8a7ac494a7ba37ec1acaa1fc1edeeb38c839b5d1693d47b69b080a032f122f06e5802224db4c8a58fd22c75173a713f63f89936f811c144b9e40129a043a2a872cbfa5727007adf6a48febe5f190d2e4cd5ed6122823fb6ff47ecda32"));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,9 @@ private void sendNodeStatsReport() {
final boolean isSyncing = syncState.isInSync();
final long gasPrice = suggestGasPrice(blockchainQueries.getBlockchain().getChainHeadBlock());
final long hashrate = miningCoordinator.hashesPerSecond().orElse(0L);
final int peersNumber = protocolManager.ethContext().getEthPeers().peerCount();
// safe to cast to int since it isn't realistic to have more than max int peers
final int peersNumber =
(int) protocolManager.ethContext().getEthPeers().streamAvailablePeers().count();

final NodeStatsReport nodeStatsReport =
ImmutableNodeStatsReport.builder()
Expand Down

0 comments on commit 84f3dea

Please sign in to comment.