log: mempool: log removal reason in validation interface #26419

pull jamesob wants to merge 1 commits into bitcoin:master from jamesob:2022-10-log-mempool-removal-reason changing 3 files +21 −2
  1. jamesob commented at 0:12 am on October 29, 2022: member

    Currently the exact reason a transaction is removed from the mempool isn’t logged. It is sometimes detectable from context, but adding the reason to the validation interface logs (where it is already passed) seems like an easy way to disambiguate.

    For example in the case of mempool expiry, the logs look like this:

    0[validationinterface.cpp:220] [TransactionRemovedFromMempool] [validation] Enqueuing TransactionRemovedFromMempool: txid=<txid> wtxid=<wtxid>
    1[txmempool.cpp:1050] [RemoveUnbroadcastTx] [mempool] Removed <txid> from set of unbroadcast txns before confirmation that txn was sent out
    2[validationinterface.cpp:220] [operator()] [validation] TransactionRemovedFromMempool: txid=<txid> wtxid=<wtxid>
    3[validation.cpp:267] [LimitMempoolSize] [mempool] Expired 1 transactions from the memory pool
    

    There is no context-free way to know $txid was evicted on the basis of expiry. This change will make that case (and probably others) clear.

  2. DrahtBot added the label Utils/log/libs on Oct 29, 2022
  3. 0xB10C commented at 10:05 am on October 30, 2022: contributor
    Concept ACK!
  4. jamesob force-pushed on Nov 3, 2022
  5. in src/txmempool.cpp:1243 in d76405729d outdated
    1237+        case MemPoolRemovalReason::REORG: return "reorg";
    1238+        case MemPoolRemovalReason::BLOCK: return "block";
    1239+        case MemPoolRemovalReason::CONFLICT: return "conflict";
    1240+        case MemPoolRemovalReason::REPLACED: return "replaced";
    1241+    }
    1242+    return "unknown";
    


    stickies-v commented at 4:37 pm on November 3, 2022:

    Any downside to using Assert instead so we have better observability when this fn goes out of sync with MemPoolRemovalReason?

    0    Assert(false);
    

    jamesob commented at 6:17 pm on November 3, 2022:
    We have to add a return to avoid CI failures, but I think that assert is a great idea. Will add.
  6. stickies-v commented at 6:02 pm on November 3, 2022: contributor

    Approach ACK d76405729d2cc369437af798ff1962e7bd481dde

    Better logging is always worthwhile.

  7. jamesob force-pushed on Nov 3, 2022
  8. in src/txmempool.cpp:1243 in f26105859f outdated
    1238+        case MemPoolRemovalReason::BLOCK: return "block";
    1239+        case MemPoolRemovalReason::CONFLICT: return "conflict";
    1240+        case MemPoolRemovalReason::REPLACED: return "replaced";
    1241+    }
    1242+    Assert(false);
    1243+    return "unknown";
    


    maflcko commented at 6:27 pm on November 3, 2022:
    0    assert(false);
    

    nit: This should be shorter and pass CI


    jamesob commented at 6:39 pm on November 3, 2022:
    Let’s give it a whirl
  9. jamesob force-pushed on Nov 3, 2022
  10. stickies-v commented at 7:46 pm on November 3, 2022: contributor
  11. jamesob force-pushed on Nov 3, 2022
  12. stickies-v approved
  13. stickies-v commented at 10:14 pm on November 3, 2022: contributor
    ACK f58c3a4
  14. DrahtBot commented at 11:36 am on November 4, 2022: contributor

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

    Conflicts

    Reviewers, this pull request conflicts with the following ones:

    • #26152 (Bump unconfirmed ancestor transactions to target feerate by Xekyo)

    If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first.

  15. log: mempool: log removal reason in validation interface
    Currently the exact reason a transaction is removed from the mempool isn't
    logged. It is sometimes detectable from context, but adding the `reason` to
    the validation interface logs (where it is already passed) seems like an easy
    way to disambiguate.
    
    For example, in the case of mempool expiry, the logs look like this:
    
    ```
    [validationinterface.cpp:220] [TransactionRemovedFromMempool] [validation] Enqueuing TransactionRemovedFromMempool: txid=<txid> wtxid=<wtxid>
    [txmempool.cpp:1050] [RemoveUnbroadcastTx] [mempool] Removed <txid> from set of unbroadcast txns before confirmation that txn was sent out
    [validationinterface.cpp:220] [operator()] [validation] TransactionRemovedFromMempool: txid=<txid> wtxid=<wtxid>
    [validation.cpp:267] [LimitMempoolSize] [mempool] Expired 1 transactions from the memory pool
    ```
    
    There is no context-free way to know $txid was evicted on the basis of expiry.
    This change will make that case (and probably others) clear.
    25ef049d60
  16. in src/validationinterface.h:23 in f58c3a47f8 outdated
    19@@ -20,6 +20,7 @@ struct CBlockLocator;
    20 class CValidationInterface;
    21 class CScheduler;
    22 enum class MemPoolRemovalReason;
    23+const std::string RemovalReasonToString(const MemPoolRemovalReason& r) noexcept;
    


    0xB10C commented at 12:50 pm on November 4, 2022:

    This spews a bunch of redundant-decls warnings when compiling for me. I tried dropping it, but that doesn’t work.

     0In file included from ./validation.h:28,
     1                 from ./rpc/blockchain.h:13,
     2                 from rest.cpp:19:
     3./txmempool.h:358:19: warning: redundant redeclaration of const string RemovalReasonToString(const MemPoolRemovalReason&) in same scope [-Wredundant-decls]
     4  358 | const std::string RemovalReasonToString(const MemPoolRemovalReason& r) noexcept;
     5      |                   ^~~~~~~~~~~~~~~~~~~~~
     6In file included from ./index/base.h:11,
     7                 from ./index/blockfilterindex.h:12,
     8                 from rest.cpp:13:
     9./validationinterface.h:23:19: note: previous declaration of const string RemovalReasonToString(const MemPoolRemovalReason&)
    10   23 | const std::string RemovalReasonToString(const MemPoolRemovalReason& r) noexcept;
    11      |                   ^~~~~~~~~~~~~~~~~~~~~
    12  CXX      rpc/libbitcoin_node_a-net.o
    13In file included from ./index/base.h:11,
    14                 from ./index/blockfilterindex.h:12,
    15                 from rpc/blockchain.cpp:20:
    16./validationinterface.h:23:19: warning: redundant redeclaration of const string RemovalReasonToString(const MemPoolRemovalReason&) in same scope [-Wredundant-decls]
    17   23 | const std::string RemovalReasonToString(const MemPoolRemovalReason& r) noexcept;
    18      |                   ^~~~~~~~~~~~~~~~~~~~~
    19In file included from ./validation.h:28,
    20                 from ./rpc/blockchain.h:13,
    21                 from rpc/blockchain.cpp:6:
    22./txmempool.h:358:19: note: previous declaration of const string RemovalReasonToString(const MemPoolRemovalReason&)
    23  358 | const std::string RemovalReasonToString(const MemPoolRemovalReason& r) noexcept;
    24      |                   ^~~~~~~~~~~~~~~~~~~~~
    25  CXX      rpc/libbitcoin_node_a-node.o
    26In file included from rpc/mining.cpp:38:
    27./validationinterface.h:23:19: warning: redundant redeclaration of const string RemovalReasonToString(const MemPoolRemovalReason&) in same scope [-Wredundant-decls]
    28   23 | const std::string RemovalReasonToString(const MemPoolRemovalReason& r) noexcept;
    29      |                   ^~~~~~~~~~~~~~~~~~~~~
    30In file included from ./node/miner.h:10,
    31                 from rpc/mining.cpp:19:
    32./txmempool.h:358:19: note: previous declaration of const string RemovalReasonToString(const MemPoolRemovalReason&)
    33  358 | const std::string RemovalReasonToString(const MemPoolRemovalReason& r) noexcept;
    34      |                   ^~~~~~~~~~~~~~~~~~~~~
    35  CXX      rpc/libbitcoin_node_a-output_script.o
    36In file included from ./validation.h:28,
    37                 from ./rpc/blockchain.h:13,
    38                 from rpc/net.cpp:18:
    39./txmempool.h:358:19: warning: redundant redeclaration of const string RemovalReasonToString(const MemPoolRemovalReason&) in same scope [-Wredundant-decls]
    40  358 | const std::string RemovalReasonToString(const MemPoolRemovalReason& r) noexcept;
    41      |                   ^~~~~~~~~~~~~~~~~~~~~
    42In file included from ./net_processing.h:10,
    43                 from rpc/net.cpp:13:
    44./validationinterface.h:23:19: note: previous declaration of const string RemovalReasonToString(const MemPoolRemovalReason&)
    45   23 | const std::string RemovalReasonToString(const MemPoolRemovalReason& r) noexcept;
    46      |                   ^~~~~~~~~~~~~~~~~~~~~
    47  CXX      rpc/libbitcoin_node_a-rawtransaction.o
    48  CXX      rpc/libbitcoin_node_a-server.o
    49...
    

    0xB10C commented at 1:02 pm on November 4, 2022:
    with gcc 11.3.0 and -Wredundant-decls in CXXFLAGS

    0xB10C commented at 1:10 pm on November 4, 2022:
    ~no warnings with gcc 10.3.0~ nvm warnings with gcc 10.3.0 too
  17. jamesob force-pushed on Nov 4, 2022
  18. jamesob commented at 1:39 pm on November 4, 2022: member
    @0xB10C ah, thanks for testing with gcc. Pushed a fix.
  19. 0xB10C commented at 2:55 pm on November 4, 2022: contributor

    ACK 25ef049d60535ac02508ba71ef60f17d8349f120

    Reviewed changes, built, and manually tested that the correct reason appears in the debug.logs of the regtest nodes spawned by the mempool_expiry.py and mempool_limit.py functional tests.

  20. josibake commented at 2:58 pm on November 4, 2022: member

    Concept ACK

    will review in depth later today!

  21. maflcko merged this on Nov 5, 2022
  22. maflcko closed this on Nov 5, 2022

  23. sidhujag referenced this in commit c9ab68b078 on Nov 6, 2022
  24. bitcoin locked this on Nov 5, 2023

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: 2024-10-31 03:12 UTC

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