Documentation ¶
Overview ¶
Package peers provides information about peers at the eth2 protocol level.
"Protocol level" is the level above the network level, so this layer never sees or interacts with (for example) hosts that are uncontactable due to being down, firewalled, etc. Instead, this works with peers that are contactable but may or may not be of the correct fork version, not currently required due to the number of current connections, etc.
A peer can have one of a number of states:
- connected if we are able to talk to the remote peer - connecting if we are attempting to be able to talk to the remote peer - disconnecting if we are attempting to stop being able to talk to the remote peer - disconnected if we are not able to talk to the remote peer
For convenience, there are two aggregate states expressed in functions:
- active if we are connecting or connected - inactive if we are disconnecting or disconnected
Peer information is persistent for the run of the service. This allows for collection of useful long-term statistics such as number of bad responses obtained from the peer, giving the basis for decisions to not talk to known-bad peers (by de-scoring them).
Index ¶
- Constants
- type Status
- func (p *Status) Active() []peer.ID
- func (p *Status) Add(record *enr.Record, pid peer.ID, address ma.Multiaddr, ...)
- func (p *Status) Address(pid peer.ID) (ma.Multiaddr, error)
- func (p *Status) All() []peer.ID
- func (p *Status) Bad() []peer.ID
- func (p *Status) BestFinalized(maxPeers int, ourFinalizedEpoch uint64) (uint64, []peer.ID)
- func (p *Status) BestNonFinalized(minPeers int, ourHeadEpoch uint64) (uint64, []peer.ID)
- func (p *Status) ChainState(pid peer.ID) (*pb.Status, error)
- func (p *Status) ChainStateLastUpdated(pid peer.ID) (time.Time, error)
- func (p *Status) CommitteeIndices(pid peer.ID) ([]uint64, error)
- func (p *Status) Connected() []peer.ID
- func (p *Status) ConnectedPeerLimit() uint64
- func (p *Status) Connecting() []peer.ID
- func (p *Status) ConnectionState(pid peer.ID) (peerdata.PeerConnectionState, error)
- func (p *Status) Direction(pid peer.ID) (network.Direction, error)
- func (p *Status) Disconnected() []peer.ID
- func (p *Status) Disconnecting() []peer.ID
- func (p *Status) ENR(pid peer.ID) (*enr.Record, error)
- func (p *Status) HighestEpoch() uint64
- func (p *Status) Inactive() []peer.ID
- func (p *Status) Inbound() []peer.ID
- func (p *Status) InboundConnected() []peer.ID
- func (p *Status) IsAboveInboundLimit() bool
- func (p *Status) IsActive(pid peer.ID) bool
- func (p *Status) IsBad(pid peer.ID) bool
- func (p *Status) IsReadyToDial(pid peer.ID) bool
- func (p *Status) MaxPeerLimit() int
- func (p *Status) Metadata(pid peer.ID) (*pb.MetaData, error)
- func (p *Status) NextValidTime(pid peer.ID) (time.Time, error)
- func (p *Status) Outbound() []peer.ID
- func (p *Status) OutboundConnected() []peer.ID
- func (p *Status) PeersToPrune() []peer.ID
- func (p *Status) Prune()
- func (p *Status) Scorers() *scorers.Service
- func (p *Status) SetChainState(pid peer.ID, chainState *pb.Status)
- func (p *Status) SetConnectionState(pid peer.ID, state peerdata.PeerConnectionState)
- func (p *Status) SetMetadata(pid peer.ID, metaData *pb.MetaData)
- func (p *Status) SetNextValidTime(pid peer.ID, nextTime time.Time)
- func (p *Status) SubscribedToSubnet(index uint64) []peer.ID
- type StatusConfig
Constants ¶
const ( // PeerDisconnected means there is no connection to the peer. PeerDisconnected peerdata.PeerConnectionState = iota // PeerDisconnecting means there is an on-going attempt to disconnect from the peer. PeerDisconnecting // PeerConnected means the peer has an active connection. PeerConnected // PeerConnecting means there is an on-going attempt to connect to the peer. PeerConnecting )
const ( // ColocationLimit restricts how many peer identities we can see from a single ip or ipv6 subnet. ColocationLimit = 5 // InboundRatio is the proportion of our connected peer limit at which we will allow inbound peers. InboundRatio = float64(1) )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Status ¶
type Status struct {
// contains filtered or unexported fields
}
Status is the structure holding the peer status information.
func NewStatus ¶
func NewStatus(ctx context.Context, config *StatusConfig) *Status
NewStatus creates a new status entity.
func (*Status) Add ¶
func (p *Status) Add(record *enr.Record, pid peer.ID, address ma.Multiaddr, direction network.Direction)
Add adds a peer. If a peer already exists with this ID its address and direction are updated with the supplied data.
func (*Status) Address ¶
Address returns the multiaddress of the given remote peer. This will error if the peer does not exist.
func (*Status) BestFinalized ¶
BestFinalized returns the highest finalized epoch equal to or higher than ours that is agreed upon by the majority of peers. This method may not return the absolute highest finalized, but the finalized epoch in which most peers can serve blocks (plurality voting). Ideally, all peers would be reporting the same finalized epoch but some may be behind due to their own latency, or because of their finalized epoch at the time we queried them. Returns epoch number and list of peers that are at or beyond that epoch.
func (*Status) BestNonFinalized ¶ added in v1.0.0
BestNonFinalized returns the highest known epoch, higher than ours, and is shared by at least minPeers.
func (*Status) ChainState ¶
ChainState gets the chain state of the given remote peer. This can return nil if there is no known chain state for the peer. This will error if the peer does not exist.
func (*Status) ChainStateLastUpdated ¶
ChainStateLastUpdated gets the last time the chain state of the given remote peer was updated. This will error if the peer does not exist.
func (*Status) CommitteeIndices ¶ added in v0.3.8
CommitteeIndices retrieves the committee subnets the peer is subscribed to.
func (*Status) ConnectedPeerLimit ¶ added in v1.0.5
ConnectedPeerLimit returns the peer limit of concurrent peers connected to the beacon-node.
func (*Status) Connecting ¶
Connecting returns the peers that are connecting.
func (*Status) ConnectionState ¶
ConnectionState gets the connection state of the given remote peer. This will error if the peer does not exist.
func (*Status) Direction ¶
Direction returns the direction of the given remote peer. This will error if the peer does not exist.
func (*Status) Disconnected ¶
Disconnected returns the peers that are disconnected.
func (*Status) Disconnecting ¶
Disconnecting returns the peers that are disconnecting.
func (*Status) HighestEpoch ¶ added in v1.0.0
HighestEpoch returns the highest epoch reported epoch amongst peers.
func (*Status) InboundConnected ¶ added in v1.2.0
InboundConnected returns the current batch of inbound peers that are connected.
func (*Status) IsAboveInboundLimit ¶ added in v1.0.5
IsAboveInboundLimit checks if we are above our current inbound peer limit.
func (*Status) IsActive ¶ added in v0.3.8
IsActive checks if a peers is active and returns the result appropriately.
func (*Status) IsBad ¶
IsBad states if the peer is to be considered bad (by *any* of the registered scorers). If the peer is unknown this will return `false`, which makes using this function easier than returning an error.
func (*Status) IsReadyToDial ¶ added in v1.0.0
IsReadyToDial checks where the given peer is ready to be dialed again.
func (*Status) MaxPeerLimit ¶ added in v1.0.0
MaxPeerLimit returns the max peer limit stored in the current peer store.
func (*Status) Metadata ¶ added in v1.0.0
Metadata returns a copy of the metadata corresponding to the provided peer id.
func (*Status) NextValidTime ¶ added in v1.0.0
NextValidTime gets the earliest possible time it is to contact/dial a peer again. This is used to back-off from peers in the event they are 'full' or have banned us.
func (*Status) OutboundConnected ¶ added in v1.2.0
OutboundConnected returns the current batch of outbound peers that are connected.
func (*Status) PeersToPrune ¶ added in v1.1.0
PeersToPrune selects the most sutiable inbound peers to disconnect the host peer from. As of this moment the pruning relies on simple heuristics such as bad response count. In the future scoring will be used to determine the most suitable peers to take out.
func (*Status) Prune ¶ added in v1.0.0
func (p *Status) Prune()
Prune clears out and removes outdated and disconnected peers.
func (*Status) SetChainState ¶
SetChainState sets the chain state of the given remote peer.
func (*Status) SetConnectionState ¶
func (p *Status) SetConnectionState(pid peer.ID, state peerdata.PeerConnectionState)
SetConnectionState sets the connection state of the given remote peer.
func (*Status) SetMetadata ¶ added in v1.0.0
SetMetadata sets the metadata of the given remote peer.
func (*Status) SetNextValidTime ¶ added in v1.0.0
SetNextValidTime sets the earliest possible time we are able to contact this peer again.
type StatusConfig ¶ added in v1.0.0
type StatusConfig struct { // PeerLimit specifies maximum amount of concurrent peers that are expected to be connect to the node. PeerLimit int // ScorerParams holds peer scorer configuration params. ScorerParams *scorers.Config }
StatusConfig represents peer status service params.