Search in sources :

Example 1 with UniqueMessageMulticaster

use of org.hyperledger.besu.consensus.common.bft.UniqueMessageMulticaster in project besu by hyperledger.

the class QbftBesuControllerBuilder method createMiningCoordinator.

@Override
protected MiningCoordinator createMiningCoordinator(final ProtocolSchedule protocolSchedule, final ProtocolContext protocolContext, final TransactionPool transactionPool, final MiningParameters miningParameters, final SyncState syncState, final EthProtocolManager ethProtocolManager) {
    final MutableBlockchain blockchain = protocolContext.getBlockchain();
    final BftExecutors bftExecutors = BftExecutors.create(metricsSystem, BftExecutors.ConsensusType.QBFT);
    final Address localAddress = Util.publicKeyToAddress(nodeKey.getPublicKey());
    final BftBlockCreatorFactory<?> blockCreatorFactory = new QbftBlockCreatorFactory(transactionPool.getPendingTransactions(), protocolContext, protocolSchedule, qbftForksSchedule, miningParameters, localAddress, bftExtraDataCodec().get());
    final ValidatorProvider validatorProvider = protocolContext.getConsensusContext(BftContext.class).getValidatorProvider();
    final ProposerSelector proposerSelector = new ProposerSelector(blockchain, bftBlockInterface().get(), true, validatorProvider);
    // NOTE: peers should not be used for accessing the network as it does not enforce the
    // "only send once" filter applied by the UniqueMessageMulticaster.
    peers = new ValidatorPeers(validatorProvider, Istanbul100SubProtocol.NAME);
    final UniqueMessageMulticaster uniqueMessageMulticaster = new UniqueMessageMulticaster(peers, qbftConfig.getGossipedHistoryLimit());
    final QbftGossip gossiper = new QbftGossip(uniqueMessageMulticaster, bftExtraDataCodec().get());
    final BftFinalState finalState = new BftFinalState(validatorProvider, nodeKey, Util.publicKeyToAddress(nodeKey.getPublicKey()), proposerSelector, uniqueMessageMulticaster, new RoundTimer(bftEventQueue, qbftConfig.getRequestTimeoutSeconds(), bftExecutors), new BlockTimer(bftEventQueue, qbftForksSchedule, bftExecutors, clock), blockCreatorFactory, clock);
    final MessageValidatorFactory messageValidatorFactory = new MessageValidatorFactory(proposerSelector, protocolSchedule, protocolContext, bftExtraDataCodec().get());
    final Subscribers<MinedBlockObserver> minedBlockObservers = Subscribers.create();
    minedBlockObservers.subscribe(ethProtocolManager);
    minedBlockObservers.subscribe(blockLogger(transactionPool, localAddress));
    final FutureMessageBuffer futureMessageBuffer = new FutureMessageBuffer(qbftConfig.getFutureMessagesMaxDistance(), qbftConfig.getFutureMessagesLimit(), blockchain.getChainHeadBlockNumber());
    final MessageTracker duplicateMessageTracker = new MessageTracker(qbftConfig.getDuplicateMessageLimit());
    final MessageFactory messageFactory = new MessageFactory(nodeKey);
    final BftEventHandler qbftController = new QbftController(blockchain, finalState, new QbftBlockHeightManagerFactory(finalState, new QbftRoundFactory(finalState, protocolContext, protocolSchedule, minedBlockObservers, messageValidatorFactory, messageFactory, bftExtraDataCodec().get()), messageValidatorFactory, messageFactory, new ValidatorModeTransitionLogger(qbftForksSchedule)), gossiper, duplicateMessageTracker, futureMessageBuffer, new EthSynchronizerUpdater(ethProtocolManager.ethContext().getEthPeers()), bftExtraDataCodec().get());
    final EventMultiplexer eventMultiplexer = new EventMultiplexer(qbftController);
    final BftProcessor bftProcessor = new BftProcessor(bftEventQueue, eventMultiplexer);
    final MiningCoordinator miningCoordinator = new BftMiningCoordinator(bftExecutors, qbftController, bftProcessor, blockCreatorFactory, blockchain, bftEventQueue);
    miningCoordinator.enable();
    return miningCoordinator;
}
Also used : ValidatorPeers(org.hyperledger.besu.consensus.common.bft.network.ValidatorPeers) MinedBlockObserver(org.hyperledger.besu.ethereum.chain.MinedBlockObserver) EthSynchronizerUpdater(org.hyperledger.besu.consensus.common.bft.EthSynchronizerUpdater) Address(org.hyperledger.besu.datatypes.Address) ValidatorModeTransitionLogger(org.hyperledger.besu.consensus.qbft.validator.ValidatorModeTransitionLogger) BftProcessor(org.hyperledger.besu.consensus.common.bft.BftProcessor) RoundTimer(org.hyperledger.besu.consensus.common.bft.RoundTimer) BftEventHandler(org.hyperledger.besu.consensus.common.bft.statemachine.BftEventHandler) QbftBlockCreatorFactory(org.hyperledger.besu.consensus.qbft.blockcreation.QbftBlockCreatorFactory) EventMultiplexer(org.hyperledger.besu.consensus.common.bft.EventMultiplexer) BftFinalState(org.hyperledger.besu.consensus.common.bft.statemachine.BftFinalState) ProposerSelector(org.hyperledger.besu.consensus.common.bft.blockcreation.ProposerSelector) UniqueMessageMulticaster(org.hyperledger.besu.consensus.common.bft.UniqueMessageMulticaster) BftExecutors(org.hyperledger.besu.consensus.common.bft.BftExecutors) BlockValidatorProvider(org.hyperledger.besu.consensus.common.validator.blockbased.BlockValidatorProvider) TransactionValidatorProvider(org.hyperledger.besu.consensus.qbft.validator.TransactionValidatorProvider) ValidatorProvider(org.hyperledger.besu.consensus.common.validator.ValidatorProvider) ForkingValidatorProvider(org.hyperledger.besu.consensus.qbft.validator.ForkingValidatorProvider) MiningCoordinator(org.hyperledger.besu.ethereum.blockcreation.MiningCoordinator) BftMiningCoordinator(org.hyperledger.besu.consensus.common.bft.blockcreation.BftMiningCoordinator) BftContext(org.hyperledger.besu.consensus.common.bft.BftContext) MessageFactory(org.hyperledger.besu.consensus.qbft.payload.MessageFactory) MessageValidatorFactory(org.hyperledger.besu.consensus.qbft.validation.MessageValidatorFactory) MessageTracker(org.hyperledger.besu.consensus.common.bft.MessageTracker) QbftBlockHeightManagerFactory(org.hyperledger.besu.consensus.qbft.statemachine.QbftBlockHeightManagerFactory) QbftController(org.hyperledger.besu.consensus.qbft.statemachine.QbftController) BftMiningCoordinator(org.hyperledger.besu.consensus.common.bft.blockcreation.BftMiningCoordinator) FutureMessageBuffer(org.hyperledger.besu.consensus.common.bft.statemachine.FutureMessageBuffer) BlockTimer(org.hyperledger.besu.consensus.common.bft.BlockTimer) MutableBlockchain(org.hyperledger.besu.ethereum.chain.MutableBlockchain) QbftGossip(org.hyperledger.besu.consensus.qbft.QbftGossip) QbftRoundFactory(org.hyperledger.besu.consensus.qbft.statemachine.QbftRoundFactory)

