-
Notifications
You must be signed in to change notification settings - Fork 287
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
refactor: Make BitcoinCore class reusable #381
Conversation
src/qt/bitcoincore.cpp
Outdated
@@ -0,0 +1,66 @@ | |||
// Copyright (c) 2014-2021 The Bitcoin Core developers |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Begging my fellow colleagues for review :
|
This seems good. Also maybe if (Longer term, I think these asynchronous executor / activity classes are mostly unnecessary and could be replaced with an AsyncUpdate or similar utility, but that's beyond the scope of this PR.) |
Many thanks for feedback. Which name could also describe that this class is also used to provide a shutdown activity? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code review ACK 7ec5526
Many thanks for feedback. Which name could also describe that this class is also used to provide a shutdown activity?
Personally I like InitExecutor
. Shutdown just seems like part of initialization. Maybe StartupExecutor
? 🤷 I do think pretty much any name would be more descriptive than a class or file called bitcoin core. But feel free to keep the current name or choose any name that seems good to you.
src/qt/bitcoin.cpp
Outdated
BitcoinCore::~BitcoinCore() | ||
{ | ||
qDebug() << __func__ << ": Stopping thread"; | ||
m_thread.quit(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In commit "qt: Add BitcoinCore::m_thread member" (6b769d9)
I'm not sure if it matters but a possible concern is that when bitcoinapplication is destroyed, this thread wait now happens after the window and platform objects are instead of before they are deleted in ~BitcoinApplication. This may be safe but it might be safer to make sure these objects are not deleted while the thread is running and maybe working. You could do this by adding m_core.reset()
to the beginning of ~BitcoinApplication. But fine to skip this if we know the thread will already be done working when ~BitcoinApplication runs.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! Updated.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code review ACK 0c7667f. Thanks! Just renaming and other suggested changes since last review
src/qt/bitcoin.h
Outdated
@@ -112,7 +116,7 @@ public Q_SLOTS: | |||
void windowShown(BitcoinGUI* window); | |||
|
|||
private: | |||
QThread *coreThread; | |||
std::unique_ptr<BitcoinCore> m_executor; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In commit "qt: Add BitcoinCore::m_thread member" (efacacb)
Not important, but this could use std::optional
instead of std::unique_ptr
to avoid a dynamic allocation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank! Updated.
This change makes BitcoinCore self-contained to improve its re-usability. BitcoinApplication::coreThread member is now unused, and removed.
-BEGIN VERIFY SCRIPT- sed -i -e 's/BitcoinCore/InitExecutor/g' src/qt/bitcoin.* -END VERIFY SCRIPT-
This change makes InitExecutor class re-usable by an alternative GUI, e.g., QML-based one.
Originally I called the class "BitcoinCore", not because the software is called like that (not sure if it even did at the time?), but because it wraps an instance of the core (=non-gui) functionality, to be executed in its own thread. But like (I don't mind it being renamed, but it was not as silly as a "let's call a class the same name as the software" at the time) |
Yeah I figured "core" was a synonym for "init". Just makes sense to make the old name more descriptive when the class is moved and more widely exposed now. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code review ACK 8169fc4. Only change is switching from m_executor
from pointer to optional type (thanks for update!)
Well not "init", more like "root model object" (e.g. I think it was supposed to create and manage ClientModel, WalletModels etc). But it's okay, I'm fine with naming it after what it is now doing. ACK 8169fc4 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code review ACK 8169fc4.
This PR makes the
BitcoinCore
class reusable, i.e., it can be used by the widget-based GUI or by the QML-based one, and it makes the divergence between these two repos minimal.The small benefit to the current branch is more structured code.
Actually, this PR is ported from bitcoin-core/gui-qml#10.
The example of the re-using of the
BitcoinCore
class is bitcoin-core/gui-qml#11.