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 +1 −7
  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 rkrux
    Stale ACK maflcko, furszy

    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


    maflcko commented at 5:13 pm on December 3, 2025:
    @ANtutov are you still working on this?

    rkrux commented at 6:14 pm on December 3, 2025:

    Sorry for the late reply. I don’t fully understand this comment though: #33962 (review)

    I suggested to remove this variable because the if condition below could be managed by the wait_callback and node.validation_signals properties directly and specially setting the callback_set variable in an if block above that doesn’t do anything else now seemed unnecessary to me.


    maflcko commented at 7:24 pm on December 3, 2025:

    in an if block above that doesn’t do anything else now seemed unnecessary to me.

    What the if-else block does is explained right after the if:

    0        if (auto mempool_tx = node.mempool->get(txid); mempool_tx) {
    1            // There's already a transaction in the mempool with this txid.
    

    rkrux commented at 7:36 pm on December 3, 2025:

    Ah, there’s another if above on line 66: https://github.com/bitcoin/bitcoin/blob/9a29b2d331eed5b4cbd6922f63e397b68ff12447/src/node/transaction.cpp#L66

    I had missed that, good catch. I see now what you mean.

    Setting callback_set in the else block seems reasonable. This suggestion can be reverted: #33962 (review).


    ANtutov commented at 7:36 am on December 4, 2025:

    @ANtutov are you still working on this?

    I’m sorry for the delay, had some problems with laptop, gonna correct


    maflcko commented at 4:35 pm on December 4, 2025:
    Please just push the prior exact commit hash.

    rkrux commented at 9:49 am on December 10, 2025:

    ANtutov commented at 11:49 am on December 10, 2025:

    This one to be precise: d09e930

    I’m grateful to you for this

  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. ANtutov force-pushed on Nov 28, 2025
  12. DrahtBot removed the label CI failed on Nov 28, 2025
  13. furszy commented at 9:26 pm on November 28, 2025: member
    ACK d56718838308c474cd73930ee276f1be7334dd68
  14. DrahtBot requested review from maflcko on Nov 28, 2025
  15. DrahtBot requested review from rkrux on Nov 28, 2025
  16. rkrux approved
  17. rkrux commented at 8:14 am on November 29, 2025: contributor
    Edit: removed a-c-k in light of #33962 (review)
  18. DrahtBot requested review from rkrux on Dec 3, 2025
  19. ANtutov force-pushed on Dec 4, 2025
  20. refactor: replace manual promise with SyncWithValidationInterfaceQueue e71c4df168
  21. ANtutov force-pushed on Dec 10, 2025
  22. rkrux approved
  23. rkrux commented at 12:24 pm on December 10, 2025: contributor

    lgtm ACK e71c4df1685131f5ab48aac6ccb07ac944e91e9f

    Sorry for causing some confusion earlier.

  24. DrahtBot requested review from furszy on Dec 10, 2025
  25. ANtutov commented at 5:35 pm on December 10, 2025: none

    lgtm ACK e71c4df

    Sorry for causing some confusion earlier.

    I’m grateful to you cause i was confused a bit


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: 2026-01-02 00:13 UTC

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