Skip to content

Commit

Permalink
Merge branch 'eip-7516-blob-base-fee' of https://github.com/Gabriel-T…
Browse files Browse the repository at this point in the history
…rintinalia/besu into eip-7516-blob-base-fee
  • Loading branch information
Gabriel-Trintinalia committed Sep 18, 2023
2 parents c8789d5 + b4edbac commit 6c23776
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 5 deletions.
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

0 comments on commit 6c23776

Please sign in to comment.