Search in sources :

Example 1 with JsonQbftConfigOptions

use of org.hyperledger.besu.config.JsonQbftConfigOptions in project besu by hyperledger.

the class QbftForksSchedulesFactoryTest method createsScheduleWithForkThatOverridesGenesisValues.

@Test
public void createsScheduleWithForkThatOverridesGenesisValues() {
    final MutableQbftConfigOptions configOptions = new MutableQbftConfigOptions(JsonQbftConfigOptions.DEFAULT);
    final ObjectNode fork = JsonUtil.objectNodeFromMap(Map.of(BftFork.FORK_BLOCK_KEY, 1, BftFork.VALIDATORS_KEY, List.of("1", "2", "3"), BftFork.BLOCK_PERIOD_SECONDS_KEY, 10, BftFork.BLOCK_REWARD_KEY, "5", QbftFork.VALIDATOR_SELECTION_MODE_KEY, VALIDATOR_SELECTION_MODE.CONTRACT, QbftFork.VALIDATOR_CONTRACT_ADDRESS_KEY, "10"));
    final ForksSchedule<QbftConfigOptions> forksSchedule = QbftForksSchedulesFactory.create(createGenesisConfig(configOptions, fork));
    assertThat(forksSchedule.getFork(0)).usingRecursiveComparison().isEqualTo(new ForkSpec<>(0, configOptions));
    final Map<String, Object> forkOptions = new HashMap<>(configOptions.asMap());
    forkOptions.put(BftFork.BLOCK_PERIOD_SECONDS_KEY, 10);
    forkOptions.put(BftFork.BLOCK_REWARD_KEY, "5");
    forkOptions.put(QbftFork.VALIDATOR_SELECTION_MODE_KEY, "5");
    forkOptions.put(QbftFork.VALIDATOR_CONTRACT_ADDRESS_KEY, "10");
    final QbftConfigOptions expectedForkConfig = new MutableQbftConfigOptions(new JsonQbftConfigOptions(JsonUtil.objectNodeFromMap(forkOptions)));
    final ForkSpec<QbftConfigOptions> expectedFork = new ForkSpec<>(1, expectedForkConfig);
    assertThat(forksSchedule.getFork(1)).usingRecursiveComparison().isEqualTo(expectedFork);
    assertThat(forksSchedule.getFork(2)).usingRecursiveComparison().isEqualTo(expectedFork);
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) ForkSpec(org.hyperledger.besu.consensus.common.ForkSpec) HashMap(java.util.HashMap) MutableQbftConfigOptions(org.hyperledger.besu.consensus.qbft.MutableQbftConfigOptions) QbftConfigOptions(org.hyperledger.besu.config.QbftConfigOptions) JsonQbftConfigOptions(org.hyperledger.besu.config.JsonQbftConfigOptions) JsonQbftConfigOptions(org.hyperledger.besu.config.JsonQbftConfigOptions) MutableQbftConfigOptions(org.hyperledger.besu.consensus.qbft.MutableQbftConfigOptions) BaseForksSchedulesFactoryTest(org.hyperledger.besu.consensus.common.bft.BaseForksSchedulesFactoryTest) Test(org.junit.Test)

Example 2 with JsonQbftConfigOptions

use of org.hyperledger.besu.config.JsonQbftConfigOptions in project besu by hyperledger.

the class TestContextBuilder method createControllerAndFinalState.

