Search in sources :

Example 1 with RunningNetwork

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);
}
Also used : Disposable(io.reactivex.rxjava3.disposables.Disposable) HashSet(java.util.HashSet) TimeUnit(java.util.concurrent.TimeUnit) TestInvariant(com.radixdlt.harness.simulation.TestInvariant) 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) BFTCommittedUpdate(com.radixdlt.consensus.bft.BFTCommittedUpdate) PreparedVertex(com.radixdlt.consensus.bft.PreparedVertex) HashSet(java.util.HashSet) Set(java.util.Set) PreparedVertex(com.radixdlt.consensus.bft.PreparedVertex) BFTCommittedUpdate(com.radixdlt.consensus.bft.BFTCommittedUpdate) Txn(com.radixdlt.atom.Txn) HashSet(java.util.HashSet)

Example 2 with RunningNetwork

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());
    });
}
Also used : LedgerUpdate(com.radixdlt.ledger.LedgerUpdate) LedgerUpdate(com.radixdlt.ledger.LedgerUpdate) TestInvariant(com.radixdlt.harness.simulation.TestInvariant) List(java.util.List) Observable(io.reactivex.rxjava3.core.Observable) Map(java.util.Map) Txn(com.radixdlt.atom.Txn) BFTNode(com.radixdlt.consensus.bft.BFTNode) Optional(java.util.Optional) RunningNetwork(com.radixdlt.harness.simulation.network.SimulationNodes.RunningNetwork) HashMap(java.util.HashMap) Collections(java.util.Collections) ArrayList(java.util.ArrayList) BFTNode(com.radixdlt.consensus.bft.BFTNode) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList) Txn(com.radixdlt.atom.Txn)

Aggregations

Txn (com.radixdlt.atom.Txn)2 TestInvariant (com.radixdlt.harness.simulation.TestInvariant)2 RunningNetwork (com.radixdlt.harness.simulation.network.SimulationNodes.RunningNetwork)2 Observable (io.reactivex.rxjava3.core.Observable)2 BFTCommittedUpdate (com.radixdlt.consensus.bft.BFTCommittedUpdate)1 BFTNode (com.radixdlt.consensus.bft.BFTNode)1 PreparedVertex (com.radixdlt.consensus.bft.PreparedVertex)1 NodeEvents (com.radixdlt.harness.simulation.monitors.NodeEvents)1 LedgerUpdate (com.radixdlt.ledger.LedgerUpdate)1 Disposable (io.reactivex.rxjava3.disposables.Disposable)1 BehaviorSubject (io.reactivex.rxjava3.subjects.BehaviorSubject)1 ArrayList (java.util.ArrayList)1 Collections (java.util.Collections)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Map (java.util.Map)1 Optional (java.util.Optional)1 Set (java.util.Set)1 TimeUnit (java.util.concurrent.TimeUnit)1