ouroboros-network-0.1.0.1: A networking layer for the Ouroboros blockchain protocol
Safe Haskell None
Language Haskell2010

Ouroboros.Network.PeerSelection.LocalRootPeers

Synopsis

Types

Basic operations

member :: Ord peeraddr => peeraddr -> LocalRootPeers peeraddr -> Bool Source #

fromGroups :: Ord peeraddr => [( Int , Map peeraddr PeerAdvertise )] -> LocalRootPeers peeraddr 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.

toGroups :: Ord peeraddr => LocalRootPeers peeraddr -> [( Int , Map peeraddr PeerAdvertise )] Source #

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

Special operations

clampToLimit Source #

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)