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;
}