func (c *Chain) SetTip(node *BlockNode) {
	c.lock.Lock()
	defer c.lock.Unlock()
	if node == nil {
		c.chain = make([]*BlockNode, 0)
		return
	}

	needed := node.Height + 1

	// algorithm copied from btcd chainview
	if uint64(cap(c.chain)) < needed {
		newChain := make([]*BlockNode, needed, 1000+needed)
		copy(newChain, c.chain)
		c.chain = newChain
	} else {
		prevLen := uint64(len(c.chain))
		c.chain = c.chain[0:needed]
		for i := prevLen; i < needed; i++ {
			c.chain[i] = nil
		}
	}

	for node != nil && c.chain[node.Height] != node {
		c.chain[node.Height] = node
		node = node.Parent
	}
}
// SetTip sets the tip of the chain.
SetTip sets the tip of the chain.
// SetTip sets the tip of the chain .
func (c *Chain) SetTip(node *BlockNode) {
	c.lock.Lock()
	defer c.lock.Unlock()
	if node == nil {
		c.chain = make([]*BlockNode, 0)
		return
	}
	needed := node.Height + 1
	if uint64(cap(c.chain)) < needed {
		newChain := make([]*BlockNode, needed, 1000+needed)
		copy(newChain, c.chain)
		c.chain = newChain
	} else {
		prevLen := uint64(len(c.chain))
		c.chain = c.chain[0:needed]
		for i := prevLen; i < needed; i++ {
			c.chain[i] = nil
		}
	}
	for node != nil && c.chain[node.Height] != node {
		c.chain[node.Height] = node
		node = node.Parent
	}
}
func ( c * Chain ) SetTip ( node * BlockNode ) { c . lock . Lock ( ) defer c . lock . Unlock ( ) if node == nil { c . chain = make ( [ ] * BlockNode , 0 ) return } needed := node . Height + 1 if uint64 ( cap ( c . chain ) ) < needed { newChain := make ( [ ] * BlockNode , needed , 1000 + needed ) copy ( newChain , c . chain ) c . chain = newChain } else { prevLen := uint64 ( len ( c . chain ) ) c . chain = c . chain [ 0 : needed ] for i := prevLen ; i < needed ; i ++ { c . chain [ i ] = nil } } for node != nil && c . chain [ node . Height ] != node { c . chain [ node . Height ] = node node = node . Parent } }
SetTip sets the tip of the chain.
SetTip sets the tip of the chain .
// algorithm copied from btcd chainview