use of com.radixdlt.hotstuff.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.hotstuff.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.hotstuff.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(currentForkView.currentForkConfig().engineRules().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.hotstuff.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.hotstuff.bft.VerifiedVertex in project radixdlt by radixdlt.
the class MessageCentralValidatorSync method responses.
public Flowable<RemoteEvent<GetVerticesResponse>> responses() {
return this.createFlowable(GetVerticesResponseMessage.class, (src, msg) -> {
BFTNode node = BFTNode.create(src.getPublicKey());
// TODO: Move hasher to a more appropriate place
ImmutableList<VerifiedVertex> hashedVertices = msg.getVertices().stream().map(v -> new VerifiedVertex(v, hasher.hash(v))).collect(ImmutableList.toImmutableList());
return RemoteEvent.create(node, new GetVerticesResponse(hashedVertices));
});
}
Aggregations