3
0
mirror of https://github.com/Qortal/altcoinj.git synced 2025-01-30 23:02:15 +00:00

Make bloom filter false positive rate configurable.

This commit is contained in:
Matt Corallo 2013-01-17 17:50:04 -05:00
parent 7c03eefefd
commit a0c25aed28

View File

@ -131,6 +131,12 @@ public class PeerGroup extends AbstractIdleService {
// A bloom filter generated from all connected wallets that is given to new peers
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
@ -151,7 +157,6 @@ public class PeerGroup extends AbstractIdleService {
this(params, chain, null);
}
/**
* <p>Creates a PeerGroup for the given network and chain, using the provided Netty {@link ClientBootstrap} object.
* </p>
@ -545,9 +550,9 @@ public class PeerGroup extends AbstractIdleService {
if (chain == null || !chain.shouldVerifyTransactions()) {
long nTweak = new Random().nextLong();
BloomFilter filter = new BloomFilter(elements, 0.001, nTweak);
BloomFilter filter = new BloomFilter(elements, bloomFilterFPRate, nTweak);
for (Wallet w : wallets)
filter.merge(w.getBloomFilter(elements, 0.001, nTweak));
filter.merge(w.getBloomFilter(elements, bloomFilterFPRate, nTweak));
bloomFilter = filter;
log.info("Sending all peers an updated Bloom Filter.");
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.
*/