Example 2 with UniqueMessageMulticaster

use of org.hyperledger.besu.consensus.common.bft.UniqueMessageMulticaster in project besu by hyperledger.

the class TestContextBuilder method build.

public TestContext build() {
    final NetworkLayout networkNodes = NetworkLayout.createNetworkLayout(validatorCount, indexOfFirstLocallyProposedBlock);
    final Block genesisBlock = createGenesisBlock(networkNodes.getValidatorAddresses());
    final MutableBlockchain blockChain = createInMemoryBlockchain(genesisBlock, BftBlockHeaderFunctions.forOnchainBlock(IBFT_EXTRA_DATA_ENCODER));
    // Use a stubbed version of the multicaster, to prevent creating PeerConnections etc.
    final StubValidatorMulticaster multicaster = new StubValidatorMulticaster();
    final UniqueMessageMulticaster uniqueMulticaster = new UniqueMessageMulticaster(multicaster, GOSSIPED_HISTORY_LIMIT);
    final Gossiper gossiper = useGossip ? new IbftGossip(uniqueMulticaster) : mock(Gossiper.class);
    final StubbedSynchronizerUpdater synchronizerUpdater = new StubbedSynchronizerUpdater();
    final ControllerAndState controllerAndState = createControllerAndFinalState(blockChain, multicaster, networkNodes.getLocalNode().getNodeKey(), clock, bftEventQueue, gossiper, synchronizerUpdater, bftForks);
    // Add each networkNode to the Multicaster (such that each can receive msgs from local node).
    // NOTE: the remotePeers needs to be ordered based on Address (as this is used to determine
    // the proposer order which must be managed in test).
    final Map<Address, ValidatorPeer> remotePeers = networkNodes.getRemotePeers().stream().collect(Collectors.toMap(NodeParams::getAddress, nodeParams -> new ValidatorPeer(nodeParams, new MessageFactory(nodeParams.getNodeKey()), controllerAndState.getEventMultiplexer()), (u, v) -> {
        throw new IllegalStateException(String.format("Duplicate key %s", u));
    }, LinkedHashMap::new));
    final List<DefaultValidatorPeer> peerCollection = new ArrayList<>(remotePeers.values());
    multicaster.addNetworkPeers(peerCollection);
    synchronizerUpdater.addNetworkPeers(peerCollection);
    return new TestContext(remotePeers, blockChain, controllerAndState.getIbftExecutors(), controllerAndState.getEventHandler(), controllerAndState.getFinalState(), controllerAndState.getEventMultiplexer(), controllerAndState.getMessageFactory());
}
Also used : BftFinalState(org.hyperledger.besu.consensus.common.bft.statemachine.BftFinalState) BftEventQueue(org.hyperledger.besu.consensus.common.bft.BftEventQueue) Subscribers(org.hyperledger.besu.util.Subscribers) BftBlockHeaderFunctions(org.hyperledger.besu.consensus.common.bft.BftBlockHeaderFunctions) InMemoryKeyValueStorageProvider.createInMemoryWorldStateArchive(org.hyperledger.besu.ethereum.core.InMemoryKeyValueStorageProvider.createInMemoryWorldStateArchive) IbftBlockHeightManagerFactory(org.hyperledger.besu.consensus.ibft.statemachine.IbftBlockHeightManagerFactory) BftContext(org.hyperledger.besu.consensus.common.bft.BftContext) StubbedSynchronizerUpdater(org.hyperledger.besu.consensus.common.bft.inttest.StubbedSynchronizerUpdater) ProposerSelector(org.hyperledger.besu.consensus.common.bft.blockcreation.ProposerSelector) UniqueMessageMulticaster(org.hyperledger.besu.consensus.common.bft.UniqueMessageMulticaster) MessageValidatorFactory(org.hyperledger.besu.consensus.ibft.validation.MessageValidatorFactory) Map(java.util.Map) BlockTimer(org.hyperledger.besu.consensus.common.bft.BlockTimer) Block(org.hyperledger.besu.ethereum.core.Block) BftFork(org.hyperledger.besu.config.BftFork) GasPricePendingTransactionsSorter(org.hyperledger.besu.ethereum.eth.transactions.sorter.GasPricePendingTransactionsSorter) RoundTimer(org.hyperledger.besu.consensus.common.bft.RoundTimer) Difficulty(org.hyperledger.besu.ethereum.core.Difficulty) BftEventHandler(org.hyperledger.besu.consensus.common.bft.statemachine.BftEventHandler) MessageTracker(org.hyperledger.besu.consensus.common.bft.MessageTracker) Set(java.util.Set) Instant(java.time.Instant) EventMultiplexer(org.hyperledger.besu.consensus.common.bft.EventMultiplexer) BlockValidatorProvider(org.hyperledger.besu.consensus.common.validator.blockbased.BlockValidatorProvider) MiningParameters(org.hyperledger.besu.ethereum.core.MiningParameters) EvmConfiguration(org.hyperledger.besu.evm.internal.EvmConfiguration) Collectors(java.util.stream.Collectors) ZoneId(java.time.ZoneId) IbftController(org.hyperledger.besu.consensus.ibft.statemachine.IbftController) BftExecutors(org.hyperledger.besu.consensus.common.bft.BftExecutors) List(java.util.List) TransactionPoolConfiguration(org.hyperledger.besu.ethereum.eth.transactions.TransactionPoolConfiguration) NodeParams(org.hyperledger.besu.consensus.common.bft.inttest.NodeParams) ValidatorProvider(org.hyperledger.besu.consensus.common.validator.ValidatorProvider) Optional(java.util.Optional) MetricsSystem(org.hyperledger.besu.plugin.services.MetricsSystem) MutableBlockchain(org.hyperledger.besu.ethereum.chain.MutableBlockchain) Mockito.mock(org.mockito.Mockito.mock) NodeKey(org.hyperledger.besu.crypto.NodeKey) Hash(org.hyperledger.besu.datatypes.Hash) MinedBlockObserver(org.hyperledger.besu.ethereum.chain.MinedBlockObserver) IbftProtocolSchedule(org.hyperledger.besu.consensus.ibft.IbftProtocolSchedule) Iterables(com.google.common.collect.Iterables) DefaultValidatorPeer(org.hyperledger.besu.consensus.common.bft.inttest.DefaultValidatorPeer) BftBlockCreatorFactory(org.hyperledger.besu.consensus.common.bft.blockcreation.BftBlockCreatorFactory) IbftRoundFactory(org.hyperledger.besu.consensus.ibft.statemachine.IbftRoundFactory) NoOpMetricsSystem(org.hyperledger.besu.metrics.noop.NoOpMetricsSystem) Bytes(org.apache.tuweni.bytes.Bytes) Address(org.hyperledger.besu.datatypes.Address) Util(org.hyperledger.besu.ethereum.core.Util) ArrayList(java.util.ArrayList) ProtocolSchedule(org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule) LinkedHashMap(java.util.LinkedHashMap) InMemoryKeyValueStorageProvider.createInMemoryBlockchain(org.hyperledger.besu.ethereum.core.InMemoryKeyValueStorageProvider.createInMemoryBlockchain) FutureMessageBuffer(org.hyperledger.besu.consensus.common.bft.statemachine.FutureMessageBuffer) ForksSchedule(org.hyperledger.besu.consensus.common.ForksSchedule) NetworkLayout(org.hyperledger.besu.consensus.common.bft.inttest.NetworkLayout) IbftGossip(org.hyperledger.besu.consensus.ibft.IbftGossip) MessageFactory(org.hyperledger.besu.consensus.ibft.payload.MessageFactory) WorldStateArchive(org.hyperledger.besu.ethereum.worldstate.WorldStateArchive) BftBlockInterface(org.hyperledger.besu.consensus.common.bft.BftBlockInterface) Wei(org.hyperledger.besu.datatypes.Wei) EpochManager(org.hyperledger.besu.consensus.common.EpochManager) BftExtraData(org.hyperledger.besu.consensus.common.bft.BftExtraData) UTF_8(java.nio.charset.StandardCharsets.UTF_8) BlockHeader(org.hyperledger.besu.ethereum.core.BlockHeader) StubValidatorMulticaster(org.hyperledger.besu.consensus.common.bft.inttest.StubValidatorMulticaster) IbftForksSchedulesFactory(org.hyperledger.besu.consensus.ibft.IbftForksSchedulesFactory) StubGenesisConfigOptions(org.hyperledger.besu.config.StubGenesisConfigOptions) AddressHelpers(org.hyperledger.besu.ethereum.core.AddressHelpers) TestTransitions(org.hyperledger.besu.consensus.common.bft.inttest.TestTransitions) BlockHeaderTestFixture(org.hyperledger.besu.ethereum.core.BlockHeaderTestFixture) Gossiper(org.hyperledger.besu.consensus.common.bft.Gossiper) IbftExtraDataCodec(org.hyperledger.besu.consensus.ibft.IbftExtraDataCodec) BftConfigOptions(org.hyperledger.besu.config.BftConfigOptions) ProtocolContext(org.hyperledger.besu.ethereum.ProtocolContext) BlockBody(org.hyperledger.besu.ethereum.core.BlockBody) Clock(java.time.Clock) BftHelpers(org.hyperledger.besu.consensus.common.bft.BftHelpers) SynchronizerUpdater(org.hyperledger.besu.consensus.common.bft.SynchronizerUpdater) Collections(java.util.Collections) TestClock(org.hyperledger.besu.testutil.TestClock) StubValidatorMulticaster(org.hyperledger.besu.consensus.common.bft.inttest.StubValidatorMulticaster) DefaultValidatorPeer(org.hyperledger.besu.consensus.common.bft.inttest.DefaultValidatorPeer) Address(org.hyperledger.besu.datatypes.Address) MessageFactory(org.hyperledger.besu.consensus.ibft.payload.MessageFactory) ArrayList(java.util.ArrayList) NetworkLayout(org.hyperledger.besu.consensus.common.bft.inttest.NetworkLayout) UniqueMessageMulticaster(org.hyperledger.besu.consensus.common.bft.UniqueMessageMulticaster) DefaultValidatorPeer(org.hyperledger.besu.consensus.common.bft.inttest.DefaultValidatorPeer) Gossiper(org.hyperledger.besu.consensus.common.bft.Gossiper) StubbedSynchronizerUpdater(org.hyperledger.besu.consensus.common.bft.inttest.StubbedSynchronizerUpdater) Block(org.hyperledger.besu.ethereum.core.Block) MutableBlockchain(org.hyperledger.besu.ethereum.chain.MutableBlockchain) IbftGossip(org.hyperledger.besu.consensus.ibft.IbftGossip)

