bench: add WalletBalanceManySpent for high-history wallet scenario #34360

Open
w0xlt wants to merge 2 commits from wallet-balance-many-spent-bench-3 into master AGit
w0xlt commented 2026-01-21 03:15:17 +00:00 (Migrated from github.com)

This PR introduces a new benchmark that measures GetBalance() performance on wallets with extensive transaction history where the majority of outputs have already been spent.

It was created to test #27865, which separates spent TXOs from spendable ones.
This pattern mirrors real-world usage in high-activity wallets such as Lightning nodes, exchanges, hot wallets, and payment processors.

Setup:

  • Creates 500 blocks × 100 coinbase outputs = 50,000 wallet TXOs
  • Matures all coinbases with COINBASE_MATURITY additional blocks
  • Spends 49,950 outputs in batched transactions (confirmed in blocks)
  • Consolidation outputs go to a burn script to avoid inflating wallet TXO count

To keep the setup time reasonable, the benchmark uses the fast “fake block” approach, similar to wallet_create_tx.cpp.

This PR introduces a new benchmark that measures `GetBalance()` performance on wallets with extensive transaction history where the majority of outputs have already been spent. It was created to test #27865, which separates spent TXOs from spendable ones. This pattern mirrors real-world usage in high-activity wallets such as Lightning nodes, exchanges, hot wallets, and payment processors. **Setup:** - Creates 500 blocks × 100 coinbase outputs = 50,000 wallet TXOs - Matures all coinbases with COINBASE_MATURITY additional blocks - Spends 49,950 outputs in batched transactions (confirmed in blocks) - Consolidation outputs go to a burn script to avoid inflating wallet TXO count To keep the setup time reasonable, the benchmark uses the fast “fake block” approach, similar to `wallet_create_tx.cpp`.
DrahtBot commented 2026-01-21 03:15:27 +00:00 (Migrated from github.com)

The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

External sites

Reviews

See the guideline and AI policy for information on the review process.

Type Reviewers
Stale ACK l0rinc

If your review is incorrectly listed, please copy-paste <!--meta-tag:bot-skip--> into the comment that the bot should ignore.

Conflicts

No conflicts as of last run.

<!--e57a25ab6845829454e8d69fc972939a--> The following sections might be updated with supplementary metadata relevant to reviewers and maintainers. <!--006a51241073e994b41acfe9ec718e94--> ### External sites * Code coverage & benchmarks: https://corecheck.dev/bitcoin/bitcoin/pulls/34360 * Ralph review <img src=https://review.fish.foo/assets/bitcoin/bitcoin/34360.png alt="Ralph review status"> https://git.fish.foo/bitcoin/bitcoin/pulls/34360#author-ralph <!--021abf342d371248e50ceaed478a90ca--> ### Reviews See [the guideline](https://github.com/bitcoin/bitcoin/blob/master/CONTRIBUTING.md#code-review) and [AI policy](https://github.com/bitcoin/bitcoin/blob/master/doc/AI_POLICY.md) for information on the review process. | Type | Reviewers | | ---- | --------- | | Stale ACK | [l0rinc](https://github.com/bitcoin/bitcoin/pull/34360#issuecomment-4519980069) | If your review is incorrectly listed, please copy-paste <code>&lt;!--meta-tag:bot-skip--&gt;</code> into the comment that the bot should ignore. <!--174a7506f384e20aa4161008e828411d--> ### Conflicts No conflicts as of last run. <!--5faf32d7da4f0f540f40219e4f7537a3-->
fanquake commented 2026-03-03 14:13:41 +00:00 (Migrated from github.com)

cc @achow101 given this is inspired by #27865.

cc @achow101 given this is inspired by #27865.
sedited commented 2026-05-14 10:44:18 +00:00 (Migrated from github.com)

@w0xlt can you rebase this?

@w0xlt can you rebase this?
l0rinc (Migrated from github.com) requested changes 2026-05-15 13:13:43 +00:00
l0rinc (Migrated from github.com) left a comment

I might have gone a bit overboard again, I left comments documenting my review journey, please see the individual explanations - feel free to pick and choose between them.

For convenience here's my local patch against your rebased branch:

Local pending changes
diff --git a/src/bench/wallet_balance.cpp b/src/bench/wallet_balance.cpp
index ee8244501a..7ce15529d6 100644
--- a/src/bench/wallet_balance.cpp
+++ b/src/bench/wallet_balance.cpp
@@ -18,6 +18,7 @@
 #include <wallet/wallet.h>
 
 #include <cassert>
+#include <cstddef>
 #include <memory>
 #include <optional>
 #include <string>
@@ -72,15 +73,26 @@ BENCHMARK(WalletBalanceWatch);
 
 static void WalletBalanceManySpent(benchmark::Bench& bench)
 {
+    constexpr int NUM_BLOCKS{500};
+    constexpr int OUTPUTS_PER_BLOCK{100};
+    constexpr CAmount OUTPUT_VALUE{50 * COIN / OUTPUTS_PER_BLOCK};
+    constexpr size_t TOTAL_WALLET_OUTPUTS{NUM_BLOCKS * OUTPUTS_PER_BLOCK};
+    constexpr size_t KEEP_UNSPENT{50};
+    constexpr size_t BATCH_SIZE{100};
+    constexpr CAmount FEE{1000};
+    constexpr size_t TXS_PER_BLOCK{10};
+    constexpr int FILLER_OUTPUTS{1};
+    constexpr CAmount FILLER_VALUE{50 * COIN};
+
     // Benchmark GetBalance with many spent TXOs and few unspent TXOs.
     // This scenario benefits from optimizations that separate definitely-spent
     // outputs from potentially-spendable ones (such as m_unusable_txos).
     //
-    // Target: ~50,000 spent TXOs, ~50 unspent TXOs
+    // Target: many spent TXOs, few unspent TXOs
     const auto test_setup = MakeNoLogFileContext<const TestingSetup>();
     const auto& params = test_setup->m_node.chainman->GetParams();
 
-    SetMockTime(params.GenesisBlock().nTime);
+    NodeClockContext clock_ctx{params.GenesisBlock().Time()};
     CWallet wallet{test_setup->m_node.chain.get(), "", CreateMockableWalletDatabase()};
     {
         LOCK(wallet.cs_wallet);
@@ -91,55 +103,51 @@ static void WalletBalanceManySpent(benchmark::Bench& bench)
 
     const auto dest = getNewDestination(wallet, OutputType::BECH32);
     const CScript wallet_script = GetScriptForDestination(dest);
-    // Burn script for outputs we don't want in the wallet
+    // OP_TRUE keeps the output spendable without adding it to the wallet
     const CScript burn_script{CScript() << OP_TRUE};
 
-    // Phase 1: Create many UTXOs (100 outputs per block * 500 blocks = 50,000 TXOs)
-    constexpr int NUM_BLOCKS = 500;
-    constexpr int OUTPUTS_PER_BLOCK = 100;
-    constexpr CAmount OUTPUT_VALUE = 50 * COIN / OUTPUTS_PER_BLOCK;
-
+    // Phase 1: Create the configured wallet-owned output history
     for (int i = 0; i < NUM_BLOCKS; ++i) {
         GenerateFakeBlock(params, test_setup->m_node, wallet, wallet_script, OUTPUTS_PER_BLOCK);
     }
 
     // Phase 2: Add COINBASE_MATURITY blocks to mature all coinbase outputs
-    // This ensures all 50,000 TXOs are spendable
     for (int i = 0; i < COINBASE_MATURITY; ++i) {
-        GenerateFakeBlock(params, test_setup->m_node, wallet, burn_script, 1);
+        GenerateFakeBlock(params, test_setup->m_node, wallet, burn_script, FILLER_OUTPUTS);
     }
 
     // Phase 3: Spend most UTXOs by creating spending transactions
     // Get all available coins and spend them in batches
     std::vector<COutPoint> outputs_to_spend;
+    outputs_to_spend.reserve(TOTAL_WALLET_OUTPUTS);
     {
         LOCK(wallet.cs_wallet);
-        auto available = AvailableCoins(wallet);
-        for (const auto& coin : available.All()) {
-            outputs_to_spend.push_back(coin.outpoint);
+        for (const auto& [_, coins] : AvailableCoins(wallet).coins) {
+            for (const auto& coin : coins) {
+                outputs_to_spend.push_back(coin.outpoint);
+            }
         }
     }
 
-    // Keep ~50 outputs unspent, spend the rest
-    constexpr int KEEP_UNSPENT = 50;
-    int num_to_spend = std::max(0, static_cast<int>(outputs_to_spend.size()) - KEEP_UNSPENT);
+    // Keep the configured small remainder unspent, and spend the rest
+    assert(outputs_to_spend.size() == TOTAL_WALLET_OUTPUTS);
+    const size_t num_to_spend{outputs_to_spend.size() - KEEP_UNSPENT};
 
-    // Create spending transactions in batches of 100 inputs each
-    constexpr int BATCH_SIZE = 100;
-    constexpr CAmount BENCHMARK_FEE = 1000;
+    // Create spending transactions in configured-size batches
     std::vector<CTransactionRef> spending_txs;
 
-    for (int i = 0; i < num_to_spend; i += BATCH_SIZE) {
+    for (size_t i{0}; i < num_to_spend; i += BATCH_SIZE) {
         CMutableTransaction spend_tx;
-        int batch_end = std::min(i + BATCH_SIZE, num_to_spend);
+        const size_t batch_end{std::min(i + BATCH_SIZE, num_to_spend)};
 
-        for (int j = i; j < batch_end; ++j) {
+        CAmount total_value{0};
+        for (size_t j{i}; j < batch_end; ++j) {
             spend_tx.vin.emplace_back(outputs_to_spend[j]);
+            total_value += OUTPUT_VALUE;
         }
 
         // Send to burn script so consolidation outputs don't add to wallet TXOs
-        CAmount total_value = (batch_end - i) * OUTPUT_VALUE;
-        spend_tx.vout.emplace_back(total_value - BENCHMARK_FEE, burn_script);
+        spend_tx.vout.emplace_back(total_value - FEE, burn_script);
 
         spending_txs.push_back(MakeTransactionRef(std::move(spend_tx)));
     }
@@ -147,22 +155,33 @@ static void WalletBalanceManySpent(benchmark::Bench& bench)
     // Phase 4: Confirm all spending transactions in new blocks
     // Include multiple spending txs per block for efficiency
     // Coinbase outputs go to burn script to avoid adding wallet TXOs
-    constexpr int TXS_PER_BLOCK = 10;
-    for (size_t i = 0; i < spending_txs.size(); i += TXS_PER_BLOCK) {
-        std::vector<CTransactionRef> block_txs;
-        for (size_t j = i; j < std::min(i + TXS_PER_BLOCK, spending_txs.size()); ++j) {
-            block_txs.push_back(spending_txs[j]);
+    for (size_t i{0}; i < spending_txs.size(); i += TXS_PER_BLOCK) {
+        const size_t batch_end{std::min(i + TXS_PER_BLOCK, spending_txs.size())};
+        std::vector<CTransactionRef> block_txs{spending_txs.begin() + i, spending_txs.begin() + batch_end};
+        GenerateFakeBlock(params, test_setup->m_node, wallet, burn_script, FILLER_OUTPUTS, FILLER_VALUE, block_txs);
+    }
+
+    // Balance alone does not prove that spent wallet outputs remain in history.
+    size_t owned_outputs{0}, spent_outputs{0};
+    {
+        LOCK(wallet.cs_wallet);
+        for (const auto& [outpoint, _] : wallet.GetTXOs()) {
+            ++owned_outputs;
+            spent_outputs += wallet.IsSpent(outpoint);
         }
-        GenerateFakeBlock(params, test_setup->m_node, wallet, burn_script, 1, 50 * COIN, block_txs);
     }
+    assert(owned_outputs == TOTAL_WALLET_OUTPUTS);
+    assert(spent_outputs == TOTAL_WALLET_OUTPUTS - KEEP_UNSPENT);
 
-    // Phase 5: Run the benchmark
-    auto bal = GetBalance(wallet); // Cache
+    CAmount expected_balance{0};
+    for (size_t i{0}; i < KEEP_UNSPENT; ++i) {
+        expected_balance += OUTPUT_VALUE;
+    }
 
-    bench.run([&] {
-        wallet.MarkDirty();
-        bal = GetBalance(wallet);
-        assert(bal.m_mine_trusted > 0);
+    bench.minEpochIterations(10).run([&] {
+        const auto bal{GetBalance(wallet)};
+        assert(bal.m_mine_trusted == expected_balance);
+        assert(bal.m_mine_immature == 0);
     });
 }
 
diff --git a/src/bench/wallet_bench_util.h b/src/bench/wallet_bench_util.h
index 7c7ebbb1d5..edc1bc15e3 100644
--- a/src/bench/wallet_bench_util.h
+++ b/src/bench/wallet_bench_util.h
@@ -19,20 +19,26 @@
 #include <versionbits.h>
 #include <wallet/wallet.h>
 
+#include <vector>
+
 namespace wallet {
 
 struct TipBlock
 {
-    uint256 prev_block_hash;
-    int64_t prev_block_time;
-    int tip_height;
+    uint256 prev_block_hash{};
+    int64_t prev_block_time{0};
+    int tip_height{0};
 };
 
 inline TipBlock GetTip(const CChainParams& params, const node::NodeContext& context)
 {
-    auto tip = WITH_LOCK(::cs_main, return context.chainman->ActiveTip());
-    return (tip) ? TipBlock{tip->GetBlockHash(), tip->GetBlockTime(), tip->nHeight} :
-           TipBlock{params.GenesisBlock().GetHash(), params.GenesisBlock().GetBlockTime(), 0};
+    {
+        LOCK(::cs_main);
+        if (const auto* tip{context.chainman->ActiveTip()}) {
+            return {tip->GetBlockHash(), tip->GetBlockTime(), tip->nHeight};
+        }
+    }
+    return {params.GenesisBlock().GetHash(), params.GenesisBlock().GetBlockTime(), 0};
 }
 
 /**
@@ -42,9 +48,7 @@ inline TipBlock GetTip(const CChainParams& params, const node::NodeContext& cont
 inline void GenerateFakeBlock(const CChainParams& params,
                               const node::NodeContext& context,
                               CWallet& wallet,
-                              const CScript& coinbase_script,
-                              int num_coinbase_outputs,
-                              CAmount total_coinbase_value = 50 * COIN,
+                              const std::vector<CTxOut>& coinbase_outputs,
                               const std::vector<CTransactionRef>& extra_txs = {})
 {
     TipBlock tip{GetTip(params, context)};
@@ -54,19 +58,11 @@ inline void GenerateFakeBlock(const CChainParams& params,
     coinbase_tx.vin.resize(1);
     coinbase_tx.vin[0].prevout.SetNull();
     coinbase_tx.vin[0].scriptSig = CScript() << ++tip.tip_height << OP_0;
-
-    // Create coinbase outputs
-    CAmount per_output = total_coinbase_value / num_coinbase_outputs;
-    for (int i = 0; i < num_coinbase_outputs; ++i) {
-        coinbase_tx.vout.emplace_back(per_output, coinbase_script);
-    }
+    coinbase_tx.vout = coinbase_outputs;
 
     block.vtx = {MakeTransactionRef(std::move(coinbase_tx))};
 
-    // Add any extra transactions
-    for (const auto& tx : extra_txs) {
-        block.vtx.push_back(tx);
-    }
+    block.vtx.insert(block.vtx.end(), extra_txs.begin(), extra_txs.end());
 
     block.nVersion = VERSIONBITS_LAST_OLD_BLOCK_VERSION;
     block.hashPrevBlock = tip.prev_block_hash;
@@ -75,16 +71,33 @@ inline void GenerateFakeBlock(const CChainParams& params,
     block.nBits = params.GenesisBlock().nBits;
     block.nNonce = 0;
 
+    CBlockIndex* pindex{nullptr};
     {
         LOCK(::cs_main);
-        CBlockIndex* pindex{context.chainman->m_blockman.AddToBlockIndex(block, context.chainman->m_best_header)};
+        pindex = context.chainman->m_blockman.AddToBlockIndex(block, context.chainman->m_best_header);
         context.chainman->ActiveChain().SetTip(*pindex);
     }
 
-    const auto* pindex = WITH_LOCK(::cs_main, return context.chainman->ActiveChain().Tip());
     wallet.blockConnected(kernel::ChainstateRole{}, kernel::MakeBlockInfo(pindex, &block));
 }
 
+inline void GenerateFakeBlock(const CChainParams& params,
+                              const node::NodeContext& context,
+                              CWallet& wallet,
+                              const CScript& coinbase_script,
+                              int num_coinbase_outputs,
+                              CAmount total_coinbase_value = 50 * COIN,
+                              const std::vector<CTransactionRef>& extra_txs = {})
+{
+    std::vector<CTxOut> coinbase_outputs;
+    coinbase_outputs.reserve(num_coinbase_outputs);
+    const CAmount per_output{total_coinbase_value / num_coinbase_outputs};
+    for (int i{0}; i < num_coinbase_outputs; ++i) {
+        coinbase_outputs.emplace_back(per_output, coinbase_script);
+    }
+    GenerateFakeBlock(params, context, wallet, coinbase_outputs, extra_txs);
+}
+
 } // namespace wallet
 
 #endif // BITCOIN_BENCH_WALLET_BENCH_UTIL_H
diff --git a/src/bench/wallet_create_tx.cpp b/src/bench/wallet_create_tx.cpp
index 11125e26fe..309c950671 100644
--- a/src/bench/wallet_create_tx.cpp
+++ b/src/bench/wallet_create_tx.cpp
@@ -4,28 +4,20 @@
 
 #include <addresstype.h>
 #include <bench/bench.h>
-#include <chain.h>
+#include <bench/wallet_bench_util.h>
 #include <chainparams.h>
 #include <consensus/amount.h>
 #include <consensus/consensus.h>
-#include <consensus/merkle.h>
 #include <interfaces/chain.h>
-#include <kernel/chain.h>
-#include <kernel/types.h>
-#include <node/blockstorage.h>
 #include <outputtype.h>
 #include <policy/feerate.h>
-#include <primitives/block.h>
 #include <primitives/transaction.h>
 #include <script/script.h>
 #include <sync.h>
 #include <test/util/setup_common.h>
 #include <test/util/time.h>
-#include <uint256.h>
 #include <util/result.h>
 #include <util/time.h>
-#include <validation.h>
-#include <versionbits.h>
 #include <wallet/coincontrol.h>
 #include <wallet/coinselection.h>
 #include <wallet/spend.h>
@@ -41,70 +33,28 @@
 #include <utility>
 #include <vector>
 
-using kernel::ChainstateRole;
 using wallet::CWallet;
 using wallet::CreateMockableWalletDatabase;
 using wallet::WALLET_FLAG_DESCRIPTORS;
 
-struct TipBlock
-{
-    uint256 prev_block_hash;
-    int64_t prev_block_time;
-    int tip_height;
-};
-
-TipBlock getTip(const CChainParams& params, const node::NodeContext& context)
-{
-    auto tip = WITH_LOCK(::cs_main, return context.chainman->ActiveTip());
-    return (tip) ? TipBlock{tip->GetBlockHash(), tip->GetBlockTime(), tip->nHeight} :
-           TipBlock{params.GenesisBlock().GetHash(), params.GenesisBlock().GetBlockTime(), 0};
-}
-
 void generateFakeBlock(const CChainParams& params,
                        const node::NodeContext& context,
                        CWallet& wallet,
                        const CScript& coinbase_out_script)
 {
-    TipBlock tip{getTip(params, context)};
-
-    // Create block
-    CBlock block;
-    CMutableTransaction coinbase_tx;
-    coinbase_tx.vin.resize(1);
-    coinbase_tx.vin[0].prevout.SetNull();
-    coinbase_tx.vout.resize(2);
-    coinbase_tx.vout[0].scriptPubKey = coinbase_out_script;
-    coinbase_tx.vout[0].nValue = 48 * COIN;
-    coinbase_tx.vin[0].scriptSig = CScript() << ++tip.tip_height << OP_0;
-    coinbase_tx.vout[1].scriptPubKey = coinbase_out_script; // extra output
-    coinbase_tx.vout[1].nValue = 1 * COIN;
+    constexpr int NON_WALLET_OUTPUTS{50};
+    std::vector<CTxOut> coinbase_outputs;
+    coinbase_outputs.reserve(2 + NON_WALLET_OUTPUTS);
+    coinbase_outputs.emplace_back(48 * COIN, coinbase_out_script);
+    coinbase_outputs.emplace_back(1 * COIN, coinbase_out_script);
 
     // Fill the coinbase with outputs that don't belong to the wallet in order to benchmark
     // AvailableCoins' behavior with unnecessary TXOs
-    for (int i = 0; i < 50; ++i) {
-        coinbase_tx.vout.emplace_back(1 * COIN / 50, CScript(OP_TRUE));
-    }
-
-    block.vtx = {MakeTransactionRef(std::move(coinbase_tx))};
-
-    block.nVersion = VERSIONBITS_LAST_OLD_BLOCK_VERSION;
-    block.hashPrevBlock = tip.prev_block_hash;
-    block.hashMerkleRoot = BlockMerkleRoot(block);
-    block.nTime = ++tip.prev_block_time;
-    block.nBits = params.GenesisBlock().nBits;
-    block.nNonce = 0;
-
-    {
-        LOCK(::cs_main);
-        // Add it to the index
-        CBlockIndex* pindex{context.chainman->m_blockman.AddToBlockIndex(block, context.chainman->m_best_header)};
-        // add it to the chain
-        context.chainman->ActiveChain().SetTip(*pindex);
+    for (int i{0}; i < NON_WALLET_OUTPUTS; ++i) {
+        coinbase_outputs.emplace_back(1 * COIN / NON_WALLET_OUTPUTS, CScript(OP_TRUE));
     }
 
-    // notify wallet
-    const auto& pindex = WITH_LOCK(::cs_main, return context.chainman->ActiveChain().Tip());
-    wallet.blockConnected(ChainstateRole{}, kernel::MakeBlockInfo(pindex, &block));
+    wallet::GenerateFakeBlock(params, context, wallet, coinbase_outputs);
 }
 
 struct PreSelectInputs {
I might have gone a bit overboard again, I left comments documenting my review journey, please see the individual explanations - feel free to pick and choose between them. For convenience here's my local patch against your rebased branch: <details><summary>Local pending changes</summary> ```patch diff --git a/src/bench/wallet_balance.cpp b/src/bench/wallet_balance.cpp index ee8244501a..7ce15529d6 100644 --- a/src/bench/wallet_balance.cpp +++ b/src/bench/wallet_balance.cpp @@ -18,6 +18,7 @@ #include <wallet/wallet.h> #include <cassert> +#include <cstddef> #include <memory> #include <optional> #include <string> @@ -72,15 +73,26 @@ BENCHMARK(WalletBalanceWatch); static void WalletBalanceManySpent(benchmark::Bench& bench) { + constexpr int NUM_BLOCKS{500}; + constexpr int OUTPUTS_PER_BLOCK{100}; + constexpr CAmount OUTPUT_VALUE{50 * COIN / OUTPUTS_PER_BLOCK}; + constexpr size_t TOTAL_WALLET_OUTPUTS{NUM_BLOCKS * OUTPUTS_PER_BLOCK}; + constexpr size_t KEEP_UNSPENT{50}; + constexpr size_t BATCH_SIZE{100}; + constexpr CAmount FEE{1000}; + constexpr size_t TXS_PER_BLOCK{10}; + constexpr int FILLER_OUTPUTS{1}; + constexpr CAmount FILLER_VALUE{50 * COIN}; + // Benchmark GetBalance with many spent TXOs and few unspent TXOs. // This scenario benefits from optimizations that separate definitely-spent // outputs from potentially-spendable ones (such as m_unusable_txos). // - // Target: ~50,000 spent TXOs, ~50 unspent TXOs + // Target: many spent TXOs, few unspent TXOs const auto test_setup = MakeNoLogFileContext<const TestingSetup>(); const auto& params = test_setup->m_node.chainman->GetParams(); - SetMockTime(params.GenesisBlock().nTime); + NodeClockContext clock_ctx{params.GenesisBlock().Time()}; CWallet wallet{test_setup->m_node.chain.get(), "", CreateMockableWalletDatabase()}; { LOCK(wallet.cs_wallet); @@ -91,55 +103,51 @@ static void WalletBalanceManySpent(benchmark::Bench& bench) const auto dest = getNewDestination(wallet, OutputType::BECH32); const CScript wallet_script = GetScriptForDestination(dest); - // Burn script for outputs we don't want in the wallet + // OP_TRUE keeps the output spendable without adding it to the wallet const CScript burn_script{CScript() << OP_TRUE}; - // Phase 1: Create many UTXOs (100 outputs per block * 500 blocks = 50,000 TXOs) - constexpr int NUM_BLOCKS = 500; - constexpr int OUTPUTS_PER_BLOCK = 100; - constexpr CAmount OUTPUT_VALUE = 50 * COIN / OUTPUTS_PER_BLOCK; - + // Phase 1: Create the configured wallet-owned output history for (int i = 0; i < NUM_BLOCKS; ++i) { GenerateFakeBlock(params, test_setup->m_node, wallet, wallet_script, OUTPUTS_PER_BLOCK); } // Phase 2: Add COINBASE_MATURITY blocks to mature all coinbase outputs - // This ensures all 50,000 TXOs are spendable for (int i = 0; i < COINBASE_MATURITY; ++i) { - GenerateFakeBlock(params, test_setup->m_node, wallet, burn_script, 1); + GenerateFakeBlock(params, test_setup->m_node, wallet, burn_script, FILLER_OUTPUTS); } // Phase 3: Spend most UTXOs by creating spending transactions // Get all available coins and spend them in batches std::vector<COutPoint> outputs_to_spend; + outputs_to_spend.reserve(TOTAL_WALLET_OUTPUTS); { LOCK(wallet.cs_wallet); - auto available = AvailableCoins(wallet); - for (const auto& coin : available.All()) { - outputs_to_spend.push_back(coin.outpoint); + for (const auto& [_, coins] : AvailableCoins(wallet).coins) { + for (const auto& coin : coins) { + outputs_to_spend.push_back(coin.outpoint); + } } } - // Keep ~50 outputs unspent, spend the rest - constexpr int KEEP_UNSPENT = 50; - int num_to_spend = std::max(0, static_cast<int>(outputs_to_spend.size()) - KEEP_UNSPENT); + // Keep the configured small remainder unspent, and spend the rest + assert(outputs_to_spend.size() == TOTAL_WALLET_OUTPUTS); + const size_t num_to_spend{outputs_to_spend.size() - KEEP_UNSPENT}; - // Create spending transactions in batches of 100 inputs each - constexpr int BATCH_SIZE = 100; - constexpr CAmount BENCHMARK_FEE = 1000; + // Create spending transactions in configured-size batches std::vector<CTransactionRef> spending_txs; - for (int i = 0; i < num_to_spend; i += BATCH_SIZE) { + for (size_t i{0}; i < num_to_spend; i += BATCH_SIZE) { CMutableTransaction spend_tx; - int batch_end = std::min(i + BATCH_SIZE, num_to_spend); + const size_t batch_end{std::min(i + BATCH_SIZE, num_to_spend)}; - for (int j = i; j < batch_end; ++j) { + CAmount total_value{0}; + for (size_t j{i}; j < batch_end; ++j) { spend_tx.vin.emplace_back(outputs_to_spend[j]); + total_value += OUTPUT_VALUE; } // Send to burn script so consolidation outputs don't add to wallet TXOs - CAmount total_value = (batch_end - i) * OUTPUT_VALUE; - spend_tx.vout.emplace_back(total_value - BENCHMARK_FEE, burn_script); + spend_tx.vout.emplace_back(total_value - FEE, burn_script); spending_txs.push_back(MakeTransactionRef(std::move(spend_tx))); } @@ -147,22 +155,33 @@ static void WalletBalanceManySpent(benchmark::Bench& bench) // Phase 4: Confirm all spending transactions in new blocks // Include multiple spending txs per block for efficiency // Coinbase outputs go to burn script to avoid adding wallet TXOs - constexpr int TXS_PER_BLOCK = 10; - for (size_t i = 0; i < spending_txs.size(); i += TXS_PER_BLOCK) { - std::vector<CTransactionRef> block_txs; - for (size_t j = i; j < std::min(i + TXS_PER_BLOCK, spending_txs.size()); ++j) { - block_txs.push_back(spending_txs[j]); + for (size_t i{0}; i < spending_txs.size(); i += TXS_PER_BLOCK) { + const size_t batch_end{std::min(i + TXS_PER_BLOCK, spending_txs.size())}; + std::vector<CTransactionRef> block_txs{spending_txs.begin() + i, spending_txs.begin() + batch_end}; + GenerateFakeBlock(params, test_setup->m_node, wallet, burn_script, FILLER_OUTPUTS, FILLER_VALUE, block_txs); + } + + // Balance alone does not prove that spent wallet outputs remain in history. + size_t owned_outputs{0}, spent_outputs{0}; + { + LOCK(wallet.cs_wallet); + for (const auto& [outpoint, _] : wallet.GetTXOs()) { + ++owned_outputs; + spent_outputs += wallet.IsSpent(outpoint); } - GenerateFakeBlock(params, test_setup->m_node, wallet, burn_script, 1, 50 * COIN, block_txs); } + assert(owned_outputs == TOTAL_WALLET_OUTPUTS); + assert(spent_outputs == TOTAL_WALLET_OUTPUTS - KEEP_UNSPENT); - // Phase 5: Run the benchmark - auto bal = GetBalance(wallet); // Cache + CAmount expected_balance{0}; + for (size_t i{0}; i < KEEP_UNSPENT; ++i) { + expected_balance += OUTPUT_VALUE; + } - bench.run([&] { - wallet.MarkDirty(); - bal = GetBalance(wallet); - assert(bal.m_mine_trusted > 0); + bench.minEpochIterations(10).run([&] { + const auto bal{GetBalance(wallet)}; + assert(bal.m_mine_trusted == expected_balance); + assert(bal.m_mine_immature == 0); }); } diff --git a/src/bench/wallet_bench_util.h b/src/bench/wallet_bench_util.h index 7c7ebbb1d5..edc1bc15e3 100644 --- a/src/bench/wallet_bench_util.h +++ b/src/bench/wallet_bench_util.h @@ -19,20 +19,26 @@ #include <versionbits.h> #include <wallet/wallet.h> +#include <vector> + namespace wallet { struct TipBlock { - uint256 prev_block_hash; - int64_t prev_block_time; - int tip_height; + uint256 prev_block_hash{}; + int64_t prev_block_time{0}; + int tip_height{0}; }; inline TipBlock GetTip(const CChainParams& params, const node::NodeContext& context) { - auto tip = WITH_LOCK(::cs_main, return context.chainman->ActiveTip()); - return (tip) ? TipBlock{tip->GetBlockHash(), tip->GetBlockTime(), tip->nHeight} : - TipBlock{params.GenesisBlock().GetHash(), params.GenesisBlock().GetBlockTime(), 0}; + { + LOCK(::cs_main); + if (const auto* tip{context.chainman->ActiveTip()}) { + return {tip->GetBlockHash(), tip->GetBlockTime(), tip->nHeight}; + } + } + return {params.GenesisBlock().GetHash(), params.GenesisBlock().GetBlockTime(), 0}; } /** @@ -42,9 +48,7 @@ inline TipBlock GetTip(const CChainParams& params, const node::NodeContext& cont inline void GenerateFakeBlock(const CChainParams& params, const node::NodeContext& context, CWallet& wallet, - const CScript& coinbase_script, - int num_coinbase_outputs, - CAmount total_coinbase_value = 50 * COIN, + const std::vector<CTxOut>& coinbase_outputs, const std::vector<CTransactionRef>& extra_txs = {}) { TipBlock tip{GetTip(params, context)}; @@ -54,19 +58,11 @@ inline void GenerateFakeBlock(const CChainParams& params, coinbase_tx.vin.resize(1); coinbase_tx.vin[0].prevout.SetNull(); coinbase_tx.vin[0].scriptSig = CScript() << ++tip.tip_height << OP_0; - - // Create coinbase outputs - CAmount per_output = total_coinbase_value / num_coinbase_outputs; - for (int i = 0; i < num_coinbase_outputs; ++i) { - coinbase_tx.vout.emplace_back(per_output, coinbase_script); - } + coinbase_tx.vout = coinbase_outputs; block.vtx = {MakeTransactionRef(std::move(coinbase_tx))}; - // Add any extra transactions - for (const auto& tx : extra_txs) { - block.vtx.push_back(tx); - } + block.vtx.insert(block.vtx.end(), extra_txs.begin(), extra_txs.end()); block.nVersion = VERSIONBITS_LAST_OLD_BLOCK_VERSION; block.hashPrevBlock = tip.prev_block_hash; @@ -75,16 +71,33 @@ inline void GenerateFakeBlock(const CChainParams& params, block.nBits = params.GenesisBlock().nBits; block.nNonce = 0; + CBlockIndex* pindex{nullptr}; { LOCK(::cs_main); - CBlockIndex* pindex{context.chainman->m_blockman.AddToBlockIndex(block, context.chainman->m_best_header)}; + pindex = context.chainman->m_blockman.AddToBlockIndex(block, context.chainman->m_best_header); context.chainman->ActiveChain().SetTip(*pindex); } - const auto* pindex = WITH_LOCK(::cs_main, return context.chainman->ActiveChain().Tip()); wallet.blockConnected(kernel::ChainstateRole{}, kernel::MakeBlockInfo(pindex, &block)); } +inline void GenerateFakeBlock(const CChainParams& params, + const node::NodeContext& context, + CWallet& wallet, + const CScript& coinbase_script, + int num_coinbase_outputs, + CAmount total_coinbase_value = 50 * COIN, + const std::vector<CTransactionRef>& extra_txs = {}) +{ + std::vector<CTxOut> coinbase_outputs; + coinbase_outputs.reserve(num_coinbase_outputs); + const CAmount per_output{total_coinbase_value / num_coinbase_outputs}; + for (int i{0}; i < num_coinbase_outputs; ++i) { + coinbase_outputs.emplace_back(per_output, coinbase_script); + } + GenerateFakeBlock(params, context, wallet, coinbase_outputs, extra_txs); +} + } // namespace wallet #endif // BITCOIN_BENCH_WALLET_BENCH_UTIL_H diff --git a/src/bench/wallet_create_tx.cpp b/src/bench/wallet_create_tx.cpp index 11125e26fe..309c950671 100644 --- a/src/bench/wallet_create_tx.cpp +++ b/src/bench/wallet_create_tx.cpp @@ -4,28 +4,20 @@ #include <addresstype.h> #include <bench/bench.h> -#include <chain.h> +#include <bench/wallet_bench_util.h> #include <chainparams.h> #include <consensus/amount.h> #include <consensus/consensus.h> -#include <consensus/merkle.h> #include <interfaces/chain.h> -#include <kernel/chain.h> -#include <kernel/types.h> -#include <node/blockstorage.h> #include <outputtype.h> #include <policy/feerate.h> -#include <primitives/block.h> #include <primitives/transaction.h> #include <script/script.h> #include <sync.h> #include <test/util/setup_common.h> #include <test/util/time.h> -#include <uint256.h> #include <util/result.h> #include <util/time.h> -#include <validation.h> -#include <versionbits.h> #include <wallet/coincontrol.h> #include <wallet/coinselection.h> #include <wallet/spend.h> @@ -41,70 +33,28 @@ #include <utility> #include <vector> -using kernel::ChainstateRole; using wallet::CWallet; using wallet::CreateMockableWalletDatabase; using wallet::WALLET_FLAG_DESCRIPTORS; -struct TipBlock -{ - uint256 prev_block_hash; - int64_t prev_block_time; - int tip_height; -}; - -TipBlock getTip(const CChainParams& params, const node::NodeContext& context) -{ - auto tip = WITH_LOCK(::cs_main, return context.chainman->ActiveTip()); - return (tip) ? TipBlock{tip->GetBlockHash(), tip->GetBlockTime(), tip->nHeight} : - TipBlock{params.GenesisBlock().GetHash(), params.GenesisBlock().GetBlockTime(), 0}; -} - void generateFakeBlock(const CChainParams& params, const node::NodeContext& context, CWallet& wallet, const CScript& coinbase_out_script) { - TipBlock tip{getTip(params, context)}; - - // Create block - CBlock block; - CMutableTransaction coinbase_tx; - coinbase_tx.vin.resize(1); - coinbase_tx.vin[0].prevout.SetNull(); - coinbase_tx.vout.resize(2); - coinbase_tx.vout[0].scriptPubKey = coinbase_out_script; - coinbase_tx.vout[0].nValue = 48 * COIN; - coinbase_tx.vin[0].scriptSig = CScript() << ++tip.tip_height << OP_0; - coinbase_tx.vout[1].scriptPubKey = coinbase_out_script; // extra output - coinbase_tx.vout[1].nValue = 1 * COIN; + constexpr int NON_WALLET_OUTPUTS{50}; + std::vector<CTxOut> coinbase_outputs; + coinbase_outputs.reserve(2 + NON_WALLET_OUTPUTS); + coinbase_outputs.emplace_back(48 * COIN, coinbase_out_script); + coinbase_outputs.emplace_back(1 * COIN, coinbase_out_script); // Fill the coinbase with outputs that don't belong to the wallet in order to benchmark // AvailableCoins' behavior with unnecessary TXOs - for (int i = 0; i < 50; ++i) { - coinbase_tx.vout.emplace_back(1 * COIN / 50, CScript(OP_TRUE)); - } - - block.vtx = {MakeTransactionRef(std::move(coinbase_tx))}; - - block.nVersion = VERSIONBITS_LAST_OLD_BLOCK_VERSION; - block.hashPrevBlock = tip.prev_block_hash; - block.hashMerkleRoot = BlockMerkleRoot(block); - block.nTime = ++tip.prev_block_time; - block.nBits = params.GenesisBlock().nBits; - block.nNonce = 0; - - { - LOCK(::cs_main); - // Add it to the index - CBlockIndex* pindex{context.chainman->m_blockman.AddToBlockIndex(block, context.chainman->m_best_header)}; - // add it to the chain - context.chainman->ActiveChain().SetTip(*pindex); + for (int i{0}; i < NON_WALLET_OUTPUTS; ++i) { + coinbase_outputs.emplace_back(1 * COIN / NON_WALLET_OUTPUTS, CScript(OP_TRUE)); } - // notify wallet - const auto& pindex = WITH_LOCK(::cs_main, return context.chainman->ActiveChain().Tip()); - wallet.blockConnected(ChainstateRole{}, kernel::MakeBlockInfo(pindex, &block)); + wallet::GenerateFakeBlock(params, context, wallet, coinbase_outputs); } struct PreSelectInputs { ``` </details>
l0rinc (Migrated from github.com) commented 2026-05-15 12:18:21 +00:00

We could use NodeClockContext here instead, like the adjacent wallet balance benchmark, so the mocked clock is restored automatically when setup leaves scope (see https://github.com/bitcoin/bitcoin/pull/34858/changes#diff-242a3d315a6189295f7169824284383659b1d83ac65241351a930348d5b8ee82L10-R39):

    NodeClockContext clock_ctx{params.GenesisBlock().Time()};

cc: @maflcko

We could use `NodeClockContext` here instead, like the adjacent wallet balance benchmark, so the mocked clock is restored automatically when setup leaves scope (see https://github.com/bitcoin/bitcoin/pull/34858/changes#diff-242a3d315a6189295f7169824284383659b1d83ac65241351a930348d5b8ee82L10-R39): ```suggestion NodeClockContext clock_ctx{params.GenesisBlock().Time()}; ``` cc: @maflcko
l0rinc (Migrated from github.com) commented 2026-05-15 11:38:51 +00:00

nit: these comments lock in the values of the configuration options above. Code comments are meant to add extra context that the code can't easily explain. Here, it's partially duplicating the code.
Please consider deduplicating the values from their meanings:

    // Target: many spent TXOs, few unspent TXOs.

and

    // Phase 1: Create the configured wallet-owned output history.

and

    // Keep the configured small remainder unspent, and spend the rest.

etc.

nit: these comments lock in the values of the configuration options above. Code comments are meant to add extra context that the code can't easily explain. Here, it's partially duplicating the code. Please consider deduplicating the values from their meanings: ```C++ // Target: many spent TXOs, few unspent TXOs. ``` and ```C++ // Phase 1: Create the configured wallet-owned output history. ``` and ```C++ // Keep the configured small remainder unspent, and spend the rest. ``` etc.
l0rinc (Migrated from github.com) commented 2026-05-15 11:24:31 +00:00

Not sure how to interpret this, why would we want to run a benchmark with 0?
The description of the PR claims we have 50k total outputs, we could reserve and assert that for clarity:

constexpr size_t TOTAL_WALLET_OUTPUTS{NUM_BLOCKS * OUTPUTS_PER_BLOCK};
...
std::vector<COutPoint> outputs_to_spend;
outputs_to_spend.reserve(TOTAL_WALLET_OUTPUTS);
...
constexpr size_t KEEP_UNSPENT{50};
assert(outputs_to_spend.size() == TOTAL_WALLET_OUTPUTS);
const size_t num_to_spend{outputs_to_spend.size() - KEEP_UNSPENT};
Not sure how to interpret this, why would we want to run a benchmark with `0`? The description of the PR claims we have 50k total outputs, we could reserve and assert that for clarity: ```C++ constexpr size_t TOTAL_WALLET_OUTPUTS{NUM_BLOCKS * OUTPUTS_PER_BLOCK}; ... std::vector<COutPoint> outputs_to_spend; outputs_to_spend.reserve(TOTAL_WALLET_OUTPUTS); ... constexpr size_t KEEP_UNSPENT{50}; assert(outputs_to_spend.size() == TOTAL_WALLET_OUTPUTS); const size_t num_to_spend{outputs_to_spend.size() - KEEP_UNSPENT}; ```
l0rinc (Migrated from github.com) commented 2026-05-15 11:37:18 +00:00

these intertwined constant definitions kinda' break the abstraction for me: the point of defining them is that we shouldn't care about their exact value when we're using them.
If you agree, please consider extracting the constant initializations either at the beginning or as fields (and maybe use brace init to avoid narrowing and weird type conversions).
That would separate the concerns: when we're interested in the configuration of the benchmark (the values used) we have that concern in one dedicated place and when we're interested in the algorithm (where we want to avoid knowing the implementation details) we can just rely on the config names:

static void WalletBalanceManySpent(benchmark::Bench& bench)
{
    constexpr int NUM_BLOCKS{500};
    constexpr int OUTPUTS_PER_BLOCK{100};
    constexpr CAmount OUTPUT_VALUE{50 * COIN / OUTPUTS_PER_BLOCK};
    constexpr size_t TOTAL_WALLET_OUTPUTS{NUM_BLOCKS * OUTPUTS_PER_BLOCK};
    constexpr size_t KEEP_UNSPENT{50};
    constexpr size_t BATCH_SIZE{100};
    constexpr CAmount FEE{1000};
    constexpr size_t TXS_PER_BLOCK{10};
    constexpr int FILLER_OUTPUTS{1};
    constexpr CAmount FILLER_VALUE{50 * COIN};
...
these intertwined constant definitions kinda' break the abstraction for me: the point of defining them is that we shouldn't care about their exact value when we're using them. If you agree, please consider extracting the constant initializations either at the beginning or as fields (and maybe use brace init to avoid narrowing and weird type conversions). That would separate the concerns: when we're interested in the configuration of the benchmark (the values used) we have that concern in one dedicated place and when we're interested in the algorithm (where we want to avoid knowing the implementation details) we can just rely on the config names: ```C++ static void WalletBalanceManySpent(benchmark::Bench& bench) { constexpr int NUM_BLOCKS{500}; constexpr int OUTPUTS_PER_BLOCK{100}; constexpr CAmount OUTPUT_VALUE{50 * COIN / OUTPUTS_PER_BLOCK}; constexpr size_t TOTAL_WALLET_OUTPUTS{NUM_BLOCKS * OUTPUTS_PER_BLOCK}; constexpr size_t KEEP_UNSPENT{50}; constexpr size_t BATCH_SIZE{100}; constexpr CAmount FEE{1000}; constexpr size_t TXS_PER_BLOCK{10}; constexpr int FILLER_OUTPUTS{1}; constexpr CAmount FILLER_VALUE{50 * COIN}; ... ```
l0rinc (Migrated from github.com) commented 2026-05-15 12:23:39 +00:00

We could avoid copying the 50k COutput entries (and avoid resizing) before the spend phase by iterating the existing AvailableCoins result directly:

    std::vector<COutPoint> outputs_to_spend;
    outputs_to_spend.reserve(TOTAL_WALLET_OUTPUTS);
    {
        LOCK(wallet.cs_wallet);
        for (const auto& [_, coins] : AvailableCoins(wallet).coins) {
            for (const auto& coin : coins) {
                outputs_to_spend.push_back(coin.outpoint);
            }
        }
    }
We could avoid copying the 50k COutput entries (and avoid resizing) before the spend phase by iterating the existing `AvailableCoins` result directly: ```suggestion std::vector<COutPoint> outputs_to_spend; outputs_to_spend.reserve(TOTAL_WALLET_OUTPUTS); { LOCK(wallet.cs_wallet); for (const auto& [_, coins] : AvailableCoins(wallet).coins) { for (const auto& coin : coins) { outputs_to_spend.push_back(coin.outpoint); } } } ```
l0rinc (Migrated from github.com) commented 2026-05-15 11:26:54 +00:00

nit: this basically duplicates the logic of the previous loop - alternatively it may be simpler to understand it if we reused the logic:

        CAmount total_value{0};
        for (size_t j{i}; j < batch_end; ++j) {
            spend_tx.vin.emplace_back(outputs_to_spend[j]);
            total_value += OUTPUT_VALUE;
        }

        // Send to burn script so consolidation outputs don't add to wallet TXOs
nit: this basically duplicates the logic of the previous loop - alternatively it may be simpler to understand it if we reused the logic: ```suggestion CAmount total_value{0}; for (size_t j{i}; j < batch_end; ++j) { spend_tx.vin.emplace_back(outputs_to_spend[j]); total_value += OUTPUT_VALUE; } // Send to burn script so consolidation outputs don't add to wallet TXOs ```
l0rinc (Migrated from github.com) commented 2026-05-15 10:44:59 +00:00

For clarity on what the unnamed primitive arguments mean, please consider adding name hints:

        GenerateFakeBlock(params, test_setup->m_node, wallet, burn_script, /*num_coinbase_outputs=*/1, /*total_coinbase_value=*/50 * COIN, block_txs);

or even better, we could extract these as suggested in https://github.com/bitcoin/bitcoin/pull/34360/changes#r3247900786
and use them as

        GenerateFakeBlock(params, test_setup->m_node, wallet, burn_script, FILLER_OUTPUTS, FILLER_VALUE, block_txs);
For clarity on what the unnamed primitive arguments mean, please consider adding name hints: ```suggestion GenerateFakeBlock(params, test_setup->m_node, wallet, burn_script, /*num_coinbase_outputs=*/1, /*total_coinbase_value=*/50 * COIN, block_txs); ``` or even better, we could extract these as suggested in https://github.com/bitcoin/bitcoin/pull/34360/changes#r3247900786 and use them as ```suggestion GenerateFakeBlock(params, test_setup->m_node, wallet, burn_script, FILLER_OUTPUTS, FILLER_VALUE, block_txs); ```
l0rinc (Migrated from github.com) commented 2026-05-15 12:27:47 +00:00

It seems to me we could simplify this continuous-slice copy:

        const size_t batch_end{std::min(i + TXS_PER_BLOCK, spending_txs.size())};
        std::vector<CTransactionRef> block_txs{spending_txs.begin() + i, spending_txs.begin() + batch_end};

Similarly for

    // Add any extra transactions
    for (const auto& tx : extra_txs) {
        block.vtx.push_back(tx);
    }

we can probably use vector::insert for that append instead of spelling out an equivalent push_back loop in the helper:

    block.vtx.insert(block.vtx.end(), extra_txs.begin(), extra_txs.end());
It seems to me we could simplify this continuous-slice copy: ```suggestion const size_t batch_end{std::min(i + TXS_PER_BLOCK, spending_txs.size())}; std::vector<CTransactionRef> block_txs{spending_txs.begin() + i, spending_txs.begin() + batch_end}; ``` ---- Similarly for ```C++ // Add any extra transactions for (const auto& tx : extra_txs) { block.vtx.push_back(tx); } ``` we can probably use `vector::insert` for that append instead of spelling out an equivalent `push_back` loop in the helper: ```C++ block.vtx.insert(block.vtx.end(), extra_txs.begin(), extra_txs.end()); ```
l0rinc (Migrated from github.com) commented 2026-05-15 11:45:38 +00:00

Why is this needed exactly? Wouldn't a bench.warmup(1) achieve the same? That would also allow us to define bal inside:

bench.warmup(1).minEpochIterations(128).run([&] {
    const auto bal{GetBalance(wallet)};
    assert(bal.m_mine_trusted == expected_balance);
    assert(bal.m_mine_immature == 0);
});

Though it kinda' begs the question: don't we want to measure the uncached state at all? Is caching referring to an internal state, i.e. the first iteration being different from the rest?

Why is this needed exactly? Wouldn't a `bench.warmup(1)` achieve the same? That would also allow us to define `bal` inside: ```C++ bench.warmup(1).minEpochIterations(128).run([&] { const auto bal{GetBalance(wallet)}; assert(bal.m_mine_trusted == expected_balance); assert(bal.m_mine_immature == 0); }); ``` Though it kinda' begs the question: don't we want to measure the uncached state at all? Is caching referring to an internal state, i.e. the first iteration being different from the rest?
l0rinc (Migrated from github.com) commented 2026-05-15 10:59:09 +00:00

we could make the benchmark more stable and avoid:

〰️ WalletBalanceManySpent (Unstable with ~1.0 iters. Increase minEpochIterations to e.g. 10)

by specifying the minimum iteration count, something like:

    bench.minEpochIterations(10).run([&] {
we could make the benchmark more stable and avoid: > :wavy_dash: `WalletBalanceManySpent` (Unstable with ~1.0 iters. Increase `minEpochIterations` to e.g. 10) by specifying the minimum iteration count, something like: ```suggestion bench.minEpochIterations(10).run([&] { ```
l0rinc (Migrated from github.com) commented 2026-05-15 11:58:34 +00:00

Is this really needed here? It walks mapWallet and invalidates per-transaction caches, while this confirmed-output balance path iterates wallet.GetTXOs(), checks spend status, and reads each remaining output value.
The benchmarks indicate the performance is also similar (except for the extra iteration):

with MarkDirty:

ns/op op/s err% total benchmark
2,927,937.88 341.54 0.3% 11.01 WalletBalanceManySpent

No MarkDirty:

ns/op op/s err% total benchmark
2,897,842.24 345.08 0.2% 11.01 WalletBalanceManySpent
Is this really needed here? It walks [mapWallet](https://github.com/bitcoin/bitcoin/blob/cad5f5604582eac95bcfbf08cca8af1c186c36eb/src/wallet/wallet.cpp#L989) and invalidates per-transaction caches, while this confirmed-output balance path iterates [wallet.GetTXOs()](https://github.com/bitcoin/bitcoin/blob/cd7865b0ce17568945c7f72db0248489cf284787/src/wallet/receive.cpp#L252), checks spend status, and reads each remaining output value. The benchmarks indicate the performance is also similar (except for the extra iteration): > with `MarkDirty`: | ns/op | op/s | err% | total | benchmark |--------------------:|--------------------:|--------:|----------:|:---------- | 2,927,937.88 | 341.54 | 0.3% | 11.01 | `WalletBalanceManySpent` > No `MarkDirty`: | ns/op | op/s | err% | total | benchmark |--------------------:|--------------------:|--------:|----------:|:---------- | 2,897,842.24 | 345.08 | 0.2% | 11.01 | `WalletBalanceManySpent`
l0rinc (Migrated from github.com) commented 2026-05-15 11:41:15 +00:00

This would still pass if setup accidentally left more spendable wallet outputs than intended.
Since the benchmark claims only the configured remainder stays unspent, could we assert the exact trusted balance?

CAmount expected_balance{0};
for (size_t i{0}; i < KEEP_UNSPENT; ++i) {
    expected_balance += OUTPUT_VALUE;
}
...
assert(bal.m_mine_trusted == expected_balance);
assert(bal.m_mine_immature == 0);
This would still pass if setup accidentally left more spendable wallet outputs than intended. Since the benchmark claims only the configured remainder stays unspent, could we assert the exact trusted balance? ```C++ CAmount expected_balance{0}; for (size_t i{0}; i < KEEP_UNSPENT; ++i) { expected_balance += OUTPUT_VALUE; } ... assert(bal.m_mine_trusted == expected_balance); assert(bal.m_mine_immature == 0); ```
l0rinc (Migrated from github.com) commented 2026-05-15 12:06:31 +00:00

My understanding is that balance alone does not prove that spent wallet outputs remain in history, consider adding a sanity check here (should probably be done via a helper method to make it less noisy):

size_t owned_outputs{0}, spent_outputs{0};
{
    LOCK(wallet.cs_wallet);
    for (const auto& [outpoint, _] : wallet.GetTXOs()) {
        ++owned_outputs;
        spent_outputs += wallet.IsSpent(outpoint);
    }
}
assert(owned_outputs == TOTAL_WALLET_OUTPUTS);
assert(spent_outputs == TOTAL_WALLET_OUTPUTS - KEEP_UNSPENT);
My understanding is that balance alone does not prove that spent wallet outputs remain in history, consider adding a sanity check here (should probably be done via a helper method to make it less noisy): ```C++ size_t owned_outputs{0}, spent_outputs{0}; { LOCK(wallet.cs_wallet); for (const auto& [outpoint, _] : wallet.GetTXOs()) { ++owned_outputs; spent_outputs += wallet.IsSpent(outpoint); } } assert(owned_outputs == TOTAL_WALLET_OUTPUTS); assert(spent_outputs == TOTAL_WALLET_OUTPUTS - KEEP_UNSPENT); ```
l0rinc (Migrated from github.com) commented 2026-05-15 12:53:26 +00:00

nit: we could initialize the fields so static analysis in my IDE stops complaining:

    uint256 prev_block_hash{};
    int64_t prev_block_time{0};
    int tip_height{0};

Just resolve if you don't think it's important.

nit: we could initialize the fields so static analysis in my IDE stops complaining: ```suggestion uint256 prev_block_hash{}; int64_t prev_block_time{0}; int tip_height{0}; ``` Just resolve if you don't think it's important.
l0rinc (Migrated from github.com) commented 2026-05-15 12:36:26 +00:00

The original code calls ActiveTip() under cs_main, but then dereferences the returned CBlockIndex* after the lock is released.
That is probably harmless for these immutable-looking fields in this benchmark, but the helper only needs a snapshot, so it seems clearer to copy the hash/time/height while holding the lock and avoid carrying the tip pointer outside the protected region.

This also avoids the ternary, which my IDE parses poorly:

inline TipBlock GetTip(const CChainParams& params, const node::NodeContext& context)
{
    {
        LOCK(::cs_main);
        if (const auto* tip{context.chainman->ActiveTip()}) {
            return {tip->GetBlockHash(), tip->GetBlockTime(), tip->nHeight};
        }
    }
    return {params.GenesisBlock().GetHash(), params.GenesisBlock().GetBlockTime(), 0};
}
The original code calls `ActiveTip()` under `cs_main`, but then dereferences the returned `CBlockIndex*` after the lock is released. That is probably harmless for these immutable-looking fields in this benchmark, but the helper only needs a snapshot, so it seems clearer to copy the hash/time/height while holding the lock and avoid carrying the tip pointer outside the protected region. This also avoids the ternary, which my IDE parses poorly: ```suggestion inline TipBlock GetTip(const CChainParams& params, const node::NodeContext& context) { { LOCK(::cs_main); if (const auto* tip{context.chainman->ActiveTip()}) { return {tip->GetBlockHash(), tip->GetBlockTime(), tip->nHeight}; } } return {params.GenesisBlock().GetHash(), params.GenesisBlock().GetBlockTime(), 0}; } ```
l0rinc (Migrated from github.com) commented 2026-05-15 12:51:28 +00:00

This may be slightly bigger unrelated change (generalizing wallet_create_tx.cpp to use our newly introduced methods), but maybe the coinbase_outputs should be exposed as a single param:

inline void GenerateFakeBlock(const CChainParams& params,
                              const node::NodeContext& context,
                              CWallet& wallet,
                              const std::vector<CTxOut>& coinbase_outputs,
                              const std::vector<CTransactionRef>& extra_txs = {})

add a helper delegating to this with the old signature:

inline void GenerateFakeBlock(const CChainParams& params,
                              const node::NodeContext& context,
                              CWallet& wallet,
                              const CScript& coinbase_script,
                              int num_coinbase_outputs,
                              CAmount total_coinbase_value = 50 * COIN,
                              const std::vector<CTransactionRef>& extra_txs = {})
{
    std::vector<CTxOut> coinbase_outputs;
    coinbase_outputs.reserve(num_coinbase_outputs);
    const CAmount per_output{total_coinbase_value / num_coinbase_outputs};
    for (int i{0}; i < num_coinbase_outputs; ++i) {
        coinbase_outputs.emplace_back(per_output, coinbase_script);
    }
    GenerateFakeBlock(params, context, wallet, coinbase_outputs, extra_txs);
}

which would enable us to call it from the benchmark's generateFakeBlock and avoid a lot of duplication between wallet_create_tx.cpp and wallet_bench_util.h.

This may be slightly bigger unrelated change (generalizing wallet_create_tx.cpp to use our newly introduced methods), but maybe the `coinbase_outputs` should be exposed as a single param: ```suggestion inline void GenerateFakeBlock(const CChainParams& params, const node::NodeContext& context, CWallet& wallet, const std::vector<CTxOut>& coinbase_outputs, const std::vector<CTransactionRef>& extra_txs = {}) ``` add a helper delegating to this with the old signature: ```C++ inline void GenerateFakeBlock(const CChainParams& params, const node::NodeContext& context, CWallet& wallet, const CScript& coinbase_script, int num_coinbase_outputs, CAmount total_coinbase_value = 50 * COIN, const std::vector<CTransactionRef>& extra_txs = {}) { std::vector<CTxOut> coinbase_outputs; coinbase_outputs.reserve(num_coinbase_outputs); const CAmount per_output{total_coinbase_value / num_coinbase_outputs}; for (int i{0}; i < num_coinbase_outputs; ++i) { coinbase_outputs.emplace_back(per_output, coinbase_script); } GenerateFakeBlock(params, context, wallet, coinbase_outputs, extra_txs); } ``` which would enable us to call it from the benchmark's `generateFakeBlock` and avoid a lot of duplication between `wallet_create_tx.cpp` and `wallet_bench_util.h`.
l0rinc (Migrated from github.com) commented 2026-05-15 12:42:28 +00:00

Do we need to reread the active tip here or could we do it in the previous locked scope instead?

    CBlockIndex* pindex{nullptr};
    {
        LOCK(::cs_main);
        pindex = context.chainman->m_blockman.AddToBlockIndex(block, context.chainman->m_best_header);
        context.chainman->ActiveChain().SetTip(*pindex);
    }
Do we need to reread the active tip here or could we do it in the previous locked scope instead? ```suggestion CBlockIndex* pindex{nullptr}; { LOCK(::cs_main); pindex = context.chainman->m_blockman.AddToBlockIndex(block, context.chainman->m_best_header); context.chainman->ActiveChain().SetTip(*pindex); } ```
w0xlt (Migrated from github.com) reviewed 2026-05-22 02:06:02 +00:00
w0xlt (Migrated from github.com) commented 2026-05-22 02:06:02 +00:00

Thanks. Done

Thanks. Done
w0xlt (Migrated from github.com) reviewed 2026-05-22 02:06:09 +00:00
w0xlt (Migrated from github.com) commented 2026-05-22 02:06:09 +00:00

Thanks. Done

Thanks. Done
w0xlt (Migrated from github.com) reviewed 2026-05-22 02:06:16 +00:00
w0xlt (Migrated from github.com) commented 2026-05-22 02:06:16 +00:00

Thanks. Done

Thanks. Done
w0xlt (Migrated from github.com) reviewed 2026-05-22 02:06:23 +00:00
w0xlt (Migrated from github.com) commented 2026-05-22 02:06:23 +00:00

Thanks. Done

Thanks. Done
w0xlt (Migrated from github.com) reviewed 2026-05-22 02:06:30 +00:00
w0xlt (Migrated from github.com) commented 2026-05-22 02:06:30 +00:00

Thanks. Done

Thanks. Done
w0xlt (Migrated from github.com) reviewed 2026-05-22 02:06:36 +00:00
w0xlt (Migrated from github.com) commented 2026-05-22 02:06:36 +00:00

Thanks. Done

Thanks. Done
w0xlt (Migrated from github.com) reviewed 2026-05-22 02:06:57 +00:00
w0xlt (Migrated from github.com) commented 2026-05-22 02:06:57 +00:00

Thanks. Done

Thanks. Done
w0xlt (Migrated from github.com) reviewed 2026-05-22 02:07:04 +00:00
w0xlt (Migrated from github.com) commented 2026-05-22 02:07:04 +00:00

Thanks. Done

Thanks. Done
w0xlt (Migrated from github.com) reviewed 2026-05-22 02:07:26 +00:00
w0xlt (Migrated from github.com) commented 2026-05-22 02:07:26 +00:00

Thanks. Done

Thanks. Done
w0xlt (Migrated from github.com) reviewed 2026-05-22 02:07:36 +00:00
w0xlt (Migrated from github.com) commented 2026-05-22 02:07:36 +00:00

Thanks. Done

Thanks. Done
w0xlt (Migrated from github.com) reviewed 2026-05-22 02:07:46 +00:00
w0xlt (Migrated from github.com) commented 2026-05-22 02:07:46 +00:00

Thanks. Done

Thanks. Done
w0xlt (Migrated from github.com) reviewed 2026-05-22 02:07:52 +00:00
w0xlt (Migrated from github.com) commented 2026-05-22 02:07:52 +00:00

Thanks. Done

Thanks. Done
w0xlt (Migrated from github.com) reviewed 2026-05-22 02:07:59 +00:00
w0xlt (Migrated from github.com) commented 2026-05-22 02:07:59 +00:00

Thanks. Done

Thanks. Done
w0xlt (Migrated from github.com) reviewed 2026-05-22 02:08:05 +00:00
w0xlt (Migrated from github.com) commented 2026-05-22 02:08:05 +00:00

Thanks. Done

Thanks. Done
w0xlt (Migrated from github.com) reviewed 2026-05-22 02:08:12 +00:00
w0xlt (Migrated from github.com) commented 2026-05-22 02:08:12 +00:00

Thanks. Done

Thanks. Done
w0xlt (Migrated from github.com) reviewed 2026-05-22 02:08:21 +00:00
w0xlt (Migrated from github.com) commented 2026-05-22 02:08:21 +00:00

Thanks. Done

Thanks. Done
w0xlt (Migrated from github.com) reviewed 2026-05-22 02:08:28 +00:00
w0xlt (Migrated from github.com) commented 2026-05-22 02:08:28 +00:00

Thanks. Done

Thanks. Done
w0xlt commented 2026-05-22 02:10:26 +00:00 (Migrated from github.com)

@l0rinc Thanks for the thorough review. I split the changes into two commits to make them easier to review, and added you as a co-author on both since many of the improvements came from your suggestions.

@l0rinc Thanks for the thorough review. I split the changes into two commits to make them easier to review, and added you as a co-author on both since many of the improvements came from your suggestions.
w0xlt commented 2026-05-22 02:17:32 +00:00 (Migrated from github.com)

I've re-run this benchmark to validate bitcoin/bitcoin#27865, which changes how wallet TXOs are retained for balance calculation.

Command used:

build/bin/bench_bitcoin -filter=WalletBalanceManySpent -min-time=10000

Results:

branch median notes
current master 8,861,448 ns/op higher variance in this run, ~17% error
#27865 2,973 ns/op lower variance in this run, ~0.8% error

This is about a 2,981x speedup with #27865 for this workload.

The benchmark's purpose is to model a wallet with many spent TXOs and only a few unspent TXOs, then measure GetBalance(). On current master, the balance path still has to deal with the large spent-output history.

With #27865, the balance path only sees the relevant unspent outputs, which is the performance improvement this benchmark is intended to demonstrate.

I've re-run this benchmark to validate bitcoin/bitcoin#27865, which changes how wallet TXOs are retained for balance calculation. Command used: ```bash build/bin/bench_bitcoin -filter=WalletBalanceManySpent -min-time=10000 ``` Results: | branch | median | notes | | -- | --: | -- | | current master | 8,861,448 ns/op | higher variance in this run, ~17% error | | #27865 | 2,973 ns/op | lower variance in this run, ~0.8% error | This is about a **2,981x speedup** with #27865 for this workload. The benchmark's purpose is to model a wallet with many spent TXOs and only a few unspent TXOs, then measure `GetBalance()`. On current master, the balance path still has to deal with the large spent-output history. With #27865, the balance path only sees the relevant unspent outputs, which is the performance improvement this benchmark is intended to demonstrate.
w0xlt commented 2026-05-22 02:22:24 +00:00 (Migrated from github.com)

@w0xlt can you rebase this?

@sedited Done.

> @w0xlt can you rebase this? @sedited Done.
l0rinc (Migrated from github.com) reviewed 2026-05-22 15:15:14 +00:00
l0rinc (Migrated from github.com) commented 2026-05-22 15:15:14 +00:00

Does minEpochIterations(128) addresses benchmark stability better than the suggested 10?

Does `minEpochIterations(128)` addresses benchmark stability better than the suggested 10?
l0rinc (Migrated from github.com) reviewed 2026-05-22 15:17:26 +00:00
l0rinc (Migrated from github.com) commented 2026-05-22 15:17:26 +00:00

nit: Is this meant to support running the benchmark on top of #27865?
On this PR’s current base the else branch should be dead code, so a short comment explaining the forward-compatibility case would help.

nit: Is this meant to support running the benchmark on top of #27865? On this PR’s current base the `else` branch should be dead code, so a short comment explaining the forward-compatibility case would help.
l0rinc commented 2026-05-22 15:20:14 +00:00 (Migrated from github.com)

ACK 5defb96252e0b955d1a3863f78a87ca064d9071a

Thanks for taking the suggestions. I see you've made it forward-compatible - I'm usually more strict about adding dead code, but in this case I personally don't mind. If you touch this again, either remove it and let the other PR extend the benchmark (it likely needs other changes anyway) or add a comment explaining it. I'm also fine with just adding a note to the PR's description.

ACK 5defb96252e0b955d1a3863f78a87ca064d9071a Thanks for taking the suggestions. I see you've made it forward-compatible - I'm usually more strict about adding dead code, but in this case I personally don't mind. If you touch this again, either remove it and let the other PR extend the benchmark (it likely needs other changes anyway) or add a comment explaining it. I'm also fine with just adding a note to the PR's description.
DrahtBot commented 2026-06-15 14:29:52 +00:00 (Migrated from github.com)

🐙 This pull request conflicts with the target branch and needs rebase.

<!--cf906140f33d8803c4a75a2196329ecb--> 🐙 This pull request conflicts with the target branch and [needs rebase](https://github.com/bitcoin/bitcoin/blob/master/CONTRIBUTING.md#rebasing-changes).
sedited commented 2026-08-10 19:34:39 +00:00 (Migrated from github.com)

Ping @w0xlt for a rebase.

Ping @w0xlt for a rebase.
w0xlt commented 2026-08-18 22:48:41 +00:00 (Migrated from github.com)

Rebased. Thanks @sedited

Rebased. Thanks @sedited
DrahtBot commented 2026-08-19 00:13:37 +00:00 (Migrated from github.com)

🚧 At least one of the CI tasks failed.
Task iwyu: https://github.com/bitcoin/bitcoin/actions/runs/32194375855/job/95895267053
LLM reason (✨ experimental): CI failed because IWYU reported/fixed noncompliant headers (#includes changes were needed), triggering a “Failure generated from IWYU” error.

Hints

Try to run the tests locally, according to the documentation. However, a CI failure may still
happen due to a number of reasons, for example:

  • Possibly due to a silent merge conflict (the changes in this pull request being
    incompatible with the current code in the target branch). If so, make sure to rebase on the latest
    commit of the target branch.

  • A sanitizer issue, which can only be found by compiling with the sanitizer and running the
    affected test.

  • An intermittent issue.

Leave a comment here, if you need help tracking down a confusing failure.

<!--85328a0da195eb286784d51f73fa0af9--> 🚧 At least one of the CI tasks failed. <sub>Task `iwyu`: https://github.com/bitcoin/bitcoin/actions/runs/32194375855/job/95895267053</sub> <sub>LLM reason (✨ experimental): CI failed because IWYU reported/fixed noncompliant headers (#includes changes were needed), triggering a “Failure generated from IWYU” error.</sub> <details><summary>Hints</summary> Try to run the tests locally, according to the documentation. However, a CI failure may still happen due to a number of reasons, for example: * Possibly due to a silent merge conflict (the changes in this pull request being incompatible with the current code in the target branch). If so, make sure to rebase on the latest commit of the target branch. * A sanitizer issue, which can only be found by compiling with the sanitizer and running the affected test. * An intermittent issue. Leave a comment here, if you need help tracking down a confusing failure. </details>
DrahtBot commented 2026-08-26 14:23:47 +00:00 (Migrated from github.com)

Could turn into draft while CI is red?

Could turn into draft while CI is red?
DrahtBot commented 2026-09-09 11:51:05 +00:00 (Migrated from github.com)

🐙 This pull request conflicts with the target branch and needs rebase.

<!--cf906140f33d8803c4a75a2196329ecb--> 🐙 This pull request conflicts with the target branch and [needs rebase](https://github.com/bitcoin/bitcoin/blob/master/CONTRIBUTING.md#rebasing-changes).
w0xlt commented 2026-09-22 21:02:15 +00:00 (Migrated from github.com)

Rebased.

Rebased.
First-time contributor

No verified findings are available from this review.

Review coverage was incomplete.


Reviewed: bc9a71bfc729 · Full review report · Previous reports

<!-- forgejo-review-bot:bitcoin/bitcoin --> <!-- ralph-engine:current:6f232c871bca65facadc248ad7ecd634f87b0b5f6936bc30593af890589888f1:0cfbbc826fdd30e42f35c9a5b7d389c0902089c94f2400654bb32123e69823f6 --> <!-- ralph-base:6ed5aad06111177c39f9b9f07a52634476380ae1 --> <!-- ralph-head:bc9a71bfc729601e2f18a14f0e41853dfc643d96 --> <!-- ralph-case:e5250267c141413070861e92e5b3154ce4598203d896529644c182497afcc96c --> No verified findings are available from this review. Review coverage was incomplete. <!-- Review tier: routine --> --- Reviewed: [`bc9a71bfc729`](<https://git.fish.foo/bitcoin/bitcoin/commit/bc9a71bfc729601e2f18a14f0e41853dfc643d96>) · [Full review report](<https://review.fish.foo/traces/34360-bc9a71bfc729601e2f18a14f0e41853dfc643d96-1739-2.html>) · [Previous reports](<https://review.fish.foo/traces/34360/>)
l0rinc (Migrated from github.com) requested changes 2026-10-07 11:25:19 +00:00
l0rinc (Migrated from github.com) commented 2026-10-07 11:22:30 +00:00

I have changed my mind on this: since we don't know which direction follow-ups will take, could we rather simplify this to the assertions needed on the current base?
We can adapt them freely in a future PR if needed.

Related: Ralph's review also flags this branch. (cc: @maflcko / @willcl-ark how do we trigger @DrahtBot to update the reply?)

Simplify the output-state assertions
diff --git a/src/bench/wallet_balance.cpp b/src/bench/wallet_balance.cpp
index bfcddfc5b1..f1bed5d166 100644
--- a/src/bench/wallet_balance.cpp
+++ b/src/bench/wallet_balance.cpp
@@ -187,12 +187,8 @@ static void WalletBalanceManySpent(benchmark::Bench& bench)
             spent_outputs += wallet.IsSpent(outpoint);
         }
     }
-    if (owned_outputs == TOTAL_WALLET_OUTPUTS) {
-        assert(spent_outputs == TOTAL_WALLET_OUTPUTS - KEEP_UNSPENT);
-    } else {
-        assert(owned_outputs == KEEP_UNSPENT);
-        assert(spent_outputs == 0);
-    }
+    assert(owned_outputs == TOTAL_WALLET_OUTPUTS);
+    assert(spent_outputs == TOTAL_WALLET_OUTPUTS - KEEP_UNSPENT);
 
     CAmount expected_balance{0};
     for (size_t i{0}; i < KEEP_UNSPENT; ++i) {
I have changed my mind on this: since we don't know which direction follow-ups will take, could we rather simplify this to the assertions needed on the current base? We can adapt them freely in a future PR if needed. Related: [Ralph's review](https://git.fish.foo/bitcoin/bitcoin/pulls/34360#author-ralph) also flags this branch. (cc: @maflcko / @willcl-ark how do we trigger @DrahtBot to update the reply?) <details> <summary>Simplify the output-state assertions</summary> ```diff diff --git a/src/bench/wallet_balance.cpp b/src/bench/wallet_balance.cpp index bfcddfc5b1..f1bed5d166 100644 --- a/src/bench/wallet_balance.cpp +++ b/src/bench/wallet_balance.cpp @@ -187,12 +187,8 @@ static void WalletBalanceManySpent(benchmark::Bench& bench) spent_outputs += wallet.IsSpent(outpoint); } } - if (owned_outputs == TOTAL_WALLET_OUTPUTS) { - assert(spent_outputs == TOTAL_WALLET_OUTPUTS - KEEP_UNSPENT); - } else { - assert(owned_outputs == KEEP_UNSPENT); - assert(spent_outputs == 0); - } + assert(owned_outputs == TOTAL_WALLET_OUTPUTS); + assert(spent_outputs == TOTAL_WALLET_OUTPUTS - KEEP_UNSPENT); CAmount expected_balance{0}; for (size_t i{0}; i < KEEP_UNSPENT; ++i) { ``` </details>
maflcko (Migrated from github.com) reviewed 2026-10-07 12:16:59 +00:00
maflcko (Migrated from github.com) commented 2026-10-07 12:16:59 +00:00

Related: Ralph's review also flags this branch. (cc: @maflcko / @willcl-ark how do we trigger @DrahtBot to update the reply?)

The summary is only updated when a comment is added or edited, see github.com/maflcko/DrahtBot@7c658efafe/webhook_features/src/features/summary_comment.rs (L28-L32)

Maybe there can be a manual one-time trigger for all pull requests, if you think an updated comment is important?

> Related: [Ralph's review](https://git.fish.foo/bitcoin/bitcoin/pulls/34360#author-ralph) also flags this branch. (cc: @maflcko / @willcl-ark how do we trigger @DrahtBot to update the reply?) The summary is only updated when a comment is added or edited, see https://github.com/maflcko/DrahtBot/blob/7c658efafe394b4b7629053b582bc13df92b10aa/webhook_features/src/features/summary_comment.rs#L28-L32 Maybe there can be a manual one-time trigger for all pull requests, if you think an updated comment is important?
l0rinc (Migrated from github.com) reviewed 2026-10-07 12:42:39 +00:00
l0rinc (Migrated from github.com) commented 2026-10-07 12:42:39 +00:00

Wasn't there an option before to add a thumbs down emoji when we need an update?

Wasn't there an option before to add a thumbs down emoji when we need an update?
maflcko (Migrated from github.com) reviewed 2026-10-07 13:07:09 +00:00
maflcko (Migrated from github.com) commented 2026-10-07 13:07:09 +00:00

Wasn't there an option before to add a thumbs down emoji when we need an update?

No, there was only an option to react on the summary comment to have it act on the next update (github.com/maflcko/DrahtBot@207fb31abd). I think it is enough to have the update path on comment creation or edits, but I can re-trigger it manually globally, if needed.

> Wasn't there an option before to add a thumbs down emoji when we need an update? No, there was only an option to react on the summary comment to have it act on the *next* update (https://github.com/maflcko/DrahtBot/commit/207fb31abdf520829e5ea7395db8777ac6aeb5f5). I think it is enough to have the update path on comment creation or edits, but I can re-trigger it manually globally, if needed.
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
bitcoin/bitcoin!34360
No description provided.