// FetchHeaderByHeight returns the filter header for a particular block height.
335689
func (f *FilterHeaderStore) FetchHeaderByHeight(height uint32) (*chainhash.Hash, error) {
	// Lock store for read.
	f.mtx.RLock()
	defer f.mtx.RUnlock()

	return f.readHeader(height)
}
513288
func (pgb *ChainDB) BlockTimeByHeight(height int64) (int64, error) {
	ctx, cancel := context.WithTimeout(pgb.ctx, pgb.queryTimeout)
	defer cancel()
	time, err := RetrieveBlockTimeByHeight(ctx, pgb.db, height)
	return time.UNIX(), pgb.replaceCancelError(err)
}
53619
func (g *BlockGate) SetFetchToHeight(height int64) {
	g.mtx.RLock()
	defer g.mtx.RUnlock()
	g.fetchToHeight = height
}
783124
func (h *blockHeaderStore) HeightFromHash(hash *chainhash.Hash) (uint32, error) {
	return h.heightFromHash(hash)
}
588795
func (p *BlockPrefetchClient) HaveBlockHeight(height uint32) bool {
	p.Lock()
	defer p.Unlock()
	return p.haveBlockHeight(height)
}
1236418
func (db *DB) RetrieveHighestBlockHeight() (int64, error) {
	var blockHeight int64
	err := db.QueryRow(db.getHighestBlockHeightSQL).Scan(&blockHeight)
	return blockHeight, err
}
1262437
func (db *SQLDB) GetLastBlockHeight() (uint64, error) {
	query := db.DBAdapter.LastBlockIDQuery()
	id := ""

	db.Log.Info("msg", "MAX ID", "query", query)

	if err := db.DB.QueryRow(query).Scan(&id); err != nil {
		db.Log.Info("msg", "Error selecting last block id", "err", err)
		return 0, err
	}
	height, err := strconv.ParseUint(id, 10, 64)
	if err != nil {
		return 0, fmt.Errorf("could not parse height from block ID: %v", err)
	}
	return height, nil
}
880962
func (s *SupportImpl) GetLedgerHeight(channelID string) (uint64, error) {
	lgr := s.Peer.GetLedger(channelID)
	if lgr == nil {
		return 0, errors.Errorf("failed to look up the ledger for Channel %s", channelID)
	}

	info, err := lgr.GetBlockchainInfo()
	if err != nil {
		return 0, errors.Wrap(err, fmt.Sprintf("failed to obtain information for Channel %s", channelID))
	}

	return info.Height, nil
}
464691
func (s *NeutrinoClient) GetBlockHash(height int64) (*chainhash.Hash, error) {
	return s.CS.GetBlockHash(height)
}
586896
func (c *chainView) NodeByHeight(height int32) *blockNode {
	c.mtx.Lock()
	node := c.nodeByHeight(height)
	c.mtx.Unlock()
	return node
}
1088610
func (qs *queryServer) GetBlockHeader(ctx context.Context, param *GetBlockParam) (*types.Header, error) {
	header, err := qs.blockchain.GetBlockHeader(param.Height)
	if err != nil {
		return nil, err
	}
	abciHeader := tmtypes.TM2PB.Header(header)
	return &abciHeader, nil
}
431813
func (db *DB) GetBlockSummaryHeight() (int64, error) {
	db.mtx.RLock()
	defer db.mtx.RUnlock()
	if db.dbSummaryHeight < 0 {
		h, err := db.getBlockSummaryHeight()
		if err == nil {
			db.dbSummaryHeight = h
		}
		return h, err
	}
	return db.dbSummaryHeight, nil
}
1290085
func dbFetchHeightByHash(dbTx database.Tx, hash *chainhash.Hash) (int32, error) {
	meta := dbTx.Metadata()
	hashIndex := meta.Bucket(hashIndexBucketName)
	serializedHeight := hashIndex.Get(hash[:])
	if serializedHeight == nil {
		str := fmt.Sprintf("block %s is not in the main chain", hash)
		return 0, errNotInMainChain(str)
	}

	return int32(byteOrder.Uint32(serializedHeight)), nil
}
662126
func (g *BlockGate) NodeHeight() (int64, error) {
	_, height, err := g.client.GetBestBlock()
	return height, err
}
904189
func (c *MempoolDataCache) GetHeight() uint32 {
	c.mtx.RLock()
	defer c.mtx.RUnlock()
	return c.height
}
1004339
func (b *blockManager) getCFHeadersForAllPeers(height uint32,
	fType wire.FilterType) (map[string]*wire.MsgCFHeaders, int) {

	// Create the map we're returning.
	headers := make(map[string]*wire.MsgCFHeaders)

	// Get the header we expect at either the tip of the block header store
	// or at the end of the maximum-size response message, whichever is
	// larger.
	stopHeader, stopHeight, err := b.server.BlockHeaders.ChainTip()
	if stopHeight-height >= wire.MaxCFHeadersPerMsg {
		stopHeader, err = b.server.BlockHeaders.FetchHeaderByHeight(
			height + wire.MaxCFHeadersPerMsg - 1,
		)
		if err != nil {
			return nil, 0
		}

		// We'll make sure we also update our stopHeight so we know how
		// many headers to expect below.
		stopHeight = height + wire.MaxCFHeadersPerMsg - 1
	}

	// Calculate the hash and use it to create the query message.
	stopHash := stopHeader.BlockHash()
	msg := wire.NewMsgGetCFHeaders(fType, height, &stopHash)
	numHeaders := int(stopHeight - height + 1)

	// Send the query to all peers and record their responses in the map.
	b.server.queryAllPeers(
		msg,
		func(sp *ServerPeer, resp wire.Message, quit chan<- struct{},
			peerQuit chan<- struct{}) {
			switch m := resp.(type) {
			case *wire.MsgCFHeaders:
				if m.StopHash == stopHash &&
					m.FilterType == fType &&
					len(m.FilterHashes) == numHeaders {

					headers[sp.Addr()] = m

					// We got an answer from this peer so
					// that peer's goroutine can stop.
					close(peerQuit)
				}
			}
		},
	)

	return headers, numHeaders
}
914090
func (s *Status) SetHeight(height uint32) {
	s.Lock()
	defer s.Unlock()
	s.ready = height == s.dbHeight
	s.height = height
}