Example 3 with UniqueMessageMulticaster

use of org.hyperledger.besu.consensus.common.bft.UniqueMessageMulticaster in project besu by hyperledger.

the class TestContextBuilder method build.

public TestContext build() {
    final NetworkLayout networkNodes;
    if (nodeParams.isEmpty()) {
        networkNodes = NetworkLayout.createNetworkLayout(validatorCount, indexOfFirstLocallyProposedBlock);
    } else {
        final TreeMap<Address, NodeParams> addressKeyMap = new TreeMap<>();
        for (NodeParams params : nodeParams) {
            addressKeyMap.put(params.getAddress(), params);
        }
        final NodeParams localNode = Iterables.get(addressKeyMap.values(), indexOfFirstLocallyProposedBlock);
        networkNodes = new NetworkLayout(localNode, addressKeyMap);
    }
    final MutableBlockchain blockChain;
    final DefaultWorldStateArchive worldStateArchive = createInMemoryWorldStateArchive();
    if (genesisFile.isPresent()) {
        try {
            final GenesisState genesisState = createGenesisBlock(genesisFile.get());
            blockChain = createInMemoryBlockchain(genesisState.getBlock(), BftBlockHeaderFunctions.forOnchainBlock(BFT_EXTRA_DATA_ENCODER));
            genesisState.writeStateTo(worldStateArchive.getMutable());
        } catch (IOException e) {
            throw new IllegalStateException(e);
        }
    } else {
        final Block genesisBlock = createGenesisBlock(networkNodes.getValidatorAddresses());
        blockChain = createInMemoryBlockchain(genesisBlock, BftBlockHeaderFunctions.forOnchainBlock(BFT_EXTRA_DATA_ENCODER));
    }
    // Use a stubbed version of the multicaster, to prevent creating PeerConnections etc.
    final StubValidatorMulticaster multicaster = new StubValidatorMulticaster();
    final UniqueMessageMulticaster uniqueMulticaster = new UniqueMessageMulticaster(multicaster, GOSSIPED_HISTORY_LIMIT);
    final Gossiper gossiper = useGossip ? new QbftGossip(uniqueMulticaster, BFT_EXTRA_DATA_ENCODER) : mock(Gossiper.class);
    final StubbedSynchronizerUpdater synchronizerUpdater = new StubbedSynchronizerUpdater();
    final ControllerAndState controllerAndState = createControllerAndFinalState(blockChain, worldStateArchive, multicaster, networkNodes.getLocalNode().getNodeKey(), clock, bftEventQueue, gossiper, synchronizerUpdater, useValidatorContract, qbftForks);
    // Add each networkNode to the Multicaster (such that each can receive msgs from local node).
    // NOTE: the remotePeers needs to be ordered based on Address (as this is used to determine
    // the proposer order which must be managed in test).
    final Map<Address, ValidatorPeer> remotePeers = networkNodes.getRemotePeers().stream().collect(Collectors.toMap(NodeParams::getAddress, nodeParams -> new ValidatorPeer(nodeParams, new MessageFactory(nodeParams.getNodeKey()), controllerAndState.getEventMultiplexer()), (u, v) -> {
        throw new IllegalStateException(String.format("Duplicate key %s", u));
    }, LinkedHashMap::new));
    final List<DefaultValidatorPeer> peerCollection = new ArrayList<>(remotePeers.values());
    multicaster.addNetworkPeers(peerCollection);
    synchronizerUpdater.addNetworkPeers(peerCollection);
    return new TestContext(remotePeers, blockChain, controllerAndState.getBftExecutors(), controllerAndState.getEventHandler(), controllerAndState.getFinalState(), controllerAndState.getEventMultiplexer(), controllerAndState.getMessageFactory(), controllerAndState.getValidatorProvider(), BFT_EXTRA_DATA_ENCODER);
}
Also used : BftFinalState(org.hyperledger.besu.consensus.common.bft.statemachine.BftFinalState) QbftFork(org.hyperledger.besu.config.QbftFork) GenesisState(org.hyperledger.besu.ethereum.chain.GenesisState) Subscribers(org.hyperledger.besu.util.Subscribers) BftBlockHeaderFunctions(org.hyperledger.besu.consensus.common.bft.BftBlockHeaderFunctions) BftContext(org.hyperledger.besu.consensus.common.bft.BftContext) ProposerSelector(org.hyperledger.besu.consensus.common.bft.blockcreation.ProposerSelector) UniqueMessageMulticaster(org.hyperledger.besu.consensus.common.bft.UniqueMessageMulticaster) MessageValidatorFactory(org.hyperledger.besu.consensus.qbft.validation.MessageValidatorFactory) Map(java.util.Map) BlockTimer(org.hyperledger.besu.consensus.common.bft.BlockTimer) Block(org.hyperledger.besu.ethereum.core.Block) BftExtraDataCodec(org.hyperledger.besu.consensus.common.bft.BftExtraDataCodec) GasPricePendingTransactionsSorter(org.hyperledger.besu.ethereum.eth.transactions.sorter.GasPricePendingTransactionsSorter) Path(java.nio.file.Path) RoundTimer(org.hyperledger.besu.consensus.common.bft.RoundTimer) Difficulty(org.hyperledger.besu.ethereum.core.Difficulty) BftEventHandler(org.hyperledger.besu.consensus.common.bft.statemachine.BftEventHandler) QbftRoundFactory(org.hyperledger.besu.consensus.qbft.statemachine.QbftRoundFactory) Set(java.util.Set) JsonUtil(org.hyperledger.besu.config.JsonUtil) EventMultiplexer(org.hyperledger.besu.consensus.common.bft.EventMultiplexer) EvmConfiguration(org.hyperledger.besu.evm.internal.EvmConfiguration) ZoneId(java.time.ZoneId) BftExecutors(org.hyperledger.besu.consensus.common.bft.BftExecutors) TransactionPoolConfiguration(org.hyperledger.besu.ethereum.eth.transactions.TransactionPoolConfiguration) NodeParams(org.hyperledger.besu.consensus.common.bft.inttest.NodeParams) MessageFactory(org.hyperledger.besu.consensus.qbft.payload.MessageFactory) ProtocolScheduleFixture(org.hyperledger.besu.ethereum.core.ProtocolScheduleFixture) ValidatorContractController(org.hyperledger.besu.consensus.qbft.validator.ValidatorContractController) ForkingValidatorProvider(org.hyperledger.besu.consensus.qbft.validator.ForkingValidatorProvider) DefaultWorldStateArchive(org.hyperledger.besu.ethereum.worldstate.DefaultWorldStateArchive) Mockito.mock(org.mockito.Mockito.mock) Hash(org.hyperledger.besu.datatypes.Hash) MinedBlockObserver(org.hyperledger.besu.ethereum.chain.MinedBlockObserver) Iterables(com.google.common.collect.Iterables) BftValidatorOverrides(org.hyperledger.besu.consensus.common.BftValidatorOverrides) DefaultValidatorPeer(org.hyperledger.besu.consensus.common.bft.inttest.DefaultValidatorPeer) BftBlockCreatorFactory(org.hyperledger.besu.consensus.common.bft.blockcreation.BftBlockCreatorFactory) Bytes(org.apache.tuweni.bytes.Bytes) ArrayList(java.util.ArrayList) QbftController(org.hyperledger.besu.consensus.qbft.statemachine.QbftController) ProtocolSchedule(org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule) LinkedHashMap(java.util.LinkedHashMap) FutureMessageBuffer(org.hyperledger.besu.consensus.common.bft.statemachine.FutureMessageBuffer) QbftProtocolSchedule(org.hyperledger.besu.consensus.qbft.QbftProtocolSchedule) ForksSchedule(org.hyperledger.besu.consensus.common.ForksSchedule) NetworkLayout(org.hyperledger.besu.consensus.common.bft.inttest.NetworkLayout) BftBlockInterface(org.hyperledger.besu.consensus.common.bft.BftBlockInterface) Wei(org.hyperledger.besu.datatypes.Wei) TransactionSimulator(org.hyperledger.besu.ethereum.transaction.TransactionSimulator) QbftContext(org.hyperledger.besu.consensus.qbft.QbftContext) Files(java.nio.file.Files) BlockHeader(org.hyperledger.besu.ethereum.core.BlockHeader) AddressHelpers(org.hyperledger.besu.ethereum.core.AddressHelpers) IOException(java.io.IOException) MutableQbftConfigOptions(org.hyperledger.besu.consensus.qbft.MutableQbftConfigOptions) ValidatorModeTransitionLogger(org.hyperledger.besu.consensus.qbft.validator.ValidatorModeTransitionLogger) TestTransitions(org.hyperledger.besu.consensus.common.bft.inttest.TestTransitions) QbftExtraDataCodec(org.hyperledger.besu.consensus.qbft.QbftExtraDataCodec) QbftBlockCreatorFactory(org.hyperledger.besu.consensus.qbft.blockcreation.QbftBlockCreatorFactory) TreeMap(java.util.TreeMap) BlockBody(org.hyperledger.besu.ethereum.core.BlockBody) SynchronizerUpdater(org.hyperledger.besu.consensus.common.bft.SynchronizerUpdater) QbftGossip(org.hyperledger.besu.consensus.qbft.QbftGossip) TestClock(org.hyperledger.besu.testutil.TestClock) BftEventQueue(org.hyperledger.besu.consensus.common.bft.BftEventQueue) InMemoryKeyValueStorageProvider.createInMemoryWorldStateArchive(org.hyperledger.besu.ethereum.core.InMemoryKeyValueStorageProvider.createInMemoryWorldStateArchive) StubbedSynchronizerUpdater(org.hyperledger.besu.consensus.common.bft.inttest.StubbedSynchronizerUpdater) BftFork(org.hyperledger.besu.config.BftFork) MessageTracker(org.hyperledger.besu.consensus.common.bft.MessageTracker) Instant(java.time.Instant) QbftConfigOptions(org.hyperledger.besu.config.QbftConfigOptions) BlockValidatorProvider(org.hyperledger.besu.consensus.common.validator.blockbased.BlockValidatorProvider) MiningParameters(org.hyperledger.besu.ethereum.core.MiningParameters) Collectors(java.util.stream.Collectors) JsonQbftConfigOptions(org.hyperledger.besu.config.JsonQbftConfigOptions) List(java.util.List) TransactionValidatorProvider(org.hyperledger.besu.consensus.qbft.validator.TransactionValidatorProvider) ValidatorProvider(org.hyperledger.besu.consensus.common.validator.ValidatorProvider) Optional(java.util.Optional) MetricsSystem(org.hyperledger.besu.plugin.services.MetricsSystem) MutableBlockchain(org.hyperledger.besu.ethereum.chain.MutableBlockchain) NodeKey(org.hyperledger.besu.crypto.NodeKey) HashMap(java.util.HashMap) NoOpMetricsSystem(org.hyperledger.besu.metrics.noop.NoOpMetricsSystem) Address(org.hyperledger.besu.datatypes.Address) Util(org.hyperledger.besu.ethereum.core.Util) InMemoryKeyValueStorageProvider.createInMemoryBlockchain(org.hyperledger.besu.ethereum.core.InMemoryKeyValueStorageProvider.createInMemoryBlockchain) WorldStateArchive(org.hyperledger.besu.ethereum.worldstate.WorldStateArchive) QbftForksSchedulesFactory(org.hyperledger.besu.consensus.qbft.QbftForksSchedulesFactory) EpochManager(org.hyperledger.besu.consensus.common.EpochManager) BftExtraData(org.hyperledger.besu.consensus.common.bft.BftExtraData) UTF_8(java.nio.charset.StandardCharsets.UTF_8) StubValidatorMulticaster(org.hyperledger.besu.consensus.common.bft.inttest.StubValidatorMulticaster) StubGenesisConfigOptions(org.hyperledger.besu.config.StubGenesisConfigOptions) BlockHeaderTestFixture(org.hyperledger.besu.ethereum.core.BlockHeaderTestFixture) Gossiper(org.hyperledger.besu.consensus.common.bft.Gossiper) QbftBlockHeightManagerFactory(org.hyperledger.besu.consensus.qbft.statemachine.QbftBlockHeightManagerFactory) ProtocolContext(org.hyperledger.besu.ethereum.ProtocolContext) Clock(java.time.Clock) BftHelpers(org.hyperledger.besu.consensus.common.bft.BftHelpers) Collections(java.util.Collections) GenesisState(org.hyperledger.besu.ethereum.chain.GenesisState) Address(org.hyperledger.besu.datatypes.Address) ArrayList(java.util.ArrayList) UniqueMessageMulticaster(org.hyperledger.besu.consensus.common.bft.UniqueMessageMulticaster) DefaultValidatorPeer(org.hyperledger.besu.consensus.common.bft.inttest.DefaultValidatorPeer) StubbedSynchronizerUpdater(org.hyperledger.besu.consensus.common.bft.inttest.StubbedSynchronizerUpdater) StubValidatorMulticaster(org.hyperledger.besu.consensus.common.bft.inttest.StubValidatorMulticaster) DefaultValidatorPeer(org.hyperledger.besu.consensus.common.bft.inttest.DefaultValidatorPeer) DefaultWorldStateArchive(org.hyperledger.besu.ethereum.worldstate.DefaultWorldStateArchive) MessageFactory(org.hyperledger.besu.consensus.qbft.payload.MessageFactory) NetworkLayout(org.hyperledger.besu.consensus.common.bft.inttest.NetworkLayout) IOException(java.io.IOException) TreeMap(java.util.TreeMap) NodeParams(org.hyperledger.besu.consensus.common.bft.inttest.NodeParams) Gossiper(org.hyperledger.besu.consensus.common.bft.Gossiper) Block(org.hyperledger.besu.ethereum.core.Block) MutableBlockchain(org.hyperledger.besu.ethereum.chain.MutableBlockchain) QbftGossip(org.hyperledger.besu.consensus.qbft.QbftGossip)

