blockchain: Generalize chain reorg.
blockchain: Generalize chain reorg.

This generalizes the reorganizeChain function in the blockchain package
to allow it to rewind the chain in the case no attach nodes are provided
or extend the chain in the case no detach nodes are provided.

It also adds several assertions to ensure the assumptions about the
state hold and cleans up the handling of setting invalid ancestor nodes
in the case of a failed block validation.

tb00/btcd,ltcsuite/ltcd,btcsuite/btcd,davecgh/btcd,btcsuite/btcd,davecgh/btcd,tb00/btcd,dajohi/btcd,ppcsuite/ppcd,wallclockbuilder/btcd,dajohi/btcd,ppcsuite/ppcd,wallclockbuilder/btcd,dajohi/btcd,ltcsuite/ltcd