/** * Returns the number of distinct data items (note: NOT keys) that will be inserted into a bloom filter, when it * is constructed. */ @Override public int getBloomFilterElementCount() { beginBloomFilterCalculation(); try { int size = bloomOutPoints.size(); size += keyChainGroup.getBloomFilterElementCount(); // Some scripts may have more than one bloom element. That should normally be okay, because under-counting // just increases false-positive rate. size += watchedScripts.size(); return size; } finally { endBloomFilterCalculation(); } }
/** * Returns the number of distinct data items (note: NOT keys) that will be inserted into a bloom filter, when it * is constructed. */ @Override public int getBloomFilterElementCount() { beginBloomFilterCalculation(); try { int size = bloomOutPoints.size(); size += keyChainGroup.getBloomFilterElementCount(); // Some scripts may have more than one bloom element. That should normally be okay, because under-counting // just increases false-positive rate. size += watchedScripts.size(); return size; } finally { endBloomFilterCalculation(); } }
/** * Returns the number of distinct data items (note: NOT keys) that will be inserted into a bloom filter, when it * is constructed. */ @Override public int getBloomFilterElementCount() { beginBloomFilterCalculation(); try { int size = bloomOutPoints.size(); size += keyChainGroup.getBloomFilterElementCount(); // Some scripts may have more than one bloom element. That should normally be okay, because under-counting // just increases false-positive rate. size += watchedScripts.size(); return size; } finally { endBloomFilterCalculation(); } }
/** * Returns the number of distinct data items (note: NOT keys) that will be inserted into a bloom filter, when it * is constructed. */ @Override public int getBloomFilterElementCount() { beginBloomFilterCalculation(); try { int size = bloomOutPoints.size(); size += keyChainGroup.getBloomFilterElementCount(); // Some scripts may have more than one bloom element. That should normally be okay, because under-counting // just increases false-positive rate. size += watchedScripts.size(); return size; } finally { endBloomFilterCalculation(); } }
@Test public void serializeWatching() throws Exception { group = new KeyChainGroup(PARAMS, watchingAccountKey); group.setLookaheadSize(LOOKAHEAD_SIZE); group.freshKey(KeyChain.KeyPurpose.RECEIVE_FUNDS); group.freshKey(KeyChain.KeyPurpose.CHANGE); group.getBloomFilterElementCount(); // Force lookahead. List<Protos.Key> protoKeys1 = group.serializeToProtobuf(); assertEquals(3 + (group.getLookaheadSize() + group.getLookaheadThreshold() + 1) * 2, protoKeys1.size()); group = KeyChainGroup.fromProtobufUnencrypted(PARAMS, protoKeys1); assertEquals(3 + (group.getLookaheadSize() + group.getLookaheadThreshold() + 1) * 2, group.serializeToProtobuf().size()); }
@Test public void findRedeemScriptFromPubHash() throws Exception { group = createMarriedKeyChainGroup(); Address address = group.freshAddress(KeyChain.KeyPurpose.RECEIVE_FUNDS); assertTrue(group.findRedeemDataFromScriptHash(address.getHash160()) != null); group.getBloomFilterElementCount(); KeyChainGroup group2 = createMarriedKeyChainGroup(); group2.freshAddress(KeyChain.KeyPurpose.RECEIVE_FUNDS); group2.getBloomFilterElementCount(); // Force lookahead. // test address from lookahead zone and lookahead threshold zone for (int i = 0; i < group.getLookaheadSize() + group.getLookaheadThreshold(); i++) { address = group.freshAddress(KeyChain.KeyPurpose.RECEIVE_FUNDS); assertTrue(group2.findRedeemDataFromScriptHash(address.getHash160()) != null); } assertFalse(group2.findRedeemDataFromScriptHash(group.freshAddress(KeyChain.KeyPurpose.RECEIVE_FUNDS).getHash160()) != null); }
@Test public void freshAddress() throws Exception { group = createMarriedKeyChainGroup(); Address a1 = group.freshAddress(KeyChain.KeyPurpose.RECEIVE_FUNDS); Address a2 = group.freshAddress(KeyChain.KeyPurpose.RECEIVE_FUNDS); assertTrue(a1.isP2SHAddress()); assertNotEquals(a1, a2); group.getBloomFilterElementCount(); assertEquals(((group.getLookaheadSize() + group.getLookaheadThreshold()) * 2) // * 2 because of internal/external + (2 - group.getLookaheadThreshold()) // keys issued + group.getActiveKeyChain().getAccountPath().size() + 3 /* master, account, int, ext */, group.numKeys()); Address a3 = group.currentAddress(KeyChain.KeyPurpose.RECEIVE_FUNDS); assertEquals(a2, a3); }
@Test public void bloomFilterForMarriedChains() throws Exception { group = createMarriedKeyChainGroup(); int bufferSize = group.getLookaheadSize() + group.getLookaheadThreshold(); int expected = bufferSize * 2 /* chains */ * 2 /* elements */; assertEquals(expected, group.getBloomFilterElementCount()); Address address1 = group.freshAddress(KeyChain.KeyPurpose.RECEIVE_FUNDS); assertEquals(expected, group.getBloomFilterElementCount()); BloomFilter filter = group.getBloomFilter(expected + 2, 0.001, (long)(Math.random() * Long.MAX_VALUE)); assertTrue(filter.contains(address1.getHash160())); Address address2 = group.freshAddress(KeyChain.KeyPurpose.CHANGE); assertTrue(filter.contains(address2.getHash160())); // Check that the filter contains the lookahead buffer. for (int i = 0; i < bufferSize - 1 /* issued address */; i++) { Address address = group.freshAddress(KeyChain.KeyPurpose.RECEIVE_FUNDS); assertTrue("key " + i, filter.contains(address.getHash160())); } // We ran ahead of the lookahead buffer. assertFalse(filter.contains(group.freshAddress(KeyChain.KeyPurpose.RECEIVE_FUNDS).getHash160())); }
+ group.getActiveKeyChain().getAccountPath().size() + 2 /* account key + int/ext parent keys */; assertEquals(numKeys, group.numKeys()); assertEquals(2 * numKeys, group.getBloomFilterElementCount()); ECKey r1 = group.currentKey(KeyChain.KeyPurpose.RECEIVE_FUNDS); assertEquals(numKeys, group.numKeys()); assertEquals(2 * numKeys, group.getBloomFilterElementCount()); numKeys++; assertEquals(numKeys, group.numKeys()); assertEquals(2 * numKeys, group.getBloomFilterElementCount());
@Test public void bloom() throws Exception { ECKey key1 = group.freshKey(KeyChain.KeyPurpose.RECEIVE_FUNDS); ECKey key2 = new ECKey(); BloomFilter filter = group.getBloomFilter(group.getBloomFilterElementCount(), 0.001, (long)(Math.random() * Long.MAX_VALUE)); assertTrue(filter.contains(key1.getPubKeyHash())); assertTrue(filter.contains(key1.getPubKey())); assertFalse(filter.contains(key2.getPubKey())); // Check that the filter contains the lookahead buffer and threshold zone. for (int i = 0; i < LOOKAHEAD_SIZE + group.getLookaheadThreshold(); i++) { ECKey k = group.freshKey(KeyChain.KeyPurpose.RECEIVE_FUNDS); assertTrue(filter.contains(k.getPubKeyHash())); } // We ran ahead of the lookahead buffer. assertFalse(filter.contains(group.freshKey(KeyChain.KeyPurpose.RECEIVE_FUNDS).getPubKey())); group.importKeys(key2); filter = group.getBloomFilter(group.getBloomFilterElementCount(), 0.001, (long) (Math.random() * Long.MAX_VALUE)); assertTrue(filter.contains(key1.getPubKeyHash())); assertTrue(filter.contains(key1.getPubKey())); assertTrue(filter.contains(key2.getPubKey())); }
DeterministicKey key1 = group.freshKey(KeyChain.KeyPurpose.RECEIVE_FUNDS); DeterministicKey key2 = group.freshKey(KeyChain.KeyPurpose.CHANGE); group.getBloomFilterElementCount(); List<Protos.Key> protoKeys1 = group.serializeToProtobuf(); assertEquals(initialKeys + ((LOOKAHEAD_SIZE + 1) * 2) + 1 /* for the seed */ + 1, protoKeys1.size());