private async Task <Dictionary <int, ICalculateWay> > GetPieceWiseFuncUnderContextAsync() { var keys = _cacheCacheProvider.GetForkCacheKeys(); if (keys.Length == 0) { return(await GetDefaultPieceWiseFunctionAsync()); } var minHeight = keys.Select(k => k.BlockHeight).Min(); Dictionary <int, ICalculateWay> algorithm = null; var blockIndex = new BlockIndex { BlockHash = CalculateAlgorithmContext.BlockIndex.BlockHash, BlockHeight = CalculateAlgorithmContext.BlockIndex.BlockHeight }; do { if (_cacheCacheProvider.TryGetPieceWiseFunctionFromForkCacheByBlockIndex(blockIndex, out var value)) { algorithm = value; break; } var link = _chainBlockLinkService.GetCachedChainBlockLink(blockIndex.BlockHash); blockIndex.BlockHash = link?.PreviousBlockHash; blockIndex.BlockHeight--; } while (blockIndex.BlockHash != null && blockIndex.BlockHeight >= minHeight); return(algorithm ?? await GetDefaultPieceWiseFunctionAsync()); }