From 3201035f22fe451c808b0bb157d33a58f0d99c07 Mon Sep 17 00:00:00 2001 From: Jonas Schnelli Date: Fri, 24 Apr 2015 21:31:46 +0200 Subject: [PATCH 1/3] [autoprune] allow wallet in pruned mode --- src/init.cpp | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/src/init.cpp b/src/init.cpp index f4136f09e9a..c102464ad90 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -714,16 +714,12 @@ bool AppInit2(boost::thread_group& threadGroup, CScheduler& scheduler) nMaxConnections = nFD - MIN_CORE_FILEDESCRIPTORS; // if using block pruning, then disable txindex - // also disable the wallet (for now, until SPV support is implemented in wallet) if (GetArg("-prune", 0)) { if (GetBoolArg("-txindex", false)) return InitError(_("Prune mode is incompatible with -txindex.")); #ifdef ENABLE_WALLET - if (!GetBoolArg("-disablewallet", false)) { - if (SoftSetBoolArg("-disablewallet", true)) - LogPrintf("%s : parameter interaction: -prune -> setting -disablewallet=1\n", __func__); - else - return InitError(_("Can't run with a wallet in prune mode.")); + if (GetBoolArg("-rescan", false)) { + return InitError(_("Rescans are not possible in pruned mode. You will need to use -reindex which will download the whole blockchain again.")); } #endif } @@ -1316,6 +1312,19 @@ bool AppInit2(boost::thread_group& threadGroup, CScheduler& scheduler) } if (chainActive.Tip() && chainActive.Tip() != pindexRescan) { + //We can't rescan beyond non-pruned blocks, stop and throw an error + //this might happen if a user uses a old wallet within a pruned node + // or if he ran -disablewallet for a longer time, then decided to re-enable + if (fPruneMode) + { + CBlockIndex *block = chainActive.Tip(); + while (block && block->pprev && (block->pprev->nStatus & BLOCK_HAVE_DATA) && pindexRescan != block) + block = block->pprev; + + if (pindexRescan != block) + return InitError(_("Prune: last wallet synchronisation goes beyond pruned data. You need to -reindex (download the whole blockchain again in case of pruned node)")); + } + uiInterface.InitMessage(_("Rescanning...")); LogPrintf("Rescanning last %i blocks (from block %i)...\n", chainActive.Height() - pindexRescan->nHeight, pindexRescan->nHeight); nStart = GetTimeMillis(); From 7a12119d7a9084010725cf5b95bafcc3cf2c1d71 Mon Sep 17 00:00:00 2001 From: Jonas Schnelli Date: Fri, 24 Apr 2015 21:42:51 +0200 Subject: [PATCH 2/3] [RPC] disable import functions in pruned mode import functions could lead to a rescan beyond prune level --- src/wallet/rpcdump.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/wallet/rpcdump.cpp b/src/wallet/rpcdump.cpp index ab951d1d7d1..b8fb0675ed6 100644 --- a/src/wallet/rpcdump.cpp +++ b/src/wallet/rpcdump.cpp @@ -95,6 +95,9 @@ Value importprivkey(const Array& params, bool fHelp) + HelpExampleRpc("importprivkey", "\"mykey\", \"testing\", false") ); + if (fPruneMode) + throw JSONRPCError(RPC_WALLET_ERROR, "Importing keys is disabled in pruned mode"); + LOCK2(cs_main, pwalletMain->cs_wallet); EnsureWalletIsUnlocked(); @@ -167,6 +170,9 @@ Value importaddress(const Array& params, bool fHelp) + HelpExampleRpc("importaddress", "\"myaddress\", \"testing\", false") ); + if (fPruneMode) + throw JSONRPCError(RPC_WALLET_ERROR, "Importing addresses is disabled in pruned mode"); + LOCK2(cs_main, pwalletMain->cs_wallet); CScript script; @@ -237,6 +243,9 @@ Value importwallet(const Array& params, bool fHelp) + HelpExampleRpc("importwallet", "\"test\"") ); + if (fPruneMode) + throw JSONRPCError(RPC_WALLET_ERROR, "Importing wallets is disabled in pruned mode"); + LOCK2(cs_main, pwalletMain->cs_wallet); EnsureWalletIsUnlocked(); From 7e6569ea5be8cb26454ede3efb6a50b393aaa9be Mon Sep 17 00:00:00 2001 From: Jonas Schnelli Date: Wed, 29 Apr 2015 13:30:16 +0200 Subject: [PATCH 3/3] [squashme] improve/corrects prune mode detection test for required wallet rescans --- src/init.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/init.cpp b/src/init.cpp index c102464ad90..24e7e1c04a4 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -1318,7 +1318,7 @@ bool AppInit2(boost::thread_group& threadGroup, CScheduler& scheduler) if (fPruneMode) { CBlockIndex *block = chainActive.Tip(); - while (block && block->pprev && (block->pprev->nStatus & BLOCK_HAVE_DATA) && pindexRescan != block) + while (block && block->pprev && (block->pprev->nStatus & BLOCK_HAVE_DATA) && block->pprev->nTx > 0 && pindexRescan != block) block = block->pprev; if (pindexRescan != block)