/** * For each block in unconnectedBlocks, see if we can now fit it on top of the chain and if so, do * so. */ private void tryConnectingUnconnected() throws VerificationException, ScriptException, BlockStoreException { // 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; Iterator<Block> iter = unconnectedBlocks.iterator(); while (iter.hasNext()) { Block block = iter.next(); // Look up the blocks previous. StoredBlock prev = blockStore.get(block.getPrevBlockHash()); 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); iter.remove(); blocksConnectedThisRound++; } if (blocksConnectedThisRound > 0) { log.info("Connected {} floating blocks.", blocksConnectedThisRound); } } while (blocksConnectedThisRound > 0); }