Add src/node/ and src/wallet/ code to node:: and wallet:: namespaces #23497

pull ryanofsky wants to merge 3 commits into bitcoin:master from ryanofsky:pr/names changing 166 files +580 −140
  1. ryanofsky commented at 4:36 pm on November 12, 2021: member

    There are no code changes, this is just adding namespace and using declarations and node:: or wallet:: qualifiers in some places.

    Motivations for this change are:

    • To make it easier to see when node and wallet code is being accessed places where it shouldn’t be. For example if GUI code is accessing node and wallet internals or if wallet and node code are referencing each other.
    • To make source code organization clearer (#15732), being able to know that wallet:: code is in src/wallet/, node:: code is in src/node/, init:: code is in src/init/, util:: code is in src/util/, etc.

    Reviewing with git log -p -n1 -U0 --word-diff-regex=. can be helpful to verify this is only updating declarations, not changing code.

  2. DrahtBot added the label Block storage on Nov 12, 2021
  3. DrahtBot added the label GUI on Nov 12, 2021
  4. DrahtBot added the label interfaces on Nov 12, 2021
  5. DrahtBot added the label Mining on Nov 12, 2021
  6. DrahtBot added the label P2P on Nov 12, 2021
  7. DrahtBot added the label RPC/REST/ZMQ on Nov 12, 2021
  8. DrahtBot added the label Utils/log/libs on Nov 12, 2021
  9. DrahtBot added the label UTXO Db and Indexes on Nov 12, 2021
  10. DrahtBot added the label Validation on Nov 12, 2021
  11. DrahtBot added the label Wallet on Nov 12, 2021
  12. in src/qt/psbtoperationsdialog.cpp:21 in 768b695296 outdated
    16@@ -17,6 +17,10 @@
    17 
    18 #include <iostream>
    19 
    20+using node::AnalyzePSBT;
    21+using node::BroadcastTransaction;
    


    ryanofsky commented at 8:51 pm on November 12, 2021:

    In commit “Add src/node/* code to node:: namespace” (733a629696ef3350e5c9c861ae94254a06cc920b)

    Note: This line can be removed after #23499, since calling node::BroadcastTransaction from the bitcoin-gui process doesn’t work in the multiprocess build (there is a segfault because the NodeContext pointer this tries to pass is null). This is a preexisting bug, independent of this PR.


    ryanofsky commented at 4:50 am on November 17, 2021:

    re: #23497 (review)

    Note: This line can be removed after #23499

    Removed this now that #23499 is merged.

  13. ryanofsky force-pushed on Nov 12, 2021
  14. ryanofsky commented at 9:28 pm on November 12, 2021: member
    Updated 768b695296e343da0163e07e25f08dfbc6f58e1d -> 8c85a48eac8a0a9512e754f29c173c2ce9e55308 (pr/names.1 -> pr/names.2, compare) with tweaks to clean up and fix errors in dummy wallet and multiprocess builds https://cirrus-ci.com/task/5598684416049152 and https://cirrus-ci.com/task/6161634369470464
  15. DrahtBot commented at 1:32 am on November 13, 2021: member

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

    Conflicts

    Reviewers, this pull request conflicts with the following ones:

    • #24024 (Remove cs_main lock annotation from ChainstateManager.m_blockman by ryanofsky)
    • #23732 (refactor: Remove gArgs from bdb.h and sqlite.h by kiminuo)
    • #23599 (Tidy up RPCTxSerializationFlags by MarcoFalke)
    • #23544 (rpc, wallet: addhdseed, infer seed when importing descriptor with xpub by Sjors)
    • #23417 (wallet, spkm: Move key management from DescriptorScriptPubKeyMan to wallet level KeyManager by achow101)
    • #23373 (test: Parse command line arguments from unit and fuzz tests, make addrman consistency check ratio easier to change by vasild)
    • #23367 (Optimize coin selection by dropping BnB upper limit by S3RK)
    • #23319 (rpc: Return fee and prevout (utxos) to getrawtransaction by dougEfresh)
    • #22341 (rpc: add getxpub by Sjors)
    • #20205 (wallet: Properly support a wallet id by achow101)
    • #19602 (wallet: Migrate legacy wallets to descriptor wallets by achow101)
    • #19460 (multiprocess: Add bitcoin-wallet -ipcconnect option by ryanofsky)
    • #10102 (Multiprocess bitcoin by ryanofsky)

    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.

  16. in src/interfaces/init.h:12 in 8c85a48eac outdated
     6@@ -7,7 +7,9 @@
     7 
     8 #include <memory>
     9 
    10+namespace node {
    11 struct NodeContext;
    12+}  // namespace node
    


    katesalazar commented at 6:11 pm on November 13, 2021:
    Some lines in pull 23492 remove one of the two spaces elsewhere.

    ryanofsky commented at 4:46 am on November 17, 2021:

    re: #23497 (review)

    Some lines in pull 23492 remove one of the two spaces elsewhere.

    Oops, I’m not sure if #23492 is related, but I did seem to misremember which convention we are using. Most of our code does use 1 space not 2 spaces before trailing namespace comments. The 2 space convention is from https://google.github.io/styleguide/cppguide.html#Namespace_Formatting and seems to be rare in our code looking at `git grep -n ’ // namespace'.

    I updated everything here to use one space now. Thanks for catching this.

  17. lsilva01 approved
  18. lsilva01 commented at 6:41 pm on November 13, 2021: contributor
    tACK 8c85a48 The use of namespaces makes the code more organized and clearer.
  19. stratospher commented at 5:10 pm on November 15, 2021: contributor
    ACK 8c85a48. The changes applied make the code more understandable.
  20. DrahtBot added the label Needs rebase on Nov 17, 2021
  21. ryanofsky force-pushed on Nov 17, 2021
  22. ryanofsky commented at 2:05 am on November 17, 2021: member
    Rebased 8c85a48eac8a0a9512e754f29c173c2ce9e55308 -> 3a2c4e28775d49da233d04bed03e5cb8fe9d7239 (pr/names.2 -> pr/names.3, compare) due to conflict with #23524
  23. DrahtBot removed the label Needs rebase on Nov 17, 2021
  24. ryanofsky force-pushed on Nov 17, 2021
  25. ryanofsky commented at 5:03 am on November 17, 2021: member
    Rebased 3a2c4e28775d49da233d04bed03e5cb8fe9d7239 -> 6ea409f96ccc37c74998abad4cf56c4999b3ba8a (pr/names.3 -> pr/names.4, compare) to remove uneeded using declaration after #23499 and switch to one space instead of two spaces before trailing namespace comments. Rebased 6ea409f96ccc37c74998abad4cf56c4999b3ba8a -> d72688f16dd1056e3253663769034b100341664c (pr/names.4 -> pr/names.5, compare) due to conflicts with #23591 and #21206
  26. meshcollider removed the label GUI on Nov 22, 2021
  27. meshcollider removed the label Wallet on Nov 22, 2021
  28. meshcollider removed the label UTXO Db and Indexes on Nov 22, 2021
  29. meshcollider removed the label RPC/REST/ZMQ on Nov 22, 2021
  30. meshcollider removed the label P2P on Nov 22, 2021
  31. meshcollider removed the label Mining on Nov 22, 2021
  32. meshcollider removed the label Validation on Nov 22, 2021
  33. meshcollider removed the label Block storage on Nov 22, 2021
  34. meshcollider removed the label Utils/log/libs on Nov 22, 2021
  35. meshcollider removed the label interfaces on Nov 22, 2021
  36. meshcollider added the label Refactoring on Nov 22, 2021
  37. DrahtBot added the label Needs rebase on Nov 25, 2021
  38. ryanofsky force-pushed on Nov 29, 2021
  39. DrahtBot removed the label Needs rebase on Nov 29, 2021
  40. meshcollider commented at 8:15 am on December 2, 2021: contributor
    Concept ACK. I realise this PR is going to conflict with pretty much every move from rpcwallet. Please let me know if you’d prefer to have this merged first or after the moves, I’ll prioritise reviewing this.
  41. DrahtBot added the label Needs rebase on Dec 2, 2021
  42. ryanofsky force-pushed on Dec 2, 2021
  43. ryanofsky commented at 1:54 pm on December 2, 2021: member
    Rebased d72688f16dd1056e3253663769034b100341664c -> 0818cef3c5f6c310a953d3d90b81181a65a08dde (pr/names.5 -> pr/names.6, compare) due to conflicts with #23602, #23640, #23155
  44. ryanofsky commented at 2:03 pm on December 2, 2021: member

    Concept ACK. I realise this PR is going to conflict with pretty much every move from rpcwallet. Please let me know if you’d prefer to have this merged first or after the moves, I’ll prioritise reviewing this.

    Thanks, the only changes in this PR are adding namespace and using lines in many places and node:: wallet:: prefixes in a few places, so it’s not hard to review or maintain this, and it doesn’t matter very much if it is ordered before or after the rpc moves. If there’s only 1 RPC move PR, then it especially doesn’t matter. But if there are 10 RPC move PRs and gaps between them, then this will need to be rebased 10 times, and that could be a annoying if it requires re-acks.

  45. laanwj added this to the "Blockers" column in a project

  46. DrahtBot removed the label Needs rebase on Dec 2, 2021
  47. DrahtBot added the label Needs rebase on Dec 3, 2021
  48. ryanofsky force-pushed on Dec 3, 2021
  49. ryanofsky commented at 12:58 pm on December 3, 2021: member
    Rebased 0818cef3c5f6c310a953d3d90b81181a65a08dde -> 64c8123c6e36f42767383bd5725299a7a2b9e964 (pr/names.6 -> pr/names.7, compare) due to conflicts with #23647
  50. DrahtBot removed the label Needs rebase on Dec 3, 2021
  51. ryanofsky force-pushed on Dec 8, 2021
  52. ryanofsky commented at 5:08 am on December 8, 2021: member
    Rebased 64c8123c6e36f42767383bd5725299a7a2b9e964 -> 65c6a10a11db40b4bcf4176752334cf2c1a274ca (pr/names.7 -> pr/names.8, compare) due to conflict with #23667
  53. in src/qt/walletmodel.h:37 in 65c6a10a11 outdated
    31@@ -32,7 +32,6 @@ class SendCoinsRecipient;
    32 class TransactionTableModel;
    33 class WalletModelTransaction;
    34 
    35-class CCoinControl;
    36 class CKeyID;
    37 class COutPoint;
    38 class COutput;
    


    meshcollider commented at 9:13 am on December 8, 2021:
    This COutput should be in the wallet namespace too I think

    ryanofsky commented at 12:52 pm on December 8, 2021:

    re: #23497 (review)

    This COutput should be in the wallet namespace too I think

    Thanks, removed because it’s unused

  54. meshcollider commented at 9:22 am on December 8, 2021: contributor

    Concept ACK

    Have only reviewed the wallet commit so far. I think you missed a CWallet in dummywallet.cpp.

  55. in src/node/blockstorage.cpp:100 in e157b983d3 outdated
     94@@ -94,12 +95,14 @@ void CleanupBlockRevFiles()
     95         remove(item.second);
     96     }
     97 }
     98+} // namespace node
     99 
    100 std::string CBlockFileInfo::ToString() const
    


    meshcollider commented at 9:28 am on December 8, 2021:
    Would it be easier / cleaner to move this so it doesn’t force a weird break in the namespace?

    ryanofsky commented at 12:52 pm on December 8, 2021:

    re: #23497 (review)

    Would it be easier / cleaner to move this so it doesn’t force a weird break in the namespace?

    Thanks, moved to src/chain.cpp since the CBlockFileInfo class is declared in src/chain.h in a separate commit. Moved in a separate commit because not every diff tool lets you verify moves with no changes easily.

  56. meshcollider commented at 9:37 am on December 8, 2021: contributor
    utACK 65c6a10a11db40b4bcf4176752334cf2c1a274ca modulo above comments
  57. DrahtBot added the label Needs rebase on Dec 8, 2021
  58. ryanofsky force-pushed on Dec 8, 2021
  59. ryanofsky commented at 1:13 pm on December 8, 2021: member

    Rebased 65c6a10a11db40b4bcf4176752334cf2c1a274ca -> de0100b765a7bed45fa4e5d4fc24cc30cece957a (pr/names.8 -> pr/names.9, compare) due to conflict with #20295, also making suggested changes


    re: #23497#pullrequestreview-826179864

    I think you missed a CWallet in dummywallet.cpp.

    Thanks, removed because the only thing that was using it (a MakeWallet stub) was unused

  60. DrahtBot removed the label Needs rebase on Dec 8, 2021
  61. meshcollider commented at 0:44 am on December 9, 2021: contributor
    utACK de0100b765a7bed45fa4e5d4fc24cc30cece957a
  62. DrahtBot added the label Needs rebase on Dec 9, 2021
  63. ryanofsky force-pushed on Dec 9, 2021
  64. ryanofsky commented at 5:45 pm on December 9, 2021: member
    Rebased de0100b765a7bed45fa4e5d4fc24cc30cece957a -> 175127797f6f6c052e1bd210e174a1aa48a5e1c6 (pr/names.9 -> pr/names.10, compare) due to conflict with #22019 Rebased 175127797f6f6c052e1bd210e174a1aa48a5e1c6 -> 91aaee1be3d7a63c764db61570f06f4a3daa87e2 (pr/names.10 -> pr/names.11, compare) due to conflict with #23721
  65. DrahtBot removed the label Needs rebase on Dec 9, 2021
  66. DrahtBot added the label Needs rebase on Dec 16, 2021
  67. ryanofsky force-pushed on Dec 16, 2021
  68. DrahtBot removed the label Needs rebase on Dec 16, 2021
  69. ryanofsky requested review from dongcarl on Dec 20, 2021
  70. ryanofsky commented at 2:33 pm on December 20, 2021: member
    @dongcarl do you think could review this? The PR just adds namespace node { ... } around src/node/ code and namespace wallet { ... } around src/wallet/ code and I think should be a quick review
  71. in src/index/base.cpp:17 in 91aaee1be3 outdated
    13@@ -14,6 +14,8 @@
    14 #include <validation.h> // For g_chainman
    15 #include <warnings.h>
    16 
    17+using node::ReadBlockFromDisk;
    


    MarcoFalke commented at 2:47 pm on December 20, 2021:
    What is the rule here? Randomly pick using or specify the namespace before the symbol?

    ryanofsky commented at 3:48 pm on December 20, 2021:

    What is the rule here? Randomly pick using or specify the namespace before the symbol?

    I don’t know if there’s a rule, but I think using some_namespace::SomeSymbol; statements are generally a bad thing, and should be used sparingly. They are bad because they can make it unclear where symbols are coming from, and can lead to ugly code when longer names and shorter names are used inconsistently.

    In this PR, I’m trying to limit scope of using statements and only adding them locally in .cpp files, never in header files. I think most of the places where they are added are places where code organization should be improved, and that these will be removed when it is improved. For example, I’m working on porting src/index/ code to use interfaces::Chain and stop using node code and node:: symbols. Carl and James and others are moving more validation code to src/node/ which will make using statements in validation code go away. The using statements in RPC, bench, and test code could potentially be removed by having a src/node/test/directory analogous to the existing src/wallet/test/ directory and a src/node/rpc/ directory analagous to the existing src/wallet/rpc/ directory. Or they could just be removed by adding node:: prefixes to relevant types and symbols. I think either of these changes would be a win for clarity and organization, and the goal of this PR is to enable that.


    ryanofsky commented at 4:39 pm on December 20, 2021:

    Carl and James and others are moving more validation code to src/node/ which will make using statements in validation code go away.

    Actually, I’m assuming too much here. Validation code doesn’t have to move in order to avoid using node:: statements or node:: prefixes. It could alternately become more modular and stop depending directly on node:: types and symbols. It could move someplace other than src/node/, like src/kernel/, or not move at all. The number of using statements and node:: references goes down in any case.


    dongcarl commented at 11:32 pm on December 20, 2021:

    Agree that the using statements should be used sparingly.

    If I understand correctly, the hope is that the using statements that you have right now will be removed in the future as we find better interfaces/boundaries between our modules? I can see how that would work for src/index/ code and interfaces::Chain, but I’m wondering how we’d get rid of cases like the various places with using node::NodeContext;, or perhaps these cases are ones where we want to keep the using statements?


    ryanofsky commented at 1:28 am on December 21, 2021:

    If I understand correctly, the hope is that the using statements that you have right now will be removed in the future as we find better interfaces/boundaries between our modules?

    Yes, but I think this change is good whether or not that happens. The using statements just show places where module boundaries are being crossed. In general it’s better if modules are self-contained and boundaries are crossed in fewer places. But it’s useful in any case to be able to see the places where boundaries are crossed and not have hidden dependencies.

    I can see how that would work for src/index/ code and interfaces::Chain, but I’m wondering how we’d get rid of cases like the various places with using node::NodeContext;, or perhaps these cases are ones where we want to keep the using statements?

    Just if you move the code using node::NodeContext inside the node namespace, then you no longer need node:: prefixes or using statements to reference it. This is what I was referring to with the src/node/rpc/ src/node/test/ idea above, but that’s just one possible way the node module could be more self-contained.

    (Also NodeContext is kind of a weird case because it’s the one node identifier that begins with word “node”. I was thinking of making a followup PR that would remove all using node::NodeContext and rename node::NodeContext to node::Context and rename wallet::WalletContext to wallet::Context. Would be purely an aesthetic change, though, and low on the priority list.)

  72. ryanofsky referenced this in commit 8ef044b737 on Dec 20, 2021
  73. dongcarl commented at 0:05 am on December 21, 2021: member

    Concept ACK, I like that this forces us to be somewhat more explicit.

    Would like to wrap my head around using vs fully specifying in #23497 (review) though, let’s discuss in that thread.

  74. ryanofsky referenced this in commit 172096e9dd on Dec 21, 2021
  75. DrahtBot added the label Needs rebase on Dec 23, 2021
  76. ryanofsky force-pushed on Dec 27, 2021
  77. ryanofsky commented at 6:48 pm on December 27, 2021: member
    Rebased 91aaee1be3d7a63c764db61570f06f4a3daa87e2 -> 4decc9a53dcf36ec93b75cb2f029d07e008e00d0 (pr/names.11 -> pr/names.12, compare) due to conflicts with #23842 and #23736
  78. DrahtBot removed the label Needs rebase on Dec 27, 2021
  79. meshcollider commented at 6:34 am on December 30, 2021: contributor

    Would this resolve the TODO on line 28 of blockstorage.cpp?

    EDIT: actually, don’t think so

  80. ryanofsky referenced this in commit 76e3dda368 on Dec 30, 2021
  81. ryanofsky commented at 9:55 pm on December 30, 2021: member

    Would this resolve the TODO on line 28 of blockstorage.cpp?

    EDIT: actually, don’t think so

    It’s arguable, but I figured I’d be proactive and remove the TODO in a new commit. I can drop the TODO or try to clarify it if someone thinks it should be kept.

    Added 1 commits 4decc9a53dcf36ec93b75cb2f029d07e008e00d0 -> 76e3dda368811f3a49e0b6fd52cff612cbb3fd00 (pr/names.12 -> pr/names.13, compare)

  82. MarcoFalke commented at 10:37 am on December 31, 2021: member
    It is ok to remove the TODO. It still needs to be fixed (symbols should be private), but using a namespace is only one way to fix it. Alternatives are: Using static or private:.
  83. MarcoFalke commented at 2:57 pm on January 4, 2022: member
    Done in #23974 (draft)
  84. DrahtBot added the label Needs rebase on Jan 4, 2022
  85. ryanofsky referenced this in commit 84e96f649a on Jan 4, 2022
  86. ryanofsky referenced this in commit 4ee68619fa on Jan 4, 2022
  87. ryanofsky force-pushed on Jan 4, 2022
  88. ryanofsky commented at 7:29 pm on January 4, 2022: member
    Rebased 76e3dda368811f3a49e0b6fd52cff612cbb3fd00 -> 4ee68619fad12f99a8c8b41a9f192503ad7789ea (pr/names.13 -> pr/names.14, compare) due to conflicts with #23936 and #23581
  89. DrahtBot removed the label Needs rebase on Jan 4, 2022
  90. MarcoFalke commented at 8:24 am on January 5, 2022: member
    If you remove the last commit, a conflict with #23974 can be avoided
  91. ryanofsky force-pushed on Jan 5, 2022
  92. ryanofsky commented at 1:54 pm on January 5, 2022: member

    If you remove the last commit, a conflict with #23974 can be avoided

    Sure, dropped commit.

    Updated 4ee68619fad12f99a8c8b41a9f192503ad7789ea -> c776907128c4f041bb3b40494982207bebceb252 (pr/names.14 -> pr/names.15, compare) dropping commit Rebased c776907128c4f041bb3b40494982207bebceb252 -> e5b6aef61221b621ad77b5f075a16897e08835bf (pr/names.15 -> pr/names.16, compare) due to conflict with #23974

  93. MarcoFalke referenced this in commit ddcc518cbd on Jan 6, 2022
  94. Add src/node/* code to node:: namespace 90fc8b089d
  95. Add src/wallet/* code to wallet:: namespace f7086fd8ff
  96. Move CBlockFileInfo::ToString method where class is declared
    CBlockFileInfo class is declared in src/chain.h, so move ToString
    definition to src/chain.cpp instead of src/node/blockstorage.cpp
    e5b6aef612
  97. DrahtBot added the label Needs rebase on Jan 7, 2022
  98. ryanofsky force-pushed on Jan 7, 2022
  99. DrahtBot removed the label Needs rebase on Jan 7, 2022
  100. achow101 commented at 9:25 pm on January 10, 2022: member
    ACK e5b6aef61221b621ad77b5f075a16897e08835bf
  101. MarcoFalke commented at 10:10 am on January 11, 2022: member

    Concept ACK e5b6aef61221b621ad77b5f075a16897e08835bf 🍨

    Signature:

     0-----BEGIN PGP SIGNED MESSAGE-----
     1Hash: SHA512
     2
     3Concept ACK e5b6aef61221b621ad77b5f075a16897e08835bf 🍨
     4-----BEGIN PGP SIGNATURE-----
     5
     6iQGzBAEBCgAdFiEE+rVPoUahrI9sLGYTzit1aX5ppUgFAlwqrYAACgkQzit1aX5p
     7pUjJRwv/Ra0FnQ2CgmimyjQbDwPhXhsHl4FbFarePo1urtKhZ/yzz2lVLmwrkcZg
     83cfd6brTclPTRxU8D+E8V95fqXLurfM1rZJ9tt380MezX/toYLwhdA1r26k7UR4P
     9iilscs/uld+uGYCSMjDMWHfWSR6Fz3ckGCdzr1yvMeKi2pbaakd4kF7ICwtDnPOs
    10BLJatB+aAulZ0bKJWYYdhwgCzqUMrgf0w5ojBJ51TnTMXXburtmSqjcppcDuU3Fy
    11sVJ4QncxUGBtC0e61hM4zKs88pu4yO72iBkiuTTRfZNoMhM0FZ++Thiw+PB8bULG
    12nSlQlN5CMllRHs1Yy3JzzTaLkKsFJ5B1/Frrg8yv8AI6+HMwxdN2H/+RA21Grvqi
    13EZtS9rRPgg8rMB/5cB53/1HPr7tQXtzO2fulFRoJwFEbAV0W0n2fzoFvNu7rpJYJ
    14hVkO+9Zr8xxCX80gpjplvyV3sK0Zw0G+jOELhxqXmPDyIqgLarhZ7a/tx6asYO+M
    15em97A1l/
    16=31o2
    17-----END PGP SIGNATURE-----
    
  102. MarcoFalke merged this on Jan 11, 2022
  103. MarcoFalke closed this on Jan 11, 2022

  104. sidhujag referenced this in commit 7502ae351a on Jan 12, 2022
  105. laanwj removed this from the "Blockers" column in a project

  106. domob1812 referenced this in commit f8398a0875 on Jan 17, 2022
  107. domob1812 referenced this in commit b196a1df3c on Jan 17, 2022
  108. mzumsande referenced this in commit 69c7d9cecc on Jan 17, 2022
  109. rebroad referenced this in commit 872e296bdb on Feb 3, 2022
  110. Fabcien referenced this in commit e1fa92adeb on Dec 5, 2022
  111. Fabcien referenced this in commit c3c7cb0ab6 on Dec 6, 2022
  112. DrahtBot locked this on Jan 11, 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-11-17 18:12 UTC

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