Safe Haskell | None |
---|---|
Language | Haskell2010 |
Synopsis
- data LocalRootPeers peeraddr = LocalRootPeers ( Map peeraddr PeerAdvertise ) [( Int , Set peeraddr)]
- invariant :: Ord peeraddr => LocalRootPeers peeraddr -> Bool
- empty :: LocalRootPeers peeraddr
- null :: LocalRootPeers peeraddr -> Bool
- size :: LocalRootPeers peeraddr -> Int
- member :: Ord peeraddr => peeraddr -> LocalRootPeers peeraddr -> Bool
- target :: LocalRootPeers peeraddr -> Int
- fromGroups :: Ord peeraddr => [( Int , Map peeraddr PeerAdvertise )] -> LocalRootPeers peeraddr
- toGroups :: Ord peeraddr => LocalRootPeers peeraddr -> [( Int , Map peeraddr PeerAdvertise )]
- toGroupSets :: LocalRootPeers peeraddr -> [( Int , Set peeraddr)]
- toMap :: LocalRootPeers peeraddr -> Map peeraddr PeerAdvertise
- keysSet :: LocalRootPeers peeraddr -> Set peeraddr
- clampToLimit :: Ord peeraddr => Int -> LocalRootPeers peeraddr -> LocalRootPeers peeraddr
Types
data LocalRootPeers peeraddr Source #
LocalRootPeers ( Map peeraddr PeerAdvertise ) [( Int , Set peeraddr)] |
Instances
Eq peeraddr => Eq ( LocalRootPeers peeraddr) Source # | |
Defined in Ouroboros.Network.PeerSelection.LocalRootPeers (==) :: LocalRootPeers peeraddr -> LocalRootPeers peeraddr -> Bool Source # (/=) :: LocalRootPeers peeraddr -> LocalRootPeers peeraddr -> Bool Source # |
|
( Show peeraddr, Ord peeraddr) => Show ( LocalRootPeers peeraddr) Source # | |
|
Basic operations
empty :: LocalRootPeers peeraddr Source #
null :: LocalRootPeers peeraddr -> Bool Source #
size :: LocalRootPeers peeraddr -> Int Source #
target :: LocalRootPeers peeraddr -> Int 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.
toGroupSets :: LocalRootPeers peeraddr -> [( Int , Set peeraddr)] Source #
toMap :: LocalRootPeers peeraddr -> Map peeraddr PeerAdvertise Source #
keysSet :: LocalRootPeers peeraddr -> Set peeraddr Source #
Special operations
:: 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)