BitSharper.BlockChain.FindSplit C# (CSharp) Method

FindSplit() private method

Locates the point in the chain at which newStoredBlock and chainHead diverge. Returns null if no split point was found (ie they are part of the same chain).
private FindSplit ( StoredBlock newChainHead, StoredBlock chainHead ) : StoredBlock
newChainHead StoredBlock
chainHead StoredBlock
return StoredBlock
        private StoredBlock FindSplit(StoredBlock newChainHead, StoredBlock chainHead)
        {
            var currentChainCursor = chainHead;
            var newChainCursor = newChainHead;
            // Loop until we find the block both chains have in common. Example:
            //
            //    A -> B -> C -> D
            //         \--> E -> F -> G
            //
            // findSplit will return block B. chainHead = D and newChainHead = G.
            while (!currentChainCursor.Equals(newChainCursor))
            {
                if (currentChainCursor.Height > newChainCursor.Height)
                {
                    currentChainCursor = currentChainCursor.GetPrev(_blockStore);
                    Debug.Assert(newChainCursor != null, "Attempt to follow an orphan chain");
                }
                else
                {
                    newChainCursor = newChainCursor.GetPrev(_blockStore);
                    Debug.Assert(currentChainCursor != null, "Attempt to follow an orphan chain");
                }
            }
            return currentChainCursor;
        }