Handle peer addition/removal in a right way #164

pull hebasto wants to merge 3 commits into bitcoin-core:master from hebasto:201224-signal changing 3 files +58 −61
  1. hebasto commented at 7:03 pm on December 24, 2020: member
  2. DrahtBot added the label Needs rebase on Dec 28, 2020
  3. hebasto force-pushed on Dec 30, 2020
  4. hebasto commented at 7:54 pm on December 30, 2020: member
    Rebased 734dd5f95168886e12dc2f07dd91902b1242ffc3 -> d325799acdd8d010d5e4b2f77d9cc67d76d4ad28 (pr164.01 -> pr164.02) due to the conflict with #162.
  5. DrahtBot removed the label Needs rebase on Dec 30, 2020
  6. DrahtBot added the label Needs rebase on Jan 7, 2021
  7. hebasto commented at 3:11 pm on January 7, 2021: member
    Will be rebased after any progress in #161 :)
  8. jonasschnelli referenced this in commit 616eace02a on Jan 11, 2021
  9. hebasto force-pushed on Jan 11, 2021
  10. hebasto commented at 9:55 am on January 11, 2021: member
    Rebased d325799acdd8d010d5e4b2f77d9cc67d76d4ad28 -> f73d340abeedf7e583fe9b2a8b3685a745a9199e (pr164.02 -> pr164.03) due to the conflict with #161.
  11. promag commented at 10:00 am on January 11, 2021: contributor
    Why is this based on #18?
  12. hebasto commented at 10:06 am on January 11, 2021: member

    Why is this based on #18?

    It fixes selection behavior and handling in general.

  13. DrahtBot removed the label Needs rebase on Jan 11, 2021
  14. jarolrod commented at 8:05 pm on January 14, 2021: member

    tACK f73d340abeedf7e583fe9b2a8b3685a745a9199e

    Confirming that the PR fixes the issue laid out in #160 on macOS 11.1 with Qt 5.15.2.

    On master: If I select a peer, and a peer above it is disconnected, then the peer I had selected becomes unselected. Below are screenshots exhibiting this behavior.

    Master: I have selected Peer ID 32 peer-is-selected

    Master: Peer ID 32 is no longer selected because Peer ID 29 is above it and disconnected peer-becomes-deselected

    on this PR: This behavior no longer occurs. If I select a peer, it remains selected even if a peer above it is disconnected.

    PR: Peer ID 14 is selected pr-peer-selected

    PR: Peer ID 0 has disconnected. Peer ID 14 remains selected. pr-peer-remains-selected

  15. DrahtBot added the label Needs rebase on Jan 27, 2021
  16. hebasto force-pushed on Jan 27, 2021
  17. hebasto commented at 9:05 pm on January 27, 2021: member
    Rebased f73d340abeedf7e583fe9b2a8b3685a745a9199e -> 32ce58cb18acc6eb3ac3a2c650c38b7bfdb6ad8b (pr164.03 -> pr164.04) due to the conflict with #180.
  18. DrahtBot removed the label Needs rebase on Jan 27, 2021
  19. DrahtBot added the label Needs rebase on Feb 22, 2021
  20. hebasto force-pushed on Feb 22, 2021
  21. hebasto commented at 8:03 am on February 22, 2021: member
    Rebased 32ce58cb18acc6eb3ac3a2c650c38b7bfdb6ad8b -> a3d21d3dc3d9166a60f050352ea0eff2a8c2140b (pr164.04 -> pr164.05) due to the conflict with #179.
  22. DrahtBot removed the label Needs rebase on Feb 22, 2021
  23. jarolrod commented at 5:11 pm on February 22, 2021: member
    re-ACK a3d21d3dc3d9166a60f050352ea0eff2a8c2140b, tested on macOS 11.1 Qt 5.15.2 after rebase
  24. DrahtBot added the label Needs rebase on Mar 4, 2021
  25. hebasto force-pushed on Mar 6, 2021
  26. hebasto commented at 6:33 pm on March 6, 2021: member
    Rebased a3d21d3dc3d9166a60f050352ea0eff2a8c2140b -> fa95a2205e8c88b23e786a382e55f4534e7733ac (pr164.05 -> pr164.06) due to the conflict with https://github.com/bitcoin/bitcoin/pull/21015.
  27. hebasto added the label Bug on Mar 6, 2021
  28. DrahtBot removed the label Needs rebase on Mar 6, 2021
  29. DrahtBot added the label Needs rebase on Mar 7, 2021
  30. hebasto force-pushed on Mar 7, 2021
  31. hebasto commented at 3:05 pm on March 7, 2021: member
    Rebased fa95a2205e8c88b23e786a382e55f4534e7733ac -> b7fe2b1691330166b478f0ced2dd1b6a8835729b (pr164.06 -> pr164.07) due to the conflict with #166..
  32. DrahtBot removed the label Needs rebase on Mar 7, 2021
  33. jarolrod commented at 6:25 pm on March 7, 2021: member
    re-ack b7fe2b1691330166b478f0ced2dd1b6a8835729b, tested on macOS 11.2 Qt 5.15.2 after rebase
  34. in src/qt/clientmodel.h:58 in b7fe2b1691 outdated
    54@@ -54,6 +55,7 @@ class ClientModel : public QObject
    55     interfaces::Node& node() const { return m_node; }
    56     OptionsModel *getOptionsModel();
    57     PeerTableModel *getPeerTableModel();
    58+    PeerTableSortProxy* peerTableSortProxy();
    


    Talkless commented at 7:34 pm on March 11, 2021:
    nit: could be noexcept, since it just returns pointer. Though since other similar getters here does not use noexcept, adding that one kinda seems out of scope.

    hebasto commented at 12:05 pm on March 12, 2021:

    Though since other similar getters here does not use noexcept, adding that one kinda seems out of scope.

    Going to leave it as is.


    promag commented at 9:17 am on April 28, 2021:
    FWIW I’ve suggested that this should not be “global” but rather instanced for each view (currently one in console dialog).
  35. in src/qt/peertablemodel.cpp:152 in b7fe2b1691 outdated
    155+    interfaces::Node::NodesStats nodes_stats;
    156+    m_node.getNodesStats(nodes_stats);
    157+    decltype(m_peers_data) new_peers_data;
    158+    new_peers_data.reserve(nodes_stats.size());
    159+    for (const auto& node_stats : nodes_stats) {
    160+        CNodeCombinedStats stats;
    


    Talkless commented at 7:38 pm on March 11, 2021:

    These stats has quite a few members, and they all gonna be overwritten after construction. Since it’s loop, consider initializing in this wat:

    0const CNodeCombinedStats stats{std::get<0>(node_stats), std::get<2>(node_stats), std::get<1>(node_stats)};
    

    It’s most dissapointing that QList does not have emplace() here…


    hebasto commented at 12:36 pm on March 12, 2021:
    Thanks! Updated.
  36. in src/qt/peertablemodel.h:81 in b7fe2b1691 outdated
    82+Q_SIGNALS:
    83+    void changed();
    84+
    85 private:
    86+    //! Internal peer data structure.
    87+    QList<CNodeCombinedStats> m_peers_data{};
    


    Talkless commented at 7:42 pm on March 11, 2021:
    nit: {} seems redundant, it’s not fundamental type like int, pointer or bool to need this kind of explicit default initialization, constructor will be invoked regardless.

    hebasto commented at 12:14 pm on March 12, 2021:
    Yes, it is redundant. Leaving as is to be explicit.
  37. in src/qt/peertablemodel.h:65 in b7fe2b1691 outdated
    61@@ -74,22 +62,25 @@ class PeerTableModel : public QAbstractTableModel
    62 
    63     /** @name Methods overridden from QAbstractTableModel
    64         @{*/
    65-    int rowCount(const QModelIndex &parent) const override;
    66-    int columnCount(const QModelIndex &parent) const override;
    67-    QVariant data(const QModelIndex &index, int role) const override;
    68-    QVariant headerData(int section, Qt::Orientation orientation, int role) const override;
    69-    QModelIndex index(int row, int column, const QModelIndex &parent) const override;
    70+    int rowCount(const QModelIndex& parent = QModelIndex()) const override;
    


    Talkless commented at 7:44 pm on March 11, 2021:
    nit: if one likes C++11 toys, one could write = {} instead of = QModelIndex().

    hebasto commented at 12:33 pm on March 12, 2021:
    As stated in the commit description, the goal is to follow Qt docs.
  38. in src/qt/peertablesortproxy.cpp:15 in b7fe2b1691 outdated
    10+#include <QModelIndex>
    11+#include <QString>
    12+#include <QVariant>
    13+
    14+PeerTableSortProxy::PeerTableSortProxy(QObject* parent)
    15+    : QSortFilterProxyModel(parent)
    


    Talkless commented at 7:45 pm on March 11, 2021:
    nit: since you use {} in m_peer_table_sort_proxy{nullptr};, maybe worth using {} in QSortFilterProxyModel{parent} too (meaning in the new code)?

    hebasto commented at 12:23 pm on March 12, 2021:
    ~As stated in the commit description, the goal is to follow Qt docs.~ wrong comment

    hebasto commented at 12:35 pm on March 12, 2021:
    This commit belongs to the #18 pr which this one is based on.
  39. in src/qt/rpcconsole.cpp:13 in b7fe2b1691 outdated
     8@@ -9,13 +9,14 @@
     9 #include <qt/rpcconsole.h>
    10 #include <qt/forms/ui_debugwindow.h>
    11 
    12+#include <chainparams.h>
    13+#include <interfaces/node.h>
    


    Talkless commented at 7:47 pm on March 11, 2021:
    On My Machine™, it seems only #include <interfaces/node.h> is needed?

    hebasto commented at 12:28 pm on March 12, 2021:
    That commit only adds #include <qt/peertablesortproxy.h>, and other includes are sorted only. I’d leave the need of the interfaces/node.h header out of this pr scope.

    Talkless commented at 1:24 pm on March 12, 2021:
    Sorry, missed the fact that it’s a sort.
  40. Talkless changes_requested
  41. Talkless commented at 7:48 pm on March 11, 2021: none
    Concept ACK, right fix with nice cleanup.
  42. hebasto force-pushed on Mar 12, 2021
  43. hebasto commented at 12:36 pm on March 12, 2021: member

    Updated b7fe2b1691330166b478f0ced2dd1b6a8835729b -> 7bb0dc97ab08ebcba84b54031874c0648367d756 (pr164.07 -> pr164.08, diff):

  44. in src/qt/peertablemodel.cpp:151 in 7bb0dc97ab outdated
    154-}
    155+    interfaces::Node::NodesStats nodes_stats;
    156+    m_node.getNodesStats(nodes_stats);
    157+    decltype(m_peers_data) new_peers_data;
    158+    new_peers_data.reserve(nodes_stats.size());
    159+    for (const auto& node_stats : nodes_stats) {
    


    Talkless commented at 3:34 pm on March 12, 2021:

    Ugh, my suggestion was not good enought, you can actually move values out of that local nodes_stats:

    0    for (auto&& node_stats : nodes_stats) {
    1        const CNodeCombinedStats stats{std::get<0>(std::move(node_stats)), 
    2                                       std::get<2>(std::move(node_stats)),
    3                                       std::get<1>(std::move(node_stats))};
    

    (note loop variable is no longer cost reference!)

    Or even with an algorithm (also moves, at least it does on local test), if one would care about “No raw loops” mantra :)

    0    std::transform(nodes_stats.begin(), nodes_stats.end(), std::back_inserter(new_peers_data), [](auto&& i) {
    1        return CNodeCombinedStats{std::get<0>(std::move(i)), std::get<2>(std::move(i)), std::get<1>(std::move(i))};
    2    });
    

    Though moving std::transform seems fishy, not sure if it’s “legal” to move source… But gcc 10.2.1 does that.


    hebasto commented at 0:38 am on March 26, 2021:

    Ugh, my suggestion was not good enought…

    It seems like a kind of premature optimization, no?


    Talkless commented at 12:33 pm on March 27, 2021:
    Maybe, probably. Since there will be mostly on up to ~128 nodes by default, “nobody” would care if there are some extra copies I guess, and std::transform variant do look particularly “noisy” (i.e. “optimization” not worth the effort/readability cost).
  45. hebasto force-pushed on Apr 28, 2021
  46. hebasto commented at 6:06 pm on April 28, 2021: member
    Rebased 7bb0dc97ab08ebcba84b54031874c0648367d756 -> ec3075d7342b65bdd72e34f5705f6cdc8a948b67 (pr164.08 -> pr164.09) due to the merging of #18.
  47. Talkless approved
  48. Talkless commented at 5:37 pm on May 3, 2021: none

    tACK ec3075d7342b65bdd72e34f5705f6cdc8a948b67, tested on Debian Sid with Qt 5.15.2.

    Tested using two bitcoind’s connected to PR’s bitcoin-qt in regtest mode. Did some reconnects, and so far table seems to work fine.

  49. DrahtBot added the label Needs rebase on May 26, 2021
  50. qt, refactor: Use default arguments for overridden functions
    See Qt docs for QAbstractTableModel and QAbstractItemModel classes.
    efb7e5aa96
  51. qt: Drop PeerTablePriv class
    This commit does not change behavior.
    1b66f6e556
  52. hebasto force-pushed on May 27, 2021
  53. hebasto commented at 7:48 pm on May 27, 2021: member
    Rebased ec3075d7342b65bdd72e34f5705f6cdc8a948b67 -> e102c90e41fb82e534c155bd7cfb9d0e9852c092 (pr164.09 -> pr164.10) due to the conflict with #311.
  54. DrahtBot removed the label Needs rebase on May 27, 2021
  55. promag commented at 2:32 pm on June 3, 2021: contributor

    Tested ACK e102c90e41fb82e534c155bd7cfb9d0e9852c092 on macos 11.2.3 with depends build.

    Also ran with -server and while some peer was selected removing/adding others from -cli didn’t mess with the selection. Also didn’t observe weird behaviors while resizing columns.

  56. jonatack commented at 2:42 pm on June 5, 2021: contributor
    Concept ACK. If this fixes what I think it does, it would be good to see it in v22 as a bug fix.
  57. in src/qt/peertablemodel.cpp:156 in e102c90e41 outdated
    158+    for (const auto& node_stats : nodes_stats) {
    159+        const CNodeCombinedStats stats{std::get<0>(node_stats), std::get<2>(node_stats), std::get<1>(node_stats)};
    160+        new_peers_data.append(stats);
    161+    }
    162+
    163+    // Handle a new peer addition or an old peer in a right way. See:
    


    jarolrod commented at 6:47 am on June 7, 2021:

    nit, or something similar

    0    // Handle new peer addition or removal as suggested in Qt Docs. See:
    

    hebasto commented at 2:42 pm on June 7, 2021:
    Thanks! Updated.
  58. in src/qt/peertablemodel.cpp:159 in e102c90e41 outdated
    161+    }
    162+
    163+    // Handle a new peer addition or an old peer in a right way. See:
    164+    // - https://doc.qt.io/qt-5/model-view-programming.html#inserting-and-removing-rows
    165+    // - https://doc.qt.io/qt-5/model-view-programming.html#resizable-models
    166+    // We use the fact that interfaces::Node::getNodesStats
    


    jarolrod commented at 6:49 am on June 7, 2021:
    0    // We take advantage of the fact that the std::vector returned by  interfaces::Node::getNodesStats
    

    hebasto commented at 2:42 pm on June 7, 2021:
  59. in src/qt/peertablemodel.cpp:160 in e102c90e41 outdated
    162+
    163+    // Handle a new peer addition or an old peer in a right way. See:
    164+    // - https://doc.qt.io/qt-5/model-view-programming.html#inserting-and-removing-rows
    165+    // - https://doc.qt.io/qt-5/model-view-programming.html#resizable-models
    166+    // We use the fact that interfaces::Node::getNodesStats
    167+    // returns std::vector naturally sorted by nodeid.
    


    jarolrod commented at 6:50 am on June 7, 2021:
    0    // is sorted by nodeid.
    

    hebasto commented at 2:42 pm on June 7, 2021:
  60. jarolrod commented at 6:52 am on June 7, 2021: member

    ACK e102c90e41fb82e534c155bd7cfb9d0e9852c092

    Tested functionality on Arch Linux Qt 5.15.2, macOS 11.3 Qt 5.15.2, and cross-compile from Linux to Windows 10.

    Notes on Commits:

    • efb7e5aa962d4a4047061996bbb50b6da4592cbc
    • 1b66f6e556631a1a2d89aefba70a79894bd14fcd
      • code review ACK, the PeerTablePriv class would no longer be needed.
    • e102c90e41fb82e534c155bd7cfb9d0e9852c092
      • code review ACK, patch looks correct in its implementation in following recommendations from Qt docs
      • some nits (1, 2, 3)

    Screenshots:

    The below screenshots show that this PR will close the mutated version of #160 (see, #160 (comment)). While I am not including videos showing that this PR also fixes #191, I can confirm that it does on all three tested platforms.

    Arch Linux

    master

    Select Peer 6 Disconnect Peer 0, Peer 7 is now selected ❌
    master0start master-disconnect

    PR

    Select Peer 9 Disconnect Peer 1, Peer 9 remains selected ✅
    linux-pr-start linux-pr-disconnect

    macOS 11.3

    master

    Select Peer 6 Disconnect Peer 0, Peer 7 is now selected ❌
    Screen Shot 2021-06-06 at 9 17 11 PM Screen Shot 2021-06-06 at 9 17 48 PM

    PR

    Select Peer 8 Disconnect Peer 0, Peer 8 remains selected ✅
    macOS-pr-start macOS-pr-disconnect

    Windows 10

    Note: Difference between UI on master and PR is because master includes ab86ac7739b27f2c45ae72ce4c4ebecf324b3e90

    master

    Select Peer 4 Disconnect Peer 0, Peer 6 is now selected ❌
    windows-master-start windows-master-disconnect

    PR

    Select Peer 5 Disconnect Peer 1, Peer 5 remains selected ✅
    windows-start-pr windows-disconnect-pr
  61. qt: Handle peer addition/removal in a right way
    This change fixes a bug when a multiple rows selection gets inconsistent
    after a peer addition/removal.
    ecbd911538
  62. hebasto force-pushed on Jun 7, 2021
  63. hebasto commented at 2:41 pm on June 7, 2021: member

    Updated e102c90e41fb82e534c155bd7cfb9d0e9852c092 -> ecbd91153875c8cdd5b92b840afc116f65e457fb (pr164.10 -> pr164.11, diff):

  64. promag commented at 3:21 pm on June 7, 2021: contributor
    reACK ecbd91153875c8cdd5b92b840afc116f65e457fb just improvements to the comment since last review.
  65. jarolrod commented at 5:34 pm on June 7, 2021: member

    re-ACK ecbd911

    Only changes since last review are implementation of comment nits

  66. hebasto merged this on Jun 7, 2021
  67. hebasto closed this on Jun 7, 2021

  68. hebasto deleted the branch on Jun 7, 2021
  69. sidhujag referenced this in commit 932f4953cc on Jun 9, 2021
  70. hebasto referenced this in commit a62fc35a15 on Jul 5, 2021
  71. gwillen referenced this in commit b6205a6f44 on Jun 1, 2022
  72. bitcoin-core locked this on Aug 16, 2022

github-metadata-mirror

This is a metadata mirror of the GitHub repository bitcoin-core/gui. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2024-10-23 00:20 UTC

This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me