Author SHA1 Message Date
DanS aea4bb7fa3 Merge branch 'fix/expired-log-and-sweep-error' into dev 2026-12-01 15:17:18 -06:00
DanSandClaude Opus 5.5 a7b15e40a0 wallet: say why a zsweep or autoshield round failed when its tx is rejected
When CommitAutomatedTx refused a transaction (AcceptToMemoryPool rejected it),
the sweep and autoshield ops returned false without setting an error, so the
operation finished as "failed" with an empty message:

  Sweep operation finished. (status=failed, error=)

Seen twice in 175 sweep rounds in the 2026-12-01 soak; one was a note already
spent by another transaction ("sapling nullifier ... exists"). Both ops now set
RPC_WALLET_ERROR and a message naming the rejected txid, pointing at debug.log
for the mempool's reason (CommitTransaction does not return it), and saying the
next round retries. Consolidation already records a per-address reason.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-12-01 15:11:48 -06:00
DanSandClaude Opus 5.5 2a2eaa2078 wallet: stop logging every mined transaction as "expired" on each rebroadcast
ResendWalletTransactionsBefore applied its "expired, don't relay" test to every
wallet transaction, mined ones included. A confirmed transaction is past its
expiry height a few hundred blocks after it was mined, so every pass (every
0-30 minutes) logged one "ignoring expired tx" line per transaction the wallet
had ever made, and the count only grew.

Measured in the 2026-12-01 soak (exchange-style wallet, ~15k transactions):
14,735 distinct "expired" txs x 89 passes = 1.1 million lines; debug.log grew
by 354 MB in 24 h.

Mined transactions are now skipped before the expiry test (they have nothing to
rebroadcast; RelayWalletTransaction already refused them). Genuinely expired
unconfirmed transactions are counted and reported in one summary line, with the
per-transaction detail under -debug=wallet. The function now takes cs_main
itself as well; both callers already hold it, and GetDepthInMainChain needs it.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-12-01 15:07:24 -06:00
DanS c4b0a23911 Merge branch 'fix/trim-spent-witnesses' into dev 2026-11-30 12:44:29 -06:00
DanSandClaude Opus 5.5 7c0702affa wallet: make zsweep and consolidation take strict turns
The previous fix (3e75769a4) let a due sweep give way once to a consolidation
round that was running or "due within 5 blocks", and then hold every new
consolidation round off until the sweep had run. On a wallet that always has
something to sweep this starved consolidation instead: the 5-block "give way"
itself set the waiting flag, the next consolidation was refused because a sweep
was waiting, the sweep ran, and so on.

Measured on the 2026-11-30 soak of 9c7c5835b (exchange-style wallet, zsweep
every 5 blocks, consolidation at the default 25): in 15.5 h, 2,375 sweep txs and
0 consolidation txs (273 deferrals); the withdraw address piled up to 5,898
unspent notes and RSS reached 4.7 GB.

Now the two ops take strict turns:
- a due sweep that finds a consolidation round running sets fSweepWaiting, and
  no new consolidation round starts until the sweep is dispatched;
- a due consolidation round that finds a sweep running sets
  fConsolidationWaiting, and no new sweep round starts until it is dispatched;
- the 5-block blackout is gone (with consolidationinterval=5 it was always true);
- whichever op yields clears its own flag, so they can never both be waiting;
- each flag is cleared on dispatch, when its op is off, or when it is skipped for
  a locked wallet.

z_consolidationstatus gains waiting_for_sweep, next to z_sweepstatus's
waiting_for_consolidation. doc/zsweep-consolidation.md updated.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-11-30 12:44:29 -06:00
DanSandClaude Opus 5.5 19f20736df wallet: drop the witness history of notes spent beyond reorg reach
BuildWitnessCache stops extending a note once its spend is deeper than
WITNESS_CACHE_SIZE (MAX_REORG_LENGTH + 10 = 109): no reorg can un-spend it any
more. But the up-to-109 witness snapshots the note had by then were never
released. Every spent note the wallet ever had kept them, in memory and in
wallet.dat, and SetBestChain rewrote them all on every save. On a wallet that
receives a steady stream of deposits and sweeps them, memory and wallet.dat grow
with the number of notes ever received.

Measured in the 2026-11-29/30 stress soak (exchange-style wallet, ~360 deposit
notes an hour swept to a withdraw address): RSS rose ~120-170 MB an hour to
2.9 GB over 18 h, wallet.dat reached 855 MB for ~6,500 transactions, and the
per-block log reported ~6,200 witnessed notes. With deposits stopped, RSS stopped
climbing, so this is history growth, not a leak.

Now such a note keeps only its newest witness (front()). That one is at
witnessHeight, gives the position its nullifier is derived from, and is the root
VerifyAndSetInitialWitness validates at startup, so a trimmed note loads and
validates exactly as before. The list is never emptied: a note with no witnesses
loses its nullifier in UpdateSaplingNullifierNoteMapWithTx and would then count
as unspent. A deeper-than-cache reorg (only possible after raising -maxreorg)
already pops or clears such notes' single remaining witness and reseeds them.

The trim runs in the per-block BuildWitnessCache pass, which already evaluates
each note's spend depth, so it costs no extra wallet walk. It bumps
nWitnessGeneration so the next SetBestChain or the shutdown save writes the
shorter lists, and logs how many notes it trimmed.

New gtest WalletWitnessTrim covers: deeply spent notes keep exactly their newest
witness (root, position, height, nullifier unchanged); unspent and in-reach notes,
notes without a nullifier, and empty lists are untouched; the serialized note
shrinks by more than 20x.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-11-29 22:23:02 -06:00
DanS 9c7c5835bd Merge branch 'fix/sweep-consolidation-fairness' into dev 2026-11-29 19:41:43 -06:00
DanS 722c3a7d7a Merge branch 'fix/autoop-expiry' into dev 2026-11-29 19:41:43 -06:00
DanS 8dc2e3c93c Merge branch 'fix/stratum-default-address' into dev 2026-11-29 19:41:43 -06:00
DanSandClaude Opus 5.5 3e75769a48 wallet: stop consolidation from starving zsweep
RunSaplingSweep returned early, and retried the next block, whenever a
consolidation round was running or due within 5 blocks, but kept no memory of
having given way. With consolidationinterval=5 the "due within 5 blocks" test is
always true, and with longer intervals a long consolidation round could fill the
remaining blocks, so on a busy wallet the sweep could go a whole run without
dispatching while deposits piled up.

