Search in sources :

Example 11 with Txn

use of com.radixdlt.atom.Txn in project radixdlt by radixdlt.

the class WithdrawVoteHandler method handleRequest.

@Override
public UpdateVoteResponse handleRequest(UpdateVoteRequest request) throws CoreApiException {
    coreModelMapper.verifyNetwork(request.getNetworkIdentifier());
    final Txn signedTx;
    try {
        signedTx = radixEngine.constructWithFees(this::buildWithdrawVote, false, REAddr.ofPubKeyAccount(validatorKey), NotEnoughNativeTokensForFeesException::new).signAndBuild(hashSigner::sign);
    } catch (TxBuilderException e) {
        throw CoreApiException.badRequest(coreModelMapper.builderErrorDetails(e));
    }
    try {
        radixEngineStateComputer.addToMempool(signedTx);
        return new UpdateVoteResponse().transactionIdentifier(coreModelMapper.transactionIdentifier(signedTx.getId())).duplicate(false);
    } catch (MempoolDuplicateException e) {
        return new UpdateVoteResponse().transactionIdentifier(coreModelMapper.transactionIdentifier(signedTx.getId())).duplicate(true);
    } catch (MempoolFullException e) {
        throw coreModelMapper.mempoolFullException(e);
    } catch (MempoolRejectedException e) {
        throw coreModelMapper.radixEngineException((RadixEngineException) e.getCause());
    }
}
Also used : MempoolDuplicateException(com.radixdlt.mempool.MempoolDuplicateException) NotEnoughNativeTokensForFeesException(com.radixdlt.api.core.model.NotEnoughNativeTokensForFeesException) MempoolRejectedException(com.radixdlt.mempool.MempoolRejectedException) MempoolFullException(com.radixdlt.mempool.MempoolFullException) RadixEngineException(com.radixdlt.engine.RadixEngineException) Txn(com.radixdlt.atom.Txn) UpdateVoteResponse(com.radixdlt.api.core.openapitools.model.UpdateVoteResponse) TxBuilderException(com.radixdlt.atom.TxBuilderException)

Example 12 with Txn

use of com.radixdlt.atom.Txn 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)12 TxBuilderException (com.radixdlt.atom.TxBuilderException)3 REProcessedTxn (com.radixdlt.constraintmachine.REProcessedTxn)3 NotEnoughNativeTokensForFeesException (com.radixdlt.api.core.model.NotEnoughNativeTokensForFeesException)2 UpdateVoteResponse (com.radixdlt.api.core.openapitools.model.UpdateVoteResponse)2 SystemMapKey (com.radixdlt.constraintmachine.SystemMapKey)2 ECPublicKey (com.radixdlt.crypto.ECPublicKey)2 RadixEngineException (com.radixdlt.engine.RadixEngineException)2 TestInvariant (com.radixdlt.harness.simulation.TestInvariant)2 RunningNetwork (com.radixdlt.harness.simulation.network.SimulationNodes.RunningNetwork)2 PreparedVertex (com.radixdlt.hotstuff.bft.PreparedVertex)2 MempoolDuplicateException (com.radixdlt.mempool.MempoolDuplicateException)2 MempoolFullException (com.radixdlt.mempool.MempoolFullException)2 MempoolRejectedException (com.radixdlt.mempool.MempoolRejectedException)2 Observable (io.reactivex.rxjava3.core.Observable)2 IOException (java.io.IOException)2 List (java.util.List)2 Optional (java.util.Optional)2 Test (org.junit.Test)2 Stopwatch (com.google.common.base.Stopwatch)1