private static ControllerAndState createControllerAndFinalState(final MutableBlockchain blockChain, final WorldStateArchive worldStateArchive, final StubValidatorMulticaster multicaster, final NodeKey nodeKey, final Clock clock, final BftEventQueue bftEventQueue, final Gossiper gossiper, final SynchronizerUpdater synchronizerUpdater, final boolean useValidatorContract, final List<QbftFork> qbftForks) {
    final MiningParameters miningParams = new MiningParameters.Builder().coinbase(AddressHelpers.ofValue(1)).minTransactionGasPrice(Wei.ZERO).extraData(Bytes.wrap("Qbft Int tests".getBytes(UTF_8))).miningEnabled(true).build();
    final StubGenesisConfigOptions genesisConfigOptions = new StubGenesisConfigOptions();
    final Map<String, Object> qbftConfigValues = useValidatorContract ? Map.of(JsonQbftConfigOptions.VALIDATOR_CONTRACT_ADDRESS, VALIDATOR_CONTRACT_ADDRESS.toHexString()) : Collections.emptyMap();
    final QbftConfigOptions qbftConfigOptions = createGenesisConfig(useValidatorContract);
    genesisConfigOptions.byzantiumBlock(0);
    genesisConfigOptions.qbftConfigOptions(new JsonQbftConfigOptions(JsonUtil.objectNodeFromMap(qbftConfigValues)));
    genesisConfigOptions.transitions(TestTransitions.createQbftTestTransitions(qbftForks));
    genesisConfigOptions.qbftConfigOptions(qbftConfigOptions);
    final EpochManager epochManager = new EpochManager(EPOCH_LENGTH);
    final BftBlockInterface blockInterface = new BftBlockInterface(BFT_EXTRA_DATA_ENCODER);
    final ForksSchedule<QbftConfigOptions> forksSchedule = QbftForksSchedulesFactory.create(genesisConfigOptions);
    final ProtocolSchedule protocolSchedule = QbftProtocolSchedule.create(genesisConfigOptions, forksSchedule, BFT_EXTRA_DATA_ENCODER, EvmConfiguration.DEFAULT);
    final BftValidatorOverrides validatorOverrides = convertBftForks(qbftForks);
    final TransactionSimulator transactionSimulator = new TransactionSimulator(blockChain, worldStateArchive, protocolSchedule);
    final BlockValidatorProvider blockValidatorProvider = BlockValidatorProvider.forkingValidatorProvider(blockChain, epochManager, blockInterface, validatorOverrides);
    final TransactionValidatorProvider transactionValidatorProvider = new TransactionValidatorProvider(blockChain, new ValidatorContractController(transactionSimulator), forksSchedule);
    final ValidatorProvider validatorProvider = new ForkingValidatorProvider(blockChain, forksSchedule, blockValidatorProvider, transactionValidatorProvider);
    final ProtocolContext protocolContext = new ProtocolContext(blockChain, worldStateArchive, new QbftContext(validatorProvider, epochManager, blockInterface, Optional.empty()));
    final GasPricePendingTransactionsSorter pendingTransactions = new GasPricePendingTransactionsSorter(TransactionPoolConfiguration.DEFAULT_TX_RETENTION_HOURS, 1, clock, metricsSystem, blockChain::getChainHeadHeader, TransactionPoolConfiguration.DEFAULT_PRICE_BUMP);
    final Address localAddress = Util.publicKeyToAddress(nodeKey.getPublicKey());
    final BftBlockCreatorFactory<?> blockCreatorFactory = new QbftBlockCreatorFactory(// changed from QbftBesuController
    pendingTransactions, protocolContext, protocolSchedule, forksSchedule, miningParams, localAddress, BFT_EXTRA_DATA_ENCODER);
    final ProposerSelector proposerSelector = new ProposerSelector(blockChain, blockInterface, true, validatorProvider);
    final BftExecutors bftExecutors = BftExecutors.create(new NoOpMetricsSystem(), BftExecutors.ConsensusType.QBFT);
    final BftFinalState finalState = new BftFinalState(protocolContext.getConsensusContext(BftContext.class).getValidatorProvider(), nodeKey, Util.publicKeyToAddress(nodeKey.getPublicKey()), proposerSelector, multicaster, new RoundTimer(bftEventQueue, ROUND_TIMER_SEC, bftExecutors), new BlockTimer(bftEventQueue, forksSchedule, bftExecutors, TestClock.fixed()), blockCreatorFactory, clock);
    final MessageFactory messageFactory = new MessageFactory(nodeKey);
    final MessageValidatorFactory messageValidatorFactory = new MessageValidatorFactory(proposerSelector, protocolSchedule, protocolContext, BFT_EXTRA_DATA_ENCODER);
    final Subscribers<MinedBlockObserver> minedBlockObservers = Subscribers.create();
    final MessageTracker duplicateMessageTracker = new MessageTracker(DUPLICATE_MESSAGE_LIMIT);
    final FutureMessageBuffer futureMessageBuffer = new FutureMessageBuffer(FUTURE_MESSAGES_MAX_DISTANCE, FUTURE_MESSAGES_LIMIT, blockChain.getChainHeadBlockNumber());
    final BftEventHandler qbftController = new QbftController(blockChain, finalState, new QbftBlockHeightManagerFactory(finalState, new QbftRoundFactory(finalState, protocolContext, protocolSchedule, minedBlockObservers, messageValidatorFactory, messageFactory, BFT_EXTRA_DATA_ENCODER), messageValidatorFactory, messageFactory, new ValidatorModeTransitionLogger(forksSchedule)), gossiper, duplicateMessageTracker, futureMessageBuffer, synchronizerUpdater, BFT_EXTRA_DATA_ENCODER);
    final EventMultiplexer eventMultiplexer = new EventMultiplexer(qbftController);
    return new ControllerAndState(bftExecutors, qbftController, finalState, eventMultiplexer, messageFactory, validatorProvider);
}
Also used : BftBlockInterface(org.hyperledger.besu.consensus.common.bft.BftBlockInterface) MinedBlockObserver(org.hyperledger.besu.ethereum.chain.MinedBlockObserver) ForkingValidatorProvider(org.hyperledger.besu.consensus.qbft.validator.ForkingValidatorProvider) Address(org.hyperledger.besu.datatypes.Address) ValidatorModeTransitionLogger(org.hyperledger.besu.consensus.qbft.validator.ValidatorModeTransitionLogger) QbftContext(org.hyperledger.besu.consensus.qbft.QbftContext) RoundTimer(org.hyperledger.besu.consensus.common.bft.RoundTimer) BftEventHandler(org.hyperledger.besu.consensus.common.bft.statemachine.BftEventHandler) JsonQbftConfigOptions(org.hyperledger.besu.config.JsonQbftConfigOptions) QbftBlockCreatorFactory(org.hyperledger.besu.consensus.qbft.blockcreation.QbftBlockCreatorFactory) EventMultiplexer(org.hyperledger.besu.consensus.common.bft.EventMultiplexer) BftValidatorOverrides(org.hyperledger.besu.consensus.common.BftValidatorOverrides) BftFinalState(org.hyperledger.besu.consensus.common.bft.statemachine.BftFinalState) ProposerSelector(org.hyperledger.besu.consensus.common.bft.blockcreation.ProposerSelector) TransactionValidatorProvider(org.hyperledger.besu.consensus.qbft.validator.TransactionValidatorProvider) ForkingValidatorProvider(org.hyperledger.besu.consensus.qbft.validator.ForkingValidatorProvider) 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) BftExecutors(org.hyperledger.besu.consensus.common.bft.BftExecutors) MiningParameters(org.hyperledger.besu.ethereum.core.MiningParameters) ProtocolContext(org.hyperledger.besu.ethereum.ProtocolContext) ValidatorContractController(org.hyperledger.besu.consensus.qbft.validator.ValidatorContractController) TransactionSimulator(org.hyperledger.besu.ethereum.transaction.TransactionSimulator) MessageFactory(org.hyperledger.besu.consensus.qbft.payload.MessageFactory) MessageValidatorFactory(org.hyperledger.besu.consensus.qbft.validation.MessageValidatorFactory) ProtocolSchedule(org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule) QbftProtocolSchedule(org.hyperledger.besu.consensus.qbft.QbftProtocolSchedule) MessageTracker(org.hyperledger.besu.consensus.common.bft.MessageTracker) BlockValidatorProvider(org.hyperledger.besu.consensus.common.validator.blockbased.BlockValidatorProvider) QbftBlockHeightManagerFactory(org.hyperledger.besu.consensus.qbft.statemachine.QbftBlockHeightManagerFactory) QbftController(org.hyperledger.besu.consensus.qbft.statemachine.QbftController) FutureMessageBuffer(org.hyperledger.besu.consensus.common.bft.statemachine.FutureMessageBuffer) NoOpMetricsSystem(org.hyperledger.besu.metrics.noop.NoOpMetricsSystem) BlockTimer(org.hyperledger.besu.consensus.common.bft.BlockTimer) MutableQbftConfigOptions(org.hyperledger.besu.consensus.qbft.MutableQbftConfigOptions) QbftConfigOptions(org.hyperledger.besu.config.QbftConfigOptions) JsonQbftConfigOptions(org.hyperledger.besu.config.JsonQbftConfigOptions) StubGenesisConfigOptions(org.hyperledger.besu.config.StubGenesisConfigOptions) GasPricePendingTransactionsSorter(org.hyperledger.besu.ethereum.eth.transactions.sorter.GasPricePendingTransactionsSorter) EpochManager(org.hyperledger.besu.consensus.common.EpochManager) QbftRoundFactory(org.hyperledger.besu.consensus.qbft.statemachine.QbftRoundFactory)

