Search in sources :

Example 6 with PreparedVertex

use of com.radixdlt.hotstuff.bft.PreparedVertex 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 7 with PreparedVertex

use of com.radixdlt.hotstuff.bft.PreparedVertex 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 8 with PreparedVertex

use of com.radixdlt.hotstuff.bft.PreparedVertex 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 9 with PreparedVertex

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

the class ConsensusToLedgerCommittedInvariant method check.

@Override
public Observable<TestInvariantError> check(RunningNetwork network) {
    BehaviorSubject<Set<Txn>> committedTxns = BehaviorSubject.create();
    Disposable d = network.ledgerUpdates().<Set<Txn>>scan(new HashSet<>(), (set, next) -> {
        set.addAll(next.getSecond().getNewTxns());
        return set;
    }).subscribe(committedTxns::onNext);
    return Observable.<BFTCommittedUpdate>create(emitter -> commits.addListener((node, event) -> emitter.onNext(event), BFTCommittedUpdate.class)).serialize().concatMap(committedUpdate -> Observable.fromStream(committedUpdate.committed().stream().flatMap(PreparedVertex::successfulCommands))).flatMapMaybe(txn -> committedTxns.filter(cmdSet -> cmdSet.contains(txn.txn())).timeout(10, TimeUnit.SECONDS).firstOrError().ignoreElement().onErrorReturn(e -> new TestInvariantError("Committed command in vertex has not been inserted into the ledger" + " after 10 seconds"))).doFinally(d::dispose);
}
Also used : Disposable(io.reactivex.rxjava3.disposables.Disposable) BFTCommittedUpdate(com.radixdlt.hotstuff.bft.BFTCommittedUpdate) HashSet(java.util.HashSet) TimeUnit(java.util.concurrent.TimeUnit) TestInvariant(com.radixdlt.harness.simulation.TestInvariant) PreparedVertex(com.radixdlt.hotstuff.bft.PreparedVertex) NodeEvents(com.radixdlt.harness.simulation.monitors.NodeEvents) Observable(io.reactivex.rxjava3.core.Observable) Disposable(io.reactivex.rxjava3.disposables.Disposable) Txn(com.radixdlt.atom.Txn) Set(java.util.Set) RunningNetwork(com.radixdlt.harness.simulation.network.SimulationNodes.RunningNetwork) BehaviorSubject(io.reactivex.rxjava3.subjects.BehaviorSubject) HashSet(java.util.HashSet) Set(java.util.Set) PreparedVertex(com.radixdlt.hotstuff.bft.PreparedVertex) BFTCommittedUpdate(com.radixdlt.hotstuff.bft.BFTCommittedUpdate) Txn(com.radixdlt.atom.Txn) HashSet(java.util.HashSet)

Aggregations

PreparedVertex (com.radixdlt.hotstuff.bft.PreparedVertex)9 VerifiedVertex (com.radixdlt.hotstuff.bft.VerifiedVertex)6 Test (org.junit.Test)5 LedgerHeader (com.radixdlt.hotstuff.LedgerHeader)4 Txn (com.radixdlt.atom.Txn)3 QuorumCertificate (com.radixdlt.hotstuff.QuorumCertificate)3 StateComputerResult (com.radixdlt.ledger.StateComputerLedger.StateComputerResult)3 Provides (com.google.inject.Provides)2 HighQC (com.radixdlt.hotstuff.HighQC)2 UnverifiedVertex (com.radixdlt.hotstuff.UnverifiedVertex)2 BFTNode (com.radixdlt.hotstuff.bft.BFTNode)2 BFTValidatorSet (com.radixdlt.hotstuff.bft.BFTValidatorSet)2 View (com.radixdlt.hotstuff.bft.View)2 LinkedList (java.util.LinkedList)2 ImmutableList (com.google.common.collect.ImmutableList)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 HashCode (com.google.common.hash.HashCode)1 AbstractModule (com.google.inject.AbstractModule)1 Singleton (com.google.inject.Singleton)1 ProvidesIntoSet (com.google.inject.multibindings.ProvidesIntoSet)1