Search in sources :

Example 21 with VerifiedVertex

use of com.radixdlt.hotstuff.bft.VerifiedVertex in project radixdlt by radixdlt.

the class ConsensusModuleTest method setup.

@Before
public void setup() {
    var accumulatorState = new AccumulatorState(0, HashUtils.zero256());
    var genesis = UnverifiedVertex.createGenesis(LedgerHeader.genesis(accumulatorState, null, 0));
    var hashedGenesis = new VerifiedVertex(genesis, HashUtils.zero256());
    var qc = QuorumCertificate.ofGenesis(hashedGenesis, LedgerHeader.genesis(accumulatorState, null, 0));
    this.validatorKeyPair = ECKeyPair.generateNew();
    this.validatorBftNode = BFTNode.create(this.validatorKeyPair.getPublicKey());
    var validatorSet = BFTValidatorSet.from(Stream.of(BFTValidator.from(this.validatorBftNode, UInt256.ONE)));
    var vertexStoreState = VerifiedVertexStoreState.create(HighQC.from(qc), hashedGenesis, Optional.empty(), hasher);
    var proposerElection = new WeightedRotatingLeaders(validatorSet);
    this.bftConfiguration = new BFTConfiguration(proposerElection, validatorSet, vertexStoreState);
    this.ecKeyPair = ECKeyPair.generateNew();
    this.requestSender = rmock(RemoteEventDispatcher.class);
    this.responseSender = rmock(RemoteEventDispatcher.class);
    this.errorResponseSender = rmock(RemoteEventDispatcher.class);
    Guice.createInjector(new ConsensusModule(), new CryptoModule(), getExternalModule()).injectMembers(this);
}
Also used : VerifiedVertex(com.radixdlt.hotstuff.bft.VerifiedVertex) AccumulatorState(com.radixdlt.ledger.AccumulatorState) BFTConfiguration(com.radixdlt.hotstuff.BFTConfiguration) RemoteEventDispatcher(com.radixdlt.environment.RemoteEventDispatcher) WeightedRotatingLeaders(com.radixdlt.hotstuff.liveness.WeightedRotatingLeaders) Before(org.junit.Before)

Example 22 with VerifiedVertex

use of com.radixdlt.hotstuff.bft.VerifiedVertex in project radixdlt by radixdlt.

the class ConsensusModuleTest method on_synced_to_vertex_should_request_for_parent.

@Test
public void on_synced_to_vertex_should_request_for_parent() {
    // Arrange
    BFTNode bftNode = BFTNode.random();
    QuorumCertificate parent = vertexStore.highQC().highestQC();
    Pair<QuorumCertificate, VerifiedVertex> nextVertex = createNextVertex(parent, validatorKeyPair);
    Pair<QuorumCertificate, VerifiedVertex> nextNextVertex = createNextVertex(nextVertex.getFirst(), validatorKeyPair);
    HighQC unsyncedHighQC = HighQC.from(nextNextVertex.getFirst(), nextNextVertex.getFirst(), Optional.empty());
    bftSync.syncToQC(unsyncedHighQC, bftNode);
    // Act
    // FIXME: Remove when rate limit on send removed
    nothrowSleep(100);
    GetVerticesResponse response = new GetVerticesResponse(ImmutableList.of(nextNextVertex.getSecond()));
    bftSync.responseProcessor().process(bftNode, response);
    // Assert
    verify(requestSender, times(1)).dispatch(eq(bftNode), argThat(r -> r.getCount() == 1 && r.getVertexId().equals(nextVertex.getSecond().getId())));
}
Also used : VerifiedVertex(com.radixdlt.hotstuff.bft.VerifiedVertex) HighQC(com.radixdlt.hotstuff.HighQC) Module(com.google.inject.Module) BFTHighQCUpdate(com.radixdlt.hotstuff.bft.BFTHighQCUpdate) ArgumentMatchers.argThat(org.mockito.ArgumentMatchers.argThat) ArgumentMatchers.eq(org.mockito.ArgumentMatchers.eq) Inject(com.google.inject.Inject) PersistentSafetyStateStore(com.radixdlt.hotstuff.safety.PersistentSafetyStateStore) Hasher(com.radixdlt.crypto.Hasher) HighQC(com.radixdlt.hotstuff.HighQC) VerifiedVertexStoreState(com.radixdlt.hotstuff.bft.VerifiedVertexStoreState) RemoteEventDispatcher(com.radixdlt.environment.RemoteEventDispatcher) QuorumCertificate(com.radixdlt.hotstuff.QuorumCertificate) LedgerHeader(com.radixdlt.hotstuff.LedgerHeader) Ledger(com.radixdlt.hotstuff.Ledger) 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) NextTxnsGenerator(com.radixdlt.hotstuff.liveness.NextTxnsGenerator) VerifiedVertex(com.radixdlt.hotstuff.bft.VerifiedVertex) ViewUpdate(com.radixdlt.hotstuff.bft.ViewUpdate) TimestampedECDSASignatures(com.radixdlt.hotstuff.TimestampedECDSASignatures) GetVerticesRequestRateLimit(com.radixdlt.middleware2.network.GetVerticesRequestRateLimit) PacemakerRate(com.radixdlt.hotstuff.bft.PacemakerRate) List(java.util.List) Stream(java.util.stream.Stream) PacemakerMaxExponent(com.radixdlt.hotstuff.bft.PacemakerMaxExponent) Optional(java.util.Optional) TypeLiteral(com.google.inject.TypeLiteral) Proposal(com.radixdlt.hotstuff.Proposal) ViewQuorumReached(com.radixdlt.hotstuff.bft.ViewQuorumReached) Mockito.mock(org.mockito.Mockito.mock) BFTCommittedUpdate(com.radixdlt.hotstuff.bft.BFTCommittedUpdate) BFTValidatorSet(com.radixdlt.hotstuff.bft.BFTValidatorSet) ScheduledEventDispatcher(com.radixdlt.environment.ScheduledEventDispatcher) LedgerProof(com.radixdlt.hotstuff.LedgerProof) WeightedRotatingLeaders(com.radixdlt.hotstuff.liveness.WeightedRotatingLeaders) Sha256Hasher(com.radixdlt.hotstuff.Sha256Hasher) GetVerticesResponse(com.radixdlt.hotstuff.sync.GetVerticesResponse) 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) VertexStore(com.radixdlt.hotstuff.bft.VertexStore) View(com.radixdlt.hotstuff.bft.View) ImmutableList(com.google.common.collect.ImmutableList) BFTConfiguration(com.radixdlt.hotstuff.BFTConfiguration) AccumulatorState(com.radixdlt.ledger.AccumulatorState) UInt256(com.radixdlt.utils.UInt256) Before(org.junit.Before) BFTSync(com.radixdlt.hotstuff.sync.BFTSync) BFTHeader(com.radixdlt.hotstuff.BFTHeader) 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) VoteData(com.radixdlt.hotstuff.VoteData) Mockito.times(org.mockito.Mockito.times) 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) Provides(com.google.inject.Provides) ECKeyPair(com.radixdlt.crypto.ECKeyPair) GetVerticesRequest(com.radixdlt.hotstuff.sync.GetVerticesRequest) TimestampedECDSASignature(com.radixdlt.hotstuff.TimestampedECDSASignature) BFTValidator(com.radixdlt.hotstuff.bft.BFTValidator) LocalTimeoutOccurrence(com.radixdlt.hotstuff.liveness.LocalTimeoutOccurrence) Guice(com.google.inject.Guice) Self(com.radixdlt.hotstuff.bft.Self) Pair(com.radixdlt.utils.Pair) LastProof(com.radixdlt.store.LastProof) AbstractModule(com.google.inject.AbstractModule) BFTNode(com.radixdlt.hotstuff.bft.BFTNode) GetVerticesResponse(com.radixdlt.hotstuff.sync.GetVerticesResponse) QuorumCertificate(com.radixdlt.hotstuff.QuorumCertificate) Test(org.junit.Test)

