func (b *BlockChain) nodeAtHeightFromTopNode(node *blockNode,
	toTraverse int64) (*blockNode, error) {
	oldNode := node
	var err error
	count := int64(0)
	for {
		oldNode, err = b.getPrevNodeFromNode(oldNode)
		if err != nil {
			return nil, err
		}
		if oldNode == nil {
			return nil, fmt.Errorf("unable to obtain previous node; " +
				"ancestor is genesis block")
		}
		if HashToBig(&(oldNode.hash)).Cmp(CompactToBig(oldNode.header.Bits)) <= 0 {
			count++
		}
		if count >= toTraverse {
			break
		}
	}
	return oldNode, nil
}
nodeAtHeightFromTopNode goes backwards through a node until it a reaches
the node with a desired block height; it returns this block.  The benefit is
this works for both the main chain and the side chain.
package blockchain
import (
	"fmt"
	"github.com/HcashOrg/hcashd/blockchain/stake"
	"github.com/HcashOrg/hcashd/chaincfg/chainhash"
	"github.com/HcashOrg/hcashd/database"
)