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

gs1.1 Integrate peer score #87

Merged
merged 3 commits into from
Jun 17, 2020
Merged

Conversation

wemeetagain
Copy link
Member

@wemeetagain wemeetagain commented Jun 16, 2020

Building off #83
Minimal integration of peer score

  • adds a PeerScore object to gossipsub
  • plugs into gossipsub start/stop/_addPeer/_removePeer
  • pass a ConnectionManager into the constructor of gossipsub
  • update tests to new constructor

Copy link
Collaborator

@vasco-santos vasco-santos left a comment

Choose a reason for hiding this comment

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

Overall this is looking great to me. Just left an observation

@@ -77,7 +83,7 @@ export class PeerScore {
}
clearInterval(this._backgroundInterval)
delete this._backgroundInterval
this._addressBook.off('change:multiaddrs', this._updateIPs)
this._connectionManager.off('change:multiaddrs', this._updateIPs)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should we just remove the IPs instead?
If I understood correctly, this will keep them in the data structure

Copy link
Member Author

Choose a reason for hiding this comment

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

ah, yeah, we should probably clear all IPs.
This is also wrong, bc the ConnectionManager emits the 'peer:connect' and 'peer:disconnect' events, not 'change:multiaddrs' events

Copy link
Member Author

Choose a reason for hiding this comment

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

it seems that there are some problems with our current approach of updating IPs, and it seems the events currently emitted by the connection manager are not sufficient for tracking IPs to open connections for peers with scores.

issue 1: ConnectionManager doesn't emit on closed connections. ConnectionManager#_maybeDisconnectOne, doesn't emit when a connection is closed, more generally, ConnectionManager isn't tracking/emitting on manually closed connections, but rather only on calls to ConnectionManager#onDisconnect.

issue 2: ConnectionManager emits peer:connect event before storing the emitted connection.
The current approach is to use ConnectionManager#getAll on each peer:connect event for a list of current IPs, but since the event is triggered before the new connection is stored, the call to getAll will not include the new connection unless the event handler awaits the ConnectionManager#onConnect finishing in its entirety. But that potentially also runs into issues re issue 1.

I think, for now, to move forward, we should fall back to calling ConnectionManager#getAll for each peer in the background method here, in the same synchronous fashion that go-libp2p-pubsub does, while we sort out what a good solution for asynchronously tracking open connection IPs would look like.

Copy link
Member Author

Choose a reason for hiding this comment

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

whoops, i thought this was #83, i've updated that PR with the idea ^
Once we merge, the diff here should be tiny

Copy link
Collaborator

Choose a reason for hiding this comment

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

I had a look and I think we can go with this for now! I will create an issue for tracking this connectionManager issues that you mentioned. Hopefully we can get to that in libp2p@0.30. Meanwhile, we should probably create an issue in gossipsub to sign that this should be changed once libp2p connection manager properly supports these needs.

@wemeetagain wemeetagain force-pushed the cayman/gs1.1-integrate-peer-score branch from f3fb6d1 to 513b90c Compare June 17, 2020 15:00
@codecov-commenter
Copy link

codecov-commenter commented Jun 17, 2020

Codecov Report

Merging #87 into gsv1.1 will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@           Coverage Diff           @@
##           gsv1.1      #87   +/-   ##
=======================================
  Coverage   80.00%   80.00%           
=======================================
  Files           1        1           
  Lines          10       10           
=======================================
  Hits            8        8           
  Misses          2        2           
Impacted Files Coverage Δ
test/utils/index.js 80.00% <ø> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 938e5b1...005cdba. Read the comment docs.

@wemeetagain wemeetagain changed the title Integrate peer score gs1.1 Integrate peer score Jun 17, 2020
@wemeetagain wemeetagain merged commit ee32618 into gsv1.1 Jun 17, 2020
@wemeetagain wemeetagain deleted the cayman/gs1.1-integrate-peer-score branch June 17, 2020 16:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants