Search in sources :

Example 1 with MempoolRejectedException

use of com.radixdlt.mempool.MempoolRejectedException in project radixdlt by radixdlt.

the class RadixEngineMempool method add.

@Override
public REProcessedTxn add(Txn txn) throws MempoolRejectedException {
    if (this.data.size() >= maxSize) {
        throw new MempoolFullException(this.data.size(), maxSize);
    }
    if (this.data.containsKey(txn.getId())) {
        throw new MempoolDuplicateException(String.format("Mempool already has command %s", txn.getId()));
    }
    final RadixEngineResult<LedgerAndBFTProof> result;
    try {
        RadixEngine.RadixEngineBranch<LedgerAndBFTProof> checker = radixEngine.transientBranch();
        result = checker.execute(List.of(txn));
    } catch (RadixEngineException e) {
        // TODO: allow missing dependency atoms to live for a certain amount of time
        throw new MempoolRejectedException(e);
    } finally {
        radixEngine.deleteBranches();
    }
    var mempoolTxn = MempoolMetadata.create(System.currentTimeMillis());
    var data = Pair.of(result.getProcessedTxn(), mempoolTxn);
    this.data.put(txn.getId(), data);
    result.getProcessedTxn().substateDependencies().forEach(substateId -> substateIndex.merge(substateId, Set.of(txn.getId()), Sets::union));
    return result.getProcessedTxn();
}
Also used : MempoolDuplicateException(com.radixdlt.mempool.MempoolDuplicateException) RadixEngine(com.radixdlt.engine.RadixEngine) MempoolRejectedException(com.radixdlt.mempool.MempoolRejectedException) MempoolFullException(com.radixdlt.mempool.MempoolFullException) RadixEngineException(com.radixdlt.engine.RadixEngineException)

Example 2 with MempoolRejectedException

use of com.radixdlt.mempool.MempoolRejectedException in project radixdlt by radixdlt.

the class VoteHandler method handleRequest.

@Override
public UpdateVoteResponse handleRequest(UpdateVoteRequest request) throws CoreApiException {
    coreModelMapper.verifyNetwork(request.getNetworkIdentifier());
    final Txn signedTx;
    try {
        signedTx = radixEngine.constructWithFees(this::buildVote, 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 3 with MempoolRejectedException

use of com.radixdlt.mempool.MempoolRejectedException 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 4 with MempoolRejectedException

use of com.radixdlt.mempool.MempoolRejectedException in project radixdlt by radixdlt.

the class ConstructionSubmitHandler method handleRequest.

@Override
public ConstructionSubmitResponse handleRequest(ConstructionSubmitRequest request) throws CoreApiException {
    modelMapper.verifyNetwork(request.getNetworkIdentifier());
    var txn = modelMapper.txn(request.getSignedTransaction());
    try {
        radixEngineStateComputer.addToMempool(txn);
        return new ConstructionSubmitResponse().transactionIdentifier(modelMapper.transactionIdentifier(txn.getId())).duplicate(false);
    } catch (MempoolDuplicateException e) {
        return new ConstructionSubmitResponse().transactionIdentifier(modelMapper.transactionIdentifier(txn.getId())).duplicate(true);
    } catch (MempoolFullException e) {
        throw modelMapper.mempoolFullException(e);
    } catch (MempoolRejectedException e) {
        var reException = (RadixEngineException) e.getCause();
        throw modelMapper.radixEngineException(reException);
    }
}
Also used : MempoolDuplicateException(com.radixdlt.mempool.MempoolDuplicateException) MempoolRejectedException(com.radixdlt.mempool.MempoolRejectedException) ConstructionSubmitResponse(com.radixdlt.api.core.openapitools.model.ConstructionSubmitResponse) MempoolFullException(com.radixdlt.mempool.MempoolFullException)

Aggregations

MempoolDuplicateException (com.radixdlt.mempool.MempoolDuplicateException)4 MempoolFullException (com.radixdlt.mempool.MempoolFullException)4 MempoolRejectedException (com.radixdlt.mempool.MempoolRejectedException)4 RadixEngineException (com.radixdlt.engine.RadixEngineException)3 NotEnoughNativeTokensForFeesException (com.radixdlt.api.core.model.NotEnoughNativeTokensForFeesException)2 UpdateVoteResponse (com.radixdlt.api.core.openapitools.model.UpdateVoteResponse)2 TxBuilderException (com.radixdlt.atom.TxBuilderException)2 Txn (com.radixdlt.atom.Txn)2 ConstructionSubmitResponse (com.radixdlt.api.core.openapitools.model.ConstructionSubmitResponse)1 RadixEngine (com.radixdlt.engine.RadixEngine)1