Search in sources :

Example 1 with EpochManager

use of org.hyperledger.besu.consensus.common.EpochManager in project besu by hyperledger.

the class QbftBesuControllerBuilder method createConsensusContext.

@Override
protected BftContext createConsensusContext(final Blockchain blockchain, final WorldStateArchive worldStateArchive, final ProtocolSchedule protocolSchedule) {
    final EpochManager epochManager = new EpochManager(qbftConfig.getEpochLength());
    final BftValidatorOverrides validatorOverrides = convertBftForks(configOptionsSupplier.get().getTransitions().getQbftForks());
    final BlockValidatorProvider blockValidatorProvider = BlockValidatorProvider.forkingValidatorProvider(blockchain, epochManager, bftBlockInterface().get(), validatorOverrides);
    final TransactionSimulator transactionSimulator = new TransactionSimulator(blockchain, worldStateArchive, protocolSchedule);
    transactionValidatorProvider = new TransactionValidatorProvider(blockchain, new ValidatorContractController(transactionSimulator), qbftForksSchedule);
    final ValidatorProvider validatorProvider = new ForkingValidatorProvider(blockchain, qbftForksSchedule, blockValidatorProvider, transactionValidatorProvider);
    return new QbftContext(validatorProvider, epochManager, bftBlockInterface().get(), pkiBlockCreationConfiguration);
}
Also used : ForkingValidatorProvider(org.hyperledger.besu.consensus.qbft.validator.ForkingValidatorProvider) QbftContext(org.hyperledger.besu.consensus.qbft.QbftContext) ValidatorContractController(org.hyperledger.besu.consensus.qbft.validator.ValidatorContractController) BftValidatorOverrides(org.hyperledger.besu.consensus.common.BftValidatorOverrides) TransactionSimulator(org.hyperledger.besu.ethereum.transaction.TransactionSimulator) EpochManager(org.hyperledger.besu.consensus.common.EpochManager) BlockValidatorProvider(org.hyperledger.besu.consensus.common.validator.blockbased.BlockValidatorProvider) TransactionValidatorProvider(org.hyperledger.besu.consensus.qbft.validator.TransactionValidatorProvider) BlockValidatorProvider(org.hyperledger.besu.consensus.common.validator.blockbased.BlockValidatorProvider) TransactionValidatorProvider(org.hyperledger.besu.consensus.qbft.validator.TransactionValidatorProvider) ValidatorProvider(org.hyperledger.besu.consensus.common.validator.ValidatorProvider) ForkingValidatorProvider(org.hyperledger.besu.consensus.qbft.validator.ForkingValidatorProvider)

Example 2 with EpochManager

use of org.hyperledger.besu.consensus.common.EpochManager in project besu by hyperledger.

the class CliqueBesuControllerBuilder method prepForBuild.

@Override
protected void prepForBuild() {
    localAddress = Util.publicKeyToAddress(nodeKey.getPublicKey());
    final CliqueConfigOptions cliqueConfig = configOptionsSupplier.get().getCliqueConfigOptions();
    final long blocksPerEpoch = cliqueConfig.getEpochLength();
    secondsBetweenBlocks = cliqueConfig.getBlockPeriodSeconds();
    epochManager = new EpochManager(blocksPerEpoch);
}
Also used : CliqueConfigOptions(org.hyperledger.besu.config.CliqueConfigOptions) EpochManager(org.hyperledger.besu.consensus.common.EpochManager)

Example 3 with EpochManager

use of org.hyperledger.besu.consensus.common.EpochManager in project besu by hyperledger.

the class IbftLegacyBesuControllerBuilder method createConsensusContext.

@Override
protected IbftLegacyContext createConsensusContext(final Blockchain blockchain, final WorldStateArchive worldStateArchive, final ProtocolSchedule protocolSchedule) {
    final IbftLegacyConfigOptions ibftConfig = configOptionsSupplier.get().getIbftLegacyConfigOptions();
    final EpochManager epochManager = new EpochManager(ibftConfig.getEpochLength());
    final ValidatorProvider validatorProvider = BlockValidatorProvider.nonForkingValidatorProvider(blockchain, epochManager, blockInterface);
    return new IbftLegacyContext(validatorProvider, epochManager, blockInterface);
}
Also used : IbftLegacyConfigOptions(org.hyperledger.besu.config.IbftLegacyConfigOptions) IbftLegacyContext(org.hyperledger.besu.consensus.ibft.IbftLegacyContext) EpochManager(org.hyperledger.besu.consensus.common.EpochManager) BlockValidatorProvider(org.hyperledger.besu.consensus.common.validator.blockbased.BlockValidatorProvider) ValidatorProvider(org.hyperledger.besu.consensus.common.validator.ValidatorProvider)

Example 4 with EpochManager

use of org.hyperledger.besu.consensus.common.EpochManager in project besu by hyperledger.

the class CliqueMinerExecutorTest method extraDataCreatedOnEpochBlocksContainsValidators.

