use of com.radixdlt.consensus.bft.VerifiedVertex in project radixdlt by radixdlt.
the class RadixEngineStateComputerTest method executing_epoch_high_view_should_return_next_validator_set.
@Test
public void executing_epoch_high_view_should_return_next_validator_set() {
// Arrange
var qc = mock(QuorumCertificate.class);
var parentHeader = mock(BFTHeader.class);
when(parentHeader.getView()).thenReturn(View.of(0));
when(qc.getProposed()).thenReturn(parentHeader);
var unverified = UnverifiedVertex.create(qc, View.of(11), List.of(), BFTNode.random());
var vertex = new VerifiedVertex(unverified, mock(HashCode.class));
// Act
StateComputerResult result = sut.prepare(List.of(), vertex, 0);
// Assert
assertThat(result.getSuccessfulCommands()).hasSize(1);
assertThat(result.getFailedCommands()).isEmpty();
assertThat(result.getNextValidatorSet()).hasValueSatisfying(set -> assertThat(set.getValidators()).isNotEmpty().allMatch(v -> v.getNode().getKey().equals(unregisteredNode.getPublicKey()) || registeredNodes.stream().anyMatch(k -> k.getPublicKey().equals(v.getNode().getKey()))));
}
use of com.radixdlt.consensus.bft.VerifiedVertex in project radixdlt by radixdlt.
the class RadixEngineStateComputerTest method executing_epoch_high_view_with_register_should_not_return_new_next_validator_set.
@Test
public void executing_epoch_high_view_with_register_should_not_return_new_next_validator_set() throws Exception {
// Arrange
ECKeyPair keyPair = ECKeyPair.generateNew();
var txn = registerCommand(keyPair);
BFTNode node = BFTNode.create(keyPair.getPublicKey());
var qc = mock(QuorumCertificate.class);
var parentHeader = mock(BFTHeader.class);
when(parentHeader.getView()).thenReturn(View.of(0));
when(qc.getProposed()).thenReturn(parentHeader);
var v = UnverifiedVertex.create(qc, View.of(11), List.of(txn), BFTNode.random());
var vertex = new VerifiedVertex(v, mock(HashCode.class));
// Act
StateComputerResult result = sut.prepare(List.of(), vertex, 0);
// Assert
assertThat(result.getSuccessfulCommands()).hasSize(// since high view, command is not executed
1);
assertThat(result.getNextValidatorSet()).hasValueSatisfying(s -> {
assertThat(s.getValidators()).hasSize(2);
assertThat(s.getValidators()).extracting(BFTValidator::getNode).doesNotContain(node);
});
}
use of com.radixdlt.consensus.bft.VerifiedVertex in project radixdlt by radixdlt.
the class RadixEngineStateComputerTest method preparing_system_update_from_vertex_should_fail.
@Test
public void preparing_system_update_from_vertex_should_fail() throws TxBuilderException {
// Arrange
var txn = radixEngine.construct(new NextRound(1, false, 0, i -> proposerElection.getProposer(View.of(i)).getKey())).buildWithoutSignature();
var illegalTxn = TxLowLevelBuilder.newBuilder(rules.serialization()).down(SubstateId.ofSubstate(txn.getId(), 1)).up(new RoundData(2, 0)).end().build();
var v = UnverifiedVertex.create(mock(QuorumCertificate.class), View.of(1), List.of(illegalTxn), proposerElection.getProposer(View.of(1)));
var vertex = new VerifiedVertex(v, mock(HashCode.class));
// Act
var result = sut.prepare(ImmutableList.of(), vertex, 0);
// Assert
assertThat(result.getSuccessfulCommands()).hasSize(1);
assertThat(result.getFailedCommands()).hasValueSatisfying(new Condition<>(e -> {
var ex = (RadixEngineException) e;
var cmException = (ConstraintMachineException) ex.getCause();
return cmException.getCause() instanceof InvalidPermissionException;
}, "Is invalid_execution_permission error"));
}
use of com.radixdlt.consensus.bft.VerifiedVertex in project radixdlt by radixdlt.
the class MockedRecoveryModule method configuration.
@Provides
private BFTConfiguration configuration(@LastEpochProof LedgerProof proof, BFTValidatorSet validatorSet, Hasher hasher) {
var accumulatorState = new AccumulatorState(0, genesisHash);
UnverifiedVertex genesis = UnverifiedVertex.createGenesis(LedgerHeader.genesis(accumulatorState, validatorSet, 0));
VerifiedVertex verifiedGenesis = new VerifiedVertex(genesis, genesisHash);
LedgerHeader nextLedgerHeader = LedgerHeader.create(proof.getEpoch() + 1, View.genesis(), proof.getAccumulatorState(), proof.timestamp());
var genesisQC = QuorumCertificate.ofGenesis(verifiedGenesis, nextLedgerHeader);
var proposerElection = new WeightedRotatingLeaders(validatorSet);
return new BFTConfiguration(proposerElection, validatorSet, VerifiedVertexStoreState.create(HighQC.from(genesisQC), verifiedGenesis, Optional.empty(), hasher));
}
use of com.radixdlt.consensus.bft.VerifiedVertex in project radixdlt by radixdlt.
the class EpochManagerTest method should_not_send_consensus_messages_if_not_part_of_new_epoch.
@Test
public void should_not_send_consensus_messages_if_not_part_of_new_epoch() {
// Arrange
epochManager.start();
BFTValidatorSet nextValidatorSet = BFTValidatorSet.from(Stream.of(BFTValidator.from(BFTNode.random(), UInt256.ONE)));
var accumulatorState = new AccumulatorState(0, HashUtils.zero256());
LedgerHeader header = LedgerHeader.genesis(accumulatorState, nextValidatorSet, 0);
UnverifiedVertex genesisVertex = UnverifiedVertex.createGenesis(header);
VerifiedVertex verifiedGenesisVertex = new VerifiedVertex(genesisVertex, hasher.hash(genesisVertex));
LedgerHeader nextLedgerHeader = LedgerHeader.create(header.getEpoch() + 1, View.genesis(), header.getAccumulatorState(), header.timestamp());
var genesisQC = QuorumCertificate.ofGenesis(verifiedGenesisVertex, nextLedgerHeader);
var proposerElection = new WeightedRotatingLeaders(nextValidatorSet);
var bftConfiguration = new BFTConfiguration(proposerElection, nextValidatorSet, VerifiedVertexStoreState.create(HighQC.from(genesisQC), verifiedGenesisVertex, Optional.empty(), hasher));
LedgerProof proof = mock(LedgerProof.class);
when(proof.getEpoch()).thenReturn(header.getEpoch() + 1);
var epochChange = new EpochChange(proof, bftConfiguration);
var ledgerUpdate = new LedgerUpdate(mock(VerifiedTxnsAndProof.class), ImmutableClassToInstanceMap.of(EpochChange.class, epochChange));
// Act
epochManager.epochsLedgerUpdateEventProcessor().process(ledgerUpdate);
// Assert
verify(proposalDispatcher, never()).dispatch(any(Iterable.class), argThat(p -> p.getEpoch() == epochChange.getEpoch()));
verify(voteDispatcher, never()).dispatch(any(BFTNode.class), any());
}
Aggregations