Search in sources :

Example 6 with UnverifiedVertex

use of com.radixdlt.hotstuff.UnverifiedVertex 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());
}
Also used : LedgerUpdate(com.radixdlt.ledger.LedgerUpdate) Module(com.google.inject.Module) BFTHighQCUpdate(com.radixdlt.hotstuff.bft.BFTHighQCUpdate) ArgumentMatchers.argThat(org.mockito.ArgumentMatchers.argThat) Inject(com.google.inject.Inject) PersistentSafetyStateStore(com.radixdlt.hotstuff.safety.PersistentSafetyStateStore) Hasher(com.radixdlt.crypto.Hasher) HighQC(com.radixdlt.hotstuff.HighQC) EpochLocalTimeoutOccurrence(com.radixdlt.hotstuff.liveness.EpochLocalTimeoutOccurrence) VerifiedVertexStoreState(com.radixdlt.hotstuff.bft.VerifiedVertexStoreState) MempoolAdd(com.radixdlt.mempool.MempoolAdd) RemoteEventDispatcher(com.radixdlt.environment.RemoteEventDispatcher) QuorumCertificate(com.radixdlt.hotstuff.QuorumCertificate) LedgerHeader(com.radixdlt.hotstuff.LedgerHeader) EpochsConsensusModule(com.radixdlt.modules.EpochsConsensusModule) VerifiedTxnsAndProof(com.radixdlt.ledger.VerifiedTxnsAndProof) Map(java.util.Map) PersistentVertexStore(com.radixdlt.hotstuff.bft.PersistentVertexStore) PacemakerTimeout(com.radixdlt.hotstuff.bft.PacemakerTimeout) GetVerticesErrorResponse(com.radixdlt.hotstuff.sync.GetVerticesErrorResponse) BFTRebuildUpdate(com.radixdlt.hotstuff.bft.BFTRebuildUpdate) HashUtils(com.radixdlt.crypto.HashUtils) BFTSyncPatienceMillis(com.radixdlt.hotstuff.sync.BFTSyncPatienceMillis) BFTInsertUpdate(com.radixdlt.hotstuff.bft.BFTInsertUpdate) SystemCounters(com.radixdlt.counters.SystemCounters) Vote(com.radixdlt.hotstuff.Vote) ConsensusModule(com.radixdlt.modules.ConsensusModule) NextTxnsGenerator(com.radixdlt.hotstuff.liveness.NextTxnsGenerator) StateComputerResult(com.radixdlt.ledger.StateComputerLedger.StateComputerResult) VerifiedVertex(com.radixdlt.hotstuff.bft.VerifiedVertex) ViewUpdate(com.radixdlt.hotstuff.bft.ViewUpdate) StateComputer(com.radixdlt.ledger.StateComputerLedger.StateComputer) GetVerticesRequestRateLimit(com.radixdlt.middleware2.network.GetVerticesRequestRateLimit) PacemakerRate(com.radixdlt.hotstuff.bft.PacemakerRate) SystemCountersImpl(com.radixdlt.counters.SystemCountersImpl) List(java.util.List) Stream(java.util.stream.Stream) PacemakerMaxExponent(com.radixdlt.hotstuff.bft.PacemakerMaxExponent) LedgerModule(com.radixdlt.modules.LedgerModule) Optional(java.util.Optional) ImmutableClassToInstanceMap(com.google.common.collect.ImmutableClassToInstanceMap) TypeLiteral(com.google.inject.TypeLiteral) Proposal(com.radixdlt.hotstuff.Proposal) ViewQuorumReached(com.radixdlt.hotstuff.bft.ViewQuorumReached) Mockito.mock(org.mockito.Mockito.mock) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) BFTCommittedUpdate(com.radixdlt.hotstuff.bft.BFTCommittedUpdate) CryptoModule(com.radixdlt.modules.CryptoModule) BFTValidatorSet(com.radixdlt.hotstuff.bft.BFTValidatorSet) ScheduledEventDispatcher(com.radixdlt.environment.ScheduledEventDispatcher) LedgerProof(com.radixdlt.hotstuff.LedgerProof) WeightedRotatingLeaders(com.radixdlt.hotstuff.liveness.WeightedRotatingLeaders) GetVerticesResponse(com.radixdlt.hotstuff.sync.GetVerticesResponse) PreparedTxn(com.radixdlt.ledger.StateComputerLedger.PreparedTxn) RateLimiter(com.google.common.util.concurrent.RateLimiter) TypedMocks.rmock(com.radixdlt.utils.TypedMocks.rmock) HashSigner(com.radixdlt.hotstuff.HashSigner) LocalSyncRequest(com.radixdlt.sync.messages.local.LocalSyncRequest) LedgerStatusUpdate(com.radixdlt.sync.messages.remote.LedgerStatusUpdate) View(com.radixdlt.hotstuff.bft.View) LastEpochProof(com.radixdlt.store.LastEpochProof) BFTConfiguration(com.radixdlt.hotstuff.BFTConfiguration) AccumulatorState(com.radixdlt.ledger.AccumulatorState) UInt256(com.radixdlt.utils.UInt256) Nullable(javax.annotation.Nullable) Before(org.junit.Before) TimeSupplier(com.radixdlt.utils.TimeSupplier) EventDispatcher(com.radixdlt.environment.EventDispatcher) ScheduledLocalTimeout(com.radixdlt.hotstuff.liveness.ScheduledLocalTimeout) NoVote(com.radixdlt.hotstuff.bft.NoVote) Txn(com.radixdlt.atom.Txn) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) Mockito.verify(org.mockito.Mockito.verify) UnverifiedVertex(com.radixdlt.hotstuff.UnverifiedVertex) BFTNode(com.radixdlt.hotstuff.bft.BFTNode) VertexRequestTimeout(com.radixdlt.hotstuff.sync.VertexRequestTimeout) LedgerUpdate(com.radixdlt.ledger.LedgerUpdate) Consumer(java.util.function.Consumer) Mockito.never(org.mockito.Mockito.never) Provides(com.google.inject.Provides) ECKeyPair(com.radixdlt.crypto.ECKeyPair) GetVerticesRequest(com.radixdlt.hotstuff.sync.GetVerticesRequest) BFTValidator(com.radixdlt.hotstuff.bft.BFTValidator) LocalTimeoutOccurrence(com.radixdlt.hotstuff.liveness.LocalTimeoutOccurrence) Guice(com.google.inject.Guice) Self(com.radixdlt.hotstuff.bft.Self) Mempool(com.radixdlt.mempool.Mempool) LastProof(com.radixdlt.store.LastProof) AbstractModule(com.google.inject.AbstractModule) BFTNode(com.radixdlt.hotstuff.bft.BFTNode) AccumulatorState(com.radixdlt.ledger.AccumulatorState) BFTValidatorSet(com.radixdlt.hotstuff.bft.BFTValidatorSet) UnverifiedVertex(com.radixdlt.hotstuff.UnverifiedVertex) VerifiedVertex(com.radixdlt.hotstuff.bft.VerifiedVertex) LedgerHeader(com.radixdlt.hotstuff.LedgerHeader) BFTConfiguration(com.radixdlt.hotstuff.BFTConfiguration) VerifiedTxnsAndProof(com.radixdlt.ledger.VerifiedTxnsAndProof) LedgerProof(com.radixdlt.hotstuff.LedgerProof) WeightedRotatingLeaders(com.radixdlt.hotstuff.liveness.WeightedRotatingLeaders) Test(org.junit.Test)

