Skip to content

Conversation

jonatack
Copy link
Member

@jonatack jonatack commented Jan 25, 2022

Simplify the index base and child classes and improve encapsulation and clarity by making fully overridden virtual member functions private. In the child classes, this allows having only public and private members. This change also help contributors add virtual functions into the correct section. Also rename the GetName() getters to GetIndexName() for clarity and easier grepping/reviewing.

Some context:

A base class virtual function doesn't need to be accessible to be overridden, but it can only be private if fully overridden, e.g. no inherited base implementation is used by the child classes.

References:

  • https://en.cppreference.com/w/cpp/language/virtual: "Base::vf does not need to be accessible or visible to be overridden. (Base::vf can be declared private, or Base can be inherited using private inheritance.)"

  • "An implementation member should be protected if it provides an operation or data that a derived class will need to use in its own implementation. Otherwise, implementation members should be private." - C++ Primer (Lippman, Lajoie, Moo)

  • Herb Sutter in http://www.gotw.ca/publications/mill18.htm: "Make virtual functions private, and only if derived classes need to invoke the base implementation of a virtual function, make the virtual function protected. Prefer to make interfaces non-virtual using the Template pattern."

@DrahtBot
Copy link
Contributor

DrahtBot commented Jan 26, 2022

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

Reviews

See the guideline for information on the review process.

Type Reviewers
Concept ACK PastaPastaPasta, aureleoules
Stale ACK RandyMcMillan, w0xlt, brunoerg

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:

  • #25494 (indexes: Stop using node internal types 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.

Copy link
Contributor

@PastaPastaPasta PastaPastaPasta left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

utACK 732fafc, it makes sense to me to make stuff private instead of protected where possible

@RandyMcMillan
Copy link
Contributor

RandyMcMillan commented Feb 12, 2022

commit 7a8d2c0 scripted-diff tACK
Recreated here: https://cirrus-ci.com/build/4937613508345856 (with gsed on macOS)
Tested on macOS (Darwin ₿ 19.6.0 Darwin Kernel Version 19.6.0: x86_64)

@RandyMcMillan
Copy link
Contributor

RandyMcMillan commented Feb 12, 2022

commit 5743fa6 - Approach ACK
https://cirrus-ci.com/build/6508504977506304

NIT: since this is a refactor - Can we bring base.h into clang-format compliance?
https://cirrus-ci.com/build/5869934608646144
commit RandyMcMillan@22f74b8

diff --git a/src/index/base.h b/src/index/base.h
index 9c4d67865a..44d87f8556 100644
--- a/src/index/base.h
+++ b/src/index/base.h
@@ -33,7 +33,7 @@ protected:
      * A locator is used instead of a simple hash of the chain tip because blocks
      * and block index entries may not be flushed to disk until after this database
      * is updated.
-    */
+     */
     class DB : public CDBWrapper
     {
     public:

@jonatack
Copy link
Member Author

jonatack commented Feb 13, 2022

Thanks for reviewing @RandyMcMillan. It isn't part of the changes here but happy to if I have to repush. Edit: done.

@jonatack jonatack force-pushed the move-index-class-members-from-protected-to-private branch 2 times, most recently from a1fa9ae to 7785095 Compare March 9, 2022 14:10
@jonatack
Copy link
Member Author

jonatack commented Mar 9, 2022

Rebased per git range-diff 7003b6a 732fafc 7785095 and took suggestion in #24150 (comment).

Invalidates previous ACKs by @PastaPastaPasta and @RandyMcMillan; mind re-ACKing?

@jonatack
Copy link
Member Author

@PastaPastaPasta and @RandyMcMillan, would you mind re-ACKing here?

Copy link
Contributor

@PastaPastaPasta PastaPastaPasta left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

re-utACK

@RandyMcMillan
Copy link
Contributor

tACK 7785095

tested on

Darwin ₿ 19.6.0 Darwin Kernel Version 19.6.0: Sun Nov 14 19:58:51 PST 2021; root:xnu-6153.141.50~1/RELEASE_X86_64 x86_64

Copy link
Contributor

@brunoerg brunoerg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ACK 7785095

Agreed on updating them to private and changing from GetName to GetIndexName seems better to understand it.

@jonatack jonatack force-pushed the move-index-class-members-from-protected-to-private branch from 7785095 to ef27869 Compare April 28, 2022 14:21
@jonatack jonatack force-pushed the move-index-class-members-from-protected-to-private branch from ef27869 to 6251ba4 Compare April 28, 2022 17:18
@jonatack jonatack force-pushed the move-index-class-members-from-protected-to-private branch 2 times, most recently from cff04a7 to 4fdd404 Compare April 28, 2022 17:22
@jonatack
Copy link
Member Author

jonatack commented Apr 28, 2022

Rebased (see git range-diff dabec990 cff04a7 4fdd404) and added 4fdd404 left over from an unintentional reverted change in #21726.

@PastaPastaPasta, @RandyMcMillan and @brunoerg, mind re-ACKing? Thanks ❤️

Copy link
Contributor

@brunoerg brunoerg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

re-ACK 4fdd404

Copy link
Contributor

@w0xlt w0xlt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

crACK f5e985b

@brunoerg
Copy link
Contributor

re-ACK f5e985b

in the class declaration by access and characteristic
for clarity and documentation purposes.
@jonatack jonatack force-pushed the move-index-class-members-from-protected-to-private branch from f5e985b to 3f26a36 Compare May 20, 2022 10:05
@jonatack
Copy link
Member Author

jonatack commented May 20, 2022

Updated the motivation in the PR description and simplified the last commit by dropping the class-to-struct change, per git diff f5e985b 3f26a36

--- a/src/index/base.h
+++ b/src/index/base.h
@@ -57,8 +57,9 @@ protected:
      * and block index entries may not be flushed to disk until after this database
      * is updated.
      */
-    struct DB : public CDBWrapper
+    class DB : public CDBWrapper
     {
+    public:
         DB(const fs::path& path, size_t n_cache_size,
            bool f_memory = false, bool f_wipe = false, bool f_obfuscate = false);

@@ -26,14 +26,37 @@ struct IndexSummary {
*/
class BaseIndex : public CValidationInterface
{
public:
/// Destructor interrupts sync thread if running and blocks until it exits.
virtual ~BaseIndex();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You don't need to mark it virtual, there is a bug and it is destructor of CValidationInterface should marked as virtual

@DrahtBot
Copy link
Contributor

🐙 This pull request conflicts with the target branch and needs rebase.

Want to unsubscribe from rebase notifications on this pull request? Just convert this pull request to a "draft".

@achow101
Copy link
Member

Are you still working on this?

@achow101
Copy link
Member

Closing this as it has not had any activity in a while. If you are interested in continuing work on this, please leave a comment so that it can be reopened.

@achow101 achow101 closed this Nov 10, 2022
@jonatack
Copy link
Member Author

Are you still working on this?

Yes. Might be useful to re-open rather than opening a new one, as there is discussion and some feedback to address.

@achow101 achow101 reopened this Nov 10, 2022
Copy link
Contributor

@aureleoules aureleoules left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Concept ACK

@fanquake fanquake marked this pull request as draft February 6, 2023 14:58
@fanquake
Copy link
Member

fanquake commented Feb 6, 2023

Moved to draft for now. Was reopened 3 months ago to continue work / follow up on discussion, but hasn't been touched. Has needed rebase for 6 months.

@jonatack
Copy link
Member Author

Closing temporarily so that I can re-open it -- am still interested to work on this.

@jonatack jonatack closed this Apr 25, 2023
@bitcoin bitcoin locked and limited conversation to collaborators Apr 24, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.