From fe32a3be6c8950266d759103d2fb2beda635967e Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 16 Dec 2018 07:39:54 -1100 Subject: [PATCH] Fix stuck sync for nodes that are doing full sync MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The sapling height is calculated near the sapling activation timestamp. Until it is set, the node doesn’t know when sapling should be active. Depending on the speed at which you get blocks from the future, it was possible that you could see a sapling active block before the sapling height was set. This would happen only if syncing from a node that didn’t know the sapling height and a full resync with the most peers and most variety of incoming block sources was most likely hit by this. The net effect was that the blocks after sapling activation were marked as invalid, so by the time the node synced up to the sapling height, it couldn’t advance. --- src/main.cpp | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/main.cpp b/src/main.cpp index 6c33feb08..d822c8686 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -5043,6 +5043,19 @@ bool AcceptBlock(int32_t *futureblockp,CBlock& block, CValidationState& state, C auto verifier = libzcash::ProofVerifier::Disabled(); if ((!CheckBlock(futureblockp,pindex->GetHeight(),pindex,block, state, verifier,0)) || !ContextualCheckBlock(block, state, pindex->pprev)) { + static int32_t saplinght = -1; + CBlockIndex *tmpptr; + if ( saplinght == -1 ) + saplinght = Params().GetConsensus().vUpgrades[Consensus::UPGRADE_SAPLING].nActivationHeight; + if ( saplinght < 0 ) + *futureblockp = 1; + // the problem is when a future sapling block comes in before we detected saplinght + if ( saplinght > 0 && (tmpptr= chainActive.LastTip()) != 0 ) + { + fprintf(stderr,"saplinght.%d tipht.%d blockht.%d cmp.%d\n",saplinght,(int32_t)tmpptr->GetHeight(),pindex->GetHeight(),pindex->GetHeight() < 0 || pindex->GetHeight() >= saplinght || (tmpptr->GetHeight() > saplinght-720 && tmpptr->GetHeight() < saplinght+720)); + if ( pindex->GetHeight() < 0 || pindex->GetHeight() >= saplinght || (tmpptr->GetHeight() > saplinght-720 && tmpptr->GetHeight() < saplinght+720) ) + *futureblockp = 1; + } if ( *futureblockp == 0 ) { if (state.IsInvalid() && !state.CorruptionPossible()) {