{-# OPTIONS_GHC -Wno-orphans #-}

module Test.Ouroboros.Network.PeerSelection.PublicRootPeers
  ( arbitraryPublicRootPeers
  , tests
  ) where

import Data.Map.Strict (Map)
import Data.Map.Strict qualified as Map
import Data.Set (Set)
import Data.Set qualified as Set

import Ouroboros.Network.PeerSelection.PublicRootPeers (PublicRootPeers)
import Ouroboros.Network.PeerSelection.PublicRootPeers qualified as PublicRootPeers

import Ouroboros.Network.Testing.Utils (ShrinkCarefully, prop_shrink_nonequal,
           prop_shrink_valid)
import Test.Ouroboros.Network.PeerSelection.Instances


import Ouroboros.Network.PeerSelection.PeerAdvertise (PeerAdvertise)
import Ouroboros.Network.PeerSelection.PublicRootPeers (PublicRootPeers (..))
import Test.QuickCheck
import Test.Tasty (TestTree, testGroup)
import Test.Tasty.QuickCheck (testProperty)


tests :: TestTree
tests :: TestTree
tests =
  TestName -> [TestTree] -> TestTree
testGroup TestName
"Ouroboros.Network.PeerSelection"
  [ TestName -> [TestTree] -> TestTree
testGroup TestName
"PublicRootPeers"
    [ TestName -> (PublicRootPeers PeerAddr -> Property) -> TestTree
forall a. Testable a => TestName -> a -> TestTree
testProperty TestName
"arbitrary"              PublicRootPeers PeerAddr -> Property
prop_arbitrary_PublicRootPeers
    , TestName
-> (Map PeerAddr PeerAdvertise
    -> Set PeerAddr -> Set PeerAddr -> Set PeerAddr -> Bool)
-> TestTree
forall a. Testable a => TestName -> a -> TestTree
testProperty TestName
"fromMapAndSet"          Map PeerAddr PeerAdvertise
-> Set PeerAddr -> Set PeerAddr -> Set PeerAddr -> Bool
prop_fromMapAndSet
    , TestName
-> (Map PeerAddr PeerAdvertise
    -> Set PeerAddr -> Set PeerAddr -> Set PeerAddr -> Bool)
-> TestTree
forall a. Testable a => TestName -> a -> TestTree
testProperty TestName
"fromMapAndSet'"         Map PeerAddr PeerAdvertise
-> Set PeerAddr -> Set PeerAddr -> Set PeerAddr -> Bool
prop_fromMapAndSet'
    , TestName -> (PublicRootPeers PeerAddr -> Bool) -> TestTree
forall a. Testable a => TestName -> a -> TestTree
testProperty TestName
"fromToMapAndSet"        PublicRootPeers PeerAddr -> Bool
prop_fromToMapAndSet
    , TestName
-> (PublicRootPeers PeerAddr -> PublicRootPeers PeerAddr -> Bool)
-> TestTree
forall a. Testable a => TestName -> a -> TestTree
testProperty TestName
"merge"                  PublicRootPeers PeerAddr -> PublicRootPeers PeerAddr -> Bool
prop_merge
    , TestName
-> (PublicRootPeers PeerAddr -> PeerAddr -> PeerAdvertise -> Bool)
-> TestTree
forall a. Testable a => TestName -> a -> TestTree
testProperty TestName
"insertPublicConfigPeer" PublicRootPeers PeerAddr -> PeerAddr -> PeerAdvertise -> Bool
prop_insertPublicConfigPeer
    , TestName
-> (PublicRootPeers PeerAddr -> PeerAddr -> Bool) -> TestTree
forall a. Testable a => TestName -> a -> TestTree
testProperty TestName
"insertBootstrapPeer"    PublicRootPeers PeerAddr -> PeerAddr -> Bool
prop_insertBootstrapPeer
    , TestName
-> (PublicRootPeers PeerAddr -> PeerAddr -> Bool) -> TestTree
forall a. Testable a => TestName -> a -> TestTree
testProperty TestName
"insertLedgerPeer"       PublicRootPeers PeerAddr -> PeerAddr -> Bool
prop_insertLedgerPeer
    , TestName
-> (PublicRootPeers PeerAddr -> PeerAddr -> Bool) -> TestTree
forall a. Testable a => TestName -> a -> TestTree
testProperty TestName
"insertBigLedgerPeer"    PublicRootPeers PeerAddr -> PeerAddr -> Bool
prop_insertBigLedgerPeer
    , TestName -> (PeerAddr -> PeerAdvertise -> Bool) -> TestTree
forall a. Testable a => TestName -> a -> TestTree
testProperty TestName
"fromPeers"              PeerAddr -> PeerAdvertise -> Bool
prop_fromPeers
    , TestName
-> (ShrinkCarefully (PublicRootPeers PeerAddr) -> Property)
-> TestTree
forall a. Testable a => TestName -> a -> TestTree
testProperty TestName
"shrink"                 ShrinkCarefully (PublicRootPeers PeerAddr) -> Property
prop_shrink_PublicRootPeers
    ]
  ]

arbitraryPublicRootPeers :: Ord peeraddr
                        => Set peeraddr -> Gen (PublicRootPeers peeraddr)
arbitraryPublicRootPeers :: forall peeraddr.
Ord peeraddr =>
Set peeraddr -> Gen (PublicRootPeers peeraddr)
arbitraryPublicRootPeers Set peeraddr
peeraddrs = do
  let peersSize :: Int
peersSize = Set peeraddr -> Int
forall a. Set a -> Int
Set.size Set peeraddr
peeraddrs
      (Set peeraddr
publicConfigPeers, Set peeraddr
otherPeers) = Int -> Set peeraddr -> (Set peeraddr, Set peeraddr)
forall a. Int -> Set a -> (Set a, Set a)
Set.splitAt (Int
peersSize Int -> Int -> Int
forall a. Integral a => a -> a -> a
`div` Int
2) Set peeraddr
peeraddrs
      (Set peeraddr
bootstrapPeers, Set peeraddr
ledgerPeers) = Int -> Set peeraddr -> (Set peeraddr, Set peeraddr)
forall a. Int -> Set a -> (Set a, Set a)
Set.splitAt (Set peeraddr -> Int
forall a. Set a -> Int
Set.size Set peeraddr
otherPeers Int -> Int -> Int
forall a. Integral a => a -> a -> a
`div` Int
2) Set peeraddr
otherPeers
      (Set peeraddr
normalLedgerPeers, Set peeraddr
bigLedgerPeers) = Int -> Set peeraddr -> (Set peeraddr, Set peeraddr)
forall a. Int -> Set a -> (Set a, Set a)
Set.splitAt (Set peeraddr -> Int
forall a. Set a -> Int
Set.size Set peeraddr
ledgerPeers Int -> Int -> Int
forall a. Integral a => a -> a -> a
`div` Int
2) Set peeraddr
ledgerPeers

  advertiseInfo <- Int -> Gen PeerAdvertise -> Gen [PeerAdvertise]
forall a. Int -> Gen a -> Gen [a]
vectorOf (Set peeraddr -> Int
forall a. Set a -> Int
Set.size Set peeraddr
publicConfigPeers) Gen PeerAdvertise
forall a. Arbitrary a => Gen a
arbitrary

  let publicConfigPeersMap = [(peeraddr, PeerAdvertise)] -> Map peeraddr PeerAdvertise
forall k a. Ord k => [(k, a)] -> Map k a
Map.fromList
                           ([(peeraddr, PeerAdvertise)] -> Map peeraddr PeerAdvertise)
-> [(peeraddr, PeerAdvertise)] -> Map peeraddr PeerAdvertise
forall a b. (a -> b) -> a -> b
$ [peeraddr] -> [PeerAdvertise] -> [(peeraddr, PeerAdvertise)]
forall a b. [a] -> [b] -> [(a, b)]
zip (Set peeraddr -> [peeraddr]
forall a. Set a -> [a]
Set.toList Set peeraddr
publicConfigPeers) [PeerAdvertise]
advertiseInfo

  return (PublicRootPeers.fromMapAndSet publicConfigPeersMap bootstrapPeers normalLedgerPeers bigLedgerPeers)

instance (Arbitrary peeraddr, Ord peeraddr) =>
         Arbitrary (PublicRootPeers peeraddr) where
    arbitrary :: Gen (PublicRootPeers peeraddr)
arbitrary = do
        peeraddrs <- Gen (Set peeraddr)
forall a. Arbitrary a => Gen a
arbitrary
        arbitraryPublicRootPeers peeraddrs

    shrink :: PublicRootPeers peeraddr -> [PublicRootPeers peeraddr]
shrink (PublicRootPeers Map peeraddr PeerAdvertise
pp Set peeraddr
bsp Set peeraddr
lp Set peeraddr
blp) =
        Map peeraddr PeerAdvertise
-> Set peeraddr
-> Set peeraddr
-> Set peeraddr
-> PublicRootPeers peeraddr
forall peeraddr.
Ord peeraddr =>
Map peeraddr PeerAdvertise
-> Set peeraddr
-> Set peeraddr
-> Set peeraddr
-> PublicRootPeers peeraddr
PublicRootPeers.fromMapAndSet (Map peeraddr PeerAdvertise
 -> Set peeraddr
 -> Set peeraddr
 -> Set peeraddr
 -> PublicRootPeers peeraddr)
-> [Map peeraddr PeerAdvertise]
-> [Set peeraddr
    -> Set peeraddr -> Set peeraddr -> PublicRootPeers peeraddr]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Map peeraddr PeerAdvertise -> [Map peeraddr PeerAdvertise]
forall a. Arbitrary a => a -> [a]
shrink Map peeraddr PeerAdvertise
pp
                                      [Set peeraddr
 -> Set peeraddr -> Set peeraddr -> PublicRootPeers peeraddr]
-> [Set peeraddr]
-> [Set peeraddr -> Set peeraddr -> PublicRootPeers peeraddr]
forall a b. [a -> b] -> [a] -> [b]
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Set peeraddr -> [Set peeraddr]
forall a. Arbitrary a => a -> [a]
shrink Set peeraddr
bsp
                                      [Set peeraddr -> Set peeraddr -> PublicRootPeers peeraddr]
-> [Set peeraddr] -> [Set peeraddr -> PublicRootPeers peeraddr]
forall a b. [a -> b] -> [a] -> [b]
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Set peeraddr -> [Set peeraddr]
forall a. Arbitrary a => a -> [a]
shrink Set peeraddr
lp
                                      [Set peeraddr -> PublicRootPeers peeraddr]
-> [Set peeraddr] -> [PublicRootPeers peeraddr]
forall a b. [a -> b] -> [a] -> [b]
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Set peeraddr -> [Set peeraddr]
forall a. Arbitrary a => a -> [a]
shrink Set peeraddr
blp

prop_arbitrary_PublicRootPeers :: PublicRootPeers PeerAddr -> Property
prop_arbitrary_PublicRootPeers :: PublicRootPeers PeerAddr -> Property
prop_arbitrary_PublicRootPeers = Bool -> Property
forall prop. Testable prop => prop -> Property
property (Bool -> Property)
-> (PublicRootPeers PeerAddr -> Bool)
-> PublicRootPeers PeerAddr
-> Property
forall b c a. (b -> c) -> (a -> b) -> a -> c
. PublicRootPeers PeerAddr -> Bool
forall peeraddr. Ord peeraddr => PublicRootPeers peeraddr -> Bool
PublicRootPeers.invariant


prop_shrink_PublicRootPeers :: ShrinkCarefully (PublicRootPeers PeerAddr) -> Property
prop_shrink_PublicRootPeers :: ShrinkCarefully (PublicRootPeers PeerAddr) -> Property
prop_shrink_PublicRootPeers ShrinkCarefully (PublicRootPeers PeerAddr)
x =
      (PublicRootPeers PeerAddr -> Bool)
-> ShrinkCarefully (PublicRootPeers PeerAddr) -> Property
forall a prop.
(Arbitrary a, Show a, Testable prop) =>
(a -> prop) -> ShrinkCarefully a -> Property
prop_shrink_valid PublicRootPeers PeerAddr -> Bool
forall peeraddr. Ord peeraddr => PublicRootPeers peeraddr -> Bool
PublicRootPeers.invariant ShrinkCarefully (PublicRootPeers PeerAddr)
x
 Property -> Property -> Property
forall prop1 prop2.
(Testable prop1, Testable prop2) =>
prop1 -> prop2 -> Property
.&&. ShrinkCarefully (PublicRootPeers PeerAddr) -> Property
forall a.
(Arbitrary a, Eq a, Show a) =>
ShrinkCarefully a -> Property
prop_shrink_nonequal ShrinkCarefully (PublicRootPeers PeerAddr)
x

prop_fromMapAndSet :: Map PeerAddr PeerAdvertise
                   -> Set PeerAddr
                   -> Set PeerAddr
                   -> Set PeerAddr
                   -> Bool
prop_fromMapAndSet :: Map PeerAddr PeerAdvertise
-> Set PeerAddr -> Set PeerAddr -> Set PeerAddr -> Bool
prop_fromMapAndSet Map PeerAddr PeerAdvertise
pp Set PeerAddr
bsp Set PeerAddr
lp = PublicRootPeers PeerAddr -> Bool
forall peeraddr. Ord peeraddr => PublicRootPeers peeraddr -> Bool
PublicRootPeers.invariant
                             (PublicRootPeers PeerAddr -> Bool)
-> (Set PeerAddr -> PublicRootPeers PeerAddr)
-> Set PeerAddr
-> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Map PeerAddr PeerAdvertise
-> Set PeerAddr
-> Set PeerAddr
-> Set PeerAddr
-> PublicRootPeers PeerAddr
forall peeraddr.
Ord peeraddr =>
Map peeraddr PeerAdvertise
-> Set peeraddr
-> Set peeraddr
-> Set peeraddr
-> PublicRootPeers peeraddr
PublicRootPeers.fromMapAndSet Map PeerAddr PeerAdvertise
pp Set PeerAddr
bsp Set PeerAddr
lp

prop_fromToMapAndSet :: PublicRootPeers PeerAddr -> Bool
prop_fromToMapAndSet :: PublicRootPeers PeerAddr -> Bool
prop_fromToMapAndSet prp :: PublicRootPeers PeerAddr
prp@(PublicRootPeers Map PeerAddr PeerAdvertise
pp Set PeerAddr
bsp Set PeerAddr
lp Set PeerAddr
blp) =
  Map PeerAddr PeerAdvertise
-> Set PeerAddr
-> Set PeerAddr
-> Set PeerAddr
-> PublicRootPeers PeerAddr
forall peeraddr.
Ord peeraddr =>
Map peeraddr PeerAdvertise
-> Set peeraddr
-> Set peeraddr
-> Set peeraddr
-> PublicRootPeers peeraddr
PublicRootPeers.fromMapAndSet Map PeerAddr PeerAdvertise
pp Set PeerAddr
bsp Set PeerAddr
lp Set PeerAddr
blp PublicRootPeers PeerAddr -> PublicRootPeers PeerAddr -> Bool
forall a. Eq a => a -> a -> Bool
== PublicRootPeers PeerAddr
prp

prop_fromMapAndSet' :: Map PeerAddr PeerAdvertise
                   -> Set PeerAddr
                   -> Set PeerAddr
                   -> Set PeerAddr
                   -> Bool
prop_fromMapAndSet' :: Map PeerAddr PeerAdvertise
-> Set PeerAddr -> Set PeerAddr -> Set PeerAddr -> Bool
prop_fromMapAndSet' Map PeerAddr PeerAdvertise
pp Set PeerAddr
bsp Set PeerAddr
lp Set PeerAddr
blp =
  -- Make sets disjoint
  let pp' :: Map PeerAddr PeerAdvertise
pp'  = Map PeerAddr PeerAdvertise
-> Set PeerAddr -> Map PeerAddr PeerAdvertise
forall k a. Ord k => Map k a -> Set k -> Map k a
Map.withoutKeys Map PeerAddr PeerAdvertise
pp (Set PeerAddr
bsp Set PeerAddr -> Set PeerAddr -> Set PeerAddr
forall a. Semigroup a => a -> a -> a
<> Set PeerAddr
lp Set PeerAddr -> Set PeerAddr -> Set PeerAddr
forall a. Semigroup a => a -> a -> a
<> Set PeerAddr
blp)
      bsp' :: Set PeerAddr
bsp' = Set PeerAddr -> Set PeerAddr -> Set PeerAddr
forall a. Ord a => Set a -> Set a -> Set a
Set.difference Set PeerAddr
bsp (Set PeerAddr
lp Set PeerAddr -> Set PeerAddr -> Set PeerAddr
forall a. Semigroup a => a -> a -> a
<> Set PeerAddr
blp)
      lp' :: Set PeerAddr
lp'  = Set PeerAddr -> Set PeerAddr -> Set PeerAddr
forall a. Ord a => Set a -> Set a -> Set a
Set.difference Set PeerAddr
lp Set PeerAddr
blp
      prp :: PublicRootPeers PeerAddr
prp = Map PeerAddr PeerAdvertise
-> Set PeerAddr
-> Set PeerAddr
-> Set PeerAddr
-> PublicRootPeers PeerAddr
forall peeraddr.
Ord peeraddr =>
Map peeraddr PeerAdvertise
-> Set peeraddr
-> Set peeraddr
-> Set peeraddr
-> PublicRootPeers peeraddr
PublicRootPeers.fromMapAndSet Map PeerAddr PeerAdvertise
pp' Set PeerAddr
bsp' Set PeerAddr
lp' Set PeerAddr
blp
   in  PublicRootPeers PeerAddr -> Map PeerAddr PeerAdvertise
forall peeraddr.
PublicRootPeers peeraddr -> Map peeraddr PeerAdvertise
PublicRootPeers.getPublicConfigPeers PublicRootPeers PeerAddr
prp Map PeerAddr PeerAdvertise -> Map PeerAddr PeerAdvertise -> Bool
forall a. Eq a => a -> a -> Bool
== Map PeerAddr PeerAdvertise
pp'
    Bool -> Bool -> Bool
&& PublicRootPeers PeerAddr -> Set PeerAddr
forall peeraddr. PublicRootPeers peeraddr -> Set peeraddr
PublicRootPeers.getBootstrapPeers PublicRootPeers PeerAddr
prp    Set PeerAddr -> Set PeerAddr -> Bool
forall a. Eq a => a -> a -> Bool
== Set PeerAddr
bsp'
    Bool -> Bool -> Bool
&& PublicRootPeers PeerAddr -> Set PeerAddr
forall peeraddr. PublicRootPeers peeraddr -> Set peeraddr
PublicRootPeers.getLedgerPeers PublicRootPeers PeerAddr
prp       Set PeerAddr -> Set PeerAddr -> Bool
forall a. Eq a => a -> a -> Bool
== Set PeerAddr
lp'
    Bool -> Bool -> Bool
&& PublicRootPeers PeerAddr -> Set PeerAddr
forall peeraddr. PublicRootPeers peeraddr -> Set peeraddr
PublicRootPeers.getBigLedgerPeers PublicRootPeers PeerAddr
prp    Set PeerAddr -> Set PeerAddr -> Bool
forall a. Eq a => a -> a -> Bool
== Set PeerAddr
blp

prop_merge :: PublicRootPeers PeerAddr -> PublicRootPeers PeerAddr -> Bool
prop_merge :: PublicRootPeers PeerAddr -> PublicRootPeers PeerAddr -> Bool
prop_merge PublicRootPeers PeerAddr
prp = PublicRootPeers PeerAddr -> Bool
forall peeraddr. Ord peeraddr => PublicRootPeers peeraddr -> Bool
PublicRootPeers.invariant
               (PublicRootPeers PeerAddr -> Bool)
-> (PublicRootPeers PeerAddr -> PublicRootPeers PeerAddr)
-> PublicRootPeers PeerAddr
-> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (PublicRootPeers PeerAddr
-> PublicRootPeers PeerAddr -> PublicRootPeers PeerAddr
forall a. Semigroup a => a -> a -> a
<> PublicRootPeers PeerAddr
prp)

prop_insertPublicConfigPeer :: PublicRootPeers PeerAddr
                            -> PeerAddr
                            -> PeerAdvertise
                            -> Bool
prop_insertPublicConfigPeer :: PublicRootPeers PeerAddr -> PeerAddr -> PeerAdvertise -> Bool
prop_insertPublicConfigPeer PublicRootPeers PeerAddr
prp PeerAddr
p PeerAdvertise
pa =
  PublicRootPeers PeerAddr -> Bool
forall peeraddr. Ord peeraddr => PublicRootPeers peeraddr -> Bool
PublicRootPeers.invariant (PeerAddr
-> PeerAdvertise
-> PublicRootPeers PeerAddr
-> PublicRootPeers PeerAddr
forall peeraddr.
Ord peeraddr =>
peeraddr
-> PeerAdvertise
-> PublicRootPeers peeraddr
-> PublicRootPeers peeraddr
PublicRootPeers.insertPublicConfigPeer PeerAddr
p PeerAdvertise
pa PublicRootPeers PeerAddr
prp)

prop_insertBootstrapPeer :: PublicRootPeers PeerAddr
                         -> PeerAddr
                         -> Bool
prop_insertBootstrapPeer :: PublicRootPeers PeerAddr -> PeerAddr -> Bool
prop_insertBootstrapPeer PublicRootPeers PeerAddr
prp PeerAddr
p =
  PublicRootPeers PeerAddr -> Bool
forall peeraddr. Ord peeraddr => PublicRootPeers peeraddr -> Bool
PublicRootPeers.invariant (PeerAddr -> PublicRootPeers PeerAddr -> PublicRootPeers PeerAddr
forall peeraddr.
Ord peeraddr =>
peeraddr -> PublicRootPeers peeraddr -> PublicRootPeers peeraddr
PublicRootPeers.insertBootstrapPeer PeerAddr
p PublicRootPeers PeerAddr
prp)

prop_insertLedgerPeer :: PublicRootPeers PeerAddr
                      -> PeerAddr
                      -> Bool
prop_insertLedgerPeer :: PublicRootPeers PeerAddr -> PeerAddr -> Bool
prop_insertLedgerPeer PublicRootPeers PeerAddr
prp PeerAddr
p =
  PublicRootPeers PeerAddr -> Bool
forall peeraddr. Ord peeraddr => PublicRootPeers peeraddr -> Bool
PublicRootPeers.invariant (PeerAddr -> PublicRootPeers PeerAddr -> PublicRootPeers PeerAddr
forall peeraddr.
Ord peeraddr =>
peeraddr -> PublicRootPeers peeraddr -> PublicRootPeers peeraddr
PublicRootPeers.insertLedgerPeer PeerAddr
p PublicRootPeers PeerAddr
prp)

prop_insertBigLedgerPeer :: PublicRootPeers PeerAddr
                         -> PeerAddr
                         -> Bool
prop_insertBigLedgerPeer :: PublicRootPeers PeerAddr -> PeerAddr -> Bool
prop_insertBigLedgerPeer PublicRootPeers PeerAddr
prp PeerAddr
p =
  PublicRootPeers PeerAddr -> Bool
forall peeraddr. Ord peeraddr => PublicRootPeers peeraddr -> Bool
PublicRootPeers.invariant (PeerAddr -> PublicRootPeers PeerAddr -> PublicRootPeers PeerAddr
forall peeraddr.
Ord peeraddr =>
peeraddr -> PublicRootPeers peeraddr -> PublicRootPeers peeraddr
PublicRootPeers.insertBigLedgerPeer PeerAddr
p PublicRootPeers PeerAddr
prp)

prop_fromPeers :: PeerAddr
               -> PeerAdvertise
               -> Bool
prop_fromPeers :: PeerAddr -> PeerAdvertise -> Bool
prop_fromPeers PeerAddr
peer PeerAdvertise
peerAdvertise =
  let insertPP :: PublicRootPeers PeerAddr
insertPP  = PeerAddr
-> PeerAdvertise
-> PublicRootPeers PeerAddr
-> PublicRootPeers PeerAddr
forall peeraddr.
Ord peeraddr =>
peeraddr
-> PeerAdvertise
-> PublicRootPeers peeraddr
-> PublicRootPeers peeraddr
PublicRootPeers.insertPublicConfigPeer PeerAddr
peer PeerAdvertise
peerAdvertise PublicRootPeers PeerAddr
forall peeraddr. PublicRootPeers peeraddr
PublicRootPeers.empty
      insertBSP :: PublicRootPeers PeerAddr
insertBSP = PeerAddr -> PublicRootPeers PeerAddr -> PublicRootPeers PeerAddr
forall peeraddr.
Ord peeraddr =>
peeraddr -> PublicRootPeers peeraddr -> PublicRootPeers peeraddr
PublicRootPeers.insertBootstrapPeer PeerAddr
peer PublicRootPeers PeerAddr
forall peeraddr. PublicRootPeers peeraddr
PublicRootPeers.empty
      insertLP :: PublicRootPeers PeerAddr
insertLP  = PeerAddr -> PublicRootPeers PeerAddr -> PublicRootPeers PeerAddr
forall peeraddr.
Ord peeraddr =>
peeraddr -> PublicRootPeers peeraddr -> PublicRootPeers peeraddr
PublicRootPeers.insertLedgerPeer PeerAddr
peer PublicRootPeers PeerAddr
forall peeraddr. PublicRootPeers peeraddr
PublicRootPeers.empty
      insertBLP :: PublicRootPeers PeerAddr
insertBLP = PeerAddr -> PublicRootPeers PeerAddr -> PublicRootPeers PeerAddr
forall peeraddr.
Ord peeraddr =>
peeraddr -> PublicRootPeers peeraddr -> PublicRootPeers peeraddr
PublicRootPeers.insertBigLedgerPeer PeerAddr
peer PublicRootPeers PeerAddr
forall peeraddr. PublicRootPeers peeraddr
PublicRootPeers.empty
   in    PublicRootPeers PeerAddr -> Map PeerAddr PeerAdvertise
forall peeraddr.
PublicRootPeers peeraddr -> Map peeraddr PeerAdvertise
PublicRootPeers.getPublicConfigPeers PublicRootPeers PeerAddr
insertPP Map PeerAddr PeerAdvertise -> Map PeerAddr PeerAdvertise -> Bool
forall a. Eq a => a -> a -> Bool
== PeerAddr -> PeerAdvertise -> Map PeerAddr PeerAdvertise
forall k a. k -> a -> Map k a
Map.singleton PeerAddr
peer PeerAdvertise
peerAdvertise
      Bool -> Bool -> Bool
&& PublicRootPeers PeerAddr -> Set PeerAddr
forall peeraddr. PublicRootPeers peeraddr -> Set peeraddr
PublicRootPeers.getBootstrapPeers PublicRootPeers PeerAddr
insertBSP   Set PeerAddr -> Set PeerAddr -> Bool
forall a. Eq a => a -> a -> Bool
== PeerAddr -> Set PeerAddr
forall a. a -> Set a
Set.singleton PeerAddr
peer
      Bool -> Bool -> Bool
&& PublicRootPeers PeerAddr -> Set PeerAddr
forall peeraddr. PublicRootPeers peeraddr -> Set peeraddr
PublicRootPeers.getLedgerPeers PublicRootPeers PeerAddr
insertLP       Set PeerAddr -> Set PeerAddr -> Bool
forall a. Eq a => a -> a -> Bool
== PeerAddr -> Set PeerAddr
forall a. a -> Set a
Set.singleton PeerAddr
peer
      Bool -> Bool -> Bool
&& PublicRootPeers PeerAddr -> Set PeerAddr
forall peeraddr. PublicRootPeers peeraddr -> Set peeraddr
PublicRootPeers.getBigLedgerPeers PublicRootPeers PeerAddr
insertBLP   Set PeerAddr -> Set PeerAddr -> Bool
forall a. Eq a => a -> a -> Bool
== PeerAddr -> Set PeerAddr
forall a. a -> Set a
Set.singleton PeerAddr
peer