Example 23 with VerifiedVertex

use of com.radixdlt.hotstuff.bft.VerifiedVertex in project radixdlt by radixdlt.

the class MockedLedgerModule method syncedLedger.

@Provides
@Singleton
Ledger syncedLedger(TimeSupplier timeSupplier) {
    return new Ledger() {

        @Override
        public Optional<PreparedVertex> prepare(LinkedList<PreparedVertex> previous, VerifiedVertex vertex) {
            final long timestamp = vertex.getQC().getTimestampedSignatures().weightedTimestamp();
            final LedgerHeader ledgerHeader = vertex.getParentHeader().getLedgerHeader().updateViewAndTimestamp(vertex.getView(), timestamp);
            return Optional.of(vertex.withHeader(ledgerHeader, timeSupplier.currentTime()).andTxns(vertex.getTxns().stream().<PreparedTxn>map(MockPrepared::new).toList(), Map.of()));
        }
    };
}
Also used : VerifiedVertex(com.radixdlt.hotstuff.bft.VerifiedVertex) LedgerHeader(com.radixdlt.hotstuff.LedgerHeader) PreparedVertex(com.radixdlt.hotstuff.bft.PreparedVertex) Ledger(com.radixdlt.hotstuff.Ledger) LinkedList(java.util.LinkedList) Singleton(com.google.inject.Singleton) Provides(com.google.inject.Provides)

Example 24 with VerifiedVertex

use of com.radixdlt.hotstuff.bft.VerifiedVertex in project radixdlt by radixdlt.

the class StateComputerLedgerTest method should_not_change_accumulator_when_there_is_no_command.

@Test
public void should_not_change_accumulator_when_there_is_no_command() {
    // Arrange
    genesisIsEndOfEpoch(false);
    when(stateComputer.prepare(any(), any(), anyLong())).thenReturn(new StateComputerResult(ImmutableList.of(), ImmutableMap.of()));
    var unverifiedVertex = UnverifiedVertex.create(genesisQC, View.of(1), List.of(), BFTNode.random());
    var proposedVertex = new VerifiedVertex(unverifiedVertex, hasher.hash(unverifiedVertex));
    // Act
    Optional<PreparedVertex> nextPrepared = sut.prepare(new LinkedList<>(), proposedVertex);
    // Assert
    assertThat(nextPrepared).hasValueSatisfying(x -> assertThat(x.getLedgerHeader().isEndOfEpoch()).isFalse());
    assertThat(nextPrepared).hasValueSatisfying(x -> assertThat(x.getLedgerHeader().getAccumulatorState()).isEqualTo(ledgerHeader.getAccumulatorState()));
}
Also used : VerifiedVertex(com.radixdlt.hotstuff.bft.VerifiedVertex) PreparedVertex(com.radixdlt.hotstuff.bft.PreparedVertex) StateComputerResult(com.radixdlt.ledger.StateComputerLedger.StateComputerResult) Test(org.junit.Test)

Example 25 with VerifiedVertex

use of com.radixdlt.hotstuff.bft.VerifiedVertex 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)

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