diff --git a/blockchain/chain.go b/blockchain/chain.go index e1600d7741..52822eadcb 100644 --- a/blockchain/chain.go +++ b/blockchain/chain.go @@ -1174,6 +1174,11 @@ func (b *BlockChain) getReorganizeNodes(node *blockNode) (*list.List, *list.List // common ancestor adding each block to the list of nodes to detach from // the main chain. for n := b.bestNode; n != nil; n = n.parent { + if n.hash == ancestor.hash { + break + } + detachNodes.PushBack(n) + if n.parent == nil { var err error n.parent, err = b.findNode(&n.header.PrevBlock, maxSearchDepth) @@ -1181,12 +1186,6 @@ func (b *BlockChain) getReorganizeNodes(node *blockNode) (*list.List, *list.List return nil, nil, err } } - - if n.hash == ancestor.hash { - break - } - - detachNodes.PushBack(n) } return detachNodes, attachNodes, nil diff --git a/blockchain/indexers/addrindex.go b/blockchain/indexers/addrindex.go index 48a6c927cd..959d86f44f 100644 --- a/blockchain/indexers/addrindex.go +++ b/blockchain/indexers/addrindex.go @@ -720,7 +720,7 @@ func (idx *AddrIndex) indexPkScript(data writeIndexData, scriptVersion uint16, p // transaction using the passed map. func (idx *AddrIndex) indexBlock(data writeIndexData, block, parent *dcrutil.Block, view *blockchain.UtxoViewpoint) { var parentRegularTxs []*dcrutil.Tx - if approvesParent(block) { + if approvesParent(block) && block.Height() > 1 { parentRegularTxs = parent.Transactions() } for txIdx, tx := range parentRegularTxs { diff --git a/blockchain/indexers/txindex.go b/blockchain/indexers/txindex.go index 4b7084507a..17aacf1311 100644 --- a/blockchain/indexers/txindex.go +++ b/blockchain/indexers/txindex.go @@ -308,7 +308,7 @@ func dbRemoveTxIndexEntries(dbTx database.Tx, block, parent *dcrutil.Block) erro } // Remove all of the regular transactions of the parent if voted valid. - if approvesParent(block) { + if approvesParent(block) && block.Height() > 1 { if err := removeEntries(parent.Transactions()); err != nil { return err }