Measured on the 2026-11-29 stress fleet (exchange-style wallet, zsweepinterval=5,
consolidationinterval=5, 150 deposit notes): in 20 minutes consolidation ran
4 rounds / 11 txs and the sweep 0, with 45 "not sweeping since consolidation"
lines; the deposit notes never moved.

A due sweep now gives way once and records it in fSweepWaiting. While that is
set, RunSaplingConsolidation starts no new round (nextConsolidation is left
alone, so that round runs right after the sweep), and the sweep skips the
5-block blackout. The flag is cleared when the sweep is dispatched, disabled, or
skipped for a locked wallet, so it cannot hold consolidation off once there is
no sweep to wait for. z_sweepstatus reports it as waiting_for_consolidation.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-11-29 10:48:26 -06:00
DanSandClaude Opus 5.5 66b74aa6aa wallet: give zsweep, consolidation and autoshield txs the normal expiry
The automated ops set nExpiryHeight to buildHeight + 15. The wallet only
rebroadcasts its unconfirmed transactions every 0-30 minutes (randomised, for
privacy), and only those a few minutes older than the last block, while each
transaction is relayed to a random half of the node's peers. A tx that missed
the miners on its first relay was therefore almost never retried before block
+15 (~9 minutes on mainnet), and expired. The op had already logged "Committed"
and, for zsweep, added it to amount_swept; the notes reappeared as unspent and
were swept again a round later. Nothing was lost, but z_sweepstatus overstated
progress, and manual z_sendmany calls from the deposit addresses kept colliding
with the re-sweeps ("bad-txns-shielded-requirements-not-met").

Measured on the 2026-11-29 stress fleet (exchange-style node with ~5 peer
connections): 38 of 184 sweep txs (21%) never confirmed; the log shows 1810
"ignoring expired tx" lines from the rebroadcast pass.

The three ops now use -txexpirydelta (default 200), the same window every other
wallet transaction gets, through AutoOpExpiryDelta(). Their NU-straddle guards
use the same window, so near a network upgrade they pause for the full expiry
window instead of 15 blocks. This applies to v1.2.0 too (its per-op
*_EXPIRY_DELTA constants were also 15); it is not a v1.3.0 regression.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-11-29 10:46:59 -06:00
DanSandClaude Opus 5.5 23159fcb25 stratum: honour the "x" worker name again
mining.authorize maps the worker name "x" to -stratumaddress, but it tested
CBitcoinAddress("x").ToString() == "x". "x" is not a valid address, so the
CBitcoinAddress holds no data and never prints as "x": the default address was
never used, and every "x" miner was refused with "Invalid DragonX address: x".
stratummine's default worker is "x", so the reference miner failed with "did not
receive complete RandomX work" unless it was given an explicit address.

Compare the worker name as sent (after stripping a ".rig" suffix) instead.

Found in the 2026-11-29 stress run: on a local RandomX chain with -stratumaddress
set, authorize "x" got the error above, while the same session authorized with the
address itself received set_randomx_key/set_target/notify and mined accepted shares.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-11-29 10:46:15 -06:00
DanSandClaude Opus 5.5 4538a8cd76 rpc: build getblocktemplate's block into a local before touching the cached template
getblocktemplate releases cs_main while CreateNewBlockWithKey runs, but it wrote the result
straight into the function-static pblocktemplate from inside that unlocked scope. A second
getblocktemplate call holding cs_main could then delete and NULL it (the "create new block"
branch frees the old template first) just before the first call took cs_main back, so the
first call threw "CreateNewBlock(): create block failed" for a block that had been built
fine, and templates overwritten this way were leaked.

The new block now goes into a local, and the cached template is freed and replaced only
after cs_main is held again. The old template also stays valid while the new one is built.

Seen once on the 3-VPS stress fleet (4 concurrent RPC hammer workers, one of them calling
getblocktemplate). Not reproduced locally: 720 calls (24 concurrent callers per forced
rebuild, 13 wide shielded txs in the mempool, background cs_main load) passed on both the
old and the new binary, so the fix rests on the code path above. The new binary showed no
regressions in that run.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-11-28 21:51:22 -06:00
DanS 0ac7812b11 Merge branch 'chore/remove-arrakis-wording' into dev 2026-11-28 17:23:59 -06:00
DanSandClaude Opus 5.5 5770f73b3d wallet/rpc: remove the unused Lock2NSPV/Unlock2NSPV
Neither has a caller anywhere in the tree. Both took cs_main and cs_wallet by hand, so any future
caller that threw between them would have leaked both locks. Remove them rather than keep a trap.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-11-26 22:26:29 -06:00
DanSandClaude Opus 5.5 8e34bcbba7 net: reset a peer's addrKnown under cs_addrKnown in the daily rebroadcast
SendMessages' 24-hour address rebroadcast cleared each peer's addrKnown under cs_vNodes only, while
the message handler inserts into and tests the same filter under cs_addrKnown
(AddAddressIfNotAlreadyKnown, IsAddressKnown): a data race on the bloom filter. Take
cs_addrKnown for the reset, as CloseSocketDisconnect already does. The order is unchanged:
cs_main (try-locked) -> cs_vNodes -> cs_addrKnown, as on the relay path.

