mirror of
https://github.com/bitcoinj/bitcoinj.git
synced 2025-02-24 22:58:32 +01:00
Make bloom filter false positive rate configurable.
This commit is contained in:
parent
7c03eefefd
commit
a0c25aed28
1 changed files with 21 additions and 4 deletions
|
@ -131,6 +131,12 @@ public class PeerGroup extends AbstractIdleService {
|
||||||
|
|
||||||
// A bloom filter generated from all connected wallets that is given to new peers
|
// A bloom filter generated from all connected wallets that is given to new peers
|
||||||
private BloomFilter bloomFilter;
|
private BloomFilter bloomFilter;
|
||||||
|
/** A reasonable default for the bloom filter false positive rate on mainnet.
|
||||||
|
* Users for which low data usage is of utmost concern, 0.0001 may be better, for users
|
||||||
|
* to whom anonymity is of utmost concern, 0.001 should provide very good privacy */
|
||||||
|
public static final double DEFAULT_BLOOM_FILTER_FP_RATE = 0.0005;
|
||||||
|
// The false positive rate for bloomFilter
|
||||||
|
private double bloomFilterFPRate = DEFAULT_BLOOM_FILTER_FP_RATE;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a PeerGroup with the given parameters. No chain is provided so this node will report its chain height
|
* Creates a PeerGroup with the given parameters. No chain is provided so this node will report its chain height
|
||||||
|
@ -151,7 +157,6 @@ public class PeerGroup extends AbstractIdleService {
|
||||||
this(params, chain, null);
|
this(params, chain, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>Creates a PeerGroup for the given network and chain, using the provided Netty {@link ClientBootstrap} object.
|
* <p>Creates a PeerGroup for the given network and chain, using the provided Netty {@link ClientBootstrap} object.
|
||||||
* </p>
|
* </p>
|
||||||
|
@ -545,9 +550,9 @@ public class PeerGroup extends AbstractIdleService {
|
||||||
|
|
||||||
if (chain == null || !chain.shouldVerifyTransactions()) {
|
if (chain == null || !chain.shouldVerifyTransactions()) {
|
||||||
long nTweak = new Random().nextLong();
|
long nTweak = new Random().nextLong();
|
||||||
BloomFilter filter = new BloomFilter(elements, 0.001, nTweak);
|
BloomFilter filter = new BloomFilter(elements, bloomFilterFPRate, nTweak);
|
||||||
for (Wallet w : wallets)
|
for (Wallet w : wallets)
|
||||||
filter.merge(w.getBloomFilter(elements, 0.001, nTweak));
|
filter.merge(w.getBloomFilter(elements, bloomFilterFPRate, nTweak));
|
||||||
bloomFilter = filter;
|
bloomFilter = filter;
|
||||||
log.info("Sending all peers an updated Bloom Filter.");
|
log.info("Sending all peers an updated Bloom Filter.");
|
||||||
for (Peer peer : peers)
|
for (Peer peer : peers)
|
||||||
|
@ -558,6 +563,18 @@ public class PeerGroup extends AbstractIdleService {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the false positive rate of bloom filters given to peers.
|
||||||
|
* Be careful regenerating the bloom filter too often, as it decreases anonymity because remote nodes can
|
||||||
|
* compare transactions against both the new and old filters to significantly decrease the false positive rate.
|
||||||
|
*
|
||||||
|
* See the docs for {@link BloomFilter#BloomFilter(int, double)} for a brief explanation of anonymity when using bloom filters.
|
||||||
|
*/
|
||||||
|
public void setBloomFilterFalsePositiveRate(double bloomFilterFPRate) {
|
||||||
|
this.bloomFilterFPRate = bloomFilterFPRate;
|
||||||
|
recalculateFastCatchupAndFilter();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Unlinks the given wallet so it no longer receives broadcast transactions or has its transactions announced.
|
* Unlinks the given wallet so it no longer receives broadcast transactions or has its transactions announced.
|
||||||
*/
|
*/
|
||||||
|
|
Loading…
Add table
Reference in a new issue