private uint256[] GetIdsToPrefetch(Block block, CacheCoinView cache, bool enforceBIP30) { List <uint256> ids = new List <uint256>(block.Transactions.Count + block.Transactions.Where(tx => !tx.IsCoinBase).SelectMany(txin => txin.Inputs).Count()); foreach (var tx in block.Transactions) { if (enforceBIP30) { var txId = tx.GetHash(); if (cache == null || !cache.Contains(txId)) { ids.Add(txId); } } if (!tx.IsCoinBase) { foreach (var input in tx.Inputs) { if (cache == null || !cache.Contains(input.PrevOut.Hash)) { ids.Add(input.PrevOut.Hash); } } } } return(ids.ToArray()); }
private static Task GetPrefetchingTask(CacheCoinView cache, ILookaheadBlockPuller lookaheadPuller, ConsensusFlags flags) { Task prefetching = Task.FromResult <bool>(true); if (cache != null && lookaheadPuller != null) { var nextBlock = lookaheadPuller.TryGetLookahead(0); if (nextBlock != null) { prefetching = Task.Run(() => cache.FetchCoins(GetIdsToFetch(nextBlock, flags.EnforceBIP30))); } } return(prefetching); }