Exercised on regtest with two nodes on a mock clock moved 25 hours at a time: the reset ran 4 times
(seen with a gdb breakpoint) with no fault.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-11-26 22:26:29 -06:00
DanSandClaude Opus 5.5 7d5893cd2a rpc: hold cs_main across gettxoutsetinfo's flush and scan
gettxoutsetinfo flushed the chainstate and then scanned it with no lock. GetStats reads the best
block and iterates a snapshot of the coins database separately, so a flush landing in between
reported the UTXO totals of a different block than the "height" and "bestblock" it returned. Hold
cs_main across both. The transparent UTXO set of a fully shielded chain is small, so the scan is
short (12 outputs on a 113-block regtest chain).

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-11-26 22:26:29 -06:00
DanSandClaude Opus 5.5 bc36fa5a74 miner: take CreateNewBlock's locks with LOCK2 instead of by hand
CreateNewBlock entered cs_main and mempool.cs with ENTER_CRITICAL_SECTION and released them by
hand before each of its four returns. Anything that threw in between -- TestBlockValidity, the
notary payment, the coinbase setup, an allocation -- left both locks held by that thread for good:
for the RPC thread in getblocktemplate that wedges every later cs_main user, and for a miner thread
the same. The releases were also in the wrong order (cs_main before mempool.cs), which pops the
wrong DEBUG_LOCKORDER lock-stack entry.

Take them with LOCK2 for the block's scope, so every return and any exception releases both, in
reverse order, and drop the four hand-written release pairs.

