From d7b3766c4b856aa1c3ee83b22e3e8b3411e97d85 Mon Sep 17 00:00:00 2001 From: Mike Hearn Date: Tue, 14 Jan 2014 18:49:09 +0100 Subject: [PATCH] Memory optimisations to avoid OOM when the user thread falls behind. - Remove needless recalculations of the Bloom filter on any wallet change, instead of just when keys/scripts are added. This may fix one of the privacy leak issues too. - Run fast catchup/filter recalculations on the dedicated PeerGroup thread instead of abusing the user thread. Resolves a TODO. - Replace the user thread SingleThreadedExecutor with a custom class that blocks the submitting thread and logs a warning if the queue is saturated, to avoid building up a backlog of closures. --- .../com/google/bitcoin/core/PeerGroup.java | 92 +++++++++++++------ .../com/google/bitcoin/utils/Threading.java | 10 +- .../google/bitcoin/core/PeerGroupTest.java | 8 +- 3 files changed, 74 insertions(+), 36 deletions(-) diff --git a/core/src/main/java/com/google/bitcoin/core/PeerGroup.java b/core/src/main/java/com/google/bitcoin/core/PeerGroup.java index 34d15eaf..de2389f2 100644 --- a/core/src/main/java/com/google/bitcoin/core/PeerGroup.java +++ b/core/src/main/java/com/google/bitcoin/core/PeerGroup.java @@ -25,6 +25,7 @@ import com.google.bitcoin.script.Script; import com.google.bitcoin.utils.ExponentialBackoff; import com.google.bitcoin.utils.ListenerRegistration; import com.google.bitcoin.utils.Threading; +import com.google.common.annotations.VisibleForTesting; import com.google.common.base.Preconditions; import com.google.common.collect.Sets; import com.google.common.util.concurrent.*; @@ -33,7 +34,6 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import javax.annotation.Nullable; -import java.math.BigInteger; import java.net.InetAddress; import java.net.InetSocketAddress; import java.util.*; @@ -132,14 +132,18 @@ public class PeerGroup extends AbstractExecutionThreadService implements Transac }; private int minBroadcastConnections = 0; - private AbstractWalletEventListener walletEventListener = new AbstractWalletEventListener() { - private void onChanged() { + private Runnable recalculateRunnable = new Runnable() { + @Override public void run() { recalculateFastCatchupAndFilter(false); } - @Override public void onScriptsAdded(Wallet wallet, List