log: expand BCLog::LogFlags (categories) to 64 bits #26619

pull LarryRuane wants to merge 1 commits into bitcoin:master from LarryRuane:2022-11-log-categories-64 changing 4 files +41 −39
  1. LarryRuane commented at 4:29 pm on December 1, 2022: contributor

    Increase the maximum number of logging categories from 32 to 64.

    We’re currently using 29 of the 32 available logging categories (there are only 3 remaining). It would be good to increase the limit soon; the fourth PR to be merged that adds a new logging category will be blocked until something like this is done.

  2. DrahtBot commented at 4:29 pm on December 1, 2022: contributor

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

    Code Coverage

    For detailed information about the code coverage, see the test coverage report.

    Reviews

    See the guideline for information on the review process.

    Type Reviewers
    ACK vasild, ryanofsky, theStack, achow101
    Approach ACK stickies-v

    If your review is incorrectly listed, please react with 👎 to this comment and the bot will ignore it on the next update.

    Conflicts

    Reviewers, this pull request conflicts with the following ones:

    • #30595 (kernel: Introduce initial C header API by TheCharlatan)
    • #30315 (Stratum v2 Transport by Sjors)
    • #29432 (Stratum v2 Template Provider (take 3) by Sjors)
    • #29415 (Broadcast own transactions only via short-lived Tor or I2P connections by vasild)
    • #29346 (Stratum v2 Noise Protocol by Sjors)
    • #26697 (logging: use bitset for categories by LarryRuane)

    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.

  3. DrahtBot added the label Utils/log/libs on Dec 1, 2022
  4. in src/logging.cpp:187 in c91cfa8682 outdated
    181@@ -182,6 +182,9 @@ const CLogCategoryDesc LogCategories[] =
    182     {BCLog::BLOCKSTORE, "blockstorage"},
    183     {BCLog::TXRECONCILIATION, "txreconciliation"},
    184     {BCLog::SCAN, "scan"},
    185+    // Add new entries before this line.
    186+
    187+    {BCLog::TEST, "test"}, // logging testing only
    


    stickies-v commented at 6:28 pm on December 1, 2022:
    0    {BCLog::TEST, "test"}, // internal flag only to be used to test logging
    

    stickies-v commented at 6:29 pm on December 1, 2022:
    What about calling it LOGTEST instead of TEST? Makes the purpose more clear and also keeps the TEST name free if we want to use it later?
  5. stickies-v commented at 6:53 pm on December 1, 2022: contributor

    Concept ACK - makes sense to expand this now

    There are still a couple of places that use uint32_t, e.g. here https://github.com/bitcoin/bitcoin/blob/02515117dc5a25998f5dd92938eccb326b1eec5c/src/logging.h#L174 and callsites of GetCategoryMask() (and possibly further upstream)

  6. LarryRuane force-pushed on Dec 1, 2022
  7. LarryRuane commented at 8:30 pm on December 1, 2022: contributor

    Force-pushed to address review comments – thanks, @stickies-v!

    One further change this PR could make is to modify all the existing BCLog::LogFlags definitions as follows:

    0-        NET         = (1 <<  0),
    1+        NET         = (1ULL <<  0),
    

    More lines would change, but greater consistency. Any opinions?

  8. theStack commented at 8:40 pm on December 1, 2022: contributor
    Concept ACK
  9. stickies-v commented at 9:45 pm on December 1, 2022: contributor

    More lines would change, but greater consistency. Any opinions?

    I wouldn’t, there’s not really a connection with this PR and the lines of code aren’t touched.

  10. stickies-v commented at 12:11 pm on December 2, 2022: contributor

    Approach ACK fe99f6858

    I can’t make up my mind if I think the LOGTEST flag is helpful. PR states it helps unearth wrong 32bits assumptions, but… we only use it in a single function call (LogPrint) - so, does it really? Atm I’m leaning towards preferring leaving it out.

    Otherwise, everything looks good to me with some basic testing.

  11. luke-jr commented at 8:50 am on December 7, 2022: member

    What’s the benefit from growing it prematurely?

    Maybe there should be a typedef? (Been thinking we should have a blockheight_t or such too, but no real benefit to the refactor)

  12. stickies-v commented at 11:28 am on December 7, 2022: contributor

    What’s the benefit from growing it prematurely?

    If we have multiple PRs open that each need to add their own new log category, it would be unclear which PR is to eventually exceed the limit and/or multiple PRs would have to implement this upgrade independently and then rebase. It makes sense to me do to this in advance, and I think we’re close enough to the limit to go ahead? Could probably wait for another category to be added first too, but… since it’s already implemented and we’ll need it soon anyway, I think it’s best to not waste more review/dev time by letting this go stale.

    Maybe there should be a typedef?

    That seems sensible. I don’t think we’ll need to replace the uint64_t anytime soon, but we’re changing all the types now so might as well include that.

  13. LarryRuane commented at 3:33 pm on December 7, 2022: contributor

    but we’re changing all the types now so might as well include that

    Just so I understand, is the suggestion (for this PR) to add a typedef rather than using uint64_t directly? I’d be happy to do that, and I think you’re right, we can keep this PR smaller by eliminating the test stuff, I could do that as well. Please give this comment a thumbs up (or down) to let me know, thanks.

  14. LarryRuane force-pushed on Dec 9, 2022
  15. LarryRuane commented at 5:59 am on December 9, 2022: contributor

    Force-pushed to remove the test; I agree it doesn’t add enough value for the additional complexity.

    Maybe there should be a typedef?

    I don’t think we’ll need to replace the uint64_t anytime soon, but we’re changing all the types now so might as well include that.

    I’m now leaning toward keeping this patch as simple as possible, just the straightforward change from uint32_t to uint64_t. If we introduce a new typedef, then if we ever need more than 64 logging categories, we won’t be able to just change that one typedef because there’s no standard uint128_t, so we’d need bigger changes anyway.

  16. luke-jr commented at 6:19 am on December 9, 2022: member

    If we introduce a new typedef, then if we ever need more than 64 logging categories, we won’t be able to just change that one typedef because there’s no standard uint128_t, so we’d need bigger changes anyway.

    We’d be able to introduce a class and change the typedef to that. Perhaps similar to QFlags.

    But actually, it doesn’t really make sense for LogFlags to be allocated by bit at all. The only time we need to indicate multiple is the configuration for logging them, right? That could easily be a std::bitset.

  17. LarryRuane commented at 7:06 am on December 9, 2022: contributor

    But actually, it doesn’t really make sense for LogFlags to be allocated by bit at all. The only time we need to indicate multiple is the configuration for logging them, right? That could easily be a std::bitset.

    That’s an excellent suggestion; std::bitset looks perfect for this. Would you favor changing this PR to implement that? Or maybe do this simple one now, and then do a follow-up?

  18. luke-jr commented at 5:05 pm on December 9, 2022: member
    I think there’s no urgent need for >32 bits, so might as well go straight to bitset. Perhaps close this and open a new PR for it, to avoid confusion?
  19. LarryRuane commented at 5:45 am on December 14, 2022: contributor

    I think there’s no urgent need for >32 bits, so might as well go straight to bitset. Perhaps close this and open a new PR for it, to avoid confusion?

    I just created #26697 as a replacement for this PR, closing. If someone can think of a reason this PR would be better than #26697, leave a comment here and I’ll reopen it.

  20. LarryRuane closed this on Dec 14, 2022

  21. LarryRuane commented at 4:23 am on January 15, 2023: contributor
    Some additional historical context: #9424 (comment)
  22. LarryRuane commented at 0:02 am on January 23, 2023: contributor
    I closed the current PR because #26697 was intended to replace it, but the current PR may be preferable after all, so I’m now reopening it.
  23. LarryRuane reopened this on Jan 23, 2023

  24. LarryRuane force-pushed on Jan 23, 2023
  25. LarryRuane commented at 0:23 am on January 23, 2023: contributor
    Force pushed to make the enum LogFlags literals’ type match the enum type, uint64_t (instead of uint32_t). This isn’t necessary unless the shift amount is 32 or more, but this way all these constants will be defined consistently.
  26. fanquake commented at 11:43 am on March 20, 2023: member

    but the current PR may be preferable after all

    Looks like the concerns expressed in #26697, which were reason for reopening here, are no-longer valid? Going to reclose this.

  27. fanquake closed this on Mar 20, 2023

  28. achow101 referenced this in commit 630756cac0 on Mar 23, 2023
  29. sidhujag referenced this in commit 433494e1d3 on Mar 24, 2023
  30. bitcoin locked this on Mar 19, 2024
  31. bitcoin unlocked this on Aug 12, 2024
  32. vasild commented at 10:28 am on August 12, 2024: contributor

    ACK 90c3d904bcbf294a6fcef8bc9ecb9445fd41c4bd

    This probably needs a rebase. It is a trivial change.

    10 new categories were added in the last 7 years. That is 1-2 per year. 32 extra should suffice for a few decades.

  33. maflcko reopened this on Aug 12, 2024

  34. LarryRuane force-pushed on Aug 12, 2024
  35. vasild approved
  36. vasild commented at 2:18 pm on August 13, 2024: contributor
    ACK 9bed303b9cc28e13b12af067b34e6058cbccf639
  37. DrahtBot requested review from stickies-v on Aug 13, 2024
  38. DrahtBot requested review from theStack on Aug 13, 2024
  39. in src/logging.h:207 in 9bed303b9c outdated
    203@@ -204,7 +204,7 @@ namespace BCLog {
    204         void SetLogLevel(Level level) { m_log_level = level; }
    205         bool SetLogLevel(std::string_view level);
    206 
    207-        uint32_t GetCategoryMask() const { return m_categories.load(); }
    208+        uint64_t GetCategoryMask() const { return m_categories.load(); }
    


    ryanofsky commented at 2:28 pm on August 13, 2024:

    In commit “log: expand BCLog::LogFlags (categories) to 64 bits” (9bed303b9cc28e13b12af067b34e6058cbccf639)

    Instead of hardcoding uint64_t throughout this PR, it might make sense to add using CategoryMask = uint64_t; and use CategoryMask as a type name describing purpose of the type rather than how many bits it presently contains.

  40. ryanofsky approved
  41. ryanofsky commented at 2:31 pm on August 13, 2024: contributor
    Code review ACK 9bed303b9cc28e13b12af067b34e6058cbccf639. I do think #26697 is a nicer alternative to this PR because it makes code more safe and readable. But this approach is also fine.
  42. LarryRuane force-pushed on Aug 13, 2024
  43. LarryRuane commented at 3:30 pm on August 13, 2024: contributor

    @ryanofsky

    Instead of hardcoding uint64_t throughout this PR, it might make sense to add using CategoryMask = uint64_t

    I took this suggestion, thanks. As a test, I defined CategoryMask to be uint32_t, but the compile failed because of the ULL suffix on all those constants (width exceeds 32 bits). So I’m trying to work around that by defining a mask_bit constant. (Should it have a name like MaskBit? It’s only used within the enum definition.) I think it makes the code easy to read. If CI fails, I can change them back to ULL (even though it’s kind of old fashioned and ugly).

  44. vasild approved
  45. vasild commented at 4:17 pm on August 13, 2024: contributor

    ACK f64b861c0940ca90869303a9754ebe5bf40bb0c7

    I was fine with (1ULL << 23) as well. Another way is to use the 0b prefix (then no need for the ULL suffix):

    0enum LogFlags : CategoryMask {
    1    NONE =    0b00000000000000000000000000000000,
    2    NET =     0b00000000000000000000000000000001,
    3    TOR =     0b00000000000000000000000000000010,
    4    MEMPOOL = 0b00000000000000000000000000000100,
    5    HTTP =    0b00000000000000000000000000001000,
    6    ....
    7};
    
  46. DrahtBot requested review from ryanofsky on Aug 13, 2024
  47. ryanofsky commented at 5:27 pm on August 13, 2024: contributor

    Code review ACK f64b861c0940ca90869303a9754ebe5bf40bb0c7, just added uint64_t typedef since last review.

    As a test, I defined CategoryMask to be uint32_t, but the compile failed because of the ULL suffix on all those constants (width exceeds 32 bits). So I’m trying to work around that by defining a mask_bit constant. (Should it have a name like MaskBit? It’s only used within the enum definition.) I think it makes the code easy to read. If CI fails, I can change them back to ULL (even though it’s kind of old fashioned and ugly).

    This seems ok, though I think would just write CategoryMask{1} everywhere instead of having a separate constant. Since the code is already using CategoryMask{0} this seems consistent, and it avoids defining another identifier to look up. I do think either of these approaches are a little better than using ULL suffixes, but those suffixes would be ok too. I have to say I am horrified :scream: by vasild’s suggestion to write the flags in binary because its seems dizzying and error prone to me, but maybe this representation seems more natural to other people.

    I also still think #26697 is a nicer alternative to this, removing hardcoded numbers and bitwise operations outside of the bitset class.

  48. vasild commented at 6:37 pm on August 13, 2024: contributor
    Maybe 0b00000000'00000000'00000000'00001000 is a bit less horrific ;) The current is ok, no need to change it further.
  49. log: expand BCLog::LogFlags (categories) to 64 bits
    This will increase the maximum number of logging categories
    from 32 to 64.
    b31a0cd037
  50. LarryRuane force-pushed on Aug 13, 2024
  51. LarryRuane commented at 7:58 pm on August 13, 2024: contributor

    I think would just write CategoryMask{1} everywhere instead of having a separate constant

    I like that suggestion, I just force-pushed it, thanks!

  52. vasild approved
  53. vasild commented at 12:36 pm on August 14, 2024: contributor
    ACK b31a0cd0378184b2b9eb8f4bd3120cbd32c62005
  54. ryanofsky approved
  55. ryanofsky commented at 2:15 pm on August 14, 2024: contributor
    Code review ACK b31a0cd0378184b2b9eb8f4bd3120cbd32c62005, just dropping mask_bit constant since last review. I still think #26697 is a better alternative to this PR because it is more type-safe and gets rid of bitwise flags and operations outside the bitset class, but it could also be a followup to this PR.
  56. theStack approved
  57. theStack commented at 4:46 pm on August 20, 2024: contributor
    Code-review ACK b31a0cd0378184b2b9eb8f4bd3120cbd32c62005
  58. achow101 commented at 7:51 pm on September 3, 2024: member
    ACK b31a0cd0378184b2b9eb8f4bd3120cbd32c62005
  59. achow101 merged this on Sep 3, 2024
  60. achow101 closed this on Sep 3, 2024

  61. LarryRuane deleted the branch on Sep 3, 2024

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-12-22 06:12 UTC

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