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

Handle peer addition/removal in a right way #164

Merged
merged 3 commits into from
Jun 7, 2021

Conversation

hebasto
Copy link
Member

@hebasto hebasto commented Dec 24, 2020

@hebasto
Copy link
Member Author

hebasto commented Dec 30, 2020

Rebased 734dd5f -> d325799 (pr164.01 -> pr164.02) due to the conflict with #162.

@hebasto
Copy link
Member Author

hebasto commented Jan 7, 2021

Will be rebased after any progress in #161 :)

jonasschnelli added a commit that referenced this pull request Jan 11, 2021
…tion

b3e9bca qt, refactor: Drop no longer used PeerTableModel::getNodeStats function (Hennadii Stepanov)
49c6040 qt: Use PeerTableModel::StatsRole (Hennadii Stepanov)
35007ed qt: Add PeerTableModel::StatsRole (Hennadii Stepanov)

Pull request description:

  This PR allows to access to the `CNodeCombinedStats` instance directly from any view object.

  The `PeerTableModel::getNodeStats` member function removed as a kind of layer violation.

  No behavior changes.

  Also other pulls (bugfixes) are based on this one: #18 and #164.

ACKs for top commit:
  jonatack:
    Tested re-ACK b3e9bca per `git range-diff ae8f797 4c05fe0 b3e9bca`
  promag:
    Code review ACK b3e9bca.
  jonasschnelli:
    utACK b3e9bca

Tree-SHA512: 6ba50d5dd2c0373655d491ce8b130c47d598da2db5ff4b00633f447404c7e70f8562ead53ddf166e851384d9632ff9146a770c99845c2cdd3ff7250677e4c130
@hebasto
Copy link
Member Author

hebasto commented Jan 11, 2021

Rebased d325799 -> f73d340 (pr164.02 -> pr164.03) due to the conflict with #161.

@promag
Copy link
Contributor

promag commented Jan 11, 2021

Why is this based on #18?

@hebasto
Copy link
Member Author

hebasto commented Jan 11, 2021

Why is this based on #18?

It fixes selection behavior and handling in general.

Copy link
Member

@jarolrod jarolrod left a comment

Choose a reason for hiding this comment

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

tACK f73d340

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

@hebasto
Copy link
Member Author

hebasto commented Jan 27, 2021

Rebased f73d340 -> 32ce58c (pr164.03 -> pr164.04) due to the conflict with #180.

@hebasto
Copy link
Member Author

hebasto commented Feb 22, 2021

Rebased 32ce58c -> a3d21d3 (pr164.04 -> pr164.05) due to the conflict with #179.

Copy link
Member

@jarolrod jarolrod left a comment

Choose a reason for hiding this comment

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

re-ACK a3d21d3, tested on macOS 11.1 Qt 5.15.2 after rebase

@hebasto
Copy link
Member Author

hebasto commented Mar 6, 2021

Rebased a3d21d3 -> fa95a22 (pr164.05 -> pr164.06) due to the conflict with bitcoin/bitcoin#21015.

@hebasto hebasto added the Bug Something isn't working label Mar 6, 2021
@hebasto
Copy link
Member Author

hebasto commented Mar 12, 2021

Updated b7fe2b1 -> 7bb0dc9 (pr164.07 -> pr164.08, diff):

