From 81a9e1e893a442c501fcbdae879955c20561195c Mon Sep 17 00:00:00 2001 From: Mike Hearn Date: Tue, 23 Jul 2013 20:10:57 +0200 Subject: [PATCH] Peer: drop out of fast catchup mode when reaching the top of the chain. This bug could cause problems if you sync a wallet containing no keys, and then a chain fork happens (you won't follow the fork). --- core/src/main/java/com/google/bitcoin/core/Peer.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/core/src/main/java/com/google/bitcoin/core/Peer.java b/core/src/main/java/com/google/bitcoin/core/Peer.java index 06b84dfc2..db32fe897 100644 --- a/core/src/main/java/com/google/bitcoin/core/Peer.java +++ b/core/src/main/java/com/google/bitcoin/core/Peer.java @@ -422,7 +422,12 @@ public class Peer { checkState(!downloadBlockBodies, toString()); for (int i = 0; i < m.getBlockHeaders().size(); i++) { Block header = m.getBlockHeaders().get(i); - if (header.getTimeSeconds() < fastCatchupTimeSecs) { + // Process headers until we pass the fast catchup time, or are about to catch up with the head + // of the chain - always process the last block as a full/filtered block to kick us out of the + // fast catchup mode (in which we ignore new blocks). + boolean passedTime = header.getTimeSeconds() >= fastCatchupTimeSecs; + boolean reachedTop = blockChain.getBestChainHeight() >= vPeerVersionMessage.bestHeight; + if (!passedTime && !reachedTop) { if (!vDownloadData) { // Not download peer anymore, some other peer probably became better. log.info("Lost download peer status, throwing away downloaded headers.");