Make all
NodeImpl,ChainImplandExternalSignerImplclass memberspublic(and document why), to be consistent in all the*Implclasses insrc/node/interfaces.cppandsrc/wallet/interfaces.cppand to help future reviewers and contributors.Remove unneeded temporaries in
NodeImplandChainImplmethods insrc/node/interfaces.cppand simplify, to make the code easier to read and understand and to improve performance by avoiding unnecessary move operations.
refactor: make all NodeImpl/ChainImpl/ExternalSignerImpl members public, rm temporaries, simplify #25651
pull jonatack wants to merge 2 commits into bitcoin:master from jonatack:make-ChainImpl-m_node-data-member-private changing 2 files +16 −37-
jonatack commented at 4:31 PM on July 20, 2022: contributor
-
MarcoFalke commented at 4:52 PM on July 20, 2022: member
Some notes:
- The whole file is in an unnamed namespace, so everything in it is already "private" for all other files.
- I can't imagine code that instantiates this class in this file and calls methods on it, so I don't think
private/publicmakes any difference in practise. - As no methods are called (and will ever be called directly), except the constructor, everything else could be
privateas well. Though, as this makes no difference in practise, I am not sure if this even makes sense conceptually.
-
jonatack commented at 5:02 PM on July 20, 2022: contributor
Thanks for having a look, Marco. It seems some of those things could change in the future, so this change looks preferable to me.
In addition to the motivations in the OP, having
m_nodenext to the already privateChainstateManager& chainman() { return *Assert(m_node.chainman); }method seems easier to reason about. This is what made me look form_nodein the first place and wonder why it was placed there. -
MarcoFalke commented at 5:12 PM on July 20, 2022: member
It seems some of those things could change in the future
I don't think any of the things could change in the future, unless I am missing something or you have examples where it would change.
So to me this mostly seems like a stylistic change, as I can't imagine a real-world example where this could make any difference.
-
ryanofsky commented at 5:41 PM on July 20, 2022: contributor
I guess I have a mild preference for making everything public, but this change seems fine.
By design everything in ChainImpl NodeImpl WalletImpl has been public since the classes were written because the classes themselves are private. IMO it is only meaningful to distinguish between overridden and non-overridden members and private/public seems like noise in this context.
Whatever style you land on though I do think would be good to consistently apply it to all the
*Implclasses insrc/node/interfaces.cppandsrc/wallet/interfaces.cpp - DrahtBot added the label Refactoring on Jul 20, 2022
-
jonatack commented at 6:10 PM on July 20, 2022: contributor
Thanks, I'm convinced. Nothing in
src/wallet/interfaces.cppis private. Making everything insrc/node/interfaces.cpppublic (and maybe documenting why) makes sense. - jonatack renamed this:
refactor: make ChainImpl::m_node data member private
refactor: make all NodeImpl and ChainImpl members public and document why
on Jul 20, 2022 - jonatack force-pushed on Jul 20, 2022
-
jonatack commented at 7:08 PM on July 20, 2022: contributor
Updated per review feedback (thank you).
- jonatack renamed this:
refactor: make all NodeImpl and ChainImpl members public and document why
refactor: make all NodeImpl/ChainImpl members public, rm unneeded temporaries, simplify
on Jul 27, 2022 - jonatack force-pushed on Jul 27, 2022
-
jonatack commented at 1:42 PM on July 27, 2022: contributor
Added a second commit removing unnecessary and verbose temporaries in
NodeImplandChainImplmethods insrc/node/interfaces.cppto make the code easier to read and understand and avoid unnecessary move operations. Updated the pull title and description. Refactoring only, no change in behavior; should be easy to review. -
DrahtBot commented at 10:16 PM on July 27, 2022: contributor
<!--e57a25ab6845829454e8d69fc972939a-->
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.
<!--174a7506f384e20aa4161008e828411d-->
Conflicts
Reviewers, this pull request conflicts with the following ones:
- #25673 (refactor: make member functions const when applicable by aureleoules)
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.
-
in src/node/interfaces.cpp:386 in b9a715ea03 outdated
382 | @@ -384,12 +383,13 @@ class NodeImpl : public Node 383 | /* verification progress is unused when a header was received */ 0); 384 | })); 385 | } 386 | + NodeContext* m_context{nullptr};
ryanofsky commented at 5:47 PM on July 28, 2022:In commit "refactor: make all NodeImpl and ChainImpl members public" (b9a715ea03506bc6aa647d3df1cd177221d30dd0)
Would encourage putting class member variables all together and not interspersing them with methods. If I'm trying to understand what a class does and what its role is in the application, knowing what data it contains is maybe the single most important piece of information I could have, and it's harder to see if the data fields aren't declared in a single place.
#21525 messed up the style a bit but the original style and style I'd recommend would be:
class NodeImpl : public Node { public: // ... virtual methods first ... // ... nonvirtual helper methods next ... // ... data fields last ... };
jonatack commented at 5:25 PM on July 29, 2022:Done, and it's a smaller diff too. Thanks for clarifying!
in src/node/interfaces.cpp:504 in d742ebbc91 outdated
506 | - if (height >= 0) { 507 | - return height; 508 | - } 509 | - return std::nullopt; 510 | + const int height{WITH_LOCK(::cs_main, return chainman().ActiveChain().Height())}; 511 | + return height >= 0 ? std::optional{height} : std::nullopt;
ryanofsky commented at 5:52 PM on July 28, 2022:In commit "refactor: remove unneeded temporaries in node/interfaces, simplify code" (d742ebbc91e5ca40389a3923bffba3e24911cc6f)
Nice simplification!
ryanofsky approvedryanofsky commented at 5:55 PM on July 28, 2022: contributorCode review ACK d742ebbc91e5ca40389a3923bffba3e24911cc6f. Suggested a change but is already an improvement as-is and the second commit does a nice job of modernizing some of this code
jonatack renamed this:refactor: make all NodeImpl/ChainImpl members public, rm unneeded temporaries, simplify
refactor: make all NodeImpl/ChainImpl/ExternalSignerImpl members public, rm temporaries, simplify
on Jul 29, 2022b27ba169ebrefactor: make all NodeImpl/ChainImpl/ExternalSignerImpl members public
as the classes themselves are private, and to be consistent within all the *Impl classes in src/node/interfaces.cpp and src/wallet/interfaces.cpp following this order: public: // ... virtual methods ... // ... nonvirtual helper methods ... // ... data members ... and add documentation in src/node/interfaces.cpp and src/wallet/interfaces.cpp to help future reviewers and contributors.
jonatack force-pushed on Jul 29, 20224bedfd702arefactor: remove unneeded temporaries in node/interfaces, simplify code
- make the code easier to read and understand - improve performance by avoiding unnecessary move operations - the cleaner, simpler, and easier to read the code is, the better chance the compiler has at implementing it well
jonatack force-pushed on Jul 29, 2022jonatack commented at 5:47 PM on July 29, 2022: contributorUpdated the first commit with @ryanofsky's suggestion (thanks!) and the second commit with a simplification.
<details><summary><code>git diff d742ebb 4bedfd7</code></summary><p>
diff --git a/src/node/interfaces.cpp b/src/node/interfaces.cpp index bd819cf53e..699dca0a73 100644 --- a/src/node/interfaces.cpp +++ b/src/node/interfaces.cpp @@ -73,9 +73,9 @@ namespace { class ExternalSignerImpl : public interfaces::ExternalSigner { public: - ::ExternalSigner m_signer; ExternalSignerImpl(::ExternalSigner signer) : m_signer(std::move(signer)) {} std::string getName() override { return m_signer.m_name; } + ::ExternalSigner m_signer; }; #endif @@ -378,13 +378,13 @@ public: /* verification progress is unused when a header was received */ 0); })); } - NodeContext* m_context{nullptr}; NodeContext* context() override { return m_context; } void setContext(NodeContext* context) override { m_context = context; } ChainstateManager& chainman() { return *Assert(m_context->chainman); } + NodeContext* m_context{nullptr}; }; bool FillBlock(const CBlockIndex* index, const FoundBlock& block, UniqueLock<RecursiveMutex>& lock, const CChain& active) @@ -702,10 +702,7 @@ public: } void waitForNotificationsIfTipChanged(const uint256& old_tip) override { - if (!old_tip.IsNull()) { - LOCK(::cs_main); - if (old_tip == chainman().ActiveChain().Tip()->GetBlockHash()) return; - } + if (!old_tip.IsNull() && old_tip == WITH_LOCK(::cs_main, return chainman().ActiveChain().Tip()->GetBlockHash())) return; SyncWithValidationInterfaceQueue(); } std::unique_ptr<Handler> handleRpc(const CRPCCommand& command) override @@ -760,9 +757,9 @@ public: return chainman().IsSnapshotActive(); } - NodeContext& m_node; NodeContext* context() override { return &m_node; } ChainstateManager& chainman() { return *Assert(m_node.chainman); } + NodeContext& m_node; };</p></details>
ryanofsky approvedryanofsky commented at 10:26 PM on July 29, 2022: contributorCode review ACK 4bedfd702ad878645c51bea6ee8ce40d8c0bd3da. Changes since last review, applying suggested style & simplifiying first commit. Also avoiding another lock in second commit.
MarcoFalke merged this on Aug 1, 2022MarcoFalke closed this on Aug 1, 2022jonatack deleted the branch on Aug 1, 2022sidhujag referenced this in commit fb0bbd8e26 on Aug 1, 2022bitcoin locked this on Aug 1, 2023ContributorsLabels
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-04-14 21:13 UTC
More mirrored repositories can be found on mirror.b10c.me