Example 4 with UniqueMessageMulticaster

use of org.hyperledger.besu.consensus.common.bft.UniqueMessageMulticaster in project besu by hyperledger.

the class IbftBesuControllerBuilder method createMiningCoordinator.

@Override
protected MiningCoordinator createMiningCoordinator(final ProtocolSchedule protocolSchedule, final ProtocolContext protocolContext, final TransactionPool transactionPool, final MiningParameters miningParameters, final SyncState syncState, final EthProtocolManager ethProtocolManager) {
    final MutableBlockchain blockchain = protocolContext.getBlockchain();
    final BftExecutors bftExecutors = BftExecutors.create(metricsSystem, BftExecutors.ConsensusType.IBFT);
    final Address localAddress = Util.publicKeyToAddress(nodeKey.getPublicKey());
    final BftBlockCreatorFactory<?> blockCreatorFactory = new BftBlockCreatorFactory<>(transactionPool.getPendingTransactions(), protocolContext, protocolSchedule, forksSchedule, miningParameters, localAddress, bftExtraDataCodec().get());
    final ValidatorProvider validatorProvider = protocolContext.getConsensusContext(BftContext.class).getValidatorProvider();
    final ProposerSelector proposerSelector = new ProposerSelector(blockchain, bftBlockInterface().get(), true, validatorProvider);
    // NOTE: peers should not be used for accessing the network as it does not enforce the
    // "only send once" filter applied by the UniqueMessageMulticaster.
    peers = new ValidatorPeers(validatorProvider, IbftSubProtocol.NAME);
    final UniqueMessageMulticaster uniqueMessageMulticaster = new UniqueMessageMulticaster(peers, bftConfig.getGossipedHistoryLimit());
    final IbftGossip gossiper = new IbftGossip(uniqueMessageMulticaster);
    final BftFinalState finalState = new BftFinalState(validatorProvider, nodeKey, Util.publicKeyToAddress(nodeKey.getPublicKey()), proposerSelector, uniqueMessageMulticaster, new RoundTimer(bftEventQueue, bftConfig.getRequestTimeoutSeconds(), bftExecutors), new BlockTimer(bftEventQueue, forksSchedule, bftExecutors, clock), blockCreatorFactory, clock);
    final MessageValidatorFactory messageValidatorFactory = new MessageValidatorFactory(proposerSelector, protocolSchedule, protocolContext, bftExtraDataCodec().get());
    final Subscribers<MinedBlockObserver> minedBlockObservers = Subscribers.create();
    minedBlockObservers.subscribe(ethProtocolManager);
    minedBlockObservers.subscribe(blockLogger(transactionPool, localAddress));
    final FutureMessageBuffer futureMessageBuffer = new FutureMessageBuffer(bftConfig.getFutureMessagesMaxDistance(), bftConfig.getFutureMessagesLimit(), blockchain.getChainHeadBlockNumber());
    final MessageTracker duplicateMessageTracker = new MessageTracker(bftConfig.getDuplicateMessageLimit());
    final MessageFactory messageFactory = new MessageFactory(nodeKey);
    final BftEventHandler ibftController = new IbftController(blockchain, finalState, new IbftBlockHeightManagerFactory(finalState, new IbftRoundFactory(finalState, protocolContext, protocolSchedule, minedBlockObservers, messageValidatorFactory, messageFactory, bftExtraDataCodec().get()), messageValidatorFactory, messageFactory), gossiper, duplicateMessageTracker, futureMessageBuffer, new EthSynchronizerUpdater(ethProtocolManager.ethContext().getEthPeers()));
    final EventMultiplexer eventMultiplexer = new EventMultiplexer(ibftController);
    final BftProcessor bftProcessor = new BftProcessor(bftEventQueue, eventMultiplexer);
    final MiningCoordinator ibftMiningCoordinator = new BftMiningCoordinator(bftExecutors, ibftController, bftProcessor, blockCreatorFactory, blockchain, bftEventQueue);
    ibftMiningCoordinator.enable();
    return ibftMiningCoordinator;
}
Also used : ValidatorPeers(org.hyperledger.besu.consensus.common.bft.network.ValidatorPeers) MinedBlockObserver(org.hyperledger.besu.ethereum.chain.MinedBlockObserver) EthSynchronizerUpdater(org.hyperledger.besu.consensus.common.bft.EthSynchronizerUpdater) Address(org.hyperledger.besu.datatypes.Address) BftBlockCreatorFactory(org.hyperledger.besu.consensus.common.bft.blockcreation.BftBlockCreatorFactory) BftProcessor(org.hyperledger.besu.consensus.common.bft.BftProcessor) RoundTimer(org.hyperledger.besu.consensus.common.bft.RoundTimer) BftEventHandler(org.hyperledger.besu.consensus.common.bft.statemachine.BftEventHandler) EventMultiplexer(org.hyperledger.besu.consensus.common.bft.EventMultiplexer) BftFinalState(org.hyperledger.besu.consensus.common.bft.statemachine.BftFinalState) ProposerSelector(org.hyperledger.besu.consensus.common.bft.blockcreation.ProposerSelector) UniqueMessageMulticaster(org.hyperledger.besu.consensus.common.bft.UniqueMessageMulticaster) BftExecutors(org.hyperledger.besu.consensus.common.bft.BftExecutors) BlockValidatorProvider(org.hyperledger.besu.consensus.common.validator.blockbased.BlockValidatorProvider) ValidatorProvider(org.hyperledger.besu.consensus.common.validator.ValidatorProvider) MiningCoordinator(org.hyperledger.besu.ethereum.blockcreation.MiningCoordinator) BftMiningCoordinator(org.hyperledger.besu.consensus.common.bft.blockcreation.BftMiningCoordinator) BftContext(org.hyperledger.besu.consensus.common.bft.BftContext) IbftController(org.hyperledger.besu.consensus.ibft.statemachine.IbftController) MessageFactory(org.hyperledger.besu.consensus.ibft.payload.MessageFactory) MessageValidatorFactory(org.hyperledger.besu.consensus.ibft.validation.MessageValidatorFactory) MessageTracker(org.hyperledger.besu.consensus.common.bft.MessageTracker) IbftRoundFactory(org.hyperledger.besu.consensus.ibft.statemachine.IbftRoundFactory) BftMiningCoordinator(org.hyperledger.besu.consensus.common.bft.blockcreation.BftMiningCoordinator) FutureMessageBuffer(org.hyperledger.besu.consensus.common.bft.statemachine.FutureMessageBuffer) IbftBlockHeightManagerFactory(org.hyperledger.besu.consensus.ibft.statemachine.IbftBlockHeightManagerFactory) BlockTimer(org.hyperledger.besu.consensus.common.bft.BlockTimer) MutableBlockchain(org.hyperledger.besu.ethereum.chain.MutableBlockchain) IbftGossip(org.hyperledger.besu.consensus.ibft.IbftGossip)

