From 10340b13a6b8e33a20f82b69ab9e285110e078ad Mon Sep 17 00:00:00 2001 From: Mike Hearn Date: Thu, 13 Nov 2014 23:07:02 +0100 Subject: [PATCH] Don't hold the peergroup lock whilst calculating bloom filters, and run on the executor thread. Move responsibility for deduplication into recalculateFastCatchupAndFilter(). --- .../java/org/bitcoinj/core/PeerGroup.java | 134 ++++++++---------- .../java/org/bitcoinj/net/FilterMerger.java | 25 ++-- 2 files changed, 76 insertions(+), 83 deletions(-) diff --git a/core/src/main/java/org/bitcoinj/core/PeerGroup.java b/core/src/main/java/org/bitcoinj/core/PeerGroup.java index 4c0f4761..4b44a546 100644 --- a/core/src/main/java/org/bitcoinj/core/PeerGroup.java +++ b/core/src/main/java/org/bitcoinj/core/PeerGroup.java @@ -22,6 +22,7 @@ import com.google.common.base.Preconditions; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableSet; import com.google.common.collect.Lists; +import com.google.common.collect.Maps; import com.google.common.net.InetAddresses; import com.google.common.primitives.Ints; import com.google.common.primitives.Longs; @@ -166,48 +167,12 @@ public class PeerGroup implements TransactionBroadcaster { private int minBroadcastConnections = 0; private final AbstractWalletEventListener walletEventListener = new AbstractWalletEventListener() { - // Because calculation of the new filter takes place asynchronously, these flags deduplicate requests. - @GuardedBy("this") private boolean sendIfChangedQueued, dontSendQueued; - - private Runnable bloomSendIfChanged = new Runnable() { - @Override public void run() { - recalculateFastCatchupAndFilter(FilterRecalculateMode.SEND_IF_CHANGED); - synchronized (walletEventListener) { - sendIfChangedQueued = false; - } - } - }; - private Runnable bloomDontSend = new Runnable() { - @Override public void run() { - recalculateFastCatchupAndFilter(FilterRecalculateMode.DONT_SEND); - synchronized (walletEventListener) { - dontSendQueued = false; - } - } - }; - - private synchronized void queueRecalc(boolean andTransmit) { - if (andTransmit) { - if (!sendIfChangedQueued) { - log.info("Queuing recalc of the Bloom filter due to new keys or scripts becoming available"); - sendIfChangedQueued = true; - executor.execute(bloomSendIfChanged); - } - } else { - if (!dontSendQueued) { - log.info("Queuing recalc of the Bloom filter due to observing a pay to pubkey output on a relevant tx"); - dontSendQueued = true; - executor.execute(bloomDontSend); - } - } - } - @Override public void onScriptsChanged(Wallet wallet, List