Search in sources :

Example 1 with MutableQbftConfigOptions

use of org.hyperledger.besu.consensus.qbft.MutableQbftConfigOptions in project besu by hyperledger.

the class QbftBlockCreatorFactoryTest method setUp.

@Before
@SuppressWarnings("unchecked")
public void setUp() throws Exception {
    final MiningParameters miningParams = mock(MiningParameters.class);
    when(miningParams.getExtraData()).thenReturn(Bytes.wrap("Qbft tests".getBytes(UTF_8)));
    final MutableQbftConfigOptions qbftConfigOptions = new MutableQbftConfigOptions(JsonQbftConfigOptions.DEFAULT);
    qbftConfigOptions.setValidatorContractAddress(Optional.of("1"));
    final ForkSpec<QbftConfigOptions> spec = new ForkSpec<>(0, qbftConfigOptions);
    final ForksSchedule<QbftConfigOptions> forksSchedule = mock(ForksSchedule.class);
    when(forksSchedule.getFork(anyLong())).thenReturn(spec);
    qbftBlockCreatorFactory = new QbftBlockCreatorFactory(mock(AbstractPendingTransactionsSorter.class), mock(ProtocolContext.class), mock(ProtocolSchedule.class), forksSchedule, miningParams, mock(Address.class), extraDataCodec);
}
Also used : MiningParameters(org.hyperledger.besu.ethereum.core.MiningParameters) ForkSpec(org.hyperledger.besu.consensus.common.ForkSpec) MutableQbftConfigOptions(org.hyperledger.besu.consensus.qbft.MutableQbftConfigOptions) QbftConfigOptions(org.hyperledger.besu.config.QbftConfigOptions) JsonQbftConfigOptions(org.hyperledger.besu.config.JsonQbftConfigOptions) MutableQbftConfigOptions(org.hyperledger.besu.consensus.qbft.MutableQbftConfigOptions) Before(org.junit.Before)

Example 2 with MutableQbftConfigOptions

use of org.hyperledger.besu.consensus.qbft.MutableQbftConfigOptions in project besu by hyperledger.

the class TestContextBuilder method createGenesisConfig.

private static QbftConfigOptions createGenesisConfig(final boolean useValidatorContract) {
    final MutableQbftConfigOptions qbftConfigOptions = new MutableQbftConfigOptions(JsonQbftConfigOptions.DEFAULT);
    qbftConfigOptions.setBlockPeriodSeconds(BLOCK_TIMER_SEC);
    if (useValidatorContract) {
        qbftConfigOptions.setValidatorContractAddress(Optional.of(VALIDATOR_CONTRACT_ADDRESS.toHexString()));
    }
    return qbftConfigOptions;
}
Also used : MutableQbftConfigOptions(org.hyperledger.besu.consensus.qbft.MutableQbftConfigOptions)

Example 3 with MutableQbftConfigOptions

use of org.hyperledger.besu.consensus.qbft.MutableQbftConfigOptions in project besu by hyperledger.

the class QbftBesuControllerBuilderTest method setup.

@Before
public void setup() {
    // besu controller setup
    when(genesisConfigFile.getParentHash()).thenReturn(Hash.ZERO.toHexString());
    when(genesisConfigFile.getDifficulty()).thenReturn(Bytes.of(0).toHexString());
    when(genesisConfigFile.getExtraData()).thenReturn(Bytes.EMPTY.toHexString());
    when(genesisConfigFile.getMixHash()).thenReturn(Hash.ZERO.toHexString());
    when(genesisConfigFile.getNonce()).thenReturn(Long.toHexString(1));
    when(genesisConfigFile.getConfigOptions(any())).thenReturn(genesisConfigOptions);
    when(genesisConfigOptions.getCheckpointOptions()).thenReturn(checkpointConfigOptions);
    when(storageProvider.createBlockchainStorage(any())).thenReturn(new KeyValueStoragePrefixedKeyBlockchainStorage(new InMemoryKeyValueStorage(), new MainnetBlockHeaderFunctions()));
    when(storageProvider.createWorldStateStorage(DataStorageFormat.FOREST)).thenReturn(worldStateStorage);
    when(worldStateStorage.isWorldStateAvailable(any(), any())).thenReturn(true);
    when(worldStateStorage.updater()).thenReturn(mock(WorldStateStorage.Updater.class));
    when(worldStatePreimageStorage.updater()).thenReturn(mock(WorldStatePreimageStorage.Updater.class));
    when(storageProvider.createWorldStatePreimageStorage()).thenReturn(worldStatePreimageStorage);
    when(synchronizerConfiguration.getDownloaderParallelism()).thenReturn(1);
    when(synchronizerConfiguration.getTransactionsParallelism()).thenReturn(1);
    when(synchronizerConfiguration.getComputationParallelism()).thenReturn(1);
    when(observableMetricsSystem.createLabelledCounter(any(), anyString(), anyString(), anyString())).thenReturn(labels -> null);
    when(synchronizerConfiguration.getBlockPropagationRange()).thenReturn(Range.closed(1L, 2L));
    // qbft prepForBuild setup
    when(genesisConfigOptions.getQbftConfigOptions()).thenReturn(new MutableQbftConfigOptions(JsonQbftConfigOptions.DEFAULT));
    when(genesisConfigOptions.getTransitions()).thenReturn(mock(TransitionsConfigOptions.class));
    when(genesisConfigFile.getExtraData()).thenReturn(QbftExtraDataCodec.createGenesisExtraDataString(List.of(Address.fromHexString("1"))));
    qbftBesuControllerBuilder = new QbftBesuControllerBuilder().genesisConfigFile(genesisConfigFile).synchronizerConfiguration(synchronizerConfiguration).ethProtocolConfiguration(ethProtocolConfiguration).networkId(networkId).miningParameters(miningParameters).metricsSystem(observableMetricsSystem).privacyParameters(privacyParameters).dataDirectory(tempDirRule.getRoot().toPath()).clock(clock).transactionPoolConfiguration(poolConfiguration).nodeKey(nodeKey).storageProvider(storageProvider).gasLimitCalculator(gasLimitCalculator).evmConfiguration(EvmConfiguration.DEFAULT);
}
Also used : InMemoryKeyValueStorage(org.hyperledger.besu.services.kvstore.InMemoryKeyValueStorage) TransitionsConfigOptions(org.hyperledger.besu.config.TransitionsConfigOptions) MainnetBlockHeaderFunctions(org.hyperledger.besu.ethereum.mainnet.MainnetBlockHeaderFunctions) KeyValueStoragePrefixedKeyBlockchainStorage(org.hyperledger.besu.ethereum.storage.keyvalue.KeyValueStoragePrefixedKeyBlockchainStorage) MutableQbftConfigOptions(org.hyperledger.besu.consensus.qbft.MutableQbftConfigOptions) Before(org.junit.Before)

Example 4 with MutableQbftConfigOptions

use of org.hyperledger.besu.consensus.qbft.MutableQbftConfigOptions in project besu by hyperledger.

the class QbftForksSchedulesFactoryTest method switchingToBlockHeaderRemovesValidatorContractAddress.

