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

blockchain: Refactor db main chain idx to blk idx. #1332

Merged
merged 1 commit into from
Jul 6, 2018

Commits on Jul 6, 2018

  1. blockchain: Refactor db main chain idx to blk idx.

    This refactors the code that relies on the database main chain index to
    use the in-memory block index now that the full index is in memory.
    
    This is a major optimization for several functions because they no
    longer have to first consult the database (which is incredibly slow in
    many cases due to the way leveldb splits all of the information across
    files) to perform lookups and determine if blocks are in the main chain.
    
    It should also be noted that even though the main chain index is no
    longer used as of this commit, the code which writes the main chain
    index entries to the database in connectBlock, disconnectBlock, and
    createChainState have not been removed because, once that is done, it
    will no longer be possible to downgrade and thus those changes must be
    performed along with a database migration and associated version bump.
    
    An overview of the changes are as follows:
    
    - Update all code which previously used the db to use the main chain by
      height map instead
    - Update several internal functions which previously accepted the
      hash to instead accept the block node as the parameter
      - Rename fetchMainChainBlockByHash to fetchMainChainBlockByNode
      - Rename fetchBlockByHash to fetchBlockByNode
      - Rename dbFetchBlockByHash to dbFetchBlockByNode
      - Update all callers to use the new names and semantics
    - Optimize HeaderByHeight to use block index/height map instead of db
      - Move to chain.go since it no longer involves database I/O
    - Optimize BlockByHash to use block index instead of db
      - Move to chain.go since it no longer involves database I/O
    - Optimize BlockByHeight to use block index/height map instead of db
      - Move to chain.go since it no longer involves database I/O
    - Optimize MainChainHasBlock to use block index instead of db
      - Move to chain.go since it no longer involves database I/O
      - Removed error return since it can no longer fail
    - Optimize BlockHeightByHash to use block index instead of db
      - Move to chain.go since it no longer involves database I/O
    - Optimize BlockHashByHeight to use block index instead of db
      - Move to chain.go since it no longer involves database I/O
    - Optimize HeightRange to use block index instead of db
      - Move to chain.go since it no longer involves database I/O
    - Remove several unused functions related to the main chain index
      - dbFetchHeaderByHash
      - DBFetchHeaderByHeight
      - dbFetchBlockByHeight
      - DBFetchBlockByHeight
      - dbMainChainHasBlock
      - DBMainChainHasBlock
    - Rework IsCheckpointCandidate to use block index
    - Modify the upgrade code to expose the old dbFetchBlockByHeight
      function only in the local scope since upgrades require the ability to
      read the old format
    - Update indexers to fetch the blocks themselves while only querying
      chain for chain-related details
    davecgh committed Jul 6, 2018
    Configuration menu
    Copy the full SHA
    c6b5f6d View commit details
    Browse the repository at this point in the history