public override UnspentOutputs[] FetchCoins(uint256[] txIds) { int remain; int batchCount = Math.DivRem(txIds.Length, BatchMaxSize, out remain); if (batchCount == 0) { return(_Inner.FetchCoins(txIds)); } if (remain > 0) { batchCount++; } UnspentOutputs[] utxos = new UnspentOutputs[txIds.Length]; Task[] subfetch = new Task[batchCount]; int total = txIds.Length; int offset = 0; for (int i = 0; i < batchCount; i++) { int localOffset = offset; int size = Math.Min(BatchMaxSize, total); uint256[] txIdsPart = new uint256[size]; Array.Copy(txIds, offset, txIdsPart, 0, size); total -= size; offset += size; subfetch[i] = new Task(() => { Array.Copy(_Inner.FetchCoins(txIdsPart), 0, utxos, localOffset, txIdsPart.Length); }); subfetch[i].Start(TaskScheduler); } Task.WhenAll(subfetch).GetAwaiter().GetResult(); return(utxos); }
public override Coins[] FetchCoins(uint256[] txIds) { if (_CurrentPrefetch == null) { return(_Inner.FetchCoins(txIds)); } return(_CurrentPrefetch.GetAwaiter().GetResult().FetchCoins(txIds)); }
public override Coins[] FetchCoins(uint256[] txIds) { var fetched = _Cache.FetchCoins(txIds); List <uint256> toFetch = new List <uint256>(txIds.Length); for (int i = 0; i < txIds.Length; i++) { if (fetched[i] == null && !_NotFound.Contains(txIds[i])) { toFetch.Add(txIds[i]); } } PerformanceCounter.AddMissCount(toFetch.Count); PerformanceCounter.AddHitCount(txIds.Length - toFetch.Count); var innerCoins = _Inner.FetchCoins(toFetch.ToArray()); int innerIndex = 0; for (int i = 0; i < txIds.Length; i++) { if (fetched[i] == null && !_NotFound.Contains(txIds[i])) { toFetch.Add(txIds[i]); fetched[i] = innerCoins[innerIndex++]; if (ReadThrough) { AddToCache(txIds[i], fetched[i]); } } } return(fetched); }
public override UnspentOutputs[] FetchCoins(uint256[] txIds) { var fetched = _Cache.FetchCoins(txIds); List <ToFetch> toFetch = new List <ToFetch>(txIds.Length); for (int i = 0; i < txIds.Length; i++) { if (fetched[i] == null && !_NotFound.Contains(txIds[i])) { toFetch.Add(new ToFetch() { TxId = txIds[i], Index = i }); } } PerformanceCounter.AddMissCount(toFetch.Count); PerformanceCounter.AddHitCount(txIds.Length - toFetch.Count); var innerCoins = _Inner.FetchCoins(toFetch.Select(f => f.TxId).ToArray()); for (int i = 0; i < innerCoins.Length; i++) { if (ReadThrough) { AddToCache(toFetch[i].TxId, innerCoins[i]); } fetched[toFetch[i].Index] = innerCoins[i]; } return(fetched); }
public override UnspentOutputs[] FetchCoins(uint256[] txIds) { UnspentOutputs[] coins = new UnspentOutputs[txIds.Length]; int i = 0; int notInCache = 0; foreach (var coin in _Uncommited.FetchCoins(txIds)) { if (coin == null) { notInCache++; } coins[i++] = coin; } uint256[] txIds2 = new uint256[notInCache]; i = 0; for (int ii = 0; ii < txIds.Length; ii++) { if (coins[ii] == null) { txIds2[i++] = txIds[ii]; } } i = 0; foreach (var coin in Inner.FetchCoins(txIds2)) { for (; i < coins.Length;) { if (coins[i] == null) { break; } i++; } if (i >= coins.Length) { break; } if (ReadThrough) { _Uncommited.SaveChange(txIds[i], coin); } coins[i] = coin; i++; } return(coins); }