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

refactor(networking): peermanager refactor and cleanups #1539

Merged
merged 2 commits into from
Feb 27, 2023

Conversation

alrevuelta
Copy link
Contributor

@alrevuelta alrevuelta commented Feb 7, 2023

Changes:

  • Uses addServicePeer where needed
  • Removes unused code.
  • Removes proto from addPeer. From now on that is populated by Identify.
  • Move to TRACE adding peer to peermanager, since it was quite spammy.
  • Split connectToRelayPeers into function + loop.

@status-im-auto
Copy link
Collaborator

Jenkins Builds

Commit #️⃣ Finished (UTC) Duration Platform Result
✔️ 9d71988 #1 2023-02-07 15:05:43 ~18 min macos 📦bin

@alrevuelta alrevuelta force-pushed the misc-refactors branch 4 times, most recently from 0cf7aa8 to e9ede91 Compare February 21, 2023 10:35
@alrevuelta alrevuelta marked this pull request as ready for review February 21, 2023 13:11
Copy link
Contributor

@LNSD LNSD left a comment

Choose a reason for hiding this comment

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

Please check my comments 🤔

A side note:

IMO, the next thing we must do, after this PR and before evolving anything else, is to unify the "Peer" data model. We have 3/4 data models (e.g., peer multiaddress, Ethereum and Waku ENRs, PeerId, RemotePeerId, etc.). This fragmentation makes the code complex and "Unexpected exceptions/defect" prone.

Comment on lines +411 to +415
info "Relay peer connections",
connectedPeers = numConPeers,
targetConnectedPeers = maxConnections,
notConnectedPeers = notConnectedPeers.len,
outsideBackoffPeers = outsideBackoffPeers.len
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this logged periodically? If so, we must put it behind a configurable flag (like the "poor-man's metrics" log in wakunode2) or lower the log level. This kind of thing pollutes the logs, and we already have it in the metrics.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The thing is that as it is now, I can't log some of this information in the periodic metrics startMetricsLog.

I have some plans for this as well, so will address in future Prs.

Comment on lines +65 to +73
proc protocolMatcher*(codec: string): Matcher =
## Returns a protocol matcher function for the provided codec
proc match(proto: string): bool {.gcsafe.} =
## Matches a proto with any postfix to the provided codec.
## E.g. if the codec is `/vac/waku/filter/2.0.0` it matches the protos:
## `/vac/waku/filter/2.0.0`, `/vac/waku/filter/2.0.0-beta3`, `/vac/waku/filter/2.0.0-actualnonsense`
return proto.startsWith(codec)

return match
Copy link
Contributor

Choose a reason for hiding this comment

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

I noticed you moved this method to the peer_manager module. Is there any reason for this method to be exposed in this module's public API?

Suggested change
proc protocolMatcher*(codec: string): Matcher =
## Returns a protocol matcher function for the provided codec
proc match(proto: string): bool {.gcsafe.} =
## Matches a proto with any postfix to the provided codec.
## E.g. if the codec is `/vac/waku/filter/2.0.0` it matches the protos:
## `/vac/waku/filter/2.0.0`, `/vac/waku/filter/2.0.0-beta3`, `/vac/waku/filter/2.0.0-actualnonsense`
return proto.startsWith(codec)
return match
proc protocolMatcher(codec: string): Matcher =
## Returns a protocol matcher function for the provided codec. The protocol matcher
## searches for protocol IDs with any postfix.
## E.g. if the codec is `/vac/waku/filter/2.0.0`, it matches the protocol IDs:
## `/vac/waku/filter/2.0.0`, `/vac/waku/filter/2.0.0-beta3`, `/vac/waku/filter/2.0.0-actualnonsense`
proc match(proto: string): bool {.gcsafe.} =
proto.startsWith(codec)
return match

Copy link
Contributor Author

Choose a reason for hiding this comment

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

mm good catch, will remove it

Copy link
Contributor Author

Choose a reason for hiding this comment

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

wops, actually used by the waku_node in startRelay. adding to the todo list since reconnection logic should be in peermanager side, and waku_node should just call a high level function.

Comment on lines 24 to 27
declarePublicGauge waku_peers_errors, "Number of peer manager errors", ["type"]
declarePublicGauge waku_connected_peers, "Number of connected peers per direction: inbound|outbound", ["direction"]
declarePublicGauge waku_peer_store_size, "Number of peers managed by the peer store"
declarePublicGauge waku_service_peers, "Configured waku service peers protocol/peerId", labels = ["protocol", "peerId"]
Copy link
Contributor

Choose a reason for hiding this comment

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

Note that this description is returned by the metrics server. The lighter we make them, the better. Shorter the description of the metric, the better.

Suggested change
declarePublicGauge waku_peers_errors, "Number of peer manager errors", ["type"]
declarePublicGauge waku_connected_peers, "Number of connected peers per direction: inbound|outbound", ["direction"]
declarePublicGauge waku_peer_store_size, "Number of peers managed by the peer store"
declarePublicGauge waku_service_peers, "Configured waku service peers protocol/peerId", labels = ["protocol", "peerId"]
declarePublicGauge waku_peers_errors, "Number of peer manager errors", ["type"]
declarePublicGauge waku_connected_peers, "Number of connected peers per direction", ["direction"]
declarePublicGauge waku_peer_store_size, "Number of peers managed by the peer store"
declarePublicGauge waku_service_peers, "Number of service peers per protocol", labels = ["protocol", "peerId"]

Copy link
Contributor Author

Choose a reason for hiding this comment

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

sure, can simplify it a bit but note that Number of service peers per protocol is not correct since its not the number but the protocol and peerId

Copy link
Contributor

@jm-clius jm-clius left a comment

Choose a reason for hiding this comment

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

LGTM! Thanks. Clearly improves things.

@alrevuelta
Copy link
Contributor Author

IMO, the next thing we must do, after this PR and before evolving anything else, is to unify the "Peer" data model. We have 3/4 data models (e.g., peer multiaddress, Ethereum and Waku ENRs, PeerId, RemotePeerId, etc.). This fragmentation makes the code complex and "Unexpected exceptions/defect" prone.

yup, added it to #1353 to track it.

@alrevuelta alrevuelta merged commit 700dbbb into master Feb 27, 2023
@alrevuelta alrevuelta deleted the misc-refactors branch February 27, 2023 17:24
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.

4 participants