m_node.getNodesStats(nodes_stats);
decltype(m_peers_data) new_peers_data;
new_peers_data.reserve(nodes_stats.size());
for (const auto& node_stats : nodes_stats) {

Choose a reason for hiding this comment

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

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

    for (auto&& node_stats : nodes_stats) {
        const CNodeCombinedStats stats{std::get<0>(std::move(node_stats)), 
                                       std::get<2>(std::move(node_stats)),
                                       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 :)

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

Though moving std::transform seems fishy, not sure if it's "legal" to move source... But gcc 10.2.1 does that.

Copy link
Member Author

Choose a reason for hiding this comment

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

Ugh, my suggestion was not good enought...

It seems like a kind of premature optimization, no?

Choose a reason for hiding this comment

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

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

@hebasto
Copy link
Member Author

hebasto commented Apr 28, 2021

Rebased 7bb0dc9 -> ec3075d (pr164.08 -> pr164.09) due to the merging of #18.

Copy link

@Talkless Talkless left a comment

Choose a reason for hiding this comment

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

tACK ec3075d, 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.

See Qt docs for QAbstractTableModel and QAbstractItemModel classes.
This commit does not change behavior.
@hebasto
Copy link
Member Author

hebasto commented May 27, 2021

Rebased ec3075d -> e102c90 (pr164.09 -> pr164.10) due to the conflict with #311.

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.

Tested ACK e102c90 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.

@jonatack
Copy link
Member

jonatack commented Jun 5, 2021

Concept ACK. If this fixes what I think it does, it would be good to see it in v22 as a bug fix.

Copy link
Member

@jarolrod jarolrod left a comment

Choose a reason for hiding this comment

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

ACK e102c90

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:

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 ab86ac7

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

src/qt/peertablemodel.cpp Outdated Show resolved Hide resolved
src/qt/peertablemodel.cpp Outdated Show resolved Hide resolved
src/qt/peertablemodel.cpp Outdated Show resolved Hide resolved
This change fixes a bug when a multiple rows selection gets inconsistent
after a peer addition/removal.
@hebasto
Copy link
Member Author

hebasto commented Jun 7, 2021

Updated e102c90 -> ecbd911 (pr164.10 -> pr164.11, diff):

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.

reACK ecbd911 just improvements to the comment since last review.

@jarolrod
Copy link
Member

jarolrod commented Jun 7, 2021

re-ACK ecbd911

Only changes since last review are implementation of comment nits

@hebasto hebasto merged commit e638acf into bitcoin-core:master Jun 7, 2021
@hebasto hebasto deleted the 201224-signal branch June 7, 2021 19:15
sidhujag pushed a commit to syscoin/syscoin that referenced this pull request Jun 9, 2021
ecbd911 qt: Handle peer addition/removal in a right way (Hennadii Stepanov)
1b66f6e qt: Drop PeerTablePriv class (Hennadii Stepanov)
efb7e5a qt, refactor: Use default arguments for overridden functions (Hennadii Stepanov)

Pull request description:

  This PR makes `PeerTableModel` handle a peer addition/removal in a right way. See:
  - https://doc.qt.io/qt-5/model-view-programming.html#inserting-and-removing-rows
  - https://doc.qt.io/qt-5/model-view-programming.html#resizable-models

  Fixes #160.

  Fixes #191.

ACKs for top commit:
  jarolrod:
    re-ACK ecbd911
  promag:
    reACK ecbd911 just improvements to the comment since last review.

Tree-SHA512: 074935d67f78561724218e8b33822e2de16749f873c29054926b720ffcd642f08249a222b563983cf65a9b716290aa14e2372c47fc04e5f401f759db25ca710f
hebasto added a commit that referenced this pull request Jul 5, 2021
986bf78 qt: Emit dataChanged signal to dynamically re-sort Peers table (Hennadii Stepanov)

Pull request description:

  [By default](https://doc.qt.io/qt-5/qsortfilterproxymodel.html#details), the `PeerTableSortProxy`
  > dynamically re-sorts ... data whenever the original model changes.

  That is not the case on master (8cdf917) as in ecbd911 (#164) no signals are emitted to notify about model changes.

  This PR uses a dedicated [`dataChanged`](https://doc.qt.io/qt-5/qabstractitemmodel.html#dataChanged) signal.

  Fixes #367.

  An alternative to #374.

ACKs for top commit:
  jarolrod:
    ACK 986bf78

Tree-SHA512: dcb92c2f9a2c632880429e9528007db426d2ad938c64dfa1f1538c03e4b62620df52ad7daf33b582976c67b472ff76bc0dae707049f4bbbd4941232cee9ce3d4
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
Projects
None yet
6 participants