diff --git a/src/wallet/asyncrpcoperation_sweep.cpp b/src/wallet/asyncrpcoperation_sweep.cpp index 981141099..c40b091aa 100644 --- a/src/wallet/asyncrpcoperation_sweep.cpp +++ b/src/wallet/asyncrpcoperation_sweep.cpp @@ -128,6 +128,15 @@ bool AsyncRPCOperation_sweep::main_impl() { return true; } + // A locked wallet yields no spending keys, so every address below would be skipped and the round + // would report success having swept nothing. RunSaplingSweep already declines to enqueue while + // locked; this catches a wallet locked between enqueue and execution, and makes the reason + // visible in z_getoperationstatus. + if (pwalletMain->IsLocked()) { + LogPrintf("%s: wallet is locked; nothing can be swept. Unlock it with walletpassphrase\n", getId()); + throw JSONRPCError(RPC_WALLET_UNLOCK_NEEDED, "Wallet is locked; unlock it with walletpassphrase for zsweep to sign"); + } + std::vector saplingEntries; libzcash::SaplingPaymentAddress sweepAddress; std::map> mapAddresses; @@ -342,6 +351,17 @@ bool AsyncRPCOperation_sweep::main_impl() { status = false; break; } + } else if (pwalletMain->IsLocked()) { + // Locked part-way through the round (a walletpassphrase timeout): nothing further can be + // signed. Fail the round rather than report the unswept addresses as done. + LogPrintf("%s: wallet was locked during the sweep; stopping. Unlock it with walletpassphrase\n", getId()); + set_error_code(RPC_WALLET_UNLOCK_NEEDED); + set_error_message("Wallet was locked during the sweep; unlock it with walletpassphrase for zsweep to sign"); + status = false; + break; + } else { + // A viewing-key-only address: its notes are visible but cannot be spent from this wallet. + LogPrint("zrpcunsafe", "%s: no spending key for %s; not sweeping it\n", getId(), EncodePaymentAddress(addr)); } } diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index 941fb08dc..100e5dc66 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -660,6 +660,15 @@ void CWallet::RunSaplingSweep(int blockHeight) { } LogPrintf("%s: Sweep enabled at blockHeight=%d nextSweep=%d\n", __func__, blockHeight, nextSweep); + // Nothing can be signed while the wallet is locked: every address would be skipped and the round + // would report success with nothing swept. Say so, and look again an interval later. + if (IsLocked()) { + LogPrintf("%s: wallet locked; not sweeping at height=%d. Unlock it with walletpassphrase " + "for zsweep to resume\n", __func__, blockHeight); + nextSweep = sweepInterval + blockHeight; + return; + } + //Don't Run if consolidation will run soon. if (fSaplingConsolidationEnabled && nextConsolidation - 5 <= blockHeight) { LogPrintf("%s: not sweeping since next consolidation is within 5 blocks, nextConsolidation=%d , blockHeight=%d\n", __func__, nextConsolidation, blockHeight);