Browse Source

Break out of incoming transactions processing loop if we need to sync.

online-level-zero-accounts-api-call
CalDescent 3 years ago
parent
commit
b6d633ab24
  1. 5
      src/main/java/org/qortal/controller/Controller.java
  2. 7
      src/main/java/org/qortal/controller/Synchronizer.java

5
src/main/java/org/qortal/controller/Controller.java

@ -856,6 +856,11 @@ public class Controller extends Thread {
return; return;
} }
if (Synchronizer.getInstance().isSyncRequestPending()) {
LOGGER.debug("Breaking out of transaction processing loop with {} remaining, because a sync request is pending", this.incomingTransactions.size());
return;
}
TransactionData transactionData = (TransactionData) iterator.next(); TransactionData transactionData = (TransactionData) iterator.next();
Transaction transaction = Transaction.fromData(repository, transactionData); Transaction transaction = Transaction.fromData(repository, transactionData);

7
src/main/java/org/qortal/controller/Synchronizer.java

@ -82,6 +82,7 @@ public class Synchronizer extends Thread {
private volatile int syncPercent = 0; private volatile int syncPercent = 0;
private static volatile boolean requestSync = false; private static volatile boolean requestSync = false;
private boolean syncRequestPending = false;
// Keep track of invalid blocks so that we don't keep trying to sync them // Keep track of invalid blocks so that we don't keep trying to sync them
private Map<String, Long> invalidBlockSignatures = Collections.synchronizedMap(new HashMap<>()); private Map<String, Long> invalidBlockSignatures = Collections.synchronizedMap(new HashMap<>());
@ -123,6 +124,8 @@ public class Synchronizer extends Thread {
// Something went wrong, so try again next time // Something went wrong, so try again next time
requestSync = true; requestSync = true;
} }
// Remember that we have a pending sync request if this attempt failed
syncRequestPending = !success;
} }
} }
} catch (InterruptedException e) { } catch (InterruptedException e) {
@ -143,6 +146,10 @@ public class Synchronizer extends Thread {
return this.isSynchronizing; return this.isSynchronizing;
} }
public boolean isSyncRequestPending() {
return this.syncRequestPending;
}
public Integer getSyncPercent() { public Integer getSyncPercent() {
synchronized (this.syncLock) { synchronized (this.syncLock) {
return this.isSynchronizing ? this.syncPercent : null; return this.isSynchronizing ? this.syncPercent : null;

Loading…
Cancel
Save