use of com.radixdlt.mempool.MempoolFullException 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();
}
use of com.radixdlt.mempool.MempoolFullException 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());
}
}
use of com.radixdlt.mempool.MempoolFullException 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());
}
}
use of com.radixdlt.mempool.MempoolFullException 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);
}
}
Aggregations