forked from Qortal/qortal
Change API transaction subsmission from single-shot to 500ms timeout for obtaining blockchain lock
This commit is contained in:
parent
03f60ef898
commit
4f25fffbe9
@ -11,6 +11,8 @@ import io.swagger.v3.oas.annotations.tags.Tag;
|
|||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
import java.util.concurrent.locks.ReentrantLock;
|
||||||
|
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
import javax.ws.rs.GET;
|
import javax.ws.rs.GET;
|
||||||
@ -427,14 +429,22 @@ public class TransactionsResource {
|
|||||||
if (!transaction.isSignatureValid())
|
if (!transaction.isSignatureValid())
|
||||||
throw ApiExceptionFactory.INSTANCE.createException(request, ApiError.INVALID_SIGNATURE);
|
throw ApiExceptionFactory.INSTANCE.createException(request, ApiError.INVALID_SIGNATURE);
|
||||||
|
|
||||||
ValidationResult result = transaction.importAsUnconfirmed();
|
ReentrantLock blockchainLock = Controller.getInstance().getBlockchainLock();
|
||||||
if (result != ValidationResult.OK)
|
if (!blockchainLock.tryLock(500, TimeUnit.MILLISECONDS))
|
||||||
throw createTransactionInvalidException(request, result);
|
throw createTransactionInvalidException(request, ValidationResult.NO_BLOCKCHAIN_LOCK);
|
||||||
|
|
||||||
// Notify controller of new transaction
|
try {
|
||||||
Controller.getInstance().onNewTransaction(transactionData);
|
ValidationResult result = transaction.importAsUnconfirmed();
|
||||||
|
if (result != ValidationResult.OK)
|
||||||
|
throw createTransactionInvalidException(request, result);
|
||||||
|
|
||||||
return "true";
|
// Notify controller of new transaction
|
||||||
|
Controller.getInstance().onNewTransaction(transactionData);
|
||||||
|
|
||||||
|
return "true";
|
||||||
|
} finally {
|
||||||
|
blockchainLock.unlock();
|
||||||
|
}
|
||||||
} catch (NumberFormatException e) {
|
} catch (NumberFormatException e) {
|
||||||
throw ApiExceptionFactory.INSTANCE.createException(request, ApiError.INVALID_DATA, e);
|
throw ApiExceptionFactory.INSTANCE.createException(request, ApiError.INVALID_DATA, e);
|
||||||
} catch (TransformationException e) {
|
} catch (TransformationException e) {
|
||||||
@ -443,6 +453,8 @@ public class TransactionsResource {
|
|||||||
throw e;
|
throw e;
|
||||||
} catch (DataException e) {
|
} catch (DataException e) {
|
||||||
throw ApiExceptionFactory.INSTANCE.createException(request, ApiError.REPOSITORY_ISSUE, e);
|
throw ApiExceptionFactory.INSTANCE.createException(request, ApiError.REPOSITORY_ISSUE, e);
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
throw createTransactionInvalidException(request, ValidationResult.NO_BLOCKCHAIN_LOCK);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user