@@ -714,16 +714,12 @@ bool AppInit2(boost::thread_group& threadGroup, CScheduler& scheduler)
714714 nMaxConnections = nFD - MIN_CORE_FILEDESCRIPTORS;
715715
716716 // if using block pruning, then disable txindex
717- // also disable the wallet (for now, until SPV support is implemented in wallet)
718717 if (GetArg (" -prune" , 0 )) {
719718 if (GetBoolArg (" -txindex" , false ))
720719 return InitError (_ (" Prune mode is incompatible with -txindex." ));
721720#ifdef ENABLE_WALLET
722- if (!GetBoolArg (" -disablewallet" , false )) {
723- if (SoftSetBoolArg (" -disablewallet" , true ))
724- LogPrintf (" %s : parameter interaction: -prune -> setting -disablewallet=1\n " , __func__);
725- else
726- return InitError (_ (" Can't run with a wallet in prune mode." ));
721+ if (GetBoolArg (" -rescan" , false )) {
722+ return InitError (_ (" Rescans are not possible in pruned mode. You will need to use -reindex which will download the whole blockchain again." ));
727723 }
728724#endif
729725 }
@@ -1310,6 +1306,19 @@ bool AppInit2(boost::thread_group& threadGroup, CScheduler& scheduler)
13101306 }
13111307 if (chainActive.Tip () && chainActive.Tip () != pindexRescan)
13121308 {
1309+ // We can't rescan beyond non-pruned blocks, stop and throw an error
1310+ // this might happen if a user uses a old wallet within a pruned node
1311+ // or if he ran -disablewallet for a longer time, then decided to re-enable
1312+ if (fPruneMode )
1313+ {
1314+ CBlockIndex *block = chainActive.Tip ();
1315+ while (block && block->pprev && (block->pprev ->nStatus & BLOCK_HAVE_DATA) && block->pprev ->nTx > 0 && pindexRescan != block)
1316+ block = block->pprev ;
1317+
1318+ if (pindexRescan != block)
1319+ return InitError (_ (" Prune: last wallet synchronisation goes beyond pruned data. You need to -reindex (download the whole blockchain again in case of pruned node)" ));
1320+ }
1321+
13131322 uiInterface.InitMessage (_ (" Rescanning..." ));
13141323 LogPrintf (" Rescanning last %i blocks (from block %i)...\n " , chainActive.Height () - pindexRescan->nHeight , pindexRescan->nHeight );
13151324 nStart = GetTimeMillis ();
0 commit comments