Search in sources :

Example 1 with VerifiedVertex

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()))));
}
Also used : VerifiedVertex(com.radixdlt.hotstuff.bft.VerifiedVertex) Module(com.google.inject.Module) SimpleLedgerAccumulatorAndVerifier(com.radixdlt.ledger.SimpleLedgerAccumulatorAndVerifier) TxAction(com.radixdlt.atom.TxAction) NoOpCommittedReader(com.radixdlt.sync.NoOpCommittedReader) ArgumentMatchers.argThat(org.mockito.ArgumentMatchers.argThat) RadixEngineException(com.radixdlt.engine.RadixEngineException) RadixEngineForksLatestOnlyModule(com.radixdlt.statecomputer.forks.RadixEngineForksLatestOnlyModule) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Inject(com.google.inject.Inject) TypedMocks(com.radixdlt.utils.TypedMocks) DefaultSerialization(com.radixdlt.DefaultSerialization) Hasher(com.radixdlt.crypto.Hasher) MempoolAdd(com.radixdlt.mempool.MempoolAdd) RoundData(com.radixdlt.application.system.state.RoundData) QuorumCertificate(com.radixdlt.hotstuff.QuorumCertificate) LedgerHeader(com.radixdlt.hotstuff.LedgerHeader) ByzantineQuorumException(com.radixdlt.ledger.ByzantineQuorumException) CurrentForkView(com.radixdlt.statecomputer.forks.CurrentForkView) VerifiedTxnsAndProof(com.radixdlt.ledger.VerifiedTxnsAndProof) PersistentVertexStore(com.radixdlt.hotstuff.bft.PersistentVertexStore) HashUtils(com.radixdlt.crypto.HashUtils) Genesis(com.radixdlt.statecomputer.checkpoint.Genesis) SystemCounters(com.radixdlt.counters.SystemCounters) NoOpForksEpochStore(com.radixdlt.statecomputer.forks.NoOpForksEpochStore) REEvent(com.radixdlt.constraintmachine.REEvent) StateComputerResult(com.radixdlt.ledger.StateComputerLedger.StateComputerResult) VerifiedVertex(com.radixdlt.hotstuff.bft.VerifiedVertex) EngineStore(com.radixdlt.store.EngineStore) TimestampedECDSASignatures(com.radixdlt.hotstuff.TimestampedECDSASignatures) Collectors(java.util.stream.Collectors) ForksEpochStore(com.radixdlt.statecomputer.forks.ForksEpochStore) SystemCountersImpl(com.radixdlt.counters.SystemCountersImpl) List(java.util.List) Stream(java.util.stream.Stream) ConstraintMachineException(com.radixdlt.constraintmachine.exceptions.ConstraintMachineException) CommittedReader(com.radixdlt.sync.CommittedReader) MainnetForksModule(com.radixdlt.statecomputer.forks.modules.MainnetForksModule) Amount(com.radixdlt.application.tokens.Amount) TypeLiteral(com.google.inject.TypeLiteral) LedgerAccumulator(com.radixdlt.ledger.LedgerAccumulator) Mockito.mock(org.mockito.Mockito.mock) BFTValidatorSet(com.radixdlt.hotstuff.bft.BFTValidatorSet) LedgerProof(com.radixdlt.hotstuff.LedgerProof) Serialization(com.radixdlt.serialization.Serialization) WeightedRotatingLeaders(com.radixdlt.hotstuff.liveness.WeightedRotatingLeaders) Sha256Hasher(com.radixdlt.hotstuff.Sha256Hasher) PermissionLevel(com.radixdlt.constraintmachine.PermissionLevel) com.radixdlt.atom(com.radixdlt.atom) ProposerElection(com.radixdlt.hotstuff.liveness.ProposerElection) MockedGenesisModule(com.radixdlt.statecomputer.checkpoint.MockedGenesisModule) View(com.radixdlt.hotstuff.bft.View) Assertions.assertThatThrownBy(org.assertj.core.api.Assertions.assertThatThrownBy) ImmutableList(com.google.common.collect.ImmutableList) MempoolConfig(com.radixdlt.mempool.MempoolConfig) AccumulatorState(com.radixdlt.ledger.AccumulatorState) RadixEngineCheckpointModule(com.radixdlt.statecomputer.checkpoint.RadixEngineCheckpointModule) UInt256(com.radixdlt.utils.UInt256) Before(org.junit.Before) MempoolAddSuccess(com.radixdlt.mempool.MempoolAddSuccess) BFTHeader(com.radixdlt.hotstuff.BFTHeader) EventDispatcher(com.radixdlt.environment.EventDispatcher) HashCode(com.google.common.hash.HashCode) RadixEngine(com.radixdlt.engine.RadixEngine) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) MempoolRelayTrigger(com.radixdlt.mempool.MempoolRelayTrigger) ForksModule(com.radixdlt.statecomputer.forks.ForksModule) Mockito.verify(org.mockito.Mockito.verify) UnverifiedVertex(com.radixdlt.hotstuff.UnverifiedVertex) BFTNode(com.radixdlt.hotstuff.bft.BFTNode) LedgerUpdate(com.radixdlt.ledger.LedgerUpdate) InMemoryEngineStore(com.radixdlt.store.InMemoryEngineStore) ECKeyPair(com.radixdlt.crypto.ECKeyPair) Rule(org.junit.Rule) Ignore(org.junit.Ignore) BFTValidator(com.radixdlt.hotstuff.bft.BFTValidator) Condition(org.assertj.core.api.Condition) Guice(com.google.inject.Guice) InvalidPermissionException(com.radixdlt.constraintmachine.exceptions.InvalidPermissionException) TemporaryFolder(org.junit.rules.TemporaryFolder) AbstractModule(com.google.inject.AbstractModule) HashCode(com.google.common.hash.HashCode) StateComputerResult(com.radixdlt.ledger.StateComputerLedger.StateComputerResult) Test(org.junit.Test)

Example 2 with VerifiedVertex

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);
    });
}
Also used : VerifiedVertex(com.radixdlt.hotstuff.bft.VerifiedVertex) BFTNode(com.radixdlt.hotstuff.bft.BFTNode) HashCode(com.google.common.hash.HashCode) ECKeyPair(com.radixdlt.crypto.ECKeyPair) StateComputerResult(com.radixdlt.ledger.StateComputerLedger.StateComputerResult) Test(org.junit.Test)

Example 3 with VerifiedVertex

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"));
}
Also used : VerifiedVertex(com.radixdlt.hotstuff.bft.VerifiedVertex) Module(com.google.inject.Module) SimpleLedgerAccumulatorAndVerifier(com.radixdlt.ledger.SimpleLedgerAccumulatorAndVerifier) TxAction(com.radixdlt.atom.TxAction) NoOpCommittedReader(com.radixdlt.sync.NoOpCommittedReader) ArgumentMatchers.argThat(org.mockito.ArgumentMatchers.argThat) RadixEngineException(com.radixdlt.engine.RadixEngineException) RadixEngineForksLatestOnlyModule(com.radixdlt.statecomputer.forks.RadixEngineForksLatestOnlyModule) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Inject(com.google.inject.Inject) TypedMocks(com.radixdlt.utils.TypedMocks) DefaultSerialization(com.radixdlt.DefaultSerialization) Hasher(com.radixdlt.crypto.Hasher) MempoolAdd(com.radixdlt.mempool.MempoolAdd) RoundData(com.radixdlt.application.system.state.RoundData) QuorumCertificate(com.radixdlt.hotstuff.QuorumCertificate) LedgerHeader(com.radixdlt.hotstuff.LedgerHeader) ByzantineQuorumException(com.radixdlt.ledger.ByzantineQuorumException) CurrentForkView(com.radixdlt.statecomputer.forks.CurrentForkView) VerifiedTxnsAndProof(com.radixdlt.ledger.VerifiedTxnsAndProof) PersistentVertexStore(com.radixdlt.hotstuff.bft.PersistentVertexStore) HashUtils(com.radixdlt.crypto.HashUtils) Genesis(com.radixdlt.statecomputer.checkpoint.Genesis) SystemCounters(com.radixdlt.counters.SystemCounters) NoOpForksEpochStore(com.radixdlt.statecomputer.forks.NoOpForksEpochStore) REEvent(com.radixdlt.constraintmachine.REEvent) StateComputerResult(com.radixdlt.ledger.StateComputerLedger.StateComputerResult) VerifiedVertex(com.radixdlt.hotstuff.bft.VerifiedVertex) EngineStore(com.radixdlt.store.EngineStore) TimestampedECDSASignatures(com.radixdlt.hotstuff.TimestampedECDSASignatures) Collectors(java.util.stream.Collectors) ForksEpochStore(com.radixdlt.statecomputer.forks.ForksEpochStore) SystemCountersImpl(com.radixdlt.counters.SystemCountersImpl) List(java.util.List) Stream(java.util.stream.Stream) ConstraintMachineException(com.radixdlt.constraintmachine.exceptions.ConstraintMachineException) CommittedReader(com.radixdlt.sync.CommittedReader) MainnetForksModule(com.radixdlt.statecomputer.forks.modules.MainnetForksModule) Amount(com.radixdlt.application.tokens.Amount) TypeLiteral(com.google.inject.TypeLiteral) LedgerAccumulator(com.radixdlt.ledger.LedgerAccumulator) Mockito.mock(org.mockito.Mockito.mock) BFTValidatorSet(com.radixdlt.hotstuff.bft.BFTValidatorSet) LedgerProof(com.radixdlt.hotstuff.LedgerProof) Serialization(com.radixdlt.serialization.Serialization) WeightedRotatingLeaders(com.radixdlt.hotstuff.liveness.WeightedRotatingLeaders) Sha256Hasher(com.radixdlt.hotstuff.Sha256Hasher) PermissionLevel(com.radixdlt.constraintmachine.PermissionLevel) com.radixdlt.atom(com.radixdlt.atom) ProposerElection(com.radixdlt.hotstuff.liveness.ProposerElection) MockedGenesisModule(com.radixdlt.statecomputer.checkpoint.MockedGenesisModule) View(com.radixdlt.hotstuff.bft.View) Assertions.assertThatThrownBy(org.assertj.core.api.Assertions.assertThatThrownBy) ImmutableList(com.google.common.collect.ImmutableList) MempoolConfig(com.radixdlt.mempool.MempoolConfig) AccumulatorState(com.radixdlt.ledger.AccumulatorState) RadixEngineCheckpointModule(com.radixdlt.statecomputer.checkpoint.RadixEngineCheckpointModule) UInt256(com.radixdlt.utils.UInt256) Before(org.junit.Before) MempoolAddSuccess(com.radixdlt.mempool.MempoolAddSuccess) BFTHeader(com.radixdlt.hotstuff.BFTHeader) EventDispatcher(com.radixdlt.environment.EventDispatcher) HashCode(com.google.common.hash.HashCode) RadixEngine(com.radixdlt.engine.RadixEngine) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) MempoolRelayTrigger(com.radixdlt.mempool.MempoolRelayTrigger) ForksModule(com.radixdlt.statecomputer.forks.ForksModule) Mockito.verify(org.mockito.Mockito.verify) UnverifiedVertex(com.radixdlt.hotstuff.UnverifiedVertex) BFTNode(com.radixdlt.hotstuff.bft.BFTNode) LedgerUpdate(com.radixdlt.ledger.LedgerUpdate) InMemoryEngineStore(com.radixdlt.store.InMemoryEngineStore) ECKeyPair(com.radixdlt.crypto.ECKeyPair) Rule(org.junit.Rule) Ignore(org.junit.Ignore) BFTValidator(com.radixdlt.hotstuff.bft.BFTValidator) Condition(org.assertj.core.api.Condition) Guice(com.google.inject.Guice) InvalidPermissionException(com.radixdlt.constraintmachine.exceptions.InvalidPermissionException) TemporaryFolder(org.junit.rules.TemporaryFolder) AbstractModule(com.google.inject.AbstractModule) InvalidPermissionException(com.radixdlt.constraintmachine.exceptions.InvalidPermissionException) HashCode(com.google.common.hash.HashCode) RoundData(com.radixdlt.application.system.state.RoundData) QuorumCertificate(com.radixdlt.hotstuff.QuorumCertificate) Test(org.junit.Test)

