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);
}
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;
}
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);
}
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();
}
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();
}
Aggregations