refactor: Make BitcoinCore class reusable#381
Conversation
| @@ -0,0 +1,66 @@ | |||
| // Copyright (c) 2014-2021 The Bitcoin Core developers | |||
|
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? |
ryanofsky
left a comment
There was a problem hiding this comment.
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.
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.
src/qt/bitcoin.h
Outdated
|
|
||
| private: | ||
| QThread *coreThread; | ||
| std::unique_ptr<BitcoinCore> m_executor; |
There was a problem hiding this comment.
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
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. |
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 |

This PR makes the
BitcoinCoreclass 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
BitcoinCoreclass is bitcoin-core/gui-qml#11.