Search in sources :

Example 1 with ValidatorProvider

use of org.hyperledger.besu.consensus.common.validator.ValidatorProvider in project besu by hyperledger.

the class QbftBesuControllerBuilder method createConsensusContext.

@Override
protected BftContext createConsensusContext(final Blockchain blockchain, final WorldStateArchive worldStateArchive, final ProtocolSchedule protocolSchedule) {
    final EpochManager epochManager = new EpochManager(qbftConfig.getEpochLength());
    final BftValidatorOverrides validatorOverrides = convertBftForks(configOptionsSupplier.get().getTransitions().getQbftForks());
    final BlockValidatorProvider blockValidatorProvider = BlockValidatorProvider.forkingValidatorProvider(blockchain, epochManager, bftBlockInterface().get(), validatorOverrides);
    final TransactionSimulator transactionSimulator = new TransactionSimulator(blockchain, worldStateArchive, protocolSchedule);
    transactionValidatorProvider = new TransactionValidatorProvider(blockchain, new ValidatorContractController(transactionSimulator), qbftForksSchedule);
    final ValidatorProvider validatorProvider = new ForkingValidatorProvider(blockchain, qbftForksSchedule, blockValidatorProvider, transactionValidatorProvider);
    return new QbftContext(validatorProvider, epochManager, bftBlockInterface().get(), pkiBlockCreationConfiguration);
}
Also used : ForkingValidatorProvider(org.hyperledger.besu.consensus.qbft.validator.ForkingValidatorProvider) QbftContext(org.hyperledger.besu.consensus.qbft.QbftContext) ValidatorContractController(org.hyperledger.besu.consensus.qbft.validator.ValidatorContractController) BftValidatorOverrides(org.hyperledger.besu.consensus.common.BftValidatorOverrides) TransactionSimulator(org.hyperledger.besu.ethereum.transaction.TransactionSimulator) EpochManager(org.hyperledger.besu.consensus.common.EpochManager) BlockValidatorProvider(org.hyperledger.besu.consensus.common.validator.blockbased.BlockValidatorProvider) TransactionValidatorProvider(org.hyperledger.besu.consensus.qbft.validator.TransactionValidatorProvider) 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)

Example 2 with ValidatorProvider

use of org.hyperledger.besu.consensus.common.validator.ValidatorProvider 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 3 with ValidatorProvider

use of org.hyperledger.besu.consensus.common.validator.ValidatorProvider in project besu by hyperledger.

the class IbftLegacyBesuControllerBuilder method createConsensusContext.

@Override
protected IbftLegacyContext createConsensusContext(final Blockchain blockchain, final WorldStateArchive worldStateArchive, final ProtocolSchedule protocolSchedule) {
    final IbftLegacyConfigOptions ibftConfig = configOptionsSupplier.get().getIbftLegacyConfigOptions();
    final EpochManager epochManager = new EpochManager(ibftConfig.getEpochLength());
    final ValidatorProvider validatorProvider = BlockValidatorProvider.nonForkingValidatorProvider(blockchain, epochManager, blockInterface);
    return new IbftLegacyContext(validatorProvider, epochManager, blockInterface);
}
Also used : IbftLegacyConfigOptions(org.hyperledger.besu.config.IbftLegacyConfigOptions) IbftLegacyContext(org.hyperledger.besu.consensus.ibft.IbftLegacyContext) EpochManager(org.hyperledger.besu.consensus.common.EpochManager) BlockValidatorProvider(org.hyperledger.besu.consensus.common.validator.blockbased.BlockValidatorProvider) ValidatorProvider(org.hyperledger.besu.consensus.common.validator.ValidatorProvider)

Example 4 with ValidatorProvider

use of org.hyperledger.besu.consensus.common.validator.ValidatorProvider in project besu by hyperledger.

the class CliqueDifficultyCalculatorTest method setup.

