Reduce wasted time that could otherwise be spent validating queued transaction signatures.

This commit is contained in:
CalDescent 2022-05-14 12:53:36 +01:00
parent 6990766f75
commit fa3a81575a

View File

@ -19,7 +19,6 @@ import org.qortal.utils.Base58;
import org.qortal.utils.NTP; import org.qortal.utils.NTP;
import java.util.*; import java.util.*;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.locks.ReentrantLock; import java.util.concurrent.locks.ReentrantLock;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@ -62,7 +61,7 @@ public class TransactionImporter extends Thread {
try { try {
while (!Controller.isStopping()) { while (!Controller.isStopping()) {
Thread.sleep(1000L); Thread.sleep(500L);
// Process incoming transactions queue // Process incoming transactions queue
validateTransactionsInQueue(); validateTransactionsInQueue();
@ -226,14 +225,9 @@ public class TransactionImporter extends Thread {
return; return;
} }
try { ReentrantLock blockchainLock = Controller.getInstance().getBlockchainLock();
ReentrantLock blockchainLock = Controller.getInstance().getBlockchainLock(); if (!blockchainLock.tryLock()) {
if (!blockchainLock.tryLock(2, TimeUnit.SECONDS)) { LOGGER.debug("Too busy to import incoming transactions queue");
LOGGER.debug("Too busy to import incoming transactions queue");
return;
}
} catch (InterruptedException e) {
LOGGER.debug("Interrupted when trying to acquire blockchain lock");
return; return;
} }
@ -304,7 +298,6 @@ public class TransactionImporter extends Thread {
} }
} finally { } finally {
LOGGER.debug("Finished importing {} incoming transaction{}", processedCount, (processedCount == 1 ? "" : "s")); LOGGER.debug("Finished importing {} incoming transaction{}", processedCount, (processedCount == 1 ? "" : "s"));
ReentrantLock blockchainLock = Controller.getInstance().getBlockchainLock();
blockchainLock.unlock(); blockchainLock.unlock();
} }
} catch (DataException e) { } catch (DataException e) {