From f48181a1207ba8c325bfb6c88b03ec2521c548a0 Mon Sep 17 00:00:00 2001 From: Duke Date: Wed, 25 Oct 2023 13:16:47 -0400 Subject: [PATCH 1/6] Add help for -consolidationinterval which was missing --- src/init.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/init.cpp b/src/init.cpp index f49e146dd..20ef95b45 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -458,6 +458,7 @@ std::string HelpMessage(HelpMessageMode mode) strUsage += HelpMessageOpt("-disablewallet", _("Do not load the wallet and disable wallet RPC calls")); strUsage += HelpMessageOpt("-keypool=", strprintf(_("Set key pool size to (default: %u)"), 100)); strUsage += HelpMessageOpt("-consolidation", _("Enable auto Sapling note consolidation (default: false)")); + strUsage += HelpMessageOpt("-consolidationinterval", _("Block interval between consolidations (default: 25)")); strUsage += HelpMessageOpt("-consolidatesaplingaddress=", _("Specify Sapling Address to Consolidate. (default: all)")); strUsage += HelpMessageOpt("-consolidationtxfee", strprintf(_("Fee amount in Puposhis used send consolidation transactions. (default %i)"), DEFAULT_CONSOLIDATION_FEE)); From b73297f1f52892933d64e978df7800009b06b5eb Mon Sep 17 00:00:00 2001 From: Duke Date: Wed, 25 Oct 2023 13:17:10 -0400 Subject: [PATCH 2/6] More debugging when resending txs --- src/wallet/wallet.cpp | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index 43f4b5b2a..a615d5bdc 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -3116,6 +3116,7 @@ std::vector CWallet::ResendWalletTransactionsBefore(int64_t nTime) // Sort them in chronological order multimap mapSorted; uint32_t now = (uint32_t)time(NULL); + LogPrintf("%s: nTime=%ld now=%d\n", __func__, nTime, now); // vector of wallet transactions to delete std::vector vwtxh; @@ -3183,6 +3184,7 @@ std::vector CWallet::ResendWalletTransactionsBefore(int64_t nTime) void CWallet::ResendWalletTransactions(int64_t nBestBlockTime) { + LogPrintf("%s: nBestBlockTime=%ld nNextResend=%ld nLastResend=%ld time=%ld\n", __func__, nBestBlockTime, nNextResend, nLastResend, GetTime()); // Do this infrequently and randomly to avoid giving away // that these are our transactions. if (GetTime() < nNextResend || !fBroadcastTransactions) @@ -3207,15 +3209,11 @@ void CWallet::ResendWalletTransactions(int64_t nBestBlockTime) /** @} */ // end of mapWallet - - - /** @defgroup Actions * * @{ */ - CAmount CWallet::GetBalance() const { CAmount nTotal = 0; From f0395196ec8bbd2b5e01e52dc01bfe5e474e30c0 Mon Sep 17 00:00:00 2001 From: Duke Date: Sun, 29 Oct 2023 21:45:30 -0400 Subject: [PATCH 3/6] Do not resend wallet txs during IBD, rescan or loading blocks --- src/wallet/wallet.cpp | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index a615d5bdc..3071d46a7 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -67,6 +67,7 @@ bool fPayAtLeastCustomFee = true; CBlockIndex *hush_chainactive(int32_t height); extern std::string DONATION_PUBKEY; +extern int32_t HUSH_LOADINGBLOCKS; int32_t hush_dpowconfs(int32_t height,int32_t numconfs); int tx_height( const uint256 &hash ); bool fTxDeleteEnabled = false; @@ -3184,7 +3185,6 @@ std::vector CWallet::ResendWalletTransactionsBefore(int64_t nTime) void CWallet::ResendWalletTransactions(int64_t nBestBlockTime) { - LogPrintf("%s: nBestBlockTime=%ld nNextResend=%ld nLastResend=%ld time=%ld\n", __func__, nBestBlockTime, nNextResend, nLastResend, GetTime()); // Do this infrequently and randomly to avoid giving away // that these are our transactions. if (GetTime() < nNextResend || !fBroadcastTransactions) @@ -3195,11 +3195,26 @@ void CWallet::ResendWalletTransactions(int64_t nBestBlockTime) if (fFirst) return; + // do not resend during IBD/rescan because some txs will be unconfirmed + // until completion + if(IsInitialBlockDownload()) { + return; + } + if (pwalletMain->fRescanning) { + return; + } + + // do not resend during a reindex or initial loading of blocks + if (HUSH_LOADINGBLOCKS) { + return; + } + // Only do it if there's been a new block since last time if (nBestBlockTime < nLastResend) return; nLastResend = GetTime(); + LogPrintf("%s: nBestBlockTime=%ld nNextResend=%ld nLastResend=%ld time=%ld\n", __func__, nBestBlockTime, nNextResend, nLastResend, GetTime()); // Rebroadcast unconfirmed txes older than 5 minutes before the last // block was found: std::vector relayed = ResendWalletTransactionsBefore(nBestBlockTime-5*60); From 7eb9d75b94469c3fc8c028f29b35be9ac764a10c Mon Sep 17 00:00:00 2001 From: Duke Date: Mon, 30 Oct 2023 09:31:48 -0400 Subject: [PATCH 4/6] Support * or ANY_ZADDR in z_mergetoaddress --- src/wallet/rpcwallet.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 8467c0453..fb4f24eb3 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -5667,8 +5667,10 @@ UniValue z_mergetoaddress(const UniValue& params, bool fHelp, const CPubKey& myp if (address == "ANY_TADDR") { useAnyUTXO = true; - } else if (address == "ANY_SAPLING") { + } else if (address == "ANY_ZADDR" || address == "ANY_SAPLING") { useAnySapling = true; + } else if (address == "*") { + useAnyUTXO = useAnySapling = true; } else { CTxDestination taddr = DecodeDestination(address); if (IsValidDestination(taddr)) { @@ -5692,7 +5694,7 @@ UniValue z_mergetoaddress(const UniValue& params, bool fHelp, const CPubKey& myp throw JSONRPCError(RPC_INVALID_PARAMETER, "Cannot specify specific t-addrs when using \"ANY_TADDR\""); } if ((useAnySapling) && zaddrs.size() > 0) { - throw JSONRPCError(RPC_INVALID_PARAMETER, "Cannot specify specific z-addrs when using \"ANY_SAPLING\""); + throw JSONRPCError(RPC_INVALID_PARAMETER, "Cannot specify specific z-addrs when using \"ANY_SAPLING\" or \"ANY_ZADDR\""); } const int nextBlockHeight = chainActive.Height() + 1; From a554377225687fbca3680f8cc43e30a3133aad12 Mon Sep 17 00:00:00 2001 From: Duke Date: Tue, 31 Oct 2023 10:30:18 -0400 Subject: [PATCH 5/6] Clean up --- src/validationinterface.cpp | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/validationinterface.cpp b/src/validationinterface.cpp index 12cabfac5..8db9e25f3 100644 --- a/src/validationinterface.cpp +++ b/src/validationinterface.cpp @@ -135,9 +135,6 @@ void ThreadNotifyWallets(CBlockIndex *pindexLastTip) while (pindex && pindex != pindexFork) { // Get the Sprout commitment tree as of the start of this block. SproutMerkleTree oldSproutTree; - //TODO: how important is oldSproutTree ? - //assert(pcoinsTip->GetSproutAnchorAt(pindex->hashSproutAnchor, oldSproutTree)); - // Get the Sapling commitment tree as of the start of this block. // We can get this from the `hashFinalSaplingRoot` of the last block // However, this is only reliable if the last block was on or after From 0936d4c2c2f771dbec6d7614991b4a96ce87b80d Mon Sep 17 00:00:00 2001 From: Duke Date: Mon, 6 Nov 2023 11:53:59 -0500 Subject: [PATCH 6/6] Add option to disable automatic resending of txs This option can disable automatic resending of txs. It defaults to the normal behavior of resending txs automatically and resending can be disabled with -resendtx=0 . This is not intended for normal usage and is undocumented for now. It is useful for devs who are debugging internals and also when rescanning large wallets. We seem to have either some bugs and/or performance problems when rescanning wallets with many txs. --- src/validationinterface.cpp | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/validationinterface.cpp b/src/validationinterface.cpp index 8db9e25f3..62ba5ea80 100644 --- a/src/validationinterface.cpp +++ b/src/validationinterface.cpp @@ -32,7 +32,13 @@ void RegisterValidationInterface(CValidationInterface* pwalletIn) { g_signals.UpdatedTransaction.connect(boost::bind(&CValidationInterface::UpdatedTransaction, pwalletIn, _1)); g_signals.ChainTip.connect(boost::bind(&CValidationInterface::ChainTip, pwalletIn, _1, _2, _3)); g_signals.SetBestChain.connect(boost::bind(&CValidationInterface::SetBestChain, pwalletIn, _1)); - g_signals.Broadcast.connect(boost::bind(&CValidationInterface::ResendWalletTransactions, pwalletIn, _1)); + + if(GetArg("-resendtx", true)) { + g_signals.Broadcast.connect(boost::bind(&CValidationInterface::ResendWalletTransactions, pwalletIn, _1)); + } else { + LogPrintf("%s: automatic resending of wallet transactions disabled\n", __func__); + } + g_signals.BlockChecked.connect(boost::bind(&CValidationInterface::BlockChecked, pwalletIn, _1, _2)); //g_signals.ScriptForMining.connect(boost::bind(&CValidationInterface::GetScriptForMining, pwalletIn, _1)); } @@ -40,7 +46,9 @@ void RegisterValidationInterface(CValidationInterface* pwalletIn) { void UnregisterValidationInterface(CValidationInterface* pwalletIn) { //g_signals.ScriptForMining.disconnect(boost::bind(&CValidationInterface::GetScriptForMining, pwalletIn, _1)); g_signals.BlockChecked.disconnect(boost::bind(&CValidationInterface::BlockChecked, pwalletIn, _1, _2)); - g_signals.Broadcast.disconnect(boost::bind(&CValidationInterface::ResendWalletTransactions, pwalletIn, _1)); + if(GetArg("-resendtx", true)) { + g_signals.Broadcast.disconnect(boost::bind(&CValidationInterface::ResendWalletTransactions, pwalletIn, _1)); + } g_signals.ChainTip.disconnect(boost::bind(&CValidationInterface::ChainTip, pwalletIn, _1, _2, _3)); g_signals.SetBestChain.disconnect(boost::bind(&CValidationInterface::SetBestChain, pwalletIn, _1)); g_signals.UpdatedTransaction.disconnect(boost::bind(&CValidationInterface::UpdatedTransaction, pwalletIn, _1));