Skip to content
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

Early subscribe core signals in transaction table model #121

Merged

Conversation

promag
Copy link
Contributor

@promag promag commented Oct 28, 2020

This fixes the case where transaction notifications arrive between getWalletTxs and subscribeToCoreSignals. Basically notifications are queued until getWalletTxs and wallet rescan complete.

This is also a requirement to call getWalletTxs in a background thread.

Motivated by bitcoin/bitcoin#20241.

@promag
Copy link
Contributor Author

promag commented Oct 28, 2020

Please ignore whitespaces when reviewing.

@promag promag force-pushed the 2020-10-missing-transaction-notifications branch from 9267d2a to 8b65985 Compare November 1, 2020 13:00
@promag
Copy link
Contributor Author

promag commented Nov 1, 2020

Rebased due to conflict with updated #120.

@hebasto
Copy link
Member

hebasto commented Dec 16, 2020

Concept ACK.

@hebasto
Copy link
Member

hebasto commented Jan 4, 2021

This fixes the case where transaction notifications arrive between getWalletTxs and subscribeToCoreSignals.

Yes, the current behavior is indeed buggy. It is easy to verify by patching TransactionTableModel ctor with a delay before subscribeToCoreSignals call.

Copy link
Member

@hebasto hebasto left a comment

Choose a reason for hiding this comment

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

Approach ACK 5d7d363.

src/qt/transactiontablemodel.cpp Outdated Show resolved Hide resolved
src/qt/transactiontablemodel.cpp Outdated Show resolved Hide resolved
src/qt/transactiontablemodel.cpp Outdated Show resolved Hide resolved
src/qt/transactiontablemodel.cpp Show resolved Hide resolved
Copy link
Contributor

@ryanofsky ryanofsky left a comment

Choose a reason for hiding this comment

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

Code review ACK 5d7d363. This looks good but is a pretty confusing change. I think it could be clearer split up into two commits: one pure refactoring commit replacing ShowProgress with DispatchNotifications, and another commit changing initialization order moving the subscribeToCoreSignals call before the refreshWallet call and adding the new DispatchNotifications call at the end of the refreshWallet implementation.

I will say I don't fully understand the motivation for the two refreshMethod related changes. They seem safe but I don't know if they are actually changing behavior now or just setting something up for the future. If they were moved to standalone commit, purpose of the changes could be made more clear either in the commit description or code comments.

In case it helps other reviewers, I found the refactoring changes replacing ShowProgress with DispatchNotifications easier to understand after ignoring whitespace and rereading a previous explanation of the code #120 (comment).

Hebasto's suggestions also all seem reasonable and good. Basically a lot could be made clearer here, but this PR does seems fine to merge in its current form.

This PR might be interesting to people dealing with large wallets that have a lot of transactions, since it seems like it could help move to loading transactions asynchronously without locking up the GUI.

Copy link
Contributor Author

@promag promag left a comment

Choose a reason for hiding this comment

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

Thanks for reviewing, I'll improve readability.

src/qt/transactiontablemodel.cpp Show resolved Hide resolved
@laanwj
Copy link
Member

laanwj commented Jan 27, 2021

This is also a requirement to call getWalletTxs in a background thread.

Concept ACK, thanks for working on that.

Copy link
Member

@hebasto hebasto left a comment

Choose a reason for hiding this comment

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

ACK 5d7d363, agree with #121 (review)

this PR does seems fine to merge in its current form.

@hebasto hebasto added the Bug Something isn't working label Mar 25, 2021
@promag promag force-pushed the 2020-10-missing-transaction-notifications branch from 5d7d363 to 8f16516 Compare April 19, 2021 12:10
Copy link
Contributor Author

@promag promag left a comment

Choose a reason for hiding this comment

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

Rebased and addressed @hebasto review.

src/qt/transactiontablemodel.cpp Outdated Show resolved Hide resolved
src/qt/transactiontablemodel.cpp Outdated Show resolved Hide resolved
src/qt/transactiontablemodel.cpp Outdated Show resolved Hide resolved
@hebasto hebasto added the Wallet label Apr 19, 2021
@hebasto hebasto changed the title qt: Early subscribe core signals in transaction table model Early subscribe core signals in transaction table model Apr 19, 2021
Copy link
Member

@jonatack jonatack left a comment

Choose a reason for hiding this comment

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

Approach ACK modulo that it's a fairly confusing change and separating into more commits may help here (as mentioned above).

src/qt/transactiontablemodel.cpp Outdated Show resolved Hide resolved
src/qt/transactiontablemodel.cpp Outdated Show resolved Hide resolved
@promag promag force-pushed the 2020-10-missing-transaction-notifications branch from 8f16516 to cafef08 Compare April 28, 2021 23:19
@promag
Copy link
Contributor Author

promag commented Apr 28, 2021

Ok, I've tried to split in decent commits.

{
for (const auto& wtx : wallet.getWalletTxs()) {
if (TransactionRecord::showTransaction()) {
cachedWallet.append(TransactionRecord::decomposeTransaction(wtx));
}
}
}
m_loaded = true;
Copy link
Member

Choose a reason for hiding this comment

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

3bccd50 nit, can drop extra brackets