The boost::this_thread::disable_interruption() before them constructed a temporary that was
destroyed on the same line, so it never disabled anything. It is removed rather than "fixed": with
scoped locks an interruption unwinds cleanly, and disabling it would only delay stopping a miner
thread.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-11-26 22:26:29 -06:00
14 changed files with 240 additions and 73 deletions
+6 -3
View File
@@ -58,7 +58,8 @@ witness rebuilds. Consolidation keeps that in check.
so every address keeps at least one spendable note while the round confirms.
* Each transaction has exactly 8 shielded outputs: the real one plus 7 zero-value dummy ("Sietch") outputs to random
addresses, so it does not shrink the anonymity set. It pays `consolidationtxfee`, or no fee when its notes are worth
no more than the fee, and expires 15 blocks after it is made.
no more than the fee, and expires `-txexpirydelta` blocks (default 200) after it is made, like any other wallet
transaction, so the wallet's periodic rebroadcast can still retry it.
* Only the notes a round actually spends are locked while it proves, so sends made meanwhile still see the rest of
the wallet.
* All spends of one transaction must use one anchor (Sapling tree root). An address's spends use the tip's root,
@@ -128,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, and they take
strict turns: a round that comes due while the other op is running goes next, and the other op starts no new
round until it has run, so neither can starve the other. `z_sweepstatus` shows `"waiting_for_consolidation": true`
and `z_consolidationstatus` shows `"waiting_for_sweep": true` while a round is waiting for its turn.
### Copyright
+1
View File
@@ -19,6 +19,7 @@ hush_gtest_SOURCES = \
gtest/test_sweep_note_selection.cpp \
gtest/test_asyncrpc_cancel.cpp \
gtest/test_wallet_notedata.cpp \
gtest/test_wallet_witnesstrim.cpp \
gtest/test_net_closesocket.cpp \
gtest/test_net_addrrelay.cpp \
gtest/test_fd_defense.cpp \
+93
View File
@@ -0,0 +1,93 @@
// Copyright (c) 2024-2026 The DragonX developers
// Distributed under the GPLv3 software license, see the accompanying
// file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html
#include <gtest/gtest.h>
#include "random.h"
#include "uint256.h"
#include "wallet/wallet.h"
#include "zcash/IncrementalMerkleTree.hpp"
namespace {
libzcash::SaplingIncomingViewingKey TestIvk()
{
return libzcash::SaplingIncomingViewingKey(uint256S("0202020202020202020202020202020202020202020202020202020202020202"));
}
// A note with a witness for every one of nSnapshots blocks, newest at the front, the way
// BuildWitnessCache leaves it: each snapshot is the previous one plus one more commitment.
SaplingNoteData NoteWithHistory(int nSnapshots, int tipHeight, bool fNullifier = true)
{
SaplingNoteData nd = fNullifier ? SaplingNoteData(TestIvk(), GetRandHash()) : SaplingNoteData(TestIvk());
SaplingMerkleTree tree;
tree.append(GetRandHash()); // the note's own commitment
nd.witnesses.push_front(tree.witness());
for (int i = 1; i < nSnapshots; i++) {
nd.witnesses.push_front(nd.witnesses.front());
nd.witnesses.front().append(GetRandHash());
}
nd.witnessHeight = tipHeight;
return nd;
}
const unsigned int CACHE = 109; // WITNESS_CACHE_SIZE on DragonX: MAX_REORG_LENGTH (99) + 10
} // namespace
// Spent deeper than the cache: only the newest witness survives, unchanged, and the note keeps the
// position and height its nullifier and startup validation depend on.
TEST(WalletWitnessTrim, DeeplySpentNoteKeepsOnlyNewestWitness)
{
SaplingNoteData nd = NoteWithHistory(CACHE, 5000);
const uint256 rootBefore = nd.witnesses.front().root();
const uint64_t posBefore = nd.witnesses.front().position();
const boost::optional<uint256> nfBefore = nd.nullifier;
EXPECT_TRUE(TrimDeeplySpentNoteWitnesses(nd, CACHE + 1, CACHE));
ASSERT_EQ(nd.witnesses.size(), 1u);
EXPECT_EQ(nd.witnesses.front().root(), rootBefore);
EXPECT_EQ(nd.witnesses.front().position(), posBefore);
EXPECT_EQ(nd.witnessHeight, 5000);
EXPECT_TRUE(nd.nullifier == nfBefore);
// Already trimmed: nothing more to do.
EXPECT_FALSE(TrimDeeplySpentNoteWitnesses(nd, CACHE + 50, CACHE));
EXPECT_EQ(nd.witnesses.size(), 1u);
}
// Unspent (depth 0) and spent within reorg reach: a reorg may still need the older snapshots.
TEST(WalletWitnessTrim, UnspentAndShallowSpentNotesAreUntouched)
{
SaplingNoteData unspent = NoteWithHistory(CACHE, 5000);
EXPECT_FALSE(TrimDeeplySpentNoteWitnesses(unspent, 0, CACHE));
EXPECT_EQ(unspent.witnesses.size(), CACHE);
SaplingNoteData shallow = NoteWithHistory(CACHE, 5000);
EXPECT_FALSE(TrimDeeplySpentNoteWitnesses(shallow, CACHE, CACHE)); // depth == cache size: still in reach
EXPECT_EQ(shallow.witnesses.size(), CACHE);
}
// A note without a nullifier is never trimmed (it is not known to be spent), and an empty list stays
// empty: trimming must never be what leaves a note with no witnesses.
TEST(WalletWitnessTrim, NoNullifierOrNoWitnessesIsLeftAlone)
{
SaplingNoteData noNf = NoteWithHistory(CACHE, 5000, false);
EXPECT_FALSE(TrimDeeplySpentNoteWitnesses(noNf, CACHE + 1, CACHE));
EXPECT_EQ(noNf.witnesses.size(), CACHE);
SaplingNoteData empty(TestIvk(), GetRandHash());
EXPECT_FALSE(TrimDeeplySpentNoteWitnesses(empty, CACHE + 1, CACHE));
EXPECT_TRUE(empty.witnesses.empty());
}
// The serialized note shrinks with the list: what SetBestChain rewrites for every spent note.
TEST(WalletWitnessTrim, SerializedSizeShrinks)
{
SaplingNoteData nd = NoteWithHistory(CACHE, 5000);
const size_t before = ::GetSerializeSize(nd, SER_DISK, CLIENT_VERSION);
ASSERT_TRUE(TrimDeeplySpentNoteWitnesses(nd, CACHE + 1, CACHE));
const size_t after = ::GetSerializeSize(nd, SER_DISK, CLIENT_VERSION);
EXPECT_LT(after * 20, before);
}
+5 -2
View File
@@ -8398,9 +8398,12 @@ bool SendMessages(CNode* pto, bool fSendTrickle)
LOCK(cs_vNodes);
BOOST_FOREACH(CNode* pnode, vNodes)
{
// Periodically clear addrKnown to allow refresh broadcasts
if (nLastRebroadcast)
// Periodically clear addrKnown to allow refresh broadcasts. Under cs_addrKnown, as in
// CloseSocketDisconnect: the message handler reads and inserts into it concurrently.
if (nLastRebroadcast) {
LOCK(pnode->cs_addrKnown);
pnode->addrKnown.reset();
}
// Rebroadcast our address
AdvertizeLocal(pnode);
+6 -19
View File
@@ -224,10 +224,12 @@ CBlockTemplate* CreateNewBlock(CPubKey _pk,const CScript& _scriptPubKeyIn, int32
CBlockIndex* pindexPrev = 0;
{
// this should stop create block ever exiting until it has returned something.
boost::this_thread::disable_interruption();
ENTER_CRITICAL_SECTION(cs_main);
ENTER_CRITICAL_SECTION(mempool.cs);
// Scoped, so every return below and any exception releases both, in reverse order. They
// were taken and released by hand, which leaked them whenever something in here threw, and
// released cs_main before mempool.cs. (The boost::this_thread::disable_interruption() that
// stood here built a temporary, so it never disabled anything; with scoped locks an
// interruption now unwinds cleanly.)
LOCK2(cs_main, mempool.cs);
pindexPrev = chainActive.LastTip();
const int nHeight = pindexPrev->GetHeight() + 1;
const Consensus::Params &consensusParams = chainparams.GetConsensus();
@@ -664,8 +666,6 @@ CBlockTemplate* CreateNewBlock(CPubKey _pk,const CScript& _scriptPubKeyIn, int32
}
} else if ( (uint64_t)(txNew.vout[0].nValue) >= ASSETCHAINS_TIMELOCKGTE) {
LogPrintf("timelocked chains not supported in this code!\n");
LEAVE_CRITICAL_SECTION(cs_main);
LEAVE_CRITICAL_SECTION(mempool.cs);
return(0);
} else if ( fNotarizationBlock && ASSETCHAINS_NOTARY_PAY[0] != 0 && pblock->vtx[1].vout.size() == 2 && pblock->vtx[1].vout[1].nValue == 0 ) {
// Get the OP_RETURN for the notarization
@@ -677,11 +677,6 @@ CBlockTemplate* CreateNewBlock(CPubKey _pk,const CScript& _scriptPubKeyIn, int32
if ( totalsats == 0 )
{
LogPrintf("Could not create notary payment, trying again.\n");
// Release unconditionally to match the unconditional ENTER above. The old
// `if(!isStake)` guard leaked cs_main/mempool.cs on the isStake path (this
// still return(0)s), while the success and timelock paths always release.
LEAVE_CRITICAL_SECTION(cs_main);
LEAVE_CRITICAL_SECTION(mempool.cs);
return(0);
}
} else LogPrintf("vout 2 of notarization is not OP_RETURN scriptlen.%i\n", scriptlen);
@@ -726,11 +721,6 @@ CBlockTemplate* CreateNewBlock(CPubKey _pk,const CScript& _scriptPubKeyIn, int32
CValidationState state;
if ( !TestBlockValidity(state, *pblock, pindexPrev, false, false)) // invokes CC checks
{
// Release unconditionally to match the unconditional ENTER above. The old
// `if(!isStake)` guard leaked cs_main/mempool.cs on the isStake path (this
// still return(0)s), while the success and timelock paths always release.
LEAVE_CRITICAL_SECTION(cs_main);
LEAVE_CRITICAL_SECTION(mempool.cs);
LogPrintf("%s: TestBlockValidity failed!\n", __func__);
//throw std::runtime_error("CreateNewBlock(): TestBlockValidity failed"); // crashes the node, moved to GetBlockTemplate and issue return.
return(0);
@@ -738,9 +728,6 @@ CBlockTemplate* CreateNewBlock(CPubKey _pk,const CScript& _scriptPubKeyIn, int32
}
}
LEAVE_CRITICAL_SECTION(cs_main);
LEAVE_CRITICAL_SECTION(mempool.cs);
return pblocktemplate.release();
}
+5
View File
@@ -861,6 +861,11 @@ UniValue gettxoutsetinfo(const UniValue& params, bool fHelp, const CPubKey& mypk
UniValue ret(UniValue::VOBJ);
CCoinsStats stats;
// Hold cs_main across the flush and the scan: GetStats reads the best block and iterates a
// snapshot of the coins database separately, and a flush landing in between would report the
// UTXO totals of a different block than "height"/"bestblock" claim. The transparent UTXO set
// of a fully shielded chain is small, so the scan is short.
LOCK(cs_main);
FlushStateToDisk();
if (pcoinsTip->GetStats(stats)) {
ret.push_back(Pair("height", (int64_t)stats.nHeight));
+10 -9
View File
@@ -765,12 +765,10 @@ UniValue getblocktemplate(const UniValue& params, bool fHelp, const CPubKey& myp
CBlockIndex* pindexPrevNew = chainActive.LastTip();
nStart = GetTime();
// Create new block
if(pblocktemplate)
{
delete pblocktemplate;
pblocktemplate = NULL;
}
// Create new block. cs_main is released while it is built, so another getblocktemplate call can
// run this block meanwhile: build into a local and only touch the shared pblocktemplate once cs_main
// is held again, or that call could delete or overwrite it under us.
CBlockTemplate* pblocktemplateNew = NULL;
#ifdef ENABLE_WALLET
CReserveKey reservekey(pwalletMain);
#endif
@@ -778,15 +776,18 @@ UniValue getblocktemplate(const UniValue& params, bool fHelp, const CPubKey& myp
// CreateNewBlockWithKey can throw (keypool/wallet DB errors); cs_main must be held again by then.
CMainUnlockScope unlockMain;
#ifdef ENABLE_WALLET
pblocktemplate = CreateNewBlockWithKey(reservekey,pindexPrevNew->GetHeight()+1,HUSH_MAXGPUCOUNT,false);
pblocktemplateNew = CreateNewBlockWithKey(reservekey,pindexPrevNew->GetHeight()+1,HUSH_MAXGPUCOUNT,false);
#else
pblocktemplate = CreateNewBlockWithKey();
pblocktemplateNew = CreateNewBlockWithKey();
#endif
}
if (!pblocktemplate)
if (!pblocktemplateNew)
throw std::runtime_error("CreateNewBlock(): create block failed");
//throw JSONRPCError(RPC_OUT_OF_MEMORY, "Out of memory or no available utxo for staking");
delete pblocktemplate;
pblocktemplate = pblocktemplateNew;
// Need to update only after we know CreateNewBlockWithKey succeeded
pindexPrev = pindexPrevNew;
}
+4 -2
View File
@@ -1274,14 +1274,16 @@ UniValue stratum_mining_authorize(StratumClient& client, const UniValue& params)
boost::trim_right(username);
}
CBitcoinAddress addr(get_stripped_username(username));
const std::string strippedUsername = get_stripped_username(username);
CBitcoinAddress addr(strippedUsername);
// If given the special address "x", mine to the default address given by -stratumaddress
// This means a miner can run a private pool without TLS and not
// worry about MITM attacks that change addresses, and leaks less metadata.
// It also means many miners can be used and updating their mining address does not
// require any changes on each miner, just restart dragonxd with a new -stratumaddress
if(addr.ToString() == "x") {
// Compare the name as sent: "x" is not a valid address, so addr.ToString() never returns it.
if(strippedUsername == "x") {
addr = CBitcoinAddress(GetArg("-stratumaddress", ""));
const std::string msg = strprintf("%s: Authorized client with default stratum address=%s", __func__, addr.ToString());
LogPrint("stratum", "%s\n", msg);
@@ -294,7 +294,7 @@ bool AsyncRPCOperation_autoshieldcoinbase::main_impl() {
// from below), not the stale enqueue-time targetHeight_, so a queue delay
// cannot slip a straddling expiry past this guard.
auto nextActivationHeight = NextActivationHeight(tipHeight, consensusParams);
if (nextActivationHeight && tipHeight + AUTO_OP_EXPIRY_DELTA >= nextActivationHeight.get()) {
if (nextActivationHeight && tipHeight + AutoOpExpiryDelta() >= nextActivationHeight.get()) {
LogPrintf("%s: autoshield tx could expire across a NU activation. Skipping this round.\n", opid);
return true;
}
@@ -414,7 +414,7 @@ bool AsyncRPCOperation_autoshieldcoinbase::main_impl() {
// stale enqueue-time height here meant the guard was checking a height the
// transaction was not actually signed against.
auto builder = TransactionBuilder(consensusParams, tipHeight, pwalletMain);
builder.SetExpiryHeight(tipHeight + AUTO_OP_EXPIRY_DELTA);
builder.SetExpiryHeight(tipHeight + AutoOpExpiryDelta());
builder.SetFee(fee);
for (const auto& t : inputs) {
@@ -461,6 +461,9 @@ bool AsyncRPCOperation_autoshieldcoinbase::main_impl() {
}
LogPrintf("%s: autoshield tx FAILED in CommitTransaction, txid=%s\n", opid, tx.GetHash().ToString());
set_error_code(RPC_WALLET_ERROR);
set_error_message(strprintf("Autoshield transaction %s was not accepted into the mempool (see debug.log for the "
"reason). The next round tries again.", tx.GetHash().ToString()));
return false;
}
@@ -313,7 +313,7 @@ bool AsyncRPCOperation_saplingconsolidation::main_impl() {
// the NU-straddle guard agree with the height the tx is signed for. Mirrors
// the autoshield op (commit 65130c312).
auto nextActivationHeight = NextActivationHeight(tipHeight, consensusParams);
if (nextActivationHeight && tipHeight + AUTO_OP_EXPIRY_DELTA >= nextActivationHeight.get()) {
if (nextActivationHeight && tipHeight + AutoOpExpiryDelta() >= nextActivationHeight.get()) {
LogPrintf("%s: Consolidation txs would be created before a NU activation but may expire after. Skipping this round.\n",opid);
setConsolidationResult(ConsolidationTally());
return status;
@@ -469,7 +469,7 @@ bool AsyncRPCOperation_saplingconsolidation::main_impl() {
const AddressNotes& group = groups[planned.group];
auto builder = TransactionBuilder(consensusParams, tipHeight, pwalletMain);
builder.SetExpiryHeight(tipHeight + AUTO_OP_EXPIRY_DELTA);
builder.SetExpiryHeight(tipHeight + AutoOpExpiryDelta());
CAmount amountToSend = 0;
for (const SaplingNoteEntry& entry : planned.notes)
+9 -3
View File
@@ -192,7 +192,7 @@ bool AsyncRPCOperation_sweep::main_impl() {
// targetHeight_, so a queue delay cannot slip a straddling expiry past this
// guard. Mirrors the autoshield op (commit 65130c312).
auto nextActivationHeight = NextActivationHeight(tipHeight, consensusParams);
if (nextActivationHeight && tipHeight + AUTO_OP_EXPIRY_DELTA >= nextActivationHeight.get()) {
if (nextActivationHeight && tipHeight + AutoOpExpiryDelta() >= nextActivationHeight.get()) {
LogPrintf("%s: Sweep txs would be created before a NU activation but may expire after. Skipping this round.\n", getId());
setSweepResult(0, 0, std::vector<std::string>());
sweepComplete_ = true; // nothing to do this round; back nextSweep off one interval instead of re-dispatching every block
@@ -347,12 +347,12 @@ bool AsyncRPCOperation_sweep::main_impl() {
buildHeight = (chainActive.Tip() != NULL) ? chainActive.Tip()->GetHeight() : tipHeight;
}
auto nextActivation = NextActivationHeight(buildHeight, consensusParams);
if (nextActivation && buildHeight + AUTO_OP_EXPIRY_DELTA >= nextActivation.get()) {
if (nextActivation && buildHeight + AutoOpExpiryDelta() >= nextActivation.get()) {
LogPrintf("%s: Sweep txs would now be created before a NU activation but may expire after. Stopping this round.\n", getId());
break;
}
auto builder = TransactionBuilder(consensusParams, buildHeight, pwalletMain);
builder.SetExpiryHeight(buildHeight + AUTO_OP_EXPIRY_DELTA);
builder.SetExpiryHeight(buildHeight + AutoOpExpiryDelta());
LogPrintf("%s: Beginning creating transaction with Sapling output amount=%s\n", getId(), FormatMoney(amountToSend - fee));
// Add Sapling spends, each with the witness it was selected with
@@ -411,6 +411,12 @@ bool AsyncRPCOperation_sweep::main_impl() {
numTxCreated++;
} else {
LogPrintf("%s: Sweep transaction FAILED in CommitTransaction, txid=%s\n",opid , tx.GetHash().ToString());
// Say why the round failed: this used to finish as "failed" with an empty error. The mempool's
// reason is in debug.log just above (most often a note already spent by another transaction).
set_error_code(RPC_WALLET_ERROR);
set_error_message(strprintf("Sweep transaction %s was not accepted into the mempool (see debug.log for "
"the reason; usually one of its notes was spent by another transaction "
"meanwhile). The next round sweeps what is left.", tx.GetHash().ToString()));
setSweepResult(numTxCreated, amountSwept, sweepTxIds);
status = false;
break;
+6 -17
View File
@@ -113,23 +113,6 @@ void EnsureWalletIsUnlocked()
throw JSONRPCError(RPC_WALLET_UNLOCK_NEEDED, "Error: Please enter the wallet passphrase with walletpassphrase first.");
}
void Lock2NSPV(const CPubKey &pk)
{
if (!pk.IsValid())
{
ENTER_CRITICAL_SECTION(cs_main);
ENTER_CRITICAL_SECTION(pwalletMain->cs_wallet);
}
}
void Unlock2NSPV(const CPubKey &pk)
{
if (!pk.IsValid())
{
LEAVE_CRITICAL_SECTION(cs_main);
LEAVE_CRITICAL_SECTION(pwalletMain->cs_wallet);
}
}
void WalletTxToJSON(const CWalletTx& wtx, UniValue& entry)
{
@@ -3317,6 +3300,8 @@ UniValue z_consolidationstatus(const UniValue& params, bool fHelp, const CPubKey
"{\n"
" \"consolidation\" : true|false, (boolean) whether periodic consolidation (-consolidation) is on\n"
" \"running\" : true|false, (boolean) whether a round is in flight\n"
" \"waiting_for_sweep\" : true|false, (boolean) a due round is waiting for a zsweep round to end;\n"
" no new sweep round starts until it has run\n"
" \"amount_consolidated\" : n, (numeric) value of the notes created since startup, in puposhis\n"
" \"next_consolidation\" : n, (numeric) height of the next periodic round\n"
" \"consolidationinterval\" : n, (numeric) blocks between periodic rounds\n"
@@ -3365,6 +3350,7 @@ UniValue z_consolidationstatus(const UniValue& params, bool fHelp, const CPubKey
UniValue ret(UniValue::VOBJ);
ret.push_back(Pair("consolidation", pwalletMain->fSaplingConsolidationEnabled));
ret.push_back(Pair("running", pwalletMain->fConsolidationRunning));
ret.push_back(Pair("waiting_for_sweep", pwalletMain->fConsolidationWaiting));
ret.push_back(Pair("amount_consolidated", (int64_t)stats.amountConsolidated));
ret.push_back(Pair("next_consolidation", pwalletMain->nextConsolidation));
ret.push_back(Pair("consolidationinterval", pwalletMain->consolidationInterval));
@@ -3553,6 +3539,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"
@@ -3573,6 +3561,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));
+66 -13
View File
@@ -640,6 +640,7 @@ void CWallet::RunSaplingSweep(int blockHeight) {
}
if (!fSweepEnabled) {
fSweepWaiting = false;
return;
}
@@ -666,18 +667,23 @@ 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);
return;
}
//Don't Run While consolidation is running.
// Strict turns with consolidation (see fSweepWaiting / fConsolidationWaiting). This replaces a
// "consolidation is due within 5 blocks" blackout, which with consolidationinterval=5 was always true.
//Don't Run While consolidation is running: wait, and take the next turn.
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; the sweep goes next\n", __func__, blockHeight);
fSweepWaiting = true;
return;
}
//A consolidation round that came due while a sweep was running goes first.
if (fConsolidationWaiting && fSaplingConsolidationEnabled) {
LogPrintf("%s: not sweeping since a consolidation round is waiting for its turn at height=%d\n", __func__, blockHeight);
fSweepWaiting = false; // never both waiting: that would leave neither op able to start
return;
}
@@ -688,6 +694,7 @@ void CWallet::RunSaplingSweep(int blockHeight) {
}
fSweepRunning = true;
fSweepWaiting = false;
std::shared_ptr<AsyncRPCQueue> q = getAsyncRPCQueue();
std::shared_ptr<AsyncRPCOperation> lastOperation = q->getOperationForId(saplingSweepOperationId);
@@ -720,6 +727,7 @@ void CWallet::RunSaplingConsolidation(int blockHeight) {
LOCK(cs_wallet);
if (!fSaplingConsolidationEnabled) {
fConsolidationWaiting = false;
return;
}
@@ -739,13 +747,23 @@ void CWallet::RunSaplingConsolidation(int blockHeight) {
if (IsLocked()) {
LogPrintf("%s: wallet locked; not consolidating at height=%d\n", __func__, blockHeight);
nextConsolidation = consolidationInterval + blockHeight;
fConsolidationWaiting = false;
return;
}
LogPrintf("%s: consolidation enabled at blockHeight=%d fSweepRunning=%d\n", __func__, blockHeight, fSweepRunning );
//Don't Run While a sweep is running: wait, and take the next turn (nextConsolidation stays put).
if (fSweepRunning) {
LogPrintf("%s: not consolidating since sweep is currently running at height=%d\n", __func__, blockHeight);
LogPrintf("%s: not consolidating since sweep is currently running at height=%d; consolidation goes next\n", __func__, blockHeight);
fConsolidationWaiting = true;
return;
}
//A sweep that came due while this op was running goes first.
if (fSweepWaiting && fSweepEnabled) {
LogPrintf("%s: not consolidating since a due sweep is waiting for its turn at height=%d\n", __func__, blockHeight);
fConsolidationWaiting = false; // never both waiting
return;
}
@@ -756,6 +774,7 @@ void CWallet::RunSaplingConsolidation(int blockHeight) {
LogPrintf("%s: creating consolidation operation at blockHeight=%d\n", __func__, blockHeight);
fConsolidationRunning = true;
fConsolidationWaiting = false;
std::shared_ptr<AsyncRPCQueue> q = getAsyncRPCQueue();
std::shared_ptr<AsyncRPCOperation> lastOperation = q->getOperationForId(saplingConsolidationOperationId);
if (lastOperation != nullptr) {
@@ -1435,6 +1454,17 @@ void ClearSingleNoteWitnessCache(NoteData* nd)
nd->witnessRootValidated = false;
}
bool TrimDeeplySpentNoteWitnesses(SaplingNoteData& nd, unsigned int nSpendDepth, unsigned int nCacheSize)
{
// Never empty the list: UpdateSaplingNullifierNoteMapWithTx drops the nullifier of a note with no
// witnesses, and a spent note without a nullifier is counted as unspent by GetFilteredNotes.
if (!nd.nullifier || nSpendDepth <= nCacheSize || nd.witnesses.size() <= 1)
return false;
while (nd.witnesses.size() > 1)
nd.witnesses.pop_back(); // oldest snapshots are at the back; front() stays the one at witnessHeight
return true;
}
// A note without a nullifier is never extended by BuildWitnessCache (its pending-note gate requires one),
// so it doesn't pull the rebuild's start height down.
int CWallet::SaplingWitnessMinimumHeight(const boost::optional<uint256>& nullifier, int nWitnessHeight, int nMinimumHeight)
@@ -1735,6 +1765,7 @@ void CWallet::BuildWitnessCache(const CBlockIndex* pindex, bool witnessOnly)
// cost changes from O(blocks * walletSize) to O(blocks + activeNotes).
struct PendingNote { int startWitnessHeight; SaplingNoteData* nd; };
std::vector<PendingNote> pending;
int nNotesTrimmed = 0;
for (std::pair<const uint256, CWalletTx>& wtxItem : mapWallet) {
if (wtxItem.second.mapSaplingNoteData.empty())
continue;
@@ -1746,14 +1777,24 @@ void CWallet::BuildWitnessCache(const CBlockIndex* pindex, bool witnessOnly)
continue;
if (nd->witnesses.empty()) // cannot extend (front() would be UB); the original gate also never matched these in practice
continue;
if (GetSaplingSpendDepth(*nd->nullifier) > WITNESS_CACHE_SIZE)
const unsigned int nSpendDepth = GetSaplingSpendDepth(*nd->nullifier);
if (nSpendDepth > WITNESS_CACHE_SIZE) {
// Spent beyond reorg reach: no longer extended, so its older snapshots are dead weight.
if (TrimDeeplySpentNoteWitnesses(*nd, nSpendDepth, WITNESS_CACHE_SIZE))
nNotesTrimmed++;
continue;
}
// Only notes that still lag the build target need extension. The lowest such witnessHeight
// is exactly startHeight-1 (startHeight = nMinimumHeight+1 from SaplingWitnessMinimumHeight).
if (nd->witnessHeight >= startHeight - 1 && nd->witnessHeight <= pindex->GetHeight() - 1)
pending.push_back({ nd->witnessHeight, nd });
}
}
if (nNotesTrimmed > 0) {
nWitnessGeneration++; // the next SetBestChain (or the shutdown save) writes the shorter lists
LogPrintf("%s: dropped the older witnesses of %d note(s) spent more than %u blocks ago\n",
__func__, nNotesTrimmed, WITNESS_CACHE_SIZE);
}
std::sort(pending.begin(), pending.end(),
[](const PendingNote& a, const PendingNote& b) { return a.startWitnessHeight < b.startWitnessHeight; });
@@ -4310,7 +4351,9 @@ std::vector<uint256> CWallet::ResendWalletTransactionsBefore(int64_t nTime)
{
std::vector<uint256> result;
LOCK(cs_wallet);
// Both callers (the periodic Broadcast signal from SendMessages, and resendwallettransactions) hold
// cs_main already; GetDepthInMainChain below needs it.
LOCK2(cs_main, cs_wallet);
// Sort them in chronological order
multimap<unsigned int, CWalletTx*> mapSorted;
uint32_t now = (uint32_t)time(NULL);
@@ -4318,7 +4361,7 @@ std::vector<uint256> CWallet::ResendWalletTransactionsBefore(int64_t nTime)
// vector of wallet transactions to delete
std::vector<uint256> vwtxh;
uint32_t erased = 0, skipped = 0;
uint32_t erased = 0, skipped = 0, expired = 0;
BOOST_FOREACH(PAIRTYPE(const uint256, CWalletTx)& item, mapWallet)
{
@@ -4327,10 +4370,18 @@ std::vector<uint256> CWallet::ResendWalletTransactionsBefore(int64_t nTime)
if (wtx.nTimeReceived > nTime)
continue;
// A mined transaction has nothing to rebroadcast. It used to reach the expiry test below, and every
// confirmed tx is past its expiry height a few hundred blocks after it was mined, so each pass logged
// one "ignoring expired tx" line per wallet tx ever made: 1.1M lines (354 MB of debug.log) in a day on
// an exchange-style wallet of ~15k txs.
if (wtx.GetDepthInMainChain() > 0)
continue;
// Do not relay expired transactions, to avoid other nodes banning us
// Current code will not ban nodes relaying expired txs but older nodes will
if (wtx.nExpiryHeight > 0 && wtx.nExpiryHeight < chainActive.LastTip()->GetHeight()) {
LogPrintf("%s: ignoring expired tx %s with expiry %d at height %d\n", __func__, wtx.GetHash().ToString().c_str(), wtx.nExpiryHeight, chainActive.LastTip()->GetHeight() );
LogPrint("wallet", "%s: ignoring expired tx %s with expiry %d at height %d\n", __func__, wtx.GetHash().ToString().c_str(), wtx.nExpiryHeight, chainActive.LastTip()->GetHeight() );
expired++;
// TODO: expired detection doesn't seem to work right
// append to list of txs to delete
// vwtxh.push_back(wtx.GetHash());
@@ -4376,6 +4427,8 @@ std::vector<uint256> CWallet::ResendWalletTransactionsBefore(int64_t nTime)
if(erased > 0 || skipped > 0) {
LogPrintf("%s: Prevented relaying %d and erased %d transactions which are too old\n", __func__, skipped, erased);
}
if (expired > 0)
LogPrintf("%s: not relaying %u expired unconfirmed transaction(s) (-debug=wallet lists them)\n", __func__, expired);
return result;
}
+22 -1
View File
@@ -132,7 +132,12 @@ static const CAmount CONSOLIDATION_MIN_FEE = AUTOSHIELD_MIN_FEE;
static const CAmount CONSOLIDATION_MAX_FEE = AUTOSHIELD_MAX_FEE;
static const int CONSOLIDATION_MIN_DEPTH = 11; // leaves room for an anchor at height N-10
static const int AUTO_OP_TARGET_HEIGHT_OFFSET = 5; // blocks of lookahead when scheduling an async op
static const int AUTO_OP_EXPIRY_DELTA = 15; // NU-straddle expiry window, shared by all three ops
// Expiry window for the transactions zsweep, consolidation and autoshield build, and for their NU-straddle
// guards: the same -txexpirydelta (default 200) as any other wallet transaction. These used a fixed 15 blocks,
// which ran out before the wallet's rebroadcast (every 0-30 min, and only for txs a few minutes older than the
// last block) ever retried a tx the half-of-peers relay had not carried to a miner: on a node with a handful of
// peers about one sweep tx in five expired unmined, while the sweep had already counted it as swept.
inline int AutoOpExpiryDelta() { return (int)expiryDelta; }
extern const char * DEFAULT_WALLET_DAT;
@@ -394,6 +399,13 @@ public:
typedef std::map<JSOutPoint, SproutNoteData> mapSproutNoteData_t;
typedef std::map<SaplingOutPoint, SaplingNoteData> mapSaplingNoteData_t;
//! For a note spent nSpendDepth blocks ago: once that is deeper than nCacheSize (WITNESS_CACHE_SIZE) no reorg
//! can un-spend it and BuildWitnessCache stops extending it, so only the newest witness is kept. That one holds
//! the note's position (its nullifier) and the root VerifyAndSetInitialWitness validates; the older snapshots,
//! up to nCacheSize per note, were otherwise kept in memory and rewritten to wallet.dat for every spent note
//! the wallet ever had. Returns true if anything was dropped; never empties the list.
bool TrimDeeplySpentNoteWitnesses(SaplingNoteData& nd, unsigned int nSpendDepth, unsigned int nCacheSize);
/** Sapling note, its location in a transaction, and number of confirmations. */
struct SaplingNoteEntry
{
@@ -903,6 +915,15 @@ public:
bool fSweepEnabled = false;
bool fSweepExternalEnabled = false;
bool fSweepRunning = false;
// Strict turns between zsweep and consolidation: an op that came due while the other was running
// goes next. fSweepWaiting is set when a due sweep finds a consolidation round running, and keeps a
// new consolidation round from starting; fConsolidationWaiting is the same the other way round, and
// keeps a new sweep round from starting. Each is cleared when its own op is dispatched (or turned
// off, or skipped for a locked wallet). Without them the two starved each other: the sweep lost every
// block to a 5-block "consolidation is due soon" blackout, and once that was relaxed, back-to-back
// sweep rounds left consolidation no block at all.
bool fSweepWaiting = false;
bool fConsolidationWaiting = false;
// Automatic coinbase shielding (t->z). The real default is computed in
// init.cpp: ON only for known-recoverable seed provenance (CREATED/RESTORED),