From e888807dfd233f3500755a7aeb1f263c9ae65e4b Mon Sep 17 00:00:00 2001 From: Mike Hearn Date: Tue, 12 Aug 2014 18:32:51 +0200 Subject: [PATCH] PeerFilterProvider methods are called with the lock already held, so just assert on that instead of locking again. --- .../java/com/google/bitcoin/core/Wallet.java | 26 ++++++++----------- 1 file changed, 11 insertions(+), 15 deletions(-) diff --git a/core/src/main/java/com/google/bitcoin/core/Wallet.java b/core/src/main/java/com/google/bitcoin/core/Wallet.java index c9ac410d..b36bd649 100644 --- a/core/src/main/java/com/google/bitcoin/core/Wallet.java +++ b/core/src/main/java/com/google/bitcoin/core/Wallet.java @@ -3648,6 +3648,7 @@ public class Wallet extends BaseTaggableObject implements Serializable, BlockCha */ @Override public int getBloomFilterElementCount() { + checkState(lock.isHeldByCurrentThread()); int size = keychain.getBloomFilterElementCount(); for (Transaction tx : getTransactions(false)) { for (TransactionOutput out : tx.getOutputs()) { @@ -3674,6 +3675,7 @@ public class Wallet extends BaseTaggableObject implements Serializable, BlockCha */ @Override public boolean isRequiringUpdateAllBloomFilter() { + checkState(lock.isHeldByCurrentThread()); return !watchedScripts.isEmpty(); } @@ -3698,23 +3700,17 @@ public class Wallet extends BaseTaggableObject implements Serializable, BlockCha */ @Override public BloomFilter getBloomFilter(int size, double falsePositiveRate, long nTweak) { - BloomFilter filter; - lock.lock(); - try { - filter = keychain.getBloomFilter(size, falsePositiveRate, nTweak); - - for (Script script : watchedScripts) { - for (ScriptChunk chunk : script.getChunks()) { - // Only add long (at least 64 bit) data to the bloom filter. - // If any long constants become popular in scripts, we will need logic - // here to exclude them. - if (!chunk.isOpCode() && chunk.data.length >= MINIMUM_BLOOM_DATA_LENGTH) { - filter.insert(chunk.data); - } + checkState(lock.isHeldByCurrentThread()); + BloomFilter filter = keychain.getBloomFilter(size, falsePositiveRate, nTweak); + for (Script script : watchedScripts) { + for (ScriptChunk chunk : script.getChunks()) { + // Only add long (at least 64 bit) data to the bloom filter. + // If any long constants become popular in scripts, we will need logic + // here to exclude them. + if (!chunk.isOpCode() && chunk.data.length >= MINIMUM_BLOOM_DATA_LENGTH) { + filter.insert(chunk.data); } } - } finally { - lock.unlock(); } for (Transaction tx : getTransactions(false)) { for (int i = 0; i < tx.getOutputs().size(); i++) {