net: Use log categories when logging events that P2P peers can trigger arbitrarily #17828

pull practicalswift wants to merge 1 commits into bitcoin:master from practicalswift:log-categories changing 2 files +12 −5
  1. practicalswift commented at 9:45 pm on December 29, 2019: contributor

    Use log categories when logging events that P2P peers can trigger arbitrarily.

    Rationale similar to that of PR #17762 (net: Log to net category for exceptions in ProcessMessages):

    It is not good to panick end users with verbose errors (let alone writing to stderr) when any peer can generate them.

  2. fanquake added the label P2P on Dec 29, 2019
  3. fanquake added the label Utils/log/libs on Dec 29, 2019
  4. hebasto commented at 9:47 pm on December 29, 2019: member
    Concept ACK.
  5. DrahtBot commented at 0:05 am on December 30, 2019: member

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

    Conflicts

    No conflicts as of last run.

  6. in src/util/system.h:56 in e148126246 outdated
    51@@ -52,6 +52,13 @@ bool error(const char* fmt, const Args&... args)
    52     return false;
    53 }
    54 
    55+template<typename... Args>
    56+bool error_debug(const BCLog::LogFlags& category, const char* fmt, const Args&... args)
    


    promag commented at 4:52 pm on January 2, 2020:
    Drop reference in 1st arg?

    practicalswift commented at 12:45 pm on January 8, 2020:
    Fixed!
  7. promag commented at 4:57 pm on January 2, 2020: member
    Concept ACK. nit, error_debug() looks strange to me.
  8. practicalswift commented at 5:25 pm on January 2, 2020: contributor
    @promag I agree the name does not feel perfect. Have any suggestions w.r.t. naming? :) I’m trying to mimic bool error(…). Perhaps bool error_with_category(…) or bool error_with_debug(…)?
  9. luke-jr referenced this in commit 721e6360df on Jan 5, 2020
  10. practicalswift force-pushed on Jan 8, 2020
  11. practicalswift commented at 12:46 pm on January 8, 2020: contributor

    Now using error_with_debug_log(…) instead of error_debug(…).

    Please re-review :)

  12. practicalswift force-pushed on Jan 10, 2020
  13. practicalswift commented at 1:45 pm on January 10, 2020: contributor
    Rebased! :)
  14. luke-jr referenced this in commit 6f2ecd96a6 on Jan 12, 2020
  15. practicalswift requested review from laanwj on Jan 14, 2020
  16. luke-jr referenced this in commit 0015578415 on Feb 9, 2020
  17. DrahtBot added the label Needs rebase on Mar 1, 2020
  18. net: Use log categories when logging events that P2P peers can trigger arbitrarily 0496062158
  19. practicalswift force-pushed on Mar 5, 2020
  20. DrahtBot removed the label Needs rebase on Mar 5, 2020
  21. in src/validation.cpp:3818 in 0496062158
    3814@@ -3815,7 +3815,7 @@ bool ProcessNewBlock(const CChainParams& chainparams, const std::shared_ptr<cons
    3815         }
    3816         if (!ret) {
    3817             GetMainSignals().BlockChecked(*pblock, state);
    3818-            return error("%s: AcceptBlock FAILED (%s)", __func__, state.ToString());
    3819+            return error_with_debug_log(BCLog::VALIDATION, "%s: AcceptBlock FAILED (%s)", __func__, state.ToString());
    


    MarcoFalke commented at 10:00 pm on March 5, 2020:
    BCLog::VALIDATION is used for the validation interface. Is the same category applicable here?

    practicalswift commented at 1:26 pm on March 6, 2020:

    I’d be happy to change but I’m not sure to which TBH: which BCLog category would be appropriate in these cases?

    FWIW, these are the location of BCLog uses in current master:

     0$ git grep -E '^ *LogPrint\(BCLog::' | tr -d " " | cut -f1 -d, | \
     1    sed 's/:LogPrint(/ /g' | sort -u | awk '{ print $2 " " $1 }' | sort -u
     2BCLog::ADDRMAN src/addrman.cpp
     3BCLog::ADDRMAN src/addrman.h
     4BCLog::BENCH src/miner.cpp
     5BCLog::BENCH src/validation.cpp
     6BCLog::CMPCTBLOCK src/blockencodings.cpp
     7BCLog::COINDB src/txdb.cpp
     8BCLog::ESTIMATEFEE src/policy/fees.cpp
     9BCLog::HTTP src/httpserver.cpp
    10BCLog::LEVELDB src/dbwrapper.cpp
    11BCLog::LIBEVENT src/httpserver.cpp
    12BCLog::MEMPOOLREJ src/net_processing.cpp
    13BCLog::MEMPOOL src/net_processing.cpp
    14BCLog::MEMPOOL src/txmempool.cpp
    15BCLog::MEMPOOL src/validation.cpp
    16BCLog::NET src/addrman.cpp
    17BCLog::NET src/banman.cpp
    18BCLog::NET src/netbase.cpp
    19BCLog::NET src/net.cpp
    20BCLog::NET src/net_processing.cpp
    21BCLog::NET src/timedata.cpp
    22BCLog::PROXY src/netbase.cpp
    23BCLog::PRUNE src/validation.cpp
    24BCLog::QT src/qt/bitcoin.cpp
    25BCLog::RAND src/random.cpp
    26BCLog::REINDEX src/validation.cpp
    27BCLog::RPC src/httprpc.cpp
    28BCLog::RPC src/init.cpp
    29BCLog::RPC src/rpc/blockchain.cpp
    30BCLog::RPC src/rpc/request.cpp
    31BCLog::RPC src/rpc/server.cpp
    32BCLog::SELECTCOINS src/wallet/coinselection.cpp
    33BCLog::TOR src/torcontrol.cpp
    34BCLog::VALIDATION src/validation.cpp
    35BCLog::VALIDATION src/validationinterface.cpp
    36BCLog::WALLETDB src/wallet/db.cpp
    37BCLog::WALLETDB src/wallet/walletdb.cpp
    38BCLog::ZMQ src/zmq/zmqnotificationinterface.cpp
    39BCLog::ZMQ src/zmq/zmqpublishnotifier.cpp
    
  22. MarcoFalke approved
  23. MarcoFalke commented at 10:00 pm on March 5, 2020: member
    ACK on the mempool category. Not sure about BCLog::VALIDATION.
  24. MarcoFalke commented at 3:13 pm on March 6, 2020: member

    I think there is a tradeoff. IIRC -debug is disabled by default, disabling all debug categories. Thus, the debug log is pretty much useless to find the root cause of an issue after a crash or other misbehavior if all log statements are put into a category. Still, it makes sense to put log statments into categories to make it possible to disable or enable them specifically.

    I think we should rethink what categories are enabled/disabled by default and come up with a broader guideline on debug categories.

  25. practicalswift commented at 3:22 pm on March 6, 2020: contributor
    @MarcoFalke Sounds good, but what changes do you suggest for this PR? :)
  26. MarcoFalke commented at 3:23 pm on March 6, 2020: member
    This PR should be revisited after a guideline has been established
  27. practicalswift commented at 3:26 pm on March 6, 2020: contributor
    @MarcoFalke I’m not sure I follow: which of the error messages touched in this PR do you think should be shown to users not running -debug?
  28. MarcoFalke commented at 7:34 pm on March 6, 2020: member
    @practicalswift Any of them. Assume a user has a crashed node (or just high memory usage, high CPU usage, or any other anomaly). In that case those debug messages can give a hint which peer or which message type or which code part/module is responsible for the misbehavior.
  29. practicalswift closed this on Mar 6, 2020

  30. practicalswift deleted the branch on Apr 10, 2021
  31. DrahtBot locked this on Aug 18, 2022
  32. MarcoFalke added the label Up for grabs on Feb 20, 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-07-05 22:12 UTC

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