Browse Source

Synchronize peer data lookups.

Without this we could broadcast the same data multiple times, due to more than one thread processing the same message from different peers.
qdn
CalDescent 3 years ago
parent
commit
e7cb33d8e2
  1. 8
      src/main/java/org/qortal/controller/arbitrary/ArbitraryDataManager.java

8
src/main/java/org/qortal/controller/arbitrary/ArbitraryDataManager.java

@ -36,6 +36,7 @@ public class ArbitraryDataManager extends Thread {
private static final long ARBITRARY_REQUEST_TIMEOUT = 5 * 1000L; // ms private static final long ARBITRARY_REQUEST_TIMEOUT = 5 * 1000L; // ms
private static ArbitraryDataManager instance; private static ArbitraryDataManager instance;
private final Object peerDataLock = new Object();
private boolean buildInProgress = false; private boolean buildInProgress = false;
@ -679,6 +680,9 @@ public class ArbitraryDataManager extends Thread {
boolean containsNewEntry = false; boolean containsNewEntry = false;
// Synchronize peer data lookups to make this process thread safe. Otherwise we could broadcast
// the same data multiple times, due to more than one thread processing the same message from different peers
synchronized (this.peerDataLock) {
try (final Repository repository = RepositoryManager.getRepository()) { try (final Repository repository = RepositoryManager.getRepository()) {
for (byte[] signature : signatures) { for (byte[] signature : signatures) {
@ -703,8 +707,7 @@ public class ArbitraryDataManager extends Thread {
if (containsNewEntry) { if (containsNewEntry) {
LOGGER.info("Rebroadcasting arbitrary signature list for peer {}", peerAddress); LOGGER.info("Rebroadcasting arbitrary signature list for peer {}", peerAddress);
Network.getInstance().broadcast(broadcastPeer -> arbitrarySignaturesMessage); Network.getInstance().broadcast(broadcastPeer -> arbitrarySignaturesMessage);
} } else {
else {
// Don't re-broadcast as otherwise we could get into a loop // Don't re-broadcast as otherwise we could get into a loop
} }
@ -714,5 +717,6 @@ public class ArbitraryDataManager extends Thread {
LOGGER.error(String.format("Repository issue while processing arbitrary transaction signature list from peer %s", peer), e); LOGGER.error(String.format("Repository issue while processing arbitrary transaction signature list from peer %s", peer), e);
} }
} }
}
} }

Loading…
Cancel
Save