Aggregations

JsonQbftConfigOptions (org.hyperledger.besu.config.JsonQbftConfigOptions)2 QbftConfigOptions (org.hyperledger.besu.config.QbftConfigOptions)2 MutableQbftConfigOptions (org.hyperledger.besu.consensus.qbft.MutableQbftConfigOptions)2 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)1 HashMap (java.util.HashMap)1 StubGenesisConfigOptions (org.hyperledger.besu.config.StubGenesisConfigOptions)1 BftValidatorOverrides (org.hyperledger.besu.consensus.common.BftValidatorOverrides)1 EpochManager (org.hyperledger.besu.consensus.common.EpochManager)1 ForkSpec (org.hyperledger.besu.consensus.common.ForkSpec)1 BaseForksSchedulesFactoryTest (org.hyperledger.besu.consensus.common.bft.BaseForksSchedulesFactoryTest)1 BftBlockInterface (org.hyperledger.besu.consensus.common.bft.BftBlockInterface)1 BftExecutors (org.hyperledger.besu.consensus.common.bft.BftExecutors)1 BlockTimer (org.hyperledger.besu.consensus.common.bft.BlockTimer)1 EventMultiplexer (org.hyperledger.besu.consensus.common.bft.EventMultiplexer)1 MessageTracker (org.hyperledger.besu.consensus.common.bft.MessageTracker)1 RoundTimer (org.hyperledger.besu.consensus.common.bft.RoundTimer)1 ProposerSelector (org.hyperledger.besu.consensus.common.bft.blockcreation.ProposerSelector)1 BftEventHandler (org.hyperledger.besu.consensus.common.bft.statemachine.BftEventHandler)1 BftFinalState (org.hyperledger.besu.consensus.common.bft.statemachine.BftFinalState)1 FutureMessageBuffer (org.hyperledger.besu.consensus.common.bft.statemachine.FutureMessageBuffer)1