Search in sources :

Example 1 with VALIDATOR_SELECTION_MODE

use of org.hyperledger.besu.config.QbftFork.VALIDATOR_SELECTION_MODE in project besu by hyperledger.

the class QbftForksSchedulesFactory method createQbftConfigOptions.

private static QbftConfigOptions createQbftConfigOptions(final ForkSpec<QbftConfigOptions> lastSpec, final QbftFork fork) {
    final MutableQbftConfigOptions bftConfigOptions = new MutableQbftConfigOptions(lastSpec.getValue());
    fork.getBlockPeriodSeconds().ifPresent(bftConfigOptions::setBlockPeriodSeconds);
    fork.getBlockRewardWei().ifPresent(bftConfigOptions::setBlockRewardWei);
    if (fork.isMiningBeneficiaryConfigured()) {
        // Only override if mining beneficiary is explicitly configured
        bftConfigOptions.setMiningBeneficiary(fork.getMiningBeneficiary());
    }
    if (fork.getValidatorSelectionMode().isPresent()) {
        final VALIDATOR_SELECTION_MODE mode = fork.getValidatorSelectionMode().get();
        if (mode == VALIDATOR_SELECTION_MODE.BLOCKHEADER) {
            final Optional<List<String>> optionalValidators = fork.getValidators();
            if (optionalValidators.isEmpty() || optionalValidators.get().isEmpty()) {
                throw new IllegalStateException("QBFT transition to blockheader mode requires a validators list containing at least one validator");
            }
            bftConfigOptions.setValidatorContractAddress(Optional.empty());
        } else if (mode == VALIDATOR_SELECTION_MODE.CONTRACT && fork.getValidatorContractAddress().isPresent()) {
            bftConfigOptions.setValidatorContractAddress(fork.getValidatorContractAddress());
        } else if (fork.getValidatorContractAddress().isEmpty()) {
            throw new IllegalStateException("QBFT transition has config with contract mode but no contract address");
        }
    }
    return bftConfigOptions;
}
Also used : VALIDATOR_SELECTION_MODE(org.hyperledger.besu.config.QbftFork.VALIDATOR_SELECTION_MODE) QbftConfigOptions(org.hyperledger.besu.config.QbftConfigOptions) List(java.util.List)

Aggregations

List (java.util.List)1 QbftConfigOptions (org.hyperledger.besu.config.QbftConfigOptions)1 VALIDATOR_SELECTION_MODE (org.hyperledger.besu.config.QbftFork.VALIDATOR_SELECTION_MODE)1