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:
@@ -159,7 +159,7 @@ bool AsyncRPCOperation_saplingconsolidation::main_impl() {
|
||||
|
||||
amountConsolidated += amountToSend;
|
||||
auto builder = TransactionBuilder(consensusParams, targetHeight_, pwalletMain);
|
||||
//builder.SetExpiryHeight(targetHeight_ + CONSOLIDATION_EXPIRY_DELTA);
|
||||
builder.SetExpiryHeight(targetHeight_ + CONSOLIDATION_EXPIRY_DELTA);
|
||||
auto actualAmountToSend = amountToSend < fConsolidationTxFee ? 0 : amountToSend - fConsolidationTxFee;
|
||||
LogPrintf("%s: %s Beginning to create transaction with Sapling output amount=%s\n", __func__, opid, FormatMoney(actualAmountToSend));
|
||||
|
||||
@@ -235,7 +235,7 @@ bool AsyncRPCOperation_saplingconsolidation::main_impl() {
|
||||
break;
|
||||
}
|
||||
|
||||
if(pwalletMain->CommitConsolidationTx(tx)) {
|
||||
if(pwalletMain->CommitAutomatedTx(tx)) {
|
||||
LogPrint("zrpcunsafe", "%s: Committed consolidation transaction with txid=%s\n",opid, tx.GetHash().ToString());
|
||||
amountConsolidated += actualAmountToSend;
|
||||
consolidationTxIds.push_back(tx.GetHash().ToString());
|
||||
|
||||
@@ -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());
|
||||
|
||||
@@ -785,6 +785,9 @@ private:
|
||||
std::vector<CTransaction> pendingSaplingConsolidationTxs;
|
||||
AsyncRPCOperationId saplingConsolidationOperationId;
|
||||
|
||||
std::vector<CTransaction> pendingSaplingSweepTxs;
|
||||
AsyncRPCOperationId saplingSweepOperationId;
|
||||
|
||||
void AddToTransparentSpends(const COutPoint& outpoint, const uint256& wtxid);
|
||||
void AddToSaplingSpends(const uint256& nullifier, const uint256& wtxid);
|
||||
void AddToSpends(const uint256& wtxid);
|
||||
@@ -797,7 +800,13 @@ public:
|
||||
*/
|
||||
int64_t nWitnessCacheSize;
|
||||
bool needsRescan = false;
|
||||
int nextConsolidation = 0;
|
||||
|
||||
bool fSaplingConsolidationEnabled = false;
|
||||
bool fConsolidationRunning = false;
|
||||
bool fSweepEnabled = false;
|
||||
bool fSweepRunning = false;
|
||||
int nextSweep = 0;
|
||||
|
||||
void ClearNoteWitnessCache();
|
||||
|
||||
@@ -1181,12 +1190,14 @@ public:
|
||||
CAmount GetCredit(const CTransaction& tx, int32_t voutNum, const isminefilter& filter) const;
|
||||
CAmount GetCredit(const CTransaction& tx, const isminefilter& filter) const;
|
||||
CAmount GetChange(const CTransaction& tx) const;
|
||||
void RunSaplingSweep(int blockHeight);
|
||||
|
||||
void ChainTip(
|
||||
const CBlockIndex *pindex,
|
||||
const CBlock *pblock,
|
||||
boost::optional<std::pair<SproutMerkleTree, SaplingMerkleTree>> added);
|
||||
void RunSaplingConsolidation(int blockHeight);
|
||||
bool CommitConsolidationTx(const CTransaction& tx);
|
||||
bool CommitAutomatedTx(const CTransaction& tx);
|
||||
/** Saves witness caches and best block locator to disk. */
|
||||
void SetBestChain(const CBlockLocator& loc);
|
||||
std::set<std::pair<libzcash::PaymentAddress, uint256>> GetNullifiersForAddresses(const std::set<libzcash::PaymentAddress> & addresses);
|
||||
|
||||
Reference in New Issue
Block a user