@Before
public void setup() {
    localAddr = Util.publicKeyToAddress(proposerKeyPair.getPublicKey());
    validatorList.add(localAddr);
    validatorList.add(AddressHelpers.calculateAddressWithRespectTo(localAddr, 1));
    final ValidatorProvider validatorProvider = mock(ValidatorProvider.class);
    when(validatorProvider.getValidatorsAfterBlock(any())).thenReturn(validatorList);
    final CliqueContext cliqueContext = new CliqueContext(validatorProvider, null, blockInterface);
    cliqueProtocolContext = new ProtocolContext(null, null, cliqueContext);
    blockHeaderBuilder = new BlockHeaderTestFixture();
}
Also used : BlockHeaderTestFixture(org.hyperledger.besu.ethereum.core.BlockHeaderTestFixture) ProtocolContext(org.hyperledger.besu.ethereum.ProtocolContext) ValidatorProvider(org.hyperledger.besu.consensus.common.validator.ValidatorProvider) Before(org.junit.Before)

Example 5 with ValidatorProvider

use of org.hyperledger.besu.consensus.common.validator.ValidatorProvider in project besu by hyperledger.

the class NodeCanProduceNextBlockTest method nonValidatorIsNotAllowedToCreateABlock.

@Test
public void nonValidatorIsNotAllowedToCreateABlock() {
    genesisBlock = createEmptyBlock(otherNodeKeyPair);
    blockChain = createInMemoryBlockchain(genesisBlock);
    final ValidatorProvider validatorProvider = mock(ValidatorProvider.class);
    when(validatorProvider.getValidatorsAfterBlock(any())).thenReturn(validatorList);
    final CliqueContext cliqueContext = new CliqueContext(validatorProvider, null, blockInterface);
    cliqueProtocolContext = new ProtocolContext(blockChain, null, cliqueContext);
    headerBuilder.parentHash(Hash.ZERO).number(3);
    final BlockHeader parentHeader = headerBuilder.buildHeader();
    assertThat(CliqueHelpers.addressIsAllowedToProduceNextBlock(AddressHelpers.ofValue(1), cliqueProtocolContext, parentHeader)).isFalse();
}
Also used : ProtocolContext(org.hyperledger.besu.ethereum.ProtocolContext) BlockHeader(org.hyperledger.besu.ethereum.core.BlockHeader) ValidatorProvider(org.hyperledger.besu.consensus.common.validator.ValidatorProvider) Test(org.junit.Test)

Aggregations

ValidatorProvider (org.hyperledger.besu.consensus.common.validator.ValidatorProvider)38 Address (org.hyperledger.besu.datatypes.Address)21 ProtocolContext (org.hyperledger.besu.ethereum.ProtocolContext)15 BlockHeader (org.hyperledger.besu.ethereum.core.BlockHeader)12 Test (org.junit.Test)10 BlockValidatorProvider (org.hyperledger.besu.consensus.common.validator.blockbased.BlockValidatorProvider)8 Before (org.junit.Before)8 BftContext (org.hyperledger.besu.consensus.common.bft.BftContext)7 BlockHeaderTestFixture (org.hyperledger.besu.ethereum.core.BlockHeaderTestFixture)7 NodeParams (org.hyperledger.besu.consensus.common.bft.inttest.NodeParams)6 TestContext (org.hyperledger.besu.consensus.qbft.support.TestContext)6 TestContextBuilder (org.hyperledger.besu.consensus.qbft.support.TestContextBuilder)6 Block (org.hyperledger.besu.ethereum.core.Block)6 Test (org.junit.jupiter.api.Test)6 QbftFork (org.hyperledger.besu.config.QbftFork)5 EpochManager (org.hyperledger.besu.consensus.common.EpochManager)5 BftBlockInterface (org.hyperledger.besu.consensus.common.bft.BftBlockInterface)5 CliqueContext (org.hyperledger.besu.consensus.clique.CliqueContext)4 ForkingValidatorProvider (org.hyperledger.besu.consensus.qbft.validator.ForkingValidatorProvider)4 BftExecutors (org.hyperledger.besu.consensus.common.bft.BftExecutors)3