Skip to content
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

wallet+waddrmgr: sync and store up to MaxReorgDepth blocks #618

Merged
merged 12 commits into from
Jun 14, 2019
Merged

wallet+waddrmgr: sync and store up to MaxReorgDepth blocks #618

merged 12 commits into from
Jun 14, 2019

Commits on Jun 11, 2019

  1. waddrmgr: maintain a maximum of MaxReorgDepth block hashes stored

    In this commit, we modify the wallet's block hash index to only store up
    to MaxReorgDepth blocks. This allows us to reduce consumed storage, as
    we'd be mostly storing duplicate data. We choose to store up to
    MaxReorgDepth to ensure we can recover from a potential long reorg.
    wpaulino committed Jun 11, 2019
    Configuration menu
    Copy the full SHA
    e548e76 View commit details
    Browse the repository at this point in the history
  2. waddrmgr: add migration to maintain MaxReorgDepth block hashes stored

    In this commit, we add a migration that will be used by existing wallets
    to ensure they can adhere to the new requirement of storing up to
    MaxReorgDepth entries within the block hash index.
    wpaulino committed Jun 11, 2019
    Configuration menu
    Copy the full SHA
    f2f46b6 View commit details
    Browse the repository at this point in the history

Commits on Jun 14, 2019

  1. wallet: make wallet initial sync synchronous

    This ensures the wallet can properly do an initial sync, a recovery, or
    detect if it's on a stale branch before attempting to process new blocks
    at tip.
    
    Since the rescan will be triggered synchronously as well, we'll need to
    catch the wallet's quit chan when handling rescan batches in order to
    allow for clean shutdowns.
    wpaulino committed Jun 14, 2019
    Configuration menu
    Copy the full SHA
    1ee2a23 View commit details
    Browse the repository at this point in the history
  2. chain: add IsCurrent method to chain.Interface

    IsCurrent allows us to determine if the chain backend considers itself
    "current" with the chain.
    wpaulino committed Jun 14, 2019
    Configuration menu
    Copy the full SHA
    39f81c6 View commit details
    Browse the repository at this point in the history
  3. wallet: wait until chain backend is current to begin wallet sync

    This serves as groundwork for only storing up to MaxReorgDepth blocks
    upon initial sync. To do so, we want to make sure the chain backend
    considers itself current so that we can only fetch the latest
    MaxReorgDepth blocks from it.
    wpaulino committed Jun 14, 2019
    Configuration menu
    Copy the full SHA
    17efcdb View commit details
    Browse the repository at this point in the history
  4. wallet: locate birthday block without scanning chain from genesis

    We do this as the wallet will no longer store blocks all the way from
    genesis to the tip of the chain. Instead, in order to find a reasonable
    birthday block, we resort to performing a binary search for a block
    timestamp that's within +/-2 hours of the birthday timestamp.
    wpaulino committed Jun 14, 2019
    Configuration menu
    Copy the full SHA
    2a6f24c View commit details
    Browse the repository at this point in the history
  5. wallet: modify recovery logic to not start from genesis

    This commit serves as another building point to allow the wallet to not
    store blocks all the way from genesis to the tip of chain. We modify the
    wallet's recovery logic to now start from either its birthday block, or
    the current reorg safe height if it's before the birthday, to ensure the
    wallet properly only stores MaxReorgDepth blocks.
    
    We also refactor things a bit in hopes of making the logic a bit more
    readable.
    wpaulino committed Jun 14, 2019
    Configuration menu
    Copy the full SHA
    e754478 View commit details
    Browse the repository at this point in the history
  6. wallet: store reorg safe height upon initial sync

    Currently, wallet rescans start from its known tip of the chain. Since
    we no longer store blocks all the way from genesis to the tip of the
    chain, performing a rescan would cause us to scan blocks all the way
    from genesis, which we want to avoid. To prevent this, we set the
    wallet's tip to be the current reorg safe height. This ensures that
    we're unable to scan any blocks before it, and that we maintain
    MaxReorgDepth blocks stored.
    wpaulino committed Jun 14, 2019
    Configuration menu
    Copy the full SHA
    fa65c1b View commit details
    Browse the repository at this point in the history
  7. Configuration menu
    Copy the full SHA
    26bc5ab View commit details
    Browse the repository at this point in the history
  8. wallet: use locateBirthdayBlock within birthdaySanityCheck

    We use the recently introduced locateBirthdayBlock function within
    birthdaySanityCheck as it serves as a more optimized alternative that
    achieves the same purpose.
    wpaulino committed Jun 14, 2019
    Configuration menu
    Copy the full SHA
    fd8aa5d View commit details
    Browse the repository at this point in the history
  9. wallet: improve error logging for unsuccessful notification handling

    If a block arrives while the wallet is rescanning, users would be shown
    a log message that is confusing and not very helpful.
    wpaulino committed Jun 14, 2019
    Configuration menu
    Copy the full SHA
    a9847c2 View commit details
    Browse the repository at this point in the history
  10. chain: only allow bitcoind block notifications at tip after NotifyBlocks

    One could argue that the behavior before this commit was incorrect, as
    the ChainClient interface expects a call to NotifyBlocks before
    notifying blocks at tip, so we decide to fix this.
    
    Since we now wait for the chain backend to be considered "current"
    before proceeding to sync the wallet with it, any blocks that were
    processed while waiting would result in being notified and scanned
    twice, once by processing it at tip, and another while rescanning the
    wallet, which is not desirable.
    wpaulino committed Jun 14, 2019
    Configuration menu
    Copy the full SHA
    4a913d0 View commit details
    Browse the repository at this point in the history