@Test
public void switchingToBlockHeaderRemovesValidatorContractAddress() {
    final MutableQbftConfigOptions configOptions = new MutableQbftConfigOptions(JsonQbftConfigOptions.DEFAULT);
    configOptions.setValidatorContractAddress(Optional.of("10"));
    List<Address> validators = List.of(AddressHelpers.ofValue(1));
    final List<TextNode> jsonValidators = validators.stream().map(v -> TextNode.valueOf(v.toHexString())).collect(Collectors.toList());
    final ObjectNode fork = JsonUtil.objectNodeFromMap(Map.of(BftFork.FORK_BLOCK_KEY, 1, QbftFork.VALIDATOR_SELECTION_MODE_KEY, VALIDATOR_SELECTION_MODE.BLOCKHEADER, BftFork.VALIDATORS_KEY, JsonUtil.getObjectMapper().createArrayNode().addAll(jsonValidators)));
    final ForksSchedule<QbftConfigOptions> forksSchedule = QbftForksSchedulesFactory.create(createGenesisConfig(configOptions, fork));
    assertThat(forksSchedule.getFork(1).getValue().getValidatorContractAddress()).isEmpty();
}
Also used : Arrays(java.util.Arrays) HashMap(java.util.HashMap) GenesisConfigOptions(org.hyperledger.besu.config.GenesisConfigOptions) BaseForksSchedulesFactoryTest(org.hyperledger.besu.consensus.common.bft.BaseForksSchedulesFactoryTest) QbftFork(org.hyperledger.besu.config.QbftFork) Address(org.hyperledger.besu.datatypes.Address) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) ForkSpec(org.hyperledger.besu.consensus.common.ForkSpec) ForksSchedule(org.hyperledger.besu.consensus.common.ForksSchedule) Map(java.util.Map) AssertionsForClassTypes.assertThatThrownBy(org.assertj.core.api.AssertionsForClassTypes.assertThatThrownBy) AssertionsForClassTypes.assertThat(org.assertj.core.api.AssertionsForClassTypes.assertThat) BftFork(org.hyperledger.besu.config.BftFork) QbftForksSchedulesFactory(org.hyperledger.besu.consensus.qbft.QbftForksSchedulesFactory) TransitionsConfigOptions(org.hyperledger.besu.config.TransitionsConfigOptions) StubGenesisConfigOptions(org.hyperledger.besu.config.StubGenesisConfigOptions) AddressHelpers(org.hyperledger.besu.ethereum.core.AddressHelpers) Test(org.junit.Test) JsonUtil(org.hyperledger.besu.config.JsonUtil) MutableQbftConfigOptions(org.hyperledger.besu.consensus.qbft.MutableQbftConfigOptions) QbftConfigOptions(org.hyperledger.besu.config.QbftConfigOptions) Collectors(java.util.stream.Collectors) TextNode(com.fasterxml.jackson.databind.node.TextNode) JsonQbftConfigOptions(org.hyperledger.besu.config.JsonQbftConfigOptions) Consumer(java.util.function.Consumer) List(java.util.List) VALIDATOR_SELECTION_MODE(org.hyperledger.besu.config.QbftFork.VALIDATOR_SELECTION_MODE) Optional(java.util.Optional) Address(org.hyperledger.besu.datatypes.Address) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) MutableQbftConfigOptions(org.hyperledger.besu.consensus.qbft.MutableQbftConfigOptions) QbftConfigOptions(org.hyperledger.besu.config.QbftConfigOptions) JsonQbftConfigOptions(org.hyperledger.besu.config.JsonQbftConfigOptions) TextNode(com.fasterxml.jackson.databind.node.TextNode) MutableQbftConfigOptions(org.hyperledger.besu.consensus.qbft.MutableQbftConfigOptions) BaseForksSchedulesFactoryTest(org.hyperledger.besu.consensus.common.bft.BaseForksSchedulesFactoryTest) Test(org.junit.Test)

Example 5 with MutableQbftConfigOptions

use of org.hyperledger.besu.consensus.qbft.MutableQbftConfigOptions in project besu by hyperledger.

the class QbftForksSchedulesFactoryTest method createBftOptions.

@Override
protected QbftConfigOptions createBftOptions(final Consumer<MutableQbftConfigOptions> optionModifier) {
    final MutableQbftConfigOptions options = new MutableQbftConfigOptions(JsonQbftConfigOptions.DEFAULT);
    optionModifier.accept(options);
    return options;
}
Also used : MutableQbftConfigOptions(org.hyperledger.besu.consensus.qbft.MutableQbftConfigOptions)

Aggregations

MutableQbftConfigOptions (org.hyperledger.besu.consensus.qbft.MutableQbftConfigOptions)12 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)5 BaseForksSchedulesFactoryTest (org.hyperledger.besu.consensus.common.bft.BaseForksSchedulesFactoryTest)5 Test (org.junit.Test)5 ForkSpec (org.hyperledger.besu.consensus.common.ForkSpec)4 JsonQbftConfigOptions (org.hyperledger.besu.config.JsonQbftConfigOptions)3 QbftConfigOptions (org.hyperledger.besu.config.QbftConfigOptions)3 Before (org.junit.Before)3 HashMap (java.util.HashMap)2 TransitionsConfigOptions (org.hyperledger.besu.config.TransitionsConfigOptions)2 Address (org.hyperledger.besu.datatypes.Address)2 TextNode (com.fasterxml.jackson.databind.node.TextNode)1 Arrays (java.util.Arrays)1 List (java.util.List)1 Map (java.util.Map)1 Optional (java.util.Optional)1 Consumer (java.util.function.Consumer)1 Collectors (java.util.stream.Collectors)1 Bytes (org.apache.tuweni.bytes.Bytes)1 AssertionsForClassTypes.assertThat (org.assertj.core.api.AssertionsForClassTypes.assertThat)1