Skip to content

Conversation

hebasto
Copy link
Member

@hebasto hebasto commented Nov 9, 2019

On master (a7aec7a) this connection

connect(model, &ClientModel::mempoolSizeChanged, this, &RPCConsole::setMempoolSize);
fails due to ClientModel::mempoolSizeChanged() signal has unregistered parameter type size_t:
void mempoolSizeChanged(long count, size_t mempoolSizeInBytes);

More:

$ QT_FATAL_WARNINGS=1 lldb src/qt/bitcoin-qt -- -debug=qt
...
(lldb) bt
* thread #17, name = 'QThread', stop reason = signal SIGABRT
  * frame #0: 0x00007ffff35fce97 libc.so.6`__GI_raise(sig=2) at raise.c:51
    frame #1: 0x00007ffff35fe801 libc.so.6`__GI_abort at abort.c:79
    frame #2: 0x00007ffff5901352 libQt5Core.so.5`QMessageLogger::warning(char const*, ...) const + 354
    frame #3: 0x00007ffff5b216fe libQt5Core.so.5`___lldb_unnamed_symbol2329$$libQt5Core.so.5 + 334
    frame #4: 0x00007ffff5b2456d libQt5Core.so.5`QMetaObject::activate(QObject*, int, int, void**) + 1933
    frame #5: 0x000055555566872e bitcoin-qt`ClientModel::mempoolSizeChanged(this=<unavailable>, _t1=<unavailable>, _t2=<unavailable>) at moc_clientmodel.cpp:260
...

debug.log:

[] GUI: QObject::connect: Cannot queue arguments of type 'size_t'
(Make sure 'size_t' is registered using qRegisterMetaType().)

This PR fixes it.

Refs:


Side NOTE: Also I believe this line

Q_DECLARE_METATYPE(CAmount)
is redundant since long CAmount is a typedef.

@hebasto
Copy link
Member Author

hebasto commented Nov 9, 2019

friendly ping @promag

@DrahtBot DrahtBot added the GUI label Nov 9, 2019
@fanquake fanquake requested a review from promag November 9, 2019 14:56
@fanquake fanquake added this to the 0.19.1 milestone Nov 9, 2019
@fanquake
Copy link
Member

fanquake commented Nov 9, 2019

Tested that 40d2256 fixes the issue. Looks like the mempool info in the debug window has been broken since #17135 was merged, so is part of 0.19.0. We can backport this into 0.19.1.

master(a7aec7a):
master

pr(40d2256):
pr

@hebasto
Copy link
Member Author

hebasto commented Nov 9, 2019

Looks like the mempool info in the debug window has been broken since #16348 was merged

