- 
                Notifications
    You must be signed in to change notification settings 
- Fork 412
          Use a universal lookahead value for KeychainTxOutIndex and have a reasonable default
          #1229
        
          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
  
    Use a universal lookahead value for KeychainTxOutIndex and have a reasonable default
  
  #1229
              Conversation
| Not sure how i would implement a test which: 
 | 
| See the tests in  Historical note that I actually pushed against having a lookahead for a little while. I felt like it encouraged a design where people had multiple devices giving out addresses for the same keychain which I feel is bad practice. The wallet giving out addresses for the xpub knows the last one that has been produced so it's technically not possible for it exist on the blockchain and application developers should be using this invariant. My complaints were put aside when @evanlinjin pointed out the impossibility of doing block-by-block updating without a lookahead. The default was probably set to 0 to placate me because I still wanted the developer to consciously engage this feature for that scenario.  | 
2194abb    to
    6f2cb9c      
    Compare
  
    | Does this mean it is watching the next 1000 addresses? That seems pretty expensive for syncing | 
| 
 No what you actually go out and fetch from the chain is under your control and this lookahead doesn't effect it. This is about what the txout index will find when you feed it transaction. It's only relevant when you are doing block style syncing -- it shouldn't effect at all electrum/esplora. | 
6f2cb9c    to
    9077c07      
    Compare
  
    | Please rebase now that #1183 has been merged. | 
| @darosior If it is alright with you, could I take over this PR? I think this is important for syncing from block-by-block chain sources. | 
| After discussion with @LLFourn, we have come to agreement to use a universal  pub fn new(lookahead: u32) -> Self { todo!() }I will move this PR forward in this manner. | 
734803f    to
    bb750a2      
    Compare
  
    | I fixed the CI issues with #1247, it just needs to be ACKd and merged and then this PR rebased. | 
bb750a2    to
    ab848d6      
    Compare
  
    KeychainTxOutIndex and have a reasonable default
      ab848d6    to
    8eb9411      
    Compare
  
    8eb9411    to
    627953d      
    Compare
  
    | The main changes looks good, but when I tried to do some manual  if init_changeset.0.is_empty() {
        let genesis_hash = genesis_block(Regtest).block_hash();
        dbg!(genesis_hash);
        let  (_chain, changeset) = LocalChain::from_genesis_hash(genesis_hash);
        init_changeset.0 = changeset;
        db.lock().unwrap().stage(init_changeset.clone());
        db.lock().unwrap().commit()?;
    } | 
The wallet is currently created without setting any lookahead value for the keychain. This implicitly makes it a lookahead of 0. As this is a high-level interface we should avoid footguns and aim for a reasonable default. Instead of simply patching it for wallet, we alter `KeychainTxOutIndex` to have a default lookahead value. Additionally, instead of a per-keychain lookahead, the constructor asks for a `lookahead` value. This avoids the footguns of having methods which allows the caller the decrease the `lookahead` (and therefore panicing). This also simplifies the API. Co-authored-by: Antoine Poisot <[email protected]> Co-authored-by: 志宇 <[email protected]>
Previously, the genesis block is not initialized properly. Thank you @notmandatory for identifying this bug.
627953d    to
    bc796f4      
    Compare
  
    There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tACK bc796f4
I manually tested using example_bitcoind_rpc_polling cli with the steps in gist: https://gist.github.com/notmandatory/6fa85dd942089833629bdb40d2b54858
| I pushed a commit to improve the lookahead doc slightly. self-ACK: c9467dc | 
9c4a8ec    to
    cbc8454      
    Compare
  
    cbc8454    to
    1def76f      
    Compare
  
    There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ACK 1def76f
Description
The
bdk::Walletis currently created without setting any lookahead value for the keychain. This implicitly makes it a lookahead of 0. As this is a high-level interface we should avoid footguns and aim for a reasonable default.To fix this, we have also decided to change
KeychainTxOutIndexto have a default lookahead. Additionally, we have simplified theKeychainTxOutIndexAPI to have a singlelookaheadthat is ONLY set at constructionKeychainTxOutIndex::new(lookahead: u32) -> Self. This avoids the footguns of having methods which allows the caller to decrease thelookahead(which will panic).Notes to the reviewers
A way to set this value externally is introduced in #1172. This PR only aims to use a saner default than 0.1_000is the value used by the Bitcoin Core wallet, and that seems reasonable to me.Edit: we should NOT allow setting the
lookaheadvalue after-the-fact. Instead, thelookaheadshould be provided to the wallet's constructor.@evanlinjin: I don't think additional tests are necessary as no additional features are added, and the surface area of the API is decreased. The original tests already thoroughly test the
lookaheadconcept.Checklists
All Submissions:
(This section was updated as this PR changed from being a simple setting to introducing a new method.)
cargo fmtandcargo clippybefore committing* [ ] I've added tests