Example 4 with VerifiedVertex

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));
}
Also used : VerifiedVertex(com.radixdlt.hotstuff.bft.VerifiedVertex) LedgerHeader(com.radixdlt.hotstuff.LedgerHeader) AccumulatorState(com.radixdlt.ledger.AccumulatorState) BFTConfiguration(com.radixdlt.hotstuff.BFTConfiguration) UnverifiedVertex(com.radixdlt.hotstuff.UnverifiedVertex) WeightedRotatingLeaders(com.radixdlt.hotstuff.liveness.WeightedRotatingLeaders) Provides(com.google.inject.Provides)

Example 5 with VerifiedVertex

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));
    });
}
Also used : VerifiedVertex(com.radixdlt.hotstuff.bft.VerifiedVertex) Flowable(io.reactivex.rxjava3.core.Flowable) Message(org.radix.network.messaging.Message) Inject(com.google.inject.Inject) BiFunction(java.util.function.BiFunction) Hasher(com.radixdlt.crypto.Hasher) VerifiedVertex(com.radixdlt.hotstuff.bft.VerifiedVertex) GetVerticesResponse(com.radixdlt.hotstuff.sync.GetVerticesResponse) RemoteEvent(com.radixdlt.environment.rx.RemoteEvent) BFTNode(com.radixdlt.hotstuff.bft.BFTNode) Objects(java.util.Objects) RemoteEventDispatcher(com.radixdlt.environment.RemoteEventDispatcher) GetVerticesRequest(com.radixdlt.hotstuff.sync.GetVerticesRequest) ImmutableList(com.google.common.collect.ImmutableList) NodeId(com.radixdlt.network.p2p.NodeId) BackpressureStrategy(io.reactivex.rxjava3.core.BackpressureStrategy) MessageCentral(com.radixdlt.network.messaging.MessageCentral) GetVerticesErrorResponse(com.radixdlt.hotstuff.sync.GetVerticesErrorResponse) BFTNode(com.radixdlt.hotstuff.bft.BFTNode) GetVerticesResponse(com.radixdlt.hotstuff.sync.GetVerticesResponse)