It seems there was another commit (not from #16348) that changed the GUI thread model and, as consequence, the connection type from Qt::DirectConnection to Qt::QueuedConnection.

Copy link
Contributor

@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.

Not sure but I think the bug was introduced in #17135.

I'd just add the new qRegisterMetaType considering this is a fix.

@@ -430,16 +430,19 @@ int GuiMain(int argc, char* argv[])

BitcoinApplication app(*node);

// Register meta types used for QMetaObject::invokeMethod
qRegisterMetaType< bool* >();
Copy link
Member

Choose a reason for hiding this comment

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

No need to touch formatting.

qRegisterMetaType< CAmount >("CAmount");
qRegisterMetaType< std::function<void()> >("std::function<void()>");
// Register typedefs (see http://qt-project.org/doc/qt-5/qmetatype.html#qRegisterMetaType)
// IMPORTANT: if CAmount is no longer a typedef use the normal variant above (see https://doc.qt.io/qt-5/qmetatype.html#qRegisterMetaType-1)
Copy link
Member

Choose a reason for hiding this comment

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

size_t is also using the typedef variant here now too?

Copy link
Member Author

Choose a reason for hiding this comment

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

size_t is missed intentionally in this comment, as it is C++'s typedef, not ours.

@laanwj
Copy link
Member

laanwj commented Nov 10, 2019

ACK.

It's kind of annoying that this can't be a compile-time error (as it's essentially static). Would it help to add checks to the return values of connect everywhere, to prevent something like this from silently happening again? (not necessarily in this PR but in general)

@promag
Copy link
Contributor

promag commented Nov 10, 2019

I think the warning is on emit, not on connect.

@hebasto
Copy link
Member Author

hebasto commented Nov 10, 2019

I think the warning is on emit, not on connect.

True.

@laanwj
Copy link
Member

laanwj commented Nov 10, 2019

Wait, so there's no way to do static or dynamic checking on this at connect time? That's kind of sucky.

It would be good to add a developer note on this, that Qt's signal/slot deceptively look like functions, but the arguments are marshalled internally. This restrict the set of types that can be passed that way.
And to be really careful around this.

@@ -430,16 +430,19 @@ int GuiMain(int argc, char* argv[])

BitcoinApplication app(*node);

// Register meta types used for QMetaObject::invokeMethod
Copy link
Member

Choose a reason for hiding this comment

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

I don't like how this commit rewrites and reformats this entire section to add a statement. I'd prefer to split this into two commits: one that adds the missing line, and one that's purely restyling / comment updates.

Copy link
Contributor

Choose a reason for hiding this comment

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

Like I said, I also prefer a single line addition.

Copy link
Member Author

Choose a reason for hiding this comment

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

I'd prefer to split this into two commits: one that adds the missing line, and one that's purely restyling / comment updates.

Done.

@hebasto hebasto force-pushed the 20191109-fix-signal-argument-type branch from 40d2256 to 1828c6f Compare November 10, 2019 10:11
@hebasto
Copy link
Member Author

hebasto commented Nov 10, 2019

Split in two commits as requested by @laanwj.

@laanwj
Copy link
Member

laanwj commented Nov 10, 2019

Thanks!
Tested ACK 1828c6f

laanwj added a commit that referenced this pull request Nov 10, 2019
1828c6f refactor: Styling w/ clang-format, comment update (Hennadii Stepanov)
88a94f7 qt: Fix missing qRegisterMetaType for size_t (Hennadii Stepanov)

Pull request description:

  On master (a7aec7a) this connection https://github.com/bitcoin/bitcoin/blob/a7aec7ad97949a82f870c033d8fd8b65d772eacb/src/qt/rpcconsole.cpp#L587 fails due to `ClientModel::mempoolSizeChanged()` signal has unregistered parameter type `size_t`: https://github.com/bitcoin/bitcoin/blob/a7aec7ad97949a82f870c033d8fd8b65d772eacb/src/qt/clientmodel.h#L102

  More:
  ```
  $ QT_FATAL_WARNINGS=1 lldb src/qt/bitcoin-qt -- -debug=qt
  ...
  (lldb) bt
  * thread #17, name = 'QThread', stop reason = signal SIGABRT
    * frame #0: 0x00007ffff35fce97 libc.so.6`__GI_raise(sig=2) at raise.c:51
      frame #1: 0x00007ffff35fe801 libc.so.6`__GI_abort at abort.c:79
      frame #2: 0x00007ffff5901352 libQt5Core.so.5`QMessageLogger::warning(char const*, ...) const + 354
      frame #3: 0x00007ffff5b216fe libQt5Core.so.5`___lldb_unnamed_symbol2329$$libQt5Core.so.5 + 334
      frame #4: 0x00007ffff5b2456d libQt5Core.so.5`QMetaObject::activate(QObject*, int, int, void**) + 1933
      frame #5: 0x000055555566872e bitcoin-qt`ClientModel::mempoolSizeChanged(this=<unavailable>, _t1=<unavailable>, _t2=<unavailable>) at moc_clientmodel.cpp:260
  ...

  ```

  `debug.log`:
  ```
  [] GUI: QObject::connect: Cannot queue arguments of type 'size_t'
  (Make sure 'size_t' is registered using qRegisterMetaType().)
  ```

  This PR fixes it.

  Refs:
  - [Qt docs: qRegisterMetaType](https://doc.qt.io/qt-5/qmetatype.html#qRegisterMetaType)
  - #16348

  ---

  Side NOTE: Also I believe this line https://github.com/bitcoin/bitcoin/blob/a7aec7ad97949a82f870c033d8fd8b65d772eacb/src/qt/bitcoin.cpp#L63 is redundant since long `CAmount` is a `typedef`.

ACKs for top commit:
  laanwj:
    Tested ACK 1828c6f

Tree-SHA512: 2c7f9fe6a5ae70f2e1dd86b07f95d4b00c85c5706a9d722f063f80beb71880d012ec46556963fb1544c2af53d006936c2f7612eae60d9193f67db62ba3d86129
@laanwj laanwj merged commit 1828c6f into bitcoin:master Nov 10, 2019
@hebasto hebasto deleted the 20191109-fix-signal-argument-type branch November 10, 2019 10:53
@maflcko
Copy link
Member

maflcko commented Nov 11, 2019

Confirmed that this was introduced in 6b6be41.
Confirmed that this was fixed by 88a94f7.

Didn't look at the code

@promag
Copy link
Contributor

promag commented Nov 12, 2019

qt/test/test_bitcoin-qt gives

QWARN  : AppTests::appTests() QObject::connect: Cannot queue arguments of type 'size_t'
(Make sure 'size_t' is registered using qRegisterMetaType().)

Fixed in 52b09b3

luke-jr pushed a commit to bitcoinknots/bitcoin that referenced this pull request Nov 15, 2019
It is required in order to use size_t in QueuedConnections.

Github-Pull: bitcoin#17427
Rebased-From: 88a94f7
MarkLTZ added a commit to litecoinz-core/litecoinz that referenced this pull request Nov 17, 2019
laanwj pushed a commit that referenced this pull request Nov 25, 2019
It is required in order to use size_t in QueuedConnections.

Github-Pull: #17427
Rebased-From: 88a94f7
Tree-SHA512: 55accd997209c559dfc8e88b0db189ba314ac31e265ba2f94fa2009f1aba6b96213e2aa8cbad492b1230078f2e6cf1cca7a233dc6f54e9bc449f4e5438330b4d
laanwj pushed a commit that referenced this pull request Nov 25, 2019
Github-Pull: #17427
Rebased-From: 1828c6f
Tree-SHA512: 140b723bd9c8d8823ecb84d7f774d213a9e9dac45fb0de82c43521cf8276d946feaa1b7c0b7d40f51dbab38c88c53b4680da1965b1e0ce7f858eb35b2c4537da
@bitcoin bitcoin deleted a comment from Domel1985 Mar 31, 2020
@bitcoin bitcoin deleted a comment from Domel1985 Mar 31, 2020
@bitcoin bitcoin deleted a comment from Domel1985 Mar 31, 2020
@bitcoin bitcoin locked and limited conversation to collaborators Mar 31, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants