BitSharper.BlockChain.TryConnectingUnconnected C# (CSharp) Method

TryConnectingUnconnected() private method

For each block in unconnectedBlocks, see if we can now fit it on top of the chain and if so, do so.
private TryConnectingUnconnected ( ) : void
return void
        private void TryConnectingUnconnected()
        {
            // For each block in our unconnected list, try and fit it onto the head of the chain. If we succeed remove it
            // from the list and keep going. If we changed the head of the list at the end of the round try again until
            // we can't fit anything else on the top.
            int blocksConnectedThisRound;
            do
            {
                blocksConnectedThisRound = 0;
                foreach (var block in _unconnectedBlocks.ToList())
                {
                    var prev = _blockStore.Get(block.PrevBlockHash);
                    if (prev == null)
                    {
                        // This is still an unconnected/orphan block.
                        continue;
                    }
                    // Otherwise we can connect it now.
                    // False here ensures we don't recurse infinitely downwards when connecting huge chains.
                    Add(block, false);
                    _unconnectedBlocks.Remove(block);
                    blocksConnectedThisRound++;
                }
                if (blocksConnectedThisRound > 0)
                {
                    _log.InfoFormat("Connected {0} floating blocks.", blocksConnectedThisRound);
                }
            } while (blocksConnectedThisRound > 0);
        }