mirror of
https://github.com/bitcoinj/bitcoinj.git
synced 2025-02-23 14:40:40 +01:00
PeerFilterProvider: Remove isRequiringUpdateAllBloomFilter().
Bloom filters will now always be created with UPDATE_ALL. With SegWit there is hardly any wallet that can do without. This will save some locking.
This commit is contained in:
parent
c14e9240ad
commit
af9400a650
4 changed files with 3 additions and 39 deletions
|
@ -53,11 +53,6 @@ public interface PeerFilterProvider {
|
|||
*/
|
||||
BloomFilter getBloomFilter(int size, double falsePositiveRate, long nTweak);
|
||||
|
||||
/**
|
||||
* Whether this filter provider depends on the server updating the filter on all matches.
|
||||
*/
|
||||
boolean isRequiringUpdateAllBloomFilter();
|
||||
|
||||
/**
|
||||
* See {@link #beginBloomFilterCalculation()}.
|
||||
*/
|
||||
|
|
|
@ -69,11 +69,9 @@ public class FilterMerger {
|
|||
Result result = new Result();
|
||||
result.earliestKeyTimeSecs = Long.MAX_VALUE;
|
||||
int elements = 0;
|
||||
boolean requiresUpdateAll = false;
|
||||
for (PeerFilterProvider p : providers) {
|
||||
result.earliestKeyTimeSecs = Math.min(result.earliestKeyTimeSecs, p.getEarliestKeyCreationTime());
|
||||
elements += p.getBloomFilterElementCount();
|
||||
requiresUpdateAll = requiresUpdateAll || p.isRequiringUpdateAllBloomFilter();
|
||||
}
|
||||
|
||||
if (elements > 0) {
|
||||
|
@ -82,10 +80,10 @@ public class FilterMerger {
|
|||
// The constant 100 here is somewhat arbitrary, but makes sense for small to medium wallets -
|
||||
// it will likely mean we never need to create a filter with different parameters.
|
||||
lastBloomFilterElementCount = elements > lastBloomFilterElementCount ? elements + 100 : lastBloomFilterElementCount;
|
||||
BloomFilter.BloomUpdate bloomFlags =
|
||||
requiresUpdateAll ? BloomFilter.BloomUpdate.UPDATE_ALL : BloomFilter.BloomUpdate.UPDATE_P2PUBKEY_ONLY;
|
||||
double fpRate = vBloomFilterFPRate;
|
||||
BloomFilter filter = new BloomFilter(lastBloomFilterElementCount, fpRate, bloomFilterTweak, bloomFlags);
|
||||
// We now always use UPDATE_ALL because with SegWit there is hardly any wallet that can do without.
|
||||
BloomFilter filter = new BloomFilter(lastBloomFilterElementCount, fpRate, bloomFilterTweak,
|
||||
BloomFilter.BloomUpdate.UPDATE_ALL);
|
||||
for (PeerFilterProvider p : providers)
|
||||
filter.merge(p.getBloomFilter(lastBloomFilterElementCount, fpRate, bloomFilterTweak));
|
||||
|
||||
|
|
|
@ -4874,29 +4874,6 @@ public class Wallet extends BaseTaggableObject
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* If we are watching any scripts, the bloom filter must update on peers whenever an output is
|
||||
* identified. This is because we don't necessarily have the associated pubkey, so we can't
|
||||
* watch for it on spending transactions.
|
||||
*/
|
||||
@Override
|
||||
public boolean isRequiringUpdateAllBloomFilter() {
|
||||
// This is typically called by the PeerGroup, in which case it will have already explicitly taken the lock
|
||||
// before calling, but because this is public API we must still lock again regardless.
|
||||
keyChainGroupLock.lock();
|
||||
try {
|
||||
if (!watchedScripts.isEmpty())
|
||||
return true;
|
||||
if (keyChainGroup.chains != null)
|
||||
for (DeterministicKeyChain chain : keyChainGroup.chains)
|
||||
if (chain.getOutputScriptType() == Script.ScriptType.P2WPKH)
|
||||
return true;
|
||||
return false;
|
||||
} finally {
|
||||
keyChainGroupLock.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a bloom filter that contains all of the public keys from this wallet, and which will provide the given
|
||||
* false-positive rate. See the docs for {@link BloomFilter} for a brief explanation of anonymity when using filters.
|
||||
|
|
|
@ -1683,14 +1683,11 @@ public class WalletTest extends TestWithWallet {
|
|||
|
||||
@Test
|
||||
public void watchingScriptsBloomFilter() throws Exception {
|
||||
assertFalse(wallet.isRequiringUpdateAllBloomFilter());
|
||||
|
||||
Address watchedAddress = LegacyAddress.fromKey(UNITTEST, new ECKey());
|
||||
Transaction t1 = createFakeTx(UNITTEST, CENT, watchedAddress);
|
||||
TransactionOutPoint outPoint = new TransactionOutPoint(UNITTEST, 0, t1);
|
||||
wallet.addWatchedAddress(watchedAddress);
|
||||
|
||||
assertTrue(wallet.isRequiringUpdateAllBloomFilter());
|
||||
// Note that this has a 1e-12 chance of failing this unit test due to a false positive
|
||||
assertFalse(wallet.getBloomFilter(1e-12).contains(outPoint.unsafeBitcoinSerialize()));
|
||||
|
||||
|
@ -1719,8 +1716,6 @@ public class WalletTest extends TestWithWallet {
|
|||
wallet.removeWatchedAddresses(addressesForRemoval);
|
||||
for (Address addr : addressesForRemoval)
|
||||
assertFalse(wallet.isAddressWatched(addr));
|
||||
|
||||
assertFalse(wallet.isRequiringUpdateAllBloomFilter());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -1729,7 +1724,6 @@ public class WalletTest extends TestWithWallet {
|
|||
wallet.addWatchedAddress(watchedAddress);
|
||||
wallet.removeWatchedAddress(watchedAddress);
|
||||
assertFalse(wallet.isAddressWatched(watchedAddress));
|
||||
assertFalse(wallet.isRequiringUpdateAllBloomFilter());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
Loading…
Add table
Reference in a new issue