Search in sources :

Example 1 with QbftConfigOptions

use of org.hyperledger.besu.config.QbftConfigOptions 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 QbftConfigOptions

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

the class ValidatorModeTransitionLogger method logTransitionChange.

public void logTransitionChange(final BlockHeader parentHeader) {
    final ForkSpec<QbftConfigOptions> currentForkSpec = forksSchedule.getFork(parentHeader.getNumber());
    final ForkSpec<QbftConfigOptions> nextForkSpec = forksSchedule.getFork(parentHeader.getNumber() + 1L);
    final QbftConfigOptions currentConfigOptions = currentForkSpec.getValue();
    final QbftConfigOptions nextConfigOptions = nextForkSpec.getValue();
    if (hasChangedConfig(currentConfigOptions, nextConfigOptions)) {
        msgConsumer.accept(String.format("Transitioning validator selection mode from %s to %s", parseConfigToLog(currentConfigOptions), parseConfigToLog(nextConfigOptions)));
    }
}
Also used : QbftConfigOptions(org.hyperledger.besu.config.QbftConfigOptions)

Example 3 with QbftConfigOptions

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

the class QbftProtocolSchedule method createBlockHeaderRuleset.

@Override
protected BlockHeaderValidator.Builder createBlockHeaderRuleset(final BftConfigOptions config, final FeeMarket feeMarket) {
    checkArgument(config instanceof QbftConfigOptions, "QbftProtocolSchedule must use QbftConfigOptions");
    final QbftConfigOptions qbftConfigOptions = (QbftConfigOptions) config;
    final Optional<BaseFeeMarket> baseFeeMarket = Optional.of(feeMarket).filter(FeeMarket::implementsBaseFee).map(BaseFeeMarket.class::cast);
    return QbftBlockHeaderValidationRulesetFactory.blockHeaderValidator(qbftConfigOptions.getBlockPeriodSeconds(), qbftConfigOptions.isValidatorContractMode(), baseFeeMarket);
}
Also used : BaseFeeMarket(org.hyperledger.besu.ethereum.mainnet.feemarket.BaseFeeMarket) QbftConfigOptions(org.hyperledger.besu.config.QbftConfigOptions)

Example 4 with QbftConfigOptions

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

the class ForkingValidatorProviderTest method getVoteProviderAfterBlock_correctVoteProviderIsResolved.

@Test
public void getVoteProviderAfterBlock_correctVoteProviderIsResolved() {
    final ForksSchedule<QbftConfigOptions> forksSchedule = new ForksSchedule<>(List.of(createBlockForkSpec(0), createBlockForkSpec(1), createContractForkSpec(2, CONTRACT_ADDRESS_1)));
    final ForkingValidatorProvider validatorProvider = new ForkingValidatorProvider(blockChain, forksSchedule, blockValidatorProvider, contractValidatorProvider);
    final VoteProvider voteProviderForBlockValidator = Mockito.mock(VoteProvider.class);
    when(blockValidatorProvider.getVoteProviderAtHead()).thenReturn(Optional.of(voteProviderForBlockValidator));
    when(contractValidatorProvider.getVoteProviderAtHead()).thenReturn(Optional.empty());
    SoftAssertions.assertSoftly((softly) -> {
        softly.assertThat(validatorProvider.getVoteProviderAfterBlock(genesisHeader)).contains(voteProviderForBlockValidator);
        softly.assertThat(validatorProvider.getVoteProviderAfterBlock(header1)).isEmpty();
        softly.assertThat(validatorProvider.getVoteProviderAfterBlock(header2)).isEmpty();
    });
}
Also used : VoteProvider(org.hyperledger.besu.consensus.common.validator.VoteProvider) QbftConfigOptions(org.hyperledger.besu.config.QbftConfigOptions) ForksSchedule(org.hyperledger.besu.consensus.common.ForksSchedule) Test(org.junit.Test)

Example 5 with QbftConfigOptions

use of org.hyperledger.besu.config.QbftConfigOptions 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)

Aggregations

QbftConfigOptions (org.hyperledger.besu.config.QbftConfigOptions)8 JsonQbftConfigOptions (org.hyperledger.besu.config.JsonQbftConfigOptions)4 MutableQbftConfigOptions (org.hyperledger.besu.consensus.qbft.MutableQbftConfigOptions)4 ForkSpec (org.hyperledger.besu.consensus.common.ForkSpec)3 Test (org.junit.Test)3 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)2 HashMap (java.util.HashMap)2 List (java.util.List)2 VALIDATOR_SELECTION_MODE (org.hyperledger.besu.config.QbftFork.VALIDATOR_SELECTION_MODE)2 StubGenesisConfigOptions (org.hyperledger.besu.config.StubGenesisConfigOptions)2 ForksSchedule (org.hyperledger.besu.consensus.common.ForksSchedule)2 BaseForksSchedulesFactoryTest (org.hyperledger.besu.consensus.common.bft.BaseForksSchedulesFactoryTest)2 Address (org.hyperledger.besu.datatypes.Address)2 MiningParameters (org.hyperledger.besu.ethereum.core.MiningParameters)2 TextNode (com.fasterxml.jackson.databind.node.TextNode)1 Arrays (java.util.Arrays)1 Map (java.util.Map)1 Optional (java.util.Optional)1 Consumer (java.util.function.Consumer)1 Collectors (java.util.stream.Collectors)1