use of org.hyperledger.besu.config.QbftFork in project besu by hyperledger.
the class ValidatorContractTest method transitionsFromValidatorContractModeToValidatorContractMode.
@Test
public void transitionsFromValidatorContractModeToValidatorContractMode() {
final List<QbftFork> qbftForks = List.of(createContractFork(1, NEW_VALIDATOR_CONTRACT_ADDRESS));
final TestContext context = new TestContextBuilder().indexOfFirstLocallyProposedBlock(1).nodeParams(List.of(new NodeParams(NODE_ADDRESS, NodeKeyUtils.createFrom(NODE_PRIVATE_KEY)), new NodeParams(NODE_2_ADDRESS, NodeKeyUtils.createFrom(NODE_2_PRIVATE_KEY)))).clock(clock).genesisFile(Resources.getResource("genesis_validator_contract.json").getFile()).useValidatorContract(true).qbftForks(qbftForks).buildAndStart();
// block 0 uses validator contract with 1 validator
// block 1 uses validator contract with 2 validators
final List<Address> block0Addresses = List.of(NODE_ADDRESS);
final List<Address> block1Addresses = Stream.of(NODE_ADDRESS, NODE_2_ADDRESS).sorted().collect(Collectors.toList());
remotePeerProposesNewBlock(context, 1L);
final ValidatorProvider validatorProvider = context.getValidatorProvider();
final BlockHeader genesisBlock = context.getBlockchain().getBlockHeader(0).get();
final BlockHeader block1 = context.getBlockchain().getBlockHeader(1).get();
// contract block extra data cannot contain validators or vote
assertThat(validatorProvider.getValidatorsForBlock(genesisBlock)).isEqualTo(block0Addresses);
assertThat(extraDataCodec.decode(genesisBlock).getValidators()).isEmpty();
assertThat(extraDataCodec.decode(genesisBlock).getVote()).isEmpty();
// contract block extra data cannot contain validators or vote
assertThat(validatorProvider.getValidatorsForBlock(block1)).isEqualTo(block1Addresses);
assertThat(extraDataCodec.decode(block1).getValidators()).isEmpty();
assertThat(extraDataCodec.decode(block1).getVote()).isEmpty();
}
use of org.hyperledger.besu.config.QbftFork in project besu by hyperledger.
the class ValidatorContractTest method transitionsFromValidatorContractModeToBlockHeaderMode.
@Test
public void transitionsFromValidatorContractModeToBlockHeaderMode() {
final List<QbftFork> qbftForks = List.of(createBlockHeaderFork(1, List.of(NODE_ADDRESS, NODE_2_ADDRESS)));
final TestContext context = new TestContextBuilder().indexOfFirstLocallyProposedBlock(0).nodeParams(List.of(new NodeParams(NODE_ADDRESS, NodeKeyUtils.createFrom(NODE_PRIVATE_KEY)), new NodeParams(NODE_2_ADDRESS, NodeKeyUtils.createFrom(NODE_2_PRIVATE_KEY)))).clock(clock).genesisFile(Resources.getResource("genesis_validator_contract.json").getFile()).useValidatorContract(true).qbftForks(qbftForks).buildAndStart();
// block 0 uses validator contract with 1 validator
// block 1 onwards uses block header voting with 2 overridden validators
// block 2 uses block header voting with the cached validators
final List<Address> block0Addresses = Stream.of(NODE_ADDRESS).collect(Collectors.toList());
final List<Address> block1Addresses = Stream.of(NODE_ADDRESS, NODE_2_ADDRESS).sorted().collect(Collectors.toList());
createNewBlockAsProposer(context, 1);
clock.step(TestContextBuilder.BLOCK_TIMER_SEC, SECONDS);
remotePeerProposesNewBlock(context, 2L);
final ValidatorProvider validatorProvider = context.getValidatorProvider();
final BlockHeader genesisBlock = context.getBlockchain().getBlockHeader(0).get();
final BlockHeader block1 = context.getBlockchain().getBlockHeader(1).get();
final BlockHeader block2 = context.getBlockchain().getBlockHeader(2).get();
// contract block extra data cannot contain validators or vote
assertThat(validatorProvider.getValidatorsForBlock(genesisBlock)).isEqualTo(block0Addresses);
assertThat(extraDataCodec.decode(genesisBlock).getValidators()).isEmpty();
assertThat(extraDataCodec.decode(genesisBlock).getVote()).isEmpty();
// uses overridden validators
assertThat(validatorProvider.getValidatorsForBlock(block1)).isEqualTo(block1Addresses);
assertThat(extraDataCodec.decode(block1).getValidators()).containsExactly(NODE_2_ADDRESS, NODE_ADDRESS);
// uses cached validators
assertThat(validatorProvider.getValidatorsForBlock(block2)).isEqualTo(block1Addresses);
assertThat(extraDataCodec.decode(block2).getValidators()).containsExactly(NODE_2_ADDRESS, NODE_ADDRESS);
}
use of org.hyperledger.besu.config.QbftFork in project besu by hyperledger.
the class TransitionsTest method transitionsBlockPeriod.
@Test
public void transitionsBlockPeriod() throws InterruptedException {
final TestClock clock = new TestClock(Instant.EPOCH);
final List<QbftFork> qbftForks = List.of(new QbftFork(JsonUtil.objectNodeFromMap(Map.of(BftFork.FORK_BLOCK_KEY, 1, BftFork.BLOCK_PERIOD_SECONDS_KEY, 10))), new QbftFork(JsonUtil.objectNodeFromMap(Map.of(BftFork.FORK_BLOCK_KEY, 2, BftFork.BLOCK_PERIOD_SECONDS_KEY, 20))));
final BftEventQueue bftEventQueue = new BftEventQueue(TestContextBuilder.MESSAGE_QUEUE_LIMIT);
final TestContext context = new TestContextBuilder().indexOfFirstLocallyProposedBlock(0).validatorCount(1).clock(clock).qbftForks(qbftForks).eventQueue(bftEventQueue).buildAndStart();
clock.stepMillis(10_000);
context.getEventMultiplexer().handleBftEvent(bftEventQueue.poll(1, TimeUnit.SECONDS));
context.getController().handleNewBlockEvent(new NewChainHead(context.getBlockchain().getChainHeadHeader()));
clock.stepMillis(20_000);
context.getEventMultiplexer().handleBftEvent(bftEventQueue.poll(1, TimeUnit.SECONDS));
final BlockHeader genesisBlock = context.getBlockchain().getBlockHeader(0).get();
final BlockHeader blockHeader1 = context.getBlockchain().getBlockHeader(1).get();
final BlockHeader blockHeader2 = context.getBlockchain().getBlockHeader(2).get();
assertThat(blockHeader1.getTimestamp()).isEqualTo(genesisBlock.getTimestamp() + 10);
assertThat(blockHeader2.getTimestamp()).isEqualTo(blockHeader1.getTimestamp() + 20);
}
use of org.hyperledger.besu.config.QbftFork in project besu by hyperledger.
the class ValidatorContractTest method transitionsFromValidatorContractModeToBlockHeaderModeThenBackToNewContract.
@Test
public void transitionsFromValidatorContractModeToBlockHeaderModeThenBackToNewContract() {
final List<QbftFork> qbftForks = List.of(createBlockHeaderFork(1, List.of(NODE_2_ADDRESS)), createContractFork(2, NEW_VALIDATOR_CONTRACT_ADDRESS));
final TestContext context = new TestContextBuilder().indexOfFirstLocallyProposedBlock(0).nodeParams(List.of(new NodeParams(NODE_ADDRESS, NodeKeyUtils.createFrom(NODE_PRIVATE_KEY)), new NodeParams(NODE_2_ADDRESS, NodeKeyUtils.createFrom(NODE_2_PRIVATE_KEY)))).clock(clock).genesisFile(Resources.getResource("genesis_validator_contract.json").getFile()).useValidatorContract(true).qbftForks(qbftForks).buildAndStart();
// block 0 uses validator contract with 1 validator
// block 1 uses block header voting with 1 overridden validator
// block 2 uses validator contract with 2 validators
final List<Address> block0Addresses = List.of(NODE_ADDRESS);
final List<Address> block1Addresses = List.of(NODE_2_ADDRESS);
final List<Address> block2Addresses = Stream.of(NODE_ADDRESS, NODE_2_ADDRESS).sorted().collect(Collectors.toList());
createNewBlockAsProposer(context, 1L);
clock.step(TestContextBuilder.BLOCK_TIMER_SEC, SECONDS);
remotePeerProposesNewBlock(context, 2L);
final ValidatorProvider validatorProvider = context.getValidatorProvider();
final BlockHeader genesisBlock = context.getBlockchain().getBlockHeader(0).get();
final BlockHeader block1 = context.getBlockchain().getBlockHeader(1).get();
final BlockHeader block2 = context.getBlockchain().getBlockHeader(2).get();
// contract block extra data cannot contain validators or vote
assertThat(validatorProvider.getValidatorsForBlock(genesisBlock)).isEqualTo(block0Addresses);
assertThat(extraDataCodec.decode(genesisBlock).getValidators()).isEmpty();
assertThat(extraDataCodec.decode(genesisBlock).getVote()).isEmpty();
assertThat(validatorProvider.getValidatorsForBlock(block1)).isEqualTo(block1Addresses);
assertThat(extraDataCodec.decode(block1).getValidators()).containsExactly(NODE_2_ADDRESS);
// contract block extra data cannot contain validators or vote
assertThat(validatorProvider.getValidatorsForBlock(block2)).isEqualTo(block2Addresses);
assertThat(extraDataCodec.decode(block2).getValidators()).isEmpty();
assertThat(extraDataCodec.decode(block2).getVote()).isEmpty();
}
use of org.hyperledger.besu.config.QbftFork in project besu by hyperledger.
the class ValidatorContractTest method transitionsFromBlockHeaderModeToValidatorContractMode.
@Test
public void transitionsFromBlockHeaderModeToValidatorContractMode() {
final List<QbftFork> qbftForks = List.of(createContractFork(1, TestContextBuilder.VALIDATOR_CONTRACT_ADDRESS));
final TestContext context = new TestContextBuilder().indexOfFirstLocallyProposedBlock(1).nodeParams(List.of(new NodeParams(NODE_ADDRESS, NodeKeyUtils.createFrom(NODE_PRIVATE_KEY)), new NodeParams(NODE_2_ADDRESS, NodeKeyUtils.createFrom(NODE_2_PRIVATE_KEY)))).clock(TestClock.fixed()).genesisFile(Resources.getResource("genesis_migrating_validator_contract.json").getFile()).useValidatorContract(false).qbftForks(qbftForks).buildAndStart();
// block 0 uses block header voting with 1 validator
// block 1 onwards uses validator contract with 2 validators
final List<Address> block0Addresses = List.of(NODE_ADDRESS);
final List<Address> block1Addresses = Stream.of(NODE_ADDRESS, NODE_2_ADDRESS).sorted().collect(Collectors.toList());
remotePeerProposesNewBlock(context, 1L);
final ValidatorProvider validatorProvider = context.getValidatorProvider();
final BlockHeader genesisBlock = context.getBlockchain().getBlockHeader(0).get();
final BlockHeader block1 = context.getBlockchain().getBlockHeader(1).get();
assertThat(validatorProvider.getValidatorsForBlock(genesisBlock)).isEqualTo(block0Addresses);
assertThat(extraDataCodec.decode(genesisBlock).getValidators()).containsExactly(NODE_ADDRESS);
// contract block extra data cannot contain validators or vote
assertThat(validatorProvider.getValidatorsForBlock(block1)).isEqualTo(block1Addresses);
assertThat(extraDataCodec.decode(block1).getValidators()).isEmpty();
assertThat(extraDataCodec.decode(block1).getVote()).isEmpty();
}
Aggregations