diff --git a/core/src/main/java/com/google/bitcoin/core/BloomFilter.java b/core/src/main/java/com/google/bitcoin/core/BloomFilter.java index a952d823..ba9ed772 100644 --- a/core/src/main/java/com/google/bitcoin/core/BloomFilter.java +++ b/core/src/main/java/com/google/bitcoin/core/BloomFilter.java @@ -17,12 +17,13 @@ package com.google.bitcoin.core; import com.google.common.base.Objects; -import com.google.common.base.Preconditions; import java.io.IOException; import java.io.OutputStream; import java.util.Arrays; +import static com.google.common.base.Preconditions.checkArgument; + /** *
A Bloom filter is a probabilistic data structure which can be sent to another client so that it can avoid * sending us transactions that aren't relevant to our set of keys. This allows for significantly more efficient @@ -233,29 +234,35 @@ public class BloomFilter extends Message { } /** - * Sets this filter to match all objects + * Sets this filter to match all objects. A Bloom filter which matches everything may seem pointless, however, + * it is useful in order to reduce steady state bandwidth usage when you want full blocks. Instead of receiving + * all transaction data twice, you will receive the vast majority of all transactions just once, at broadcast time. + * Solved blocks will then be send just as Merkle trees of tx hashes, meaning a constant 32 bytes of data for each + * transaction instead of 100-300 bytes as per usual. */ public void setMatchAll() { data = new byte[] {(byte) 0xff}; } /** - * Copies filter into this. - * filter must have the same size, hash function count and nTweak or an exception will be thrown. + * Copies filter into this. Filter must have the same size, hash function count and nTweak or an + * IllegalArgumentException will be thrown. */ public void merge(BloomFilter filter) { if (!this.matchesAll() && !filter.matchesAll()) { - Preconditions.checkArgument(filter.data.length == this.data.length && - filter.hashFuncs == this.hashFuncs && - filter.nTweak == this.nTweak); + checkArgument(filter.data.length == this.data.length && + filter.hashFuncs == this.hashFuncs && + filter.nTweak == this.nTweak); for (int i = 0; i < data.length; i++) this.data[i] |= filter.data[i]; - } else + } else { this.data = new byte[] {(byte) 0xff}; + } } /** - * Returns true if this filter will match anything + * Returns true if this filter will match anything. See {@link com.google.bitcoin.core.BloomFilter#setMatchAll()} + * for when this can be a useful thing to do. */ public boolean matchesAll() { for (byte b : data)