diff --git a/src/qt/transactiontablemodel.cpp b/src/qt/transactiontablemodel.cpp
index 0175c88e7..8dc6d4c40 100644
--- a/src/qt/transactiontablemodel.cpp
+++ b/src/qt/transactiontablemodel.cpp
@@ -110,11 +110,9 @@ public:
     void refreshWallet(interfaces::Wallet& wallet)
     {
         assert(!m_loaded);
-        {
-            for (const auto& wtx : wallet.getWalletTxs()) {
-                if (TransactionRecord::showTransaction()) {
-                    cachedWallet.append(TransactionRecord::decomposeTransaction(wtx));
-                }
+        for (const auto& wtx : wallet.getWalletTxs()) {
+            if (TransactionRecord::showTransaction()) {
+                cachedWallet.append(TransactionRecord::decomposeTransaction(wtx));
             }
         }
         m_loaded = true;

Copy link
Member

Choose a reason for hiding this comment

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

(similar to the change in the last commit, git show cafef080a2e --ignore-all-space)

bool invoked = QMetaObject::invokeMethod(parent, "setProcessingQueuedTransactions", Qt::QueuedConnection, Q_ARG(bool, true));
assert(invoked);
}
for (unsigned int i = 0; i < vQueueNotifications.size(); ++i)
{
Copy link
Member

Choose a reason for hiding this comment

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

cafef08 nit, while removing the brackets in this commit could also

diff --git a/src/qt/transactiontablemodel.cpp b/src/qt/transactiontablemodel.cpp
index 0175c88e7..734605a47 100644
--- a/src/qt/transactiontablemodel.cpp
+++ b/src/qt/transactiontablemodel.cpp
@@ -739,8 +739,7 @@ void TransactionTablePriv::DispatchNotifications()
         bool invoked = QMetaObject::invokeMethod(parent, "setProcessingQueuedTransactions", Qt::QueuedConnection, Q_ARG(bool, true));
         assert(invoked);
     }
-    for (unsigned int i = 0; i < vQueueNotifications.size(); ++i)
-    {
+    for (unsigned int i = 0; i < vQueueNotifications.size(); ++i) {

Copy link
Member

@jonatack jonatack left a comment

Choose a reason for hiding this comment

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

tACK cafef08

happy to re-ACK for the above

Copy link
Member

@hebasto hebasto left a comment

Choose a reason for hiding this comment

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

Thanks for splitting commits! Much easier to review.

bool fQueueNotifications = false;
/** True when model finishes loading all wallet transactions on start */
bool m_loaded = false;
/** True when transactions are being notified, for instance when scanning */
Copy link
Member

@hebasto hebasto Apr 29, 2021

Choose a reason for hiding this comment

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

It could be just my bad English, but it seems should be "... are not being notified", no?

If I'm correct, maybe re-word the comment in positive one?

Or maybe we think about different notifications: (a) from the node vs (b) to a user?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Right, I'll rephrase.

Copy link
Contributor

Choose a reason for hiding this comment

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

In commit "qt: Refactor ShowProgress to DispatchNotifications" (c6cbdf1)

re: #121 (comment)

Right, I'll rephrase.

If you're still planning to update this, my attempt at a comment would be: "This will be true when blocks in the chain are being scanned for new transactions, and transaction notification popups should be suppressed until the scan is done. It can be true even after m_loaded is true if a rescan has been triggered." I think I would also call this m_delay_notifications instead of m_loading because it can be true when m_loaded is also true, but feel free to stick with whatever name you prefer.

std::vector< TransactionNotification > vQueueNotifications;

void NotifyTransactionChanged(const uint256 &hash, ChangeType status);
void ShowProgress(const std::string &title, int nProgress);
void DispatchNotifications();
Copy link
Member

Choose a reason for hiding this comment

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

A doxygen comment?

Comment on lines +726 to 727
if (!m_loaded || m_loading)
{
Copy link
Member

Choose a reason for hiding this comment

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

style nit:

Suggested change
if (!m_loaded || m_loading)
{
if (!m_loaded || m_loading) {

Copy link
Contributor

@ryanofsky ryanofsky left a comment

Choose a reason for hiding this comment

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

Code review ACK cafef08. Only change since last review is splitting commits and replacing m_progress with m_loading.

Thanks for the updates! I think this change is much easier to understand now.

It would be good to clarify in the PR description what exactly is meant by "This fixes the case where transaction notifications arrive between getWalletTxs and subscribeToCoreSignals." It's not clear from the description what the old behavior was and what the new behavior is.

IIUC, the problem was that notifications about new transactions discovered while the wallet was being loaded were dropped previously, and now they are shown?

bool fQueueNotifications = false;
/** True when model finishes loading all wallet transactions on start */
bool m_loaded = false;
/** True when transactions are being notified, for instance when scanning */
Copy link
Contributor

Choose a reason for hiding this comment

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

In commit "qt: Refactor ShowProgress to DispatchNotifications" (c6cbdf1)

re: #121 (comment)

Right, I'll rephrase.

If you're still planning to update this, my attempt at a comment would be: "This will be true when blocks in the chain are being scanned for new transactions, and transaction notification popups should be suppressed until the scan is done. It can be true even after m_loaded is true if a rescan has been triggered." I think I would also call this m_delay_notifications instead of m_loading because it can be true when m_loaded is also true, but feel free to stick with whatever name you prefer.

Copy link
Contributor

@meshcollider meshcollider left a comment

Choose a reason for hiding this comment

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

Code review ACK cafef08

@hebasto hebasto merged commit 3ec033e into bitcoin-core:master May 26, 2021
@promag promag deleted the 2020-10-missing-transaction-notifications branch May 26, 2021 10:38
sidhujag pushed a commit to syscoin/syscoin that referenced this pull request May 27, 2021
gwillen pushed a commit to ElementsProject/elements that referenced this pull request Jun 1, 2022
@bitcoin-core bitcoin-core locked as resolved and limited conversation to collaborators Aug 16, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Bug Something isn't working Wallet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants