Merge branch 'fix/sweep-consolidation-fairness' into dev
This commit is contained in:
@@ -129,8 +129,10 @@ wallet: `N addresses have more than 25 spendable notes; consider -consolidation=
|
||||
|
||||
1. With zsweep on, consolidation only works on the sweep address: a `consolidatesaplingaddress` other than the
|
||||
sweep address is refused at startup (with `consolidation=0` it is replaced by the sweep address, with a warning),
|
||||
and `z_consolidate` refuses any other address too. Sweep and consolidation never run at the same time, and a
|
||||
sweep is not started when a consolidation round is due within 5 blocks.
|
||||
and `z_consolidate` refuses any other address too. Sweep and consolidation never run at the same time. A due sweep
|
||||
gives way once, to a consolidation round that is running or due within 5 blocks; after that no new consolidation
|
||||
round starts until the sweep has run, so neither can starve the other. `z_sweepstatus` shows
|
||||
`"waiting_for_consolidation": true` while a sweep is waiting.
|
||||
|
||||
### Copyright
|
||||
|
||||
|
||||
@@ -3536,6 +3536,8 @@ UniValue z_sweepstatus(const UniValue& params, bool fHelp, const CPubKey& mypk)
|
||||
" \"running\" : true|false, (boolean) whether a sweep round is in flight\n"
|
||||
" \"wallet_locked\" : true|false, (boolean) the wallet is encrypted and locked, so nothing can be swept\n"
|
||||
" until it is unlocked with walletpassphrase\n"
|
||||
" \"waiting_for_consolidation\" : true|false, (boolean) a due round is waiting for a consolidation round to end;\n"
|
||||
" no new consolidation round starts until it has run\n"
|
||||
" \"amount_swept\" : x.xxx, (numeric) DRGX sent to the sweep address since startup\n"
|
||||
" \"next_zsweep\" : n, (numeric) height of the next round\n"
|
||||
" \"zsweepinterval\" : n, (numeric) blocks between rounds\n"
|
||||
@@ -3556,6 +3558,7 @@ UniValue z_sweepstatus(const UniValue& params, bool fHelp, const CPubKey& mypk)
|
||||
ret.push_back(Pair("zsweep", pwalletMain->fSweepEnabled));
|
||||
ret.push_back(Pair("running", pwalletMain->fSweepRunning));
|
||||
ret.push_back(Pair("wallet_locked", pwalletMain->IsLocked()));
|
||||
ret.push_back(Pair("waiting_for_consolidation", pwalletMain->fSweepWaiting));
|
||||
ret.push_back(Pair("amount_swept", ValueFromAmount(pwalletMain->amountSwept)));
|
||||
ret.push_back(Pair("next_zsweep", pwalletMain->nextSweep));
|
||||
ret.push_back(Pair("zsweepinterval", pwalletMain->sweepInterval));
|
||||
|
||||
+21
-4
@@ -640,6 +640,7 @@ void CWallet::RunSaplingSweep(int blockHeight) {
|
||||
}
|
||||
|
||||
if (!fSweepEnabled) {
|
||||
fSweepWaiting = false;
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -666,18 +667,26 @@ void CWallet::RunSaplingSweep(int blockHeight) {
|
||||
LogPrintf("%s: wallet locked; not sweeping at height=%d. Unlock it with walletpassphrase "
|
||||
"for zsweep to resume\n", __func__, blockHeight);
|
||||
nextSweep = sweepInterval + blockHeight;
|
||||
fSweepWaiting = false;
|
||||
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);
|
||||
// Yield to consolidation once, then take priority. Both checks used to return without any memory of
|
||||
// having done so: with a consolidation interval of 5 the "within 5 blocks" test is always true, and
|
||||
// otherwise a long consolidation round filled the remaining blocks, so the sweep could go a whole run
|
||||
// without dispatching while deposits piled up. fSweepWaiting makes RunSaplingConsolidation hold off its
|
||||
// next round, and lets the sweep past the blackout below on a later block.
|
||||
//Don't Run if consolidation will run soon, unless this sweep has already waited for consolidation.
|
||||
if (!fSweepWaiting && fSaplingConsolidationEnabled && nextConsolidation - 5 <= blockHeight) {
|
||||
LogPrintf("%s: not sweeping since next consolidation is within 5 blocks, nextConsolidation=%d , blockHeight=%d; the sweep goes first next time\n", __func__, nextConsolidation, blockHeight);
|
||||
fSweepWaiting = true;
|
||||
return;
|
||||
}
|
||||
|
||||
//Don't Run While consolidation is running.
|
||||
if (fConsolidationRunning) {
|
||||
LogPrintf("%s: not sweeping since consolidation is currently running at height=%d\n", __func__, blockHeight);
|
||||
LogPrintf("%s: not sweeping since consolidation is currently running at height=%d; no new consolidation round starts until this sweep has run\n", __func__, blockHeight);
|
||||
fSweepWaiting = true;
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -688,6 +697,7 @@ void CWallet::RunSaplingSweep(int blockHeight) {
|
||||
}
|
||||
|
||||
fSweepRunning = true;
|
||||
fSweepWaiting = false;
|
||||
|
||||
std::shared_ptr<AsyncRPCQueue> q = getAsyncRPCQueue();
|
||||
std::shared_ptr<AsyncRPCOperation> lastOperation = q->getOperationForId(saplingSweepOperationId);
|
||||
@@ -749,6 +759,13 @@ void CWallet::RunSaplingConsolidation(int blockHeight) {
|
||||
return;
|
||||
}
|
||||
|
||||
// A due sweep already gave way to this op once (see fSweepWaiting): let it run before the next round.
|
||||
// nextConsolidation is left as it is, so this round starts as soon as that sweep finishes.
|
||||
if (fSweepWaiting && fSweepEnabled) {
|
||||
LogPrintf("%s: not consolidating since a due sweep is waiting at height=%d\n", __func__, blockHeight);
|
||||
return;
|
||||
}
|
||||
|
||||
if (fAutoShieldRunning) {
|
||||
LogPrintf("%s: not consolidating since autoshield is currently running at height=%d\n", __func__, blockHeight);
|
||||
return;
|
||||
|
||||
@@ -908,6 +908,10 @@ public:
|
||||
bool fSweepEnabled = false;
|
||||
bool fSweepExternalEnabled = false;
|
||||
bool fSweepRunning = false;
|
||||
// A due sweep was held back by consolidation (running, or about to run). While set, consolidation
|
||||
// starts no new round and the sweep skips its pre-consolidation blackout, so the sweep goes as soon
|
||||
// as the running round ends instead of losing every block to consolidation. Cleared on dispatch.
|
||||
bool fSweepWaiting = false;
|
||||
|
||||
// Automatic coinbase shielding (t->z). The real default is computed in
|
||||
// init.cpp: ON only for known-recoverable seed provenance (CREATED/RESTORED),
|
||||
|
||||
Reference in New Issue
Block a user