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