From f9576d8afb117e3a138cc8352f7e97af1973d893 Mon Sep 17 00:00:00 2001 From: CalDescent Date: Fri, 4 Mar 2022 11:05:58 +0000 Subject: [PATCH] Further optimizations to Controller.processIncomingTransactionsQueue() - Signature validation is now able to run concurrently with synchronization, to reduce the chances of the queue building up, and to speed up the propagation of new transactions. There's no need to break out of the loop - or avoid looping in the first place - since signatures can be validated without holding the blockchain lock. - A blockchain lock isn't even attempted if a sync request is pending. --- .../org/qortal/controller/Controller.java | 20 +++++++------------ 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/src/main/java/org/qortal/controller/Controller.java b/src/main/java/org/qortal/controller/Controller.java index fddc575d..40ede12f 100644 --- a/src/main/java/org/qortal/controller/Controller.java +++ b/src/main/java/org/qortal/controller/Controller.java @@ -851,11 +851,6 @@ public class Controller extends Thread { return; } - if (Synchronizer.getInstance().isSyncRequested() || Synchronizer.getInstance().isSynchronizing()) { - // Prioritize syncing, and don't attempt to lock - return; - } - try (final Repository repository = RepositoryManager.getRepository()) { // Take a snapshot of incomingTransactions, so we don't need to lock it while processing Map incomingTransactionsCopy = Map.copyOf(this.incomingTransactions); @@ -871,13 +866,6 @@ public class Controller extends Thread { return; } - if (Synchronizer.getInstance().isSyncRequestPending()) { - LOGGER.debug("Breaking out of transaction signature validation with {} remaining, because a sync request is pending", incomingTransactionsCopy.size()); - - // Fall-through to importing, or we could not even attempt to import by changing following line to 'return' - break; - } - TransactionData transactionData = transactionEntry.getKey(); Transaction transaction = Transaction.fromData(repository, transactionData); @@ -917,10 +905,16 @@ public class Controller extends Thread { return; } + if (Synchronizer.getInstance().isSyncRequested() || Synchronizer.getInstance().isSynchronizing()) { + // Prioritize syncing, and don't attempt to lock + // Signature validity is retained in the incomingTransactions map, to avoid the above work being wasted + return; + } + try { ReentrantLock blockchainLock = Controller.getInstance().getBlockchainLock(); if (!blockchainLock.tryLock(2, TimeUnit.SECONDS)) { - // This is not great if we've just spent a while doing mem-PoW during signature validation round above + // Signature validity is retained in the incomingTransactions map, to avoid the above work being wasted LOGGER.debug("Too busy to process incoming transactions queue"); return; }