File tree Expand file tree Collapse file tree 3 files changed +60
-5
lines changed
besu/src/main/java/org/hyperledger/besu/controller
consensus/common/src/main/java/org/hyperledger/besu/consensus/common/bft/blockcreation Expand file tree Collapse file tree 3 files changed +60
-5
lines changed Original file line number Diff line number Diff line change 7272import org .hyperledger .besu .ethereum .mainnet .ProtocolSchedule ;
7373import org .hyperledger .besu .ethereum .p2p .config .SubProtocolConfiguration ;
7474import org .hyperledger .besu .ethereum .worldstate .WorldStateArchive ;
75+ import org .hyperledger .besu .plugin .services .BesuEvents ;
7576import org .hyperledger .besu .util .Subscribers ;
7677
7778import java .util .HashMap ;
@@ -231,7 +232,30 @@ protected MiningCoordinator createMiningCoordinator(
231232 blockCreatorFactory ,
232233 blockchain ,
233234 bftEventQueue );
234- ibftMiningCoordinator .enable ();
235+
236+ if (syncState .isInitialSyncPhaseDone ()) {
237+ LOG .info ("Starting IBFT mining coordinator" );
238+ ibftMiningCoordinator .enable ();
239+ ibftMiningCoordinator .start ();
240+ } else {
241+ LOG .info ("IBFT mining coordinator not starting while initial sync in progress" );
242+ }
243+
244+ syncState .subscribeCompletionReached (
245+ new BesuEvents .InitialSyncCompletionListener () {
246+ @ Override
247+ public void onInitialSyncCompleted () {
248+ LOG .info ("Starting IBFT mining coordinator following initial sync" );
249+ ibftMiningCoordinator .enable ();
250+ ibftMiningCoordinator .start ();
251+ }
252+
253+ @ Override
254+ public void onInitialSyncRestart () {
255+ // Nothing to do. The mining coordinator won't be started until
256+ // sync has completed.
257+ }
258+ });
235259
236260 return ibftMiningCoordinator ;
237261 }
Original file line number Diff line number Diff line change 8282import org .hyperledger .besu .ethereum .p2p .config .SubProtocolConfiguration ;
8383import org .hyperledger .besu .ethereum .transaction .TransactionSimulator ;
8484import org .hyperledger .besu .ethereum .worldstate .WorldStateArchive ;
85+ import org .hyperledger .besu .plugin .services .BesuEvents ;
8586import org .hyperledger .besu .util .Subscribers ;
8687
8788import java .util .HashMap ;
@@ -271,7 +272,30 @@ protected MiningCoordinator createMiningCoordinator(
271272 blockCreatorFactory ,
272273 blockchain ,
273274 bftEventQueue );
274- miningCoordinator .enable ();
275+
276+ if (syncState .isInitialSyncPhaseDone ()) {
277+ LOG .info ("Starting QBFT mining coordinator" );
278+ miningCoordinator .enable ();
279+ miningCoordinator .start ();
280+ } else {
281+ LOG .info ("QBFT mining coordinator not starting while initial sync in progress" );
282+ }
283+
284+ syncState .subscribeCompletionReached (
285+ new BesuEvents .InitialSyncCompletionListener () {
286+ @ Override
287+ public void onInitialSyncCompleted () {
288+ LOG .info ("Starting QBFT mining coordinator following initial sync" );
289+ miningCoordinator .enable ();
290+ miningCoordinator .start ();
291+ }
292+
293+ @ Override
294+ public void onInitialSyncRestart () {
295+ // Nothing to do. The mining coordinator won't be started until
296+ // sync has completed.
297+ }
298+ });
275299
276300 return miningCoordinator ;
277301 }
Original file line number Diff line number Diff line change @@ -46,7 +46,9 @@ private enum State {
4646 /** Running state. */
4747 RUNNING ,
4848 /** Stopped state. */
49- STOPPED
49+ STOPPED ,
50+ /** Paused state. */
51+ PAUSED ,
5052 }
5153
5254 private static final Logger LOG = LoggerFactory .getLogger (BftMiningCoordinator .class );
@@ -61,7 +63,7 @@ private enum State {
6163 private final BftExecutors bftExecutors ;
6264
6365 private long blockAddedObserverId ;
64- private final AtomicReference <State > state = new AtomicReference <>(State .IDLE );
66+ private final AtomicReference <State > state = new AtomicReference <>(State .PAUSED );
6567
6668 /**
6769 * Instantiates a new Bft mining coordinator.
@@ -122,7 +124,12 @@ public void awaitStop() throws InterruptedException {
122124
123125 @ Override
124126 public boolean enable () {
125- return true ;
127+ // Return true if we're already running, or successfully switch to running
128+ if (state .get () == State .RUNNING
129+ || state .compareAndSet (State .PAUSED , State .IDLE )) {
130+ return true ;
131+ }
132+ return false ;
126133 }
127134
128135 @ Override
You can’t perform that action at this time.
0 commit comments