@Test
public void extraDataCreatedOnEpochBlocksContainsValidators() {
    final Bytes vanityData = generateRandomVanityData();
    final CliqueMinerExecutor executor = new CliqueMinerExecutor(cliqueProtocolContext, CliqueProtocolSchedule.create(GENESIS_CONFIG_OPTIONS, proposerNodeKey, false, EvmConfiguration.DEFAULT), new GasPricePendingTransactionsSorter(TransactionPoolConfiguration.DEFAULT_TX_RETENTION_HOURS, 1, TestClock.fixed(), metricsSystem, CliqueMinerExecutorTest::mockBlockHeader, TransactionPoolConfiguration.DEFAULT_PRICE_BUMP), proposerNodeKey, new MiningParameters.Builder().coinbase(AddressHelpers.ofValue(1)).minTransactionGasPrice(Wei.ZERO).extraData(vanityData).miningEnabled(false).build(), mock(CliqueBlockScheduler.class), new EpochManager(EPOCH_LENGTH));
    // NOTE: Passing in the *parent* block, so must be 1 less than EPOCH
    final BlockHeader header = blockHeaderBuilder.number(EPOCH_LENGTH - 1).buildHeader();
    final Bytes extraDataBytes = executor.calculateExtraData(header);
    final CliqueExtraData cliqueExtraData = CliqueExtraData.decode(blockHeaderBuilder.number(EPOCH_LENGTH).extraData(extraDataBytes).blockHeaderFunctions(new CliqueBlockHeaderFunctions()).buildHeader());
    assertThat(cliqueExtraData.getVanityData()).isEqualTo(vanityData);
    assertThat(cliqueExtraData.getValidators()).containsExactly(validatorList.toArray(new Address[0]));
}
Also used : Bytes(org.apache.tuweni.bytes.Bytes) Address(org.hyperledger.besu.datatypes.Address) CliqueBlockHeaderFunctions(org.hyperledger.besu.consensus.clique.CliqueBlockHeaderFunctions) BlockHeader(org.hyperledger.besu.ethereum.core.BlockHeader) GasPricePendingTransactionsSorter(org.hyperledger.besu.ethereum.eth.transactions.sorter.GasPricePendingTransactionsSorter) EpochManager(org.hyperledger.besu.consensus.common.EpochManager) CliqueExtraData(org.hyperledger.besu.consensus.clique.CliqueExtraData) Test(org.junit.Test)

Example 5 with EpochManager

use of org.hyperledger.besu.consensus.common.EpochManager in project besu by hyperledger.

the class CliqueExtraDataValidationRuleTest method missingSignerFailsValidation.

@Test
public void missingSignerFailsValidation() {
    final Bytes extraData = CliqueExtraData.createWithoutProposerSeal(Bytes.wrap(new byte[32]), Lists.newArrayList());
    final BlockHeaderTestFixture headerBuilder = new BlockHeaderTestFixture();
    final BlockHeader parent = headerBuilder.number(1).buildHeader();
    final BlockHeader child = headerBuilder.number(2).extraData(extraData).buildHeader();
    final CliqueExtraDataValidationRule rule = new CliqueExtraDataValidationRule(new EpochManager(10));
    assertThat(rule.validate(child, parent, cliqueProtocolContext)).isFalse();
}
Also used : Bytes(org.apache.tuweni.bytes.Bytes) BlockHeaderTestFixture(org.hyperledger.besu.ethereum.core.BlockHeaderTestFixture) BlockHeader(org.hyperledger.besu.ethereum.core.BlockHeader) EpochManager(org.hyperledger.besu.consensus.common.EpochManager) Test(org.junit.Test)

Aggregations

EpochManager (org.hyperledger.besu.consensus.common.EpochManager)32 Test (org.junit.Test)19 BlockHeader (org.hyperledger.besu.ethereum.core.BlockHeader)11 Address (org.hyperledger.besu.datatypes.Address)10 BlockHeaderTestFixture (org.hyperledger.besu.ethereum.core.BlockHeaderTestFixture)8 BftValidatorOverrides (org.hyperledger.besu.consensus.common.BftValidatorOverrides)7 BlockValidatorProvider (org.hyperledger.besu.consensus.common.validator.blockbased.BlockValidatorProvider)6 GasPricePendingTransactionsSorter (org.hyperledger.besu.ethereum.eth.transactions.sorter.GasPricePendingTransactionsSorter)6 Bytes (org.apache.tuweni.bytes.Bytes)5 ValidatorProvider (org.hyperledger.besu.consensus.common.validator.ValidatorProvider)5 Block (org.hyperledger.besu.ethereum.core.Block)5 HashMap (java.util.HashMap)4 List (java.util.List)4 Before (org.junit.Before)4 CliqueBlockHeaderFunctions (org.hyperledger.besu.consensus.clique.CliqueBlockHeaderFunctions)3 CliqueExtraData (org.hyperledger.besu.consensus.clique.CliqueExtraData)3 BftBlockInterface (org.hyperledger.besu.consensus.common.bft.BftBlockInterface)3 BftContext (org.hyperledger.besu.consensus.common.bft.BftContext)3 ForkingValidatorProvider (org.hyperledger.besu.consensus.qbft.validator.ForkingValidatorProvider)3 ProtocolContext (org.hyperledger.besu.ethereum.ProtocolContext)3