Search in sources :

Example 1 with MutableBftConfigOptions

use of org.hyperledger.besu.consensus.common.bft.MutableBftConfigOptions in project besu by hyperledger.

the class IbftForksSchedulesFactoryTest method createsScheduleWithForkThatOverridesGenesisValues.

@Test
public void createsScheduleWithForkThatOverridesGenesisValues() {
    final MutableBftConfigOptions configOptions = new MutableBftConfigOptions(JsonBftConfigOptions.DEFAULT);
    final ObjectNode fork = JsonUtil.objectNodeFromMap(Map.of(BftFork.FORK_BLOCK_KEY, 1, BftFork.BLOCK_PERIOD_SECONDS_KEY, 10, BftFork.BLOCK_REWARD_KEY, "5"));
    final ForksSchedule<BftConfigOptions> forksSchedule = IbftForksSchedulesFactory.create(createGenesisConfig(configOptions, fork));
    assertThat(forksSchedule.getFork(0)).usingRecursiveComparison().isEqualTo(new ForkSpec<>(0, configOptions));
    final Map<String, Object> forkOptions = new HashMap<>(configOptions.asMap());
    forkOptions.put(BftFork.BLOCK_PERIOD_SECONDS_KEY, 10);
    forkOptions.put(BftFork.BLOCK_REWARD_KEY, "5");
    final BftConfigOptions expectedForkConfig = new MutableBftConfigOptions(new JsonBftConfigOptions(JsonUtil.objectNodeFromMap(forkOptions)));
    final ForkSpec<BftConfigOptions> expectedFork = new ForkSpec<>(1, expectedForkConfig);
    assertThat(forksSchedule.getFork(1)).usingRecursiveComparison().isEqualTo(expectedFork);
    assertThat(forksSchedule.getFork(2)).usingRecursiveComparison().isEqualTo(expectedFork);
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) ForkSpec(org.hyperledger.besu.consensus.common.ForkSpec) JsonBftConfigOptions(org.hyperledger.besu.config.JsonBftConfigOptions) BftConfigOptions(org.hyperledger.besu.config.BftConfigOptions) MutableBftConfigOptions(org.hyperledger.besu.consensus.common.bft.MutableBftConfigOptions) HashMap(java.util.HashMap) MutableBftConfigOptions(org.hyperledger.besu.consensus.common.bft.MutableBftConfigOptions) JsonBftConfigOptions(org.hyperledger.besu.config.JsonBftConfigOptions) Test(org.junit.Test) BaseForksSchedulesFactoryTest(org.hyperledger.besu.consensus.common.bft.BaseForksSchedulesFactoryTest)

Example 2 with MutableBftConfigOptions

use of org.hyperledger.besu.consensus.common.bft.MutableBftConfigOptions in project besu by hyperledger.

the class ForksScheduleTest method createBftConfigOptions.

private MutableBftConfigOptions createBftConfigOptions(final int blockPeriodSeconds) {
    final MutableBftConfigOptions bftConfigOptions = new MutableBftConfigOptions(JsonBftConfigOptions.DEFAULT);
    bftConfigOptions.setBlockPeriodSeconds(blockPeriodSeconds);
    return bftConfigOptions;
}
Also used : MutableBftConfigOptions(org.hyperledger.besu.consensus.common.bft.MutableBftConfigOptions)

Example 3 with MutableBftConfigOptions

use of org.hyperledger.besu.consensus.common.bft.MutableBftConfigOptions in project besu by hyperledger.

the class IbftForksSchedulesFactory method createBftConfigOptions.

private static BftConfigOptions createBftConfigOptions(final ForkSpec<BftConfigOptions> lastSpec, final BftFork fork) {
    final MutableBftConfigOptions bftConfigOptions = new MutableBftConfigOptions(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());
    }
    return bftConfigOptions;
}
Also used : MutableBftConfigOptions(org.hyperledger.besu.consensus.common.bft.MutableBftConfigOptions)

Example 4 with MutableBftConfigOptions

use of org.hyperledger.besu.consensus.common.bft.MutableBftConfigOptions in project besu by hyperledger.

the class IbftForksSchedulesFactoryTest method createBftOptions.

@Override
protected BftConfigOptions createBftOptions(final Consumer<MutableBftConfigOptions> optionModifier) {
    final MutableBftConfigOptions options = new MutableBftConfigOptions(JsonBftConfigOptions.DEFAULT);
    optionModifier.accept(options);
    return options;
}
Also used : MutableBftConfigOptions(org.hyperledger.besu.consensus.common.bft.MutableBftConfigOptions)

Example 5 with MutableBftConfigOptions

use of org.hyperledger.besu.consensus.common.bft.MutableBftConfigOptions in project besu by hyperledger.

the class IbftProtocolScheduleTest method blockModeTransitionsCreatesBlockModeHeaderValidators.

@Test
public void blockModeTransitionsCreatesBlockModeHeaderValidators() {
    final MutableBftConfigOptions arbitraryTransition = new MutableBftConfigOptions(JsonQbftConfigOptions.DEFAULT);
    arbitraryTransition.setBlockRewardWei(BigInteger.ONE);
    final BlockHeader parentHeader = IbftBlockHeaderUtils.createPresetHeaderBuilder(1, proposerNodeKey, validators, null).buildHeader();
    final BlockHeader blockHeader = IbftBlockHeaderUtils.createPresetHeaderBuilder(2, proposerNodeKey, validators, parentHeader).buildHeader();
    final ProtocolSchedule schedule = createProtocolSchedule(JsonGenesisConfigOptions.fromJsonObject(JsonUtil.createEmptyObjectNode()), List.of(new ForkSpec<>(0, JsonQbftConfigOptions.DEFAULT), new ForkSpec<>(1, arbitraryTransition), new ForkSpec<>(2, JsonQbftConfigOptions.DEFAULT)));
    assertThat(schedule.streamMilestoneBlocks().count()).isEqualTo(3);
    assertThat(validateHeader(schedule, validators, parentHeader, blockHeader, 0)).isTrue();
    assertThat(validateHeader(schedule, validators, parentHeader, blockHeader, 1)).isTrue();
    assertThat(validateHeader(schedule, validators, parentHeader, blockHeader, 2)).isTrue();
}
Also used : ForkSpec(org.hyperledger.besu.consensus.common.ForkSpec) MutableBftConfigOptions(org.hyperledger.besu.consensus.common.bft.MutableBftConfigOptions) BlockHeader(org.hyperledger.besu.ethereum.core.BlockHeader) ProtocolSchedule(org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule) Test(org.junit.Test)

Aggregations

MutableBftConfigOptions (org.hyperledger.besu.consensus.common.bft.MutableBftConfigOptions)6 ForkSpec (org.hyperledger.besu.consensus.common.ForkSpec)2 Test (org.junit.Test)2 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)1 HashMap (java.util.HashMap)1 BftConfigOptions (org.hyperledger.besu.config.BftConfigOptions)1 JsonBftConfigOptions (org.hyperledger.besu.config.JsonBftConfigOptions)1 BaseForksSchedulesFactoryTest (org.hyperledger.besu.consensus.common.bft.BaseForksSchedulesFactoryTest)1 BlockHeader (org.hyperledger.besu.ethereum.core.BlockHeader)1 ProtocolSchedule (org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule)1