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.
This commit is contained in:
CalDescent 2021-10-29 17:46:58 +01:00
parent c63d238316
commit e7cb33d8e2

View File

@ -36,6 +36,7 @@ public class ArbitraryDataManager extends Thread {
private static final long ARBITRARY_REQUEST_TIMEOUT = 5 * 1000L; // ms
private static ArbitraryDataManager instance;
private final Object peerDataLock = new Object();
private boolean buildInProgress = false;
@ -679,6 +680,9 @@ public class ArbitraryDataManager extends Thread {
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()) {
for (byte[] signature : signatures) {
@ -703,8 +707,7 @@ public class ArbitraryDataManager extends Thread {
if (containsNewEntry) {
LOGGER.info("Rebroadcasting arbitrary signature list for peer {}", peerAddress);
Network.getInstance().broadcast(broadcastPeer -> arbitrarySignaturesMessage);
}
else {
} else {
// 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);
}
}
}
}