refactor: replace manual promise with SyncWithValidationInterfaceQueue #33962

pull ANtutov wants to merge 1 commits into bitcoin:master from ANtutov:refactor/broadcast-tx-sync-without-promise changing 1 files +10 −21
  1. ANtutov commented at 4:12 pm on November 27, 2025: none
    BroadcastTransaction() now waits for validation callbacks using the built-in validation_signals>SyncWithValidationInterfaceQueue() instead of creating a local std::promise and scheduling a lambda. This removes an unnecessary allocation and uses the canonical API.
  2. DrahtBot added the label Refactoring on Nov 27, 2025
  3. DrahtBot commented at 4:12 pm on November 27, 2025: contributor

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

    Code Coverage & Benchmarks

    For details see: https://corecheck.dev/bitcoin/bitcoin/pulls/33962.

    Reviews

    See the guideline for information on the review process.

    Type Reviewers
    ACK furszy, rkrux
    Stale ACK maflcko

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

  4. maflcko commented at 4:29 pm on November 27, 2025: member
    lgtm ACK d09e9306cab86c0917cc0ae198ef1993d764d106
  5. in src/node/transaction.cpp:115 in d09e9306ca
    111@@ -115,9 +112,6 @@ TransactionError BroadcastTransaction(NodeContext& node,
    112                 // with a transaction to/from their wallet, immediately call some
    113                 // wallet RPC, and get a stale result because callbacks have not
    114                 // yet been processed.
    115-                node.validation_signals->CallFunctionInValidationInterfaceQueue([&promise] {
    116-                    promise.set_value();
    117-                });
    118                 callback_set = true;
    


    rkrux commented at 10:39 am on November 28, 2025:

    Nit: The callback_set variable seems unnecessary now.

     0diff --git a/src/node/transaction.cpp b/src/node/transaction.cpp
     1index 05450299e5..0b6213f7fd 100644
     2--- a/src/node/transaction.cpp
     3+++ b/src/node/transaction.cpp
     4@@ -45,7 +45,6 @@ TransactionError BroadcastTransaction(NodeContext& node,
     5 
     6     Txid txid = tx->GetHash();
     7     Wtxid wtxid = tx->GetWitnessHash();
     8-    bool callback_set = false;
     9 
    10     {
    11         LOCK(cs_main);
    12@@ -102,22 +101,19 @@ TransactionError BroadcastTransaction(NodeContext& node,
    13                 }
    14                 break;
    15             }
    16-
    17-            if (wait_callback && node.validation_signals) {
    18-                // For transactions broadcast from outside the wallet, make sure
    19-                // that the wallet has been notified of the transaction before
    20-                // continuing.
    21-                //
    22-                // This prevents a race where a user might call sendrawtransaction
    23-                // with a transaction to/from their wallet, immediately call some
    24-                // wallet RPC, and get a stale result because callbacks have not
    25-                // yet been processed.
    26-                callback_set = true;
    27-            }
    28         }
    29     } // cs_main
    30 
    31-    if (callback_set) {
    32+    if (wait_callback && node.validation_signals) {
    33+        // For transactions broadcast from outside the wallet, make sure
    34+        // that the wallet has been notified of the transaction before
    35+        // continuing.
    36+        //
    37+        // This prevents a race where a user might call sendrawtransaction
    38+        // with a transaction to/from their wallet, immediately call some
    39+        // wallet RPC, and get a stale result because callbacks have not
    40+        // yet been processed.
    41+
    42         // Wait until Validation Interface clients have been notified of the
    43         // transaction entering the mempool.
    44         node.validation_signals->SyncWithValidationInterfaceQueue();
    

    maflcko commented at 1:48 pm on December 1, 2025:

    Nit: The callback_set variable seems unnecessary now.

    Why would it be unnecessary now? Sure, it is harmless to call SyncWithValidationInterfaceQueue when the tx is in the mempool, but this will need to be mentioned

  6. rkrux commented at 10:40 am on November 28, 2025: contributor

    ACK d09e9306cab86c0917cc0ae198ef1993d764d106

    Looks fine, this function doc highlights the similarity:

    https://github.com/bitcoin/bitcoin/blob/808f1d972be35f4c66bdc30ab0f4064dab0c43c0/src/validationinterface.h#L208-L217

  7. fanquake commented at 4:22 pm on November 28, 2025: member
  8. ANtutov force-pushed on Nov 28, 2025
  9. DrahtBot added the label CI failed on Nov 28, 2025
  10. DrahtBot commented at 4:30 pm on November 28, 2025: contributor

    🚧 At least one of the CI tasks failed. Task lint: https://github.com/bitcoin/bitcoin/actions/runs/19769125602/job/56649201966 LLM reason (✨ experimental): CI failed due to trailing whitespace detected by lint in src/node/transaction.cpp.

    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.

  11. refactor: replace manual promise with SyncWithValidationInterfaceQueue d567188383
  12. ANtutov force-pushed on Nov 28, 2025
  13. DrahtBot removed the label CI failed on Nov 28, 2025
  14. furszy commented at 9:26 pm on November 28, 2025: member
    ACK d56718838308c474cd73930ee276f1be7334dd68
  15. DrahtBot requested review from maflcko on Nov 28, 2025
  16. DrahtBot requested review from rkrux on Nov 28, 2025
  17. rkrux approved
  18. rkrux commented at 8:14 am on November 29, 2025: contributor
    lgtm ACK d567188

github-metadata-mirror

This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2025-12-01 21:13 UTC

This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me