diff --git a/p2p/src/main/java/bisq/network/p2p/peers/getdata/RequestDataHandler.java b/p2p/src/main/java/bisq/network/p2p/peers/getdata/RequestDataHandler.java index 654be9ab4ae..3dcd8fa2a01 100644 --- a/p2p/src/main/java/bisq/network/p2p/peers/getdata/RequestDataHandler.java +++ b/p2p/src/main/java/bisq/network/p2p/peers/getdata/RequestDataHandler.java @@ -250,6 +250,9 @@ public void onMessage(NetworkEnvelope networkEnvelope, Connection connection) { List processDelayedItems = new ArrayList<>(); dataSet.stream().forEach(e -> { + if(dataStorage.isRecentlyRemoved(e)) + return; + if (e.getProtectedStoragePayload() instanceof LazyProcessedPayload) { processDelayedItems.add(e); } else { diff --git a/p2p/src/main/java/bisq/network/p2p/storage/P2PDataStorage.java b/p2p/src/main/java/bisq/network/p2p/storage/P2PDataStorage.java index 9852dc2d589..5df6e40f2db 100644 --- a/p2p/src/main/java/bisq/network/p2p/storage/P2PDataStorage.java +++ b/p2p/src/main/java/bisq/network/p2p/storage/P2PDataStorage.java @@ -121,7 +121,7 @@ public class P2PDataStorage implements MessageListener, ConnectionListener, Pers private final Set appendOnlyDataStoreListeners = new CopyOnWriteArraySet<>(); private final Set protectedDataStoreListeners = new CopyOnWriteArraySet<>(); - private List recentlyRemovedMessages = new ArrayList<>(); + private Map recentlyRemovedMessages = new ConcurrentHashMap<>(); /////////////////////////////////////////////////////////////////////////////////////////// @@ -351,13 +351,6 @@ public boolean addProtectedStorageEntry(ProtectedStorageEntry protectedStorageEn && checkSignature(protectedStorageEntry) && sequenceNrValid; - synchronized (recentlyRemovedMessages) { - if (recentlyRemovedMessages.contains(hashOfPayload)) { - log.trace("We ignore this message as we received a remove command for this very data only recently"); - return false; - } - } - boolean containsKey = map.containsKey(hashOfPayload); if (containsKey) result = result && checkIfStoredDataPubKeyMatchesNewDataPubKey(protectedStorageEntry.getOwnerPubKey(), hashOfPayload); @@ -447,6 +440,10 @@ public boolean refreshTTL(RefreshOfferMessage refreshTTLMessage, @Nullable NodeA } } + public boolean isRecentlyRemoved(ProtectedStorageEntry e) { + return recentlyRemovedMessages.values().contains(get32ByteHashAsByteArray(e)); + } + public boolean remove(ProtectedStorageEntry protectedStorageEntry, @Nullable NodeAddress sender, boolean isDataOwner) { final ProtectedStoragePayload protectedStoragePayload = protectedStorageEntry.getProtectedStoragePayload(); ByteArray hashOfPayload = get32ByteHashAsByteArray(protectedStoragePayload); @@ -586,11 +583,11 @@ public void removeProtectedDataStoreListener(ProtectedDataStoreListener listener private void doRemoveProtectedExpirableData(ProtectedStorageEntry protectedStorageEntry, ByteArray hashOfPayload) { map.remove(hashOfPayload); - synchronized (recentlyRemovedMessages) { - recentlyRemovedMessages.add(hashOfPayload); - while (recentlyRemovedMessages.size() > 500) - recentlyRemovedMessages.remove(0); - } + // add to the list of recently removed messages + recentlyRemovedMessages.put(System.currentTimeMillis(), hashOfPayload); + + // clean the list by removing all recently removed messages which have been removed in the last minute + recentlyRemovedMessages.keySet().removeIf(timestamp -> timestamp < System.currentTimeMillis() - TimeUnit.MINUTES.toMillis(1)); log.trace("Data removed from our map. We broadcast the message to our peers."); hashMapChangedListeners.stream().forEach(e -> e.onRemoved(protectedStorageEntry));