Move IbftEvents to common (#1698)

Moves IBFT events to the common package for reuse with the QBFT implementation.

This necessitated the creation of BftEventHandler interface, such that a generic IbftController can be passed around, rather than the literal IbftController.

Signed-off-by: Trent Mohay <trent.mohay@consensys.net>
pull/1703/head
Trent Mohay 4 years ago committed by GitHub
parent 4f30b01c0d
commit bdf9408b8d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 5
      besu/src/main/java/org/hyperledger/besu/controller/IbftBesuControllerBuilder.java
  2. 28
      consensus/common/src/main/java/org/hyperledger/besu/consensus/common/bft/EventMultiplexer.java
  3. 2
      consensus/common/src/main/java/org/hyperledger/besu/consensus/common/bft/events/BlockTimerExpiry.java
  4. 2
      consensus/common/src/main/java/org/hyperledger/besu/consensus/common/bft/events/IbftEvent.java
  5. 2
      consensus/common/src/main/java/org/hyperledger/besu/consensus/common/bft/events/IbftEvents.java
  6. 2
      consensus/common/src/main/java/org/hyperledger/besu/consensus/common/bft/events/IbftReceivedMessageEvent.java
  7. 2
      consensus/common/src/main/java/org/hyperledger/besu/consensus/common/bft/events/NewChainHead.java
  8. 2
      consensus/common/src/main/java/org/hyperledger/besu/consensus/common/bft/events/RoundExpiry.java
  9. 33
      consensus/common/src/main/java/org/hyperledger/besu/consensus/common/bft/statemachine/BftEventHandler.java
  10. 10
      consensus/ibft/src/integration-test/java/org/hyperledger/besu/consensus/ibft/support/TestContext.java
  11. 17
      consensus/ibft/src/integration-test/java/org/hyperledger/besu/consensus/ibft/support/TestContextBuilder.java
  12. 4
      consensus/ibft/src/integration-test/java/org/hyperledger/besu/consensus/ibft/support/ValidatorPeer.java
  13. 2
      consensus/ibft/src/integration-test/java/org/hyperledger/besu/consensus/ibft/tests/FutureHeightTest.java
  14. 2
      consensus/ibft/src/integration-test/java/org/hyperledger/besu/consensus/ibft/tests/GossipTest.java
  15. 6
      consensus/ibft/src/integration-test/java/org/hyperledger/besu/consensus/ibft/tests/LocalNodeIsProposerTest.java
  16. 2
      consensus/ibft/src/integration-test/java/org/hyperledger/besu/consensus/ibft/tests/RoundChangeTest.java
  17. 2
      consensus/ibft/src/main/java/org/hyperledger/besu/consensus/ibft/BlockTimer.java
  18. 2
      consensus/ibft/src/main/java/org/hyperledger/besu/consensus/ibft/IbftEventQueue.java
  19. 3
      consensus/ibft/src/main/java/org/hyperledger/besu/consensus/ibft/IbftProcessor.java
  20. 2
      consensus/ibft/src/main/java/org/hyperledger/besu/consensus/ibft/RoundTimer.java
  21. 12
      consensus/ibft/src/main/java/org/hyperledger/besu/consensus/ibft/blockcreation/IbftMiningCoordinator.java
  22. 4
      consensus/ibft/src/main/java/org/hyperledger/besu/consensus/ibft/protocol/IbftProtocolManager.java
  23. 2
      consensus/ibft/src/main/java/org/hyperledger/besu/consensus/ibft/statemachine/BlockHeightManager.java
  24. 2
      consensus/ibft/src/main/java/org/hyperledger/besu/consensus/ibft/statemachine/IbftBlockHeightManager.java
  25. 16
      consensus/ibft/src/main/java/org/hyperledger/besu/consensus/ibft/statemachine/IbftController.java
  26. 2
      consensus/ibft/src/main/java/org/hyperledger/besu/consensus/ibft/statemachine/NoOpBlockHeightManager.java
  27. 4
      consensus/ibft/src/test/java/org/hyperledger/besu/consensus/ibft/BlockTimerTest.java
  28. 4
      consensus/ibft/src/test/java/org/hyperledger/besu/consensus/ibft/IbftEventQueueTest.java
  29. 3
      consensus/ibft/src/test/java/org/hyperledger/besu/consensus/ibft/IbftProcessorTest.java
  30. 2
      consensus/ibft/src/test/java/org/hyperledger/besu/consensus/ibft/RoundTimerTest.java
  31. 6
      consensus/ibft/src/test/java/org/hyperledger/besu/consensus/ibft/blockcreation/IbftMiningCoordinatorTest.java
  32. 2
      consensus/ibft/src/test/java/org/hyperledger/besu/consensus/ibft/statemachine/IbftBlockHeightManagerTest.java
  33. 8
      consensus/ibft/src/test/java/org/hyperledger/besu/consensus/ibft/statemachine/IbftControllerTest.java

@ -24,9 +24,10 @@ import org.hyperledger.besu.consensus.common.IbftValidatorOverrides;
import org.hyperledger.besu.consensus.common.VoteProposer;
import org.hyperledger.besu.consensus.common.VoteTallyCache;
import org.hyperledger.besu.consensus.common.VoteTallyUpdater;
import org.hyperledger.besu.consensus.common.bft.EventMultiplexer;
import org.hyperledger.besu.consensus.common.bft.statemachine.BftEventHandler;
import org.hyperledger.besu.consensus.ibft.BlockTimer;
import org.hyperledger.besu.consensus.ibft.EthSynchronizerUpdater;
import org.hyperledger.besu.consensus.ibft.EventMultiplexer;
import org.hyperledger.besu.consensus.ibft.IbftBlockInterface;
import org.hyperledger.besu.consensus.ibft.IbftContext;
import org.hyperledger.besu.consensus.ibft.IbftEventQueue;
@ -172,7 +173,7 @@ public class IbftBesuControllerBuilder extends BesuControllerBuilder {
final MessageTracker duplicateMessageTracker =
new MessageTracker(ibftConfig.getDuplicateMessageLimit());
final IbftController ibftController =
final BftEventHandler ibftController =
new IbftController(
blockchain,
finalState,

@ -12,14 +12,14 @@
*
* SPDX-License-Identifier: Apache-2.0
*/
package org.hyperledger.besu.consensus.ibft;
package org.hyperledger.besu.consensus.common.bft;
import org.hyperledger.besu.consensus.ibft.ibftevent.BlockTimerExpiry;
import org.hyperledger.besu.consensus.ibft.ibftevent.IbftEvent;
import org.hyperledger.besu.consensus.ibft.ibftevent.IbftReceivedMessageEvent;
import org.hyperledger.besu.consensus.ibft.ibftevent.NewChainHead;
import org.hyperledger.besu.consensus.ibft.ibftevent.RoundExpiry;
import org.hyperledger.besu.consensus.ibft.statemachine.IbftController;
import org.hyperledger.besu.consensus.common.bft.events.BlockTimerExpiry;
import org.hyperledger.besu.consensus.common.bft.events.IbftEvent;
import org.hyperledger.besu.consensus.common.bft.events.IbftReceivedMessageEvent;
import org.hyperledger.besu.consensus.common.bft.events.NewChainHead;
import org.hyperledger.besu.consensus.common.bft.events.RoundExpiry;
import org.hyperledger.besu.consensus.common.bft.statemachine.BftEventHandler;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
@ -28,10 +28,10 @@ public class EventMultiplexer {
private static final Logger LOG = LogManager.getLogger();
private final IbftController ibftController;
private final BftEventHandler eventHandler;
public EventMultiplexer(final IbftController ibftController) {
this.ibftController = ibftController;
public EventMultiplexer(final BftEventHandler eventHandler) {
this.eventHandler = eventHandler;
}
public void handleIbftEvent(final IbftEvent ibftEvent) {
@ -39,19 +39,19 @@ public class EventMultiplexer {
switch (ibftEvent.getType()) {
case MESSAGE:
final IbftReceivedMessageEvent rxEvent = (IbftReceivedMessageEvent) ibftEvent;
ibftController.handleMessageEvent(rxEvent);
eventHandler.handleMessageEvent(rxEvent);
break;
case ROUND_EXPIRY:
final RoundExpiry roundExpiryEvent = (RoundExpiry) ibftEvent;
ibftController.handleRoundExpiry(roundExpiryEvent);
eventHandler.handleRoundExpiry(roundExpiryEvent);
break;
case NEW_CHAIN_HEAD:
final NewChainHead newChainHead = (NewChainHead) ibftEvent;
ibftController.handleNewBlockEvent(newChainHead);
eventHandler.handleNewBlockEvent(newChainHead);
break;
case BLOCK_TIMER_EXPIRY:
final BlockTimerExpiry blockTimerExpiry = (BlockTimerExpiry) ibftEvent;
ibftController.handleBlockTimerExpiry(blockTimerExpiry);
eventHandler.handleBlockTimerExpiry(blockTimerExpiry);
break;
default:
throw new RuntimeException("Illegal event in queue.");

@ -12,7 +12,7 @@
*
* SPDX-License-Identifier: Apache-2.0
*/
package org.hyperledger.besu.consensus.ibft.ibftevent;
package org.hyperledger.besu.consensus.common.bft.events;
import org.hyperledger.besu.consensus.common.bft.ConsensusRoundIdentifier;

@ -12,7 +12,7 @@
*
* SPDX-License-Identifier: Apache-2.0
*/
package org.hyperledger.besu.consensus.ibft.ibftevent;
package org.hyperledger.besu.consensus.common.bft.events;
/** Category of events that will effect and are interpretable by the Ibft processing mechanism */
public interface IbftEvent {

@ -12,7 +12,7 @@
*
* SPDX-License-Identifier: Apache-2.0
*/
package org.hyperledger.besu.consensus.ibft.ibftevent;
package org.hyperledger.besu.consensus.common.bft.events;
import org.hyperledger.besu.ethereum.p2p.rlpx.wire.Message;

@ -12,7 +12,7 @@
*
* SPDX-License-Identifier: Apache-2.0
*/
package org.hyperledger.besu.consensus.ibft.ibftevent;
package org.hyperledger.besu.consensus.common.bft.events;
import org.hyperledger.besu.ethereum.p2p.rlpx.wire.Message;

@ -12,7 +12,7 @@
*
* SPDX-License-Identifier: Apache-2.0
*/
package org.hyperledger.besu.consensus.ibft.ibftevent;
package org.hyperledger.besu.consensus.common.bft.events;
import org.hyperledger.besu.ethereum.core.BlockHeader;

@ -12,7 +12,7 @@
*
* SPDX-License-Identifier: Apache-2.0
*/
package org.hyperledger.besu.consensus.ibft.ibftevent;
package org.hyperledger.besu.consensus.common.bft.events;
import org.hyperledger.besu.consensus.common.bft.ConsensusRoundIdentifier;

@ -0,0 +1,33 @@
/*
* Copyright ConsenSys AG.
*
* 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
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
*
* SPDX-License-Identifier: Apache-2.0
*/
package org.hyperledger.besu.consensus.common.bft.statemachine;
import org.hyperledger.besu.consensus.common.bft.events.BlockTimerExpiry;
import org.hyperledger.besu.consensus.common.bft.events.IbftReceivedMessageEvent;
import org.hyperledger.besu.consensus.common.bft.events.NewChainHead;
import org.hyperledger.besu.consensus.common.bft.events.RoundExpiry;
public interface BftEventHandler {
void start();
void handleMessageEvent(IbftReceivedMessageEvent msg);
void handleNewBlockEvent(NewChainHead newChainHead);
void handleBlockTimerExpiry(BlockTimerExpiry blockTimerExpiry);
void handleRoundExpiry(RoundExpiry roundExpiry);
}

@ -15,10 +15,10 @@
package org.hyperledger.besu.consensus.ibft.support;
import org.hyperledger.besu.consensus.common.bft.ConsensusRoundIdentifier;
import org.hyperledger.besu.consensus.ibft.EventMultiplexer;
import org.hyperledger.besu.consensus.common.bft.EventMultiplexer;
import org.hyperledger.besu.consensus.common.bft.statemachine.BftEventHandler;
import org.hyperledger.besu.consensus.ibft.IbftExecutors;
import org.hyperledger.besu.consensus.ibft.payload.MessageFactory;
import org.hyperledger.besu.consensus.ibft.statemachine.IbftController;
import org.hyperledger.besu.consensus.ibft.statemachine.IbftFinalState;
import org.hyperledger.besu.ethereum.chain.MutableBlockchain;
import org.hyperledger.besu.ethereum.core.Address;
@ -42,7 +42,7 @@ public class TestContext {
private final Map<Address, ValidatorPeer> remotePeers;
private final MutableBlockchain blockchain;
private final IbftExecutors ibftExecutors;
private final IbftController controller;
private final BftEventHandler controller;
private final IbftFinalState finalState;
private final EventMultiplexer eventMultiplexer;
@ -50,7 +50,7 @@ public class TestContext {
final Map<Address, ValidatorPeer> remotePeers,
final MutableBlockchain blockchain,
final IbftExecutors ibftExecutors,
final IbftController controller,
final BftEventHandler controller,
final IbftFinalState finalState,
final EventMultiplexer eventMultiplexer) {
this.remotePeers = remotePeers;
@ -70,7 +70,7 @@ public class TestContext {
return blockchain;
}
public IbftController getController() {
public BftEventHandler getController() {
return controller;
}

@ -25,8 +25,9 @@ import org.hyperledger.besu.consensus.common.EpochManager;
import org.hyperledger.besu.consensus.common.VoteProposer;
import org.hyperledger.besu.consensus.common.VoteTallyCache;
import org.hyperledger.besu.consensus.common.VoteTallyUpdater;
import org.hyperledger.besu.consensus.common.bft.EventMultiplexer;
import org.hyperledger.besu.consensus.common.bft.statemachine.BftEventHandler;
import org.hyperledger.besu.consensus.ibft.BlockTimer;
import org.hyperledger.besu.consensus.ibft.EventMultiplexer;
import org.hyperledger.besu.consensus.ibft.Gossiper;
import org.hyperledger.besu.consensus.ibft.IbftBlockHeaderFunctions;
import org.hyperledger.besu.consensus.ibft.IbftBlockInterface;
@ -94,17 +95,17 @@ public class TestContextBuilder {
private static class ControllerAndState {
private final IbftExecutors ibftExecutors;
private final IbftController controller;
private final BftEventHandler eventHandler;
private final IbftFinalState finalState;
private final EventMultiplexer eventMultiplexer;
public ControllerAndState(
final IbftExecutors ibftExecutors,
final IbftController controller,
final BftEventHandler eventHandler,
final IbftFinalState finalState,
final EventMultiplexer eventMultiplexer) {
this.ibftExecutors = ibftExecutors;
this.controller = controller;
this.eventHandler = eventHandler;
this.finalState = finalState;
this.eventMultiplexer = eventMultiplexer;
}
@ -113,8 +114,8 @@ public class TestContextBuilder {
return ibftExecutors;
}
public IbftController getController() {
return controller;
public BftEventHandler getEventHandler() {
return eventHandler;
}
public IbftFinalState getFinalState() {
@ -219,7 +220,7 @@ public class TestContextBuilder {
remotePeers,
blockChain,
controllerAndState.getIbftExecutors(),
controllerAndState.getController(),
controllerAndState.getEventHandler(),
controllerAndState.getFinalState(),
controllerAndState.getEventMultiplexer());
}
@ -347,7 +348,7 @@ public class TestContextBuilder {
FUTURE_MESSAGES_LIMIT,
blockChain.getChainHeadBlockNumber());
final IbftController ibftController =
final BftEventHandler ibftController =
new IbftController(
blockChain,
finalState,

@ -17,8 +17,8 @@ package org.hyperledger.besu.consensus.ibft.support;
import static org.assertj.core.api.Assertions.assertThat;
import org.hyperledger.besu.consensus.common.bft.ConsensusRoundIdentifier;
import org.hyperledger.besu.consensus.ibft.EventMultiplexer;
import org.hyperledger.besu.consensus.ibft.ibftevent.IbftEvents;
import org.hyperledger.besu.consensus.common.bft.EventMultiplexer;
import org.hyperledger.besu.consensus.common.bft.events.IbftEvents;
import org.hyperledger.besu.consensus.ibft.messagedata.CommitMessageData;
import org.hyperledger.besu.consensus.ibft.messagedata.PrepareMessageData;
import org.hyperledger.besu.consensus.ibft.messagedata.ProposalMessageData;

@ -19,8 +19,8 @@ import static org.assertj.core.util.Lists.emptyList;
import static org.hyperledger.besu.consensus.ibft.support.IntegrationTestHelpers.createSignedCommitPayload;
import org.hyperledger.besu.consensus.common.bft.ConsensusRoundIdentifier;
import org.hyperledger.besu.consensus.common.bft.events.NewChainHead;
import org.hyperledger.besu.consensus.ibft.IbftHelpers;
import org.hyperledger.besu.consensus.ibft.ibftevent.NewChainHead;
import org.hyperledger.besu.consensus.ibft.messagewrappers.Commit;
import org.hyperledger.besu.consensus.ibft.messagewrappers.Prepare;
import org.hyperledger.besu.consensus.ibft.payload.MessageFactory;

@ -18,8 +18,8 @@ import static java.util.Collections.emptyList;
import static java.util.Collections.singletonList;
import org.hyperledger.besu.consensus.common.bft.ConsensusRoundIdentifier;
import org.hyperledger.besu.consensus.common.bft.events.NewChainHead;
import org.hyperledger.besu.consensus.ibft.IbftHelpers;
import org.hyperledger.besu.consensus.ibft.ibftevent.NewChainHead;
import org.hyperledger.besu.consensus.ibft.messagedata.ProposalMessageData;
import org.hyperledger.besu.consensus.ibft.messagewrappers.Commit;
import org.hyperledger.besu.consensus.ibft.messagewrappers.Prepare;

@ -18,9 +18,9 @@ import static org.assertj.core.api.Assertions.assertThat;
import static org.hyperledger.besu.consensus.ibft.support.IntegrationTestHelpers.createSignedCommitPayload;
import org.hyperledger.besu.consensus.common.bft.ConsensusRoundIdentifier;
import org.hyperledger.besu.consensus.ibft.ibftevent.BlockTimerExpiry;
import org.hyperledger.besu.consensus.ibft.ibftevent.NewChainHead;
import org.hyperledger.besu.consensus.ibft.ibftevent.RoundExpiry;
import org.hyperledger.besu.consensus.common.bft.events.BlockTimerExpiry;
import org.hyperledger.besu.consensus.common.bft.events.NewChainHead;
import org.hyperledger.besu.consensus.common.bft.events.RoundExpiry;
import org.hyperledger.besu.consensus.ibft.messagewrappers.Commit;
import org.hyperledger.besu.consensus.ibft.messagewrappers.Proposal;
import org.hyperledger.besu.consensus.ibft.payload.MessageFactory;

@ -19,9 +19,9 @@ import static java.util.Optional.empty;
import static org.hyperledger.besu.consensus.ibft.support.IntegrationTestHelpers.createValidPreparedRoundArtifacts;
import org.hyperledger.besu.consensus.common.bft.ConsensusRoundIdentifier;
import org.hyperledger.besu.consensus.common.bft.events.RoundExpiry;
import org.hyperledger.besu.consensus.common.bft.payload.SignedData;
import org.hyperledger.besu.consensus.ibft.IbftHelpers;
import org.hyperledger.besu.consensus.ibft.ibftevent.RoundExpiry;
import org.hyperledger.besu.consensus.ibft.messagewrappers.Prepare;
import org.hyperledger.besu.consensus.ibft.messagewrappers.Proposal;
import org.hyperledger.besu.consensus.ibft.messagewrappers.RoundChange;

@ -15,7 +15,7 @@
package org.hyperledger.besu.consensus.ibft;
import org.hyperledger.besu.consensus.common.bft.ConsensusRoundIdentifier;
import org.hyperledger.besu.consensus.ibft.ibftevent.BlockTimerExpiry;
import org.hyperledger.besu.consensus.common.bft.events.BlockTimerExpiry;
import org.hyperledger.besu.ethereum.core.BlockHeader;
import java.time.Clock;

@ -14,7 +14,7 @@
*/
package org.hyperledger.besu.consensus.ibft;
import org.hyperledger.besu.consensus.ibft.ibftevent.IbftEvent;
import org.hyperledger.besu.consensus.common.bft.events.IbftEvent;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.LinkedBlockingQueue;

@ -14,7 +14,8 @@
*/
package org.hyperledger.besu.consensus.ibft;
import org.hyperledger.besu.consensus.ibft.ibftevent.IbftEvent;
import org.hyperledger.besu.consensus.common.bft.EventMultiplexer;
import org.hyperledger.besu.consensus.common.bft.events.IbftEvent;
import java.util.Optional;
import java.util.concurrent.CountDownLatch;

@ -15,7 +15,7 @@
package org.hyperledger.besu.consensus.ibft;
import org.hyperledger.besu.consensus.common.bft.ConsensusRoundIdentifier;
import org.hyperledger.besu.consensus.ibft.ibftevent.RoundExpiry;
import org.hyperledger.besu.consensus.common.bft.events.RoundExpiry;
import java.util.Optional;
import java.util.concurrent.ScheduledFuture;

@ -16,11 +16,11 @@ package org.hyperledger.besu.consensus.ibft.blockcreation;
import static org.apache.logging.log4j.LogManager.getLogger;
import org.hyperledger.besu.consensus.common.bft.events.NewChainHead;
import org.hyperledger.besu.consensus.common.bft.statemachine.BftEventHandler;
import org.hyperledger.besu.consensus.ibft.IbftEventQueue;
import org.hyperledger.besu.consensus.ibft.IbftExecutors;
import org.hyperledger.besu.consensus.ibft.IbftProcessor;
import org.hyperledger.besu.consensus.ibft.ibftevent.NewChainHead;
import org.hyperledger.besu.consensus.ibft.statemachine.IbftController;
import org.hyperledger.besu.ethereum.blockcreation.MiningCoordinator;
import org.hyperledger.besu.ethereum.chain.BlockAddedEvent;
import org.hyperledger.besu.ethereum.chain.BlockAddedObserver;
@ -48,7 +48,7 @@ public class IbftMiningCoordinator implements MiningCoordinator, BlockAddedObser
private static final Logger LOG = getLogger();
private final IbftController controller;
private final BftEventHandler eventHandler;
private final IbftProcessor ibftProcessor;
private final IbftBlockCreatorFactory blockCreatorFactory;
protected final Blockchain blockchain;
@ -60,13 +60,13 @@ public class IbftMiningCoordinator implements MiningCoordinator, BlockAddedObser
public IbftMiningCoordinator(
final IbftExecutors ibftExecutors,
final IbftController controller,
final BftEventHandler eventHandler,
final IbftProcessor ibftProcessor,
final IbftBlockCreatorFactory blockCreatorFactory,
final Blockchain blockchain,
final IbftEventQueue eventQueue) {
this.ibftExecutors = ibftExecutors;
this.controller = controller;
this.eventHandler = eventHandler;
this.ibftProcessor = ibftProcessor;
this.blockCreatorFactory = blockCreatorFactory;
this.eventQueue = eventQueue;
@ -79,7 +79,7 @@ public class IbftMiningCoordinator implements MiningCoordinator, BlockAddedObser
if (state.compareAndSet(State.IDLE, State.RUNNING)) {
ibftExecutors.start();
blockAddedObserverId = blockchain.observeBlockAdded(this);
controller.start();
eventHandler.start();
ibftExecutors.executeIbftProcessor(ibftProcessor);
}
}

@ -14,9 +14,9 @@
*/
package org.hyperledger.besu.consensus.ibft.protocol;
import org.hyperledger.besu.consensus.common.bft.events.IbftEvent;
import org.hyperledger.besu.consensus.common.bft.events.IbftEvents;
import org.hyperledger.besu.consensus.ibft.IbftEventQueue;
import org.hyperledger.besu.consensus.ibft.ibftevent.IbftEvent;
import org.hyperledger.besu.consensus.ibft.ibftevent.IbftEvents;
import org.hyperledger.besu.consensus.ibft.network.PeerConnectionTracker;
import org.hyperledger.besu.ethereum.p2p.network.ProtocolManager;
import org.hyperledger.besu.ethereum.p2p.rlpx.connections.PeerConnection;

@ -15,7 +15,7 @@
package org.hyperledger.besu.consensus.ibft.statemachine;
import org.hyperledger.besu.consensus.common.bft.ConsensusRoundIdentifier;
import org.hyperledger.besu.consensus.ibft.ibftevent.RoundExpiry;
import org.hyperledger.besu.consensus.common.bft.events.RoundExpiry;
import org.hyperledger.besu.consensus.ibft.messagewrappers.Commit;
import org.hyperledger.besu.consensus.ibft.messagewrappers.Prepare;
import org.hyperledger.besu.consensus.ibft.messagewrappers.Proposal;

@ -19,10 +19,10 @@ import static org.hyperledger.besu.consensus.ibft.statemachine.IbftBlockHeightMa
import static org.hyperledger.besu.consensus.ibft.statemachine.IbftBlockHeightManager.MessageAge.PRIOR_ROUND;
import org.hyperledger.besu.consensus.common.bft.ConsensusRoundIdentifier;
import org.hyperledger.besu.consensus.common.bft.events.RoundExpiry;
import org.hyperledger.besu.consensus.common.bft.messagewrappers.BftMessage;
import org.hyperledger.besu.consensus.common.bft.payload.Payload;
import org.hyperledger.besu.consensus.ibft.BlockTimer;
import org.hyperledger.besu.consensus.ibft.ibftevent.RoundExpiry;
import org.hyperledger.besu.consensus.ibft.messagewrappers.Commit;
import org.hyperledger.besu.consensus.ibft.messagewrappers.Prepare;
import org.hyperledger.besu.consensus.ibft.messagewrappers.Proposal;

@ -15,15 +15,16 @@
package org.hyperledger.besu.consensus.ibft.statemachine;
import org.hyperledger.besu.consensus.common.bft.ConsensusRoundIdentifier;
import org.hyperledger.besu.consensus.common.bft.events.BlockTimerExpiry;
import org.hyperledger.besu.consensus.common.bft.events.IbftReceivedMessageEvent;
import org.hyperledger.besu.consensus.common.bft.events.NewChainHead;
import org.hyperledger.besu.consensus.common.bft.events.RoundExpiry;
import org.hyperledger.besu.consensus.common.bft.messagewrappers.BftMessage;
import org.hyperledger.besu.consensus.common.bft.payload.Authored;
import org.hyperledger.besu.consensus.common.bft.statemachine.BftEventHandler;
import org.hyperledger.besu.consensus.ibft.Gossiper;
import org.hyperledger.besu.consensus.ibft.MessageTracker;
import org.hyperledger.besu.consensus.ibft.SynchronizerUpdater;
import org.hyperledger.besu.consensus.ibft.ibftevent.BlockTimerExpiry;
import org.hyperledger.besu.consensus.ibft.ibftevent.IbftReceivedMessageEvent;
import org.hyperledger.besu.consensus.ibft.ibftevent.NewChainHead;
import org.hyperledger.besu.consensus.ibft.ibftevent.RoundExpiry;
import org.hyperledger.besu.consensus.ibft.messagedata.CommitMessageData;
import org.hyperledger.besu.consensus.ibft.messagedata.IbftV2;
import org.hyperledger.besu.consensus.ibft.messagedata.PrepareMessageData;
@ -40,7 +41,7 @@ import java.util.function.Consumer;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
public class IbftController {
public class IbftController implements BftEventHandler {
private static final Logger LOG = LogManager.getLogger();
private final Blockchain blockchain;
@ -71,12 +72,14 @@ public class IbftController {
this.sychronizerUpdater = sychronizerUpdater;
}
@Override
public void start() {
if (started.compareAndSet(false, true)) {
startNewHeightManager(blockchain.getChainHeadHeader());
}
}
@Override
public void handleMessageEvent(final IbftReceivedMessageEvent msg) {
final MessageData data = msg.getMessage().getData();
if (!duplicateMessageTracker.hasSeenMessage(data)) {
@ -145,6 +148,7 @@ public class IbftController {
}
}
@Override
public void handleNewBlockEvent(final NewChainHead newChainHead) {
final BlockHeader newBlockHeader = newChainHead.getNewChainHeadHeader();
final BlockHeader currentMiningParent = currentHeightManager.getParentBlockHeader();
@ -177,6 +181,7 @@ public class IbftController {
startNewHeightManager(newBlockHeader);
}
@Override
public void handleBlockTimerExpiry(final BlockTimerExpiry blockTimerExpiry) {
final ConsensusRoundIdentifier roundIndentifier = blockTimerExpiry.getRoundIndentifier();
if (isMsgForCurrentHeight(roundIndentifier)) {
@ -189,6 +194,7 @@ public class IbftController {
}
}
@Override
public void handleRoundExpiry(final RoundExpiry roundExpiry) {
// Discard all messages which target the BLOCKCHAIN height (which SHOULD be 1 less than
// the currentHeightManager, but CAN be the same directly following import).

@ -15,7 +15,7 @@
package org.hyperledger.besu.consensus.ibft.statemachine;
import org.hyperledger.besu.consensus.common.bft.ConsensusRoundIdentifier;
import org.hyperledger.besu.consensus.ibft.ibftevent.RoundExpiry;
import org.hyperledger.besu.consensus.common.bft.events.RoundExpiry;
import org.hyperledger.besu.consensus.ibft.messagewrappers.Commit;
import org.hyperledger.besu.consensus.ibft.messagewrappers.Prepare;
import org.hyperledger.besu.consensus.ibft.messagewrappers.Proposal;

@ -25,8 +25,8 @@ import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import org.hyperledger.besu.consensus.common.bft.ConsensusRoundIdentifier;
import org.hyperledger.besu.consensus.ibft.ibftevent.BlockTimerExpiry;
import org.hyperledger.besu.consensus.ibft.ibftevent.IbftEvent;
import org.hyperledger.besu.consensus.common.bft.events.BlockTimerExpiry;
import org.hyperledger.besu.consensus.common.bft.events.IbftEvent;
import org.hyperledger.besu.ethereum.core.BlockHeader;
import org.hyperledger.besu.ethereum.core.BlockHeaderTestFixture;

@ -17,8 +17,8 @@ package org.hyperledger.besu.consensus.ibft;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatCode;
import org.hyperledger.besu.consensus.ibft.ibftevent.IbftEvent;
import org.hyperledger.besu.consensus.ibft.ibftevent.IbftEvents;
import org.hyperledger.besu.consensus.common.bft.events.IbftEvent;
import org.hyperledger.besu.consensus.common.bft.events.IbftEvents;
import java.util.ArrayList;
import java.util.List;

@ -25,7 +25,8 @@ import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import org.hyperledger.besu.consensus.common.bft.ConsensusRoundIdentifier;
import org.hyperledger.besu.consensus.ibft.ibftevent.RoundExpiry;
import org.hyperledger.besu.consensus.common.bft.EventMultiplexer;
import org.hyperledger.besu.consensus.common.bft.events.RoundExpiry;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

@ -24,7 +24,7 @@ import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import org.hyperledger.besu.consensus.common.bft.ConsensusRoundIdentifier;
import org.hyperledger.besu.consensus.ibft.ibftevent.RoundExpiry;
import org.hyperledger.besu.consensus.common.bft.events.RoundExpiry;
import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.TimeUnit;

@ -19,11 +19,11 @@ import static org.mockito.Mockito.never;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import org.hyperledger.besu.consensus.common.bft.events.NewChainHead;
import org.hyperledger.besu.consensus.common.bft.statemachine.BftEventHandler;
import org.hyperledger.besu.consensus.ibft.IbftEventQueue;
import org.hyperledger.besu.consensus.ibft.IbftExecutors;
import org.hyperledger.besu.consensus.ibft.IbftProcessor;
import org.hyperledger.besu.consensus.ibft.ibftevent.NewChainHead;
import org.hyperledger.besu.consensus.ibft.statemachine.IbftController;
import org.hyperledger.besu.ethereum.chain.BlockAddedEvent;
import org.hyperledger.besu.ethereum.chain.Blockchain;
import org.hyperledger.besu.ethereum.core.Block;
@ -44,7 +44,7 @@ import org.mockito.junit.MockitoJUnitRunner;
@RunWith(MockitoJUnitRunner.class)
public class IbftMiningCoordinatorTest {
@Mock private IbftController controller;
@Mock private BftEventHandler controller;
@Mock private IbftExecutors ibftExecutors;
@Mock private IbftProcessor ibftProcessor;
@Mock private IbftBlockCreatorFactory ibftBlockCreatorFactory;

@ -31,11 +31,11 @@ import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import org.hyperledger.besu.consensus.common.bft.ConsensusRoundIdentifier;
import org.hyperledger.besu.consensus.common.bft.events.RoundExpiry;
import org.hyperledger.besu.consensus.ibft.BlockTimer;
import org.hyperledger.besu.consensus.ibft.IbftExtraData;
import org.hyperledger.besu.consensus.ibft.RoundTimer;
import org.hyperledger.besu.consensus.ibft.blockcreation.IbftBlockCreator;
import org.hyperledger.besu.consensus.ibft.ibftevent.RoundExpiry;
import org.hyperledger.besu.consensus.ibft.messagewrappers.Commit;
import org.hyperledger.besu.consensus.ibft.messagewrappers.Prepare;
import org.hyperledger.besu.consensus.ibft.messagewrappers.Proposal;

@ -27,13 +27,13 @@ import static org.mockito.Mockito.verifyNoMoreInteractions;
import static org.mockito.Mockito.when;
import org.hyperledger.besu.consensus.common.bft.ConsensusRoundIdentifier;
import org.hyperledger.besu.consensus.common.bft.events.BlockTimerExpiry;
import org.hyperledger.besu.consensus.common.bft.events.IbftReceivedMessageEvent;
import org.hyperledger.besu.consensus.common.bft.events.NewChainHead;
import org.hyperledger.besu.consensus.common.bft.events.RoundExpiry;
import org.hyperledger.besu.consensus.ibft.EthSynchronizerUpdater;
import org.hyperledger.besu.consensus.ibft.IbftGossip;
import org.hyperledger.besu.consensus.ibft.MessageTracker;
import org.hyperledger.besu.consensus.ibft.ibftevent.BlockTimerExpiry;
import org.hyperledger.besu.consensus.ibft.ibftevent.IbftReceivedMessageEvent;
import org.hyperledger.besu.consensus.ibft.ibftevent.NewChainHead;
import org.hyperledger.besu.consensus.ibft.ibftevent.RoundExpiry;
import org.hyperledger.besu.consensus.ibft.messagedata.CommitMessageData;
import org.hyperledger.besu.consensus.ibft.messagedata.IbftV2;
import org.hyperledger.besu.consensus.ibft.messagedata.PrepareMessageData;

Loading…
Cancel
Save