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