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()));
}
};
}
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()));
}
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));
}
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);
}
Aggregations