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

Update peer endpoints #101

Merged
merged 7 commits into from
Nov 11, 2020
Merged

Update peer endpoints #101

merged 7 commits into from
Nov 11, 2020

Conversation

mpetrunic
Copy link
Collaborator

Breaking:
peer.address -> peer.last_seen_p2p_address

Added clarifications and examples from #97

@AgeManning is this ok?

resolves #97

@mcdee
Copy link
Contributor

mcdee commented Oct 20, 2020

Do we really want pagination in this API? What is the use case for fetching an arbitrary subset of peers?

@mpetrunic
Copy link
Collaborator Author

Do we really want pagination in this API? What is the use case for fetching an arbitrary subset of peers?

you are suppose to include disconnected peers as well, it could be response with 500-600 peers or even more on mainnet

@mcdee
Copy link
Contributor

mcdee commented Oct 20, 2020

Surely that is an argument to have filtering, not pagination.

@mpetrunic
Copy link
Collaborator Author

mpetrunic commented Oct 20, 2020

Surely that is an argument to have filtering, not pagination.

On what fields would you filter?
I guess, you can always set limit to 10k and get all results.

Let's say I want all disconnected outgoing peers, that could still be 300 responses

@mcdee
Copy link
Contributor

mcdee commented Oct 20, 2020

Let's say I want all disconnected outgoing peers, that could still be 300 responses

Yes, but if that is the information you want then why receive it piecemeal going through multiple requests rather than all in one response?

From my experience, pagination is useful when results are ordered and end-user facing. For example, if someone wanted to list validators ordered by balance it's possible they are doing so to just see the first x validators, in which pagination makes sense because the user may well stop at page 1 or 2 of several hundred. However, if the common requirement is to obtain all results, possibly restricted by filter, I don't see the benefit of doing this.

A good example of where this caused problems was in the beacon chain explorers recently. They use the prysm API to fetch validators, and it's paginated. The APi is by default limited to 250 responses, so the explorer required around 300 calls to obtain the data. The problem was that fetching validators for a non-head state required recreating the state from the last checkpoint, so what happened was:

  • the beacon node recreated the state for all 70-odd thousand validators (which was taking up to 1 minute)
  • the beacon node returned 250 of the validators
  • the rest of the results were discarded

This caused the explorers to be unable to provide information. It could be possible to cache the data, but then you're in to a world of second-guessing which results are going to be requested again, cache management, and all that fun.

All that said, if client teams want to build pagination in to their APIs that's up to them. But if it's going to happen I'd far rather it was purely optional, and standard across all APIs (perhaps by adding generic pageSize and cursor options to all queries). The default should always be to return all requested values.

apis/node/peers.yaml Outdated Show resolved Hide resolved
@AgeManning
Copy link
Contributor

Originally I was concerned about there not being an endpoint for peer count.

I imagine there are going to be a lot of applications wanting to know how many connected peers a client has. If I've understood the current API's correctly, in order to do that, they have to receive all the data for all peers the client currently knows about and then filter. I would imagine they would poll regularly for this.

Perhaps we have a peer_count endpoint which can have the queries connected, disconnected etc, which returns a single uint.

@mcdee
Copy link
Contributor

mcdee commented Oct 21, 2020

Perhaps we have a peer_count endpoint which can have the queries connected, disconnected etc, which returns a single uint.

Or not take a query and return the number in each state, which could be easier on the implementer.

@realbigsean
Copy link
Contributor

I don't really see a need for ordering by peer_id + pagination. Ordering by a time-based metric like a new state_last_updated or first_connected field might make sense. But overall I'd probably be in favor of no ordering/pagination (unless optionally implemented by client teams) and instead adding a state filter and a new peer_count endpoint.

@mpetrunic
Copy link
Collaborator Author

As per comments here, removed pagination and peer ordering. I've added peer filtering by connection direction and state.

Since we cannot really have /node/peers/peer_count since peer_count would be peer id in that case, I've added peer_count (number of connected peers) to /node/indentity. I'm not too happy by that solution so if you have better proposal, I can revert last commit and do that instead.

@AgeManning
Copy link
Contributor

What about /node/peer_count ?

Or maybe we could add it to health?

I'm not too concerned either way. Just some suggestions. I assume its something that would get polled regularly for misc applications.

@mcdee
Copy link
Contributor

mcdee commented Oct 29, 2020

A separate /eth/v1/node/peer_counts seems to follow the existing API endpoint layout most closely. A per-state count would be useful, e.g.:

{
 "data": {
    "disconnected": "12",
    "connecting": "34",
    "connected": "56",
    "disconnecting": "78"
  }
}

(As an aside, we should specify all possible states somewhere).

@mpetrunic mpetrunic requested a review from djrtwo November 7, 2020 06:50
Copy link
Contributor

@djrtwo djrtwo left a comment

Choose a reason for hiding this comment

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

looks good, quick question and a minor copy suggestion

apis/node/peer_count.yaml Outdated Show resolved Hide resolved
apis/node/peers.yaml Outdated Show resolved Hide resolved
@djrtwo djrtwo merged commit 5f8d85d into master Nov 11, 2020
@djrtwo djrtwo deleted the mpetrunic/update-peer-endpoints branch November 11, 2020 19:05
@protolambda
Copy link

@mpetrunic I still see a meta field in the peers list endpoint with a count in it, is that a remnant from the removed peers pagination? Shouldn't it always be equal to the length of the returned json list?

@mpetrunic
Copy link
Collaborator Author

@mpetrunic I still see a meta field in the peers list endpoint with a count in it, is that a remnant from the removed peers pagination? Shouldn't it always be equal to the length of the returned json list?

Seems like I forgot to remove it. Yeah it should always be length of list

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.

​[Clarification] /eth​/v1​/node​/peers
6 participants