+func (c *cache) lookupMainChainHash(height uint64) (*bc.Hash, error) {
+ if hash, ok := c.lruMainChainHashes.Get(height); ok {
+ return hash.(*bc.Hash), nil
+ }
+
+ heightStr := strconv.FormatUint(height, 10)
+ hash, err := c.sf.Do("BlockHashByHeight:"+heightStr, func() (interface{}, error) {
+ hash, err := c.fillMainChainHashFn(height)
+ if err != nil {
+ return nil, err
+ }
+
+ c.lruMainChainHashes.Add(height, hash)
+ return hash, nil
+ })
+ if err != nil {
+ return nil, err
+ }
+ return hash.(*bc.Hash), nil
+}
+
+func (c *cache) lookupBlockHashesByHeight(height uint64) ([]*bc.Hash, error) {
+ if hashes, ok := c.lruBlockHashes.Get(height); ok {
+ return hashes.([]*bc.Hash), nil
+ }
+
+ heightStr := strconv.FormatUint(height, 10)
+ hashes, err := c.sf.Do("BlockHashesByHeight:"+heightStr, func() (interface{}, error) {
+ hashes, err := c.fillBlockHashesFn(height)
+ if err != nil {
+ return nil, err
+ }
+
+ c.lruBlockHashes.Add(height, hashes)
+ return hashes, nil
+ })
+ if err != nil {
+ return nil, err
+ }
+ return hashes.([]*bc.Hash), nil
+}
+