func (i *ShardBlockIndex) GetNodeByHash(h *chainhash.Hash) (*ShardBlockNode, error) {
	i.Lock.RLock()
	defer i.Lock.RUnlock()
	node, found := i.Index[*h]
	if !found {
		return nil, fmt.Errorf("do not have block with hash %s", h)
	}
	return node, nil
}
GetNodeByHash gets a block node by hash.
package index
import (
	"fmt"
	"sync"
	"github.com/phoreproject/synapse/chainhash"
	"github.com/phoreproject/synapse/primitives"
	"github.com/prysmaticlabs/go-ssz"
)
type ShardBlockNode struct {
	Parent    *ShardBlockNode
	BlockHash chainhash.Hash
	StateRoot chainhash.Hash
	Slot      uint64
	Height    uint64
}
func (node *ShardBlockNode) GetAncestorAtSlot(slot uint64) *ShardBlockNode {
	if node.Slot < slot {
		return nil
	}
	current := node
	for current != nil && slot < current.Slot {
		current = current.Parent
	}
	return current
}
func (node *ShardBlockNode) GetClosestAncestorAtSlot(slot uint64) *ShardBlockNode {
	n := node.GetAncestorAtSlot(slot)
	if n == nil {
		return node
	}
	return n
}
func (node *ShardBlockNode) GetAncestorAtHeight(height uint64) *ShardBlockNode {
	if node.Height < height {
		return nil
	}
	current := node
	for current != nil && height < current.Height {
		current = current.Parent
	}
	return current
}
type ShardBlockIndex struct {
	Lock  *sync.RWMutex
	Index map[chainhash.Hash]*ShardBlockNode
}
func (i *ShardBlockIndex) AddToIndex(block primitives.ShardBlock) (*ShardBlockNode, error) {
	i.Lock.Lock()
	defer i.Lock.Unlock()
	parent, found := i.Index[block.Header.PreviousBlockHash]
	if !found {
		return nil, fmt.Errorf("missing parent block %s", block.Header.PreviousBlockHash)
	}
	blockHash, err := ssz.HashTreeRoot(block)
	if err != nil {
		return nil, err
	}
	node := &ShardBlockNode{
		Parent:    parent,
		BlockHash: blockHash,
		StateRoot: block.Header.StateRoot,
		Slot:      block.Header.Slot,
		Height:    parent.Height + 1,
	}
	i.Index[blockHash] = node
	return node, nil
}
func (i *ShardBlockIndex) HasBlock(hash chainhash.Hash) bool {
	i.Lock.RLock()
	defer i.Lock.RUnlock()
	_, found := i.Index[hash]
	return found
}