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>
82 lines
2.6 KiB
Makefile
82 lines
2.6 KiB
Makefile
# Copyright (c) 2016-2024 The Hush developers
|
|
# Released under the GPLv3
|
|
TESTS += hush-gtest
|
|
bin_PROGRAMS += hush-gtest
|
|
|
|
# tool for generating our public parameters
|
|
# NOTE: the original test list used an invalid automake form (comment after a trailing
|
|
# backslash, and `zcash_gtest_SOURCES +=` with no prior `=`), which is why the whole
|
|
# gtest harness was disabled via a `#include`. Minimal valid set: the harness + the
|
|
# Re-add other gtest sources here as they are revived.
|
|
hush_gtest_SOURCES = \
|
|
gtest/main.cpp \
|
|
gtest/utils.cpp \
|
|
gtest/test_randomx_preverify.cpp \
|
|
gtest/test_randomx_heightrecover.cpp \
|
|
gtest/test_hdtransparent.cpp \
|
|
gtest/test_mnemonic_compat.cpp \
|
|
gtest/test_stratum_jobid.cpp \
|
|
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 \
|
|
gtest/test_wallet_dbenv.cpp \
|
|
gtest/test_wallet_notecache.cpp \
|
|
gtest/test_wallet_history.cpp \
|
|
gtest/test_wallet_consolidation.cpp \
|
|
gtest/test_wallet_shutdownsave.cpp \
|
|
gtest/test_wallet_witnessroots.cpp \
|
|
gtest/test_sapling_addr_validity.cpp
|
|
|
|
hush_gtest_CPPFLAGS = $(AM_CPPFLAGS) -DMULTICORE -fopenmp -DBINARY_OUTPUT -DCURVE_ALT_BN128 -DSTATIC $(BITCOIN_INCLUDES)
|
|
hush_gtest_CXXFLAGS = $(AM_CXXFLAGS) $(PIE_FLAGS)
|
|
|
|
# Mirror dragonxd_LDADD's working library set/order (the old list used a non-existent
|
|
# $(LIBBITCOIN_UNIVALUE) so univalue was never linked, and omitted LIBHUSH/LIBRANDOMX/libcc).
|
|
hush_gtest_LDADD = -lgtest -lgmock \
|
|
$(LIBBITCOIN_SERVER) \
|
|
$(LIBCURL) \
|
|
$(LIBBITCOIN_COMMON) \
|
|
$(LIBUNIVALUE) \
|
|
$(LIBBITCOIN_UTIL) \
|
|
$(LIBBITCOIN_CRYPTO) \
|
|
$(LIBZCASH) \
|
|
$(LIBHUSH) \
|
|
$(LIBLEVELDB) \
|
|
$(LIBMEMENV) \
|
|
$(LIBSECP256K1) \
|
|
$(LIBRANDOMX)
|
|
if ENABLE_WALLET
|
|
# libbitcoin_server again after the wallet, spelled ./ so libtool keeps both copies (see dragonxd_LDADD).
|
|
hush_gtest_LDADD += $(LIBBITCOIN_WALLET) ./$(LIBBITCOIN_SERVER)
|
|
endif
|
|
|
|
hush_gtest_LDADD += \
|
|
$(BOOST_LIBS) \
|
|
$(BOOST_UNIT_TEST_FRAMEWORK_LIB) \
|
|
$(BDB_LIBS) \
|
|
$(SSL_LIBS) \
|
|
$(CRYPTO_LIBS) \
|
|
$(EVENT_PTHREADS_LIBS) \
|
|
$(EVENT_LIBS) \
|
|
$(LIBBITCOIN_CRYPTO) \
|
|
$(LIBZCASH_LIBS)
|
|
|
|
if TARGET_DARWIN
|
|
hush_gtest_LDADD += libcc.dylib $(LIBSECP256K1)
|
|
endif
|
|
if TARGET_WINDOWS
|
|
hush_gtest_LDADD += libcc.dll $(LIBSECP256K1)
|
|
endif
|
|
if TARGET_LINUX
|
|
hush_gtest_LDADD += libcc.so $(LIBSECP256K1)
|
|
endif
|
|
|
|
hush_gtest_LDFLAGS = $(RELDFLAGS) $(AM_LDFLAGS) $(LIBTOOL_APP_LDFLAGS)
|
|
|
|
hush-gtest-expected-failures: hush-gtest FORCE
|
|
./hush-gtest --gtest_filter=*DISABLED_* --gtest_also_run_disabled_tests
|