forked from Qortal/qortal
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.
This commit is contained in:
parent
6a8a113fa1
commit
f9576d8afb
@ -851,11 +851,6 @@ public class Controller extends Thread {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Synchronizer.getInstance().isSyncRequested() || Synchronizer.getInstance().isSynchronizing()) {
|
|
||||||
// Prioritize syncing, and don't attempt to lock
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
try (final Repository repository = RepositoryManager.getRepository()) {
|
try (final Repository repository = RepositoryManager.getRepository()) {
|
||||||
// Take a snapshot of incomingTransactions, so we don't need to lock it while processing
|
// Take a snapshot of incomingTransactions, so we don't need to lock it while processing
|
||||||
Map<TransactionData, Boolean> incomingTransactionsCopy = Map.copyOf(this.incomingTransactions);
|
Map<TransactionData, Boolean> incomingTransactionsCopy = Map.copyOf(this.incomingTransactions);
|
||||||
@ -871,13 +866,6 @@ public class Controller extends Thread {
|
|||||||
return;
|
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();
|
TransactionData transactionData = transactionEntry.getKey();
|
||||||
Transaction transaction = Transaction.fromData(repository, transactionData);
|
Transaction transaction = Transaction.fromData(repository, transactionData);
|
||||||
|
|
||||||
@ -917,10 +905,16 @@ public class Controller extends Thread {
|
|||||||
return;
|
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 {
|
try {
|
||||||
ReentrantLock blockchainLock = Controller.getInstance().getBlockchainLock();
|
ReentrantLock blockchainLock = Controller.getInstance().getBlockchainLock();
|
||||||
if (!blockchainLock.tryLock(2, TimeUnit.SECONDS)) {
|
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");
|
LOGGER.debug("Too busy to process incoming transactions queue");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user