Skip to content

Commit ac5476e

Browse files
committed
Merge pull request #6057
7e6569e [squashme] improve/corrects prune mode detection test for required wallet rescans (Jonas Schnelli) 7a12119 [RPC] disable import functions in pruned mode (Jonas Schnelli) 3201035 [autoprune] allow wallet in pruned mode (Jonas Schnelli)
2 parents 3a1d3e8 + 7e6569e commit ac5476e

File tree

2 files changed

+24
-6
lines changed

2 files changed

+24
-6
lines changed

src/init.cpp

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -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();

src/wallet/rpcdump.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,9 @@ UniValue importprivkey(const UniValue& params, bool fHelp)
9494
+ HelpExampleRpc("importprivkey", "\"mykey\", \"testing\", false")
9595
);
9696

97+
if (fPruneMode)
98+
throw JSONRPCError(RPC_WALLET_ERROR, "Importing keys is disabled in pruned mode");
99+
97100
LOCK2(cs_main, pwalletMain->cs_wallet);
98101

99102
EnsureWalletIsUnlocked();
@@ -166,6 +169,9 @@ UniValue importaddress(const UniValue& params, bool fHelp)
166169
+ HelpExampleRpc("importaddress", "\"myaddress\", \"testing\", false")
167170
);
168171

172+
if (fPruneMode)
173+
throw JSONRPCError(RPC_WALLET_ERROR, "Importing addresses is disabled in pruned mode");
174+
169175
LOCK2(cs_main, pwalletMain->cs_wallet);
170176

171177
CScript script;
@@ -236,6 +242,9 @@ UniValue importwallet(const UniValue& params, bool fHelp)
236242
+ HelpExampleRpc("importwallet", "\"test\"")
237243
);
238244

245+
if (fPruneMode)
246+
throw JSONRPCError(RPC_WALLET_ERROR, "Importing wallets is disabled in pruned mode");
247+
239248
LOCK2(cs_main, pwalletMain->cs_wallet);
240249

241250
EnsureWalletIsUnlocked();

0 commit comments

Comments
 (0)