use of com.radixdlt.harness.simulation.network.SimulationNodes.RunningNetwork 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);
}
use of com.radixdlt.harness.simulation.network.SimulationNodes.RunningNetwork in project radixdlt by radixdlt.
the class LedgerInOrderInvariant method check.
@Override
public Observable<TestInvariantError> check(RunningNetwork network) {
Map<BFTNode, List<Txn>> commandsPerNode = new HashMap<>();
network.getNodes().forEach(n -> commandsPerNode.put(n, new ArrayList<>()));
return network.ledgerUpdates().flatMap(nodeAndCommand -> {
BFTNode node = nodeAndCommand.getFirst();
LedgerUpdate ledgerUpdate = nodeAndCommand.getSecond();
List<Txn> nodeTxns = commandsPerNode.get(node);
nodeTxns.addAll(ledgerUpdate.getNewTxns());
return commandsPerNode.values().stream().filter(list -> nodeTxns != list).filter(list -> list.size() >= nodeTxns.size()).findFirst().flatMap(list -> {
if (Collections.indexOfSubList(list, nodeTxns) != 0) {
TestInvariantError err = new TestInvariantError("Two nodes don't agree on commands: " + list + " " + nodeTxns);
return Optional.of(Observable.just(err));
}
return Optional.empty();
}).orElse(Observable.empty());
});
}
Aggregations