There was a rare case that a block could be incorrectly added to
the indexer if the indexer was disabled during a reorg to a height
that matched the height that was expected, and the `sync` method
for the indexer wasn't called that would detect the reorg.
- Write indexer state and index atomically.
- Simplify chain state with current height.
- Roll forward to best height.
- Synchronize the index with the chain with common method `sync` for
the events 'connect', 'disconnect' and 'reset'. This will prevent
any of the events from conflicting with each other.
- Fix the chain rollback and reset.
- Make sure blocks are connected in the correct order.
- Improve logging to log similar to chain.
module indexer introduces a extensible architecture for indexing the
chain. It provides a base class which handles syncing with the chain,
handling re-orgs, interruptions, dynamic toggling, etc. TXIndexer
and AddrIndexer are provided for indexing transactions and addresses,
using the same flags as before i.e --index-tx and --index-address.
Indexes are stored in a different database and can be maintained
independently of the chain.