-
Notifications
You must be signed in to change notification settings - Fork 38.6k
qt: Remove redundant WalletController::addWallet slot #16349
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
Conversation
|
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers. ConflictsReviewers, this pull request conflicts with the following ones:
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. |
|
Can you explain why it fixes? |
|
Concept ACK. I've tested that this PR fixes #15453 (running with I agree with promag that more of an explanation (also added to the PR body) would be good. Can you also try improve the commit title. |
Trying to investigate the #15453 bug I've downloaded Qt 5.7.1, but failed to build the Bitcoin Core. I even failed to start Qt Creator (there are some similar messages on Qt bug tracker). Regarding the code patch: the private slot |
With my pleasure. What title could you suggest? |
Maybe: Then you could extend the body text to be:
|
|
So this is only an issue with qt5.7.x? If so, it could be tested by reverting depends to 2fca656 locally. |
|
@promag regarding the IRC discussion:
|
1b83875 to
d665a5b
Compare
|
As #15453 is fixed in #16348 (comment) I have updated the OP and the commit message. Please, label this PR as refactoring. |
promag
left a comment
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.
Concept ACK, will test.
d665a5b to
225ff6b
Compare
|
Rebased on top of #16348. |
|
@ryanofsky Would you mind reviewing this PR? |
src/qt/walletcontroller.cpp
Outdated
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.
Could keep this comment.
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.
Done.
src/qt/walletcontroller.cpp
Outdated
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.
Just to be clear, this would work even without qRegisterMetaType<WalletModel*>() added in #16348?
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.
Yes.
225ff6b to
41c900a
Compare
|
s/signal/slot in PR title and commit message? |
41c900a to
6285a31
Compare
Sure ;) Thank you. |
|
ACK 6285a31. |
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 d665a5bd8c2df38151dd9c2642ef0be14eaf4825. This seems good as a pure code simplification since the previous code was wild, but the PR description isn't understandable to me, and I can't figure out what the thread affinities and parent child associations are used for here. I'd recommend rewriting the PR description to reflect current state of things, and adding better comments.
Specifically, I don't understand why the WalletController::setParent call is necessary. Where are parents and children used here? If the setParent call isn't necessary, then the moveToThread call doesn't seem necessary either. I don't see any signals being sent to WalletController objects, only signals emitted from WalletController objects, so I don't know how WalletController thread affinity would be relevant to anything.
In general, it seems not ideal that wallet and RPC threads would call GUI methods and create QObjects. It would be better if wallet notifications just emitted signals that got handled asynchronously in the GUI. That way, wallet code wouldn't be blocked and GUI code wouldn't have to be written to deal with external threads.
|
|
||
| // Instantiate model and register it. | ||
| WalletModel* wallet_model = new WalletModel(std::move(wallet), m_node, m_platform_style, m_options_model, nullptr); | ||
| // Handler callback runs in a different thread so fix wallet model thread affinity. |
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.
This comment is very vague. In particular it's not clear what "handler callback runs in a different thread" is referring to. If I'm understanding this correctly, I think a comment that specifically says which threads the object is being moved to and from would be more helpful:
// Move WalletModel object to the thread that created the WalletController
// object (GUI main thread), instead of the current thread, which could be
// an outside wallet thread or RPC thread sending a LoadWallet notification.
//
// This ensures queued signals sent to the WalletModel object will be
// handled on the GUI event loop, see
// https://doc.qt.io/qt-5/threads-qobject.html#signals-and-slots-across-threadsThere 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.
This comment is very vague.
Agree, but I'd leave it to preserve ACKs.
| WalletModel* wallet_model = new WalletModel(std::move(wallet), m_node, m_platform_style, m_options_model, nullptr); | ||
| // Handler callback runs in a different thread so fix wallet model thread affinity. | ||
| wallet_model->moveToThread(thread()); | ||
| wallet_model->setParent(this); |
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.
Curious: Is this setParent call actually necessary for anything? Maybe consider dropping it or adding a comment that says why it's useful.
If you will keep this line, it'd also be helpful to have a comment explaining why we are passing parent=nullptr to the constructor above, and then changing the parent later. I am guessing from https://doc.qt.io/qt-5/qobject.html#thread-affinity, that it is because "All QObjects must live in the same thread as their parent" and so this is necessary to avoid a "QObject: Cannot create children for a parent that is in a different thread" error.
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.
Exactly, can't set parent on constructor because parent thread can be different.
setParent is not necessary at the moment because (afaict) the wallet is always unloaded here:
bitcoin/src/qt/walletcontroller.cpp
Line 104 in 8046a3e
| connect(wallet_model, &WalletModel::unload, [this, wallet_model] { |
However I think it's good habit to set ownership, so at least the following would release all models:
Line 216 in 8046a3e
| delete m_wallet_controller; |
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.
PR description has been updated.
| // Re-emit coinsSent signal from wallet model. | ||
| connect(wallet_model, &WalletModel::coinsSent, this, &WalletController::coinsSent); | ||
|
|
||
| // Notify walletAdded signal on the GUI thread. |
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.
It seems like this comment is obsolete and should be dropped.
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.
Agree, but I'd leave it to preserve ACKs.
| } else { | ||
| // Handler callback runs in a different thread so fix wallet model thread affinity. | ||
| wallet_model->moveToThread(thread()); | ||
| bool invoked = QMetaObject::invokeMethod(this, "addWallet", Qt::QueuedConnection, Q_ARG(WalletModel*, wallet_model)); |
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.
It seems good to get rid of this, but I can't figure out why it was ever necessary to call addWallet here with invokeMethod instead of directly.
@ryanofsky IIRC I had some problems with this because of From #16349 (comment)
At the time the idea was to allow (and prevent issues) But agree, this code can be improved. |
ryanofsky
left a comment
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.
utACK 6285a31. Only change since last review is rebasing and restoring a deleted comment. I do think the comments I suggested last review would be better than this one, but this is at least better than before.
|
utACK 6285a31 |
… slot 6285a31 Remove redundant WalletController::addWallet slot (Hennadii Stepanov) Pull request description: ~~Fix bitcoin#15453.~~ It is fixed by bitcoin#16348 (comment) The _only_ reason of these lines on master (8c69fae) https://github.com/bitcoin/bitcoin/blob/2679bb8919b5089f8067ccfd94f766747b8df671/src/qt/walletcontroller.cpp#L121-L128 is to `Q_EMIT walletAdded(wallet_model);` in a thread-safe manner; This PR makes this in a line of code: https://github.com/bitcoin/bitcoin/blob/1b83875006749d79916af0197bed65aecdc7ff17/src/qt/walletcontroller.cpp#L121 EDITED: To establish the ownership of a new `WalletModel` object is not necessary on the master (bitcoin#16349 (comment) by **promag**). But: > it's good habit to set ownership And I agree. It is a safe practice. ACKs for top commit: promag: ACK 6285a31. jonasschnelli: utACK 6285a31 ryanofsky: utACK 6285a31. Only change since last review is rebasing and restoring a deleted comment. I do think the comments I suggested last review would be better than this one, but this is at least better than before. Tree-SHA512: 90370cb1fe853b84dd16c3781ba4f97f3f4deca56bba0203e457f37b3220fd13228cf8495fd882ff18b7c782c27544cc2e7a88aaec5b69b9ef6d8626bdaaf332
… slot 6285a31 Remove redundant WalletController::addWallet slot (Hennadii Stepanov) Pull request description: ~~Fix bitcoin#15453.~~ It is fixed by bitcoin#16348 (comment) The _only_ reason of these lines on master (8c69fae) https://github.com/bitcoin/bitcoin/blob/2679bb8919b5089f8067ccfd94f766747b8df671/src/qt/walletcontroller.cpp#L121-L128 is to `Q_EMIT walletAdded(wallet_model);` in a thread-safe manner; This PR makes this in a line of code: https://github.com/bitcoin/bitcoin/blob/1b83875006749d79916af0197bed65aecdc7ff17/src/qt/walletcontroller.cpp#L121 EDITED: To establish the ownership of a new `WalletModel` object is not necessary on the master (bitcoin#16349 (comment) by **promag**). But: > it's good habit to set ownership And I agree. It is a safe practice. ACKs for top commit: promag: ACK 6285a31. jonasschnelli: utACK 6285a31 ryanofsky: utACK 6285a31. Only change since last review is rebasing and restoring a deleted comment. I do think the comments I suggested last review would be better than this one, but this is at least better than before. Tree-SHA512: 90370cb1fe853b84dd16c3781ba4f97f3f4deca56bba0203e457f37b3220fd13228cf8495fd882ff18b7c782c27544cc2e7a88aaec5b69b9ef6d8626bdaaf332
Summary: bitcoin/bitcoin@6285a31 --- Depends on D6183 Backport of Core [[bitcoin/bitcoin#16349 | PR16349]] Test Plan: ninja check ./srt/qt/bitcoin-qt -regtest check the UI works as expected, close the default wallet, open the default wallet Reviewers: #bitcoin_abc, deadalnix Reviewed By: #bitcoin_abc, deadalnix Differential Revision: https://reviews.bitcoinabc.org/D6184
1a85aa3 Remove redundant WalletController::addWallet slot (Hennadii Stepanov) Pull request description: ~~Fix #15453.~~ It is fixed by bitcoin/bitcoin#16348 (comment) The _only_ reason of these lines on master (03465aa) https://github.com/bitcoin/bitcoin/blob/8605f6a4c7cc8cdbe7eb72600b62fa18abba372e/src/qt/walletcontroller.cpp#L121-L128 is to `Q_EMIT walletAdded(wallet_model);` in a thread-safe manner; This PR makes this in a line of code: https://github.com/bitcoin/bitcoin/blob/1b83875006749d79916af0197bed65aecdc7ff17/src/qt/walletcontroller.cpp#L121 EDITED: To establish the ownership of a new `WalletModel` object is not necessary on the master (bitcoin/bitcoin#16349 (comment) by **promag**). But: > it's good habit to set ownership And I agree. It is a safe practice. ACKs for top commit: promag: ACK 1a85aa3. jonasschnelli: utACK 1a85aa3 ryanofsky: utACK 1a85aa3. Only change since last review is rebasing and restoring a deleted comment. I do think the comments I suggested last review would be better than this one, but this is at least better than before. Tree-SHA512: 90370cb1fe853b84dd16c3781ba4f97f3f4deca56bba0203e457f37b3220fd13228cf8495fd882ff18b7c782c27544cc2e7a88aaec5b69b9ef6d8626bdaaf332
… slot 6285a31 Remove redundant WalletController::addWallet slot (Hennadii Stepanov) Pull request description: ~~Fix bitcoin#15453.~~ It is fixed by bitcoin#16348 (comment) The _only_ reason of these lines on master (8c69fae) https://github.com/bitcoin/bitcoin/blob/2679bb8919b5089f8067ccfd94f766747b8df671/src/qt/walletcontroller.cpp#L121-L128 is to `Q_EMIT walletAdded(wallet_model);` in a thread-safe manner; This PR makes this in a line of code: https://github.com/bitcoin/bitcoin/blob/1b83875006749d79916af0197bed65aecdc7ff17/src/qt/walletcontroller.cpp#L121 EDITED: To establish the ownership of a new `WalletModel` object is not necessary on the master (bitcoin#16349 (comment) by **promag**). But: > it's good habit to set ownership And I agree. It is a safe practice. ACKs for top commit: promag: ACK 6285a31. jonasschnelli: utACK 6285a31 ryanofsky: utACK 6285a31. Only change since last review is rebasing and restoring a deleted comment. I do think the comments I suggested last review would be better than this one, but this is at least better than before. Tree-SHA512: 90370cb1fe853b84dd16c3781ba4f97f3f4deca56bba0203e457f37b3220fd13228cf8495fd882ff18b7c782c27544cc2e7a88aaec5b69b9ef6d8626bdaaf332
Fix #15453.It is fixed by #16348 (comment)The only reason of these lines on master (8c69fae)
bitcoin/src/qt/walletcontroller.cpp
Lines 121 to 128 in 2679bb8
is to
Q_EMIT walletAdded(wallet_model);in a thread-safe manner;This PR makes this in a line of code:
https://github.com/bitcoin/bitcoin/blob/1b83875006749d79916af0197bed65aecdc7ff17/src/qt/walletcontroller.cpp#L121
EDITED:
To establish the ownership of a new
WalletModelobject is not necessary on the master (#16349 (comment) by promag).But:
And I agree. It is a safe practice.