From ca2d847fe7fa9a4a374c1a11bbaa444d9fbd1921 Mon Sep 17 00:00:00 2001 From: Mike Hearn Date: Mon, 14 Oct 2013 12:05:18 +0200 Subject: [PATCH] Don't run confidence listeners if we get duplicate invs from the same peer (can happen if we connect to the same peer IP multiple times). --- core/src/main/java/com/google/bitcoin/core/MemoryPool.java | 4 ++-- .../java/com/google/bitcoin/core/TransactionConfidence.java | 5 +++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/core/src/main/java/com/google/bitcoin/core/MemoryPool.java b/core/src/main/java/com/google/bitcoin/core/MemoryPool.java index bb22917e..533a1069 100644 --- a/core/src/main/java/com/google/bitcoin/core/MemoryPool.java +++ b/core/src/main/java/com/google/bitcoin/core/MemoryPool.java @@ -268,8 +268,8 @@ public class MemoryPool { private void markBroadcast(PeerAddress byPeer, Transaction tx) { checkState(lock.isHeldByCurrentThread()); final TransactionConfidence confidence = tx.getConfidence(); - confidence.markBroadcastBy(byPeer); - confidence.queueListeners(TransactionConfidence.Listener.ChangeReason.SEEN_PEERS); + if (confidence.markBroadcastBy(byPeer)) + confidence.queueListeners(TransactionConfidence.Listener.ChangeReason.SEEN_PEERS); } /** diff --git a/core/src/main/java/com/google/bitcoin/core/TransactionConfidence.java b/core/src/main/java/com/google/bitcoin/core/TransactionConfidence.java index 5f95cbe9..a5b609b9 100644 --- a/core/src/main/java/com/google/bitcoin/core/TransactionConfidence.java +++ b/core/src/main/java/com/google/bitcoin/core/TransactionConfidence.java @@ -259,12 +259,13 @@ public class TransactionConfidence implements Serializable { * * @param address IP address of the peer, used as a proxy for identity. */ - public synchronized void markBroadcastBy(PeerAddress address) { + public synchronized boolean markBroadcastBy(PeerAddress address) { if (!broadcastBy.addIfAbsent(address)) - return; // Duplicate. + return false; // Duplicate. if (getConfidenceType() == ConfidenceType.UNKNOWN) { this.confidenceType = ConfidenceType.PENDING; } + return true; } /**