use of org.hyperledger.besu.consensus.common.bft.inttest.NodeParams in project besu by hyperledger.
the class SpuriousBehaviourTest method nonValidatorsCannotTriggerResponses.
@Test
public void nonValidatorsCannotTriggerResponses() {
final NodeKey nonValidatorNodeKey = NodeKeyUtils.generate();
final NodeParams nonValidatorParams = new NodeParams(Util.publicKeyToAddress(nonValidatorNodeKey.getPublicKey()), nonValidatorNodeKey);
final ValidatorPeer nonvalidator = new ValidatorPeer(nonValidatorParams, new MessageFactory(nonValidatorParams.getNodeKey()), context.getEventMultiplexer());
nonvalidator.injectProposal(new ConsensusRoundIdentifier(1, 0), proposedBlock);
peers.verifyNoMessagesReceived();
}
use of org.hyperledger.besu.consensus.common.bft.inttest.NodeParams 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.consensus.common.bft.inttest.NodeParams 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.consensus.common.bft.inttest.NodeParams in project besu by hyperledger.
the class TestContextBuilder method build.
public TestContext build() {
final NetworkLayout networkNodes = NetworkLayout.createNetworkLayout(validatorCount, indexOfFirstLocallyProposedBlock);
final Block genesisBlock = createGenesisBlock(networkNodes.getValidatorAddresses());
final MutableBlockchain blockChain = createInMemoryBlockchain(genesisBlock, BftBlockHeaderFunctions.forOnchainBlock(IBFT_EXTRA_DATA_ENCODER));
// Use a stubbed version of the multicaster, to prevent creating PeerConnections etc.
final StubValidatorMulticaster multicaster = new StubValidatorMulticaster();
final UniqueMessageMulticaster uniqueMulticaster = new UniqueMessageMulticaster(multicaster, GOSSIPED_HISTORY_LIMIT);
final Gossiper gossiper = useGossip ? new IbftGossip(uniqueMulticaster) : mock(Gossiper.class);
final StubbedSynchronizerUpdater synchronizerUpdater = new StubbedSynchronizerUpdater();
final ControllerAndState controllerAndState = createControllerAndFinalState(blockChain, multicaster, networkNodes.getLocalNode().getNodeKey(), clock, bftEventQueue, gossiper, synchronizerUpdater, bftForks);
// Add each networkNode to the Multicaster (such that each can receive msgs from local node).
// NOTE: the remotePeers needs to be ordered based on Address (as this is used to determine
// the proposer order which must be managed in test).
final Map<Address, ValidatorPeer> remotePeers = networkNodes.getRemotePeers().stream().collect(Collectors.toMap(NodeParams::getAddress, nodeParams -> new ValidatorPeer(nodeParams, new MessageFactory(nodeParams.getNodeKey()), controllerAndState.getEventMultiplexer()), (u, v) -> {
throw new IllegalStateException(String.format("Duplicate key %s", u));
}, LinkedHashMap::new));
final List<DefaultValidatorPeer> peerCollection = new ArrayList<>(remotePeers.values());
multicaster.addNetworkPeers(peerCollection);
synchronizerUpdater.addNetworkPeers(peerCollection);
return new TestContext(remotePeers, blockChain, controllerAndState.getIbftExecutors(), controllerAndState.getEventHandler(), controllerAndState.getFinalState(), controllerAndState.getEventMultiplexer(), controllerAndState.getMessageFactory());
}
use of org.hyperledger.besu.consensus.common.bft.inttest.NodeParams in project besu by hyperledger.
the class SpuriousBehaviourTest method nonValidatorsCannotTriggerResponses.
@Test
public void nonValidatorsCannotTriggerResponses() {
final NodeKey nonValidatorNodeKey = NodeKeyUtils.generate();
final NodeParams nonValidatorParams = new NodeParams(Util.publicKeyToAddress(nonValidatorNodeKey.getPublicKey()), nonValidatorNodeKey);
final ValidatorPeer nonvalidator = new ValidatorPeer(nonValidatorParams, new MessageFactory(nonValidatorParams.getNodeKey()), context.getEventMultiplexer());
nonvalidator.injectProposal(new ConsensusRoundIdentifier(1, 0), proposedBlock);
peers.verifyNoMessagesReceived();
}
Aggregations