Aggregations

BftContext (org.hyperledger.besu.consensus.common.bft.BftContext)4 BftExecutors (org.hyperledger.besu.consensus.common.bft.BftExecutors)4 BlockTimer (org.hyperledger.besu.consensus.common.bft.BlockTimer)4 EventMultiplexer (org.hyperledger.besu.consensus.common.bft.EventMultiplexer)4 MessageTracker (org.hyperledger.besu.consensus.common.bft.MessageTracker)4 RoundTimer (org.hyperledger.besu.consensus.common.bft.RoundTimer)4 UniqueMessageMulticaster (org.hyperledger.besu.consensus.common.bft.UniqueMessageMulticaster)4 ProposerSelector (org.hyperledger.besu.consensus.common.bft.blockcreation.ProposerSelector)4 BftEventHandler (org.hyperledger.besu.consensus.common.bft.statemachine.BftEventHandler)4 BftFinalState (org.hyperledger.besu.consensus.common.bft.statemachine.BftFinalState)4 FutureMessageBuffer (org.hyperledger.besu.consensus.common.bft.statemachine.FutureMessageBuffer)4 ValidatorProvider (org.hyperledger.besu.consensus.common.validator.ValidatorProvider)4 BlockValidatorProvider (org.hyperledger.besu.consensus.common.validator.blockbased.BlockValidatorProvider)4 Address (org.hyperledger.besu.datatypes.Address)4 MinedBlockObserver (org.hyperledger.besu.ethereum.chain.MinedBlockObserver)4 MutableBlockchain (org.hyperledger.besu.ethereum.chain.MutableBlockchain)4 Iterables (com.google.common.collect.Iterables)2 UTF_8 (java.nio.charset.StandardCharsets.UTF_8)2 Clock (java.time.Clock)2 Instant (java.time.Instant)2