aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSuhas Daftuar <sdaftuar@gmail.com>2016-04-20 13:49:55 -0400
committerMarcoFalke <falke.marco@gmail.com>2016-04-27 22:34:48 +0200
commit43c14acf14ee191d946de070615bed93a0601dfa (patch)
tree8115a2574088090fd52f0cec77ca1507766b6593
parent06c73a1751b346726f549c2780bc1b2a19035db9 (diff)
downloadbitcoin-43c14acf14ee191d946de070615bed93a0601dfa.tar.xz
Fix headers announcements edge case
Previously we would assert that if every block in vBlockHashesToAnnounce is in chainActive, then the blocks to be announced must connect. However, there are edge cases where this assumption could be violated (eg using invalidateblock / reconsiderblock), so just check for this case and revert to inv-announcement instead. Github-Pull: #7919 Rebased-From: 3a99fb2cb14955f5e029d315041a093e957e6c3e
-rw-r--r--src/main.cpp16
1 files changed, 15 insertions, 1 deletions
diff --git a/src/main.cpp b/src/main.cpp
index 1ae202ea40..5187d543a1 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -5770,7 +5770,21 @@ bool SendMessages(CNode* pto)
fRevertToInv = true;
break;
}
- assert(pBestIndex == NULL || pindex->pprev == pBestIndex);
+ if (pBestIndex != NULL && pindex->pprev != pBestIndex) {
+ // This means that the list of blocks to announce don't
+ // connect to each other.
+ // This shouldn't really be possible to hit during
+ // regular operation (because reorgs should take us to
+ // a chain that has some block not on the prior chain,
+ // which should be caught by the prior check), but one
+ // way this could happen is by using invalidateblock /
+ // reconsiderblock repeatedly on the tip, causing it to
+ // be added multiple times to vBlockHashesToAnnounce.
+ // Robustly deal with this rare situation by reverting
+ // to an inv.
+ fRevertToInv = true;
+ break;
+ }
pBestIndex = pindex;
if (fFoundStartingHeader) {
// add this to the headers message