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