Aggregations

VerifiedVertex (com.radixdlt.hotstuff.bft.VerifiedVertex)31 Test (org.junit.Test)19 HighQC (com.radixdlt.hotstuff.HighQC)15 View (com.radixdlt.hotstuff.bft.View)15 BFTHeader (com.radixdlt.hotstuff.BFTHeader)13 BFTNode (com.radixdlt.hotstuff.bft.BFTNode)13 LedgerHeader (com.radixdlt.hotstuff.LedgerHeader)12 QuorumCertificate (com.radixdlt.hotstuff.QuorumCertificate)12 Hasher (com.radixdlt.crypto.Hasher)10 UnverifiedVertex (com.radixdlt.hotstuff.UnverifiedVertex)10 Vote (com.radixdlt.hotstuff.Vote)10 AccumulatorState (com.radixdlt.ledger.AccumulatorState)10 WeightedRotatingLeaders (com.radixdlt.hotstuff.liveness.WeightedRotatingLeaders)9 Inject (com.google.inject.Inject)8 SystemCounters (com.radixdlt.counters.SystemCounters)8 ImmutableList (com.google.common.collect.ImmutableList)7 EventDispatcher (com.radixdlt.environment.EventDispatcher)7 BFTValidatorSet (com.radixdlt.hotstuff.bft.BFTValidatorSet)7 PreparedVertex (com.radixdlt.hotstuff.bft.PreparedVertex)7 HashUtils (com.radixdlt.crypto.HashUtils)6