ouroboros-network-0.1.0.0: A networking layer for the Ouroboros blockchain protocol

Ouroboros.Network.PeerSelection.LocalRootPeers

Synopsis

# Types

data LocalRootPeers peeraddr Source #

Constructors

#### Instances

Instances details
 Eq peeraddr ⇒ Eq (LocalRootPeers peeraddr) Source # Instance details Methods(==) ∷ LocalRootPeers peeraddr → LocalRootPeers peeraddr → Bool Source #(/=) ∷ LocalRootPeers peeraddr → LocalRootPeers peeraddr → Bool Source # (Show peeraddr, Ord peeraddr) ⇒ Show (LocalRootPeers peeraddr) Source # Instance details MethodsshowsPrec ∷ Int → LocalRootPeers peeraddr → ShowS Source #show ∷ LocalRootPeers peeraddr → String Source #showList ∷ [LocalRootPeers peeraddr] → ShowS Source #

invariantOrd peeraddr ⇒ LocalRootPeers peeraddr → Bool Source #

# Basic operations

nullLocalRootPeers peeraddr → Bool Source #

sizeLocalRootPeers peeraddr → Int Source #

memberOrd peeraddr ⇒ peeraddr → LocalRootPeers peeraddr → Bool Source #

targetLocalRootPeers peeraddr → Int Source #

The local root peers info has some invariants that are not directly enforced in the types, and the config comes from an external source. Of course it's good to validate that at source, but here we need to not fail if we're given imperfect data.

So what we do is bash it until it is valid. We don't need to be too careful about how we do it, it's ok to be brutal. We should however make sure we trace a warning about dodgy config.

Inverse of fromGroups, for the subset of inputs to fromGroups that satisfy the invariant.

toGroupSetsLocalRootPeers peeraddr → [(Int, Set peeraddr)] Source #

keysSetLocalRootPeers peeraddr → Set peeraddr Source #

# Special operations

Arguments

 ∷ Ord peeraddr ⇒ Int The limit on the total number of local peers → LocalRootPeers peeraddr → LocalRootPeers peeraddr

Limit the size of the root peers collection to fit within given bounds.

The governor needs to be able to do this to enforce its invariant that:

LocalRootPeers.size localRootPeers <= targetNumberOfKnownPeers

It needs to be able to establish that invariant given arbitrary configuration for local root peers. It makes sense to do it this way rather than just enforce that local root peers config fits the invariant because the invariant depends on both the targets and the local root peers config and these can both vary dynamically and independently.

It is unlikely in practice that there are so many local root peers configured that it goes over this targets, so it's ok to resolve it pretty arbitrarily. We just take the local roots in left to right order up to the limit. So we have the property that

LocalRootPeers.size (LocalRootPeers.clampToLimit sz lrps)
== min sz (LocalRootPeers.size lrps)