Example 7 with UnverifiedVertex

use of com.radixdlt.hotstuff.UnverifiedVertex in project radixdlt by radixdlt.

the class StateComputerLedgerTest method should_accumulate_when_next_command_valid.

@Test
public void should_accumulate_when_next_command_valid() {
    // Arrange
    genesisIsEndOfEpoch(false);
    when(stateComputer.prepare(any(), any(), anyLong())).thenReturn(new StateComputerResult(ImmutableList.of(successfulNextCommand), ImmutableMap.of()));
    // Act
    var unverifiedVertex = UnverifiedVertex.create(genesisQC, View.of(1), List.of(nextTxn), BFTNode.random());
    var proposedVertex = new VerifiedVertex(unverifiedVertex, hasher.hash(unverifiedVertex));
    Optional<PreparedVertex> nextPrepared = sut.prepare(new LinkedList<>(), proposedVertex);
    // Assert
    assertThat(nextPrepared).hasValueSatisfying(x -> assertThat(x.getLedgerHeader().isEndOfEpoch()).isFalse());
    assertThat(nextPrepared.flatMap(x -> accumulatorVerifier.verifyAndGetExtension(ledgerHeader.getAccumulatorState(), List.of(nextTxn), txn -> txn.getId().asHashCode(), x.getLedgerHeader().getAccumulatorState()))).contains(List.of(nextTxn));
}
Also used : VerifiedVertex(com.radixdlt.hotstuff.bft.VerifiedVertex) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) ArgumentMatchers.anyLong(org.mockito.ArgumentMatchers.anyLong) BFTValidatorSet(com.radixdlt.hotstuff.bft.BFTValidatorSet) LedgerProof(com.radixdlt.hotstuff.LedgerProof) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) TypedMocks(com.radixdlt.utils.TypedMocks) Hasher(com.radixdlt.crypto.Hasher) Sha256Hasher(com.radixdlt.hotstuff.Sha256Hasher) PreparedTxn(com.radixdlt.ledger.StateComputerLedger.PreparedTxn) QuorumCertificate(com.radixdlt.hotstuff.QuorumCertificate) PreparedVertex(com.radixdlt.hotstuff.bft.PreparedVertex) LedgerHeader(com.radixdlt.hotstuff.LedgerHeader) View(com.radixdlt.hotstuff.bft.View) ImmutableList(com.google.common.collect.ImmutableList) LinkedList(java.util.LinkedList) HashUtils(com.radixdlt.crypto.HashUtils) UInt256(com.radixdlt.utils.UInt256) Before(org.junit.Before) SystemCounters(com.radixdlt.counters.SystemCounters) TimeSupplier(com.radixdlt.utils.TimeSupplier) ImmutableMap(com.google.common.collect.ImmutableMap) Txn(com.radixdlt.atom.Txn) StateComputerResult(com.radixdlt.ledger.StateComputerLedger.StateComputerResult) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) VerifiedVertex(com.radixdlt.hotstuff.bft.VerifiedVertex) StateComputer(com.radixdlt.ledger.StateComputerLedger.StateComputer) TimestampedECDSASignatures(com.radixdlt.hotstuff.TimestampedECDSASignatures) Mockito.verify(org.mockito.Mockito.verify) UnverifiedVertex(com.radixdlt.hotstuff.UnverifiedVertex) BFTNode(com.radixdlt.hotstuff.bft.BFTNode) Mockito.never(org.mockito.Mockito.never) List(java.util.List) Stream(java.util.stream.Stream) BFTValidator(com.radixdlt.hotstuff.bft.BFTValidator) Pair(com.radixdlt.utils.Pair) Optional(java.util.Optional) Mempool(com.radixdlt.mempool.Mempool) Comparator(java.util.Comparator) Mockito.mock(org.mockito.Mockito.mock) PreparedVertex(com.radixdlt.hotstuff.bft.PreparedVertex) StateComputerResult(com.radixdlt.ledger.StateComputerLedger.StateComputerResult) Test(org.junit.Test)

