@Override public int numKeys() { // We need to return here the total number of keys including the lookahead zone, not the number of keys we // have issued via getKey/freshReceiveKey. lock.lock(); try { maybeLookAhead(); return basicKeyChain.numKeys(); } finally { lock.unlock(); } }
@Override public int numKeys() { // We need to return here the total number of keys including the lookahead zone, not the number of keys we // have issued via getKey/freshReceiveKey. lock.lock(); try { maybeLookAhead(); return basicKeyChain.numKeys(); } finally { lock.unlock(); } }
@Override public int numKeys() { // We need to return here the total number of keys including the lookahead zone, not the number of keys we // have issued via getKey/freshReceiveKey. lock.lock(); try { maybeLookAhead(); return basicKeyChain.numKeys(); } finally { lock.unlock(); } }
@Override public int numKeys() { // We need to return here the total number of keys including the lookahead zone, not the number of keys we // have issued via getKey/freshReceiveKey. lock.lock(); try { maybeLookAhead(); return basicKeyChain.numKeys(); } finally { lock.unlock(); } }
/** * Pre-generate enough keys to reach the lookahead size. You can call this if you need to explicitly invoke * the lookahead procedure, but it's normally unnecessary as it will be done automatically when needed. */ public void maybeLookAhead() { lock.lock(); try { List<DeterministicKey> keys = maybeLookAhead(externalParentKey, issuedExternalKeys); keys.addAll(maybeLookAhead(internalParentKey, issuedInternalKeys)); if (keys.isEmpty()) return; keyLookaheadEpoch++; // Batch add all keys at once so there's only one event listener invocation, as this will be listened to // by the wallet and used to rebuild/broadcast the Bloom filter. That's expensive so we don't want to do // it more often than necessary. basicKeyChain.importKeys(keys); } finally { lock.unlock(); } }
private List<ECKey> getMarriedKeysWithFollowed(DeterministicKey followedKey) { ImmutableList.Builder<ECKey> keys = ImmutableList.builder(); for (DeterministicKeyChain keyChain : followingKeyChains) { keyChain.maybeLookAhead(); keys.add(keyChain.getKeyByPath(followedKey.getPath())); } keys.add(followedKey); return keys.build(); }
private List<ECKey> getMarriedKeysWithFollowed(DeterministicKey followedKey) { ImmutableList.Builder<ECKey> keys = ImmutableList.builder(); for (DeterministicKeyChain keyChain : followingKeyChains) { keyChain.maybeLookAhead(); keys.add(keyChain.getKeyByPath(followedKey.getPath())); } keys.add(followedKey); return keys.build(); }
private List<ECKey> getMarriedKeysWithFollowed(DeterministicKey followedKey) { ImmutableList.Builder<ECKey> keys = ImmutableList.builder(); for (DeterministicKeyChain keyChain : followingKeyChains) { keyChain.maybeLookAhead(); keys.add(keyChain.getKeyByPath(followedKey.getPath())); } keys.add(followedKey); return keys.build(); }
private List<ECKey> getMarriedKeysWithFollowed(DeterministicKey followedKey) { ImmutableList.Builder<ECKey> keys = ImmutableList.builder(); for (DeterministicKeyChain keyChain : followingKeyChains) { keyChain.maybeLookAhead(); keys.add(keyChain.getKeyByPath(followedKey.getPath())); } keys.add(followedKey); return keys.build(); }
@Override public BloomFilter getFilter(int size, double falsePositiveRate, long tweak) { lock.lock(); try { checkArgument(size >= numBloomFilterEntries()); maybeLookAhead(); return basicKeyChain.getFilter(size, falsePositiveRate, tweak); } finally { lock.unlock(); } }
@Override public BloomFilter getFilter(int size, double falsePositiveRate, long tweak) { lock.lock(); try { checkArgument(size >= numBloomFilterEntries()); maybeLookAhead(); return basicKeyChain.getFilter(size, falsePositiveRate, tweak); } finally { lock.unlock(); } }
@Override public BloomFilter getFilter(int size, double falsePositiveRate, long tweak) { lock.lock(); try { checkArgument(size >= numBloomFilterEntries()); maybeLookAhead(); return basicKeyChain.getFilter(size, falsePositiveRate, tweak); } finally { lock.unlock(); } }
@Override public BloomFilter getFilter(int size, double falsePositiveRate, long tweak) { lock.lock(); try { checkArgument(size >= numBloomFilterEntries()); maybeLookAhead(); return basicKeyChain.getFilter(size, falsePositiveRate, tweak); } finally { lock.unlock(); } }
private List<DeterministicKey> maybeLookAhead(DeterministicKey parent, int issued) { checkState(lock.isHeldByCurrentThread()); return maybeLookAhead(parent, issued, getLookaheadSize(), getLookaheadThreshold()); }
private List<DeterministicKey> maybeLookAhead(DeterministicKey parent, int issued) { checkState(lock.isHeldByCurrentThread()); return maybeLookAhead(parent, issued, getLookaheadSize(), getLookaheadThreshold()); }
private List<DeterministicKey> maybeLookAhead(DeterministicKey parent, int issued) { checkState(lock.isHeldByCurrentThread()); return maybeLookAhead(parent, issued, getLookaheadSize(), getLookaheadThreshold()); }
private List<DeterministicKey> maybeLookAhead(DeterministicKey parent, int issued) { checkState(lock.isHeldByCurrentThread()); return maybeLookAhead(parent, issued, getLookaheadSize(), getLookaheadThreshold()); }
/** * Mark the DeterministicKey as used. * Also correct the issued{Internal|External}Keys counter, because all lower children seem to be requested already. * If the counter was updated, we also might trigger lookahead. */ public DeterministicKey markKeyAsUsed(DeterministicKey k) { int numChildren = k.getChildNumber().i() + 1; if (k.getParent() == internalParentKey) { if (issuedInternalKeys < numChildren) { issuedInternalKeys = numChildren; maybeLookAhead(); } } else if (k.getParent() == externalParentKey) { if (issuedExternalKeys < numChildren) { issuedExternalKeys = numChildren; maybeLookAhead(); } } return k; }
/** * Mark the DeterministicKey as used. * Also correct the issued{Internal|External}Keys counter, because all lower children seem to be requested already. * If the counter was updated, we also might trigger lookahead. */ public DeterministicKey markKeyAsUsed(DeterministicKey k) { int numChildren = k.getChildNumber().i() + 1; if (k.getParent() == internalParentKey) { if (issuedInternalKeys < numChildren) { issuedInternalKeys = numChildren; maybeLookAhead(); } } else if (k.getParent() == externalParentKey) { if (issuedExternalKeys < numChildren) { issuedExternalKeys = numChildren; maybeLookAhead(); } } return k; }
@Test public void getKeys() throws Exception { chain.getKey(KeyChain.KeyPurpose.RECEIVE_FUNDS); chain.getKey(KeyChain.KeyPurpose.CHANGE); chain.maybeLookAhead(); assertEquals(2, chain.getKeys(false, false).size()); }