-
-
Notifications
You must be signed in to change notification settings - Fork 266
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
Refactor peer managment #2142
Refactor peer managment #2142
Conversation
Code Climate has analyzed commit 1aa305c and detected 8 issues on this pull request. Here's the issue category breakdown:
View more on Code Climate. |
12cf874
to
89166b9
Compare
b103d68
to
46788e9
Compare
52cc280
to
fa5a188
Compare
fa5a188
to
c664475
Compare
c664475
to
3bdb3e6
Compare
3bdb3e6
to
a308980
Compare
516ccf8
to
3fba248
Compare
3fba248
to
b6fe4a3
Compare
b6fe4a3
to
674b7a3
Compare
This pull request fixes 1 alert when merging 674b7a3 into 867db03 - view on LGTM.com fixed alerts:
|
Rebased into a merge-able status. Ready for review. |
@@ -6,7 +6,7 @@ export interface INetworkArgs { | |||
"network.discv5.bindAddr": string; | |||
"network.discv5.bootEnrs": string[]; | |||
"network.maxPeers": number; | |||
"network.minPeers": number; | |||
"network.targetPeers": number; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
whats the difference between that and maxPeers?
Idea behind minPeers was to not allow sync if peer count is below that
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You refer to sync.minPeers
, which is different option with the purpose you describe. In current master network.minPeers
is used by libp2p's autoDial logic. In the Range Sync PR #2111 sync.minPeers
is eliminated, so we will then only have network.minPeers
and network.targetPeers
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok, and whats the difference between network.targetPeers and network.maxPeers? 😄
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
targetPeers
: Below that number actively discover and connect to peers. Above that number actively disconnect peersmaxPeers
: Hard cap to not allow any peer connections above that number.
You want maxPeers
to be a little larger than targetPeers
to allow new inbound peers that just joined the network connect to you (for the sake of the network's health).
@@ -159,3 +162,9 @@ export const goodbyeReasonCodeDescriptions: Record<string, string> = { | |||
250: "Peer score too low", | |||
251: "Peer banned this node", | |||
}; | |||
|
|||
/** Until js-libp2p types its events */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Aren't we maintaining types for that still in libp2p-ts?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
libp2p-ts types these events but as a string uninon, not an enum.
export type ConnectionEvents = 'peer:connect' | 'peer:disconnect';
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not change that there instead of here? 😄
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just opened an issue ChainSafe/libp2p-ts#21
This pull request fixes 1 alert when merging 1aa305c into 867db03 - view on LGTM.com fixed alerts:
|
Group all peer management functionality into a single class PeerManager. Current master segregates the functionality between tasks, network, and sync. PeerManager does:
All ReqResp logic moved to network/reqResp so it can easily notify the PeerManager on incoming requests.
This PR is a spin-off from #2111 which is still unclear if it causes more memory and lag issues than master. I will A/B test this PR too to ensure it performs at least as well as master
PeerManager
PeerManager runs an internal
heartbeat
function which is a convenient start to follow its logiclodestar/packages/lodestar/src/network/peers/peerManager.ts
Line 119 in 03f356b
Key sensitive logic:
prioritizePeers
: How to decide which peers to connect to and which to disconnect given an existing peer set and target peer count + target subnetsFixes #823 fixes #1989