Ignore duplicate adds of the chain head.

This commit is contained in:
Mike Hearn
2011-06-14 16:01:38 +00:00
parent ece79783ab
commit d1385d50df

View File

@@ -116,7 +116,11 @@ public class BlockChain {
statsLastTime = System.currentTimeMillis(); statsLastTime = System.currentTimeMillis();
statsBlocksAdded = 0; statsBlocksAdded = 0;
} }
// We don't check for double adds here to avoid potentially expensive block chain misses. // We check only the chain head for double adds here to avoid potentially expensive block chain misses.
if (block.equals(chainHead.getHeader())) {
// Duplicate add of the block at the top of the chain, can be a natural artifact of the download process.
return true;
}
// Prove the block is internally valid: hash is lower than target, merkle root is correct and so on. // Prove the block is internally valid: hash is lower than target, merkle root is correct and so on.
try { try {
@@ -174,7 +178,11 @@ public class BlockChain {
if (haveNewBestChain) { if (haveNewBestChain) {
log.info("Block is causing a re-organize"); log.info("Block is causing a re-organize");
} else { } else {
log.info("Block forks the chain, but it did not cause a reorganize."); StoredBlock splitPoint = findSplit(newStoredBlock, chainHead);
String splitPointHash =
splitPoint != null ? splitPoint.getHeader().getHashAsString() : "?";
log.info("Block forks the chain at {}, but it did not cause a reorganize:\n{}",
splitPointHash, newStoredBlock);
} }
// We may not have any transactions if we received only a header. That never happens today but will in // We may not have any transactions if we received only a header. That never happens today but will in