Example 8 with UnverifiedVertex

use of com.radixdlt.hotstuff.UnverifiedVertex in project radixdlt by radixdlt.

the class GetVerticesResponseMessageSerializeTest method get.

private static GetVerticesResponseMessage get() {
    LedgerHeader ledgerHeader = LedgerHeaderMock.get();
    UnverifiedVertex genesisVertex = UnverifiedVertex.createGenesis(ledgerHeader);
    return new GetVerticesResponseMessage(ImmutableList.of(genesisVertex));
}
Also used : LedgerHeader(com.radixdlt.hotstuff.LedgerHeader) UnverifiedVertex(com.radixdlt.hotstuff.UnverifiedVertex)

Example 9 with UnverifiedVertex

use of com.radixdlt.hotstuff.UnverifiedVertex in project radixdlt by radixdlt.

the class DifferentTimestampsCauseTimeoutTest method mutateProposal.

private Proposal mutateProposal(Proposal p, int destination) {
    QuorumCertificate committedQC = p.highQC().highestCommittedQC();
    UnverifiedVertex vertex = p.getVertex();
    ECDSASignature signature = p.getSignature();
    return new Proposal(mutateVertex(vertex, destination), committedQC, signature, Optional.empty());
}
Also used : QuorumCertificate(com.radixdlt.hotstuff.QuorumCertificate) ECDSASignature(com.radixdlt.crypto.ECDSASignature) TimestampedECDSASignature(com.radixdlt.hotstuff.TimestampedECDSASignature) UnverifiedVertex(com.radixdlt.hotstuff.UnverifiedVertex) Proposal(com.radixdlt.hotstuff.Proposal)

Aggregations

UnverifiedVertex (com.radixdlt.hotstuff.UnverifiedVertex)9 LedgerHeader (com.radixdlt.hotstuff.LedgerHeader)6 QuorumCertificate (com.radixdlt.hotstuff.QuorumCertificate)6 VerifiedVertex (com.radixdlt.hotstuff.bft.VerifiedVertex)5 Txn (com.radixdlt.atom.Txn)4 BFTNode (com.radixdlt.hotstuff.bft.BFTNode)4 View (com.radixdlt.hotstuff.bft.View)4 Hasher (com.radixdlt.crypto.Hasher)3 BFTConfiguration (com.radixdlt.hotstuff.BFTConfiguration)3 HighQC (com.radixdlt.hotstuff.HighQC)3 LedgerProof (com.radixdlt.hotstuff.LedgerProof)3 Proposal (com.radixdlt.hotstuff.Proposal)3 WeightedRotatingLeaders (com.radixdlt.hotstuff.liveness.WeightedRotatingLeaders)3 StateComputer (com.radixdlt.ledger.StateComputerLedger.StateComputer)3 List (java.util.List)3 Optional (java.util.Optional)3 Test (org.junit.Test)3 ImmutableClassToInstanceMap (com.google.common.collect.ImmutableClassToInstanceMap)2 Inject (com.google.inject.Inject)2 SystemCounters (com.radixdlt.counters.SystemCounters)2