Skip to content

Commit

Permalink
Adjust LocalRootPeers to require targets > 0
Browse files Browse the repository at this point in the history
Previously we allowed local root peer groups to have a target of zero.
This is not useful given the way we interpret the target, and makes
things unnecessarily complicated. So we change the invariant to require
the target to be greater than zero.

We interpret these targets strictly, both from below and above, so a
target of zero means we will never connect to any of the given peers.
  • Loading branch information
dcoutts authored and karknu committed May 12, 2021
1 parent 50acd67 commit 8c6c55f
Showing 1 changed file with 6 additions and 6 deletions.
Expand Up @@ -62,9 +62,9 @@ invariant (LocalRootPeers m gs) =
-- The localRootPeers groups must not overlap with each other
&& Map.size m == sum [ Set.size g | (_, g) <- gs ]

-- Individual group targets must be zero or more and achievable given the
-- group sizes.
&& and [ 0 <= t && t <= Set.size g | (t, g) <- gs ]
-- Individual group targets must be greater than zero and achievable given
-- the group sizes.
&& and [ 0 < t && t <= Set.size g | (t, g) <- gs ]


empty :: LocalRootPeers peeraddr
Expand Down Expand Up @@ -110,11 +110,11 @@ fromGroups =
-- The groups must not overlap; have achievable targets; and be non-empty.
establishStructureInvariant !_ [] = []
establishStructureInvariant !acc ((t, g): gs)
| not (Map.null g') = (t', g') : establishStructureInvariant acc' gs
| otherwise = establishStructureInvariant acc' gs
| t' > 0 = (t', g') : establishStructureInvariant acc' gs
| otherwise = establishStructureInvariant acc' gs
where
!g' = g `Map.withoutKeys` acc
!t' = min (max 0 t) (Map.size g')
!t' = min t (Map.size g')
!acc' = acc <> Map.keysSet g

-- | Inverse of 'fromGroups', for the subset of inputs to 'fromGroups' that
Expand Down

0 comments on commit 8c6c55f

Please sign in to comment.