You might be a king or a little street zsweeper, but sooner or later you will dance with the reaper

This commit is contained in:
Duke Leto
2022-08-24 23:38:19 -04:00
parent afd3f93e2e
commit c6e5b07a59
22 changed files with 146 additions and 9 deletions

View File

@@ -38,6 +38,7 @@
#include "crypter.h"
#include "coins.h"
#include "wallet/asyncrpcoperation_saplingconsolidation.h"
#include "wallet/asyncrpcoperation_sweep.h"
#include "zcash/zip32.h"
#include "cc/CCinclude.h"
#include <assert.h>
@@ -483,6 +484,9 @@ void CWallet::ChainTip(const CBlockIndex *pindex,
if (fSaplingConsolidationEnabled) {
RunSaplingConsolidation(pindex->GetHeight());
}
if (fSweepEnabled) {
RunSaplingSweep(pindex->GetHeight());
}
if (fTxDeleteEnabled) {
DeleteWalletTransactions(pindex);
}
@@ -501,6 +505,43 @@ void CWallet::ChainTip(const CBlockIndex *pindex,
}
}
void CWallet::RunSaplingSweep(int blockHeight) {
// Sapling is always active since height=1 of HUSH+HSCs
// if (!NetworkUpgradeActive(blockHeight, Params().GetConsensus(), Consensus::UPGRADE_SAPLING)) {
// return;
// }
AssertLockHeld(cs_wallet);
if (!fSweepEnabled) {
return;
}
if (nextSweep > blockHeight) {
return;
}
//Don't Run if consolidation will run soon.
if (fSaplingConsolidationEnabled && nextConsolidation - 15 <= blockHeight) {
return;
}
//Don't Run While consolidation is running.
if (fConsolidationRunning) {
return;
}
fSweepRunning = true;
std::shared_ptr<AsyncRPCQueue> q = getAsyncRPCQueue();
std::shared_ptr<AsyncRPCOperation> lastOperation = q->getOperationForId(saplingSweepOperationId);
if (lastOperation != nullptr) {
lastOperation->cancel();
}
pendingSaplingSweepTxs.clear();
std::shared_ptr<AsyncRPCOperation> operation(new AsyncRPCOperation_sweep(blockHeight + 5));
saplingSweepOperationId = operation->getId();
q->addOperation(operation);
}
void CWallet::RunSaplingConsolidation(int blockHeight) {
if (!NetworkUpgradeActive(blockHeight, Params().GetConsensus(), Consensus::UPGRADE_SAPLING)) {
return;
@@ -512,6 +553,10 @@ void CWallet::RunSaplingConsolidation(int blockHeight) {
return;
}
if (fSweepRunning) {
return;
}
int consolidateInterval = rand() % 5 + 5;
if(fZdebug)
@@ -530,7 +575,7 @@ void CWallet::RunSaplingConsolidation(int blockHeight) {
}
}
bool CWallet::CommitConsolidationTx(const CTransaction& tx) {
bool CWallet::CommitAutomatedTx(const CTransaction& tx) {
CWalletTx wtx(this, tx);
CReserveKey reservekey(pwalletMain);
fprintf(stderr,"%s: %s\n",__func__,tx.ToString().c_str());