-
Notifications
You must be signed in to change notification settings - Fork 334
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Impact of lookahead
variable on users of bdk_wallet
#1540
Comments
Thanks for collecting all this information in one place. My current thinking is to keep the lookahead option on |
I suppose the other option is to do away with the |
The lookahead is there for situations where you are not using SPK based syncing (electrum and esplora). There you use How are we meant to find script pubkeys when you do I think in the future Also I see there is a method called |
028f687 doc(wallet): Add docs to explain the lookahead (valued mammal) Pull request description: Adds clarifying language to `CreateParams` and `LoadParams` regarding the `lookahead` parameter. Commit 028f687 also includes some minor documentation fixes. If anyone is aware of any more documentation flaws that need attention I'm happy to add them here. cc #1540 ### Checklists #### All Submissions: * [x] I've signed all my commits * [x] I followed the [contribution guidelines](https://github.com/bitcoindevkit/bdk/blob/master/CONTRIBUTING.md) * [x] I ran `cargo fmt` and `cargo clippy` before committing ACKs for top commit: LagginTimes: ACK 028f687 oleonardolima: ACK 028f687 evanlinjin: ACK 028f687 Tree-SHA512: 971d09652948ed2e2dc86d255cfd18607d96b0806aa0e990190cd1d7035c6660ea2ac1092ef2c6c209e61920c0d4ff9d8c0a900bcc74a8662546d284fec3218f
Hello folks. After reviewing the new builder pattern for the wallet type and speaking to people in Nashville, I've come to the conclusion that the idea behind the
lookahead
and its impact on users ofbdk_wallet
is not well understood. Moreover, setting the lookahead value is part of the public API of theWallet
(through the builder) but is not (I think?) part of persistence, so understanding it well is important for users.This issue is meant to clear that up for everyone, and arrive at either:
CC'ing the two people I have not yet asked about this in person or over the dev call yesterday: @evanlinjin @LLFourn.
Related API Docs
Just so they're easy to find for everyone, here are the API docs on this:
Previous Discussions
See my Q2 on #1533:
I see that the
lookahead
is a setter, but even after reading the docs I'm not sure what it's setting exactly because it just sounds like a sort of stop gap but not a stop gap. See the docs here on lookahead and the more explicit lookahead in KeychainTxOutIndex.Don't we scan up to the stop gap? I know this from experience when looking at the Esplora logs on full scan and syncs (for example a stop gap of 3 with a lookahead of 100 will query the Esplora instance for only 4 addresses), so not sure if maybe it refers to something else?
Wait so is it persisted then? Or by that do we mean it can't be altered per session but altered on every
load
of the wallet?I know (think?) the
lookahead
is not persisted, but is there a danger in having two different lookahead between sessions? What if I set a lookahead of 3 when I create a wallet, and 300 the next time I load the wallet? Or the opposite?And my follow up here:
Does lookahead impact the sync/full_scan workflows? I have not been able to find this to be the case locally, so I'm still unclear about what this lookahead is doing, and because it's part of the public API of the
Wallet
type I want to make sure I really get it. Here's what I have tried on regtest, and looking at the logs for my esplora instance:More notes on this: the docs here say:
Again this makes it sound close to the concept of the stop gap, but I assume it's different somehow or a more generalized version of it that can be used in the deeper logic of the KeychainIndex? That's as far as the API docs go.
And the response from @ValuedMammal:
The lookahead doesn't appear to have a role during full scan for esplora because we get the SPKs to sync by calling
all_unbounded_spk_iters
For sync it's also not relevant because we only sync SPKs that are already revealed.
In short, the lookahead defines a number of scripts to derive ahead of time without revealing them. If you do a full scan with the default lookahead of 25 and persist the wallet, then on subsequent loads
those SPKs are still stored in the index and there shouldn't be any harm in setting a new lookahead.Edit: Nope that's also wrong. we don't persist derived SPKs, only the value of
last_revealed
. So yeah we probably need more testing.One way to illustrate the effect of the lookahead is to create a wallet with the default value of 25. Then peek at address index 25. The method
Wallet::is_mine
will return false because internally the address is not yet derived (remembering that SPKs are 0-indexed).For context one of the reasons we chose to make the lookahead configurable is because for a short time we had it set to 1000 and users reported unbearably long load times. Beyond that, I don't think it's something users should generally care about other than to know it exists
Further questions
Following up on the comment from VM,
is_mine()
to work as intended?The text was updated successfully, but these errors were encountered: