{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE CPP #-}
{-# LANGUAGE DeriveFunctor #-}
{-# LANGUAGE DerivingStrategies #-}
{-# LANGUAGE DerivingVia #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE GeneralisedNewtypeDeriving #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE NumericUnderscores #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE StandaloneDeriving #-}
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE ViewPatterns #-}
{-# OPTIONS_GHC -Wno-orphans #-}
{-# OPTIONS_GHC -Wno-unused-top-binds #-}
{-# OPTIONS_GHC -Wno-incomplete-uni-patterns #-}
#if __GLASGOW_HASKELL__ >= 908
{-# OPTIONS_GHC -Wno-x-partial #-}
#endif
module Test.Ouroboros.Network.PeerSelection
( tests
, unfHydra
, takeBigLedgerPeers
, dropBigLedgerPeers
) where
import Control.Concurrent.Class.MonadSTM.Strict
import Control.Exception (AssertionFailed (..), catch, evaluate)
import Control.Monad (when)
import Control.Monad.Class.MonadTime.SI
import Control.Monad.Class.MonadTimer.SI
import Control.Tracer (Tracer (..))
import Data.Bifoldable (bitraverse_)
import Data.ByteString.Char8 qualified as BS
import Data.Foldable (traverse_)
import Data.Function (on)
import Data.IP qualified as IP
import Data.List as List (foldl', groupBy, intercalate)
import Data.List.NonEmpty qualified as NonEmpty
import Data.List.Trace qualified as Trace
import Data.Map.Strict (Map)
import Data.Map.Strict qualified as Map
import Data.Maybe (fromMaybe, isNothing, listToMaybe)
import Data.OrdPSQ qualified as PSQ
import Data.Set (Set)
import Data.Set qualified as Set
import Data.Void (Void)
import System.Random (mkStdGen)
import Network.DNS qualified as DNS (defaultResolvConf)
import Network.Socket (SockAddr)
import Ouroboros.Network.ConsensusMode
import Ouroboros.Network.ExitPolicy (RepromoteDelay (..))
import Ouroboros.Network.NodeToNode.Version (DiffusionMode (..))
import Ouroboros.Network.PeerSelection.Bootstrap (UseBootstrapPeers (..),
requiresBootstrapPeers)
import Ouroboros.Network.PeerSelection.Governor hiding (PeerSelectionState (..),
peerSharing)
import Ouroboros.Network.PeerSelection.Governor qualified as Governor
import Ouroboros.Network.PeerSelection.LedgerPeers
import Ouroboros.Network.PeerSelection.LocalRootPeers (OutboundConnectionsState)
import Ouroboros.Network.PeerSelection.PeerAdvertise
import Ouroboros.Network.PeerSelection.PeerSharing (PeerSharing (..))
import Ouroboros.Network.PeerSelection.PeerTrustable (PeerTrustable (..))
import Ouroboros.Network.PeerSelection.PublicRootPeers (PublicRootPeers)
import Ouroboros.Network.PeerSelection.PublicRootPeers qualified as PublicRootPeers
import Ouroboros.Network.PeerSelection.RootPeersDNS.DNSActions
import Ouroboros.Network.PeerSelection.RootPeersDNS.DNSSemaphore
import Ouroboros.Network.PeerSelection.RootPeersDNS.PublicRootPeers
import Ouroboros.Network.PeerSelection.State.EstablishedPeers qualified as EstablishedPeers
import Ouroboros.Network.PeerSelection.State.KnownPeers qualified as KnownPeers
import Ouroboros.Network.PeerSelection.State.LocalRootPeers (HotValency (..),
LocalRootConfig (..), LocalRootPeers (..), WarmValency (..))
import Ouroboros.Network.PeerSelection.State.LocalRootPeers qualified as LocalRootPeers
import Ouroboros.Network.Point
import Ouroboros.Network.Protocol.PeerSharing.Type (PeerSharingResult (..))
import Ouroboros.Network.Testing.Data.Script
import Ouroboros.Network.Testing.Data.Signal (E (E), Events, Signal, TS (TS),
signalProperty)
import Ouroboros.Network.Testing.Data.Signal qualified as Signal
import Ouroboros.Network.Testing.Utils (disjointSetsProperty, isSubsetProperty,
nightlyTest)
import Test.Ouroboros.Network.PeerSelection.Instances
import Test.Ouroboros.Network.PeerSelection.MockEnvironment hiding (tests)
import Test.Ouroboros.Network.PeerSelection.PeerGraph
import Control.Monad.IOSim
import Test.QuickCheck
import Test.QuickCheck.Monoids
import Test.Tasty
import Test.Tasty.QuickCheck
import Text.Pretty.Simple
unfHydra :: Int
unfHydra :: Int
unfHydra = Int
1
tests :: TestTree
tests :: TestTree
tests =
TestName -> [TestTree] -> TestTree
testGroup TestName
"Ouroboros.Network.PeerSelection"
[ TestName -> [TestTree] -> TestTree
testGroup TestName
"PeerSelectionView"
[ TestName -> (GovernorMockEnvironment -> Property) -> TestTree
forall a. Testable a => TestName -> a -> TestTree
testProperty TestName
"sizes" GovernorMockEnvironment -> Property
prop_peerSelectionView_sizes
]
, TestName -> [TestTree] -> TestTree
testGroup TestName
"basic"
[ TestName -> (GovernorMockEnvironment -> Property) -> TestTree
forall a. Testable a => TestName -> a -> TestTree
testProperty TestName
"has output" GovernorMockEnvironment -> Property
prop_governor_hasoutput
, TestName -> (GovernorMockEnvironment -> Property) -> TestTree
forall a. Testable a => TestName -> a -> TestTree
testProperty TestName
"no failure" GovernorMockEnvironment -> Property
prop_governor_nofail
, TestName -> (GovernorMockEnvironment -> Property) -> TestTree
forall a. Testable a => TestName -> a -> TestTree
testProperty TestName
"no livelock" GovernorMockEnvironment -> Property
prop_governor_nolivelock
]
, DependencyType -> TestName -> TestTree -> TestTree
after DependencyType
AllSucceed TestName
"Ouroboros.Network.PeerSelection.basic" (TestTree -> TestTree) -> TestTree -> TestTree
forall a b. (a -> b) -> a -> b
$
TestName -> [TestTree] -> TestTree
testGroup TestName
"safety"
[ TestName -> (GovernorMockEnvironment -> Property) -> TestTree
forall a. Testable a => TestName -> a -> TestTree
testProperty TestName
"no excess busyness" GovernorMockEnvironment -> Property
prop_governor_nobusyness
, TestName -> (GovernorMockEnvironment -> Property) -> TestTree
forall a. Testable a => TestName -> a -> TestTree
testProperty TestName
"event coverage" GovernorMockEnvironment -> Property
prop_governor_trace_coverage
, TestName -> (GovernorMockEnvironment -> Property) -> TestTree
forall a. Testable a => TestName -> a -> TestTree
testProperty TestName
"connection status" GovernorMockEnvironment -> Property
prop_governor_connstatus
, TestName -> (GovernorMockEnvironment -> Property) -> TestTree
forall a. Testable a => TestName -> a -> TestTree
testProperty TestName
"event number coverage" GovernorMockEnvironment -> Property
prop_governor_events_coverage
]
, DependencyType -> TestName -> TestTree -> TestTree
after DependencyType
AllSucceed TestName
"Ouroboros.Network.PeerSelection.basic" (TestTree -> TestTree) -> TestTree -> TestTree
forall a b. (a -> b) -> a -> b
$
TestName -> [TestTree] -> TestTree
testGroup TestName
"progress"
[ TestName -> [TestTree] -> TestTree
testGroup TestName
"ledger peers"
[ TestName
-> (MaxTime -> GovernorMockEnvironment -> Property) -> TestTree
forall a. Testable a => TestName -> a -> TestTree
testProperty TestName
"progresses towards known target (from below)"
MaxTime -> GovernorMockEnvironment -> Property
prop_governor_target_known_below
, TestName
-> (MaxTime -> GovernorMockEnvironment -> Property) -> TestTree
forall a. Testable a => TestName -> a -> TestTree
testProperty TestName
"progresses towards known target (from above)"
MaxTime -> GovernorMockEnvironment -> Property
prop_governor_target_known_above
, TestName
-> (MaxTime -> GovernorMockEnvironment -> Property) -> TestTree
forall a. Testable a => TestName -> a -> TestTree
testProperty TestName
"progresses towards established target (from below)"
MaxTime -> GovernorMockEnvironment -> Property
prop_governor_target_established_below
, TestName
-> (MaxTime -> GovernorMockEnvironment -> Property) -> TestTree
forall a. Testable a => TestName -> a -> TestTree
testProperty TestName
"progresses towards established target (from above)"
MaxTime -> GovernorMockEnvironment -> Property
prop_governor_target_established_above
, TestName
-> (MaxTime -> GovernorMockEnvironment -> Property) -> TestTree
forall a. Testable a => TestName -> a -> TestTree
testProperty TestName
"progresses towards active target (from below)"
MaxTime -> GovernorMockEnvironment -> Property
prop_governor_target_active_below
, TestName
-> (MaxTime -> GovernorMockEnvironment -> Property) -> TestTree
forall a. Testable a => TestName -> a -> TestTree
testProperty TestName
"progresses towards active target (from above)"
MaxTime -> GovernorMockEnvironment -> Property
prop_governor_target_active_above
]
, TestName -> [TestTree] -> TestTree
testGroup TestName
"public root peers"
[ TestName -> (GovernorMockEnvironment -> Property) -> TestTree
forall a. Testable a => TestName -> a -> TestTree
testProperty TestName
"progresses towards target (from below)"
GovernorMockEnvironment -> Property
prop_governor_target_root_below
, TestName
-> (MaxTime -> GovernorMockEnvironment -> Property) -> TestTree
forall a. Testable a => TestName -> a -> TestTree
testProperty TestName
"progresses towards established peers"
MaxTime -> GovernorMockEnvironment -> Property
prop_governor_target_established_public
, TestName
-> (MaxTime -> GovernorMockEnvironment -> Property) -> TestTree
forall a. Testable a => TestName -> a -> TestTree
testProperty TestName
"progresses towards active peers"
MaxTime -> GovernorMockEnvironment -> Property
prop_governor_target_active_public
]
, TestName -> [TestTree] -> TestTree
testGroup TestName
"local root peers"
[ TestName
-> (MaxTime -> GovernorMockEnvironment -> Property) -> TestTree
forall a. Testable a => TestName -> a -> TestTree
testProperty TestName
"progresses towards established target"
MaxTime -> GovernorMockEnvironment -> Property
prop_governor_target_established_local
, TestName
-> (MaxTime -> GovernorMockEnvironment -> Property) -> TestTree
forall a. Testable a => TestName -> a -> TestTree
testProperty TestName
"progresses towards active target (from below)"
MaxTime -> GovernorMockEnvironment -> Property
prop_governor_target_active_local_below
, TestName
-> (MaxTime -> GovernorMockEnvironment -> Property) -> TestTree
forall a. Testable a => TestName -> a -> TestTree
testProperty TestName
"progresses towards active target (from above)"
MaxTime -> GovernorMockEnvironment -> Property
prop_governor_target_active_local_above
]
, TestName -> [TestTree] -> TestTree
testGroup TestName
"big ledger peers"
[ TestName
-> (MaxTime -> GovernorMockEnvironment -> Property) -> TestTree
forall a. Testable a => TestName -> a -> TestTree
testProperty TestName
"progresses towards known target (from below)"
MaxTime -> GovernorMockEnvironment -> Property
prop_governor_target_known_big_ledger_peers_below
, TestName
-> (MaxTime -> GovernorMockEnvironment -> Property) -> TestTree
forall a. Testable a => TestName -> a -> TestTree
testProperty TestName
"progresses towards known target (from above)"
MaxTime -> GovernorMockEnvironment -> Property
prop_governor_target_known_big_ledger_peers_above
, TestName
-> (MaxTime -> GovernorMockEnvironment -> Property) -> TestTree
forall a. Testable a => TestName -> a -> TestTree
testProperty TestName
"progresses towards established target"
MaxTime -> GovernorMockEnvironment -> Property
prop_governor_target_established_big_ledger_peers
, TestName
-> (MaxTime -> GovernorMockEnvironment -> Property) -> TestTree
forall a. Testable a => TestName -> a -> TestTree
testProperty TestName
"progresses towards established target (from below)"
MaxTime -> GovernorMockEnvironment -> Property
prop_governor_target_established_big_ledger_peers_below
, TestName
-> (MaxTime -> GovernorMockEnvironment -> Property) -> TestTree
forall a. Testable a => TestName -> a -> TestTree
testProperty TestName
"progresses towards established target (from above)"
MaxTime -> GovernorMockEnvironment -> Property
prop_governor_target_established_big_ledger_peers_above
, TestName
-> (MaxTime -> GovernorMockEnvironment -> Property) -> TestTree
forall a. Testable a => TestName -> a -> TestTree
testProperty TestName
"progresses towards active target (from below)"
MaxTime -> GovernorMockEnvironment -> Property
prop_governor_target_active_big_ledger_peers_below
, TestName
-> (MaxTime -> GovernorMockEnvironment -> Property) -> TestTree
forall a. Testable a => TestName -> a -> TestTree
testProperty TestName
"progresses towards active target (from above)"
MaxTime -> GovernorMockEnvironment -> Property
prop_governor_target_active_big_ledger_peers_above
]
,
TestName -> [TestTree] -> TestTree
testGroup TestName
"bootstrap peers"
[ TestName -> (GovernorPraosMockEnvironment -> Property) -> TestTree
forall a. Testable a => TestName -> a -> TestTree
testProperty TestName
"progress towards only bootstrap peers after changing to fallback state"
((GovernorPraosMockEnvironment -> Property) -> TestTree)
-> (GovernorPraosMockEnvironment -> Property) -> TestTree
forall a b. (a -> b) -> a -> b
$ GovernorMockEnvironment -> Property
prop_governor_only_bootstrap_peers_in_fallback_state (GovernorMockEnvironment -> Property)
-> (GovernorPraosMockEnvironment -> GovernorMockEnvironment)
-> GovernorPraosMockEnvironment
-> Property
forall b c a. (b -> c) -> (a -> b) -> a -> c
. GovernorPraosMockEnvironment -> GovernorMockEnvironment
getMockEnv
, TestName -> (GovernorPraosMockEnvironment -> Property) -> TestTree
forall a. Testable a => TestName -> a -> TestTree
testProperty TestName
"node does not learn about non trustable peers when in fallback state"
((GovernorPraosMockEnvironment -> Property) -> TestTree)
-> (GovernorPraosMockEnvironment -> Property) -> TestTree
forall a b. (a -> b) -> a -> b
$ GovernorMockEnvironment -> Property
prop_governor_no_non_trustable_peers_before_caught_up_state (GovernorMockEnvironment -> Property)
-> (GovernorPraosMockEnvironment -> GovernorMockEnvironment)
-> GovernorPraosMockEnvironment
-> Property
forall b c a. (b -> c) -> (a -> b) -> a -> c
. GovernorPraosMockEnvironment -> GovernorMockEnvironment
getMockEnv
, TestName -> (GovernorPraosMockEnvironment -> Property) -> TestTree
forall a. Testable a => TestName -> a -> TestTree
testProperty TestName
"node only use bootstrap peers if in sensitive state"
((GovernorPraosMockEnvironment -> Property) -> TestTree)
-> (GovernorPraosMockEnvironment -> Property) -> TestTree
forall a b. (a -> b) -> a -> b
$ GovernorMockEnvironment -> Property
prop_governor_stops_using_bootstrap_peers (GovernorMockEnvironment -> Property)
-> (GovernorPraosMockEnvironment -> GovernorMockEnvironment)
-> GovernorPraosMockEnvironment
-> Property
forall b c a. (b -> c) -> (a -> b) -> a -> c
. GovernorPraosMockEnvironment -> GovernorMockEnvironment
getMockEnv
, TestName -> (GovernorPraosMockEnvironment -> Property) -> TestTree
forall a. Testable a => TestName -> a -> TestTree
testProperty TestName
"node never uses non-trustable peers in clean state"
((GovernorPraosMockEnvironment -> Property) -> TestTree)
-> (GovernorPraosMockEnvironment -> Property) -> TestTree
forall a b. (a -> b) -> a -> b
$ GovernorMockEnvironment -> Property
prop_governor_only_bootstrap_peers_in_clean_state (GovernorMockEnvironment -> Property)
-> (GovernorPraosMockEnvironment -> GovernorMockEnvironment)
-> GovernorPraosMockEnvironment
-> Property
forall b c a. (b -> c) -> (a -> b) -> a -> c
. GovernorPraosMockEnvironment -> GovernorMockEnvironment
getMockEnv
, TestName -> (GovernorPraosMockEnvironment -> Property) -> TestTree
forall a. Testable a => TestName -> a -> TestTree
testProperty TestName
"node uses ledger peers in non-sensitive mode"
((GovernorPraosMockEnvironment -> Property) -> TestTree)
-> (GovernorPraosMockEnvironment -> Property) -> TestTree
forall a b. (a -> b) -> a -> b
$ GovernorMockEnvironment -> Property
prop_governor_uses_ledger_peers (GovernorMockEnvironment -> Property)
-> (GovernorPraosMockEnvironment -> GovernorMockEnvironment)
-> GovernorPraosMockEnvironment
-> Property
forall b c a. (b -> c) -> (a -> b) -> a -> c
. GovernorPraosMockEnvironment -> GovernorMockEnvironment
getMockEnv
]
, TestName -> (GovernorMockEnvironment -> Property) -> TestTree
forall a. Testable a => TestName -> a -> TestTree
testProperty TestName
"association mode" GovernorMockEnvironment -> Property
prop_governor_association_mode
]
, TestName -> [TestTree] -> TestTree
testGroup TestName
"issues"
[ TestName -> Property -> TestTree
forall a. Testable a => TestName -> a -> TestTree
testProperty TestName
"3233" Property
prop_issue_3233
, TestName -> Property -> TestTree
forall a. Testable a => TestName -> a -> TestTree
testProperty TestName
"3494" Property
prop_issue_3494
, TestName -> Property -> TestTree
forall a. Testable a => TestName -> a -> TestTree
testProperty TestName
"3515" Property
prop_issue_3515
, TestName -> Property -> TestTree
forall a. Testable a => TestName -> a -> TestTree
testProperty TestName
"3550" Property
prop_issue_3550
]
, TestName
-> (MaxTime -> GovernorMockEnvironment -> Property) -> TestTree
forall a. Testable a => TestName -> a -> TestTree
testProperty TestName
"governor repromote delay with fuzz" MaxTime -> GovernorMockEnvironment -> Property
prop_governor_repromote_delay
, TestName -> (GovernorMockEnvironment -> Property) -> TestTree
forall a. Testable a => TestName -> a -> TestTree
testProperty TestName
"governor peer share reachable in 1hr" GovernorMockEnvironment -> Property
prop_governor_peershare_1hr
, TestName -> (GovernorMockEnvironment -> Property) -> TestTree
forall a. Testable a => TestName -> a -> TestTree
testProperty TestName
"governor connection status" GovernorMockEnvironment -> Property
prop_governor_connstatus
, TestName -> (GovernorMockEnvironment -> Property) -> TestTree
forall a. Testable a => TestName -> a -> TestTree
testProperty TestName
"governor no livelock" GovernorMockEnvironment -> Property
prop_governor_nolivelock
, TestName -> [TestTree] -> TestTree
testGroup TestName
"races"
[ TestTree -> TestTree
nightlyTest (TestTree -> TestTree) -> TestTree -> TestTree
forall a b. (a -> b) -> a -> b
$ TestName -> (GovernorMockEnvironment -> Property) -> TestTree
forall a. Testable a => TestName -> a -> TestTree
testProperty TestName
"governor no livelock" ((GovernorMockEnvironment -> Property) -> TestTree)
-> (GovernorMockEnvironment -> Property) -> TestTree
forall a b. (a -> b) -> a -> b
$ GovernorMockEnvironment -> Property
prop_explore_governor_nolivelock
, TestTree -> TestTree
nightlyTest (TestTree -> TestTree) -> TestTree -> TestTree
forall a b. (a -> b) -> a -> b
$ TestName -> (GovernorMockEnvironment -> Property) -> TestTree
forall a. Testable a => TestName -> a -> TestTree
testProperty TestName
"governor connection status" ((GovernorMockEnvironment -> Property) -> TestTree)
-> (GovernorMockEnvironment -> Property) -> TestTree
forall a b. (a -> b) -> a -> b
$ GovernorMockEnvironment -> Property
prop_explore_governor_connstatus
]
]
prop_peerSelectionView_sizes :: GovernorMockEnvironment -> Property
prop_peerSelectionView_sizes :: GovernorMockEnvironment -> Property
prop_peerSelectionView_sizes GovernorMockEnvironment
env =
let trace :: SimTrace Void
trace = GovernorMockEnvironment -> SimTrace Void
runGovernorInMockEnvironment GovernorMockEnvironment
env
evs :: [(Time, DebugPeerSelection PeerAddr)]
evs = [(Time, TestTraceEvent)] -> [(Time, DebugPeerSelection PeerAddr)]
selectGovernorStateEvents
([(Time, TestTraceEvent)] -> [(Time, DebugPeerSelection PeerAddr)])
-> [(Time, TestTraceEvent)]
-> [(Time, DebugPeerSelection PeerAddr)]
forall a b. (a -> b) -> a -> b
$ Time -> SimTrace Void -> [(Time, TestTraceEvent)]
forall a. Time -> SimTrace a -> [(Time, TestTraceEvent)]
selectPeerSelectionTraceEventsUntil (DiffTime -> Time
Time (DiffTime
10 DiffTime -> DiffTime -> DiffTime
forall a. Num a => a -> a -> a
* DiffTime
3600)) SimTrace Void
trace
in All -> Property
forall prop. Testable prop => prop -> Property
property (All -> Property) -> All -> Property
forall a b. (a -> b) -> a -> b
$
((Time, DebugPeerSelection PeerAddr) -> All)
-> [(Time, DebugPeerSelection PeerAddr)] -> All
forall m a. Monoid m => (a -> m) -> [a] -> m
forall (t :: * -> *) m a.
(Foldable t, Monoid m) =>
(a -> m) -> t a -> m
foldMap (\(Time
_, TraceGovernorState Time
_ Maybe DiffTime
_ PeerSelectionState PeerAddr peerconn
st) ->
let view :: PeerSelectionSetsWithSizes PeerAddr
view = PeerSelectionState PeerAddr peerconn
-> PeerSelectionSetsWithSizes PeerAddr
forall peeraddr peerconn.
Ord peeraddr =>
PeerSelectionState peeraddr peerconn
-> PeerSelectionSetsWithSizes peeraddr
peerSelectionStateToView PeerSelectionState PeerAddr peerconn
st in
Property -> All
forall p. Testable p => p -> All
All (PeerSelectionView (Set PeerAddr) -> Property
viewInvariant ((Set PeerAddr, Int) -> Set PeerAddr
forall a b. (a, b) -> a
fst ((Set PeerAddr, Int) -> Set PeerAddr)
-> PeerSelectionSetsWithSizes PeerAddr
-> PeerSelectionView (Set PeerAddr)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> PeerSelectionSetsWithSizes PeerAddr
view))
All -> All -> All
forall a. Semigroup a => a -> a -> a
<> Property -> All
forall p. Testable p => p -> All
All (PeerSelectionSetsWithSizes PeerAddr -> Property
viewSizeInvariant PeerSelectionSetsWithSizes PeerAddr
view))
[(Time, DebugPeerSelection PeerAddr)]
evs
where
viewInvariant :: PeerSelectionView (Set PeerAddr)
-> Property
viewInvariant :: PeerSelectionView (Set PeerAddr) -> Property
viewInvariant PeerSelectionView {Set PeerAddr
viewRootPeers :: Set PeerAddr
viewKnownPeers :: Set PeerAddr
viewAvailableToConnectPeers :: Set PeerAddr
viewColdPeersPromotions :: Set PeerAddr
viewEstablishedPeers :: Set PeerAddr
viewWarmPeersDemotions :: Set PeerAddr
viewWarmPeersPromotions :: Set PeerAddr
viewActivePeers :: Set PeerAddr
viewActivePeersDemotions :: Set PeerAddr
viewKnownBigLedgerPeers :: Set PeerAddr
viewAvailableToConnectBigLedgerPeers :: Set PeerAddr
viewColdBigLedgerPeersPromotions :: Set PeerAddr
viewEstablishedBigLedgerPeers :: Set PeerAddr
viewWarmBigLedgerPeersDemotions :: Set PeerAddr
viewWarmBigLedgerPeersPromotions :: Set PeerAddr
viewActiveBigLedgerPeers :: Set PeerAddr
viewActiveBigLedgerPeersDemotions :: Set PeerAddr
viewKnownLocalRootPeers :: Set PeerAddr
viewAvailableToConnectLocalRootPeers :: Set PeerAddr
viewColdLocalRootPeersPromotions :: Set PeerAddr
viewEstablishedLocalRootPeers :: Set PeerAddr
viewWarmLocalRootPeersPromotions :: Set PeerAddr
viewActiveLocalRootPeers :: Set PeerAddr
viewActiveLocalRootPeersDemotions :: Set PeerAddr
viewKnownNonRootPeers :: Set PeerAddr
viewColdNonRootPeersPromotions :: Set PeerAddr
viewEstablishedNonRootPeers :: Set PeerAddr
viewWarmNonRootPeersDemotions :: Set PeerAddr
viewWarmNonRootPeersPromotions :: Set PeerAddr
viewActiveNonRootPeers :: Set PeerAddr
viewActiveNonRootPeersDemotions :: Set PeerAddr
viewKnownBootstrapPeers :: Set PeerAddr
viewColdBootstrapPeersPromotions :: Set PeerAddr
viewEstablishedBootstrapPeers :: Set PeerAddr
viewWarmBootstrapPeersDemotions :: Set PeerAddr
viewWarmBootstrapPeersPromotions :: Set PeerAddr
viewActiveBootstrapPeers :: Set PeerAddr
viewActiveBootstrapPeersDemotions :: Set PeerAddr
viewActiveBigLedgerPeers :: forall a. PeerSelectionView a -> a
viewActiveBigLedgerPeersDemotions :: forall a. PeerSelectionView a -> a
viewActiveBootstrapPeers :: forall a. PeerSelectionView a -> a
viewActiveBootstrapPeersDemotions :: forall a. PeerSelectionView a -> a
viewActiveLocalRootPeers :: forall a. PeerSelectionView a -> a
viewActiveLocalRootPeersDemotions :: forall a. PeerSelectionView a -> a
viewActiveNonRootPeers :: forall a. PeerSelectionView a -> a
viewActiveNonRootPeersDemotions :: forall a. PeerSelectionView a -> a
viewActivePeers :: forall a. PeerSelectionView a -> a
viewActivePeersDemotions :: forall a. PeerSelectionView a -> a
viewAvailableToConnectBigLedgerPeers :: forall a. PeerSelectionView a -> a
viewAvailableToConnectLocalRootPeers :: forall a. PeerSelectionView a -> a
viewAvailableToConnectPeers :: forall a. PeerSelectionView a -> a
viewColdBigLedgerPeersPromotions :: forall a. PeerSelectionView a -> a
viewColdBootstrapPeersPromotions :: forall a. PeerSelectionView a -> a
viewColdLocalRootPeersPromotions :: forall a. PeerSelectionView a -> a
viewColdNonRootPeersPromotions :: forall a. PeerSelectionView a -> a
viewColdPeersPromotions :: forall a. PeerSelectionView a -> a
viewEstablishedBigLedgerPeers :: forall a. PeerSelectionView a -> a
viewEstablishedBootstrapPeers :: forall a. PeerSelectionView a -> a
viewEstablishedLocalRootPeers :: forall a. PeerSelectionView a -> a
viewEstablishedNonRootPeers :: forall a. PeerSelectionView a -> a
viewEstablishedPeers :: forall a. PeerSelectionView a -> a
viewKnownBigLedgerPeers :: forall a. PeerSelectionView a -> a
viewKnownBootstrapPeers :: forall a. PeerSelectionView a -> a
viewKnownLocalRootPeers :: forall a. PeerSelectionView a -> a
viewKnownNonRootPeers :: forall a. PeerSelectionView a -> a
viewKnownPeers :: forall a. PeerSelectionView a -> a
viewRootPeers :: forall a. PeerSelectionView a -> a
viewWarmBigLedgerPeersDemotions :: forall a. PeerSelectionView a -> a
viewWarmBigLedgerPeersPromotions :: forall a. PeerSelectionView a -> a
viewWarmBootstrapPeersDemotions :: forall a. PeerSelectionView a -> a
viewWarmBootstrapPeersPromotions :: forall a. PeerSelectionView a -> a
viewWarmLocalRootPeersPromotions :: forall a. PeerSelectionView a -> a
viewWarmNonRootPeersDemotions :: forall a. PeerSelectionView a -> a
viewWarmNonRootPeersPromotions :: forall a. PeerSelectionView a -> a
viewWarmPeersDemotions :: forall a. PeerSelectionView a -> a
viewWarmPeersPromotions :: forall a. PeerSelectionView a -> a
..} =
TestName -> Set PeerAddr -> Set PeerAddr -> Property
forall a. (Ord a, Show a) => TestName -> Set a -> Set a -> Property
isSubsetProperty TestName
"viewActivePeersDemotions" Set PeerAddr
viewActivePeersDemotions Set PeerAddr
viewActivePeers
Property -> Property -> Property
forall prop1 prop2.
(Testable prop1, Testable prop2) =>
prop1 -> prop2 -> Property
.&&. TestName -> Set PeerAddr -> Set PeerAddr -> Property
forall a. (Ord a, Show a) => TestName -> Set a -> Set a -> Property
isSubsetProperty TestName
"viewActivePeers" Set PeerAddr
viewActivePeers Set PeerAddr
viewEstablishedPeers
Property -> Property -> Property
forall prop1 prop2.
(Testable prop1, Testable prop2) =>
prop1 -> prop2 -> Property
.&&. TestName -> Set PeerAddr -> Set PeerAddr -> Property
forall a. (Ord a, Show a) => TestName -> Set a -> Set a -> Property
isSubsetProperty TestName
"viewEstablishedPeers" Set PeerAddr
viewEstablishedPeers Set PeerAddr
viewKnownPeers
Property -> Property -> Property
forall prop1 prop2.
(Testable prop1, Testable prop2) =>
prop1 -> prop2 -> Property
.&&. TestName -> Set PeerAddr -> Set PeerAddr -> Property
forall a. (Ord a, Show a) => TestName -> Set a -> Set a -> Property
isSubsetProperty TestName
"viewColdPeersPromotions" Set PeerAddr
viewColdPeersPromotions Set PeerAddr
viewKnownPeers
Property -> Property -> Property
forall prop1 prop2.
(Testable prop1, Testable prop2) =>
prop1 -> prop2 -> Property
.&&. TestName -> Set PeerAddr -> Set PeerAddr -> Property
forall a. (Ord a, Show a) => TestName -> Set a -> Set a -> Property
isSubsetProperty TestName
"viewAvailableToConnectPeers" Set PeerAddr
viewAvailableToConnectPeers Set PeerAddr
viewKnownPeers
Property -> Property -> Property
forall prop1 prop2.
(Testable prop1, Testable prop2) =>
prop1 -> prop2 -> Property
.&&. TestName -> Set PeerAddr -> Set PeerAddr -> Property
forall a. (Ord a, Show a) => TestName -> Set a -> Set a -> Property
isSubsetProperty TestName
"viewWarmPeersDemotions" Set PeerAddr
viewWarmPeersDemotions (Set PeerAddr
viewEstablishedPeers Set PeerAddr -> Set PeerAddr -> Set PeerAddr
forall a. Ord a => Set a -> Set a -> Set a
Set.\\ Set PeerAddr
viewActivePeers)
Property -> Property -> Property
forall prop1 prop2.
(Testable prop1, Testable prop2) =>
prop1 -> prop2 -> Property
.&&. TestName -> Set PeerAddr -> Set PeerAddr -> Property
forall a. (Ord a, Show a) => TestName -> Set a -> Set a -> Property
isSubsetProperty TestName
"viewWarmPeersPromotions" Set PeerAddr
viewWarmPeersPromotions (Set PeerAddr
viewEstablishedPeers Set PeerAddr -> Set PeerAddr -> Set PeerAddr
forall a. Ord a => Set a -> Set a -> Set a
Set.\\ Set PeerAddr
viewActivePeers)
Property -> Property -> Property
forall prop1 prop2.
(Testable prop1, Testable prop2) =>
prop1 -> prop2 -> Property
.&&. TestName -> Set PeerAddr -> Set PeerAddr -> Property
forall a. (Ord a, Show a) => TestName -> Set a -> Set a -> Property
isSubsetProperty TestName
"viewActiveBigLedgerPeersDemotions" Set PeerAddr
viewActiveBigLedgerPeersDemotions Set PeerAddr
viewActiveBigLedgerPeers
Property -> Property -> Property
forall prop1 prop2.
(Testable prop1, Testable prop2) =>
prop1 -> prop2 -> Property
.&&. TestName -> Set PeerAddr -> Set PeerAddr -> Property
forall a. (Ord a, Show a) => TestName -> Set a -> Set a -> Property
isSubsetProperty TestName
"viewActiveBigLedgerPeers" Set PeerAddr
viewActiveBigLedgerPeers Set PeerAddr
viewEstablishedBigLedgerPeers
Property -> Property -> Property
forall prop1 prop2.
(Testable prop1, Testable prop2) =>
prop1 -> prop2 -> Property
.&&. TestName -> Set PeerAddr -> Set PeerAddr -> Property
forall a. (Ord a, Show a) => TestName -> Set a -> Set a -> Property
isSubsetProperty TestName
"viewEstablishedBigLedgerPeers" Set PeerAddr
viewEstablishedBigLedgerPeers Set PeerAddr
viewKnownBigLedgerPeers
Property -> Property -> Property
forall prop1 prop2.
(Testable prop1, Testable prop2) =>
prop1 -> prop2 -> Property
.&&. TestName -> Set PeerAddr -> Set PeerAddr -> Property
forall a. (Ord a, Show a) => TestName -> Set a -> Set a -> Property
isSubsetProperty TestName
"viewColdBigLedgerPeersPromotions" Set PeerAddr
viewColdBigLedgerPeersPromotions Set PeerAddr
viewKnownBigLedgerPeers
Property -> Property -> Property
forall prop1 prop2.
(Testable prop1, Testable prop2) =>
prop1 -> prop2 -> Property
.&&. TestName -> Set PeerAddr -> Set PeerAddr -> Property
forall a. (Ord a, Show a) => TestName -> Set a -> Set a -> Property
isSubsetProperty TestName
"viewAvailableToConnectBigLedgerPeers" Set PeerAddr
viewAvailableToConnectBigLedgerPeers Set PeerAddr
viewKnownBigLedgerPeers
Property -> Property -> Property
forall prop1 prop2.
(Testable prop1, Testable prop2) =>
prop1 -> prop2 -> Property
.&&. TestName -> Set PeerAddr -> Set PeerAddr -> Property
forall a. (Ord a, Show a) => TestName -> Set a -> Set a -> Property
isSubsetProperty TestName
"viewWarmBigLedgerPeersDemotions" Set PeerAddr
viewWarmBigLedgerPeersDemotions (Set PeerAddr
viewEstablishedBigLedgerPeers Set PeerAddr -> Set PeerAddr -> Set PeerAddr
forall a. Ord a => Set a -> Set a -> Set a
Set.\\ Set PeerAddr
viewActiveBigLedgerPeers)
Property -> Property -> Property
forall prop1 prop2.
(Testable prop1, Testable prop2) =>
prop1 -> prop2 -> Property
.&&. TestName -> Set PeerAddr -> Set PeerAddr -> Property
forall a. (Ord a, Show a) => TestName -> Set a -> Set a -> Property
isSubsetProperty TestName
"viewWarmBigLedgerPeersPromotions" Set PeerAddr
viewWarmBigLedgerPeersPromotions (Set PeerAddr
viewEstablishedBigLedgerPeers Set PeerAddr -> Set PeerAddr -> Set PeerAddr
forall a. Ord a => Set a -> Set a -> Set a
Set.\\ Set PeerAddr
viewActiveBigLedgerPeers)
Property -> Property -> Property
forall prop1 prop2.
(Testable prop1, Testable prop2) =>
prop1 -> prop2 -> Property
.&&. TestName -> Set PeerAddr -> Set PeerAddr -> Property
forall a. (Ord a, Show a) => TestName -> Set a -> Set a -> Property
isSubsetProperty TestName
"viewActiveLocalRootPeersDemotions" Set PeerAddr
viewActiveLocalRootPeersDemotions Set PeerAddr
viewActiveLocalRootPeers
Property -> Property -> Property
forall prop1 prop2.
(Testable prop1, Testable prop2) =>
prop1 -> prop2 -> Property
.&&. TestName -> Set PeerAddr -> Set PeerAddr -> Property
forall a. (Ord a, Show a) => TestName -> Set a -> Set a -> Property
isSubsetProperty TestName
"viewActiveLocalRootPeers" Set PeerAddr
viewActiveLocalRootPeers Set PeerAddr
viewEstablishedLocalRootPeers
Property -> Property -> Property
forall prop1 prop2.
(Testable prop1, Testable prop2) =>
prop1 -> prop2 -> Property
.&&. TestName -> Set PeerAddr -> Set PeerAddr -> Property
forall a. (Ord a, Show a) => TestName -> Set a -> Set a -> Property
isSubsetProperty TestName
"viewEstablishedLocalRootPeers" Set PeerAddr
viewEstablishedLocalRootPeers Set PeerAddr
viewKnownLocalRootPeers
Property -> Property -> Property
forall prop1 prop2.
(Testable prop1, Testable prop2) =>
prop1 -> prop2 -> Property
.&&. TestName -> Set PeerAddr -> Set PeerAddr -> Property
forall a. (Ord a, Show a) => TestName -> Set a -> Set a -> Property
isSubsetProperty TestName
"viewColdLocalRootPeersPromotions" Set PeerAddr
viewColdLocalRootPeersPromotions Set PeerAddr
viewKnownLocalRootPeers
Property -> Property -> Property
forall prop1 prop2.
(Testable prop1, Testable prop2) =>
prop1 -> prop2 -> Property
.&&. TestName -> Set PeerAddr -> Set PeerAddr -> Property
forall a. (Ord a, Show a) => TestName -> Set a -> Set a -> Property
isSubsetProperty TestName
"viewAvailableToConnectLocalRootPeers" Set PeerAddr
viewAvailableToConnectLocalRootPeers Set PeerAddr
viewKnownLocalRootPeers
Property -> Property -> Property
forall prop1 prop2.
(Testable prop1, Testable prop2) =>
prop1 -> prop2 -> Property
.&&. TestName -> Set PeerAddr -> Set PeerAddr -> Property
forall a. (Ord a, Show a) => TestName -> Set a -> Set a -> Property
isSubsetProperty TestName
"viewWarmLocalRootPeersPromotions" Set PeerAddr
viewWarmLocalRootPeersPromotions (Set PeerAddr
viewEstablishedLocalRootPeers Set PeerAddr -> Set PeerAddr -> Set PeerAddr
forall a. Ord a => Set a -> Set a -> Set a
Set.\\ Set PeerAddr
viewActiveLocalRootPeers)
Property -> Property -> Property
forall prop1 prop2.
(Testable prop1, Testable prop2) =>
prop1 -> prop2 -> Property
.&&. TestName -> Set PeerAddr -> Set PeerAddr -> Property
forall a. (Ord a, Show a) => TestName -> Set a -> Set a -> Property
isSubsetProperty TestName
"viewActiveNonRootPeersDemotions" Set PeerAddr
viewActiveNonRootPeersDemotions Set PeerAddr
viewActiveNonRootPeers
Property -> Property -> Property
forall prop1 prop2.
(Testable prop1, Testable prop2) =>
prop1 -> prop2 -> Property
.&&. TestName -> Set PeerAddr -> Set PeerAddr -> Property
forall a. (Ord a, Show a) => TestName -> Set a -> Set a -> Property
isSubsetProperty TestName
"viewActiveNonRootPeers" Set PeerAddr
viewActiveNonRootPeers Set PeerAddr
viewEstablishedNonRootPeers
Property -> Property -> Property
forall prop1 prop2.
(Testable prop1, Testable prop2) =>
prop1 -> prop2 -> Property
.&&. TestName -> Set PeerAddr -> Set PeerAddr -> Property
forall a. (Ord a, Show a) => TestName -> Set a -> Set a -> Property
isSubsetProperty TestName
"viewEstablishedNonRootPeers" Set PeerAddr
viewEstablishedNonRootPeers Set PeerAddr
viewKnownNonRootPeers
Property -> Property -> Property
forall prop1 prop2.
(Testable prop1, Testable prop2) =>
prop1 -> prop2 -> Property
.&&. TestName -> Set PeerAddr -> Set PeerAddr -> Property
forall a. (Ord a, Show a) => TestName -> Set a -> Set a -> Property
isSubsetProperty TestName
"viewColdNonRootPeersPromotions" Set PeerAddr
viewColdNonRootPeersPromotions Set PeerAddr
viewKnownNonRootPeers
Property -> Property -> Property
forall prop1 prop2.
(Testable prop1, Testable prop2) =>
prop1 -> prop2 -> Property
.&&. TestName -> Set PeerAddr -> Set PeerAddr -> Property
forall a. (Ord a, Show a) => TestName -> Set a -> Set a -> Property
isSubsetProperty TestName
"viewWarmNonRootPeersPromotions" Set PeerAddr
viewWarmNonRootPeersPromotions (Set PeerAddr
viewEstablishedNonRootPeers Set PeerAddr -> Set PeerAddr -> Set PeerAddr
forall a. Ord a => Set a -> Set a -> Set a
Set.\\ Set PeerAddr
viewActiveNonRootPeers)
Property -> Property -> Property
forall prop1 prop2.
(Testable prop1, Testable prop2) =>
prop1 -> prop2 -> Property
.&&. TestName -> Set PeerAddr -> Set PeerAddr -> Property
forall a. (Ord a, Show a) => TestName -> Set a -> Set a -> Property
isSubsetProperty TestName
"viewWarmNonRootPeersDemotions" Set PeerAddr
viewWarmNonRootPeersDemotions (Set PeerAddr
viewEstablishedNonRootPeers Set PeerAddr -> Set PeerAddr -> Set PeerAddr
forall a. Ord a => Set a -> Set a -> Set a
Set.\\ Set PeerAddr
viewActiveNonRootPeers)
Property -> Property -> Property
forall prop1 prop2.
(Testable prop1, Testable prop2) =>
prop1 -> prop2 -> Property
.&&. TestName -> Set PeerAddr -> Set PeerAddr -> Property
forall a. (Ord a, Show a) => TestName -> Set a -> Set a -> Property
isSubsetProperty TestName
"viewActiveBootstrapPeersDemotions" Set PeerAddr
viewActiveBootstrapPeersDemotions Set PeerAddr
viewActiveBootstrapPeers
Property -> Property -> Property
forall prop1 prop2.
(Testable prop1, Testable prop2) =>
prop1 -> prop2 -> Property
.&&. TestName -> Set PeerAddr -> Set PeerAddr -> Property
forall a. (Ord a, Show a) => TestName -> Set a -> Set a -> Property
isSubsetProperty TestName
"viewActiveBootstrapPeers" Set PeerAddr
viewActiveBootstrapPeers Set PeerAddr
viewEstablishedBootstrapPeers
Property -> Property -> Property
forall prop1 prop2.
(Testable prop1, Testable prop2) =>
prop1 -> prop2 -> Property
.&&. TestName -> Set PeerAddr -> Set PeerAddr -> Property
forall a. (Ord a, Show a) => TestName -> Set a -> Set a -> Property
isSubsetProperty TestName
"viewEstablishedBootstrapPeers" Set PeerAddr
viewEstablishedBootstrapPeers Set PeerAddr
viewKnownBootstrapPeers
Property -> Property -> Property
forall prop1 prop2.
(Testable prop1, Testable prop2) =>
prop1 -> prop2 -> Property
.&&. TestName -> Set PeerAddr -> Set PeerAddr -> Property
forall a. (Ord a, Show a) => TestName -> Set a -> Set a -> Property
isSubsetProperty TestName
"viewColdBootstrapPeersPromotions" Set PeerAddr
viewColdBootstrapPeersPromotions Set PeerAddr
viewKnownBootstrapPeers
Property -> Property -> Property
forall prop1 prop2.
(Testable prop1, Testable prop2) =>
prop1 -> prop2 -> Property
.&&. TestName -> Set PeerAddr -> Set PeerAddr -> Property
forall a. (Ord a, Show a) => TestName -> Set a -> Set a -> Property
isSubsetProperty TestName
"viewWarmBootstrapPeersPromotions" Set PeerAddr
viewWarmBootstrapPeersPromotions (Set PeerAddr
viewEstablishedBootstrapPeers Set PeerAddr -> Set PeerAddr -> Set PeerAddr
forall a. Ord a => Set a -> Set a -> Set a
Set.\\ Set PeerAddr
viewActiveBootstrapPeers)
Property -> Property -> Property
forall prop1 prop2.
(Testable prop1, Testable prop2) =>
prop1 -> prop2 -> Property
.&&. TestName -> Set PeerAddr -> Set PeerAddr -> Property
forall a. (Ord a, Show a) => TestName -> Set a -> Set a -> Property
isSubsetProperty TestName
"viewWarmBootstrapPeersDemotions" Set PeerAddr
viewWarmBootstrapPeersDemotions (Set PeerAddr
viewEstablishedBootstrapPeers Set PeerAddr -> Set PeerAddr -> Set PeerAddr
forall a. Ord a => Set a -> Set a -> Set a
Set.\\ Set PeerAddr
viewActiveBootstrapPeers)
Property -> Property -> Property
forall prop1 prop2.
(Testable prop1, Testable prop2) =>
prop1 -> prop2 -> Property
.&&. TestName -> Set PeerAddr -> Set PeerAddr -> Property
forall a. (Ord a, Show a) => TestName -> Set a -> Set a -> Property
disjointSetsProperty TestName
"viewKnownPeers viewKnownBigLedgerPeers" Set PeerAddr
viewKnownPeers Set PeerAddr
viewKnownBigLedgerPeers
Property -> Property -> Property
forall prop1 prop2.
(Testable prop1, Testable prop2) =>
prop1 -> prop2 -> Property
.&&. TestName -> Set PeerAddr -> Set PeerAddr -> Property
forall a. (Ord a, Show a) => TestName -> Set a -> Set a -> Property
isSubsetProperty TestName
"viewKnownLocalRootPeers" Set PeerAddr
viewKnownLocalRootPeers Set PeerAddr
viewKnownPeers
Property -> Property -> Property
forall prop1 prop2.
(Testable prop1, Testable prop2) =>
prop1 -> prop2 -> Property
.&&. TestName -> Set PeerAddr -> Set PeerAddr -> Property
forall a. (Ord a, Show a) => TestName -> Set a -> Set a -> Property
isSubsetProperty TestName
"viewKnownNonRootPeers" Set PeerAddr
viewKnownNonRootPeers Set PeerAddr
viewKnownPeers
Property -> Property -> Property
forall prop1 prop2.
(Testable prop1, Testable prop2) =>
prop1 -> prop2 -> Property
.&&. TestName -> Set PeerAddr -> Set PeerAddr -> Property
forall a. (Ord a, Show a) => TestName -> Set a -> Set a -> Property
isSubsetProperty TestName
"viewKnownBootstrapPeers" Set PeerAddr
viewKnownBootstrapPeers Set PeerAddr
viewKnownPeers
Property -> Property -> Property
forall prop1 prop2.
(Testable prop1, Testable prop2) =>
prop1 -> prop2 -> Property
.&&. TestName -> Set PeerAddr -> Set PeerAddr -> Property
forall a. (Ord a, Show a) => TestName -> Set a -> Set a -> Property
disjointSetsProperty TestName
"viewKnownLocalRootPeers-viewKnownBigLedgerPeers" Set PeerAddr
viewKnownLocalRootPeers Set PeerAddr
viewKnownBigLedgerPeers
Property -> Property -> Property
forall prop1 prop2.
(Testable prop1, Testable prop2) =>
prop1 -> prop2 -> Property
.&&. TestName -> Set PeerAddr -> Set PeerAddr -> Property
forall a. (Ord a, Show a) => TestName -> Set a -> Set a -> Property
disjointSetsProperty TestName
"viewKnownLocalRootPeers-viewKnownNonRootPeers" Set PeerAddr
viewKnownLocalRootPeers Set PeerAddr
viewKnownNonRootPeers
Property -> Property -> Property
forall prop1 prop2.
(Testable prop1, Testable prop2) =>
prop1 -> prop2 -> Property
.&&. TestName -> Set PeerAddr -> Set PeerAddr -> Property
forall a. (Ord a, Show a) => TestName -> Set a -> Set a -> Property
disjointSetsProperty TestName
"viewKnownLocalRootPeers-viewKnownBootstrapPeers" Set PeerAddr
viewKnownLocalRootPeers Set PeerAddr
viewKnownBootstrapPeers
Property -> Property -> Property
forall prop1 prop2.
(Testable prop1, Testable prop2) =>
prop1 -> prop2 -> Property
.&&. TestName -> Set PeerAddr -> Set PeerAddr -> Property
forall a. (Ord a, Show a) => TestName -> Set a -> Set a -> Property
disjointSetsProperty TestName
"viewKnownNonRootPeers-viewKnownBigLedgerPeers" Set PeerAddr
viewKnownNonRootPeers Set PeerAddr
viewKnownBigLedgerPeers
Property -> Property -> Property
forall prop1 prop2.
(Testable prop1, Testable prop2) =>
prop1 -> prop2 -> Property
.&&. TestName -> Set PeerAddr -> Set PeerAddr -> Property
forall a. (Ord a, Show a) => TestName -> Set a -> Set a -> Property
disjointSetsProperty TestName
"viewKnownBootstrapPeers-viewKnownBigLedgerPeers" Set PeerAddr
viewKnownBootstrapPeers Set PeerAddr
viewKnownBigLedgerPeers
viewSizeInvariant :: PeerSelectionSetsWithSizes PeerAddr
-> Property
viewSizeInvariant :: PeerSelectionSetsWithSizes PeerAddr -> Property
viewSizeInvariant PeerSelectionView {(Set PeerAddr, Int)
viewActiveBigLedgerPeers :: forall a. PeerSelectionView a -> a
viewActiveBigLedgerPeersDemotions :: forall a. PeerSelectionView a -> a
viewActiveBootstrapPeers :: forall a. PeerSelectionView a -> a
viewActiveBootstrapPeersDemotions :: forall a. PeerSelectionView a -> a
viewActiveLocalRootPeers :: forall a. PeerSelectionView a -> a
viewActiveLocalRootPeersDemotions :: forall a. PeerSelectionView a -> a
viewActiveNonRootPeers :: forall a. PeerSelectionView a -> a
viewActiveNonRootPeersDemotions :: forall a. PeerSelectionView a -> a
viewActivePeers :: forall a. PeerSelectionView a -> a
viewActivePeersDemotions :: forall a. PeerSelectionView a -> a
viewAvailableToConnectBigLedgerPeers :: forall a. PeerSelectionView a -> a
viewAvailableToConnectLocalRootPeers :: forall a. PeerSelectionView a -> a
viewAvailableToConnectPeers :: forall a. PeerSelectionView a -> a
viewColdBigLedgerPeersPromotions :: forall a. PeerSelectionView a -> a
viewColdBootstrapPeersPromotions :: forall a. PeerSelectionView a -> a
viewColdLocalRootPeersPromotions :: forall a. PeerSelectionView a -> a
viewColdNonRootPeersPromotions :: forall a. PeerSelectionView a -> a
viewColdPeersPromotions :: forall a. PeerSelectionView a -> a
viewEstablishedBigLedgerPeers :: forall a. PeerSelectionView a -> a
viewEstablishedBootstrapPeers :: forall a. PeerSelectionView a -> a
viewEstablishedLocalRootPeers :: forall a. PeerSelectionView a -> a
viewEstablishedNonRootPeers :: forall a. PeerSelectionView a -> a
viewEstablishedPeers :: forall a. PeerSelectionView a -> a
viewKnownBigLedgerPeers :: forall a. PeerSelectionView a -> a
viewKnownBootstrapPeers :: forall a. PeerSelectionView a -> a
viewKnownLocalRootPeers :: forall a. PeerSelectionView a -> a
viewKnownNonRootPeers :: forall a. PeerSelectionView a -> a
viewKnownPeers :: forall a. PeerSelectionView a -> a
viewRootPeers :: forall a. PeerSelectionView a -> a
viewWarmBigLedgerPeersDemotions :: forall a. PeerSelectionView a -> a
viewWarmBigLedgerPeersPromotions :: forall a. PeerSelectionView a -> a
viewWarmBootstrapPeersDemotions :: forall a. PeerSelectionView a -> a
viewWarmBootstrapPeersPromotions :: forall a. PeerSelectionView a -> a
viewWarmLocalRootPeersPromotions :: forall a. PeerSelectionView a -> a
viewWarmNonRootPeersDemotions :: forall a. PeerSelectionView a -> a
viewWarmNonRootPeersPromotions :: forall a. PeerSelectionView a -> a
viewWarmPeersDemotions :: forall a. PeerSelectionView a -> a
viewWarmPeersPromotions :: forall a. PeerSelectionView a -> a
viewRootPeers :: (Set PeerAddr, Int)
viewKnownPeers :: (Set PeerAddr, Int)
viewAvailableToConnectPeers :: (Set PeerAddr, Int)
viewColdPeersPromotions :: (Set PeerAddr, Int)
viewEstablishedPeers :: (Set PeerAddr, Int)
viewWarmPeersDemotions :: (Set PeerAddr, Int)
viewWarmPeersPromotions :: (Set PeerAddr, Int)
viewActivePeers :: (Set PeerAddr, Int)
viewActivePeersDemotions :: (Set PeerAddr, Int)
viewKnownBigLedgerPeers :: (Set PeerAddr, Int)
viewAvailableToConnectBigLedgerPeers :: (Set PeerAddr, Int)
viewColdBigLedgerPeersPromotions :: (Set PeerAddr, Int)
viewEstablishedBigLedgerPeers :: (Set PeerAddr, Int)
viewWarmBigLedgerPeersDemotions :: (Set PeerAddr, Int)
viewWarmBigLedgerPeersPromotions :: (Set PeerAddr, Int)
viewActiveBigLedgerPeers :: (Set PeerAddr, Int)
viewActiveBigLedgerPeersDemotions :: (Set PeerAddr, Int)
viewKnownLocalRootPeers :: (Set PeerAddr, Int)
viewAvailableToConnectLocalRootPeers :: (Set PeerAddr, Int)
viewColdLocalRootPeersPromotions :: (Set PeerAddr, Int)
viewEstablishedLocalRootPeers :: (Set PeerAddr, Int)
viewWarmLocalRootPeersPromotions :: (Set PeerAddr, Int)
viewActiveLocalRootPeers :: (Set PeerAddr, Int)
viewActiveLocalRootPeersDemotions :: (Set PeerAddr, Int)
viewKnownNonRootPeers :: (Set PeerAddr, Int)
viewColdNonRootPeersPromotions :: (Set PeerAddr, Int)
viewEstablishedNonRootPeers :: (Set PeerAddr, Int)
viewWarmNonRootPeersDemotions :: (Set PeerAddr, Int)
viewWarmNonRootPeersPromotions :: (Set PeerAddr, Int)
viewActiveNonRootPeers :: (Set PeerAddr, Int)
viewActiveNonRootPeersDemotions :: (Set PeerAddr, Int)
viewKnownBootstrapPeers :: (Set PeerAddr, Int)
viewColdBootstrapPeersPromotions :: (Set PeerAddr, Int)
viewEstablishedBootstrapPeers :: (Set PeerAddr, Int)
viewWarmBootstrapPeersDemotions :: (Set PeerAddr, Int)
viewWarmBootstrapPeersPromotions :: (Set PeerAddr, Int)
viewActiveBootstrapPeers :: (Set PeerAddr, Int)
viewActiveBootstrapPeersDemotions :: (Set PeerAddr, Int)
..} =
TestName -> Property -> Property
forall prop. Testable prop => TestName -> prop -> Property
counterexample TestName
"viewRootPeers"
(Set PeerAddr -> Int
forall a. Set a -> Int
Set.size ((Set PeerAddr, Int) -> Set PeerAddr
forall a b. (a, b) -> a
fst (Set PeerAddr, Int)
viewRootPeers) Int -> Int -> Property
forall a. (Eq a, Show a) => a -> a -> Property
=== (Set PeerAddr, Int) -> Int
forall a b. (a, b) -> b
snd (Set PeerAddr, Int)
viewRootPeers)
Property -> Property -> Property
forall prop1 prop2.
(Testable prop1, Testable prop2) =>
prop1 -> prop2 -> Property
.&&. TestName -> Property -> Property
forall prop. Testable prop => TestName -> prop -> Property
counterexample TestName
"viewKnownPeers"
(Set PeerAddr -> Int
forall a. Set a -> Int
Set.size ((Set PeerAddr, Int) -> Set PeerAddr
forall a b. (a, b) -> a
fst (Set PeerAddr, Int)
viewKnownPeers) Int -> Int -> Property
forall a. (Eq a, Show a) => a -> a -> Property
=== (Set PeerAddr, Int) -> Int
forall a b. (a, b) -> b
snd (Set PeerAddr, Int)
viewKnownPeers)
Property -> Property -> Property
forall prop1 prop2.
(Testable prop1, Testable prop2) =>
prop1 -> prop2 -> Property
.&&. TestName -> Property -> Property
forall prop. Testable prop => TestName -> prop -> Property
counterexample TestName
"viewAvailableToConnectPeers"
(Set PeerAddr -> Int
forall a. Set a -> Int
Set.size ((Set PeerAddr, Int) -> Set PeerAddr
forall a b. (a, b) -> a
fst (Set PeerAddr, Int)
viewAvailableToConnectPeers) Int -> Int -> Property
forall a. (Eq a, Show a) => a -> a -> Property
=== (Set PeerAddr, Int) -> Int
forall a b. (a, b) -> b
snd (Set PeerAddr, Int)
viewAvailableToConnectPeers)
Property -> Property -> Property
forall prop1 prop2.
(Testable prop1, Testable prop2) =>
prop1 -> prop2 -> Property
.&&. TestName -> Property -> Property
forall prop. Testable prop => TestName -> prop -> Property
counterexample TestName
"viewColdPeersPromotions"
(Set PeerAddr -> Int
forall a. Set a -> Int
Set.size ((Set PeerAddr, Int) -> Set PeerAddr
forall a b. (a, b) -> a
fst (Set PeerAddr, Int)
viewColdPeersPromotions) Int -> Int -> Property
forall a. (Eq a, Show a) => a -> a -> Property
=== (Set PeerAddr, Int) -> Int
forall a b. (a, b) -> b
snd (Set PeerAddr, Int)
viewColdPeersPromotions)
Property -> Property -> Property
forall prop1 prop2.
(Testable prop1, Testable prop2) =>
prop1 -> prop2 -> Property
.&&. TestName -> Property -> Property
forall prop. Testable prop => TestName -> prop -> Property
counterexample TestName
"viewEstablishedPeers"
(Set PeerAddr -> Int
forall a. Set a -> Int
Set.size ((Set PeerAddr, Int) -> Set PeerAddr
forall a b. (a, b) -> a
fst (Set PeerAddr, Int)
viewEstablishedPeers) Int -> Int -> Property
forall a. (Eq a, Show a) => a -> a -> Property
=== (Set PeerAddr, Int) -> Int
forall a b. (a, b) -> b
snd (Set PeerAddr, Int)
viewEstablishedPeers)
Property -> Property -> Property
forall prop1 prop2.
(Testable prop1, Testable prop2) =>
prop1 -> prop2 -> Property
.&&. TestName -> Property -> Property
forall prop. Testable prop => TestName -> prop -> Property
counterexample TestName
"viewWarmPeersDemotions"
(Set PeerAddr -> Int
forall a. Set a -> Int
Set.size ((Set PeerAddr, Int) -> Set PeerAddr
forall a b. (a, b) -> a
fst (Set PeerAddr, Int)
viewWarmPeersDemotions) Int -> Int -> Property
forall a. (Eq a, Show a) => a -> a -> Property
=== (Set PeerAddr, Int) -> Int
forall a b. (a, b) -> b
snd (Set PeerAddr, Int)
viewWarmPeersDemotions)
Property -> Property -> Property
forall prop1 prop2.
(Testable prop1, Testable prop2) =>
prop1 -> prop2 -> Property
.&&. TestName -> Property -> Property
forall prop. Testable prop => TestName -> prop -> Property
counterexample TestName
"viewWarmPeersPromotions"
(Set PeerAddr -> Int
forall a. Set a -> Int
Set.size ((Set PeerAddr, Int) -> Set PeerAddr
forall a b. (a, b) -> a
fst (Set PeerAddr, Int)
viewWarmPeersPromotions) Int -> Int -> Property
forall a. (Eq a, Show a) => a -> a -> Property
=== (Set PeerAddr, Int) -> Int
forall a b. (a, b) -> b
snd (Set PeerAddr, Int)
viewWarmPeersPromotions)
Property -> Property -> Property
forall prop1 prop2.
(Testable prop1, Testable prop2) =>
prop1 -> prop2 -> Property
.&&. TestName -> Property -> Property
forall prop. Testable prop => TestName -> prop -> Property
counterexample TestName
"viewActivePeers"
(Set PeerAddr -> Int
forall a. Set a -> Int
Set.size ((Set PeerAddr, Int) -> Set PeerAddr
forall a b. (a, b) -> a
fst (Set PeerAddr, Int)
viewActivePeers) Int -> Int -> Property
forall a. (Eq a, Show a) => a -> a -> Property
=== (Set PeerAddr, Int) -> Int
forall a b. (a, b) -> b
snd (Set PeerAddr, Int)
viewActivePeers)
Property -> Property -> Property
forall prop1 prop2.
(Testable prop1, Testable prop2) =>
prop1 -> prop2 -> Property
.&&. TestName -> Property -> Property
forall prop. Testable prop => TestName -> prop -> Property
counterexample TestName
"viewActivePeersDemotions"
(Set PeerAddr -> Int
forall a. Set a -> Int
Set.size ((Set PeerAddr, Int) -> Set PeerAddr
forall a b. (a, b) -> a
fst (Set PeerAddr, Int)
viewActivePeersDemotions) Int -> Int -> Property
forall a. (Eq a, Show a) => a -> a -> Property
=== (Set PeerAddr, Int) -> Int
forall a b. (a, b) -> b
snd (Set PeerAddr, Int)
viewActivePeersDemotions)
Property -> Property -> Property
forall prop1 prop2.
(Testable prop1, Testable prop2) =>
prop1 -> prop2 -> Property
.&&. TestName -> Property -> Property
forall prop. Testable prop => TestName -> prop -> Property
counterexample TestName
"viewKnownBigLedgerPeers"
(Set PeerAddr -> Int
forall a. Set a -> Int
Set.size ((Set PeerAddr, Int) -> Set PeerAddr
forall a b. (a, b) -> a
fst (Set PeerAddr, Int)
viewKnownBigLedgerPeers) Int -> Int -> Property
forall a. (Eq a, Show a) => a -> a -> Property
=== (Set PeerAddr, Int) -> Int
forall a b. (a, b) -> b
snd (Set PeerAddr, Int)
viewKnownBigLedgerPeers)
Property -> Property -> Property
forall prop1 prop2.
(Testable prop1, Testable prop2) =>
prop1 -> prop2 -> Property
.&&. TestName -> Property -> Property
forall prop. Testable prop => TestName -> prop -> Property
counterexample TestName
"viewAvailableToConnectBigLedgerPeers"
(Set PeerAddr -> Int
forall a. Set a -> Int
Set.size ((Set PeerAddr, Int) -> Set PeerAddr
forall a b. (a, b) -> a
fst (Set PeerAddr, Int)
viewAvailableToConnectBigLedgerPeers) Int -> Int -> Property
forall a. (Eq a, Show a) => a -> a -> Property
=== (Set PeerAddr, Int) -> Int
forall a b. (a, b) -> b
snd (Set PeerAddr, Int)
viewAvailableToConnectBigLedgerPeers)
Property -> Property -> Property
forall prop1 prop2.
(Testable prop1, Testable prop2) =>
prop1 -> prop2 -> Property
.&&. TestName -> Property -> Property
forall prop. Testable prop => TestName -> prop -> Property
counterexample TestName
"viewColdBigLedgerPeersPromotions"
(Set PeerAddr -> Int
forall a. Set a -> Int
Set.size ((Set PeerAddr, Int) -> Set PeerAddr
forall a b. (a, b) -> a
fst (Set PeerAddr, Int)
viewColdBigLedgerPeersPromotions) Int -> Int -> Property
forall a. (Eq a, Show a) => a -> a -> Property
=== (Set PeerAddr, Int) -> Int
forall a b. (a, b) -> b
snd (Set PeerAddr, Int)
viewColdBigLedgerPeersPromotions)
Property -> Property -> Property
forall prop1 prop2.
(Testable prop1, Testable prop2) =>
prop1 -> prop2 -> Property
.&&. TestName -> Property -> Property
forall prop. Testable prop => TestName -> prop -> Property
counterexample TestName
"viewEstablishedBigLedgerPeers"
(Set PeerAddr -> Int
forall a. Set a -> Int
Set.size ((Set PeerAddr, Int) -> Set PeerAddr
forall a b. (a, b) -> a
fst (Set PeerAddr, Int)
viewEstablishedBigLedgerPeers) Int -> Int -> Property
forall a. (Eq a, Show a) => a -> a -> Property
=== (Set PeerAddr, Int) -> Int
forall a b. (a, b) -> b
snd (Set PeerAddr, Int)
viewEstablishedBigLedgerPeers)
Property -> Property -> Property
forall prop1 prop2.
(Testable prop1, Testable prop2) =>
prop1 -> prop2 -> Property
.&&. TestName -> Property -> Property
forall prop. Testable prop => TestName -> prop -> Property
counterexample TestName
"viewWarmBigLedgerPeersDemotions"
(Set PeerAddr -> Int
forall a. Set a -> Int
Set.size ((Set PeerAddr, Int) -> Set PeerAddr
forall a b. (a, b) -> a
fst (Set PeerAddr, Int)
viewWarmBigLedgerPeersDemotions) Int -> Int -> Property
forall a. (Eq a, Show a) => a -> a -> Property
=== (Set PeerAddr, Int) -> Int
forall a b. (a, b) -> b
snd (Set PeerAddr, Int)
viewWarmBigLedgerPeersDemotions)
Property -> Property -> Property
forall prop1 prop2.
(Testable prop1, Testable prop2) =>
prop1 -> prop2 -> Property
.&&. TestName -> Property -> Property
forall prop. Testable prop => TestName -> prop -> Property
counterexample TestName
"viewWarmBigLedgerPeersPromotions"
(Set PeerAddr -> Int
forall a. Set a -> Int
Set.size ((Set PeerAddr, Int) -> Set PeerAddr
forall a b. (a, b) -> a
fst (Set PeerAddr, Int)
viewWarmBigLedgerPeersPromotions) Int -> Int -> Property
forall a. (Eq a, Show a) => a -> a -> Property
=== (Set PeerAddr, Int) -> Int
forall a b. (a, b) -> b
snd (Set PeerAddr, Int)
viewWarmBigLedgerPeersPromotions)
Property -> Property -> Property
forall prop1 prop2.
(Testable prop1, Testable prop2) =>
prop1 -> prop2 -> Property
.&&. TestName -> Property -> Property
forall prop. Testable prop => TestName -> prop -> Property
counterexample TestName
"viewActiveBigLedgerPeers"
(Set PeerAddr -> Int
forall a. Set a -> Int
Set.size ((Set PeerAddr, Int) -> Set PeerAddr
forall a b. (a, b) -> a
fst (Set PeerAddr, Int)
viewActiveBigLedgerPeers) Int -> Int -> Property
forall a. (Eq a, Show a) => a -> a -> Property
=== (Set PeerAddr, Int) -> Int
forall a b. (a, b) -> b
snd (Set PeerAddr, Int)
viewActiveBigLedgerPeers)
Property -> Property -> Property
forall prop1 prop2.
(Testable prop1, Testable prop2) =>
prop1 -> prop2 -> Property
.&&. TestName -> Property -> Property
forall prop. Testable prop => TestName -> prop -> Property
counterexample TestName
"viewActiveBigLedgerPeersDemotions"
(Set PeerAddr -> Int
forall a. Set a -> Int
Set.size ((Set PeerAddr, Int) -> Set PeerAddr
forall a b. (a, b) -> a
fst (Set PeerAddr, Int)
viewActiveBigLedgerPeersDemotions) Int -> Int -> Property
forall a. (Eq a, Show a) => a -> a -> Property
=== (Set PeerAddr, Int) -> Int
forall a b. (a, b) -> b
snd (Set PeerAddr, Int)
viewActiveBigLedgerPeersDemotions)
Property -> Property -> Property
forall prop1 prop2.
(Testable prop1, Testable prop2) =>
prop1 -> prop2 -> Property
.&&. TestName -> Property -> Property
forall prop. Testable prop => TestName -> prop -> Property
counterexample TestName
"viewKnownLocalRootPeers"
(Set PeerAddr -> Int
forall a. Set a -> Int
Set.size ((Set PeerAddr, Int) -> Set PeerAddr
forall a b. (a, b) -> a
fst (Set PeerAddr, Int)
viewKnownLocalRootPeers) Int -> Int -> Property
forall a. (Eq a, Show a) => a -> a -> Property
=== (Set PeerAddr, Int) -> Int
forall a b. (a, b) -> b
snd (Set PeerAddr, Int)
viewKnownLocalRootPeers)
Property -> Property -> Property
forall prop1 prop2.
(Testable prop1, Testable prop2) =>
prop1 -> prop2 -> Property
.&&. TestName -> Property -> Property
forall prop. Testable prop => TestName -> prop -> Property
counterexample TestName
"viewAvailableToConnectLocalRootPeers"
(Set PeerAddr -> Int
forall a. Set a -> Int
Set.size ((Set PeerAddr, Int) -> Set PeerAddr
forall a b. (a, b) -> a
fst (Set PeerAddr, Int)
viewAvailableToConnectLocalRootPeers) Int -> Int -> Property
forall a. (Eq a, Show a) => a -> a -> Property
=== (Set PeerAddr, Int) -> Int
forall a b. (a, b) -> b
snd (Set PeerAddr, Int)
viewAvailableToConnectLocalRootPeers)
Property -> Property -> Property
forall prop1 prop2.
(Testable prop1, Testable prop2) =>
prop1 -> prop2 -> Property
.&&. TestName -> Property -> Property
forall prop. Testable prop => TestName -> prop -> Property
counterexample TestName
"viewColdLocalRootPeersPromotions"
(Set PeerAddr -> Int
forall a. Set a -> Int
Set.size ((Set PeerAddr, Int) -> Set PeerAddr
forall a b. (a, b) -> a
fst (Set PeerAddr, Int)
viewColdLocalRootPeersPromotions) Int -> Int -> Property
forall a. (Eq a, Show a) => a -> a -> Property
=== (Set PeerAddr, Int) -> Int
forall a b. (a, b) -> b
snd (Set PeerAddr, Int)
viewColdLocalRootPeersPromotions)
Property -> Property -> Property
forall prop1 prop2.
(Testable prop1, Testable prop2) =>
prop1 -> prop2 -> Property
.&&. TestName -> Property -> Property
forall prop. Testable prop => TestName -> prop -> Property
counterexample TestName
"viewEstablishedLocalRootPeers"
(Set PeerAddr -> Int
forall a. Set a -> Int
Set.size ((Set PeerAddr, Int) -> Set PeerAddr
forall a b. (a, b) -> a
fst (Set PeerAddr, Int)
viewEstablishedLocalRootPeers) Int -> Int -> Property
forall a. (Eq a, Show a) => a -> a -> Property
=== (Set PeerAddr, Int) -> Int
forall a b. (a, b) -> b
snd (Set PeerAddr, Int)
viewEstablishedLocalRootPeers)
Property -> Property -> Property
forall prop1 prop2.
(Testable prop1, Testable prop2) =>
prop1 -> prop2 -> Property
.&&. TestName -> Property -> Property
forall prop. Testable prop => TestName -> prop -> Property
counterexample TestName
"viewWarmLocalRootPeersPromotions"
(Set PeerAddr -> Int
forall a. Set a -> Int
Set.size ((Set PeerAddr, Int) -> Set PeerAddr
forall a b. (a, b) -> a
fst (Set PeerAddr, Int)
viewWarmLocalRootPeersPromotions) Int -> Int -> Property
forall a. (Eq a, Show a) => a -> a -> Property
=== (Set PeerAddr, Int) -> Int
forall a b. (a, b) -> b
snd (Set PeerAddr, Int)
viewWarmLocalRootPeersPromotions)
Property -> Property -> Property
forall prop1 prop2.
(Testable prop1, Testable prop2) =>
prop1 -> prop2 -> Property
.&&. TestName -> Property -> Property
forall prop. Testable prop => TestName -> prop -> Property
counterexample TestName
"viewActiveLocalRootPeers"
(Set PeerAddr -> Int
forall a. Set a -> Int
Set.size ((Set PeerAddr, Int) -> Set PeerAddr
forall a b. (a, b) -> a
fst (Set PeerAddr, Int)
viewActiveLocalRootPeers) Int -> Int -> Property
forall a. (Eq a, Show a) => a -> a -> Property
=== (Set PeerAddr, Int) -> Int
forall a b. (a, b) -> b
snd (Set PeerAddr, Int)
viewActiveLocalRootPeers)
Property -> Property -> Property
forall prop1 prop2.
(Testable prop1, Testable prop2) =>
prop1 -> prop2 -> Property
.&&. TestName -> Property -> Property
forall prop. Testable prop => TestName -> prop -> Property
counterexample TestName
"viewActiveLocalRootPeersDemotions"
(Set PeerAddr -> Int
forall a. Set a -> Int
Set.size ((Set PeerAddr, Int) -> Set PeerAddr
forall a b. (a, b) -> a
fst (Set PeerAddr, Int)
viewActiveLocalRootPeersDemotions) Int -> Int -> Property
forall a. (Eq a, Show a) => a -> a -> Property
=== (Set PeerAddr, Int) -> Int
forall a b. (a, b) -> b
snd (Set PeerAddr, Int)
viewActiveLocalRootPeersDemotions)
Property -> Property -> Property
forall prop1 prop2.
(Testable prop1, Testable prop2) =>
prop1 -> prop2 -> Property
.&&. TestName -> Property -> Property
forall prop. Testable prop => TestName -> prop -> Property
counterexample TestName
"viewKnownNonRootPeers"
(Set PeerAddr -> Int
forall a. Set a -> Int
Set.size ((Set PeerAddr, Int) -> Set PeerAddr
forall a b. (a, b) -> a
fst (Set PeerAddr, Int)
viewKnownNonRootPeers) Int -> Int -> Property
forall a. (Eq a, Show a) => a -> a -> Property
=== (Set PeerAddr, Int) -> Int
forall a b. (a, b) -> b
snd (Set PeerAddr, Int)
viewKnownNonRootPeers)
Property -> Property -> Property
forall prop1 prop2.
(Testable prop1, Testable prop2) =>
prop1 -> prop2 -> Property
.&&. TestName -> Property -> Property
forall prop. Testable prop => TestName -> prop -> Property
counterexample TestName
"viewColdNonRootPeersPromotions"
(Set PeerAddr -> Int
forall a. Set a -> Int
Set.size ((Set PeerAddr, Int) -> Set PeerAddr
forall a b. (a, b) -> a
fst (Set PeerAddr, Int)
viewColdNonRootPeersPromotions) Int -> Int -> Property
forall a. (Eq a, Show a) => a -> a -> Property
=== (Set PeerAddr, Int) -> Int
forall a b. (a, b) -> b
snd (Set PeerAddr, Int)
viewColdNonRootPeersPromotions)
Property -> Property -> Property
forall prop1 prop2.
(Testable prop1, Testable prop2) =>
prop1 -> prop2 -> Property
.&&. TestName -> Property -> Property
forall prop. Testable prop => TestName -> prop -> Property
counterexample TestName
"viewEstablishedNonRootPeers"
(Set PeerAddr -> Int
forall a. Set a -> Int
Set.size ((Set PeerAddr, Int) -> Set PeerAddr
forall a b. (a, b) -> a
fst (Set PeerAddr, Int)
viewEstablishedNonRootPeers) Int -> Int -> Property
forall a. (Eq a, Show a) => a -> a -> Property
=== (Set PeerAddr, Int) -> Int
forall a b. (a, b) -> b
snd (Set PeerAddr, Int)
viewEstablishedNonRootPeers)
Property -> Property -> Property
forall prop1 prop2.
(Testable prop1, Testable prop2) =>
prop1 -> prop2 -> Property
.&&. TestName -> Property -> Property
forall prop. Testable prop => TestName -> prop -> Property
counterexample TestName
"viewWarmNonRootPeersDemotions"
(Set PeerAddr -> Int
forall a. Set a -> Int
Set.size ((Set PeerAddr, Int) -> Set PeerAddr
forall a b. (a, b) -> a
fst (Set PeerAddr, Int)
viewWarmNonRootPeersDemotions) Int -> Int -> Property
forall a. (Eq a, Show a) => a -> a -> Property
=== (Set PeerAddr, Int) -> Int
forall a b. (a, b) -> b
snd (Set PeerAddr, Int)
viewWarmNonRootPeersDemotions)
Property -> Property -> Property
forall prop1 prop2.
(Testable prop1, Testable prop2) =>
prop1 -> prop2 -> Property
.&&. TestName -> Property -> Property
forall prop. Testable prop => TestName -> prop -> Property
counterexample TestName
"viewWarmNonRootPeersPromotions"
(Set PeerAddr -> Int
forall a. Set a -> Int
Set.size ((Set PeerAddr, Int) -> Set PeerAddr
forall a b. (a, b) -> a
fst (Set PeerAddr, Int)
viewWarmNonRootPeersPromotions) Int -> Int -> Property
forall a. (Eq a, Show a) => a -> a -> Property
=== (Set PeerAddr, Int) -> Int
forall a b. (a, b) -> b
snd (Set PeerAddr, Int)
viewWarmNonRootPeersPromotions)
Property -> Property -> Property
forall prop1 prop2.
(Testable prop1, Testable prop2) =>
prop1 -> prop2 -> Property
.&&. TestName -> Property -> Property
forall prop. Testable prop => TestName -> prop -> Property
counterexample TestName
"viewActiveNonRootPeers"
(Set PeerAddr -> Int
forall a. Set a -> Int
Set.size ((Set PeerAddr, Int) -> Set PeerAddr
forall a b. (a, b) -> a
fst (Set PeerAddr, Int)
viewActiveNonRootPeers) Int -> Int -> Property
forall a. (Eq a, Show a) => a -> a -> Property
=== (Set PeerAddr, Int) -> Int
forall a b. (a, b) -> b
snd (Set PeerAddr, Int)
viewActiveNonRootPeers)
Property -> Property -> Property
forall prop1 prop2.
(Testable prop1, Testable prop2) =>
prop1 -> prop2 -> Property
.&&. TestName -> Property -> Property
forall prop. Testable prop => TestName -> prop -> Property
counterexample TestName
"viewActiveNonRootPeersDemotions"
(Set PeerAddr -> Int
forall a. Set a -> Int
Set.size ((Set PeerAddr, Int) -> Set PeerAddr
forall a b. (a, b) -> a
fst (Set PeerAddr, Int)
viewActiveNonRootPeersDemotions) Int -> Int -> Property
forall a. (Eq a, Show a) => a -> a -> Property
=== (Set PeerAddr, Int) -> Int
forall a b. (a, b) -> b
snd (Set PeerAddr, Int)
viewActiveNonRootPeersDemotions)
Property -> Property -> Property
forall prop1 prop2.
(Testable prop1, Testable prop2) =>
prop1 -> prop2 -> Property
.&&. TestName -> Property -> Property
forall prop. Testable prop => TestName -> prop -> Property
counterexample TestName
"viewKnownBootstrapPeers"
(Set PeerAddr -> Int
forall a. Set a -> Int
Set.size ((Set PeerAddr, Int) -> Set PeerAddr
forall a b. (a, b) -> a
fst (Set PeerAddr, Int)
viewKnownBootstrapPeers) Int -> Int -> Property
forall a. (Eq a, Show a) => a -> a -> Property
=== (Set PeerAddr, Int) -> Int
forall a b. (a, b) -> b
snd (Set PeerAddr, Int)
viewKnownBootstrapPeers)
Property -> Property -> Property
forall prop1 prop2.
(Testable prop1, Testable prop2) =>
prop1 -> prop2 -> Property
.&&. TestName -> Property -> Property
forall prop. Testable prop => TestName -> prop -> Property
counterexample TestName
"viewColdBootstrapPeersPromotions"
(Set PeerAddr -> Int
forall a. Set a -> Int
Set.size ((Set PeerAddr, Int) -> Set PeerAddr
forall a b. (a, b) -> a
fst (Set PeerAddr, Int)
viewColdBootstrapPeersPromotions) Int -> Int -> Property
forall a. (Eq a, Show a) => a -> a -> Property
=== (Set PeerAddr, Int) -> Int
forall a b. (a, b) -> b
snd (Set PeerAddr, Int)
viewColdBootstrapPeersPromotions)
Property -> Property -> Property
forall prop1 prop2.
(Testable prop1, Testable prop2) =>
prop1 -> prop2 -> Property
.&&. TestName -> Property -> Property
forall prop. Testable prop => TestName -> prop -> Property
counterexample TestName
"viewEstablishedBootstrapPeers"
(Set PeerAddr -> Int
forall a. Set a -> Int
Set.size ((Set PeerAddr, Int) -> Set PeerAddr
forall a b. (a, b) -> a
fst (Set PeerAddr, Int)
viewEstablishedBootstrapPeers) Int -> Int -> Property
forall a. (Eq a, Show a) => a -> a -> Property
=== (Set PeerAddr, Int) -> Int
forall a b. (a, b) -> b
snd (Set PeerAddr, Int)
viewEstablishedBootstrapPeers)
Property -> Property -> Property
forall prop1 prop2.
(Testable prop1, Testable prop2) =>
prop1 -> prop2 -> Property
.&&. TestName -> Property -> Property
forall prop. Testable prop => TestName -> prop -> Property
counterexample TestName
"viewWarmBootstrapPeersDemotions"
(Set PeerAddr -> Int
forall a. Set a -> Int
Set.size ((Set PeerAddr, Int) -> Set PeerAddr
forall a b. (a, b) -> a
fst (Set PeerAddr, Int)
viewWarmBootstrapPeersDemotions) Int -> Int -> Property
forall a. (Eq a, Show a) => a -> a -> Property
=== (Set PeerAddr, Int) -> Int
forall a b. (a, b) -> b
snd (Set PeerAddr, Int)
viewWarmBootstrapPeersDemotions)
Property -> Property -> Property
forall prop1 prop2.
(Testable prop1, Testable prop2) =>
prop1 -> prop2 -> Property
.&&. TestName -> Property -> Property
forall prop. Testable prop => TestName -> prop -> Property
counterexample TestName
"viewWarmBootstrapPeersPromotions"
(Set PeerAddr -> Int
forall a. Set a -> Int
Set.size ((Set PeerAddr, Int) -> Set PeerAddr
forall a b. (a, b) -> a
fst (Set PeerAddr, Int)
viewWarmBootstrapPeersPromotions) Int -> Int -> Property
forall a. (Eq a, Show a) => a -> a -> Property
=== (Set PeerAddr, Int) -> Int
forall a b. (a, b) -> b
snd (Set PeerAddr, Int)
viewWarmBootstrapPeersPromotions)
Property -> Property -> Property
forall prop1 prop2.
(Testable prop1, Testable prop2) =>
prop1 -> prop2 -> Property
.&&. TestName -> Property -> Property
forall prop. Testable prop => TestName -> prop -> Property
counterexample TestName
"viewActiveBootstrapPeers"
(Set PeerAddr -> Int
forall a. Set a -> Int
Set.size ((Set PeerAddr, Int) -> Set PeerAddr
forall a b. (a, b) -> a
fst (Set PeerAddr, Int)
viewActiveBootstrapPeers) Int -> Int -> Property
forall a. (Eq a, Show a) => a -> a -> Property
=== (Set PeerAddr, Int) -> Int
forall a b. (a, b) -> b
snd (Set PeerAddr, Int)
viewActiveBootstrapPeers)
Property -> Property -> Property
forall prop1 prop2.
(Testable prop1, Testable prop2) =>
prop1 -> prop2 -> Property
.&&. TestName -> Property -> Property
forall prop. Testable prop => TestName -> prop -> Property
counterexample TestName
"viewActiveBootstrapPeersDemotions"
(Set PeerAddr -> Int
forall a. Set a -> Int
Set.size ((Set PeerAddr, Int) -> Set PeerAddr
forall a b. (a, b) -> a
fst (Set PeerAddr, Int)
viewActiveBootstrapPeersDemotions) Int -> Int -> Property
forall a. (Eq a, Show a) => a -> a -> Property
=== (Set PeerAddr, Int) -> Int
forall a b. (a, b) -> b
snd (Set PeerAddr, Int)
viewActiveBootstrapPeersDemotions)
prop_governor_hasoutput :: GovernorMockEnvironment -> Property
prop_governor_hasoutput :: GovernorMockEnvironment -> Property
prop_governor_hasoutput GovernorMockEnvironment
env =
let trace :: SimTrace Void
trace = GovernorMockEnvironment -> SimTrace Void
runGovernorInMockEnvironment GovernorMockEnvironment
env
evs :: [(Time, TestTraceEvent)]
evs = SimTrace Void -> [(Time, TestTraceEvent)]
forall a. SimTrace a -> [(Time, TestTraceEvent)]
selectPeerSelectionTraceEvents SimTrace Void
trace
in TestName -> Property -> Property
forall prop. Testable prop => TestName -> prop -> Property
counterexample ([TestName] -> TestName
unlines [TestName
"\nSIM TRACE", SimTrace Void -> TestName
forall a. Show a => SimTrace a -> TestName
ppTrace SimTrace Void
trace])
(Property -> Property) -> Property -> Property
forall a b. (a -> b) -> a -> b
$ TestName -> Bool -> Property
forall prop. Testable prop => TestName -> prop -> Property
counterexample ([TestName] -> TestName
unlines ([TestName] -> TestName)
-> ([(Time, TestTraceEvent)] -> [TestName])
-> [(Time, TestTraceEvent)]
-> TestName
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (TestName
"EVENTS" TestName -> [TestName] -> [TestName]
forall a. a -> [a] -> [a]
:) ([TestName] -> [TestName])
-> ([(Time, TestTraceEvent)] -> [TestName])
-> [(Time, TestTraceEvent)]
-> [TestName]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ((Time, TestTraceEvent) -> TestName)
-> [(Time, TestTraceEvent)] -> [TestName]
forall a b. (a -> b) -> [a] -> [b]
map (Time, TestTraceEvent) -> TestName
forall a. Show a => a -> TestName
show ([(Time, TestTraceEvent)] -> TestName)
-> [(Time, TestTraceEvent)] -> TestName
forall a b. (a -> b) -> a -> b
$ [(Time, TestTraceEvent)]
evs)
(Bool -> Property) -> Bool -> Property
forall a b. (a -> b) -> a -> b
$ GovernorMockEnvironment
-> [(Time, TracePeerSelection PeerAddr)] -> Bool
hasOutput GovernorMockEnvironment
env ([(Time, TestTraceEvent)] -> [(Time, TracePeerSelection PeerAddr)]
selectGovernorEvents [(Time, TestTraceEvent)]
evs)
hasOutput :: GovernorMockEnvironment
-> [(Time, TracePeerSelection PeerAddr)]
-> Bool
hasOutput :: GovernorMockEnvironment
-> [(Time, TracePeerSelection PeerAddr)] -> Bool
hasOutput GovernorMockEnvironment
_ ((Time, TracePeerSelection PeerAddr)
_:[(Time, TracePeerSelection PeerAddr)]
_) = Bool
True
hasOutput GovernorMockEnvironment
env [] = GovernorMockEnvironment -> Bool
isEmptyEnv GovernorMockEnvironment
env
isEmptyEnv :: GovernorMockEnvironment -> Bool
isEmptyEnv :: GovernorMockEnvironment -> Bool
isEmptyEnv GovernorMockEnvironment {
LocalRootPeers PeerAddr
localRootPeers :: LocalRootPeers PeerAddr
localRootPeers :: GovernorMockEnvironment -> LocalRootPeers PeerAddr
localRootPeers,
PublicRootPeers PeerAddr
publicRootPeers :: PublicRootPeers PeerAddr
publicRootPeers :: GovernorMockEnvironment -> PublicRootPeers PeerAddr
publicRootPeers,
targets :: GovernorMockEnvironment -> TimedScript ConsensusModePeerTargets
targets = targets :: TimedScript ConsensusModePeerTargets
targets@(Script NonEmpty (ConsensusModePeerTargets, ScriptDelay)
targets'),
ConsensusMode
consensusMode :: ConsensusMode
consensusMode :: GovernorMockEnvironment -> ConsensusMode
consensusMode,
ledgerStateJudgement :: GovernorMockEnvironment -> TimedScript LedgerStateJudgement
ledgerStateJudgement = Script NonEmpty (LedgerStateJudgement, ScriptDelay)
ledgerStateJudgement'
} =
(LocalRootPeers PeerAddr -> Bool
forall peeraddr. LocalRootPeers peeraddr -> Bool
LocalRootPeers.null LocalRootPeers PeerAddr
localRootPeers
Bool -> Bool -> Bool
|| case ConsensusMode
consensusMode of
ConsensusMode
PraosMode ->
((ConsensusModePeerTargets, ScriptDelay) -> Bool)
-> TimedScript ConsensusModePeerTargets -> Bool
forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
all (\(ConsensusModePeerTargets -> PeerSelectionTargets
deadlineTargets -> PeerSelectionTargets
t,ScriptDelay
_) -> PeerSelectionTargets -> Int
targetNumberOfKnownPeers PeerSelectionTargets
t Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
0)
TimedScript ConsensusModePeerTargets
targets
ConsensusMode
GenesisMode ->
(((ConsensusModePeerTargets, ScriptDelay),
(LedgerStateJudgement, ScriptDelay))
-> Bool)
-> NonEmpty
((ConsensusModePeerTargets, ScriptDelay),
(LedgerStateJudgement, ScriptDelay))
-> Bool
forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
all (\((ConsensusModePeerTargets
t, ScriptDelay
_), (LedgerStateJudgement
lsj, ScriptDelay
_)) ->
case LedgerStateJudgement
lsj of
LedgerStateJudgement
TooOld -> Int
0 Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== (PeerSelectionTargets -> Int
targetNumberOfKnownPeers (PeerSelectionTargets -> Int)
-> (ConsensusModePeerTargets -> PeerSelectionTargets)
-> ConsensusModePeerTargets
-> Int
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ConsensusModePeerTargets -> PeerSelectionTargets
syncTargets (ConsensusModePeerTargets -> Int)
-> ConsensusModePeerTargets -> Int
forall a b. (a -> b) -> a -> b
$ ConsensusModePeerTargets
t)
LedgerStateJudgement
YoungEnough ->
Int
0 Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== (PeerSelectionTargets -> Int
targetNumberOfKnownPeers (PeerSelectionTargets -> Int)
-> (ConsensusModePeerTargets -> PeerSelectionTargets)
-> ConsensusModePeerTargets
-> Int
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ConsensusModePeerTargets -> PeerSelectionTargets
deadlineTargets (ConsensusModePeerTargets -> Int)
-> ConsensusModePeerTargets -> Int
forall a b. (a -> b) -> a -> b
$ ConsensusModePeerTargets
t))
(NonEmpty
((ConsensusModePeerTargets, ScriptDelay),
(LedgerStateJudgement, ScriptDelay))
-> Bool)
-> NonEmpty
((ConsensusModePeerTargets, ScriptDelay),
(LedgerStateJudgement, ScriptDelay))
-> Bool
forall a b. (a -> b) -> a -> b
$ NonEmpty (ConsensusModePeerTargets, ScriptDelay)
-> NonEmpty (LedgerStateJudgement, ScriptDelay)
-> NonEmpty
((ConsensusModePeerTargets, ScriptDelay),
(LedgerStateJudgement, ScriptDelay))
forall a b. NonEmpty a -> NonEmpty b -> NonEmpty (a, b)
NonEmpty.zip NonEmpty (ConsensusModePeerTargets, ScriptDelay)
targets' NonEmpty (LedgerStateJudgement, ScriptDelay)
ledgerStateJudgement')
Bool -> Bool -> Bool
&& (PublicRootPeers PeerAddr -> Bool
forall peeraddr. PublicRootPeers peeraddr -> Bool
PublicRootPeers.null PublicRootPeers PeerAddr
publicRootPeers
Bool -> Bool -> Bool
|| case ConsensusMode
consensusMode of
ConsensusMode
PraosMode ->
((ConsensusModePeerTargets, ScriptDelay) -> Bool)
-> TimedScript ConsensusModePeerTargets -> Bool
forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
all (\(ConsensusModePeerTargets -> PeerSelectionTargets
deadlineTargets -> PeerSelectionTargets
t,ScriptDelay
_) -> PeerSelectionTargets -> Int
targetNumberOfRootPeers PeerSelectionTargets
t Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
0)
TimedScript ConsensusModePeerTargets
targets
ConsensusMode
GenesisMode ->
(((ConsensusModePeerTargets, ScriptDelay),
(LedgerStateJudgement, ScriptDelay))
-> Bool)
-> NonEmpty
((ConsensusModePeerTargets, ScriptDelay),
(LedgerStateJudgement, ScriptDelay))
-> Bool
forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
all (\((ConsensusModePeerTargets
t, ScriptDelay
_), (LedgerStateJudgement
lsj, ScriptDelay
_)) ->
case LedgerStateJudgement
lsj of
LedgerStateJudgement
TooOld -> Int
0 Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== (PeerSelectionTargets -> Int
targetNumberOfRootPeers (PeerSelectionTargets -> Int)
-> (ConsensusModePeerTargets -> PeerSelectionTargets)
-> ConsensusModePeerTargets
-> Int
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ConsensusModePeerTargets -> PeerSelectionTargets
syncTargets (ConsensusModePeerTargets -> Int)
-> ConsensusModePeerTargets -> Int
forall a b. (a -> b) -> a -> b
$ ConsensusModePeerTargets
t)
LedgerStateJudgement
YoungEnough ->
Int
0 Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== (PeerSelectionTargets -> Int
targetNumberOfRootPeers (PeerSelectionTargets -> Int)
-> (ConsensusModePeerTargets -> PeerSelectionTargets)
-> ConsensusModePeerTargets
-> Int
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ConsensusModePeerTargets -> PeerSelectionTargets
deadlineTargets (ConsensusModePeerTargets -> Int)
-> ConsensusModePeerTargets -> Int
forall a b. (a -> b) -> a -> b
$ ConsensusModePeerTargets
t))
(NonEmpty
((ConsensusModePeerTargets, ScriptDelay),
(LedgerStateJudgement, ScriptDelay))
-> Bool)
-> NonEmpty
((ConsensusModePeerTargets, ScriptDelay),
(LedgerStateJudgement, ScriptDelay))
-> Bool
forall a b. (a -> b) -> a -> b
$ NonEmpty (ConsensusModePeerTargets, ScriptDelay)
-> NonEmpty (LedgerStateJudgement, ScriptDelay)
-> NonEmpty
((ConsensusModePeerTargets, ScriptDelay),
(LedgerStateJudgement, ScriptDelay))
forall a b. NonEmpty a -> NonEmpty b -> NonEmpty (a, b)
NonEmpty.zip NonEmpty (ConsensusModePeerTargets, ScriptDelay)
targets' NonEmpty (LedgerStateJudgement, ScriptDelay)
ledgerStateJudgement')
prop_governor_nofail :: GovernorMockEnvironment -> Property
prop_governor_nofail :: GovernorMockEnvironment -> Property
prop_governor_nofail GovernorMockEnvironment
env =
let ioSimTrace :: SimTrace Void
ioSimTrace = GovernorMockEnvironment -> SimTrace Void
runGovernorInMockEnvironment GovernorMockEnvironment
env
trace :: [(Time, TestTraceEvent)]
trace = Int -> [(Time, TestTraceEvent)] -> [(Time, TestTraceEvent)]
forall a. Int -> [a] -> [a]
take Int
5000
([(Time, TestTraceEvent)] -> [(Time, TestTraceEvent)])
-> (SimTrace Void -> [(Time, TestTraceEvent)])
-> SimTrace Void
-> [(Time, TestTraceEvent)]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. SimTrace Void -> [(Time, TestTraceEvent)]
forall a. SimTrace a -> [(Time, TestTraceEvent)]
selectPeerSelectionTraceEvents
(SimTrace Void -> [(Time, TestTraceEvent)])
-> SimTrace Void -> [(Time, TestTraceEvent)]
forall a b. (a -> b) -> a -> b
$ SimTrace Void
ioSimTrace
in IO Property -> Property
forall prop. Testable prop => IO prop -> Property
ioProperty (IO Property -> Property) -> IO Property -> Property
forall a b. (a -> b) -> a -> b
$ do
r <-
Bool -> IO Bool
forall a. a -> IO a
evaluate ( (Bool -> () -> Bool) -> Bool -> [()] -> Bool
forall b a. (b -> a -> b) -> b -> [a] -> b
forall (t :: * -> *) b a.
Foldable t =>
(b -> a -> b) -> b -> t a -> b
List.foldl' ((() -> Bool -> Bool) -> Bool -> () -> Bool
forall a b c. (a -> b -> c) -> b -> a -> c
flip () -> Bool -> Bool
forall a b. a -> b -> b
seq) Bool
True
([()] -> Bool) -> [()] -> Bool
forall a b. (a -> b) -> a -> b
$ [ PeerSelectionState PeerAddr peerconn -> () -> ()
forall peeraddr peerconn a.
Ord peeraddr =>
PeerSelectionState peeraddr peerconn -> a -> a
assertPeerSelectionState PeerSelectionState PeerAddr peerconn
st ()
| (Time
_, GovernorDebug (TraceGovernorState Time
_ Maybe DiffTime
_ PeerSelectionState PeerAddr peerconn
st)) <- [(Time, TestTraceEvent)]
trace ]
)
IO Bool -> (AssertionFailed -> IO Bool) -> IO Bool
forall e a. Exception e => IO a -> (e -> IO a) -> IO a
`catch` \(AssertionFailed TestName
_) -> Bool -> IO Bool
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return Bool
False
case r of
Bool
True -> Property -> IO Property
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return (Property -> IO Property) -> Property -> IO Property
forall a b. (a -> b) -> a -> b
$ Bool -> Property
forall prop. Testable prop => prop -> Property
property Bool
True
Bool
False -> do
(SimResult Void -> IO ())
-> (SimEvent -> IO ()) -> SimTrace Void -> IO ()
forall (t :: * -> * -> *) (f :: * -> *) a c b d.
(Bifoldable t, Applicative f) =>
(a -> f c) -> (b -> f d) -> t a b -> f ()
bitraverse_ (TestName -> IO ()
putStrLn (TestName -> IO ())
-> (SimResult Void -> TestName) -> SimResult Void -> IO ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. SimResult Void -> TestName
forall a. Show a => a -> TestName
show)
(TestName -> IO ()
putStrLn (TestName -> IO ()) -> (SimEvent -> TestName) -> SimEvent -> IO ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> Int -> Int -> SimEvent -> TestName
ppSimEvent Int
20 Int
20 Int
20)
SimTrace Void
ioSimTrace
TestName -> IO Property
forall a. HasCallStack => TestName -> a
error TestName
"impossible!"
prop_governor_nolivelock :: GovernorMockEnvironment -> Property
prop_governor_nolivelock :: GovernorMockEnvironment -> Property
prop_governor_nolivelock GovernorMockEnvironment
env =
Int -> SimTrace Void -> Property
forall a. Int -> SimTrace a -> Property
check_governor_nolivelock Int
5000 (SimTrace Void -> Property) -> SimTrace Void -> Property
forall a b. (a -> b) -> a -> b
$ GovernorMockEnvironment -> SimTrace Void
runGovernorInMockEnvironment GovernorMockEnvironment
env
prop_explore_governor_nolivelock :: GovernorMockEnvironment -> Property
prop_explore_governor_nolivelock :: GovernorMockEnvironment -> Property
prop_explore_governor_nolivelock =
ExplorationSpec -> Int -> GovernorMockEnvironment -> Property
prop'_explore_governor_nolivelock ExplorationSpec
forall a. a -> a
id Int
500
prop'_explore_governor_nolivelock :: ExplorationSpec -> Int -> GovernorMockEnvironment -> Property
prop'_explore_governor_nolivelock :: ExplorationSpec -> Int -> GovernorMockEnvironment -> Property
prop'_explore_governor_nolivelock ExplorationSpec
spec Int
len GovernorMockEnvironment
env =
ExplorationSpec
-> GovernorMockEnvironment
-> (Maybe (SimTrace Void) -> SimTrace Void -> Property)
-> Property
forall test.
Testable test =>
ExplorationSpec
-> GovernorMockEnvironment
-> (Maybe (SimTrace Void) -> SimTrace Void -> test)
-> Property
exploreGovernorInMockEnvironment ExplorationSpec
spec GovernorMockEnvironment
env ((Maybe (SimTrace Void) -> SimTrace Void -> Property) -> Property)
-> (Maybe (SimTrace Void) -> SimTrace Void -> Property) -> Property
forall a b. (a -> b) -> a -> b
$ \Maybe (SimTrace Void)
_ SimTrace Void
trace ->
Int -> SimTrace Void -> Property
forall a. Int -> SimTrace a -> Property
check_governor_nolivelock Int
len SimTrace Void
trace
check_governor_nolivelock :: Int -> SimTrace a -> Property
check_governor_nolivelock :: forall a. Int -> SimTrace a -> Property
check_governor_nolivelock Int
n SimTrace a
trace0 =
let trace :: [(Time, TracePeerSelection PeerAddr)]
trace = Int
-> [(Time, TracePeerSelection PeerAddr)]
-> [(Time, TracePeerSelection PeerAddr)]
forall a. Int -> [a] -> [a]
take Int
n ([(Time, TracePeerSelection PeerAddr)]
-> [(Time, TracePeerSelection PeerAddr)])
-> (SimTrace a -> [(Time, TracePeerSelection PeerAddr)])
-> SimTrace a
-> [(Time, TracePeerSelection PeerAddr)]
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
[(Time, TestTraceEvent)] -> [(Time, TracePeerSelection PeerAddr)]
selectGovernorEvents ([(Time, TestTraceEvent)] -> [(Time, TracePeerSelection PeerAddr)])
-> (SimTrace a -> [(Time, TestTraceEvent)])
-> SimTrace a
-> [(Time, TracePeerSelection PeerAddr)]
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
SimTrace a -> [(Time, TestTraceEvent)]
forall a. SimTrace a -> [(Time, TestTraceEvent)]
selectPeerSelectionTraceEvents (SimTrace a -> [(Time, TracePeerSelection PeerAddr)])
-> SimTrace a -> [(Time, TracePeerSelection PeerAddr)]
forall a b. (a -> b) -> a -> b
$
SimTrace a
trace0
in case Int
-> [(Time, TracePeerSelection PeerAddr)]
-> Maybe (Time, [TracePeerSelection PeerAddr])
forall e. Int -> [(Time, e)] -> Maybe (Time, [e])
tooManyEventsBeforeTimeAdvances Int
1000 [(Time, TracePeerSelection PeerAddr)]
trace of
Maybe (Time, [TracePeerSelection PeerAddr])
Nothing -> Bool -> Property
forall prop. Testable prop => prop -> Property
property Bool
True
Just (Time
t, [TracePeerSelection PeerAddr]
es) ->
TestName -> Property -> Property
forall prop. Testable prop => TestName -> prop -> Property
counterexample
(TestName
"over 1000 events at time: " TestName -> TestName -> TestName
forall a. [a] -> [a] -> [a]
++ Time -> TestName
forall a. Show a => a -> TestName
show Time
t TestName -> TestName -> TestName
forall a. [a] -> [a] -> [a]
++ TestName
"\n" TestName -> TestName -> TestName
forall a. [a] -> [a] -> [a]
++
TestName
"first 50 events: " TestName -> TestName -> TestName
forall a. [a] -> [a] -> [a]
++ ([TestName] -> TestName
unlines ([TestName] -> TestName)
-> ([TracePeerSelection PeerAddr] -> [TestName])
-> [TracePeerSelection PeerAddr]
-> TestName
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (TracePeerSelection PeerAddr -> TestName)
-> [TracePeerSelection PeerAddr] -> [TestName]
forall a b. (a -> b) -> [a] -> [b]
map TracePeerSelection PeerAddr -> TestName
forall a. Show a => a -> TestName
show ([TracePeerSelection PeerAddr] -> [TestName])
-> ([TracePeerSelection PeerAddr] -> [TracePeerSelection PeerAddr])
-> [TracePeerSelection PeerAddr]
-> [TestName]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int
-> [TracePeerSelection PeerAddr] -> [TracePeerSelection PeerAddr]
forall a. Int -> [a] -> [a]
take Int
50 ([TracePeerSelection PeerAddr] -> TestName)
-> [TracePeerSelection PeerAddr] -> TestName
forall a b. (a -> b) -> a -> b
$ [TracePeerSelection PeerAddr]
es)) (Property -> Property) -> Property -> Property
forall a b. (a -> b) -> a -> b
$
Bool -> Property
forall prop. Testable prop => prop -> Property
property Bool
False
tooManyEventsBeforeTimeAdvances :: Int -> [(Time, e)] -> Maybe (Time, [e])
tooManyEventsBeforeTimeAdvances :: forall e. Int -> [(Time, e)] -> Maybe (Time, [e])
tooManyEventsBeforeTimeAdvances Int
_ [] = Maybe (Time, [e])
forall a. Maybe a
Nothing
tooManyEventsBeforeTimeAdvances Int
threshold [(Time, e)]
trace0 =
[(Time, DiffTime, e)] -> Maybe (Time, [e])
forall {a} {a} {c}. (Eq a, Num a) => [(a, a, c)] -> Maybe (a, [c])
go [ (Time
t, Time -> Time -> DiffTime
diffTime Time
t' Time
t, e
e)
| ((Time
t, e
e), (Time
t', e
_)) <- [(Time, e)] -> [(Time, e)] -> [((Time, e), (Time, e))]
forall a b. [a] -> [b] -> [(a, b)]
zip [(Time, e)]
trace0 ([(Time, e)] -> [(Time, e)]
forall a. HasCallStack => [a] -> [a]
tail [(Time, e)]
trace0) ]
where
go :: [(a, a, c)] -> Maybe (a, [c])
go [] = Maybe (a, [c])
forall a. Maybe a
Nothing
go trace :: [(a, a, c)]
trace@((a
t,a
_,c
_):[(a, a, c)]
_) = case Int -> [(a, a, c)] -> Maybe [(a, a, c)]
forall {t} {a} {a} {c}.
(Eq t, Eq a, Num t, Num a) =>
t -> [(a, a, c)] -> Maybe [(a, a, c)]
countdown Int
threshold [(a, a, c)]
trace of
Just [(a, a, c)]
es' -> [(a, a, c)] -> Maybe (a, [c])
go [(a, a, c)]
es'
Maybe [(a, a, c)]
Nothing -> (a, [c]) -> Maybe (a, [c])
forall a. a -> Maybe a
Just (a
t, [c]
trace')
where
trace' :: [c]
trace' = Int -> [c] -> [c]
forall a. Int -> [a] -> [a]
take Int
threshold [ c
e | (a
_,a
_,c
e) <- [(a, a, c)]
trace ]
countdown :: t -> [(a, a, c)] -> Maybe [(a, a, c)]
countdown t
0 [(a, a, c)]
_ = Maybe [(a, a, c)]
forall a. Maybe a
Nothing
countdown t
_ [] = [(a, a, c)] -> Maybe [(a, a, c)]
forall a. a -> Maybe a
Just []
countdown t
n ((a
_t,a
dt,c
_e):[(a, a, c)]
es)
| a
dt a -> a -> Bool
forall a. Eq a => a -> a -> Bool
== a
0 = t -> [(a, a, c)] -> Maybe [(a, a, c)]
countdown (t
nt -> t -> t
forall a. Num a => a -> a -> a
-t
1) [(a, a, c)]
es
| Bool
otherwise = [(a, a, c)] -> Maybe [(a, a, c)]
forall a. a -> Maybe a
Just [(a, a, c)]
es
prop_governor_nobusyness :: GovernorMockEnvironment -> Property
prop_governor_nobusyness :: GovernorMockEnvironment -> Property
prop_governor_nobusyness GovernorMockEnvironment
env =
let trace :: [(Time, TestTraceEvent)]
trace = SimTrace Void -> [(Time, TestTraceEvent)]
forall a. SimTrace a -> [(Time, TestTraceEvent)]
selectPeerSelectionTraceEvents (SimTrace Void -> [(Time, TestTraceEvent)])
-> SimTrace Void -> [(Time, TestTraceEvent)]
forall a b. (a -> b) -> a -> b
$
GovernorMockEnvironment -> SimTrace Void
runGovernorInMockEnvironment GovernorMockEnvironment
env
in case [(Time, TestTraceEvent)]
-> Maybe (Time, Time, DiffTime, [(Time, TestTraceEvent)])
tooBusyForTooLong (DiffTime -> [(Time, TestTraceEvent)] -> [(Time, TestTraceEvent)]
forall a. DiffTime -> [(Time, a)] -> [(Time, a)]
takeFirstNHours DiffTime
10 [(Time, TestTraceEvent)]
trace) of
Maybe (Time, Time, DiffTime, [(Time, TestTraceEvent)])
Nothing -> Bool -> Property
forall prop. Testable prop => prop -> Property
property Bool
True
Just (Time
busyStartTime, Time
busyEndTime, DiffTime
credits, [(Time, TestTraceEvent)]
trace') ->
TestName -> Property -> Property
forall prop. Testable prop => TestName -> prop -> Property
counterexample
(TestName
"busy span too long\n" TestName -> TestName -> TestName
forall a. [a] -> [a] -> [a]
++
TestName
"start time: " TestName -> TestName -> TestName
forall a. [a] -> [a] -> [a]
++ Time -> TestName
forall a. Show a => a -> TestName
show Time
busyStartTime TestName -> TestName -> TestName
forall a. [a] -> [a] -> [a]
++ TestName
"\n" TestName -> TestName -> TestName
forall a. [a] -> [a] -> [a]
++
TestName
"end time: " TestName -> TestName -> TestName
forall a. [a] -> [a] -> [a]
++ Time -> TestName
forall a. Show a => a -> TestName
show Time
busyEndTime TestName -> TestName -> TestName
forall a. [a] -> [a] -> [a]
++ TestName
"\n" TestName -> TestName -> TestName
forall a. [a] -> [a] -> [a]
++
TestName
"span credits: " TestName -> TestName -> TestName
forall a. [a] -> [a] -> [a]
++ DiffTime -> TestName
forall a. Show a => a -> TestName
show DiffTime
credits TestName -> TestName -> TestName
forall a. [a] -> [a] -> [a]
++ TestName
"\n" TestName -> TestName -> TestName
forall a. [a] -> [a] -> [a]
++
TestName
"first 50 events:\n" TestName -> TestName -> TestName
forall a. [a] -> [a] -> [a]
++
([TestName] -> TestName
unlines ([TestName] -> TestName)
-> ([(Time, TestTraceEvent)] -> [TestName])
-> [(Time, TestTraceEvent)]
-> TestName
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ((Time, TestTraceEvent) -> TestName)
-> [(Time, TestTraceEvent)] -> [TestName]
forall a b. (a -> b) -> [a] -> [b]
map (Time, TestTraceEvent) -> TestName
forall a. Show a => a -> TestName
show ([(Time, TestTraceEvent)] -> [TestName])
-> ([(Time, TestTraceEvent)] -> [(Time, TestTraceEvent)])
-> [(Time, TestTraceEvent)]
-> [TestName]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> [(Time, TestTraceEvent)] -> [(Time, TestTraceEvent)]
forall a. Int -> [a] -> [a]
take Int
50 ([(Time, TestTraceEvent)] -> TestName)
-> [(Time, TestTraceEvent)] -> TestName
forall a b. (a -> b) -> a -> b
$ [(Time, TestTraceEvent)]
trace')) (Property -> Property) -> Property -> Property
forall a b. (a -> b) -> a -> b
$
Bool -> Property
forall prop. Testable prop => prop -> Property
property Bool
False
tooBusyForTooLong :: [(Time, TestTraceEvent)]
-> Maybe (Time, Time, DiffTime,
[(Time, TestTraceEvent)])
tooBusyForTooLong :: [(Time, TestTraceEvent)]
-> Maybe (Time, Time, DiffTime, [(Time, TestTraceEvent)])
tooBusyForTooLong [(Time, TestTraceEvent)]
trace0 =
[(Time, DiffTime, TestTraceEvent)]
-> Maybe (Time, Time, DiffTime, [(Time, TestTraceEvent)])
idle [ (Time
t, Time -> Time -> DiffTime
diffTime Time
t' Time
t, TestTraceEvent
e)
| ((Time
t, TestTraceEvent
e), (Time
t', TestTraceEvent
_)) <- [(Time, TestTraceEvent)]
-> [(Time, TestTraceEvent)]
-> [((Time, TestTraceEvent), (Time, TestTraceEvent))]
forall a b. [a] -> [b] -> [(a, b)]
zip [(Time, TestTraceEvent)]
trace0 ([(Time, TestTraceEvent)] -> [(Time, TestTraceEvent)]
forall a. HasCallStack => [a] -> [a]
tail [(Time, TestTraceEvent)]
trace0) ]
where
sameSpanThreshold :: DiffTime
sameSpanThreshold :: DiffTime
sameSpanThreshold = DiffTime
45
initialEventCredits :: DiffTime
initialEventCredits :: DiffTime
initialEventCredits = DiffTime
65
idle :: [(Time, DiffTime, TestTraceEvent)]
-> Maybe (Time, Time, DiffTime, [(Time, TestTraceEvent)])
idle :: [(Time, DiffTime, TestTraceEvent)]
-> Maybe (Time, Time, DiffTime, [(Time, TestTraceEvent)])
idle [] = Maybe (Time, Time, DiffTime, [(Time, TestTraceEvent)])
forall a. Maybe a
Nothing
idle ((Time
_, DiffTime
_, GovernorDebug{}):[(Time, DiffTime, TestTraceEvent)]
trace') = [(Time, DiffTime, TestTraceEvent)]
-> Maybe (Time, Time, DiffTime, [(Time, TestTraceEvent)])
idle [(Time, DiffTime, TestTraceEvent)]
trace'
idle trace :: [(Time, DiffTime, TestTraceEvent)]
trace@((Time
busyStartTime,DiffTime
_,TestTraceEvent
_):[(Time, DiffTime, TestTraceEvent)]
_) =
case Time
-> DiffTime
-> [(Time, DiffTime, TestTraceEvent)]
-> Either (Time, DiffTime) [(Time, DiffTime, TestTraceEvent)]
busy Time
busyStartTime DiffTime
initialEventCredits [(Time, DiffTime, TestTraceEvent)]
trace of
Right [(Time, DiffTime, TestTraceEvent)]
trace' -> [(Time, DiffTime, TestTraceEvent)]
-> Maybe (Time, Time, DiffTime, [(Time, TestTraceEvent)])
idle [(Time, DiffTime, TestTraceEvent)]
trace'
Left (Time
busyEndTime, DiffTime
credits) ->
(Time, Time, DiffTime, [(Time, TestTraceEvent)])
-> Maybe (Time, Time, DiffTime, [(Time, TestTraceEvent)])
forall a. a -> Maybe a
Just (Time
busyStartTime, Time
busyEndTime, DiffTime
credits, [(Time, TestTraceEvent)]
trace')
where
trace' :: [(Time, TestTraceEvent)]
trace' = [ (Time
t, TestTraceEvent
e)
| (Time
t,DiffTime
_dt, TestTraceEvent
e) <-
((Time, DiffTime, TestTraceEvent) -> Bool)
-> [(Time, DiffTime, TestTraceEvent)]
-> [(Time, DiffTime, TestTraceEvent)]
forall a. (a -> Bool) -> [a] -> [a]
takeWhile (\(Time
t,DiffTime
_,TestTraceEvent
_) -> Time
t Time -> Time -> Bool
forall a. Ord a => a -> a -> Bool
<= Time
busyEndTime) [(Time, DiffTime, TestTraceEvent)]
trace
, case TestTraceEvent
e of
GovernorDebug{} -> Bool
False
TestTraceEvent
_ -> Bool
True
]
busy :: Time -> DiffTime -> [(Time, DiffTime, TestTraceEvent)]
-> Either (Time, DiffTime) [(Time, DiffTime, TestTraceEvent)]
busy :: Time
-> DiffTime
-> [(Time, DiffTime, TestTraceEvent)]
-> Either (Time, DiffTime) [(Time, DiffTime, TestTraceEvent)]
busy !Time
busyStartTime !DiffTime
credits ((Time
busyEndTime, DiffTime
_dt, GovernorEvent{}) : [(Time, DiffTime, TestTraceEvent)]
trace')
| DiffTime
busySpanLength DiffTime -> DiffTime -> Bool
forall a. Ord a => a -> a -> Bool
> DiffTime -> [(Time, DiffTime, TestTraceEvent)] -> DiffTime
forall {t} {b}. Num t => t -> [(Time, b, TestTraceEvent)] -> t
endCredits DiffTime
credits [(Time, DiffTime, TestTraceEvent)]
trace'=
(Time, DiffTime)
-> Either (Time, DiffTime) [(Time, DiffTime, TestTraceEvent)]
forall a b. a -> Either a b
Left (Time
busyEndTime, DiffTime -> [(Time, DiffTime, TestTraceEvent)] -> DiffTime
forall {t} {b}. Num t => t -> [(Time, b, TestTraceEvent)] -> t
endCredits DiffTime
credits [(Time, DiffTime, TestTraceEvent)]
trace')
where
busySpanLength :: DiffTime
busySpanLength = Time -> Time -> DiffTime
diffTime Time
busyEndTime Time
busyStartTime
endCredits :: t -> [(Time, b, TestTraceEvent)] -> t
endCredits !t
c [] = t
c
endCredits !t
c ((Time
t, b
_, MockEnvEvent TraceMockEnv
e) : [(Time, b, TestTraceEvent)]
tr) | Time
t Time -> Time -> Bool
forall a. Eq a => a -> a -> Bool
== Time
busyEndTime =
t -> [(Time, b, TestTraceEvent)] -> t
endCredits (t
c t -> t -> t
forall a. Num a => a -> a -> a
+ Int -> t
forall a b. (Integral a, Num b) => a -> b
fromIntegral (TraceMockEnv -> Int
envEventCredits TraceMockEnv
e)) [(Time, b, TestTraceEvent)]
tr
endCredits !t
c ((Time
t, b
_, TestTraceEvent
_) : [(Time, b, TestTraceEvent)]
tr) | Time
t Time -> Time -> Bool
forall a. Eq a => a -> a -> Bool
== Time
busyEndTime =
t -> [(Time, b, TestTraceEvent)] -> t
endCredits t
c [(Time, b, TestTraceEvent)]
tr
endCredits !t
c [(Time, b, TestTraceEvent)]
_ = t
c
busy !Time
_busyStartTime !DiffTime
_credits ((Time
_t, DiffTime
dt, TestTraceEvent
_event) : [(Time, DiffTime, TestTraceEvent)]
trace')
| DiffTime
dt DiffTime -> DiffTime -> Bool
forall a. Ord a => a -> a -> Bool
> DiffTime
sameSpanThreshold = [(Time, DiffTime, TestTraceEvent)]
-> Either (Time, DiffTime) [(Time, DiffTime, TestTraceEvent)]
forall a b. b -> Either a b
Right [(Time, DiffTime, TestTraceEvent)]
trace'
busy !Time
busyStartTime !DiffTime
credits ((Time
_, DiffTime
_, MockEnvEvent TraceMockEnv
e) : [(Time, DiffTime, TestTraceEvent)]
trace') =
Time
-> DiffTime
-> [(Time, DiffTime, TestTraceEvent)]
-> Either (Time, DiffTime) [(Time, DiffTime, TestTraceEvent)]
busy Time
busyStartTime (DiffTime
credits DiffTime -> DiffTime -> DiffTime
forall a. Num a => a -> a -> a
+ Int -> DiffTime
forall a b. (Integral a, Num b) => a -> b
fromIntegral (TraceMockEnv -> Int
envEventCredits TraceMockEnv
e)) [(Time, DiffTime, TestTraceEvent)]
trace'
busy !Time
busyStartTime !DiffTime
credits ((Time, DiffTime, TestTraceEvent)
_ : [(Time, DiffTime, TestTraceEvent)]
trace') =
Time
-> DiffTime
-> [(Time, DiffTime, TestTraceEvent)]
-> Either (Time, DiffTime) [(Time, DiffTime, TestTraceEvent)]
busy Time
busyStartTime DiffTime
credits [(Time, DiffTime, TestTraceEvent)]
trace'
busy !Time
_ !DiffTime
_ [] = [(Time, DiffTime, TestTraceEvent)]
-> Either (Time, DiffTime) [(Time, DiffTime, TestTraceEvent)]
forall a b. b -> Either a b
Right []
envEventCredits :: TraceMockEnv -> Int
envEventCredits :: TraceMockEnv -> Int
envEventCredits (TraceEnvAddPeers PeerGraph
peerGraph) = Int
80 Int -> Int -> Int
forall a. Num a => a -> a -> a
* Int
5 Int -> Int -> Int
forall a. Num a => a -> a -> a
+ [(PeerAddr, [PeerAddr], PeerInfo)] -> Int
forall a. [a] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length [(PeerAddr, [PeerAddr], PeerInfo)]
adjacency Int -> Int -> Int
forall a. Num a => a -> a -> a
* Int
5
where
PeerGraph [(PeerAddr, [PeerAddr], PeerInfo)]
adjacency = PeerGraph
peerGraph
envEventCredits (TraceEnvSetLocalRoots LocalRootPeers PeerAddr
peers) = LocalRootPeers PeerAddr -> Int
forall peeraddr. LocalRootPeers peeraddr -> Int
LocalRootPeers.size LocalRootPeers PeerAddr
peers
envEventCredits (TraceEnvSetPublicRoots PublicRootPeers PeerAddr
peers) = PublicRootPeers PeerAddr -> Int
forall peeraddr. PublicRootPeers peeraddr -> Int
PublicRootPeers.size PublicRootPeers PeerAddr
peers
envEventCredits TraceMockEnv
TraceEnvRequestPublicRootPeers = Int
0
envEventCredits TraceMockEnv
TraceEnvRequestBigLedgerPeers = Int
0
envEventCredits TraceMockEnv
TraceEnvPublicRootTTL = Int
60
envEventCredits TraceMockEnv
TraceEnvBigLedgerPeersTTL = Int
60
envEventCredits (TraceEnvSetTargets PeerSelectionTargets {
targetNumberOfRootPeers :: PeerSelectionTargets -> Int
targetNumberOfRootPeers = Int
_,
Int
targetNumberOfKnownPeers :: PeerSelectionTargets -> Int
targetNumberOfKnownPeers :: Int
targetNumberOfKnownPeers,
Int
targetNumberOfEstablishedPeers :: Int
targetNumberOfEstablishedPeers :: PeerSelectionTargets -> Int
targetNumberOfEstablishedPeers,
Int
targetNumberOfActivePeers :: Int
targetNumberOfActivePeers :: PeerSelectionTargets -> Int
targetNumberOfActivePeers
}) = Int
80
Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
10 Int -> Int -> Int
forall a. Num a => a -> a -> a
* (Int
targetNumberOfKnownPeers
Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
targetNumberOfEstablishedPeers
Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
targetNumberOfActivePeers)
envEventCredits (TraceEnvGenesisLsjAndTargets (LedgerStateJudgement
_, PeerSelectionTargets
targets))
= Int
80
Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
10 Int -> Int -> Int
forall a. Num a => a -> a -> a
* (Int
targetNumberOfKnownPeers
Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
targetNumberOfEstablishedPeers
Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
targetNumberOfActivePeers)
where
PeerSelectionTargets {
targetNumberOfRootPeers :: PeerSelectionTargets -> Int
targetNumberOfRootPeers = Int
_,
Int
targetNumberOfKnownPeers :: PeerSelectionTargets -> Int
targetNumberOfKnownPeers :: Int
targetNumberOfKnownPeers,
Int
targetNumberOfEstablishedPeers :: PeerSelectionTargets -> Int
targetNumberOfEstablishedPeers :: Int
targetNumberOfEstablishedPeers,
Int
targetNumberOfActivePeers :: PeerSelectionTargets -> Int
targetNumberOfActivePeers :: Int
targetNumberOfActivePeers } = PeerSelectionTargets
targets
envEventCredits (TraceEnvPeersDemote AsyncDemotion
Noop PeerAddr
_) = Int
10
envEventCredits (TraceEnvPeersDemote AsyncDemotion
ToWarm PeerAddr
_) = Int
30
envEventCredits (TraceEnvPeersDemote AsyncDemotion
ToCooling PeerAddr
_) = Int
30
envEventCredits (TraceEnvPeersDemote AsyncDemotion
ToCold PeerAddr
_) = Int
30
envEventCredits TraceEnvPeersStatus{} = Int
0
envEventCredits TraceEnvPeerShareResult{} = Int
10
envEventCredits TraceEnvRootsResult{} = Int
10
envEventCredits TraceEnvBigLedgerPeersResult{} = Int
10
envEventCredits TraceEnvPeerShareRequest{} = Int
0
envEventCredits TraceEnvPeerShareTTL {} = Int
0
envEventCredits TraceEnvEstablishConn {} = Int
0
envEventCredits TraceEnvActivatePeer {} = Int
0
envEventCredits TraceEnvDeactivatePeer {} = Int
0
envEventCredits TraceEnvCloseConn {} = Int
0
envEventCredits TraceEnvUseLedgerPeers {} = Int
30
envEventCredits TraceEnvSetLedgerStateJudgement {} = Int
30
envEventCredits TraceEnvSetUseBootstrapPeers {} = Int
30
prop_governor_events_coverage :: GovernorMockEnvironment -> Property
prop_governor_events_coverage :: GovernorMockEnvironment -> Property
prop_governor_events_coverage GovernorMockEnvironment
env =
let trace :: [(Time, TestTraceEvent)]
trace = Events TestTraceEvent -> [(Time, TestTraceEvent)]
forall a. Events a -> [(Time, a)]
Signal.eventsToList
(Events TestTraceEvent -> [(Time, TestTraceEvent)])
-> (GovernorMockEnvironment -> Events TestTraceEvent)
-> GovernorMockEnvironment
-> [(Time, TestTraceEvent)]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Time -> [(Time, TestTraceEvent)] -> Events TestTraceEvent
forall a. Time -> [(Time, a)] -> Events a
Signal.eventsFromListUpToTime (DiffTime -> Time
Time (DiffTime
10 DiffTime -> DiffTime -> DiffTime
forall a. Num a => a -> a -> a
* DiffTime
60 DiffTime -> DiffTime -> DiffTime
forall a. Num a => a -> a -> a
* DiffTime
60))
([(Time, TestTraceEvent)] -> Events TestTraceEvent)
-> (GovernorMockEnvironment -> [(Time, TestTraceEvent)])
-> GovernorMockEnvironment
-> Events TestTraceEvent
forall b c a. (b -> c) -> (a -> b) -> a -> c
. SimTrace Void -> [(Time, TestTraceEvent)]
forall a. SimTrace a -> [(Time, TestTraceEvent)]
selectPeerSelectionTraceEvents
(SimTrace Void -> [(Time, TestTraceEvent)])
-> (GovernorMockEnvironment -> SimTrace Void)
-> GovernorMockEnvironment
-> [(Time, TestTraceEvent)]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. GovernorMockEnvironment -> SimTrace Void
runGovernorInMockEnvironment
(GovernorMockEnvironment -> [(Time, TestTraceEvent)])
-> GovernorMockEnvironment -> [(Time, TestTraceEvent)]
forall a b. (a -> b) -> a -> b
$ GovernorMockEnvironment
env
printLength :: a -> TestName
printLength a
x
| a
x a -> a -> Bool
forall a. Ord a => a -> a -> Bool
< a
10 = TestName
"# events < 10"
| a
x a -> a -> Bool
forall a. Ord a => a -> a -> Bool
>= a
10 Bool -> Bool -> Bool
&& a
x a -> a -> Bool
forall a. Ord a => a -> a -> Bool
< a
100 = TestName
"# events >= 10 && < 100"
| a
x a -> a -> Bool
forall a. Ord a => a -> a -> Bool
>= a
100 Bool -> Bool -> Bool
&& a
x a -> a -> Bool
forall a. Ord a => a -> a -> Bool
< a
1000 = TestName
"# events >= 100 && < 1000"
| a
x a -> a -> Bool
forall a. Ord a => a -> a -> Bool
>= a
1000 Bool -> Bool -> Bool
&& a
x a -> a -> Bool
forall a. Ord a => a -> a -> Bool
< a
10000 = TestName
"# events >= 1000 && < 10000"
| a
x a -> a -> Bool
forall a. Ord a => a -> a -> Bool
>= a
10000 Bool -> Bool -> Bool
&& a
x a -> a -> Bool
forall a. Ord a => a -> a -> Bool
< a
100000 = TestName
"# events >= 10000 && < 100000"
| a
x a -> a -> Bool
forall a. Ord a => a -> a -> Bool
>= a
100000 Bool -> Bool -> Bool
&& a
x a -> a -> Bool
forall a. Ord a => a -> a -> Bool
< a
1000000 = TestName
"# events >= 100000 && < 1000000"
| Bool
otherwise = TestName
"# events >= 1000000"
in TestName -> [TestName] -> Bool -> Property
forall prop.
Testable prop =>
TestName -> [TestName] -> prop -> Property
tabulate TestName
"# events" [Int -> TestName
forall {a}. (Ord a, Num a) => a -> TestName
printLength ([(Time, TestTraceEvent)] -> Int
forall a. [a] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length [(Time, TestTraceEvent)]
trace)]
Bool
True
prop_governor_trace_coverage :: GovernorMockEnvironment -> Property
prop_governor_trace_coverage :: GovernorMockEnvironment -> Property
prop_governor_trace_coverage GovernorMockEnvironment
env =
let trace :: [(Time, TestTraceEvent)]
trace = Int -> [(Time, TestTraceEvent)] -> [(Time, TestTraceEvent)]
forall a. Int -> [a] -> [a]
take Int
5000 ([(Time, TestTraceEvent)] -> [(Time, TestTraceEvent)])
-> (SimTrace Void -> [(Time, TestTraceEvent)])
-> SimTrace Void
-> [(Time, TestTraceEvent)]
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
SimTrace Void -> [(Time, TestTraceEvent)]
forall a. SimTrace a -> [(Time, TestTraceEvent)]
selectPeerSelectionTraceEvents (SimTrace Void -> [(Time, TestTraceEvent)])
-> SimTrace Void -> [(Time, TestTraceEvent)]
forall a b. (a -> b) -> a -> b
$
GovernorMockEnvironment -> SimTrace Void
runGovernorInMockEnvironment GovernorMockEnvironment
env
traceNumsSeen :: Set Int
traceNumsSeen = [(Time, TestTraceEvent)] -> Set Int
collectTraces [(Time, TestTraceEvent)]
trace
traceNamesSeen :: Map Int TestName
traceNamesSeen = Map Int TestName
allTraceNames Map Int TestName -> Set Int -> Map Int TestName
forall k a. Ord k => Map k a -> Set k -> Map k a
`Map.restrictKeys` Set Int
traceNumsSeen
in TestName -> [(TestName, Double)] -> Property -> Property
forall prop.
Testable prop =>
TestName -> [(TestName, Double)] -> prop -> Property
coverTable TestName
"trace events" [ (TestName
n, Double
1) | TestName
n <- Map Int TestName -> [TestName]
forall k a. Map k a -> [a]
Map.elems Map Int TestName
allTraceNames ] (Property -> Property) -> Property -> Property
forall a b. (a -> b) -> a -> b
$
TestName -> [TestName] -> Bool -> Property
forall prop.
Testable prop =>
TestName -> [TestName] -> prop -> Property
tabulate TestName
"trace events" (Map Int TestName -> [TestName]
forall k a. Map k a -> [a]
Map.elems Map Int TestName
traceNamesSeen)
Bool
True
collectTraces :: [(Time, TestTraceEvent)] -> Set Int
collectTraces :: [(Time, TestTraceEvent)] -> Set Int
collectTraces [(Time, TestTraceEvent)]
trace =
[Int] -> Set Int
forall a. Ord a => [a] -> Set a
Set.fromList [ TracePeerSelection PeerAddr -> Int
forall peeraddr. TracePeerSelection peeraddr -> Int
traceNum TracePeerSelection PeerAddr
e | (Time
_, GovernorEvent TracePeerSelection PeerAddr
e) <- [(Time, TestTraceEvent)]
trace ]
traceNum :: TracePeerSelection peeraddr -> Int
traceNum :: forall peeraddr. TracePeerSelection peeraddr -> Int
traceNum TraceLocalRootPeersChanged{} = Int
00
traceNum TraceTargetsChanged{} = Int
01
traceNum TracePublicRootsRequest{} = Int
02
traceNum TracePublicRootsResults{} = Int
03
traceNum TracePublicRootsFailure{} = Int
04
traceNum TracePeerShareRequests{} = Int
05
traceNum TracePeerShareResults{} = Int
06
traceNum TracePeerShareResultsFiltered{} = Int
07
traceNum TraceForgetColdPeers{} = Int
08
traceNum TracePromoteColdPeers{} = Int
09
traceNum TracePromoteColdLocalPeers{} = Int
10
traceNum TracePromoteColdFailed{} = Int
11
traceNum TracePromoteColdDone{} = Int
12
traceNum TracePromoteWarmPeers{} = Int
13
traceNum TracePromoteWarmLocalPeers{} = Int
14
traceNum TracePromoteWarmFailed{} = Int
15
traceNum TracePromoteWarmDone{} = Int
16
traceNum TraceDemoteWarmPeers{} = Int
17
traceNum TraceDemoteWarmFailed{} = Int
18
traceNum TraceDemoteWarmDone{} = Int
19
traceNum TraceDemoteHotPeers{} = Int
20
traceNum TraceDemoteLocalHotPeers{} = Int
21
traceNum TraceDemoteHotFailed{} = Int
22
traceNum TraceDemoteHotDone{} = Int
23
traceNum TraceDemoteAsynchronous{} = Int
24
traceNum TraceGovernorWakeup{} = Int
25
traceNum TraceChurnWait{} = Int
26
traceNum TraceChurnMode{} = Int
27
traceNum TracePromoteWarmAborted{} = Int
28
traceNum TraceDemoteLocalAsynchronous{} = Int
29
traceNum TraceBigLedgerPeersRequest{} = Int
30
traceNum TraceBigLedgerPeersResults{} = Int
31
traceNum TraceBigLedgerPeersFailure{} = Int
32
traceNum TraceForgetBigLedgerPeers{} = Int
33
traceNum TracePromoteColdBigLedgerPeers{} = Int
34
traceNum TracePromoteColdBigLedgerPeerFailed{} = Int
35
traceNum TracePromoteColdBigLedgerPeerDone{} = Int
36
traceNum TracePromoteWarmBigLedgerPeers{} = Int
37
traceNum TracePromoteWarmBigLedgerPeerFailed{} = Int
38
traceNum TracePromoteWarmBigLedgerPeerDone{} = Int
39
traceNum TracePromoteWarmBigLedgerPeerAborted{} = Int
40
traceNum TraceDemoteWarmBigLedgerPeers{} = Int
41
traceNum TraceDemoteWarmBigLedgerPeerFailed{} = Int
42
traceNum TraceDemoteWarmBigLedgerPeerDone{} = Int
43
traceNum TraceDemoteHotBigLedgerPeers{} = Int
44
traceNum TraceDemoteHotBigLedgerPeerFailed{} = Int
45
traceNum TraceDemoteHotBigLedgerPeerDone{} = Int
46
traceNum TracePickInboundPeers{} = Int
47
traceNum TraceDemoteBigLedgerPeersAsynchronous{} = Int
48
traceNum TraceLedgerStateJudgementChanged{} = Int
49
traceNum TraceOnlyBootstrapPeers{} = Int
50
traceNum TracePeerSelection peeraddr
TraceBootstrapPeersFlagChangedWhilstInSensitiveState = Int
51
traceNum TraceUseBootstrapPeersChanged {} = Int
52
traceNum TraceOutboundGovernorCriticalFailure {} = Int
53
traceNum TraceDebugState {} = Int
54
traceNum TraceChurnAction {} = Int
55
traceNum TraceChurnTimeout {} = Int
56
traceNum TraceVerifyPeerSnapshot {} = Int
57
allTraceNames :: Map Int String
allTraceNames :: Map Int TestName
allTraceNames =
[(Int, TestName)] -> Map Int TestName
forall k a. Ord k => [(k, a)] -> Map k a
Map.fromList
[ (Int
00, TestName
"TraceLocalRootPeersChanged")
, (Int
01, TestName
"TraceTargetsChanged")
, (Int
02, TestName
"TracePublicRootsRequest")
, (Int
03, TestName
"TracePublicRootsResults")
, (Int
04, TestName
"TracePublicRootsFailure")
, (Int
05, TestName
"TracePeerShareRequests")
, (Int
06, TestName
"TracePeerShareResults")
, (Int
07, TestName
"TracePeerShareResultsFiltered")
, (Int
08, TestName
"TraceForgetColdPeers")
, (Int
09, TestName
"TracePromoteColdPeers")
, (Int
10, TestName
"TracePromoteColdLocalPeers")
, (Int
11, TestName
"TracePromoteColdFailed")
, (Int
12, TestName
"TracePromoteColdDone")
, (Int
13, TestName
"TracePromoteWarmPeers")
, (Int
14, TestName
"TracePromoteWarmLocalPeers")
, (Int
15, TestName
"TracePromoteWarmFailed")
, (Int
16, TestName
"TracePromoteWarmDone")
, (Int
17, TestName
"TraceDemoteWarmPeers")
, (Int
18, TestName
"TraceDemoteWarmFailed")
, (Int
19, TestName
"TraceDemoteWarmDone")
, (Int
20, TestName
"TraceDemoteHotPeers")
, (Int
21, TestName
"TraceDemoteLocalHotPeers")
, (Int
22, TestName
"TraceDemoteHotFailed")
, (Int
23, TestName
"TraceDemoteHotDone")
, (Int
24, TestName
"TraceDemoteAsynchronous")
, (Int
25, TestName
"TraceGovernorWakeup")
, (Int
26, TestName
"TraceChurnWait")
, (Int
27, TestName
"TraceChurnMode")
, (Int
28, TestName
"TracePromoteWarmAborted")
, (Int
29, TestName
"TraceDemoteAsynchronous")
, (Int
30, TestName
"TraceBigLedgerPeersRequest")
, (Int
31, TestName
"TraceBigLedgerPeersResults")
, (Int
32, TestName
"TraceBigLedgerPeersFailure")
, (Int
33, TestName
"TraceForgetBigLedgerPeers")
, (Int
34, TestName
"TracePromoteColdBigLedgerPeers")
, (Int
35, TestName
"TracePromoteColdBigLedgerPeerFailed")
, (Int
36, TestName
"TracePromoteColdBigLedgerPeerDone")
, (Int
37, TestName
"TracePromoteWarmBigLedgerPeers")
, (Int
38, TestName
"TracePromoteWarmBigLedgerPeerFailed")
, (Int
39, TestName
"TracePromoteWarmBigLedgerPeerDone")
, (Int
40, TestName
"TracePromoteWarmBigLedgerPeerAborted")
, (Int
41, TestName
"TraceDemoteWarmBigLedgerPeers")
, (Int
42, TestName
"TraceDemoteWarmBigLedgerPeerFailed")
, (Int
43, TestName
"TraceDemoteWarmBigLedgerPeerDone")
, (Int
44, TestName
"TraceDemoteHotBigLedgerPeers")
, (Int
45, TestName
"TraceDemoteHotBigLedgerPeerFailed")
, (Int
46, TestName
"TraceDemoteHotBigLedgerPeerDone")
, (Int
47, TestName
"TracePickInboundPeers")
, (Int
48, TestName
"TraceDemoteBigLedgerPeersAsynchronous")
, (Int
49, TestName
"TraceLedgerStateJudgementChanged")
, (Int
50, TestName
"TraceOnlyBootstrapPeers")
, (Int
51, TestName
"TraceBootstrapPeersFlagChangedWhilstInSensitiveState")
, (Int
52, TestName
"TraceUseBootstrapPeersChanged")
, (Int
53, TestName
"TraceOutboundGovernorCriticalFailure")
, (Int
54, TestName
"TraceDebugState")
, (Int
55, TestName
"TraceChurnAction")
, (Int
56, TestName
"TraceChurnTimeout")
, (Int
57, TestName
"TraceVerifyPeerSnapshot")
]
prop_governor_peershare_1hr :: GovernorMockEnvironment -> Property
prop_governor_peershare_1hr :: GovernorMockEnvironment -> Property
prop_governor_peershare_1hr env :: GovernorMockEnvironment
env@GovernorMockEnvironment {
PeerGraph
peerGraph :: PeerGraph
peerGraph :: GovernorMockEnvironment -> PeerGraph
peerGraph,
LocalRootPeers PeerAddr
localRootPeers :: GovernorMockEnvironment -> LocalRootPeers PeerAddr
localRootPeers :: LocalRootPeers PeerAddr
localRootPeers,
PublicRootPeers PeerAddr
publicRootPeers :: GovernorMockEnvironment -> PublicRootPeers PeerAddr
publicRootPeers :: PublicRootPeers PeerAddr
publicRootPeers,
TimedScript ConsensusModePeerTargets
targets :: GovernorMockEnvironment -> TimedScript ConsensusModePeerTargets
targets :: TimedScript ConsensusModePeerTargets
targets
} =
let ioSimTrace :: SimTrace Void
ioSimTrace = GovernorMockEnvironment -> SimTrace Void
runGovernorInMockEnvironment GovernorMockEnvironment
env {
targets = singletonScript (targets', NoDelay)
}
trace :: [(Time, TestTraceEvent)]
trace = SimTrace Void -> [(Time, TestTraceEvent)]
forall a. SimTrace a -> [(Time, TestTraceEvent)]
selectPeerSelectionTraceEvents SimTrace Void
ioSimTrace
Just Set PeerAddr
found = [(Time, TestTraceEvent)] -> Maybe (Set PeerAddr)
knownPeersAfter1Hour [(Time, TestTraceEvent)]
trace
reachable :: Set PeerAddr
reachable = PeerGraph -> Set PeerAddr -> Set PeerAddr
peerShareReachablePeers PeerGraph
peerGraph
(LocalRootPeers PeerAddr -> Set PeerAddr
forall peeraddr. LocalRootPeers peeraddr -> Set peeraddr
LocalRootPeers.keysSet LocalRootPeers PeerAddr
localRootPeers Set PeerAddr -> Set PeerAddr -> Set PeerAddr
forall a. Semigroup a => a -> a -> a
<> PublicRootPeers PeerAddr -> Set PeerAddr
forall peeraddr.
Ord peeraddr =>
PublicRootPeers peeraddr -> Set peeraddr
PublicRootPeers.toSet PublicRootPeers PeerAddr
publicRootPeers)
in TestName -> Property -> Property
forall prop. Testable prop => TestName -> prop -> Property
counterexample ( TestName -> [TestName] -> TestName
forall a. [a] -> [[a]] -> [a]
intercalate TestName
"\n"
([TestName] -> TestName)
-> (SimTrace Void -> [TestName]) -> SimTrace Void -> TestName
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (SimEvent -> TestName) -> [SimEvent] -> [TestName]
forall a b. (a -> b) -> [a] -> [b]
map (Int -> Int -> Int -> SimEvent -> TestName
ppSimEvent Int
20 Int
20 Int
20)
([SimEvent] -> [TestName])
-> (SimTrace Void -> [SimEvent]) -> SimTrace Void -> [TestName]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (SimEvent -> Bool) -> [SimEvent] -> [SimEvent]
forall a. (a -> Bool) -> [a] -> [a]
takeWhile (\SimEvent
e -> SimEvent -> Time
seTime SimEvent
e Time -> Time -> Bool
forall a. Ord a => a -> a -> Bool
<= DiffTime -> Time
Time (DiffTime
60DiffTime -> DiffTime -> DiffTime
forall a. Num a => a -> a -> a
*DiffTime
60))
([SimEvent] -> [SimEvent])
-> (SimTrace Void -> [SimEvent]) -> SimTrace Void -> [SimEvent]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. SimTrace Void -> [SimEvent]
forall a b. Trace a b -> [b]
Trace.toList
(SimTrace Void -> TestName) -> SimTrace Void -> TestName
forall a b. (a -> b) -> a -> b
$ SimTrace Void
ioSimTrace) (Property -> Property) -> Property -> Property
forall a b. (a -> b) -> a -> b
$
Set PeerAddr -> Set PeerAddr -> Property
forall {a}. (Show a, Ord a) => Set a -> Set a -> Property
subsetProperty Set PeerAddr
found Set PeerAddr
reachable
where
targets' :: ConsensusModePeerTargets
targets' :: ConsensusModePeerTargets
targets' = (ConsensusModePeerTargets, ScriptDelay) -> ConsensusModePeerTargets
forall a b. (a, b) -> a
fst (TimedScript ConsensusModePeerTargets
-> (ConsensusModePeerTargets, ScriptDelay)
forall a. Script a -> a
scriptHead TimedScript ConsensusModePeerTargets
targets)
knownPeersAfter1Hour :: [(Time, TestTraceEvent)] -> Maybe (Set PeerAddr)
knownPeersAfter1Hour :: [(Time, TestTraceEvent)] -> Maybe (Set PeerAddr)
knownPeersAfter1Hour [(Time, TestTraceEvent)]
trace =
[Set PeerAddr] -> Maybe (Set PeerAddr)
forall a. [a] -> Maybe a
listToMaybe
[ KnownPeers PeerAddr -> Set PeerAddr
forall peeraddr. KnownPeers peeraddr -> Set peeraddr
KnownPeers.toSet (PeerSelectionState PeerAddr peerconn -> KnownPeers PeerAddr
forall peeraddr peerconn.
PeerSelectionState peeraddr peerconn -> KnownPeers peeraddr
Governor.knownPeers PeerSelectionState PeerAddr peerconn
st)
| (Time
_, GovernorDebug (TraceGovernorState Time
_ Maybe DiffTime
_ PeerSelectionState PeerAddr peerconn
st))
<- [(Time, TestTraceEvent)] -> [(Time, TestTraceEvent)]
forall a. [a] -> [a]
reverse (DiffTime -> [(Time, TestTraceEvent)] -> [(Time, TestTraceEvent)]
forall a. DiffTime -> [(Time, a)] -> [(Time, a)]
takeFirstNHours DiffTime
1 [(Time, TestTraceEvent)]
trace)
]
subsetProperty :: Set a -> Set a -> Property
subsetProperty Set a
found Set a
reachable =
TestName -> Property -> Property
forall prop. Testable prop => TestName -> prop -> Property
counterexample (TestName
"reachable: " TestName -> TestName -> TestName
forall a. [a] -> [a] -> [a]
++ Set a -> TestName
forall a. Show a => a -> TestName
show Set a
reachable TestName -> TestName -> TestName
forall a. [a] -> [a] -> [a]
++ TestName
"\n" TestName -> TestName -> TestName
forall a. [a] -> [a] -> [a]
++
TestName
"found: " TestName -> TestName -> TestName
forall a. [a] -> [a] -> [a]
++ Set a -> TestName
forall a. Show a => a -> TestName
show Set a
found) (Property -> Property) -> Property -> Property
forall a b. (a -> b) -> a -> b
$
Bool -> Property
forall prop. Testable prop => prop -> Property
property (Set a
found Set a -> Set a -> Bool
forall a. Ord a => Set a -> Set a -> Bool
`Set.isSubsetOf` Set a
reachable)
prop_governor_connstatus :: GovernorMockEnvironment -> Property
prop_governor_connstatus :: GovernorMockEnvironment -> Property
prop_governor_connstatus GovernorMockEnvironment
env =
Maybe (SimTrace Void) -> SimTrace Void -> Property
forall a. Maybe (SimTrace a) -> SimTrace a -> Property
check_governor_connstatus Maybe (SimTrace Void)
forall a. Maybe a
Nothing (GovernorMockEnvironment -> SimTrace Void
runGovernorInMockEnvironment GovernorMockEnvironment
env)
prop_explore_governor_connstatus :: GovernorMockEnvironment -> Property
prop_explore_governor_connstatus :: GovernorMockEnvironment -> Property
prop_explore_governor_connstatus = ExplorationSpec -> GovernorMockEnvironment -> Property
prop'_explore_governor_connstatus ExplorationSpec
forall a. a -> a
id
prop'_explore_governor_connstatus :: ExplorationSpec -> GovernorMockEnvironment -> Property
prop'_explore_governor_connstatus :: ExplorationSpec -> GovernorMockEnvironment -> Property
prop'_explore_governor_connstatus ExplorationSpec
opts GovernorMockEnvironment
env =
IO () -> Property -> Property
forall prop. Testable prop => IO () -> prop -> Property
whenFail (GovernorMockEnvironment -> IO ()
forall (m :: * -> *) a. (MonadIO m, Show a) => a -> m ()
pPrint GovernorMockEnvironment
env) (Property -> Property) -> Property -> Property
forall a b. (a -> b) -> a -> b
$
ExplorationSpec
-> GovernorMockEnvironment
-> (Maybe (SimTrace Void) -> SimTrace Void -> Property)
-> Property
forall test.
Testable test =>
ExplorationSpec
-> GovernorMockEnvironment
-> (Maybe (SimTrace Void) -> SimTrace Void -> test)
-> Property
exploreGovernorInMockEnvironment ExplorationSpec
opts GovernorMockEnvironment
env Maybe (SimTrace Void) -> SimTrace Void -> Property
forall a. Maybe (SimTrace a) -> SimTrace a -> Property
check_governor_connstatus
check_governor_connstatus :: Maybe (SimTrace a) -> SimTrace a -> Property
check_governor_connstatus :: forall a. Maybe (SimTrace a) -> SimTrace a -> Property
check_governor_connstatus Maybe (SimTrace a)
_ SimTrace a
trace0 =
let trace :: [(Time, TestTraceEvent)]
trace = DiffTime -> [(Time, TestTraceEvent)] -> [(Time, TestTraceEvent)]
forall a. DiffTime -> [(Time, a)] -> [(Time, a)]
takeFirstNHours DiffTime
1
([(Time, TestTraceEvent)] -> [(Time, TestTraceEvent)])
-> (SimTrace a -> [(Time, TestTraceEvent)])
-> SimTrace a
-> [(Time, TestTraceEvent)]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. SimTrace a -> [(Time, TestTraceEvent)]
forall a. SimTrace a -> [(Time, TestTraceEvent)]
selectPeerSelectionTraceEvents (SimTrace a -> [(Time, TestTraceEvent)])
-> SimTrace a -> [(Time, TestTraceEvent)]
forall a b. (a -> b) -> a -> b
$ SimTrace a
trace0
in
IO () -> Property -> Property
forall prop. Testable prop => IO () -> prop -> Property
whenFail (((Time, TestTraceEvent) -> IO ())
-> [(Time, TestTraceEvent)] -> IO ()
forall (t :: * -> *) (f :: * -> *) a b.
(Foldable t, Applicative f) =>
(a -> f b) -> t a -> f ()
traverse_ (Time, TestTraceEvent) -> IO ()
forall a. Show a => a -> IO ()
print [(Time, TestTraceEvent)]
trace) (Property -> Property) -> Property -> Property
forall a b. (a -> b) -> a -> b
$
[Property] -> Property
forall prop. Testable prop => [prop] -> Property
conjoin ([Property] -> Property) -> [Property] -> Property
forall a b. (a -> b) -> a -> b
$ ([(Time, TestTraceEvent)] -> Property)
-> [[(Time, TestTraceEvent)]] -> [Property]
forall a b. (a -> b) -> [a] -> [b]
map [(Time, TestTraceEvent)] -> Property
ok (((Time, TestTraceEvent) -> (Time, TestTraceEvent) -> Bool)
-> [(Time, TestTraceEvent)] -> [[(Time, TestTraceEvent)]]
forall a. (a -> a -> Bool) -> [a] -> [[a]]
groupBy (Time -> Time -> Bool
forall a. Eq a => a -> a -> Bool
(==) (Time -> Time -> Bool)
-> ((Time, TestTraceEvent) -> Time)
-> (Time, TestTraceEvent)
-> (Time, TestTraceEvent)
-> Bool
forall b c a. (b -> b -> c) -> (a -> b) -> a -> a -> c
`on` (Time, TestTraceEvent) -> Time
forall a b. (a, b) -> a
fst) [(Time, TestTraceEvent)]
trace)
where
ok :: [(Time, TestTraceEvent)] -> Property
ok :: [(Time, TestTraceEvent)] -> Property
ok [(Time, TestTraceEvent)]
trace =
TestName -> Property -> Property
forall prop. Testable prop => TestName -> prop -> Property
counterexample (TestName
"last few events:\n" TestName -> TestName -> TestName
forall a. [a] -> [a] -> [a]
++ ([TestName] -> TestName
unlines ([TestName] -> TestName)
-> ([(Time, TestTraceEvent)] -> [TestName])
-> [(Time, TestTraceEvent)]
-> TestName
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ((Time, TestTraceEvent) -> TestName)
-> [(Time, TestTraceEvent)] -> [TestName]
forall a b. (a -> b) -> [a] -> [b]
map (Time, TestTraceEvent) -> TestName
forall a. Show a => a -> TestName
show) [(Time, TestTraceEvent)]
trace) (Property -> Property) -> Property -> Property
forall a b. (a -> b) -> a -> b
$
case (Maybe (Map PeerAddr PeerStatus)
lastEnvStatus, Maybe (Map PeerAddr PeerStatus)
lastGovStatus) of
(Maybe (Map PeerAddr PeerStatus)
Nothing, Maybe (Map PeerAddr PeerStatus)
_) -> Bool -> Property
forall prop. Testable prop => prop -> Property
property Bool
True
(Just Map PeerAddr PeerStatus
envStatus, Just Map PeerAddr PeerStatus
govStatus) -> Map PeerAddr PeerStatus
envStatus Map PeerAddr PeerStatus -> Map PeerAddr PeerStatus -> Property
forall a. (Eq a, Show a) => a -> a -> Property
=== Map PeerAddr PeerStatus
govStatus
(Just Map PeerAddr PeerStatus
envStatus, Maybe (Map PeerAddr PeerStatus)
Nothing) -> Map PeerAddr PeerStatus
envStatus Map PeerAddr PeerStatus -> Map PeerAddr PeerStatus -> Property
forall a. (Eq a, Show a) => a -> a -> Property
=== Map PeerAddr PeerStatus
forall k a. Map k a
Map.empty
where
lastEnvStatus :: Maybe (Map PeerAddr PeerStatus)
lastEnvStatus =
[Map PeerAddr PeerStatus] -> Maybe (Map PeerAddr PeerStatus)
forall a. [a] -> Maybe a
listToMaybe
[ (PeerStatus -> Bool)
-> Map PeerAddr PeerStatus -> Map PeerAddr PeerStatus
forall a k. (a -> Bool) -> Map k a -> Map k a
Map.filter (Bool -> Bool
not (Bool -> Bool) -> (PeerStatus -> Bool) -> PeerStatus -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. PeerStatus -> Bool
isPeerCooling) Map PeerAddr PeerStatus
status
| (Time
_, MockEnvEvent (TraceEnvPeersStatus Map PeerAddr PeerStatus
status)) <- [(Time, TestTraceEvent)] -> [(Time, TestTraceEvent)]
forall a. [a] -> [a]
reverse [(Time, TestTraceEvent)]
trace ]
isPeerCooling :: PeerStatus -> Bool
isPeerCooling PeerStatus
PeerCooling = Bool
True
isPeerCooling PeerStatus
_ = Bool
False
lastGovStatus :: Maybe (Map PeerAddr PeerStatus)
lastGovStatus =
[Map PeerAddr PeerStatus] -> Maybe (Map PeerAddr PeerStatus)
forall a. [a] -> Maybe a
listToMaybe
[ PeerSelectionState PeerAddr peerconn -> Map PeerAddr PeerStatus
forall peeraddr peerconn.
Ord peeraddr =>
PeerSelectionState peeraddr peerconn -> Map peeraddr PeerStatus
Governor.establishedPeersStatus PeerSelectionState PeerAddr peerconn
st
| (Time
_, GovernorDebug (TraceGovernorState Time
_ Maybe DiffTime
_ PeerSelectionState PeerAddr peerconn
st)) <- [(Time, TestTraceEvent)] -> [(Time, TestTraceEvent)]
forall a. [a] -> [a]
reverse [(Time, TestTraceEvent)]
trace ]
prop_governor_target_root_below :: GovernorMockEnvironment -> Property
prop_governor_target_root_below :: GovernorMockEnvironment -> Property
prop_governor_target_root_below GovernorMockEnvironment
env =
let events :: Events TestTraceEvent
events = Time -> [(Time, TestTraceEvent)] -> Events TestTraceEvent
forall a. Time -> [(Time, a)] -> Events a
Signal.eventsFromListUpToTime (DiffTime -> Time
Time (DiffTime
10 DiffTime -> DiffTime -> DiffTime
forall a. Num a => a -> a -> a
* DiffTime
60 DiffTime -> DiffTime -> DiffTime
forall a. Num a => a -> a -> a
* DiffTime
60))
([(Time, TestTraceEvent)] -> Events TestTraceEvent)
-> (GovernorMockEnvironment -> [(Time, TestTraceEvent)])
-> GovernorMockEnvironment
-> Events TestTraceEvent
forall b c a. (b -> c) -> (a -> b) -> a -> c
. SimTrace Void -> [(Time, TestTraceEvent)]
forall a. SimTrace a -> [(Time, TestTraceEvent)]
selectPeerSelectionTraceEvents
(SimTrace Void -> [(Time, TestTraceEvent)])
-> (GovernorMockEnvironment -> SimTrace Void)
-> GovernorMockEnvironment
-> [(Time, TestTraceEvent)]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. GovernorMockEnvironment -> SimTrace Void
runGovernorInMockEnvironment
(GovernorMockEnvironment -> Events TestTraceEvent)
-> GovernorMockEnvironment -> Events TestTraceEvent
forall a b. (a -> b) -> a -> b
$ GovernorMockEnvironment
env
govTargetsSig :: Signal Int
govTargetsSig :: Signal Int
govTargetsSig =
(forall peerconn. PeerSelectionState PeerAddr peerconn -> Int)
-> ConsensusMode -> Events TestTraceEvent -> Signal Int
forall a.
Eq a =>
(forall peerconn. PeerSelectionState PeerAddr peerconn -> a)
-> ConsensusMode -> Events TestTraceEvent -> Signal a
selectGovState (PeerSelectionTargets -> Int
targetNumberOfRootPeers (PeerSelectionTargets -> Int)
-> (PeerSelectionState PeerAddr peerconn -> PeerSelectionTargets)
-> PeerSelectionState PeerAddr peerconn
-> Int
forall b c a. (b -> c) -> (a -> b) -> a -> c
. PeerSelectionState PeerAddr peerconn -> PeerSelectionTargets
forall peeraddr peerconn.
PeerSelectionState peeraddr peerconn -> PeerSelectionTargets
Governor.targets) (GovernorMockEnvironment -> ConsensusMode
consensusMode GovernorMockEnvironment
env) Events TestTraceEvent
events
govLocalRootPeersSig :: Signal (Set PeerAddr)
govLocalRootPeersSig :: Signal (Set PeerAddr)
govLocalRootPeersSig =
(forall peerconn.
PeerSelectionState PeerAddr peerconn -> Set PeerAddr)
-> ConsensusMode -> Events TestTraceEvent -> Signal (Set PeerAddr)
forall a.
Eq a =>
(forall peerconn. PeerSelectionState PeerAddr peerconn -> a)
-> ConsensusMode -> Events TestTraceEvent -> Signal a
selectGovState (LocalRootPeers PeerAddr -> Set PeerAddr
forall peeraddr. LocalRootPeers peeraddr -> Set peeraddr
LocalRootPeers.keysSet (LocalRootPeers PeerAddr -> Set PeerAddr)
-> (PeerSelectionState PeerAddr peerconn
-> LocalRootPeers PeerAddr)
-> PeerSelectionState PeerAddr peerconn
-> Set PeerAddr
forall b c a. (b -> c) -> (a -> b) -> a -> c
. PeerSelectionState PeerAddr peerconn -> LocalRootPeers PeerAddr
forall peeraddr peerconn.
PeerSelectionState peeraddr peerconn -> LocalRootPeers peeraddr
Governor.localRootPeers) (GovernorMockEnvironment -> ConsensusMode
consensusMode GovernorMockEnvironment
env) Events TestTraceEvent
events
govPublicRootPeersSig :: Signal (Set PeerAddr)
govPublicRootPeersSig :: Signal (Set PeerAddr)
govPublicRootPeersSig =
(forall peerconn.
PeerSelectionState PeerAddr peerconn -> Set PeerAddr)
-> ConsensusMode -> Events TestTraceEvent -> Signal (Set PeerAddr)
forall a.
Eq a =>
(forall peerconn. PeerSelectionState PeerAddr peerconn -> a)
-> ConsensusMode -> Events TestTraceEvent -> Signal a
selectGovState (PublicRootPeers PeerAddr -> Set PeerAddr
forall peeraddr.
Ord peeraddr =>
PublicRootPeers peeraddr -> Set peeraddr
PublicRootPeers.toSet (PublicRootPeers PeerAddr -> Set PeerAddr)
-> (PeerSelectionState PeerAddr peerconn
-> PublicRootPeers PeerAddr)
-> PeerSelectionState PeerAddr peerconn
-> Set PeerAddr
forall b c a. (b -> c) -> (a -> b) -> a -> c
. PeerSelectionState PeerAddr peerconn -> PublicRootPeers PeerAddr
forall peeraddr peerconn.
PeerSelectionState peeraddr peerconn -> PublicRootPeers peeraddr
Governor.publicRootPeers) (GovernorMockEnvironment -> ConsensusMode
consensusMode GovernorMockEnvironment
env) Events TestTraceEvent
events
govRootPeersSig :: Signal (Set PeerAddr)
govRootPeersSig :: Signal (Set PeerAddr)
govRootPeersSig = Set PeerAddr -> Set PeerAddr -> Set PeerAddr
forall a. Ord a => Set a -> Set a -> Set a
Set.union (Set PeerAddr -> Set PeerAddr -> Set PeerAddr)
-> Signal (Set PeerAddr) -> Signal (Set PeerAddr -> Set PeerAddr)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Signal (Set PeerAddr)
govLocalRootPeersSig Signal (Set PeerAddr -> Set PeerAddr)
-> Signal (Set PeerAddr) -> Signal (Set PeerAddr)
forall a b. Signal (a -> b) -> Signal a -> Signal b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Signal (Set PeerAddr)
govPublicRootPeersSig
requestOpportunity :: Int -> Set a -> Set a -> Set a
requestOpportunity Int
target Set a
public Set a
roots
| Set a -> Int
forall a. Set a -> Int
Set.size Set a
roots Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
>= Int
target
= Set a
forall a. Set a
Set.empty
| Bool
otherwise
= Set a
public Set a -> Set a -> Set a
forall a. Ord a => Set a -> Set a -> Set a
Set.\\ Set a
roots
requestOpportunities :: Signal (Set PeerAddr)
requestOpportunities :: Signal (Set PeerAddr)
requestOpportunities =
Int -> Set PeerAddr -> Set PeerAddr -> Set PeerAddr
forall {a}. Ord a => Int -> Set a -> Set a -> Set a
requestOpportunity
(Int -> Set PeerAddr -> Set PeerAddr -> Set PeerAddr)
-> Signal Int
-> Signal (Set PeerAddr -> Set PeerAddr -> Set PeerAddr)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Signal Int
govTargetsSig
Signal (Set PeerAddr -> Set PeerAddr -> Set PeerAddr)
-> Signal (Set PeerAddr) -> Signal (Set PeerAddr -> Set PeerAddr)
forall a b. Signal (a -> b) -> Signal a -> Signal b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Signal (Set PeerAddr)
govPublicRootPeersSig
Signal (Set PeerAddr -> Set PeerAddr)
-> Signal (Set PeerAddr) -> Signal (Set PeerAddr)
forall a b. Signal (a -> b) -> Signal a -> Signal b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Signal (Set PeerAddr)
govRootPeersSig
requestOpportunitiesIgnoredTooLong :: Signal (Set PeerAddr)
requestOpportunitiesIgnoredTooLong :: Signal (Set PeerAddr)
requestOpportunitiesIgnoredTooLong =
DiffTime
-> (Set PeerAddr -> Set PeerAddr)
-> Signal (Set PeerAddr)
-> Signal (Set PeerAddr)
forall a b.
Ord b =>
DiffTime -> (a -> Set b) -> Signal a -> Signal (Set b)
Signal.keyedTimeout
DiffTime
10
Set PeerAddr -> Set PeerAddr
forall a. a -> a
id
Signal (Set PeerAddr)
requestOpportunities
in TestName -> Property -> Property
forall prop. Testable prop => TestName -> prop -> Property
counterexample
(TestName
"\nSignal key: (target, local peers, public peers, root peers, " TestName -> TestName -> TestName
forall a. [a] -> [a] -> [a]
++
TestName
"opportunities, ignored too long)") (Property -> Property) -> Property -> Property
forall a b. (a -> b) -> a -> b
$
Int
-> ((Int, Set PeerAddr, Set PeerAddr, Set PeerAddr, Set PeerAddr,
Set PeerAddr)
-> TestName)
-> ((Int, Set PeerAddr, Set PeerAddr, Set PeerAddr, Set PeerAddr,
Set PeerAddr)
-> Bool)
-> Signal
(Int, Set PeerAddr, Set PeerAddr, Set PeerAddr, Set PeerAddr,
Set PeerAddr)
-> Property
forall a.
Int -> (a -> TestName) -> (a -> Bool) -> Signal a -> Property
signalProperty Int
20 (Int, Set PeerAddr, Set PeerAddr, Set PeerAddr, Set PeerAddr,
Set PeerAddr)
-> TestName
forall a. Show a => a -> TestName
show
(\(Int
_,Set PeerAddr
_,Set PeerAddr
_,Set PeerAddr
_,Set PeerAddr
_,Set PeerAddr
toolong) -> Set PeerAddr -> Bool
forall a. Set a -> Bool
Set.null Set PeerAddr
toolong)
((,,,,,) (Int
-> Set PeerAddr
-> Set PeerAddr
-> Set PeerAddr
-> Set PeerAddr
-> Set PeerAddr
-> (Int, Set PeerAddr, Set PeerAddr, Set PeerAddr, Set PeerAddr,
Set PeerAddr))
-> Signal Int
-> Signal
(Set PeerAddr
-> Set PeerAddr
-> Set PeerAddr
-> Set PeerAddr
-> Set PeerAddr
-> (Int, Set PeerAddr, Set PeerAddr, Set PeerAddr, Set PeerAddr,
Set PeerAddr))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Signal Int
govTargetsSig
Signal
(Set PeerAddr
-> Set PeerAddr
-> Set PeerAddr
-> Set PeerAddr
-> Set PeerAddr
-> (Int, Set PeerAddr, Set PeerAddr, Set PeerAddr, Set PeerAddr,
Set PeerAddr))
-> Signal (Set PeerAddr)
-> Signal
(Set PeerAddr
-> Set PeerAddr
-> Set PeerAddr
-> Set PeerAddr
-> (Int, Set PeerAddr, Set PeerAddr, Set PeerAddr, Set PeerAddr,
Set PeerAddr))
forall a b. Signal (a -> b) -> Signal a -> Signal b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Signal (Set PeerAddr)
govLocalRootPeersSig
Signal
(Set PeerAddr
-> Set PeerAddr
-> Set PeerAddr
-> Set PeerAddr
-> (Int, Set PeerAddr, Set PeerAddr, Set PeerAddr, Set PeerAddr,
Set PeerAddr))
-> Signal (Set PeerAddr)
-> Signal
(Set PeerAddr
-> Set PeerAddr
-> Set PeerAddr
-> (Int, Set PeerAddr, Set PeerAddr, Set PeerAddr, Set PeerAddr,
Set PeerAddr))
forall a b. Signal (a -> b) -> Signal a -> Signal b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Signal (Set PeerAddr)
govPublicRootPeersSig
Signal
(Set PeerAddr
-> Set PeerAddr
-> Set PeerAddr
-> (Int, Set PeerAddr, Set PeerAddr, Set PeerAddr, Set PeerAddr,
Set PeerAddr))
-> Signal (Set PeerAddr)
-> Signal
(Set PeerAddr
-> Set PeerAddr
-> (Int, Set PeerAddr, Set PeerAddr, Set PeerAddr, Set PeerAddr,
Set PeerAddr))
forall a b. Signal (a -> b) -> Signal a -> Signal b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Signal (Set PeerAddr)
govRootPeersSig
Signal
(Set PeerAddr
-> Set PeerAddr
-> (Int, Set PeerAddr, Set PeerAddr, Set PeerAddr, Set PeerAddr,
Set PeerAddr))
-> Signal (Set PeerAddr)
-> Signal
(Set PeerAddr
-> (Int, Set PeerAddr, Set PeerAddr, Set PeerAddr, Set PeerAddr,
Set PeerAddr))
forall a b. Signal (a -> b) -> Signal a -> Signal b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Signal (Set PeerAddr)
requestOpportunities
Signal
(Set PeerAddr
-> (Int, Set PeerAddr, Set PeerAddr, Set PeerAddr, Set PeerAddr,
Set PeerAddr))
-> Signal (Set PeerAddr)
-> Signal
(Int, Set PeerAddr, Set PeerAddr, Set PeerAddr, Set PeerAddr,
Set PeerAddr)
forall a b. Signal (a -> b) -> Signal a -> Signal b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Signal (Set PeerAddr)
requestOpportunitiesIgnoredTooLong)
prop_governor_target_established_public :: MaxTime -> GovernorMockEnvironment -> Property
prop_governor_target_established_public :: MaxTime -> GovernorMockEnvironment -> Property
prop_governor_target_established_public (MaxTime Time
maxTime) GovernorMockEnvironment
env =
let events :: Events TestTraceEvent
events = Time -> [(Time, TestTraceEvent)] -> Events TestTraceEvent
forall a. Time -> [(Time, a)] -> Events a
Signal.eventsFromListUpToTime Time
maxTime
([(Time, TestTraceEvent)] -> Events TestTraceEvent)
-> (GovernorMockEnvironment -> [(Time, TestTraceEvent)])
-> GovernorMockEnvironment
-> Events TestTraceEvent
forall b c a. (b -> c) -> (a -> b) -> a -> c
. SimTrace Void -> [(Time, TestTraceEvent)]
forall a. SimTrace a -> [(Time, TestTraceEvent)]
selectPeerSelectionTraceEvents
(SimTrace Void -> [(Time, TestTraceEvent)])
-> (GovernorMockEnvironment -> SimTrace Void)
-> GovernorMockEnvironment
-> [(Time, TestTraceEvent)]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. GovernorMockEnvironment -> SimTrace Void
runGovernorInMockEnvironment
(GovernorMockEnvironment -> Events TestTraceEvent)
-> GovernorMockEnvironment -> Events TestTraceEvent
forall a b. (a -> b) -> a -> b
$ GovernorMockEnvironment
env
govPublicRootPeersSig :: Signal (Set PeerAddr)
govPublicRootPeersSig :: Signal (Set PeerAddr)
govPublicRootPeersSig =
(forall peerconn.
PeerSelectionState PeerAddr peerconn -> Set PeerAddr)
-> ConsensusMode -> Events TestTraceEvent -> Signal (Set PeerAddr)
forall a.
Eq a =>
(forall peerconn. PeerSelectionState PeerAddr peerconn -> a)
-> ConsensusMode -> Events TestTraceEvent -> Signal a
selectGovState (PublicRootPeers PeerAddr -> Set PeerAddr
forall peeraddr.
Ord peeraddr =>
PublicRootPeers peeraddr -> Set peeraddr
PublicRootPeers.toSet (PublicRootPeers PeerAddr -> Set PeerAddr)
-> (PeerSelectionState PeerAddr peerconn
-> PublicRootPeers PeerAddr)
-> PeerSelectionState PeerAddr peerconn
-> Set PeerAddr
forall b c a. (b -> c) -> (a -> b) -> a -> c
. PeerSelectionState PeerAddr peerconn -> PublicRootPeers PeerAddr
forall peeraddr peerconn.
PeerSelectionState peeraddr peerconn -> PublicRootPeers peeraddr
Governor.publicRootPeers)
(GovernorMockEnvironment -> ConsensusMode
consensusMode GovernorMockEnvironment
env)
Events TestTraceEvent
events
govEstablishedPeersSig :: Signal (Set PeerAddr)
govEstablishedPeersSig :: Signal (Set PeerAddr)
govEstablishedPeersSig =
(forall peerconn.
PeerSelectionState PeerAddr peerconn -> Set PeerAddr)
-> ConsensusMode -> Events TestTraceEvent -> Signal (Set PeerAddr)
forall a.
Eq a =>
(forall peerconn. PeerSelectionState PeerAddr peerconn -> a)
-> ConsensusMode -> Events TestTraceEvent -> Signal a
selectGovState
(EstablishedPeers PeerAddr peerconn -> Set PeerAddr
forall peeraddr peerconn.
EstablishedPeers peeraddr peerconn -> Set peeraddr
EstablishedPeers.toSet (EstablishedPeers PeerAddr peerconn -> Set PeerAddr)
-> (PeerSelectionState PeerAddr peerconn
-> EstablishedPeers PeerAddr peerconn)
-> PeerSelectionState PeerAddr peerconn
-> Set PeerAddr
forall b c a. (b -> c) -> (a -> b) -> a -> c
. PeerSelectionState PeerAddr peerconn
-> EstablishedPeers PeerAddr peerconn
forall peeraddr peerconn.
PeerSelectionState peeraddr peerconn
-> EstablishedPeers peeraddr peerconn
Governor.establishedPeers)
(GovernorMockEnvironment -> ConsensusMode
consensusMode GovernorMockEnvironment
env)
Events TestTraceEvent
events
govInProgressPromoteColdSig :: Signal (Set PeerAddr)
govInProgressPromoteColdSig :: Signal (Set PeerAddr)
govInProgressPromoteColdSig =
(forall peerconn.
PeerSelectionState PeerAddr peerconn -> Set PeerAddr)
-> ConsensusMode -> Events TestTraceEvent -> Signal (Set PeerAddr)
forall a.
Eq a =>
(forall peerconn. PeerSelectionState PeerAddr peerconn -> a)
-> ConsensusMode -> Events TestTraceEvent -> Signal a
selectGovState
PeerSelectionState PeerAddr peerconn -> Set PeerAddr
forall peerconn.
PeerSelectionState PeerAddr peerconn -> Set PeerAddr
forall peeraddr peerconn.
PeerSelectionState peeraddr peerconn -> Set peeraddr
Governor.inProgressPromoteCold
(GovernorMockEnvironment -> ConsensusMode
consensusMode GovernorMockEnvironment
env)
Events TestTraceEvent
events
publicInEstablished :: Signal Bool
publicInEstablished :: Signal Bool
publicInEstablished =
(\Set PeerAddr
publicPeers Set PeerAddr
established Set PeerAddr
inProgressPromoteCold ->
Set PeerAddr -> Int
forall a. Set a -> Int
Set.size
(Set PeerAddr
publicPeers Set PeerAddr -> Set PeerAddr -> Set PeerAddr
forall a. Ord a => Set a -> Set a -> Set a
`Set.intersection`
(Set PeerAddr
established Set PeerAddr -> Set PeerAddr -> Set PeerAddr
forall a. Ord a => Set a -> Set a -> Set a
`Set.union` Set PeerAddr
inProgressPromoteCold))
Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
> Int
0
) (Set PeerAddr -> Set PeerAddr -> Set PeerAddr -> Bool)
-> Signal (Set PeerAddr)
-> Signal (Set PeerAddr -> Set PeerAddr -> Bool)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Signal (Set PeerAddr)
govPublicRootPeersSig
Signal (Set PeerAddr -> Set PeerAddr -> Bool)
-> Signal (Set PeerAddr) -> Signal (Set PeerAddr -> Bool)
forall a b. Signal (a -> b) -> Signal a -> Signal b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Signal (Set PeerAddr)
govEstablishedPeersSig
Signal (Set PeerAddr -> Bool)
-> Signal (Set PeerAddr) -> Signal Bool
forall a b. Signal (a -> b) -> Signal a -> Signal b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Signal (Set PeerAddr)
govInProgressPromoteColdSig
meaning :: Bool -> String
meaning :: Bool -> TestName
meaning Bool
False = TestName
"No PublicPeers in Established Set"
meaning Bool
True = TestName
"PublicPeers in Established Set"
valuesList :: [String]
valuesList :: [TestName]
valuesList = ((Time, Bool) -> TestName) -> [(Time, Bool)] -> [TestName]
forall a b. (a -> b) -> [a] -> [b]
map (Bool -> TestName
meaning (Bool -> TestName)
-> ((Time, Bool) -> Bool) -> (Time, Bool) -> TestName
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Time, Bool) -> Bool
forall a b. (a, b) -> b
snd)
([(Time, Bool)] -> [TestName])
-> (Signal Bool -> [(Time, Bool)]) -> Signal Bool -> [TestName]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Events Bool -> [(Time, Bool)]
forall a. Events a -> [(Time, a)]
Signal.eventsToList
(Events Bool -> [(Time, Bool)])
-> (Signal Bool -> Events Bool) -> Signal Bool -> [(Time, Bool)]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Signal Bool -> Events Bool
forall a. Signal a -> Events a
Signal.toChangeEvents
(Signal Bool -> [TestName]) -> Signal Bool -> [TestName]
forall a b. (a -> b) -> a -> b
$ Signal Bool
publicInEstablished
in Property -> Property
forall prop. Testable prop => prop -> Property
checkCoverage
(Property -> Property) -> Property -> Property
forall a b. (a -> b) -> a -> b
$ TestName -> [(TestName, Double)] -> Property -> Property
forall prop.
Testable prop =>
TestName -> [(TestName, Double)] -> prop -> Property
coverTable TestName
"established public peers"
[(TestName
"PublicPeers in Established Set", Double
1)]
(Property -> Property) -> Property -> Property
forall a b. (a -> b) -> a -> b
$ TestName -> [TestName] -> Bool -> Property
forall prop.
Testable prop =>
TestName -> [TestName] -> prop -> Property
tabulate TestName
"established public peers" [TestName]
valuesList
(Bool -> Property) -> Bool -> Property
forall a b. (a -> b) -> a -> b
$ Bool
True
prop_governor_target_established_big_ledger_peers
:: MaxTime
-> GovernorMockEnvironment
-> Property
prop_governor_target_established_big_ledger_peers :: MaxTime -> GovernorMockEnvironment -> Property
prop_governor_target_established_big_ledger_peers (MaxTime Time
maxTime) GovernorMockEnvironment
env =
let events :: Events TestTraceEvent
events = Time -> [(Time, TestTraceEvent)] -> Events TestTraceEvent
forall a. Time -> [(Time, a)] -> Events a
Signal.eventsFromListUpToTime Time
maxTime
([(Time, TestTraceEvent)] -> Events TestTraceEvent)
-> (GovernorMockEnvironment -> [(Time, TestTraceEvent)])
-> GovernorMockEnvironment
-> Events TestTraceEvent
forall b c a. (b -> c) -> (a -> b) -> a -> c
. SimTrace Void -> [(Time, TestTraceEvent)]
forall a. SimTrace a -> [(Time, TestTraceEvent)]
selectPeerSelectionTraceEvents
(SimTrace Void -> [(Time, TestTraceEvent)])
-> (GovernorMockEnvironment -> SimTrace Void)
-> GovernorMockEnvironment
-> [(Time, TestTraceEvent)]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. GovernorMockEnvironment -> SimTrace Void
runGovernorInMockEnvironment
(GovernorMockEnvironment -> Events TestTraceEvent)
-> GovernorMockEnvironment -> Events TestTraceEvent
forall a b. (a -> b) -> a -> b
$ GovernorMockEnvironment
env
govBigLedgerPeersSig :: Signal (Set PeerAddr)
govBigLedgerPeersSig :: Signal (Set PeerAddr)
govBigLedgerPeersSig =
(forall peerconn.
PeerSelectionState PeerAddr peerconn -> Set PeerAddr)
-> ConsensusMode -> Events TestTraceEvent -> Signal (Set PeerAddr)
forall a.
Eq a =>
(forall peerconn. PeerSelectionState PeerAddr peerconn -> a)
-> ConsensusMode -> Events TestTraceEvent -> Signal a
selectGovState (PublicRootPeers PeerAddr -> Set PeerAddr
forall peeraddr. PublicRootPeers peeraddr -> Set peeraddr
PublicRootPeers.getBigLedgerPeers (PublicRootPeers PeerAddr -> Set PeerAddr)
-> (PeerSelectionState PeerAddr peerconn
-> PublicRootPeers PeerAddr)
-> PeerSelectionState PeerAddr peerconn
-> Set PeerAddr
forall b c a. (b -> c) -> (a -> b) -> a -> c
. PeerSelectionState PeerAddr peerconn -> PublicRootPeers PeerAddr
forall peeraddr peerconn.
PeerSelectionState peeraddr peerconn -> PublicRootPeers peeraddr
Governor.publicRootPeers)
(GovernorMockEnvironment -> ConsensusMode
consensusMode GovernorMockEnvironment
env)
Events TestTraceEvent
events
govLedgerStateJudgement :: Signal LedgerStateJudgement
govLedgerStateJudgement :: Signal LedgerStateJudgement
govLedgerStateJudgement =
(forall peerconn.
PeerSelectionState PeerAddr peerconn -> LedgerStateJudgement)
-> ConsensusMode
-> Events TestTraceEvent
-> Signal LedgerStateJudgement
forall a.
Eq a =>
(forall peerconn. PeerSelectionState PeerAddr peerconn -> a)
-> ConsensusMode -> Events TestTraceEvent -> Signal a
selectGovState (PeerSelectionState PeerAddr peerconn -> LedgerStateJudgement
forall peeraddr peerconn.
PeerSelectionState peeraddr peerconn -> LedgerStateJudgement
Governor.ledgerStateJudgement)
(GovernorMockEnvironment -> ConsensusMode
consensusMode GovernorMockEnvironment
env)
Events TestTraceEvent
events
govEstablishedPeersSig :: Signal (Set PeerAddr)
govEstablishedPeersSig :: Signal (Set PeerAddr)
govEstablishedPeersSig =
(forall peerconn.
PeerSelectionState PeerAddr peerconn -> Set PeerAddr)
-> ConsensusMode -> Events TestTraceEvent -> Signal (Set PeerAddr)
forall a.
Eq a =>
(forall peerconn. PeerSelectionState PeerAddr peerconn -> a)
-> ConsensusMode -> Events TestTraceEvent -> Signal a
selectGovState
(EstablishedPeers PeerAddr peerconn -> Set PeerAddr
forall peeraddr peerconn.
EstablishedPeers peeraddr peerconn -> Set peeraddr
EstablishedPeers.toSet (EstablishedPeers PeerAddr peerconn -> Set PeerAddr)
-> (PeerSelectionState PeerAddr peerconn
-> EstablishedPeers PeerAddr peerconn)
-> PeerSelectionState PeerAddr peerconn
-> Set PeerAddr
forall b c a. (b -> c) -> (a -> b) -> a -> c
. PeerSelectionState PeerAddr peerconn
-> EstablishedPeers PeerAddr peerconn
forall peeraddr peerconn.
PeerSelectionState peeraddr peerconn
-> EstablishedPeers peeraddr peerconn
Governor.establishedPeers)
(GovernorMockEnvironment -> ConsensusMode
consensusMode GovernorMockEnvironment
env)
Events TestTraceEvent
events
govInProgressPromoteColdSig :: Signal (Set PeerAddr)
govInProgressPromoteColdSig :: Signal (Set PeerAddr)
govInProgressPromoteColdSig =
(forall peerconn.
PeerSelectionState PeerAddr peerconn -> Set PeerAddr)
-> ConsensusMode -> Events TestTraceEvent -> Signal (Set PeerAddr)
forall a.
Eq a =>
(forall peerconn. PeerSelectionState PeerAddr peerconn -> a)
-> ConsensusMode -> Events TestTraceEvent -> Signal a
selectGovState
PeerSelectionState PeerAddr peerconn -> Set PeerAddr
forall peerconn.
PeerSelectionState PeerAddr peerconn -> Set PeerAddr
forall peeraddr peerconn.
PeerSelectionState peeraddr peerconn -> Set peeraddr
Governor.inProgressPromoteCold
(GovernorMockEnvironment -> ConsensusMode
consensusMode GovernorMockEnvironment
env)
Events TestTraceEvent
events
bigLedgerPeersInEstablished :: Signal Bool
bigLedgerPeersInEstablished :: Signal Bool
bigLedgerPeersInEstablished =
(\Set PeerAddr
bigLedgerPeers Set PeerAddr
established Set PeerAddr
inProgressPromoteCold LedgerStateJudgement
lsj ->
case LedgerStateJudgement
lsj of
LedgerStateJudgement
YoungEnough ->
Bool -> Bool
not (Bool -> Bool) -> (Set PeerAddr -> Bool) -> Set PeerAddr -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Set PeerAddr -> Bool
forall a. Set a -> Bool
Set.null (Set PeerAddr -> Bool) -> Set PeerAddr -> Bool
forall a b. (a -> b) -> a -> b
$
(Set PeerAddr
bigLedgerPeers Set PeerAddr -> Set PeerAddr -> Set PeerAddr
forall a. Ord a => Set a -> Set a -> Set a
`Set.intersection`
(Set PeerAddr
established Set PeerAddr -> Set PeerAddr -> Set PeerAddr
forall a. Ord a => Set a -> Set a -> Set a
`Set.union` Set PeerAddr
inProgressPromoteCold))
LedgerStateJudgement
TooOld -> Bool
True
) (Set PeerAddr
-> Set PeerAddr -> Set PeerAddr -> LedgerStateJudgement -> Bool)
-> Signal (Set PeerAddr)
-> Signal
(Set PeerAddr -> Set PeerAddr -> LedgerStateJudgement -> Bool)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Signal (Set PeerAddr)
govBigLedgerPeersSig
Signal
(Set PeerAddr -> Set PeerAddr -> LedgerStateJudgement -> Bool)
-> Signal (Set PeerAddr)
-> Signal (Set PeerAddr -> LedgerStateJudgement -> Bool)
forall a b. Signal (a -> b) -> Signal a -> Signal b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Signal (Set PeerAddr)
govEstablishedPeersSig
Signal (Set PeerAddr -> LedgerStateJudgement -> Bool)
-> Signal (Set PeerAddr) -> Signal (LedgerStateJudgement -> Bool)
forall a b. Signal (a -> b) -> Signal a -> Signal b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Signal (Set PeerAddr)
govInProgressPromoteColdSig
Signal (LedgerStateJudgement -> Bool)
-> Signal LedgerStateJudgement -> Signal Bool
forall a b. Signal (a -> b) -> Signal a -> Signal b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Signal LedgerStateJudgement
govLedgerStateJudgement
meaning :: Bool -> String
meaning :: Bool -> TestName
meaning Bool
False = TestName
"No BigLedgerPeers in Established Set"
meaning Bool
True = TestName
"BigLedgerPeers in Established Set"
valuesList :: [String]
valuesList :: [TestName]
valuesList = ((Time, Bool) -> TestName) -> [(Time, Bool)] -> [TestName]
forall a b. (a -> b) -> [a] -> [b]
map (Bool -> TestName
meaning (Bool -> TestName)
-> ((Time, Bool) -> Bool) -> (Time, Bool) -> TestName
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Time, Bool) -> Bool
forall a b. (a, b) -> b
snd)
([(Time, Bool)] -> [TestName])
-> (Signal Bool -> [(Time, Bool)]) -> Signal Bool -> [TestName]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Events Bool -> [(Time, Bool)]
forall a. Events a -> [(Time, a)]
Signal.eventsToList
(Events Bool -> [(Time, Bool)])
-> (Signal Bool -> Events Bool) -> Signal Bool -> [(Time, Bool)]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Signal Bool -> Events Bool
forall a. Signal a -> Events a
Signal.toChangeEvents
(Signal Bool -> [TestName]) -> Signal Bool -> [TestName]
forall a b. (a -> b) -> a -> b
$ Signal Bool
bigLedgerPeersInEstablished
in Property -> Property
forall prop. Testable prop => prop -> Property
checkCoverage
(Property -> Property) -> Property -> Property
forall a b. (a -> b) -> a -> b
$ TestName -> [(TestName, Double)] -> Property -> Property
forall prop.
Testable prop =>
TestName -> [(TestName, Double)] -> prop -> Property
coverTable TestName
"established big ledger peers"
[(TestName
"BigLedgerPeers in Established Set", Double
1)]
(Property -> Property) -> Property -> Property
forall a b. (a -> b) -> a -> b
$ TestName -> [TestName] -> Bool -> Property
forall prop.
Testable prop =>
TestName -> [TestName] -> prop -> Property
tabulate TestName
"established big ledger peers" [TestName]
valuesList
(Bool -> Property) -> Bool -> Property
forall a b. (a -> b) -> a -> b
$ Bool
True
prop_governor_target_active_public :: MaxTime -> GovernorMockEnvironment -> Property
prop_governor_target_active_public :: MaxTime -> GovernorMockEnvironment -> Property
prop_governor_target_active_public (MaxTime Time
maxTime) GovernorMockEnvironment
env =
let events :: Events TestTraceEvent
events = Time -> [(Time, TestTraceEvent)] -> Events TestTraceEvent
forall a. Time -> [(Time, a)] -> Events a
Signal.eventsFromListUpToTime Time
maxTime
([(Time, TestTraceEvent)] -> Events TestTraceEvent)
-> (GovernorMockEnvironment -> [(Time, TestTraceEvent)])
-> GovernorMockEnvironment
-> Events TestTraceEvent
forall b c a. (b -> c) -> (a -> b) -> a -> c
. SimTrace Void -> [(Time, TestTraceEvent)]
forall a. SimTrace a -> [(Time, TestTraceEvent)]
selectPeerSelectionTraceEvents
(SimTrace Void -> [(Time, TestTraceEvent)])
-> (GovernorMockEnvironment -> SimTrace Void)
-> GovernorMockEnvironment
-> [(Time, TestTraceEvent)]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. GovernorMockEnvironment -> SimTrace Void
runGovernorInMockEnvironment
(GovernorMockEnvironment -> Events TestTraceEvent)
-> GovernorMockEnvironment -> Events TestTraceEvent
forall a b. (a -> b) -> a -> b
$ GovernorMockEnvironment
env
govPublicRootPeersSig :: Signal (Set PeerAddr)
govPublicRootPeersSig :: Signal (Set PeerAddr)
govPublicRootPeersSig =
(forall peerconn.
PeerSelectionState PeerAddr peerconn -> Set PeerAddr)
-> ConsensusMode -> Events TestTraceEvent -> Signal (Set PeerAddr)
forall a.
Eq a =>
(forall peerconn. PeerSelectionState PeerAddr peerconn -> a)
-> ConsensusMode -> Events TestTraceEvent -> Signal a
selectGovState (PublicRootPeers PeerAddr -> Set PeerAddr
forall peeraddr.
Ord peeraddr =>
PublicRootPeers peeraddr -> Set peeraddr
PublicRootPeers.toSet (PublicRootPeers PeerAddr -> Set PeerAddr)
-> (PeerSelectionState PeerAddr peerconn
-> PublicRootPeers PeerAddr)
-> PeerSelectionState PeerAddr peerconn
-> Set PeerAddr
forall b c a. (b -> c) -> (a -> b) -> a -> c
. PeerSelectionState PeerAddr peerconn -> PublicRootPeers PeerAddr
forall peeraddr peerconn.
PeerSelectionState peeraddr peerconn -> PublicRootPeers peeraddr
Governor.publicRootPeers)
(GovernorMockEnvironment -> ConsensusMode
consensusMode GovernorMockEnvironment
env)
Events TestTraceEvent
events
govActivePeersSig :: Signal (Set PeerAddr)
govActivePeersSig :: Signal (Set PeerAddr)
govActivePeersSig =
(forall peerconn.
PeerSelectionState PeerAddr peerconn -> Set PeerAddr)
-> ConsensusMode -> Events TestTraceEvent -> Signal (Set PeerAddr)
forall a.
Eq a =>
(forall peerconn. PeerSelectionState PeerAddr peerconn -> a)
-> ConsensusMode -> Events TestTraceEvent -> Signal a
selectGovState PeerSelectionState PeerAddr peerconn -> Set PeerAddr
forall peerconn.
PeerSelectionState PeerAddr peerconn -> Set PeerAddr
forall peeraddr peerconn.
PeerSelectionState peeraddr peerconn -> Set peeraddr
Governor.activePeers (GovernorMockEnvironment -> ConsensusMode
consensusMode GovernorMockEnvironment
env) Events TestTraceEvent
events
publicInActive :: Signal Bool
publicInActive :: Signal Bool
publicInActive =
(\Set PeerAddr
publicPeers Set PeerAddr
active ->
Set PeerAddr -> Int
forall a. Set a -> Int
Set.size
(Set PeerAddr
publicPeers Set PeerAddr -> Set PeerAddr -> Set PeerAddr
forall a. Ord a => Set a -> Set a -> Set a
`Set.intersection` Set PeerAddr
active)
Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
> Int
0
) (Set PeerAddr -> Set PeerAddr -> Bool)
-> Signal (Set PeerAddr) -> Signal (Set PeerAddr -> Bool)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Signal (Set PeerAddr)
govPublicRootPeersSig
Signal (Set PeerAddr -> Bool)
-> Signal (Set PeerAddr) -> Signal Bool
forall a b. Signal (a -> b) -> Signal a -> Signal b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Signal (Set PeerAddr)
govActivePeersSig
meaning :: Bool -> String
meaning :: Bool -> TestName
meaning Bool
False = TestName
"No PublicPeers in Active Set"
meaning Bool
True = TestName
"PublicPeers in Active Set"
valuesList :: [String]
valuesList :: [TestName]
valuesList = ((Time, Bool) -> TestName) -> [(Time, Bool)] -> [TestName]
forall a b. (a -> b) -> [a] -> [b]
map (Bool -> TestName
meaning (Bool -> TestName)
-> ((Time, Bool) -> Bool) -> (Time, Bool) -> TestName
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Time, Bool) -> Bool
forall a b. (a, b) -> b
snd)
([(Time, Bool)] -> [TestName])
-> (Signal Bool -> [(Time, Bool)]) -> Signal Bool -> [TestName]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Events Bool -> [(Time, Bool)]
forall a. Events a -> [(Time, a)]
Signal.eventsToList
(Events Bool -> [(Time, Bool)])
-> (Signal Bool -> Events Bool) -> Signal Bool -> [(Time, Bool)]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Signal Bool -> Events Bool
forall a. Signal a -> Events a
Signal.toChangeEvents
(Signal Bool -> [TestName]) -> Signal Bool -> [TestName]
forall a b. (a -> b) -> a -> b
$ Signal Bool
publicInActive
in Property -> Property
forall prop. Testable prop => prop -> Property
checkCoverage
(Property -> Property) -> Property -> Property
forall a b. (a -> b) -> a -> b
$ TestName -> [(TestName, Double)] -> Property -> Property
forall prop.
Testable prop =>
TestName -> [(TestName, Double)] -> prop -> Property
coverTable TestName
"active public peers"
[(TestName
"PublicPeers in Active Set", Double
1)]
(Property -> Property) -> Property -> Property
forall a b. (a -> b) -> a -> b
$ TestName -> [TestName] -> Bool -> Property
forall prop.
Testable prop =>
TestName -> [TestName] -> prop -> Property
tabulate TestName
"active public peers" [TestName]
valuesList
(Bool -> Property) -> Bool -> Property
forall a b. (a -> b) -> a -> b
$ Bool
True
prop_governor_target_known_below :: MaxTime -> GovernorMockEnvironment -> Property
prop_governor_target_known_below :: MaxTime -> GovernorMockEnvironment -> Property
prop_governor_target_known_below MaxTime
maxTime GovernorMockEnvironment
env =
TestName -> Property -> Property
forall prop. Testable prop => TestName -> prop -> Property
counterexample TestName
"invalid subset"
(MaxTime -> GovernorMockEnvironment -> Property
prop_governor_target_known_1_valid_subset MaxTime
maxTime GovernorMockEnvironment
env)
Property -> Property -> Property
forall prop1 prop2.
(Testable prop1, Testable prop2) =>
prop1 -> prop2 -> Property
.&&. TestName -> Property -> Property
forall prop. Testable prop => TestName -> prop -> Property
counterexample TestName
"opportunity not taken"
(MaxTime -> GovernorMockEnvironment -> Property
prop_governor_target_known_2_opportunity_taken MaxTime
maxTime GovernorMockEnvironment
env)
Property -> Property -> Property
forall prop1 prop2.
(Testable prop1, Testable prop2) =>
prop1 -> prop2 -> Property
.&&. TestName -> Property -> Property
forall prop. Testable prop => TestName -> prop -> Property
counterexample TestName
"too chatty"
(MaxTime -> GovernorMockEnvironment -> Property
prop_governor_target_known_3_not_too_chatty MaxTime
maxTime GovernorMockEnvironment
env)
Property -> Property -> Property
forall prop1 prop2.
(Testable prop1, Testable prop2) =>
prop1 -> prop2 -> Property
.&&. TestName -> Property -> Property
forall prop. Testable prop => TestName -> prop -> Property
counterexample TestName
"not used results"
(MaxTime -> GovernorMockEnvironment -> Property
prop_governor_target_known_4_results_used MaxTime
maxTime GovernorMockEnvironment
env)
Property -> Property -> Property
forall prop1 prop2.
(Testable prop1, Testable prop2) =>
prop1 -> prop2 -> Property
.&&. TestName -> Property -> Property
forall prop. Testable prop => TestName -> prop -> Property
counterexample TestName
"shrinked below"
(MaxTime -> GovernorMockEnvironment -> Property
prop_governor_target_known_5_no_shrink_below MaxTime
maxTime GovernorMockEnvironment
env)
prop_governor_target_known_big_ledger_peers_below :: MaxTime -> GovernorMockEnvironment -> Property
prop_governor_target_known_big_ledger_peers_below :: MaxTime -> GovernorMockEnvironment -> Property
prop_governor_target_known_big_ledger_peers_below MaxTime
maxTime GovernorMockEnvironment
env =
TestName -> Property -> Property
forall prop. Testable prop => TestName -> prop -> Property
counterexample TestName
"shrinked big ledger peers below"
(MaxTime -> GovernorMockEnvironment -> Property
prop_governor_target_known_5_no_shrink_big_ledger_peers_below MaxTime
maxTime GovernorMockEnvironment
env)
prop_governor_target_known_1_valid_subset :: MaxTime
-> GovernorMockEnvironment
-> Property
prop_governor_target_known_1_valid_subset :: MaxTime -> GovernorMockEnvironment -> Property
prop_governor_target_known_1_valid_subset (MaxTime Time
maxTime) GovernorMockEnvironment
env =
let events :: Events TestTraceEvent
events = Time -> [(Time, TestTraceEvent)] -> Events TestTraceEvent
forall a. Time -> [(Time, a)] -> Events a
Signal.eventsFromListUpToTime Time
maxTime
([(Time, TestTraceEvent)] -> Events TestTraceEvent)
-> (GovernorMockEnvironment -> [(Time, TestTraceEvent)])
-> GovernorMockEnvironment
-> Events TestTraceEvent
forall b c a. (b -> c) -> (a -> b) -> a -> c
. SimTrace Void -> [(Time, TestTraceEvent)]
forall a. SimTrace a -> [(Time, TestTraceEvent)]
selectPeerSelectionTraceEvents
(SimTrace Void -> [(Time, TestTraceEvent)])
-> (GovernorMockEnvironment -> SimTrace Void)
-> GovernorMockEnvironment
-> [(Time, TestTraceEvent)]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. GovernorMockEnvironment -> SimTrace Void
runGovernorInMockEnvironment
(GovernorMockEnvironment -> Events TestTraceEvent)
-> GovernorMockEnvironment -> Events TestTraceEvent
forall a b. (a -> b) -> a -> b
$ GovernorMockEnvironment
env
envKnownPeersSig :: Signal (Set PeerAddr)
envKnownPeersSig :: Signal (Set PeerAddr)
envKnownPeersSig =
(Set PeerAddr -> Set PeerAddr -> Bool)
-> Signal (Set PeerAddr) -> Signal (Set PeerAddr)
forall a. (a -> a -> Bool) -> Signal a -> Signal a
Signal.nubBy (Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
(==) (Int -> Int -> Bool)
-> (Set PeerAddr -> Int) -> Set PeerAddr -> Set PeerAddr -> Bool
forall b c a. (b -> b -> c) -> (a -> b) -> a -> a -> c
`on` Set PeerAddr -> Int
forall a. Set a -> Int
Set.size)
(Signal (Set PeerAddr) -> Signal (Set PeerAddr))
-> (Events TestTraceEvent -> Signal (Set PeerAddr))
-> Events TestTraceEvent
-> Signal (Set PeerAddr)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Set PeerAddr -> Set PeerAddr -> Set PeerAddr)
-> Set PeerAddr -> Signal (Set PeerAddr) -> Signal (Set PeerAddr)
forall b a. (b -> a -> b) -> b -> Signal a -> Signal b
Signal.scanl Set PeerAddr -> Set PeerAddr -> Set PeerAddr
forall a. Ord a => Set a -> Set a -> Set a
Set.union Set PeerAddr
forall a. Set a
Set.empty
(Signal (Set PeerAddr) -> Signal (Set PeerAddr))
-> (Events TestTraceEvent -> Signal (Set PeerAddr))
-> Events TestTraceEvent
-> Signal (Set PeerAddr)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Set PeerAddr -> Events (Set PeerAddr) -> Signal (Set PeerAddr)
forall a. a -> Events a -> Signal a
Signal.fromChangeEvents Set PeerAddr
forall a. Set a
Set.empty
(Events (Set PeerAddr) -> Signal (Set PeerAddr))
-> (Events TestTraceEvent -> Events (Set PeerAddr))
-> Events TestTraceEvent
-> Signal (Set PeerAddr)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (TracePeerSelection PeerAddr -> Maybe (Set PeerAddr))
-> Events (TracePeerSelection PeerAddr) -> Events (Set PeerAddr)
forall a b. (a -> Maybe b) -> Events a -> Events b
Signal.selectEvents
(\case
TraceLocalRootPeersChanged LocalRootPeers PeerAddr
_ LocalRootPeers PeerAddr
x -> Set PeerAddr -> Maybe (Set PeerAddr)
forall a. a -> Maybe a
Just (LocalRootPeers PeerAddr -> Set PeerAddr
forall peeraddr. LocalRootPeers peeraddr -> Set peeraddr
LocalRootPeers.keysSet LocalRootPeers PeerAddr
x)
TracePublicRootsResults PublicRootPeers PeerAddr
x Int
_ DiffTime
_ -> Set PeerAddr -> Maybe (Set PeerAddr)
forall a. a -> Maybe a
Just (PublicRootPeers PeerAddr -> Set PeerAddr
forall peeraddr.
Ord peeraddr =>
PublicRootPeers peeraddr -> Set peeraddr
PublicRootPeers.toSet PublicRootPeers PeerAddr
x)
TraceBigLedgerPeersResults Set PeerAddr
x Int
_ DiffTime
_ -> Set PeerAddr -> Maybe (Set PeerAddr)
forall a. a -> Maybe a
Just Set PeerAddr
x
TracePeerShareResultsFiltered [PeerAddr]
x -> Set PeerAddr -> Maybe (Set PeerAddr)
forall a. a -> Maybe a
Just ([PeerAddr] -> Set PeerAddr
forall a. Ord a => [a] -> Set a
Set.fromList [PeerAddr]
x)
TracePeerSelection PeerAddr
_ -> Maybe (Set PeerAddr)
forall a. Maybe a
Nothing
)
(Events (TracePeerSelection PeerAddr) -> Events (Set PeerAddr))
-> (Events TestTraceEvent -> Events (TracePeerSelection PeerAddr))
-> Events TestTraceEvent
-> Events (Set PeerAddr)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Events TestTraceEvent -> Events (TracePeerSelection PeerAddr)
selectGovEvents
(Events TestTraceEvent -> Signal (Set PeerAddr))
-> Events TestTraceEvent -> Signal (Set PeerAddr)
forall a b. (a -> b) -> a -> b
$ Events TestTraceEvent
events
govKnownPeersSig :: Signal (Set PeerAddr)
govKnownPeersSig :: Signal (Set PeerAddr)
govKnownPeersSig =
(forall peerconn.
PeerSelectionState PeerAddr peerconn -> Set PeerAddr)
-> ConsensusMode -> Events TestTraceEvent -> Signal (Set PeerAddr)
forall a.
Eq a =>
(forall peerconn. PeerSelectionState PeerAddr peerconn -> a)
-> ConsensusMode -> Events TestTraceEvent -> Signal a
selectGovState (KnownPeers PeerAddr -> Set PeerAddr
forall peeraddr. KnownPeers peeraddr -> Set peeraddr
KnownPeers.toSet (KnownPeers PeerAddr -> Set PeerAddr)
-> (PeerSelectionState PeerAddr peerconn -> KnownPeers PeerAddr)
-> PeerSelectionState PeerAddr peerconn
-> Set PeerAddr
forall b c a. (b -> c) -> (a -> b) -> a -> c
. PeerSelectionState PeerAddr peerconn -> KnownPeers PeerAddr
forall peeraddr peerconn.
PeerSelectionState peeraddr peerconn -> KnownPeers peeraddr
Governor.knownPeers) (GovernorMockEnvironment -> ConsensusMode
consensusMode GovernorMockEnvironment
env) Events TestTraceEvent
events
validState :: Set PeerAddr -> Set PeerAddr -> Bool
validState :: Set PeerAddr -> Set PeerAddr -> Bool
validState Set PeerAddr
knownPeersEnv Set PeerAddr
knownPeersGov =
Set PeerAddr
knownPeersGov Set PeerAddr -> Set PeerAddr -> Bool
forall a. Ord a => Set a -> Set a -> Bool
`Set.isSubsetOf` Set PeerAddr
knownPeersEnv
in TestName -> Property -> Property
forall prop. Testable prop => TestName -> prop -> Property
counterexample
TestName
"Signal key: (environment known peers, governor known peers)" (Property -> Property) -> Property -> Property
forall a b. (a -> b) -> a -> b
$
Int
-> ((Set PeerAddr, Set PeerAddr) -> TestName)
-> ((Set PeerAddr, Set PeerAddr) -> Bool)
-> Signal (Set PeerAddr, Set PeerAddr)
-> Property
forall a.
Int -> (a -> TestName) -> (a -> Bool) -> Signal a -> Property
signalProperty Int
20 (Set PeerAddr, Set PeerAddr) -> TestName
forall a. Show a => a -> TestName
show ((Set PeerAddr -> Set PeerAddr -> Bool)
-> (Set PeerAddr, Set PeerAddr) -> Bool
forall a b c. (a -> b -> c) -> (a, b) -> c
uncurry Set PeerAddr -> Set PeerAddr -> Bool
validState) (Signal (Set PeerAddr, Set PeerAddr) -> Property)
-> Signal (Set PeerAddr, Set PeerAddr) -> Property
forall a b. (a -> b) -> a -> b
$
(,) (Set PeerAddr -> Set PeerAddr -> (Set PeerAddr, Set PeerAddr))
-> Signal (Set PeerAddr)
-> Signal (Set PeerAddr -> (Set PeerAddr, Set PeerAddr))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Signal (Set PeerAddr)
envKnownPeersSig
Signal (Set PeerAddr -> (Set PeerAddr, Set PeerAddr))
-> Signal (Set PeerAddr) -> Signal (Set PeerAddr, Set PeerAddr)
forall a b. Signal (a -> b) -> Signal a -> Signal b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Signal (Set PeerAddr)
govKnownPeersSig
prop_governor_target_known_2_opportunity_taken :: MaxTime
-> GovernorMockEnvironment
-> Property
prop_governor_target_known_2_opportunity_taken :: MaxTime -> GovernorMockEnvironment -> Property
prop_governor_target_known_2_opportunity_taken (MaxTime Time
maxTime) GovernorMockEnvironment
env =
let events :: Events TestTraceEvent
events = Time -> [(Time, TestTraceEvent)] -> Events TestTraceEvent
forall a. Time -> [(Time, a)] -> Events a
Signal.eventsFromListUpToTime Time
maxTime
([(Time, TestTraceEvent)] -> Events TestTraceEvent)
-> (GovernorMockEnvironment -> [(Time, TestTraceEvent)])
-> GovernorMockEnvironment
-> Events TestTraceEvent
forall b c a. (b -> c) -> (a -> b) -> a -> c
. SimTrace Void -> [(Time, TestTraceEvent)]
forall a. SimTrace a -> [(Time, TestTraceEvent)]
selectPeerSelectionTraceEvents
(SimTrace Void -> [(Time, TestTraceEvent)])
-> (GovernorMockEnvironment -> SimTrace Void)
-> GovernorMockEnvironment
-> [(Time, TestTraceEvent)]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. GovernorMockEnvironment -> SimTrace Void
runGovernorInMockEnvironment
(GovernorMockEnvironment -> Events TestTraceEvent)
-> GovernorMockEnvironment -> Events TestTraceEvent
forall a b. (a -> b) -> a -> b
$ GovernorMockEnvironment
env
govTargetsSig :: Signal Int
govTargetsSig :: Signal Int
govTargetsSig =
(forall peerconn. PeerSelectionState PeerAddr peerconn -> Int)
-> ConsensusMode -> Events TestTraceEvent -> Signal Int
forall a.
Eq a =>
(forall peerconn. PeerSelectionState PeerAddr peerconn -> a)
-> ConsensusMode -> Events TestTraceEvent -> Signal a
selectGovState (PeerSelectionTargets -> Int
targetNumberOfKnownPeers (PeerSelectionTargets -> Int)
-> (PeerSelectionState PeerAddr peerconn -> PeerSelectionTargets)
-> PeerSelectionState PeerAddr peerconn
-> Int
forall b c a. (b -> c) -> (a -> b) -> a -> c
. PeerSelectionState PeerAddr peerconn -> PeerSelectionTargets
forall peeraddr peerconn.
PeerSelectionState peeraddr peerconn -> PeerSelectionTargets
Governor.targets) (GovernorMockEnvironment -> ConsensusMode
consensusMode GovernorMockEnvironment
env) Events TestTraceEvent
events
govKnownPeersSig :: Signal (Set PeerAddr)
govKnownPeersSig :: Signal (Set PeerAddr)
govKnownPeersSig =
(forall peerconn.
PeerSelectionState PeerAddr peerconn -> Set PeerAddr)
-> ConsensusMode -> Events TestTraceEvent -> Signal (Set PeerAddr)
forall a.
Eq a =>
(forall peerconn. PeerSelectionState PeerAddr peerconn -> a)
-> ConsensusMode -> Events TestTraceEvent -> Signal a
selectGovState (KnownPeers PeerAddr -> Set PeerAddr
forall peeraddr. KnownPeers peeraddr -> Set peeraddr
KnownPeers.toSet (KnownPeers PeerAddr -> Set PeerAddr)
-> (PeerSelectionState PeerAddr peerconn -> KnownPeers PeerAddr)
-> PeerSelectionState PeerAddr peerconn
-> Set PeerAddr
forall b c a. (b -> c) -> (a -> b) -> a -> c
. PeerSelectionState PeerAddr peerconn -> KnownPeers PeerAddr
forall peeraddr peerconn.
PeerSelectionState peeraddr peerconn -> KnownPeers peeraddr
Governor.knownPeers) (GovernorMockEnvironment -> ConsensusMode
consensusMode GovernorMockEnvironment
env) Events TestTraceEvent
events
govAvailableEstablishedPeersSig :: Signal (Set PeerAddr)
govAvailableEstablishedPeersSig :: Signal (Set PeerAddr)
govAvailableEstablishedPeersSig =
(forall peerconn.
PeerSelectionState PeerAddr peerconn -> Set PeerAddr)
-> ConsensusMode -> Events TestTraceEvent -> Signal (Set PeerAddr)
forall a.
Eq a =>
(forall peerconn. PeerSelectionState PeerAddr peerconn -> a)
-> ConsensusMode -> Events TestTraceEvent -> Signal a
selectGovState
(\PeerSelectionState PeerAddr peerconn
x ->
Set PeerAddr -> KnownPeers PeerAddr -> Set PeerAddr
forall peeraddr.
Ord peeraddr =>
Set peeraddr -> KnownPeers peeraddr -> Set peeraddr
KnownPeers.getPeerSharingRequestPeers
(EstablishedPeers PeerAddr peerconn -> Set PeerAddr
forall peeraddr peerconn.
EstablishedPeers peeraddr peerconn -> Set peeraddr
EstablishedPeers.availableForPeerShare
(PeerSelectionState PeerAddr peerconn
-> EstablishedPeers PeerAddr peerconn
forall peeraddr peerconn.
PeerSelectionState peeraddr peerconn
-> EstablishedPeers peeraddr peerconn
Governor.establishedPeers PeerSelectionState PeerAddr peerconn
x)
Set PeerAddr -> Set PeerAddr -> Set PeerAddr
forall a. Ord a => Set a -> Set a -> Set a
Set.\\ (PeerSelectionState PeerAddr peerconn -> Set PeerAddr
forall peeraddr peerconn.
PeerSelectionState peeraddr peerconn -> Set peeraddr
Governor.inProgressDemoteToCold PeerSelectionState PeerAddr peerconn
x))
(PeerSelectionState PeerAddr peerconn -> KnownPeers PeerAddr
forall peeraddr peerconn.
PeerSelectionState peeraddr peerconn -> KnownPeers peeraddr
Governor.knownPeers PeerSelectionState PeerAddr peerconn
x))
(GovernorMockEnvironment -> ConsensusMode
consensusMode GovernorMockEnvironment
env)
Events TestTraceEvent
events
envPeerSharesEventsAsSig :: Signal (Maybe PeerAddr)
envPeerSharesEventsAsSig :: Signal (Maybe PeerAddr)
envPeerSharesEventsAsSig =
Events PeerAddr -> Signal (Maybe PeerAddr)
forall a. Events a -> Signal (Maybe a)
Signal.fromEvents
(Events PeerAddr -> Signal (Maybe PeerAddr))
-> (Events TestTraceEvent -> Events PeerAddr)
-> Events TestTraceEvent
-> Signal (Maybe PeerAddr)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (TraceMockEnv -> Maybe PeerAddr)
-> Events TraceMockEnv -> Events PeerAddr
forall a b. (a -> Maybe b) -> Events a -> Events b
Signal.selectEvents
(\case TraceEnvPeerShareRequest PeerAddr
addr Maybe ([PeerAddr], PeerShareTime)
_ -> PeerAddr -> Maybe PeerAddr
forall a. a -> Maybe a
Just PeerAddr
addr
TraceMockEnv
_ -> Maybe PeerAddr
forall a. Maybe a
Nothing)
(Events TraceMockEnv -> Events PeerAddr)
-> (Events TestTraceEvent -> Events TraceMockEnv)
-> Events TestTraceEvent
-> Events PeerAddr
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Events TestTraceEvent -> Events TraceMockEnv
selectEnvEvents
(Events TestTraceEvent -> Signal (Maybe PeerAddr))
-> Events TestTraceEvent -> Signal (Maybe PeerAddr)
forall a b. (a -> b) -> a -> b
$ Events TestTraceEvent
events
envPeerShareUnavailableSig :: Signal (Set PeerAddr)
envPeerShareUnavailableSig :: Signal (Set PeerAddr)
envPeerShareUnavailableSig =
DiffTime
-> (Maybe PeerAddr -> Set PeerAddr)
-> Signal (Maybe PeerAddr)
-> Signal (Set PeerAddr)
forall a b.
Ord b =>
DiffTime -> (a -> Set b) -> Signal a -> Signal (Set b)
Signal.keyedLinger
(DiffTime
60 DiffTime -> DiffTime -> DiffTime
forall a. Num a => a -> a -> a
* DiffTime
60)
(Set PeerAddr
-> (PeerAddr -> Set PeerAddr) -> Maybe PeerAddr -> Set PeerAddr
forall b a. b -> (a -> b) -> Maybe a -> b
maybe Set PeerAddr
forall a. Set a
Set.empty PeerAddr -> Set PeerAddr
forall a. a -> Set a
Set.singleton)
Signal (Maybe PeerAddr)
envPeerSharesEventsAsSig
govLedgerStateJudgementSig :: Signal LedgerStateJudgement
govLedgerStateJudgementSig :: Signal LedgerStateJudgement
govLedgerStateJudgementSig =
(forall peerconn.
PeerSelectionState PeerAddr peerconn -> LedgerStateJudgement)
-> ConsensusMode
-> Events TestTraceEvent
-> Signal LedgerStateJudgement
forall a.
Eq a =>
(forall peerconn. PeerSelectionState PeerAddr peerconn -> a)
-> ConsensusMode -> Events TestTraceEvent -> Signal a
selectGovState PeerSelectionState PeerAddr peerconn -> LedgerStateJudgement
forall peerconn.
PeerSelectionState PeerAddr peerconn -> LedgerStateJudgement
forall peeraddr peerconn.
PeerSelectionState peeraddr peerconn -> LedgerStateJudgement
Governor.ledgerStateJudgement (GovernorMockEnvironment -> ConsensusMode
consensusMode GovernorMockEnvironment
env) Events TestTraceEvent
events
govUseBootstrapPeersSig :: Signal UseBootstrapPeers
govUseBootstrapPeersSig :: Signal UseBootstrapPeers
govUseBootstrapPeersSig =
(forall peerconn.
PeerSelectionState PeerAddr peerconn -> UseBootstrapPeers)
-> ConsensusMode
-> Events TestTraceEvent
-> Signal UseBootstrapPeers
forall a.
Eq a =>
(forall peerconn. PeerSelectionState PeerAddr peerconn -> a)
-> ConsensusMode -> Events TestTraceEvent -> Signal a
selectGovState PeerSelectionState PeerAddr peerconn -> UseBootstrapPeers
forall peerconn.
PeerSelectionState PeerAddr peerconn -> UseBootstrapPeers
forall peeraddr peerconn.
PeerSelectionState peeraddr peerconn -> UseBootstrapPeers
Governor.bootstrapPeersFlag (GovernorMockEnvironment -> ConsensusMode
consensusMode GovernorMockEnvironment
env) Events TestTraceEvent
events
peerShareOpportunitiesSig :: Signal (Set PeerAddr)
peerShareOpportunitiesSig :: Signal (Set PeerAddr)
peerShareOpportunitiesSig =
Set PeerAddr -> Set PeerAddr -> Set PeerAddr
forall a. Ord a => Set a -> Set a -> Set a
(Set.\\) (Set PeerAddr -> Set PeerAddr -> Set PeerAddr)
-> Signal (Set PeerAddr) -> Signal (Set PeerAddr -> Set PeerAddr)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Signal (Set PeerAddr)
govAvailableEstablishedPeersSig
Signal (Set PeerAddr -> Set PeerAddr)
-> Signal (Set PeerAddr) -> Signal (Set PeerAddr)
forall a b. Signal (a -> b) -> Signal a -> Signal b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Signal (Set PeerAddr)
envPeerShareUnavailableSig
combinedSig :: Signal (Int,
Set PeerAddr,
Set PeerAddr,
Maybe PeerAddr,
LedgerStateJudgement,
UseBootstrapPeers
)
combinedSig :: Signal
(Int, Set PeerAddr, Set PeerAddr, Maybe PeerAddr,
LedgerStateJudgement, UseBootstrapPeers)
combinedSig =
(,,,,,) (Int
-> Set PeerAddr
-> Set PeerAddr
-> Maybe PeerAddr
-> LedgerStateJudgement
-> UseBootstrapPeers
-> (Int, Set PeerAddr, Set PeerAddr, Maybe PeerAddr,
LedgerStateJudgement, UseBootstrapPeers))
-> Signal Int
-> Signal
(Set PeerAddr
-> Set PeerAddr
-> Maybe PeerAddr
-> LedgerStateJudgement
-> UseBootstrapPeers
-> (Int, Set PeerAddr, Set PeerAddr, Maybe PeerAddr,
LedgerStateJudgement, UseBootstrapPeers))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Signal Int
govTargetsSig
Signal
(Set PeerAddr
-> Set PeerAddr
-> Maybe PeerAddr
-> LedgerStateJudgement
-> UseBootstrapPeers
-> (Int, Set PeerAddr, Set PeerAddr, Maybe PeerAddr,
LedgerStateJudgement, UseBootstrapPeers))
-> Signal (Set PeerAddr)
-> Signal
(Set PeerAddr
-> Maybe PeerAddr
-> LedgerStateJudgement
-> UseBootstrapPeers
-> (Int, Set PeerAddr, Set PeerAddr, Maybe PeerAddr,
LedgerStateJudgement, UseBootstrapPeers))
forall a b. Signal (a -> b) -> Signal a -> Signal b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Signal (Set PeerAddr)
govKnownPeersSig
Signal
(Set PeerAddr
-> Maybe PeerAddr
-> LedgerStateJudgement
-> UseBootstrapPeers
-> (Int, Set PeerAddr, Set PeerAddr, Maybe PeerAddr,
LedgerStateJudgement, UseBootstrapPeers))
-> Signal (Set PeerAddr)
-> Signal
(Maybe PeerAddr
-> LedgerStateJudgement
-> UseBootstrapPeers
-> (Int, Set PeerAddr, Set PeerAddr, Maybe PeerAddr,
LedgerStateJudgement, UseBootstrapPeers))
forall a b. Signal (a -> b) -> Signal a -> Signal b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Signal (Set PeerAddr)
peerShareOpportunitiesSig
Signal
(Maybe PeerAddr
-> LedgerStateJudgement
-> UseBootstrapPeers
-> (Int, Set PeerAddr, Set PeerAddr, Maybe PeerAddr,
LedgerStateJudgement, UseBootstrapPeers))
-> Signal (Maybe PeerAddr)
-> Signal
(LedgerStateJudgement
-> UseBootstrapPeers
-> (Int, Set PeerAddr, Set PeerAddr, Maybe PeerAddr,
LedgerStateJudgement, UseBootstrapPeers))
forall a b. Signal (a -> b) -> Signal a -> Signal b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Signal (Maybe PeerAddr)
envPeerSharesEventsAsSig
Signal
(LedgerStateJudgement
-> UseBootstrapPeers
-> (Int, Set PeerAddr, Set PeerAddr, Maybe PeerAddr,
LedgerStateJudgement, UseBootstrapPeers))
-> Signal LedgerStateJudgement
-> Signal
(UseBootstrapPeers
-> (Int, Set PeerAddr, Set PeerAddr, Maybe PeerAddr,
LedgerStateJudgement, UseBootstrapPeers))
forall a b. Signal (a -> b) -> Signal a -> Signal b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Signal LedgerStateJudgement
govLedgerStateJudgementSig
Signal
(UseBootstrapPeers
-> (Int, Set PeerAddr, Set PeerAddr, Maybe PeerAddr,
LedgerStateJudgement, UseBootstrapPeers))
-> Signal UseBootstrapPeers
-> Signal
(Int, Set PeerAddr, Set PeerAddr, Maybe PeerAddr,
LedgerStateJudgement, UseBootstrapPeers)
forall a b. Signal (a -> b) -> Signal a -> Signal b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Signal UseBootstrapPeers
govUseBootstrapPeersSig
peerShareOpportunitiesOkSig :: Signal Bool
peerShareOpportunitiesOkSig :: Signal Bool
peerShareOpportunitiesOkSig =
Time -> Signal Bool -> Signal Bool
forall a. Time -> Signal a -> Signal a
Signal.truncateAt (DiffTime -> Time
Time (DiffTime
60 DiffTime -> DiffTime -> DiffTime
forall a. Num a => a -> a -> a
* DiffTime
60 DiffTime -> DiffTime -> DiffTime
forall a. Num a => a -> a -> a
* DiffTime
10)) (Signal Bool -> Signal Bool) -> Signal Bool -> Signal Bool
forall a b. (a -> b) -> a -> b
$
PeerSharing
-> Signal
(Int, Set PeerAddr, Set PeerAddr, Maybe PeerAddr,
LedgerStateJudgement, UseBootstrapPeers)
-> Signal Bool
governorEventuallyTakesPeerShareOpportunities (GovernorMockEnvironment -> PeerSharing
peerSharingFlag GovernorMockEnvironment
env) Signal
(Int, Set PeerAddr, Set PeerAddr, Maybe PeerAddr,
LedgerStateJudgement, UseBootstrapPeers)
combinedSig
in TestName -> Property -> Property
forall prop. Testable prop => TestName -> prop -> Property
counterexample
TestName
"Signal key: (target, known peers, opportunities, peer share event)" (Property -> Property) -> Property -> Property
forall a b. (a -> b) -> a -> b
$
Int
-> ((Bool,
(Int, Set PeerAddr, Set PeerAddr, Maybe PeerAddr,
LedgerStateJudgement, UseBootstrapPeers))
-> TestName)
-> ((Bool,
(Int, Set PeerAddr, Set PeerAddr, Maybe PeerAddr,
LedgerStateJudgement, UseBootstrapPeers))
-> Bool)
-> Signal
(Bool,
(Int, Set PeerAddr, Set PeerAddr, Maybe PeerAddr,
LedgerStateJudgement, UseBootstrapPeers))
-> Property
forall a.
Int -> (a -> TestName) -> (a -> Bool) -> Signal a -> Property
signalProperty Int
20 ((Int, Set PeerAddr, Set PeerAddr, Maybe PeerAddr,
LedgerStateJudgement, UseBootstrapPeers)
-> TestName
forall a. Show a => a -> TestName
show ((Int, Set PeerAddr, Set PeerAddr, Maybe PeerAddr,
LedgerStateJudgement, UseBootstrapPeers)
-> TestName)
-> ((Bool,
(Int, Set PeerAddr, Set PeerAddr, Maybe PeerAddr,
LedgerStateJudgement, UseBootstrapPeers))
-> (Int, Set PeerAddr, Set PeerAddr, Maybe PeerAddr,
LedgerStateJudgement, UseBootstrapPeers))
-> (Bool,
(Int, Set PeerAddr, Set PeerAddr, Maybe PeerAddr,
LedgerStateJudgement, UseBootstrapPeers))
-> TestName
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Bool,
(Int, Set PeerAddr, Set PeerAddr, Maybe PeerAddr,
LedgerStateJudgement, UseBootstrapPeers))
-> (Int, Set PeerAddr, Set PeerAddr, Maybe PeerAddr,
LedgerStateJudgement, UseBootstrapPeers)
forall a b. (a, b) -> b
snd) (Bool,
(Int, Set PeerAddr, Set PeerAddr, Maybe PeerAddr,
LedgerStateJudgement, UseBootstrapPeers))
-> Bool
forall a b. (a, b) -> a
fst (Signal
(Bool,
(Int, Set PeerAddr, Set PeerAddr, Maybe PeerAddr,
LedgerStateJudgement, UseBootstrapPeers))
-> Property)
-> Signal
(Bool,
(Int, Set PeerAddr, Set PeerAddr, Maybe PeerAddr,
LedgerStateJudgement, UseBootstrapPeers))
-> Property
forall a b. (a -> b) -> a -> b
$
(,) (Bool
-> (Int, Set PeerAddr, Set PeerAddr, Maybe PeerAddr,
LedgerStateJudgement, UseBootstrapPeers)
-> (Bool,
(Int, Set PeerAddr, Set PeerAddr, Maybe PeerAddr,
LedgerStateJudgement, UseBootstrapPeers)))
-> Signal Bool
-> Signal
((Int, Set PeerAddr, Set PeerAddr, Maybe PeerAddr,
LedgerStateJudgement, UseBootstrapPeers)
-> (Bool,
(Int, Set PeerAddr, Set PeerAddr, Maybe PeerAddr,
LedgerStateJudgement, UseBootstrapPeers)))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Signal Bool
peerShareOpportunitiesOkSig
Signal
((Int, Set PeerAddr, Set PeerAddr, Maybe PeerAddr,
LedgerStateJudgement, UseBootstrapPeers)
-> (Bool,
(Int, Set PeerAddr, Set PeerAddr, Maybe PeerAddr,
LedgerStateJudgement, UseBootstrapPeers)))
-> Signal
(Int, Set PeerAddr, Set PeerAddr, Maybe PeerAddr,
LedgerStateJudgement, UseBootstrapPeers)
-> Signal
(Bool,
(Int, Set PeerAddr, Set PeerAddr, Maybe PeerAddr,
LedgerStateJudgement, UseBootstrapPeers))
forall a b. Signal (a -> b) -> Signal a -> Signal b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Signal
(Int, Set PeerAddr, Set PeerAddr, Maybe PeerAddr,
LedgerStateJudgement, UseBootstrapPeers)
combinedSig
governorEventuallyTakesPeerShareOpportunities
:: PeerSharing
-> Signal (Int, Set PeerAddr, Set PeerAddr, Maybe PeerAddr, LedgerStateJudgement, UseBootstrapPeers)
-> Signal Bool
governorEventuallyTakesPeerShareOpportunities :: PeerSharing
-> Signal
(Int, Set PeerAddr, Set PeerAddr, Maybe PeerAddr,
LedgerStateJudgement, UseBootstrapPeers)
-> Signal Bool
governorEventuallyTakesPeerShareOpportunities PeerSharing
peerSharing =
(Bool -> Bool) -> Signal Bool -> Signal Bool
forall a b. (a -> b) -> Signal a -> Signal b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Bool -> Bool
not
(Signal Bool -> Signal Bool)
-> (Signal
(Int, Set PeerAddr, Set PeerAddr, Maybe PeerAddr,
LedgerStateJudgement, UseBootstrapPeers)
-> Signal Bool)
-> Signal
(Int, Set PeerAddr, Set PeerAddr, Maybe PeerAddr,
LedgerStateJudgement, UseBootstrapPeers)
-> Signal Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. DiffTime
-> ((Int, Set PeerAddr, Set PeerAddr, Maybe PeerAddr,
LedgerStateJudgement, UseBootstrapPeers)
-> Bool)
-> Signal
(Int, Set PeerAddr, Set PeerAddr, Maybe PeerAddr,
LedgerStateJudgement, UseBootstrapPeers)
-> Signal Bool
forall a. DiffTime -> (a -> Bool) -> Signal a -> Signal Bool
Signal.timeout DiffTime
timeLimit (Int, Set PeerAddr, Set PeerAddr, Maybe PeerAddr,
LedgerStateJudgement, UseBootstrapPeers)
-> Bool
forall {a} {a} {a}.
(Int, Set a, Set a, Maybe a, LedgerStateJudgement,
UseBootstrapPeers)
-> Bool
badState
where
timeLimit :: DiffTime
timeLimit :: DiffTime
timeLimit = DiffTime
30
badState :: (Int, Set a, Set a, Maybe a, LedgerStateJudgement,
UseBootstrapPeers)
-> Bool
badState (Int
target, Set a
govKnownPeers, Set a
peerShareOpportunities, Maybe a
peerShareEvent, LedgerStateJudgement
ledgerState, UseBootstrapPeers
useBootstrapPeersFlag) =
Set a -> Int
forall a. Set a -> Int
Set.size Set a
govKnownPeers Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
< Int
target
Bool -> Bool -> Bool
&& Bool -> Bool
not (Set a -> Bool
forall a. Set a -> Bool
Set.null Set a
peerShareOpportunities)
Bool -> Bool -> Bool
&& Maybe a -> Bool
forall a. Maybe a -> Bool
isNothing Maybe a
peerShareEvent
Bool -> Bool -> Bool
&& PeerSharing
peerSharing PeerSharing -> PeerSharing -> Bool
forall a. Eq a => a -> a -> Bool
/= PeerSharing
PeerSharingDisabled
Bool -> Bool -> Bool
&& Bool -> Bool
not (UseBootstrapPeers -> LedgerStateJudgement -> Bool
requiresBootstrapPeers UseBootstrapPeers
useBootstrapPeersFlag LedgerStateJudgement
ledgerState)
prop_governor_target_known_3_not_too_chatty :: MaxTime
-> GovernorMockEnvironment
-> Property
prop_governor_target_known_3_not_too_chatty :: MaxTime -> GovernorMockEnvironment -> Property
prop_governor_target_known_3_not_too_chatty (MaxTime Time
maxTime) GovernorMockEnvironment
env =
let events :: Events TestTraceEvent
events = Time -> [(Time, TestTraceEvent)] -> Events TestTraceEvent
forall a. Time -> [(Time, a)] -> Events a
Signal.eventsFromListUpToTime Time
maxTime
([(Time, TestTraceEvent)] -> Events TestTraceEvent)
-> (GovernorMockEnvironment -> [(Time, TestTraceEvent)])
-> GovernorMockEnvironment
-> Events TestTraceEvent
forall b c a. (b -> c) -> (a -> b) -> a -> c
. SimTrace Void -> [(Time, TestTraceEvent)]
forall a. SimTrace a -> [(Time, TestTraceEvent)]
selectPeerSelectionTraceEvents
(SimTrace Void -> [(Time, TestTraceEvent)])
-> (GovernorMockEnvironment -> SimTrace Void)
-> GovernorMockEnvironment
-> [(Time, TestTraceEvent)]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. GovernorMockEnvironment -> SimTrace Void
runGovernorInMockEnvironment
(GovernorMockEnvironment -> Events TestTraceEvent)
-> GovernorMockEnvironment -> Events TestTraceEvent
forall a b. (a -> b) -> a -> b
$ GovernorMockEnvironment
env
peerShareOk :: Maybe (Set a) -> Set a -> Bool
peerShareOk Maybe (Set a)
Nothing Set a
_ = Bool
True
peerShareOk (Just Set a
peers) Set a
unavailable =
Set a -> Bool
forall a. Set a -> Bool
Set.null (Set a
peers Set a -> Set a -> Set a
forall a. Ord a => Set a -> Set a -> Set a
`Set.intersection` Set a
unavailable)
in Int
-> ((Maybe (Set PeerAddr), Set PeerAddr) -> TestName)
-> ((Maybe (Set PeerAddr), Set PeerAddr) -> Bool)
-> Signal (Maybe (Set PeerAddr), Set PeerAddr)
-> Property
forall a.
Int -> (a -> TestName) -> (a -> Bool) -> Signal a -> Property
signalProperty Int
20 (Maybe (Set PeerAddr), Set PeerAddr) -> TestName
forall a. Show a => a -> TestName
show ((Maybe (Set PeerAddr) -> Set PeerAddr -> Bool)
-> (Maybe (Set PeerAddr), Set PeerAddr) -> Bool
forall a b c. (a -> b -> c) -> (a, b) -> c
uncurry Maybe (Set PeerAddr) -> Set PeerAddr -> Bool
forall {a}. Ord a => Maybe (Set a) -> Set a -> Bool
peerShareOk) (Signal (Maybe (Set PeerAddr), Set PeerAddr) -> Property)
-> Signal (Maybe (Set PeerAddr), Set PeerAddr) -> Property
forall a b. (a -> b) -> a -> b
$
DiffTime
-> Events TestTraceEvent
-> Signal (Maybe (Set PeerAddr), Set PeerAddr)
recentPeerShareActivity DiffTime
3600 Events TestTraceEvent
events
recentPeerShareActivity :: DiffTime
-> Events TestTraceEvent
-> Signal (Maybe (Set PeerAddr), Set PeerAddr)
recentPeerShareActivity :: DiffTime
-> Events TestTraceEvent
-> Signal (Maybe (Set PeerAddr), Set PeerAddr)
recentPeerShareActivity DiffTime
d =
(Maybe (Set PeerAddr), Set PeerAddr)
-> Events (Maybe (Set PeerAddr), Set PeerAddr)
-> Signal (Maybe (Set PeerAddr), Set PeerAddr)
forall a. a -> Events a -> Signal a
Signal.fromChangeEvents (Maybe (Set PeerAddr)
forall a. Maybe a
Nothing, Set PeerAddr
forall a. Set a
Set.empty)
(Events (Maybe (Set PeerAddr), Set PeerAddr)
-> Signal (Maybe (Set PeerAddr), Set PeerAddr))
-> (Events TestTraceEvent
-> Events (Maybe (Set PeerAddr), Set PeerAddr))
-> Events TestTraceEvent
-> Signal (Maybe (Set PeerAddr), Set PeerAddr)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ([E TestTraceEvent] -> [E (Maybe (Set PeerAddr), Set PeerAddr)])
-> Events TestTraceEvent
-> Events (Maybe (Set PeerAddr), Set PeerAddr)
forall a b. ([E a] -> [E b]) -> Events a -> Events b
Signal.primitiveTransformEvents (Set PeerAddr
-> OrdPSQ PeerAddr Time ()
-> [E TestTraceEvent]
-> [E (Maybe (Set PeerAddr), Set PeerAddr)]
go Set PeerAddr
forall a. Set a
Set.empty OrdPSQ PeerAddr Time ()
forall k p v. OrdPSQ k p v
PSQ.empty)
where
go :: Set PeerAddr
-> PSQ.OrdPSQ PeerAddr Time ()
-> [E TestTraceEvent]
-> [E (Maybe (Set PeerAddr), Set PeerAddr)]
go :: Set PeerAddr
-> OrdPSQ PeerAddr Time ()
-> [E TestTraceEvent]
-> [E (Maybe (Set PeerAddr), Set PeerAddr)]
go !Set PeerAddr
recentSet !OrdPSQ PeerAddr Time ()
recentPSQ txs :: [E TestTraceEvent]
txs@(E (TS Time
t Int
_) TestTraceEvent
_ : [E TestTraceEvent]
_)
| Just (PeerAddr
k, Time
t', ()
_, OrdPSQ PeerAddr Time ()
recentPSQ') <- OrdPSQ PeerAddr Time ()
-> Maybe (PeerAddr, Time, (), OrdPSQ PeerAddr Time ())
forall k p v.
(Ord k, Ord p) =>
OrdPSQ k p v -> Maybe (k, p, v, OrdPSQ k p v)
PSQ.minView OrdPSQ PeerAddr Time ()
recentPSQ
, Time
t' Time -> Time -> Bool
forall a. Ord a => a -> a -> Bool
<= Time
t
, let recentSet' :: Set PeerAddr
recentSet' = PeerAddr -> Set PeerAddr -> Set PeerAddr
forall a. Ord a => a -> Set a -> Set a
Set.delete PeerAddr
k Set PeerAddr
recentSet
= TS
-> (Maybe (Set PeerAddr), Set PeerAddr)
-> E (Maybe (Set PeerAddr), Set PeerAddr)
forall a. TS -> a -> E a
E (Time -> Int -> TS
TS Time
t' Int
0) (Maybe (Set PeerAddr)
forall a. Maybe a
Nothing, Set PeerAddr
recentSet')
E (Maybe (Set PeerAddr), Set PeerAddr)
-> [E (Maybe (Set PeerAddr), Set PeerAddr)]
-> [E (Maybe (Set PeerAddr), Set PeerAddr)]
forall a. a -> [a] -> [a]
: Set PeerAddr
-> OrdPSQ PeerAddr Time ()
-> [E TestTraceEvent]
-> [E (Maybe (Set PeerAddr), Set PeerAddr)]
go Set PeerAddr
recentSet' OrdPSQ PeerAddr Time ()
recentPSQ' [E TestTraceEvent]
txs
go !Set PeerAddr
recentSet !OrdPSQ PeerAddr Time ()
recentPSQ
(E (TS Time
t Int
i) (GovernorEvent (TracePeerShareRequests Int
_ Int
_ PeerSharingAmount
_ Set PeerAddr
_ Set PeerAddr
addrs)) : [E TestTraceEvent]
txs) =
let recentSet' :: Set PeerAddr
recentSet' = Set PeerAddr
recentSet Set PeerAddr -> Set PeerAddr -> Set PeerAddr
forall a. Semigroup a => a -> a -> a
<> Set PeerAddr
addrs
recentPSQ' :: OrdPSQ PeerAddr Time ()
recentPSQ' = (OrdPSQ PeerAddr Time () -> PeerAddr -> OrdPSQ PeerAddr Time ())
-> OrdPSQ PeerAddr Time ()
-> Set PeerAddr
-> OrdPSQ PeerAddr Time ()
forall b a. (b -> a -> b) -> b -> Set a -> b
forall (t :: * -> *) b a.
Foldable t =>
(b -> a -> b) -> b -> t a -> b
List.foldl' (\OrdPSQ PeerAddr Time ()
q PeerAddr
a -> PeerAddr
-> Time -> () -> OrdPSQ PeerAddr Time () -> OrdPSQ PeerAddr Time ()
forall k p v.
(Ord k, Ord p) =>
k -> p -> v -> OrdPSQ k p v -> OrdPSQ k p v
PSQ.insert PeerAddr
a Time
t' () OrdPSQ PeerAddr Time ()
q) OrdPSQ PeerAddr Time ()
recentPSQ Set PeerAddr
addrs
t' :: Time
t' = DiffTime
d DiffTime -> Time -> Time
`addTime` Time
t
in TS
-> (Maybe (Set PeerAddr), Set PeerAddr)
-> E (Maybe (Set PeerAddr), Set PeerAddr)
forall a. TS -> a -> E a
E (Time -> Int -> TS
TS Time
t Int
i) (Set PeerAddr -> Maybe (Set PeerAddr)
forall a. a -> Maybe a
Just Set PeerAddr
addrs, Set PeerAddr
recentSet)
E (Maybe (Set PeerAddr), Set PeerAddr)
-> [E (Maybe (Set PeerAddr), Set PeerAddr)]
-> [E (Maybe (Set PeerAddr), Set PeerAddr)]
forall a. a -> [a] -> [a]
: TS
-> (Maybe (Set PeerAddr), Set PeerAddr)
-> E (Maybe (Set PeerAddr), Set PeerAddr)
forall a. TS -> a -> E a
E (Time -> Int -> TS
TS Time
t (Int
iInt -> Int -> Int
forall a. Num a => a -> a -> a
+Int
1)) (Maybe (Set PeerAddr)
forall a. Maybe a
Nothing, Set PeerAddr
recentSet')
E (Maybe (Set PeerAddr), Set PeerAddr)
-> [E (Maybe (Set PeerAddr), Set PeerAddr)]
-> [E (Maybe (Set PeerAddr), Set PeerAddr)]
forall a. a -> [a] -> [a]
: Set PeerAddr
-> OrdPSQ PeerAddr Time ()
-> [E TestTraceEvent]
-> [E (Maybe (Set PeerAddr), Set PeerAddr)]
go Set PeerAddr
recentSet' OrdPSQ PeerAddr Time ()
recentPSQ' [E TestTraceEvent]
txs
go !Set PeerAddr
recentSet !OrdPSQ PeerAddr Time ()
recentPSQ
(E TS
t (GovernorEvent (TraceDemoteWarmDone Int
_ Int
_ PeerAddr
addr)) : [E TestTraceEvent]
txs) =
let recentSet' :: Set PeerAddr
recentSet' = PeerAddr -> Set PeerAddr -> Set PeerAddr
forall a. Ord a => a -> Set a -> Set a
Set.delete PeerAddr
addr Set PeerAddr
recentSet
recentPSQ' :: OrdPSQ PeerAddr Time ()
recentPSQ' = PeerAddr -> OrdPSQ PeerAddr Time () -> OrdPSQ PeerAddr Time ()
forall k p v. (Ord k, Ord p) => k -> OrdPSQ k p v -> OrdPSQ k p v
PSQ.delete PeerAddr
addr OrdPSQ PeerAddr Time ()
recentPSQ
in TS
-> (Maybe (Set PeerAddr), Set PeerAddr)
-> E (Maybe (Set PeerAddr), Set PeerAddr)
forall a. TS -> a -> E a
E TS
t (Maybe (Set PeerAddr)
forall a. Maybe a
Nothing, Set PeerAddr
recentSet')
E (Maybe (Set PeerAddr), Set PeerAddr)
-> [E (Maybe (Set PeerAddr), Set PeerAddr)]
-> [E (Maybe (Set PeerAddr), Set PeerAddr)]
forall a. a -> [a] -> [a]
: Set PeerAddr
-> OrdPSQ PeerAddr Time ()
-> [E TestTraceEvent]
-> [E (Maybe (Set PeerAddr), Set PeerAddr)]
go Set PeerAddr
recentSet' OrdPSQ PeerAddr Time ()
recentPSQ' [E TestTraceEvent]
txs
go !Set PeerAddr
recentSet !OrdPSQ PeerAddr Time ()
recentPSQ
(E TS
t (GovernorEvent (TraceDemoteWarmBigLedgerPeerDone Int
_ Int
_ PeerAddr
addr)) : [E TestTraceEvent]
txs) =
let recentSet' :: Set PeerAddr
recentSet' = PeerAddr -> Set PeerAddr -> Set PeerAddr
forall a. Ord a => a -> Set a -> Set a
Set.delete PeerAddr
addr Set PeerAddr
recentSet
recentPSQ' :: OrdPSQ PeerAddr Time ()
recentPSQ' = PeerAddr -> OrdPSQ PeerAddr Time () -> OrdPSQ PeerAddr Time ()
forall k p v. (Ord k, Ord p) => k -> OrdPSQ k p v -> OrdPSQ k p v
PSQ.delete PeerAddr
addr OrdPSQ PeerAddr Time ()
recentPSQ
in TS
-> (Maybe (Set PeerAddr), Set PeerAddr)
-> E (Maybe (Set PeerAddr), Set PeerAddr)
forall a. TS -> a -> E a
E TS
t (Maybe (Set PeerAddr)
forall a. Maybe a
Nothing, Set PeerAddr
recentSet')
E (Maybe (Set PeerAddr), Set PeerAddr)
-> [E (Maybe (Set PeerAddr), Set PeerAddr)]
-> [E (Maybe (Set PeerAddr), Set PeerAddr)]
forall a. a -> [a] -> [a]
: Set PeerAddr
-> OrdPSQ PeerAddr Time ()
-> [E TestTraceEvent]
-> [E (Maybe (Set PeerAddr), Set PeerAddr)]
go Set PeerAddr
recentSet' OrdPSQ PeerAddr Time ()
recentPSQ' [E TestTraceEvent]
txs
go !Set PeerAddr
recentSet !OrdPSQ PeerAddr Time ()
recentPSQ
(E TS
t (GovernorEvent (TraceDemoteLocalAsynchronous Map PeerAddr (PeerStatus, Maybe RepromoteDelay)
m)) : [E TestTraceEvent]
txs) =
let peersDemotedToCold :: [PeerAddr]
peersDemotedToCold = (PeerAddr
-> (PeerStatus, Maybe RepromoteDelay) -> [PeerAddr] -> [PeerAddr])
-> [PeerAddr]
-> Map PeerAddr (PeerStatus, Maybe RepromoteDelay)
-> [PeerAddr]
forall k a b. (k -> a -> b -> b) -> b -> Map k a -> b
Map.foldrWithKey'
(\PeerAddr
k (PeerStatus, Maybe RepromoteDelay)
v [PeerAddr]
r -> case (PeerStatus, Maybe RepromoteDelay)
v of
(PeerStatus
PeerCold, Maybe RepromoteDelay
_) -> PeerAddr
k PeerAddr -> [PeerAddr] -> [PeerAddr]
forall a. a -> [a] -> [a]
: [PeerAddr]
r
(PeerStatus
PeerCooling, Maybe RepromoteDelay
_) -> PeerAddr
k PeerAddr -> [PeerAddr] -> [PeerAddr]
forall a. a -> [a] -> [a]
: [PeerAddr]
r
(PeerStatus, Maybe RepromoteDelay)
_ -> [PeerAddr]
r
) [] Map PeerAddr (PeerStatus, Maybe RepromoteDelay)
m
recentSet' :: Set PeerAddr
recentSet' = (Set PeerAddr -> PeerAddr -> Set PeerAddr)
-> Set PeerAddr -> [PeerAddr] -> Set PeerAddr
forall b a. (b -> a -> b) -> b -> [a] -> b
forall (t :: * -> *) b a.
Foldable t =>
(b -> a -> b) -> b -> t a -> b
List.foldl' ((PeerAddr -> Set PeerAddr -> Set PeerAddr)
-> Set PeerAddr -> PeerAddr -> Set PeerAddr
forall a b c. (a -> b -> c) -> b -> a -> c
flip PeerAddr -> Set PeerAddr -> Set PeerAddr
forall a. Ord a => a -> Set a -> Set a
Set.delete) Set PeerAddr
recentSet [PeerAddr]
peersDemotedToCold
recentPSQ' :: OrdPSQ PeerAddr Time ()
recentPSQ' = (OrdPSQ PeerAddr Time () -> PeerAddr -> OrdPSQ PeerAddr Time ())
-> OrdPSQ PeerAddr Time () -> [PeerAddr] -> OrdPSQ PeerAddr Time ()
forall b a. (b -> a -> b) -> b -> [a] -> b
forall (t :: * -> *) b a.
Foldable t =>
(b -> a -> b) -> b -> t a -> b
List.foldl' ((PeerAddr -> OrdPSQ PeerAddr Time () -> OrdPSQ PeerAddr Time ())
-> OrdPSQ PeerAddr Time () -> PeerAddr -> OrdPSQ PeerAddr Time ()
forall a b c. (a -> b -> c) -> b -> a -> c
flip PeerAddr -> OrdPSQ PeerAddr Time () -> OrdPSQ PeerAddr Time ()
forall k p v. (Ord k, Ord p) => k -> OrdPSQ k p v -> OrdPSQ k p v
PSQ.delete) OrdPSQ PeerAddr Time ()
recentPSQ [PeerAddr]
peersDemotedToCold
in TS
-> (Maybe (Set PeerAddr), Set PeerAddr)
-> E (Maybe (Set PeerAddr), Set PeerAddr)
forall a. TS -> a -> E a
E TS
t (Maybe (Set PeerAddr)
forall a. Maybe a
Nothing, Set PeerAddr
recentSet')
E (Maybe (Set PeerAddr), Set PeerAddr)
-> [E (Maybe (Set PeerAddr), Set PeerAddr)]
-> [E (Maybe (Set PeerAddr), Set PeerAddr)]
forall a. a -> [a] -> [a]
: Set PeerAddr
-> OrdPSQ PeerAddr Time ()
-> [E TestTraceEvent]
-> [E (Maybe (Set PeerAddr), Set PeerAddr)]
go Set PeerAddr
recentSet' OrdPSQ PeerAddr Time ()
recentPSQ' [E TestTraceEvent]
txs
go !Set PeerAddr
recentSet !OrdPSQ PeerAddr Time ()
recentPSQ
(E TS
t (GovernorEvent (TraceDemoteAsynchronous Map PeerAddr (PeerStatus, Maybe RepromoteDelay)
m)) : [E TestTraceEvent]
txs) =
let peersDemotedToCold :: [PeerAddr]
peersDemotedToCold = (PeerAddr
-> (PeerStatus, Maybe RepromoteDelay) -> [PeerAddr] -> [PeerAddr])
-> [PeerAddr]
-> Map PeerAddr (PeerStatus, Maybe RepromoteDelay)
-> [PeerAddr]
forall k a b. (k -> a -> b -> b) -> b -> Map k a -> b
Map.foldrWithKey'
(\PeerAddr
k (PeerStatus, Maybe RepromoteDelay)
v [PeerAddr]
r -> case (PeerStatus, Maybe RepromoteDelay)
v of
(PeerStatus
PeerCold, Maybe RepromoteDelay
_) -> PeerAddr
k PeerAddr -> [PeerAddr] -> [PeerAddr]
forall a. a -> [a] -> [a]
: [PeerAddr]
r
(PeerStatus
PeerCooling, Maybe RepromoteDelay
_) -> PeerAddr
k PeerAddr -> [PeerAddr] -> [PeerAddr]
forall a. a -> [a] -> [a]
: [PeerAddr]
r
(PeerStatus, Maybe RepromoteDelay)
_ -> [PeerAddr]
r
) [] Map PeerAddr (PeerStatus, Maybe RepromoteDelay)
m
recentSet' :: Set PeerAddr
recentSet' = (Set PeerAddr -> PeerAddr -> Set PeerAddr)
-> Set PeerAddr -> [PeerAddr] -> Set PeerAddr
forall b a. (b -> a -> b) -> b -> [a] -> b
forall (t :: * -> *) b a.
Foldable t =>
(b -> a -> b) -> b -> t a -> b
List.foldl' ((PeerAddr -> Set PeerAddr -> Set PeerAddr)
-> Set PeerAddr -> PeerAddr -> Set PeerAddr
forall a b c. (a -> b -> c) -> b -> a -> c
flip PeerAddr -> Set PeerAddr -> Set PeerAddr
forall a. Ord a => a -> Set a -> Set a
Set.delete) Set PeerAddr
recentSet [PeerAddr]
peersDemotedToCold
recentPSQ' :: OrdPSQ PeerAddr Time ()
recentPSQ' = (OrdPSQ PeerAddr Time () -> PeerAddr -> OrdPSQ PeerAddr Time ())
-> OrdPSQ PeerAddr Time () -> [PeerAddr] -> OrdPSQ PeerAddr Time ()
forall b a. (b -> a -> b) -> b -> [a] -> b
forall (t :: * -> *) b a.
Foldable t =>
(b -> a -> b) -> b -> t a -> b
List.foldl' ((PeerAddr -> OrdPSQ PeerAddr Time () -> OrdPSQ PeerAddr Time ())
-> OrdPSQ PeerAddr Time () -> PeerAddr -> OrdPSQ PeerAddr Time ()
forall a b c. (a -> b -> c) -> b -> a -> c
flip PeerAddr -> OrdPSQ PeerAddr Time () -> OrdPSQ PeerAddr Time ()
forall k p v. (Ord k, Ord p) => k -> OrdPSQ k p v -> OrdPSQ k p v
PSQ.delete) OrdPSQ PeerAddr Time ()
recentPSQ [PeerAddr]
peersDemotedToCold
in TS
-> (Maybe (Set PeerAddr), Set PeerAddr)
-> E (Maybe (Set PeerAddr), Set PeerAddr)
forall a. TS -> a -> E a
E TS
t (Maybe (Set PeerAddr)
forall a. Maybe a
Nothing, Set PeerAddr
recentSet')
E (Maybe (Set PeerAddr), Set PeerAddr)
-> [E (Maybe (Set PeerAddr), Set PeerAddr)]
-> [E (Maybe (Set PeerAddr), Set PeerAddr)]
forall a. a -> [a] -> [a]
: Set PeerAddr
-> OrdPSQ PeerAddr Time ()
-> [E TestTraceEvent]
-> [E (Maybe (Set PeerAddr), Set PeerAddr)]
go Set PeerAddr
recentSet' OrdPSQ PeerAddr Time ()
recentPSQ' [E TestTraceEvent]
txs
go !Set PeerAddr
recentSet !OrdPSQ PeerAddr Time ()
recentPSQ
(E TS
t (GovernorEvent (TraceDemoteBigLedgerPeersAsynchronous Map PeerAddr (PeerStatus, Maybe RepromoteDelay)
m)) : [E TestTraceEvent]
txs) =
let peersDemotedToCold :: [PeerAddr]
peersDemotedToCold = (PeerAddr
-> (PeerStatus, Maybe RepromoteDelay) -> [PeerAddr] -> [PeerAddr])
-> [PeerAddr]
-> Map PeerAddr (PeerStatus, Maybe RepromoteDelay)
-> [PeerAddr]
forall k a b. (k -> a -> b -> b) -> b -> Map k a -> b
Map.foldrWithKey'
(\PeerAddr
k (PeerStatus, Maybe RepromoteDelay)
v [PeerAddr]
r -> case (PeerStatus, Maybe RepromoteDelay)
v of
(PeerStatus
PeerCold, Maybe RepromoteDelay
_) -> PeerAddr
k PeerAddr -> [PeerAddr] -> [PeerAddr]
forall a. a -> [a] -> [a]
: [PeerAddr]
r
(PeerStatus
PeerCooling, Maybe RepromoteDelay
_) -> PeerAddr
k PeerAddr -> [PeerAddr] -> [PeerAddr]
forall a. a -> [a] -> [a]
: [PeerAddr]
r
(PeerStatus, Maybe RepromoteDelay)
_ -> [PeerAddr]
r
) [] Map PeerAddr (PeerStatus, Maybe RepromoteDelay)
m
recentSet' :: Set PeerAddr
recentSet' = (Set PeerAddr -> PeerAddr -> Set PeerAddr)
-> Set PeerAddr -> [PeerAddr] -> Set PeerAddr
forall b a. (b -> a -> b) -> b -> [a] -> b
forall (t :: * -> *) b a.
Foldable t =>
(b -> a -> b) -> b -> t a -> b
List.foldl' ((PeerAddr -> Set PeerAddr -> Set PeerAddr)
-> Set PeerAddr -> PeerAddr -> Set PeerAddr
forall a b c. (a -> b -> c) -> b -> a -> c
flip PeerAddr -> Set PeerAddr -> Set PeerAddr
forall a. Ord a => a -> Set a -> Set a
Set.delete) Set PeerAddr
recentSet [PeerAddr]
peersDemotedToCold
recentPSQ' :: OrdPSQ PeerAddr Time ()
recentPSQ' = (OrdPSQ PeerAddr Time () -> PeerAddr -> OrdPSQ PeerAddr Time ())
-> OrdPSQ PeerAddr Time () -> [PeerAddr] -> OrdPSQ PeerAddr Time ()
forall b a. (b -> a -> b) -> b -> [a] -> b
forall (t :: * -> *) b a.
Foldable t =>
(b -> a -> b) -> b -> t a -> b
List.foldl' ((PeerAddr -> OrdPSQ PeerAddr Time () -> OrdPSQ PeerAddr Time ())
-> OrdPSQ PeerAddr Time () -> PeerAddr -> OrdPSQ PeerAddr Time ()
forall a b c. (a -> b -> c) -> b -> a -> c
flip PeerAddr -> OrdPSQ PeerAddr Time () -> OrdPSQ PeerAddr Time ()
forall k p v. (Ord k, Ord p) => k -> OrdPSQ k p v -> OrdPSQ k p v
PSQ.delete) OrdPSQ PeerAddr Time ()
recentPSQ [PeerAddr]
peersDemotedToCold
in TS
-> (Maybe (Set PeerAddr), Set PeerAddr)
-> E (Maybe (Set PeerAddr), Set PeerAddr)
forall a. TS -> a -> E a
E TS
t (Maybe (Set PeerAddr)
forall a. Maybe a
Nothing, Set PeerAddr
recentSet')
E (Maybe (Set PeerAddr), Set PeerAddr)
-> [E (Maybe (Set PeerAddr), Set PeerAddr)]
-> [E (Maybe (Set PeerAddr), Set PeerAddr)]
forall a. a -> [a] -> [a]
: Set PeerAddr
-> OrdPSQ PeerAddr Time ()
-> [E TestTraceEvent]
-> [E (Maybe (Set PeerAddr), Set PeerAddr)]
go Set PeerAddr
recentSet' OrdPSQ PeerAddr Time ()
recentPSQ' [E TestTraceEvent]
txs
go !Set PeerAddr
recentSet !OrdPSQ PeerAddr Time ()
recentPSQ
(E TS
t (GovernorEvent (TracePromoteWarmBigLedgerPeerFailed Int
_ Int
_ PeerAddr
addr SomeException
_)) : [E TestTraceEvent]
txs) =
let recentSet' :: Set PeerAddr
recentSet' = PeerAddr -> Set PeerAddr -> Set PeerAddr
forall a. Ord a => a -> Set a -> Set a
Set.delete PeerAddr
addr Set PeerAddr
recentSet
recentPSQ' :: OrdPSQ PeerAddr Time ()
recentPSQ' = PeerAddr -> OrdPSQ PeerAddr Time () -> OrdPSQ PeerAddr Time ()
forall k p v. (Ord k, Ord p) => k -> OrdPSQ k p v -> OrdPSQ k p v
PSQ.delete PeerAddr
addr OrdPSQ PeerAddr Time ()
recentPSQ
in TS
-> (Maybe (Set PeerAddr), Set PeerAddr)
-> E (Maybe (Set PeerAddr), Set PeerAddr)
forall a. TS -> a -> E a
E TS
t (Maybe (Set PeerAddr)
forall a. Maybe a
Nothing, Set PeerAddr
recentSet')
E (Maybe (Set PeerAddr), Set PeerAddr)
-> [E (Maybe (Set PeerAddr), Set PeerAddr)]
-> [E (Maybe (Set PeerAddr), Set PeerAddr)]
forall a. a -> [a] -> [a]
: Set PeerAddr
-> OrdPSQ PeerAddr Time ()
-> [E TestTraceEvent]
-> [E (Maybe (Set PeerAddr), Set PeerAddr)]
go Set PeerAddr
recentSet' OrdPSQ PeerAddr Time ()
recentPSQ' [E TestTraceEvent]
txs
go !Set PeerAddr
recentSet !OrdPSQ PeerAddr Time ()
recentPSQ
(E TS
t (GovernorEvent (TracePromoteWarmFailed Int
_ Int
_ PeerAddr
addr SomeException
_)) : [E TestTraceEvent]
txs) =
let recentSet' :: Set PeerAddr
recentSet' = PeerAddr -> Set PeerAddr -> Set PeerAddr
forall a. Ord a => a -> Set a -> Set a
Set.delete PeerAddr
addr Set PeerAddr
recentSet
recentPSQ' :: OrdPSQ PeerAddr Time ()
recentPSQ' = PeerAddr -> OrdPSQ PeerAddr Time () -> OrdPSQ PeerAddr Time ()
forall k p v. (Ord k, Ord p) => k -> OrdPSQ k p v -> OrdPSQ k p v
PSQ.delete PeerAddr
addr OrdPSQ PeerAddr Time ()
recentPSQ
in TS
-> (Maybe (Set PeerAddr), Set PeerAddr)
-> E (Maybe (Set PeerAddr), Set PeerAddr)
forall a. TS -> a -> E a
E TS
t (Maybe (Set PeerAddr)
forall a. Maybe a
Nothing, Set PeerAddr
recentSet')
E (Maybe (Set PeerAddr), Set PeerAddr)
-> [E (Maybe (Set PeerAddr), Set PeerAddr)]
-> [E (Maybe (Set PeerAddr), Set PeerAddr)]
forall a. a -> [a] -> [a]
: Set PeerAddr
-> OrdPSQ PeerAddr Time ()
-> [E TestTraceEvent]
-> [E (Maybe (Set PeerAddr), Set PeerAddr)]
go Set PeerAddr
recentSet' OrdPSQ PeerAddr Time ()
recentPSQ' [E TestTraceEvent]
txs
go !Set PeerAddr
recentSet !OrdPSQ PeerAddr Time ()
recentPSQ
(E TS
t (GovernorEvent (TraceDemoteHotFailed Int
_ Int
_ PeerAddr
addr SomeException
_)) : [E TestTraceEvent]
txs) =
let recentSet' :: Set PeerAddr
recentSet' = PeerAddr -> Set PeerAddr -> Set PeerAddr
forall a. Ord a => a -> Set a -> Set a
Set.delete PeerAddr
addr Set PeerAddr
recentSet
recentPSQ' :: OrdPSQ PeerAddr Time ()
recentPSQ' = PeerAddr -> OrdPSQ PeerAddr Time () -> OrdPSQ PeerAddr Time ()
forall k p v. (Ord k, Ord p) => k -> OrdPSQ k p v -> OrdPSQ k p v
PSQ.delete PeerAddr
addr OrdPSQ PeerAddr Time ()
recentPSQ
in TS
-> (Maybe (Set PeerAddr), Set PeerAddr)
-> E (Maybe (Set PeerAddr), Set PeerAddr)
forall a. TS -> a -> E a
E TS
t (Maybe (Set PeerAddr)
forall a. Maybe a
Nothing, Set PeerAddr
recentSet')
E (Maybe (Set PeerAddr), Set PeerAddr)
-> [E (Maybe (Set PeerAddr), Set PeerAddr)]
-> [E (Maybe (Set PeerAddr), Set PeerAddr)]
forall a. a -> [a] -> [a]
: Set PeerAddr
-> OrdPSQ PeerAddr Time ()
-> [E TestTraceEvent]
-> [E (Maybe (Set PeerAddr), Set PeerAddr)]
go Set PeerAddr
recentSet' OrdPSQ PeerAddr Time ()
recentPSQ' [E TestTraceEvent]
txs
go !Set PeerAddr
recentSet !OrdPSQ PeerAddr Time ()
recentPSQ
(E TS
t (GovernorEvent (TraceDemoteWarmFailed Int
_ Int
_ PeerAddr
addr SomeException
_)) : [E TestTraceEvent]
txs) =
let recentSet' :: Set PeerAddr
recentSet' = PeerAddr -> Set PeerAddr -> Set PeerAddr
forall a. Ord a => a -> Set a -> Set a
Set.delete PeerAddr
addr Set PeerAddr
recentSet
recentPSQ' :: OrdPSQ PeerAddr Time ()
recentPSQ' = PeerAddr -> OrdPSQ PeerAddr Time () -> OrdPSQ PeerAddr Time ()
forall k p v. (Ord k, Ord p) => k -> OrdPSQ k p v -> OrdPSQ k p v
PSQ.delete PeerAddr
addr OrdPSQ PeerAddr Time ()
recentPSQ
in TS
-> (Maybe (Set PeerAddr), Set PeerAddr)
-> E (Maybe (Set PeerAddr), Set PeerAddr)
forall a. TS -> a -> E a
E TS
t (Maybe (Set PeerAddr)
forall a. Maybe a
Nothing, Set PeerAddr
recentSet')
E (Maybe (Set PeerAddr), Set PeerAddr)
-> [E (Maybe (Set PeerAddr), Set PeerAddr)]
-> [E (Maybe (Set PeerAddr), Set PeerAddr)]
forall a. a -> [a] -> [a]
: Set PeerAddr
-> OrdPSQ PeerAddr Time ()
-> [E TestTraceEvent]
-> [E (Maybe (Set PeerAddr), Set PeerAddr)]
go Set PeerAddr
recentSet' OrdPSQ PeerAddr Time ()
recentPSQ' [E TestTraceEvent]
txs
go !Set PeerAddr
recentSet !OrdPSQ PeerAddr Time ()
recentPSQ
(E TS
t (GovernorEvent (TraceDemoteHotBigLedgerPeerFailed Int
_ Int
_ PeerAddr
addr SomeException
_)) : [E TestTraceEvent]
txs) =
let recentSet' :: Set PeerAddr
recentSet' = PeerAddr -> Set PeerAddr -> Set PeerAddr
forall a. Ord a => a -> Set a -> Set a
Set.delete PeerAddr
addr Set PeerAddr
recentSet
recentPSQ' :: OrdPSQ PeerAddr Time ()
recentPSQ' = PeerAddr -> OrdPSQ PeerAddr Time () -> OrdPSQ PeerAddr Time ()
forall k p v. (Ord k, Ord p) => k -> OrdPSQ k p v -> OrdPSQ k p v
PSQ.delete PeerAddr
addr OrdPSQ PeerAddr Time ()
recentPSQ
in TS
-> (Maybe (Set PeerAddr), Set PeerAddr)
-> E (Maybe (Set PeerAddr), Set PeerAddr)
forall a. TS -> a -> E a
E TS
t (Maybe (Set PeerAddr)
forall a. Maybe a
Nothing, Set PeerAddr
recentSet')
E (Maybe (Set PeerAddr), Set PeerAddr)
-> [E (Maybe (Set PeerAddr), Set PeerAddr)]
-> [E (Maybe (Set PeerAddr), Set PeerAddr)]
forall a. a -> [a] -> [a]
: Set PeerAddr
-> OrdPSQ PeerAddr Time ()
-> [E TestTraceEvent]
-> [E (Maybe (Set PeerAddr), Set PeerAddr)]
go Set PeerAddr
recentSet' OrdPSQ PeerAddr Time ()
recentPSQ' [E TestTraceEvent]
txs
go !Set PeerAddr
recentSet !OrdPSQ PeerAddr Time ()
recentPSQ
(E TS
t (GovernorEvent (TraceDemoteWarmBigLedgerPeerFailed Int
_ Int
_ PeerAddr
addr SomeException
_)) : [E TestTraceEvent]
txs) =
let recentSet' :: Set PeerAddr
recentSet' = PeerAddr -> Set PeerAddr -> Set PeerAddr
forall a. Ord a => a -> Set a -> Set a
Set.delete PeerAddr
addr Set PeerAddr
recentSet
recentPSQ' :: OrdPSQ PeerAddr Time ()
recentPSQ' = PeerAddr -> OrdPSQ PeerAddr Time () -> OrdPSQ PeerAddr Time ()
forall k p v. (Ord k, Ord p) => k -> OrdPSQ k p v -> OrdPSQ k p v
PSQ.delete PeerAddr
addr OrdPSQ PeerAddr Time ()
recentPSQ
in TS
-> (Maybe (Set PeerAddr), Set PeerAddr)
-> E (Maybe (Set PeerAddr), Set PeerAddr)
forall a. TS -> a -> E a
E TS
t (Maybe (Set PeerAddr)
forall a. Maybe a
Nothing, Set PeerAddr
recentSet')
E (Maybe (Set PeerAddr), Set PeerAddr)
-> [E (Maybe (Set PeerAddr), Set PeerAddr)]
-> [E (Maybe (Set PeerAddr), Set PeerAddr)]
forall a. a -> [a] -> [a]
: Set PeerAddr
-> OrdPSQ PeerAddr Time ()
-> [E TestTraceEvent]
-> [E (Maybe (Set PeerAddr), Set PeerAddr)]
go Set PeerAddr
recentSet' OrdPSQ PeerAddr Time ()
recentPSQ' [E TestTraceEvent]
txs
go !Set PeerAddr
recentSet !OrdPSQ PeerAddr Time ()
recentPSQ (E TestTraceEvent
_ : [E TestTraceEvent]
txs) =
Set PeerAddr
-> OrdPSQ PeerAddr Time ()
-> [E TestTraceEvent]
-> [E (Maybe (Set PeerAddr), Set PeerAddr)]
go Set PeerAddr
recentSet OrdPSQ PeerAddr Time ()
recentPSQ [E TestTraceEvent]
txs
go !Set PeerAddr
_ !OrdPSQ PeerAddr Time ()
_ [] = []
prop_governor_target_known_4_results_used :: MaxTime -> GovernorMockEnvironment -> Property
prop_governor_target_known_4_results_used :: MaxTime -> GovernorMockEnvironment -> Property
prop_governor_target_known_4_results_used (MaxTime Time
maxTime) GovernorMockEnvironment
env =
let events :: Events TestTraceEvent
events = Time -> [(Time, TestTraceEvent)] -> Events TestTraceEvent
forall a. Time -> [(Time, a)] -> Events a
Signal.eventsFromListUpToTime Time
maxTime
([(Time, TestTraceEvent)] -> Events TestTraceEvent)
-> (GovernorMockEnvironment -> [(Time, TestTraceEvent)])
-> GovernorMockEnvironment
-> Events TestTraceEvent
forall b c a. (b -> c) -> (a -> b) -> a -> c
. SimTrace Void -> [(Time, TestTraceEvent)]
forall a. SimTrace a -> [(Time, TestTraceEvent)]
selectPeerSelectionTraceEvents
(SimTrace Void -> [(Time, TestTraceEvent)])
-> (GovernorMockEnvironment -> SimTrace Void)
-> GovernorMockEnvironment
-> [(Time, TestTraceEvent)]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. GovernorMockEnvironment -> SimTrace Void
runGovernorInMockEnvironment
(GovernorMockEnvironment -> Events TestTraceEvent)
-> GovernorMockEnvironment -> Events TestTraceEvent
forall a b. (a -> b) -> a -> b
$ GovernorMockEnvironment
env
govTargetsSig :: Signal Int
govTargetsSig :: Signal Int
govTargetsSig =
(forall peerconn. PeerSelectionState PeerAddr peerconn -> Int)
-> ConsensusMode -> Events TestTraceEvent -> Signal Int
forall a.
Eq a =>
(forall peerconn. PeerSelectionState PeerAddr peerconn -> a)
-> ConsensusMode -> Events TestTraceEvent -> Signal a
selectGovState (PeerSelectionTargets -> Int
targetNumberOfKnownPeers (PeerSelectionTargets -> Int)
-> (PeerSelectionState PeerAddr peerconn -> PeerSelectionTargets)
-> PeerSelectionState PeerAddr peerconn
-> Int
forall b c a. (b -> c) -> (a -> b) -> a -> c
. PeerSelectionState PeerAddr peerconn -> PeerSelectionTargets
forall peeraddr peerconn.
PeerSelectionState peeraddr peerconn -> PeerSelectionTargets
Governor.targets)
(GovernorMockEnvironment -> ConsensusMode
consensusMode GovernorMockEnvironment
env)
Events TestTraceEvent
events
govKnownPeersSig :: Signal (Set PeerAddr)
govKnownPeersSig :: Signal (Set PeerAddr)
govKnownPeersSig =
(forall peerconn.
PeerSelectionState PeerAddr peerconn -> Set PeerAddr)
-> ConsensusMode -> Events TestTraceEvent -> Signal (Set PeerAddr)
forall a.
Eq a =>
(forall peerconn. PeerSelectionState PeerAddr peerconn -> a)
-> ConsensusMode -> Events TestTraceEvent -> Signal a
selectGovState (KnownPeers PeerAddr -> Set PeerAddr
forall peeraddr. KnownPeers peeraddr -> Set peeraddr
KnownPeers.toSet (KnownPeers PeerAddr -> Set PeerAddr)
-> (PeerSelectionState PeerAddr peerconn -> KnownPeers PeerAddr)
-> PeerSelectionState PeerAddr peerconn
-> Set PeerAddr
forall b c a. (b -> c) -> (a -> b) -> a -> c
. PeerSelectionState PeerAddr peerconn -> KnownPeers PeerAddr
forall peeraddr peerconn.
PeerSelectionState peeraddr peerconn -> KnownPeers peeraddr
Governor.knownPeers)
(GovernorMockEnvironment -> ConsensusMode
consensusMode GovernorMockEnvironment
env)
Events TestTraceEvent
events
envPeerShareResultsSig :: Signal (Set PeerAddr)
envPeerShareResultsSig :: Signal (Set PeerAddr)
envPeerShareResultsSig =
(Maybe [PeerAddr] -> Set PeerAddr)
-> Signal (Maybe [PeerAddr]) -> Signal (Set PeerAddr)
forall a b. (a -> b) -> Signal a -> Signal b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (Set PeerAddr
-> ([PeerAddr] -> Set PeerAddr) -> Maybe [PeerAddr] -> Set PeerAddr
forall b a. b -> (a -> b) -> Maybe a -> b
maybe Set PeerAddr
forall a. Set a
Set.empty [PeerAddr] -> Set PeerAddr
forall a. Ord a => [a] -> Set a
Set.fromList)
(Signal (Maybe [PeerAddr]) -> Signal (Set PeerAddr))
-> (Events TestTraceEvent -> Signal (Maybe [PeerAddr]))
-> Events TestTraceEvent
-> Signal (Set PeerAddr)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Events [PeerAddr] -> Signal (Maybe [PeerAddr])
forall a. Events a -> Signal (Maybe a)
Signal.fromEvents
(Events [PeerAddr] -> Signal (Maybe [PeerAddr]))
-> (Events TestTraceEvent -> Events [PeerAddr])
-> Events TestTraceEvent
-> Signal (Maybe [PeerAddr])
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (TracePeerSelection PeerAddr -> Maybe [PeerAddr])
-> Events (TracePeerSelection PeerAddr) -> Events [PeerAddr]
forall a b. (a -> Maybe b) -> Events a -> Events b
Signal.selectEvents
(\case TracePeerShareResultsFiltered [PeerAddr]
addrs -> [PeerAddr] -> Maybe [PeerAddr]
forall a. a -> Maybe a
Just [PeerAddr]
addrs
TracePeerSelection PeerAddr
_ -> Maybe [PeerAddr]
forall a. Maybe a
Nothing)
(Events (TracePeerSelection PeerAddr) -> Events [PeerAddr])
-> (Events TestTraceEvent -> Events (TracePeerSelection PeerAddr))
-> Events TestTraceEvent
-> Events [PeerAddr]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Events TestTraceEvent -> Events (TracePeerSelection PeerAddr)
selectGovEvents
(Events TestTraceEvent -> Signal (Set PeerAddr))
-> Events TestTraceEvent -> Signal (Set PeerAddr)
forall a b. (a -> b) -> a -> b
$ Events TestTraceEvent
events
peerShareResultsUntilKnown :: Signal (Set PeerAddr)
peerShareResultsUntilKnown :: Signal (Set PeerAddr)
peerShareResultsUntilKnown =
((Int, Set PeerAddr, Set PeerAddr) -> Set PeerAddr)
-> ((Int, Set PeerAddr, Set PeerAddr) -> Set PeerAddr)
-> ((Int, Set PeerAddr, Set PeerAddr) -> Bool)
-> Signal (Int, Set PeerAddr, Set PeerAddr)
-> Signal (Set PeerAddr)
forall a b.
Ord b =>
(a -> Set b)
-> (a -> Set b) -> (a -> Bool) -> Signal a -> Signal (Set b)
Signal.keyedUntil
(\(Int
_, Set PeerAddr
_, Set PeerAddr
peerShares) -> Set PeerAddr
peerShares)
(\(Int
_, Set PeerAddr
known, Set PeerAddr
_) -> Set PeerAddr
known)
(\(Int
target, Set PeerAddr
known, Set PeerAddr
_) -> Set PeerAddr -> Int
forall a. Set a -> Int
Set.size Set PeerAddr
known Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
<= Int
target)
((,,) (Int
-> Set PeerAddr
-> Set PeerAddr
-> (Int, Set PeerAddr, Set PeerAddr))
-> Signal Int
-> Signal
(Set PeerAddr -> Set PeerAddr -> (Int, Set PeerAddr, Set PeerAddr))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Signal Int
govTargetsSig
Signal
(Set PeerAddr -> Set PeerAddr -> (Int, Set PeerAddr, Set PeerAddr))
-> Signal (Set PeerAddr)
-> Signal (Set PeerAddr -> (Int, Set PeerAddr, Set PeerAddr))
forall a b. Signal (a -> b) -> Signal a -> Signal b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Signal (Set PeerAddr)
govKnownPeersSig
Signal (Set PeerAddr -> (Int, Set PeerAddr, Set PeerAddr))
-> Signal (Set PeerAddr)
-> Signal (Int, Set PeerAddr, Set PeerAddr)
forall a b. Signal (a -> b) -> Signal a -> Signal b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Signal (Set PeerAddr)
envPeerShareResultsSig)
peerShareResultsUnknownTooLong :: Signal (Set PeerAddr)
peerShareResultsUnknownTooLong :: Signal (Set PeerAddr)
peerShareResultsUnknownTooLong =
DiffTime
-> (Set PeerAddr -> Set PeerAddr)
-> Signal (Set PeerAddr)
-> Signal (Set PeerAddr)
forall a b.
Ord b =>
DiffTime -> (a -> Set b) -> Signal a -> Signal (Set b)
Signal.keyedTimeout
(DiffTime
10 DiffTime -> DiffTime -> DiffTime
forall a. Num a => a -> a -> a
+ DiffTime
1)
Set PeerAddr -> Set PeerAddr
forall a. a -> a
id
Signal (Set PeerAddr)
peerShareResultsUntilKnown
in TestName -> Property -> Property
forall prop. Testable prop => TestName -> prop -> Property
counterexample
(TestName
"\nSignal key: (known peers, peer share result, results unknown, " TestName -> TestName -> TestName
forall a. [a] -> [a] -> [a]
++
TestName
"results unknown too long)") (Property -> Property) -> Property -> Property
forall a b. (a -> b) -> a -> b
$
Int
-> ((Int, Set PeerAddr, Set PeerAddr, Set PeerAddr, Set PeerAddr)
-> TestName)
-> ((Int, Set PeerAddr, Set PeerAddr, Set PeerAddr, Set PeerAddr)
-> Bool)
-> Signal
(Int, Set PeerAddr, Set PeerAddr, Set PeerAddr, Set PeerAddr)
-> Property
forall a.
Int -> (a -> TestName) -> (a -> Bool) -> Signal a -> Property
signalProperty Int
20 (Int, Set PeerAddr, Set PeerAddr, Set PeerAddr, Set PeerAddr)
-> TestName
forall a. Show a => a -> TestName
show
(\(Int
_,Set PeerAddr
_,Set PeerAddr
_,Set PeerAddr
_,Set PeerAddr
x) -> Set PeerAddr -> Bool
forall a. Set a -> Bool
Set.null Set PeerAddr
x) (Signal
(Int, Set PeerAddr, Set PeerAddr, Set PeerAddr, Set PeerAddr)
-> Property)
-> Signal
(Int, Set PeerAddr, Set PeerAddr, Set PeerAddr, Set PeerAddr)
-> Property
forall a b. (a -> b) -> a -> b
$
(,,,,) (Int
-> Set PeerAddr
-> Set PeerAddr
-> Set PeerAddr
-> Set PeerAddr
-> (Int, Set PeerAddr, Set PeerAddr, Set PeerAddr, Set PeerAddr))
-> Signal Int
-> Signal
(Set PeerAddr
-> Set PeerAddr
-> Set PeerAddr
-> Set PeerAddr
-> (Int, Set PeerAddr, Set PeerAddr, Set PeerAddr, Set PeerAddr))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Signal Int
govTargetsSig
Signal
(Set PeerAddr
-> Set PeerAddr
-> Set PeerAddr
-> Set PeerAddr
-> (Int, Set PeerAddr, Set PeerAddr, Set PeerAddr, Set PeerAddr))
-> Signal (Set PeerAddr)
-> Signal
(Set PeerAddr
-> Set PeerAddr
-> Set PeerAddr
-> (Int, Set PeerAddr, Set PeerAddr, Set PeerAddr, Set PeerAddr))
forall a b. Signal (a -> b) -> Signal a -> Signal b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Signal (Set PeerAddr)
govKnownPeersSig
Signal
(Set PeerAddr
-> Set PeerAddr
-> Set PeerAddr
-> (Int, Set PeerAddr, Set PeerAddr, Set PeerAddr, Set PeerAddr))
-> Signal (Set PeerAddr)
-> Signal
(Set PeerAddr
-> Set PeerAddr
-> (Int, Set PeerAddr, Set PeerAddr, Set PeerAddr, Set PeerAddr))
forall a b. Signal (a -> b) -> Signal a -> Signal b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Signal (Set PeerAddr)
envPeerShareResultsSig
Signal
(Set PeerAddr
-> Set PeerAddr
-> (Int, Set PeerAddr, Set PeerAddr, Set PeerAddr, Set PeerAddr))
-> Signal (Set PeerAddr)
-> Signal
(Set PeerAddr
-> (Int, Set PeerAddr, Set PeerAddr, Set PeerAddr, Set PeerAddr))
forall a b. Signal (a -> b) -> Signal a -> Signal b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Signal (Set PeerAddr)
peerShareResultsUntilKnown
Signal
(Set PeerAddr
-> (Int, Set PeerAddr, Set PeerAddr, Set PeerAddr, Set PeerAddr))
-> Signal (Set PeerAddr)
-> Signal
(Int, Set PeerAddr, Set PeerAddr, Set PeerAddr, Set PeerAddr)
forall a b. Signal (a -> b) -> Signal a -> Signal b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Signal (Set PeerAddr)
peerShareResultsUnknownTooLong
prop_governor_target_known_5_no_shrink_below :: MaxTime -> GovernorMockEnvironment -> Property
prop_governor_target_known_5_no_shrink_below :: MaxTime -> GovernorMockEnvironment -> Property
prop_governor_target_known_5_no_shrink_below (MaxTime Time
maxTime) GovernorMockEnvironment
env =
let events :: Events TestTraceEvent
events = Time -> [(Time, TestTraceEvent)] -> Events TestTraceEvent
forall a. Time -> [(Time, a)] -> Events a
Signal.eventsFromListUpToTime Time
maxTime
([(Time, TestTraceEvent)] -> Events TestTraceEvent)
-> (GovernorMockEnvironment -> [(Time, TestTraceEvent)])
-> GovernorMockEnvironment
-> Events TestTraceEvent
forall b c a. (b -> c) -> (a -> b) -> a -> c
. SimTrace Void -> [(Time, TestTraceEvent)]
forall a. SimTrace a -> [(Time, TestTraceEvent)]
selectPeerSelectionTraceEvents
(SimTrace Void -> [(Time, TestTraceEvent)])
-> (GovernorMockEnvironment -> SimTrace Void)
-> GovernorMockEnvironment
-> [(Time, TestTraceEvent)]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. GovernorMockEnvironment -> SimTrace Void
runGovernorInMockEnvironment
(GovernorMockEnvironment -> Events TestTraceEvent)
-> GovernorMockEnvironment -> Events TestTraceEvent
forall a b. (a -> b) -> a -> b
$ GovernorMockEnvironment
env
govTargetsSig :: Signal Int
govTargetsSig :: Signal Int
govTargetsSig =
(forall peerconn. PeerSelectionState PeerAddr peerconn -> Int)
-> ConsensusMode -> Events TestTraceEvent -> Signal Int
forall a.
Eq a =>
(forall peerconn. PeerSelectionState PeerAddr peerconn -> a)
-> ConsensusMode -> Events TestTraceEvent -> Signal a
selectGovState (PeerSelectionTargets -> Int
targetNumberOfKnownPeers (PeerSelectionTargets -> Int)
-> (PeerSelectionState PeerAddr peerconn -> PeerSelectionTargets)
-> PeerSelectionState PeerAddr peerconn
-> Int
forall b c a. (b -> c) -> (a -> b) -> a -> c
. PeerSelectionState PeerAddr peerconn -> PeerSelectionTargets
forall peeraddr peerconn.
PeerSelectionState peeraddr peerconn -> PeerSelectionTargets
Governor.targets)
(GovernorMockEnvironment -> ConsensusMode
consensusMode GovernorMockEnvironment
env)
Events TestTraceEvent
events
govKnownPeersSig :: Signal (Set PeerAddr)
govKnownPeersSig :: Signal (Set PeerAddr)
govKnownPeersSig =
(forall peerconn.
PeerSelectionState PeerAddr peerconn -> Set PeerAddr)
-> ConsensusMode -> Events TestTraceEvent -> Signal (Set PeerAddr)
forall a.
Eq a =>
(forall peerconn. PeerSelectionState PeerAddr peerconn -> a)
-> ConsensusMode -> Events TestTraceEvent -> Signal a
selectGovState (KnownPeers PeerAddr -> Set PeerAddr
forall peeraddr. KnownPeers peeraddr -> Set peeraddr
KnownPeers.toSet (KnownPeers PeerAddr -> Set PeerAddr)
-> (PeerSelectionState PeerAddr peerconn -> KnownPeers PeerAddr)
-> PeerSelectionState PeerAddr peerconn
-> Set PeerAddr
forall b c a. (b -> c) -> (a -> b) -> a -> c
. PeerSelectionState PeerAddr peerconn -> KnownPeers PeerAddr
forall peeraddr peerconn.
PeerSelectionState peeraddr peerconn -> KnownPeers peeraddr
Governor.knownPeers)
(GovernorMockEnvironment -> ConsensusMode
consensusMode GovernorMockEnvironment
env)
Events TestTraceEvent
events
bigLedgerPeersSig :: Signal (Set PeerAddr)
bigLedgerPeersSig :: Signal (Set PeerAddr)
bigLedgerPeersSig =
(forall peerconn.
PeerSelectionState PeerAddr peerconn -> Set PeerAddr)
-> ConsensusMode -> Events TestTraceEvent -> Signal (Set PeerAddr)
forall a.
Eq a =>
(forall peerconn. PeerSelectionState PeerAddr peerconn -> a)
-> ConsensusMode -> Events TestTraceEvent -> Signal a
selectGovState (PublicRootPeers PeerAddr -> Set PeerAddr
forall peeraddr. PublicRootPeers peeraddr -> Set peeraddr
PublicRootPeers.getBigLedgerPeers (PublicRootPeers PeerAddr -> Set PeerAddr)
-> (PeerSelectionState PeerAddr peerconn
-> PublicRootPeers PeerAddr)
-> PeerSelectionState PeerAddr peerconn
-> Set PeerAddr
forall b c a. (b -> c) -> (a -> b) -> a -> c
. PeerSelectionState PeerAddr peerconn -> PublicRootPeers PeerAddr
forall peeraddr peerconn.
PeerSelectionState peeraddr peerconn -> PublicRootPeers peeraddr
Governor.publicRootPeers)
(GovernorMockEnvironment -> ConsensusMode
consensusMode GovernorMockEnvironment
env)
Events TestTraceEvent
events
bootstrapPeersSig :: Signal (Set PeerAddr)
bootstrapPeersSig :: Signal (Set PeerAddr)
bootstrapPeersSig =
(forall peerconn.
PeerSelectionState PeerAddr peerconn -> Set PeerAddr)
-> ConsensusMode -> Events TestTraceEvent -> Signal (Set PeerAddr)
forall a.
Eq a =>
(forall peerconn. PeerSelectionState PeerAddr peerconn -> a)
-> ConsensusMode -> Events TestTraceEvent -> Signal a
selectGovState (PublicRootPeers PeerAddr -> Set PeerAddr
forall peeraddr. PublicRootPeers peeraddr -> Set peeraddr
PublicRootPeers.getBootstrapPeers (PublicRootPeers PeerAddr -> Set PeerAddr)
-> (PeerSelectionState PeerAddr peerconn
-> PublicRootPeers PeerAddr)
-> PeerSelectionState PeerAddr peerconn
-> Set PeerAddr
forall b c a. (b -> c) -> (a -> b) -> a -> c
. PeerSelectionState PeerAddr peerconn -> PublicRootPeers PeerAddr
forall peeraddr peerconn.
PeerSelectionState peeraddr peerconn -> PublicRootPeers peeraddr
Governor.publicRootPeers)
(GovernorMockEnvironment -> ConsensusMode
consensusMode GovernorMockEnvironment
env)
Events TestTraceEvent
events
knownPeersShrinksSig :: Signal (Set PeerAddr)
knownPeersShrinksSig :: Signal (Set PeerAddr)
knownPeersShrinksSig =
Signal (Set PeerAddr) -> Signal (Set PeerAddr)
forall a. Eq a => Signal a -> Signal a
Signal.nub
(Signal (Set PeerAddr) -> Signal (Set PeerAddr))
-> (Signal (Set PeerAddr, Set PeerAddr, Set PeerAddr)
-> Signal (Set PeerAddr))
-> Signal (Set PeerAddr, Set PeerAddr, Set PeerAddr)
-> Signal (Set PeerAddr)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Maybe (Set PeerAddr) -> Set PeerAddr)
-> Signal (Maybe (Set PeerAddr)) -> Signal (Set PeerAddr)
forall a b. (a -> b) -> Signal a -> Signal b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (Set PeerAddr -> Maybe (Set PeerAddr) -> Set PeerAddr
forall a. a -> Maybe a -> a
fromMaybe Set PeerAddr
forall a. Set a
Set.empty)
(Signal (Maybe (Set PeerAddr)) -> Signal (Set PeerAddr))
-> (Signal (Set PeerAddr, Set PeerAddr, Set PeerAddr)
-> Signal (Maybe (Set PeerAddr)))
-> Signal (Set PeerAddr, Set PeerAddr, Set PeerAddr)
-> Signal (Set PeerAddr)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ((Set PeerAddr, Set PeerAddr, Set PeerAddr)
-> (Set PeerAddr, Set PeerAddr, Set PeerAddr) -> Set PeerAddr)
-> Signal (Set PeerAddr, Set PeerAddr, Set PeerAddr)
-> Signal (Maybe (Set PeerAddr))
forall a b. (a -> a -> b) -> Signal a -> Signal (Maybe b)
Signal.difference
(\(Set PeerAddr
x,Set PeerAddr
y,Set PeerAddr
z) (Set PeerAddr
x',Set PeerAddr
y',Set PeerAddr
z') -> Set PeerAddr
x Set PeerAddr -> Set PeerAddr -> Set PeerAddr
forall a. Ord a => Set a -> Set a -> Set a
Set.\\ Set PeerAddr
x' Set PeerAddr -> Set PeerAddr -> Set PeerAddr
forall a. Ord a => Set a -> Set a -> Set a
Set.\\ Set PeerAddr
y Set PeerAddr -> Set PeerAddr -> Set PeerAddr
forall a. Ord a => Set a -> Set a -> Set a
Set.\\ Set PeerAddr
y' Set PeerAddr -> Set PeerAddr -> Set PeerAddr
forall a. Ord a => Set a -> Set a -> Set a
Set.\\ Set PeerAddr
z Set PeerAddr -> Set PeerAddr -> Set PeerAddr
forall a. Ord a => Set a -> Set a -> Set a
Set.\\ Set PeerAddr
z')
(Signal (Set PeerAddr, Set PeerAddr, Set PeerAddr)
-> Signal (Set PeerAddr))
-> Signal (Set PeerAddr, Set PeerAddr, Set PeerAddr)
-> Signal (Set PeerAddr)
forall a b. (a -> b) -> a -> b
$ (,,) (Set PeerAddr
-> Set PeerAddr
-> Set PeerAddr
-> (Set PeerAddr, Set PeerAddr, Set PeerAddr))
-> Signal (Set PeerAddr)
-> Signal
(Set PeerAddr
-> Set PeerAddr -> (Set PeerAddr, Set PeerAddr, Set PeerAddr))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Signal (Set PeerAddr)
govKnownPeersSig
Signal
(Set PeerAddr
-> Set PeerAddr -> (Set PeerAddr, Set PeerAddr, Set PeerAddr))
-> Signal (Set PeerAddr)
-> Signal
(Set PeerAddr -> (Set PeerAddr, Set PeerAddr, Set PeerAddr))
forall a b. Signal (a -> b) -> Signal a -> Signal b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Signal (Set PeerAddr)
bigLedgerPeersSig
Signal (Set PeerAddr -> (Set PeerAddr, Set PeerAddr, Set PeerAddr))
-> Signal (Set PeerAddr)
-> Signal (Set PeerAddr, Set PeerAddr, Set PeerAddr)
forall a b. Signal (a -> b) -> Signal a -> Signal b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Signal (Set PeerAddr)
bootstrapPeersSig
unexpectedShrink :: Signal Bool
unexpectedShrink :: Signal Bool
unexpectedShrink =
(\Int
target Set PeerAddr
known Set PeerAddr
shrinks ->
Bool -> Bool
not (Set PeerAddr -> Bool
forall a. Set a -> Bool
Set.null Set PeerAddr
shrinks)
Bool -> Bool -> Bool
&& Set PeerAddr -> Int
forall a. Set a -> Int
Set.size Set PeerAddr
known Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
< Int
target
) (Int -> Set PeerAddr -> Set PeerAddr -> Bool)
-> Signal Int -> Signal (Set PeerAddr -> Set PeerAddr -> Bool)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Signal Int
govTargetsSig
Signal (Set PeerAddr -> Set PeerAddr -> Bool)
-> Signal (Set PeerAddr) -> Signal (Set PeerAddr -> Bool)
forall a b. Signal (a -> b) -> Signal a -> Signal b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Signal (Set PeerAddr)
govKnownPeersSig
Signal (Set PeerAddr -> Bool)
-> Signal (Set PeerAddr) -> Signal Bool
forall a b. Signal (a -> b) -> Signal a -> Signal b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Signal (Set PeerAddr)
knownPeersShrinksSig
in TestName -> Property -> Property
forall prop. Testable prop => TestName -> prop -> Property
counterexample
TestName
"\nSignal key: (target, known peers, shrinks, unexpected)" (Property -> Property) -> Property -> Property
forall a b. (a -> b) -> a -> b
$
Int
-> ((Int, Set PeerAddr, Set PeerAddr, Bool) -> TestName)
-> ((Int, Set PeerAddr, Set PeerAddr, Bool) -> Bool)
-> Signal (Int, Set PeerAddr, Set PeerAddr, Bool)
-> Property
forall a.
Int -> (a -> TestName) -> (a -> Bool) -> Signal a -> Property
signalProperty Int
20 (Int, Set PeerAddr, Set PeerAddr, Bool) -> TestName
forall a. Show a => a -> TestName
show
(\(Int
_,Set PeerAddr
_,Set PeerAddr
_,Bool
unexpected) -> Bool -> Bool
not Bool
unexpected)
((,,,) (Int
-> Set PeerAddr
-> Set PeerAddr
-> Bool
-> (Int, Set PeerAddr, Set PeerAddr, Bool))
-> Signal Int
-> Signal
(Set PeerAddr
-> Set PeerAddr -> Bool -> (Int, Set PeerAddr, Set PeerAddr, Bool))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Signal Int
govTargetsSig
Signal
(Set PeerAddr
-> Set PeerAddr -> Bool -> (Int, Set PeerAddr, Set PeerAddr, Bool))
-> Signal (Set PeerAddr)
-> Signal
(Set PeerAddr -> Bool -> (Int, Set PeerAddr, Set PeerAddr, Bool))
forall a b. Signal (a -> b) -> Signal a -> Signal b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Signal (Set PeerAddr)
govKnownPeersSig
Signal
(Set PeerAddr -> Bool -> (Int, Set PeerAddr, Set PeerAddr, Bool))
-> Signal (Set PeerAddr)
-> Signal (Bool -> (Int, Set PeerAddr, Set PeerAddr, Bool))
forall a b. Signal (a -> b) -> Signal a -> Signal b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Signal (Set PeerAddr)
knownPeersShrinksSig
Signal (Bool -> (Int, Set PeerAddr, Set PeerAddr, Bool))
-> Signal Bool -> Signal (Int, Set PeerAddr, Set PeerAddr, Bool)
forall a b. Signal (a -> b) -> Signal a -> Signal b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Signal Bool
unexpectedShrink)
prop_governor_target_known_5_no_shrink_big_ledger_peers_below :: MaxTime -> GovernorMockEnvironment -> Property
prop_governor_target_known_5_no_shrink_big_ledger_peers_below :: MaxTime -> GovernorMockEnvironment -> Property
prop_governor_target_known_5_no_shrink_big_ledger_peers_below (MaxTime Time
maxTime) GovernorMockEnvironment
env =
let events :: Events TestTraceEvent
events = Time -> [(Time, TestTraceEvent)] -> Events TestTraceEvent
forall a. Time -> [(Time, a)] -> Events a
Signal.eventsFromListUpToTime Time
maxTime
([(Time, TestTraceEvent)] -> Events TestTraceEvent)
-> (GovernorMockEnvironment -> [(Time, TestTraceEvent)])
-> GovernorMockEnvironment
-> Events TestTraceEvent
forall b c a. (b -> c) -> (a -> b) -> a -> c
. SimTrace Void -> [(Time, TestTraceEvent)]
forall a. SimTrace a -> [(Time, TestTraceEvent)]
selectPeerSelectionTraceEvents
(SimTrace Void -> [(Time, TestTraceEvent)])
-> (GovernorMockEnvironment -> SimTrace Void)
-> GovernorMockEnvironment
-> [(Time, TestTraceEvent)]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. GovernorMockEnvironment -> SimTrace Void
runGovernorInMockEnvironment
(GovernorMockEnvironment -> Events TestTraceEvent)
-> GovernorMockEnvironment -> Events TestTraceEvent
forall a b. (a -> b) -> a -> b
$ GovernorMockEnvironment
env
govTargetsSig :: Signal Int
govTargetsSig :: Signal Int
govTargetsSig =
(forall peerconn. PeerSelectionState PeerAddr peerconn -> Int)
-> ConsensusMode -> Events TestTraceEvent -> Signal Int
forall a.
Eq a =>
(forall peerconn. PeerSelectionState PeerAddr peerconn -> a)
-> ConsensusMode -> Events TestTraceEvent -> Signal a
selectGovState (PeerSelectionTargets -> Int
targetNumberOfKnownBigLedgerPeers (PeerSelectionTargets -> Int)
-> (PeerSelectionState PeerAddr peerconn -> PeerSelectionTargets)
-> PeerSelectionState PeerAddr peerconn
-> Int
forall b c a. (b -> c) -> (a -> b) -> a -> c
. PeerSelectionState PeerAddr peerconn -> PeerSelectionTargets
forall peeraddr peerconn.
PeerSelectionState peeraddr peerconn -> PeerSelectionTargets
Governor.targets)
(GovernorMockEnvironment -> ConsensusMode
consensusMode GovernorMockEnvironment
env)
Events TestTraceEvent
events
govKnownPeersSig :: Signal (Set PeerAddr)
govKnownPeersSig :: Signal (Set PeerAddr)
govKnownPeersSig =
(forall peerconn.
PeerSelectionState PeerAddr peerconn -> Set PeerAddr)
-> ConsensusMode -> Events TestTraceEvent -> Signal (Set PeerAddr)
forall a.
Eq a =>
(forall peerconn. PeerSelectionState PeerAddr peerconn -> a)
-> ConsensusMode -> Events TestTraceEvent -> Signal a
selectGovState ((PeerSelectionState PeerAddr peerconn -> Set PeerAddr)
-> PeerSelectionState PeerAddr peerconn -> Set PeerAddr
forall peerconn.
(PeerSelectionState PeerAddr peerconn -> Set PeerAddr)
-> PeerSelectionState PeerAddr peerconn -> Set PeerAddr
takeBigLedgerPeers ((PeerSelectionState PeerAddr peerconn -> Set PeerAddr)
-> PeerSelectionState PeerAddr peerconn -> Set PeerAddr)
-> (PeerSelectionState PeerAddr peerconn -> Set PeerAddr)
-> PeerSelectionState PeerAddr peerconn
-> Set PeerAddr
forall a b. (a -> b) -> a -> b
$
KnownPeers PeerAddr -> Set PeerAddr
forall peeraddr. KnownPeers peeraddr -> Set peeraddr
KnownPeers.toSet (KnownPeers PeerAddr -> Set PeerAddr)
-> (PeerSelectionState PeerAddr peerconn -> KnownPeers PeerAddr)
-> PeerSelectionState PeerAddr peerconn
-> Set PeerAddr
forall b c a. (b -> c) -> (a -> b) -> a -> c
. PeerSelectionState PeerAddr peerconn -> KnownPeers PeerAddr
forall peeraddr peerconn.
PeerSelectionState peeraddr peerconn -> KnownPeers peeraddr
Governor.knownPeers)
(GovernorMockEnvironment -> ConsensusMode
consensusMode GovernorMockEnvironment
env)
Events TestTraceEvent
events
knownPeersShrinksSig :: Signal (Set PeerAddr)
knownPeersShrinksSig :: Signal (Set PeerAddr)
knownPeersShrinksSig =
Signal (Set PeerAddr) -> Signal (Set PeerAddr)
forall a. Eq a => Signal a -> Signal a
Signal.nub
(Signal (Set PeerAddr) -> Signal (Set PeerAddr))
-> (Signal (Maybe (Set PeerAddr)) -> Signal (Set PeerAddr))
-> Signal (Maybe (Set PeerAddr))
-> Signal (Set PeerAddr)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Maybe (Set PeerAddr) -> Set PeerAddr)
-> Signal (Maybe (Set PeerAddr)) -> Signal (Set PeerAddr)
forall a b. (a -> b) -> Signal a -> Signal b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (Set PeerAddr -> Maybe (Set PeerAddr) -> Set PeerAddr
forall a. a -> Maybe a -> a
fromMaybe Set PeerAddr
forall a. Set a
Set.empty)
(Signal (Maybe (Set PeerAddr)) -> Signal (Set PeerAddr))
-> Signal (Maybe (Set PeerAddr)) -> Signal (Set PeerAddr)
forall a b. (a -> b) -> a -> b
$ (Set PeerAddr -> Set PeerAddr -> Set PeerAddr)
-> Signal (Set PeerAddr) -> Signal (Maybe (Set PeerAddr))
forall a b. (a -> a -> b) -> Signal a -> Signal (Maybe b)
Signal.difference
(\Set PeerAddr
x Set PeerAddr
x' -> Set PeerAddr
x Set PeerAddr -> Set PeerAddr -> Set PeerAddr
forall a. Ord a => Set a -> Set a -> Set a
Set.\\ Set PeerAddr
x')
Signal (Set PeerAddr)
govKnownPeersSig
unexpectedShrink :: Signal Bool
unexpectedShrink :: Signal Bool
unexpectedShrink =
(\Int
target Set PeerAddr
known Set PeerAddr
shrinks ->
Bool -> Bool
not (Set PeerAddr -> Bool
forall a. Set a -> Bool
Set.null Set PeerAddr
shrinks)
Bool -> Bool -> Bool
&& Set PeerAddr -> Int
forall a. Set a -> Int
Set.size Set PeerAddr
known Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
< Int
target
) (Int -> Set PeerAddr -> Set PeerAddr -> Bool)
-> Signal Int -> Signal (Set PeerAddr -> Set PeerAddr -> Bool)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Signal Int
govTargetsSig
Signal (Set PeerAddr -> Set PeerAddr -> Bool)
-> Signal (Set PeerAddr) -> Signal (Set PeerAddr -> Bool)
forall a b. Signal (a -> b) -> Signal a -> Signal b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Signal (Set PeerAddr)
govKnownPeersSig
Signal (Set PeerAddr -> Bool)
-> Signal (Set PeerAddr) -> Signal Bool
forall a b. Signal (a -> b) -> Signal a -> Signal b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Signal (Set PeerAddr)
knownPeersShrinksSig
in TestName -> Property -> Property
forall prop. Testable prop => TestName -> prop -> Property
counterexample
TestName
"\nSignal key: (target, known peers, shrinks, unexpected)" (Property -> Property) -> Property -> Property
forall a b. (a -> b) -> a -> b
$
Int
-> ((Int, Set PeerAddr, Set PeerAddr, Bool) -> TestName)
-> ((Int, Set PeerAddr, Set PeerAddr, Bool) -> Bool)
-> Signal (Int, Set PeerAddr, Set PeerAddr, Bool)
-> Property
forall a.
Int -> (a -> TestName) -> (a -> Bool) -> Signal a -> Property
signalProperty Int
20 (Int, Set PeerAddr, Set PeerAddr, Bool) -> TestName
forall a. Show a => a -> TestName
show
(\(Int
_,Set PeerAddr
_,Set PeerAddr
_,Bool
unexpected) -> Bool -> Bool
not Bool
unexpected)
((,,,) (Int
-> Set PeerAddr
-> Set PeerAddr
-> Bool
-> (Int, Set PeerAddr, Set PeerAddr, Bool))
-> Signal Int
-> Signal
(Set PeerAddr
-> Set PeerAddr -> Bool -> (Int, Set PeerAddr, Set PeerAddr, Bool))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Signal Int
govTargetsSig
Signal
(Set PeerAddr
-> Set PeerAddr -> Bool -> (Int, Set PeerAddr, Set PeerAddr, Bool))
-> Signal (Set PeerAddr)
-> Signal
(Set PeerAddr -> Bool -> (Int, Set PeerAddr, Set PeerAddr, Bool))
forall a b. Signal (a -> b) -> Signal a -> Signal b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Signal (Set PeerAddr)
govKnownPeersSig
Signal
(Set PeerAddr -> Bool -> (Int, Set PeerAddr, Set PeerAddr, Bool))
-> Signal (Set PeerAddr)
-> Signal (Bool -> (Int, Set PeerAddr, Set PeerAddr, Bool))
forall a b. Signal (a -> b) -> Signal a -> Signal b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Signal (Set PeerAddr)
knownPeersShrinksSig
Signal (Bool -> (Int, Set PeerAddr, Set PeerAddr, Bool))
-> Signal Bool -> Signal (Int, Set PeerAddr, Set PeerAddr, Bool)
forall a b. Signal (a -> b) -> Signal a -> Signal b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Signal Bool
unexpectedShrink)
prop_governor_target_known_above :: MaxTime -> GovernorMockEnvironment -> Property
prop_governor_target_known_above :: MaxTime -> GovernorMockEnvironment -> Property
prop_governor_target_known_above (MaxTime Time
maxTime) GovernorMockEnvironment
env =
let events :: Events TestTraceEvent
events = Time -> [(Time, TestTraceEvent)] -> Events TestTraceEvent
forall a. Time -> [(Time, a)] -> Events a
Signal.eventsFromListUpToTime Time
maxTime
([(Time, TestTraceEvent)] -> Events TestTraceEvent)
-> (GovernorMockEnvironment -> [(Time, TestTraceEvent)])
-> GovernorMockEnvironment
-> Events TestTraceEvent
forall b c a. (b -> c) -> (a -> b) -> a -> c
. SimTrace Void -> [(Time, TestTraceEvent)]
forall a. SimTrace a -> [(Time, TestTraceEvent)]
selectPeerSelectionTraceEvents
(SimTrace Void -> [(Time, TestTraceEvent)])
-> (GovernorMockEnvironment -> SimTrace Void)
-> GovernorMockEnvironment
-> [(Time, TestTraceEvent)]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. GovernorMockEnvironment -> SimTrace Void
runGovernorInMockEnvironment
(GovernorMockEnvironment -> Events TestTraceEvent)
-> GovernorMockEnvironment -> Events TestTraceEvent
forall a b. (a -> b) -> a -> b
$ GovernorMockEnvironment
env
govTargetsSig :: Signal PeerSelectionTargets
govTargetsSig :: Signal PeerSelectionTargets
govTargetsSig =
(forall peerconn.
PeerSelectionState PeerAddr peerconn -> PeerSelectionTargets)
-> ConsensusMode
-> Events TestTraceEvent
-> Signal PeerSelectionTargets
forall a.
Eq a =>
(forall peerconn. PeerSelectionState PeerAddr peerconn -> a)
-> ConsensusMode -> Events TestTraceEvent -> Signal a
selectGovState PeerSelectionState PeerAddr peerconn -> PeerSelectionTargets
forall peerconn.
PeerSelectionState PeerAddr peerconn -> PeerSelectionTargets
forall peeraddr peerconn.
PeerSelectionState peeraddr peerconn -> PeerSelectionTargets
Governor.targets (GovernorMockEnvironment -> ConsensusMode
consensusMode GovernorMockEnvironment
env) Events TestTraceEvent
events
govLocalRootPeersSig :: Signal (Set PeerAddr)
govLocalRootPeersSig :: Signal (Set PeerAddr)
govLocalRootPeersSig =
(forall peerconn.
PeerSelectionState PeerAddr peerconn -> Set PeerAddr)
-> ConsensusMode -> Events TestTraceEvent -> Signal (Set PeerAddr)
forall a.
Eq a =>
(forall peerconn. PeerSelectionState PeerAddr peerconn -> a)
-> ConsensusMode -> Events TestTraceEvent -> Signal a
selectGovState (LocalRootPeers PeerAddr -> Set PeerAddr
forall peeraddr. LocalRootPeers peeraddr -> Set peeraddr
LocalRootPeers.keysSet (LocalRootPeers PeerAddr -> Set PeerAddr)
-> (PeerSelectionState PeerAddr peerconn
-> LocalRootPeers PeerAddr)
-> PeerSelectionState PeerAddr peerconn
-> Set PeerAddr
forall b c a. (b -> c) -> (a -> b) -> a -> c
. PeerSelectionState PeerAddr peerconn -> LocalRootPeers PeerAddr
forall peeraddr peerconn.
PeerSelectionState peeraddr peerconn -> LocalRootPeers peeraddr
Governor.localRootPeers)
(GovernorMockEnvironment -> ConsensusMode
consensusMode GovernorMockEnvironment
env)
Events TestTraceEvent
events
govPublicRootPeersSig :: Signal (Set PeerAddr)
govPublicRootPeersSig :: Signal (Set PeerAddr)
govPublicRootPeersSig =
(forall peerconn.
PeerSelectionState PeerAddr peerconn -> Set PeerAddr)
-> ConsensusMode -> Events TestTraceEvent -> Signal (Set PeerAddr)
forall a.
Eq a =>
(forall peerconn. PeerSelectionState PeerAddr peerconn -> a)
-> ConsensusMode -> Events TestTraceEvent -> Signal a
selectGovState (PublicRootPeers PeerAddr -> Set PeerAddr
forall peeraddr.
Ord peeraddr =>
PublicRootPeers peeraddr -> Set peeraddr
PublicRootPeers.toSet (PublicRootPeers PeerAddr -> Set PeerAddr)
-> (PeerSelectionState PeerAddr peerconn
-> PublicRootPeers PeerAddr)
-> PeerSelectionState PeerAddr peerconn
-> Set PeerAddr
forall b c a. (b -> c) -> (a -> b) -> a -> c
. PeerSelectionState PeerAddr peerconn -> PublicRootPeers PeerAddr
forall peeraddr peerconn.
PeerSelectionState peeraddr peerconn -> PublicRootPeers peeraddr
Governor.publicRootPeers)
(GovernorMockEnvironment -> ConsensusMode
consensusMode GovernorMockEnvironment
env)
Events TestTraceEvent
events
govKnownPeersSig :: Signal (Set PeerAddr)
govKnownPeersSig :: Signal (Set PeerAddr)
govKnownPeersSig =
(forall peerconn.
PeerSelectionState PeerAddr peerconn -> Set PeerAddr)
-> ConsensusMode -> Events TestTraceEvent -> Signal (Set PeerAddr)
forall a.
Eq a =>
(forall peerconn. PeerSelectionState PeerAddr peerconn -> a)
-> ConsensusMode -> Events TestTraceEvent -> Signal a
selectGovState ((PeerSelectionState PeerAddr peerconn -> Set PeerAddr)
-> PeerSelectionState PeerAddr peerconn -> Set PeerAddr
forall peerconn.
(PeerSelectionState PeerAddr peerconn -> Set PeerAddr)
-> PeerSelectionState PeerAddr peerconn -> Set PeerAddr
dropBigLedgerPeers ((PeerSelectionState PeerAddr peerconn -> Set PeerAddr)
-> PeerSelectionState PeerAddr peerconn -> Set PeerAddr)
-> (PeerSelectionState PeerAddr peerconn -> Set PeerAddr)
-> PeerSelectionState PeerAddr peerconn
-> Set PeerAddr
forall a b. (a -> b) -> a -> b
$
KnownPeers PeerAddr -> Set PeerAddr
forall peeraddr. KnownPeers peeraddr -> Set peeraddr
KnownPeers.toSet (KnownPeers PeerAddr -> Set PeerAddr)
-> (PeerSelectionState PeerAddr peerconn -> KnownPeers PeerAddr)
-> PeerSelectionState PeerAddr peerconn
-> Set PeerAddr
forall b c a. (b -> c) -> (a -> b) -> a -> c
. PeerSelectionState PeerAddr peerconn -> KnownPeers PeerAddr
forall peeraddr peerconn.
PeerSelectionState peeraddr peerconn -> KnownPeers peeraddr
Governor.knownPeers)
(GovernorMockEnvironment -> ConsensusMode
consensusMode GovernorMockEnvironment
env)
Events TestTraceEvent
events
govEstablishedPeersSig :: Signal (Set PeerAddr)
govEstablishedPeersSig :: Signal (Set PeerAddr)
govEstablishedPeersSig =
(forall peerconn.
PeerSelectionState PeerAddr peerconn -> Set PeerAddr)
-> ConsensusMode -> Events TestTraceEvent -> Signal (Set PeerAddr)
forall a.
Eq a =>
(forall peerconn. PeerSelectionState PeerAddr peerconn -> a)
-> ConsensusMode -> Events TestTraceEvent -> Signal a
selectGovState ((PeerSelectionState PeerAddr peerconn -> Set PeerAddr)
-> PeerSelectionState PeerAddr peerconn -> Set PeerAddr
forall peerconn.
(PeerSelectionState PeerAddr peerconn -> Set PeerAddr)
-> PeerSelectionState PeerAddr peerconn -> Set PeerAddr
dropBigLedgerPeers ((PeerSelectionState PeerAddr peerconn -> Set PeerAddr)
-> PeerSelectionState PeerAddr peerconn -> Set PeerAddr)
-> (PeerSelectionState PeerAddr peerconn -> Set PeerAddr)
-> PeerSelectionState PeerAddr peerconn
-> Set PeerAddr
forall a b. (a -> b) -> a -> b
$
EstablishedPeers PeerAddr peerconn -> Set PeerAddr
forall peeraddr peerconn.
EstablishedPeers peeraddr peerconn -> Set peeraddr
EstablishedPeers.toSet (EstablishedPeers PeerAddr peerconn -> Set PeerAddr)
-> (PeerSelectionState PeerAddr peerconn
-> EstablishedPeers PeerAddr peerconn)
-> PeerSelectionState PeerAddr peerconn
-> Set PeerAddr
forall b c a. (b -> c) -> (a -> b) -> a -> c
. PeerSelectionState PeerAddr peerconn
-> EstablishedPeers PeerAddr peerconn
forall peeraddr peerconn.
PeerSelectionState peeraddr peerconn
-> EstablishedPeers peeraddr peerconn
Governor.establishedPeers)
(GovernorMockEnvironment -> ConsensusMode
consensusMode GovernorMockEnvironment
env)
Events TestTraceEvent
events
demotionOpportunity :: PeerSelectionTargets -> Set a -> Set a -> Set a -> Set a -> Set a
demotionOpportunity PeerSelectionTargets
targets Set a
local Set a
public Set a
known Set a
established
| Set a -> Int
forall a. Set a -> Int
Set.size Set a
known Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
<= PeerSelectionTargets -> Int
targetNumberOfKnownPeers PeerSelectionTargets
targets
= Set a
forall a. Set a
Set.empty
| Bool
otherwise
= Set a
known Set a -> Set a -> Set a
forall a. Ord a => Set a -> Set a -> Set a
Set.\\ Set a
established
Set a -> Set a -> Set a
forall a. Ord a => Set a -> Set a -> Set a
Set.\\ Set a
local
Set a -> Set a -> Set a
forall a. Ord a => Set a -> Set a -> Set a
Set.\\ Set a
publicProtected
where
publicProtected :: Set a
publicProtected
| Set a -> Int
forall a. Set a -> Int
Set.size Set a
local Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Set a -> Int
forall a. Set a -> Int
Set.size Set a
public
Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
<= PeerSelectionTargets -> Int
targetNumberOfRootPeers PeerSelectionTargets
targets
= Set a
public
| Bool
otherwise
= Set a
forall a. Set a
Set.empty
demotionOpportunities :: Signal (Set PeerAddr)
demotionOpportunities :: Signal (Set PeerAddr)
demotionOpportunities =
PeerSelectionTargets
-> Set PeerAddr
-> Set PeerAddr
-> Set PeerAddr
-> Set PeerAddr
-> Set PeerAddr
forall {a}.
Ord a =>
PeerSelectionTargets -> Set a -> Set a -> Set a -> Set a -> Set a
demotionOpportunity
(PeerSelectionTargets
-> Set PeerAddr
-> Set PeerAddr
-> Set PeerAddr
-> Set PeerAddr
-> Set PeerAddr)
-> Signal PeerSelectionTargets
-> Signal
(Set PeerAddr
-> Set PeerAddr -> Set PeerAddr -> Set PeerAddr -> Set PeerAddr)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Signal PeerSelectionTargets
govTargetsSig
Signal
(Set PeerAddr
-> Set PeerAddr -> Set PeerAddr -> Set PeerAddr -> Set PeerAddr)
-> Signal (Set PeerAddr)
-> Signal
(Set PeerAddr -> Set PeerAddr -> Set PeerAddr -> Set PeerAddr)
forall a b. Signal (a -> b) -> Signal a -> Signal b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Signal (Set PeerAddr)
govLocalRootPeersSig
Signal
(Set PeerAddr -> Set PeerAddr -> Set PeerAddr -> Set PeerAddr)
-> Signal (Set PeerAddr)
-> Signal (Set PeerAddr -> Set PeerAddr -> Set PeerAddr)
forall a b. Signal (a -> b) -> Signal a -> Signal b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Signal (Set PeerAddr)
govPublicRootPeersSig
Signal (Set PeerAddr -> Set PeerAddr -> Set PeerAddr)
-> Signal (Set PeerAddr) -> Signal (Set PeerAddr -> Set PeerAddr)
forall a b. Signal (a -> b) -> Signal a -> Signal b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Signal (Set PeerAddr)
govKnownPeersSig
Signal (Set PeerAddr -> Set PeerAddr)
-> Signal (Set PeerAddr) -> Signal (Set PeerAddr)
forall a b. Signal (a -> b) -> Signal a -> Signal b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Signal (Set PeerAddr)
govEstablishedPeersSig
demotionOpportunitiesIgnoredTooLong :: Signal (Set PeerAddr)
demotionOpportunitiesIgnoredTooLong :: Signal (Set PeerAddr)
demotionOpportunitiesIgnoredTooLong =
DiffTime
-> (Set PeerAddr -> Set PeerAddr)
-> Signal (Set PeerAddr)
-> Signal (Set PeerAddr)
forall a b.
Ord b =>
DiffTime -> (a -> Set b) -> Signal a -> Signal (Set b)
Signal.keyedTimeout
DiffTime
10
Set PeerAddr -> Set PeerAddr
forall a. a -> a
id
Signal (Set PeerAddr)
demotionOpportunities
in TestName -> Property -> Property
forall prop. Testable prop => TestName -> prop -> Property
counterexample
(TestName
"\nSignal key: (target (root, known), local peers, public peers, known peers, " TestName -> TestName -> TestName
forall a. [a] -> [a] -> [a]
++
TestName
"established peers, demotion opportunities, ignored too long)") (Property -> Property) -> Property -> Property
forall a b. (a -> b) -> a -> b
$
Int
-> (((Int, Int), Set PeerAddr, Set PeerAddr, Set PeerAddr,
Set PeerAddr, Set PeerAddr, Set PeerAddr)
-> TestName)
-> (((Int, Int), Set PeerAddr, Set PeerAddr, Set PeerAddr,
Set PeerAddr, Set PeerAddr, Set PeerAddr)
-> Bool)
-> Signal
((Int, Int), Set PeerAddr, Set PeerAddr, Set PeerAddr,
Set PeerAddr, Set PeerAddr, Set PeerAddr)
-> Property
forall a.
Int -> (a -> TestName) -> (a -> Bool) -> Signal a -> Property
signalProperty Int
20 ((Int, Int), Set PeerAddr, Set PeerAddr, Set PeerAddr,
Set PeerAddr, Set PeerAddr, Set PeerAddr)
-> TestName
forall a. Show a => a -> TestName
show
(\((Int, Int)
_,Set PeerAddr
_,Set PeerAddr
_,Set PeerAddr
_,Set PeerAddr
_,Set PeerAddr
_,Set PeerAddr
toolong) -> Set PeerAddr -> Bool
forall a. Set a -> Bool
Set.null Set PeerAddr
toolong)
((,,,,,,) ((Int, Int)
-> Set PeerAddr
-> Set PeerAddr
-> Set PeerAddr
-> Set PeerAddr
-> Set PeerAddr
-> Set PeerAddr
-> ((Int, Int), Set PeerAddr, Set PeerAddr, Set PeerAddr,
Set PeerAddr, Set PeerAddr, Set PeerAddr))
-> Signal (Int, Int)
-> Signal
(Set PeerAddr
-> Set PeerAddr
-> Set PeerAddr
-> Set PeerAddr
-> Set PeerAddr
-> Set PeerAddr
-> ((Int, Int), Set PeerAddr, Set PeerAddr, Set PeerAddr,
Set PeerAddr, Set PeerAddr, Set PeerAddr))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ((\PeerSelectionTargets
t -> (PeerSelectionTargets -> Int
targetNumberOfRootPeers PeerSelectionTargets
t,
PeerSelectionTargets -> Int
targetNumberOfKnownPeers PeerSelectionTargets
t)) (PeerSelectionTargets -> (Int, Int))
-> Signal PeerSelectionTargets -> Signal (Int, Int)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Signal PeerSelectionTargets
govTargetsSig)
Signal
(Set PeerAddr
-> Set PeerAddr
-> Set PeerAddr
-> Set PeerAddr
-> Set PeerAddr
-> Set PeerAddr
-> ((Int, Int), Set PeerAddr, Set PeerAddr, Set PeerAddr,
Set PeerAddr, Set PeerAddr, Set PeerAddr))
-> Signal (Set PeerAddr)
-> Signal
(Set PeerAddr
-> Set PeerAddr
-> Set PeerAddr
-> Set PeerAddr
-> Set PeerAddr
-> ((Int, Int), Set PeerAddr, Set PeerAddr, Set PeerAddr,
Set PeerAddr, Set PeerAddr, Set PeerAddr))
forall a b. Signal (a -> b) -> Signal a -> Signal b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Signal (Set PeerAddr)
govLocalRootPeersSig
Signal
(Set PeerAddr
-> Set PeerAddr
-> Set PeerAddr
-> Set PeerAddr
-> Set PeerAddr
-> ((Int, Int), Set PeerAddr, Set PeerAddr, Set PeerAddr,
Set PeerAddr, Set PeerAddr, Set PeerAddr))
-> Signal (Set PeerAddr)
-> Signal
(Set PeerAddr
-> Set PeerAddr
-> Set PeerAddr
-> Set PeerAddr
-> ((Int, Int), Set PeerAddr, Set PeerAddr, Set PeerAddr,
Set PeerAddr, Set PeerAddr, Set PeerAddr))
forall a b. Signal (a -> b) -> Signal a -> Signal b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Signal (Set PeerAddr)
govPublicRootPeersSig
Signal
(Set PeerAddr
-> Set PeerAddr
-> Set PeerAddr
-> Set PeerAddr
-> ((Int, Int), Set PeerAddr, Set PeerAddr, Set PeerAddr,
Set PeerAddr, Set PeerAddr, Set PeerAddr))
-> Signal (Set PeerAddr)
-> Signal
(Set PeerAddr
-> Set PeerAddr
-> Set PeerAddr
-> ((Int, Int), Set PeerAddr, Set PeerAddr, Set PeerAddr,
Set PeerAddr, Set PeerAddr, Set PeerAddr))
forall a b. Signal (a -> b) -> Signal a -> Signal b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Signal (Set PeerAddr)
govKnownPeersSig
Signal
(Set PeerAddr
-> Set PeerAddr
-> Set PeerAddr
-> ((Int, Int), Set PeerAddr, Set PeerAddr, Set PeerAddr,
Set PeerAddr, Set PeerAddr, Set PeerAddr))
-> Signal (Set PeerAddr)
-> Signal
(Set PeerAddr
-> Set PeerAddr
-> ((Int, Int), Set PeerAddr, Set PeerAddr, Set PeerAddr,
Set PeerAddr, Set PeerAddr, Set PeerAddr))
forall a b. Signal (a -> b) -> Signal a -> Signal b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Signal (Set PeerAddr)
govEstablishedPeersSig
Signal
(Set PeerAddr
-> Set PeerAddr
-> ((Int, Int), Set PeerAddr, Set PeerAddr, Set PeerAddr,
Set PeerAddr, Set PeerAddr, Set PeerAddr))
-> Signal (Set PeerAddr)
-> Signal
(Set PeerAddr
-> ((Int, Int), Set PeerAddr, Set PeerAddr, Set PeerAddr,
Set PeerAddr, Set PeerAddr, Set PeerAddr))
forall a b. Signal (a -> b) -> Signal a -> Signal b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Signal (Set PeerAddr)
demotionOpportunities
Signal
(Set PeerAddr
-> ((Int, Int), Set PeerAddr, Set PeerAddr, Set PeerAddr,
Set PeerAddr, Set PeerAddr, Set PeerAddr))
-> Signal (Set PeerAddr)
-> Signal
((Int, Int), Set PeerAddr, Set PeerAddr, Set PeerAddr,
Set PeerAddr, Set PeerAddr, Set PeerAddr)
forall a b. Signal (a -> b) -> Signal a -> Signal b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Signal (Set PeerAddr)
demotionOpportunitiesIgnoredTooLong)
prop_governor_target_known_big_ledger_peers_above
:: MaxTime -> GovernorMockEnvironment -> Property
prop_governor_target_known_big_ledger_peers_above :: MaxTime -> GovernorMockEnvironment -> Property
prop_governor_target_known_big_ledger_peers_above (MaxTime Time
maxTime) GovernorMockEnvironment
env =
let events :: Events TestTraceEvent
events = Time -> [(Time, TestTraceEvent)] -> Events TestTraceEvent
forall a. Time -> [(Time, a)] -> Events a
Signal.eventsFromListUpToTime Time
maxTime
([(Time, TestTraceEvent)] -> Events TestTraceEvent)
-> (GovernorMockEnvironment -> [(Time, TestTraceEvent)])
-> GovernorMockEnvironment
-> Events TestTraceEvent
forall b c a. (b -> c) -> (a -> b) -> a -> c
. SimTrace Void -> [(Time, TestTraceEvent)]
forall a. SimTrace a -> [(Time, TestTraceEvent)]
selectPeerSelectionTraceEvents
(SimTrace Void -> [(Time, TestTraceEvent)])
-> (GovernorMockEnvironment -> SimTrace Void)
-> GovernorMockEnvironment
-> [(Time, TestTraceEvent)]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. GovernorMockEnvironment -> SimTrace Void
runGovernorInMockEnvironment
(GovernorMockEnvironment -> Events TestTraceEvent)
-> GovernorMockEnvironment -> Events TestTraceEvent
forall a b. (a -> b) -> a -> b
$ GovernorMockEnvironment
env
govTargetsSig :: Signal PeerSelectionTargets
govTargetsSig :: Signal PeerSelectionTargets
govTargetsSig =
(forall peerconn.
PeerSelectionState PeerAddr peerconn -> PeerSelectionTargets)
-> ConsensusMode
-> Events TestTraceEvent
-> Signal PeerSelectionTargets
forall a.
Eq a =>
(forall peerconn. PeerSelectionState PeerAddr peerconn -> a)
-> ConsensusMode -> Events TestTraceEvent -> Signal a
selectGovState PeerSelectionState PeerAddr peerconn -> PeerSelectionTargets
forall peerconn.
PeerSelectionState PeerAddr peerconn -> PeerSelectionTargets
forall peeraddr peerconn.
PeerSelectionState peeraddr peerconn -> PeerSelectionTargets
Governor.targets (GovernorMockEnvironment -> ConsensusMode
consensusMode GovernorMockEnvironment
env) Events TestTraceEvent
events
govKnownPeersSig :: Signal (Set PeerAddr)
govKnownPeersSig :: Signal (Set PeerAddr)
govKnownPeersSig =
(forall peerconn.
PeerSelectionState PeerAddr peerconn -> Set PeerAddr)
-> ConsensusMode -> Events TestTraceEvent -> Signal (Set PeerAddr)
forall a.
Eq a =>
(forall peerconn. PeerSelectionState PeerAddr peerconn -> a)
-> ConsensusMode -> Events TestTraceEvent -> Signal a
selectGovState ((PeerSelectionState PeerAddr peerconn -> Set PeerAddr)
-> PeerSelectionState PeerAddr peerconn -> Set PeerAddr
forall peerconn.
(PeerSelectionState PeerAddr peerconn -> Set PeerAddr)
-> PeerSelectionState PeerAddr peerconn -> Set PeerAddr
takeBigLedgerPeers ((PeerSelectionState PeerAddr peerconn -> Set PeerAddr)
-> PeerSelectionState PeerAddr peerconn -> Set PeerAddr)
-> (PeerSelectionState PeerAddr peerconn -> Set PeerAddr)
-> PeerSelectionState PeerAddr peerconn
-> Set PeerAddr
forall a b. (a -> b) -> a -> b
$
KnownPeers PeerAddr -> Set PeerAddr
forall peeraddr. KnownPeers peeraddr -> Set peeraddr
KnownPeers.toSet (KnownPeers PeerAddr -> Set PeerAddr)
-> (PeerSelectionState PeerAddr peerconn -> KnownPeers PeerAddr)
-> PeerSelectionState PeerAddr peerconn
-> Set PeerAddr
forall b c a. (b -> c) -> (a -> b) -> a -> c
. PeerSelectionState PeerAddr peerconn -> KnownPeers PeerAddr
forall peeraddr peerconn.
PeerSelectionState peeraddr peerconn -> KnownPeers peeraddr
Governor.knownPeers)
(GovernorMockEnvironment -> ConsensusMode
consensusMode GovernorMockEnvironment
env)
Events TestTraceEvent
events
govEstablishedPeersSig :: Signal (Set PeerAddr)
govEstablishedPeersSig :: Signal (Set PeerAddr)
govEstablishedPeersSig =
(forall peerconn.
PeerSelectionState PeerAddr peerconn -> Set PeerAddr)
-> ConsensusMode -> Events TestTraceEvent -> Signal (Set PeerAddr)
forall a.
Eq a =>
(forall peerconn. PeerSelectionState PeerAddr peerconn -> a)
-> ConsensusMode -> Events TestTraceEvent -> Signal a
selectGovState ((PeerSelectionState PeerAddr peerconn -> Set PeerAddr)
-> PeerSelectionState PeerAddr peerconn -> Set PeerAddr
forall peerconn.
(PeerSelectionState PeerAddr peerconn -> Set PeerAddr)
-> PeerSelectionState PeerAddr peerconn -> Set PeerAddr
takeBigLedgerPeers ((PeerSelectionState PeerAddr peerconn -> Set PeerAddr)
-> PeerSelectionState PeerAddr peerconn -> Set PeerAddr)
-> (PeerSelectionState PeerAddr peerconn -> Set PeerAddr)
-> PeerSelectionState PeerAddr peerconn
-> Set PeerAddr
forall a b. (a -> b) -> a -> b
$
EstablishedPeers PeerAddr peerconn -> Set PeerAddr
forall peeraddr peerconn.
EstablishedPeers peeraddr peerconn -> Set peeraddr
EstablishedPeers.toSet (EstablishedPeers PeerAddr peerconn -> Set PeerAddr)
-> (PeerSelectionState PeerAddr peerconn
-> EstablishedPeers PeerAddr peerconn)
-> PeerSelectionState PeerAddr peerconn
-> Set PeerAddr
forall b c a. (b -> c) -> (a -> b) -> a -> c
. PeerSelectionState PeerAddr peerconn
-> EstablishedPeers PeerAddr peerconn
forall peeraddr peerconn.
PeerSelectionState peeraddr peerconn
-> EstablishedPeers peeraddr peerconn
Governor.establishedPeers)
(GovernorMockEnvironment -> ConsensusMode
consensusMode GovernorMockEnvironment
env)
Events TestTraceEvent
events
demotionOpportunity :: PeerSelectionTargets -> Set a -> Set a -> Set a
demotionOpportunity PeerSelectionTargets
targets Set a
known Set a
established
| Set a -> Int
forall a. Set a -> Int
Set.size Set a
known Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
<= PeerSelectionTargets -> Int
targetNumberOfKnownBigLedgerPeers PeerSelectionTargets
targets
= Set a
forall a. Set a
Set.empty
| Bool
otherwise
= Set a
known Set a -> Set a -> Set a
forall a. Ord a => Set a -> Set a -> Set a
Set.\\ Set a
established
demotionOpportunities :: Signal (Set PeerAddr)
demotionOpportunities :: Signal (Set PeerAddr)
demotionOpportunities =
PeerSelectionTargets
-> Set PeerAddr -> Set PeerAddr -> Set PeerAddr
forall {a}.
Ord a =>
PeerSelectionTargets -> Set a -> Set a -> Set a
demotionOpportunity
(PeerSelectionTargets
-> Set PeerAddr -> Set PeerAddr -> Set PeerAddr)
-> Signal PeerSelectionTargets
-> Signal (Set PeerAddr -> Set PeerAddr -> Set PeerAddr)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Signal PeerSelectionTargets
govTargetsSig
Signal (Set PeerAddr -> Set PeerAddr -> Set PeerAddr)
-> Signal (Set PeerAddr) -> Signal (Set PeerAddr -> Set PeerAddr)
forall a b. Signal (a -> b) -> Signal a -> Signal b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Signal (Set PeerAddr)
govKnownPeersSig
Signal (Set PeerAddr -> Set PeerAddr)
-> Signal (Set PeerAddr) -> Signal (Set PeerAddr)
forall a b. Signal (a -> b) -> Signal a -> Signal b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Signal (Set PeerAddr)
govEstablishedPeersSig
demotionOpportunitiesIgnoredTooLong :: Signal (Set PeerAddr)
demotionOpportunitiesIgnoredTooLong :: Signal (Set PeerAddr)
demotionOpportunitiesIgnoredTooLong =
DiffTime
-> (Set PeerAddr -> Set PeerAddr)
-> Signal (Set PeerAddr)
-> Signal (Set PeerAddr)
forall a b.
Ord b =>
DiffTime -> (a -> Set b) -> Signal a -> Signal (Set b)
Signal.keyedTimeout
DiffTime
10
Set PeerAddr -> Set PeerAddr
forall a. a -> a
id
Signal (Set PeerAddr)
demotionOpportunities
in TestName -> Property -> Property
forall prop. Testable prop => TestName -> prop -> Property
counterexample
(TestName
"\nSignal key: (target (root, known), local peers, public peers, known peers, " TestName -> TestName -> TestName
forall a. [a] -> [a] -> [a]
++
TestName
"established peers, demotion opportunities, ignored too long)") (Property -> Property) -> Property -> Property
forall a b. (a -> b) -> a -> b
$
Int
-> (((Int, Int), Set PeerAddr, Set PeerAddr, Set PeerAddr,
Set PeerAddr)
-> TestName)
-> (((Int, Int), Set PeerAddr, Set PeerAddr, Set PeerAddr,
Set PeerAddr)
-> Bool)
-> Signal
((Int, Int), Set PeerAddr, Set PeerAddr, Set PeerAddr,
Set PeerAddr)
-> Property
forall a.
Int -> (a -> TestName) -> (a -> Bool) -> Signal a -> Property
signalProperty Int
20 ((Int, Int), Set PeerAddr, Set PeerAddr, Set PeerAddr,
Set PeerAddr)
-> TestName
forall a. Show a => a -> TestName
show
(\((Int, Int)
_,Set PeerAddr
_,Set PeerAddr
_,Set PeerAddr
_,Set PeerAddr
toolong) -> Set PeerAddr -> Bool
forall a. Set a -> Bool
Set.null Set PeerAddr
toolong)
((,,,,) ((Int, Int)
-> Set PeerAddr
-> Set PeerAddr
-> Set PeerAddr
-> Set PeerAddr
-> ((Int, Int), Set PeerAddr, Set PeerAddr, Set PeerAddr,
Set PeerAddr))
-> Signal (Int, Int)
-> Signal
(Set PeerAddr
-> Set PeerAddr
-> Set PeerAddr
-> Set PeerAddr
-> ((Int, Int), Set PeerAddr, Set PeerAddr, Set PeerAddr,
Set PeerAddr))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ((\PeerSelectionTargets
t -> (PeerSelectionTargets -> Int
targetNumberOfRootPeers PeerSelectionTargets
t,
PeerSelectionTargets -> Int
targetNumberOfKnownPeers PeerSelectionTargets
t)) (PeerSelectionTargets -> (Int, Int))
-> Signal PeerSelectionTargets -> Signal (Int, Int)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Signal PeerSelectionTargets
govTargetsSig)
Signal
(Set PeerAddr
-> Set PeerAddr
-> Set PeerAddr
-> Set PeerAddr
-> ((Int, Int), Set PeerAddr, Set PeerAddr, Set PeerAddr,
Set PeerAddr))
-> Signal (Set PeerAddr)
-> Signal
(Set PeerAddr
-> Set PeerAddr
-> Set PeerAddr
-> ((Int, Int), Set PeerAddr, Set PeerAddr, Set PeerAddr,
Set PeerAddr))
forall a b. Signal (a -> b) -> Signal a -> Signal b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Signal (Set PeerAddr)
govKnownPeersSig
Signal
(Set PeerAddr
-> Set PeerAddr
-> Set PeerAddr
-> ((Int, Int), Set PeerAddr, Set PeerAddr, Set PeerAddr,
Set PeerAddr))
-> Signal (Set PeerAddr)
-> Signal
(Set PeerAddr
-> Set PeerAddr
-> ((Int, Int), Set PeerAddr, Set PeerAddr, Set PeerAddr,
Set PeerAddr))
forall a b. Signal (a -> b) -> Signal a -> Signal b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Signal (Set PeerAddr)
govEstablishedPeersSig
Signal
(Set PeerAddr
-> Set PeerAddr
-> ((Int, Int), Set PeerAddr, Set PeerAddr, Set PeerAddr,
Set PeerAddr))
-> Signal (Set PeerAddr)
-> Signal
(Set PeerAddr
-> ((Int, Int), Set PeerAddr, Set PeerAddr, Set PeerAddr,
Set PeerAddr))
forall a b. Signal (a -> b) -> Signal a -> Signal b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Signal (Set PeerAddr)
demotionOpportunities
Signal
(Set PeerAddr
-> ((Int, Int), Set PeerAddr, Set PeerAddr, Set PeerAddr,
Set PeerAddr))
-> Signal (Set PeerAddr)
-> Signal
((Int, Int), Set PeerAddr, Set PeerAddr, Set PeerAddr,
Set PeerAddr)
forall a b. Signal (a -> b) -> Signal a -> Signal b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Signal (Set PeerAddr)
demotionOpportunitiesIgnoredTooLong)
prop_governor_target_established_below :: MaxTime -> GovernorMockEnvironment -> Property
prop_governor_target_established_below :: MaxTime -> GovernorMockEnvironment -> Property
prop_governor_target_established_below (MaxTime Time
maxTime) GovernorMockEnvironment
env =
let events :: Events TestTraceEvent
events = Time -> [(Time, TestTraceEvent)] -> Events TestTraceEvent
forall a. Time -> [(Time, a)] -> Events a
Signal.eventsFromListUpToTime Time
maxTime
([(Time, TestTraceEvent)] -> Events TestTraceEvent)
-> (GovernorMockEnvironment -> [(Time, TestTraceEvent)])
-> GovernorMockEnvironment
-> Events TestTraceEvent
forall b c a. (b -> c) -> (a -> b) -> a -> c
. SimTrace Void -> [(Time, TestTraceEvent)]
forall a. SimTrace a -> [(Time, TestTraceEvent)]
selectPeerSelectionTraceEvents
(SimTrace Void -> [(Time, TestTraceEvent)])
-> (GovernorMockEnvironment -> SimTrace Void)
-> GovernorMockEnvironment
-> [(Time, TestTraceEvent)]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. GovernorMockEnvironment -> SimTrace Void
runGovernorInMockEnvironment
(GovernorMockEnvironment -> Events TestTraceEvent)
-> GovernorMockEnvironment -> Events TestTraceEvent
forall a b. (a -> b) -> a -> b
$ GovernorMockEnvironment
env
govTargetsSig :: Signal Int
govTargetsSig :: Signal Int
govTargetsSig =
(forall peerconn. PeerSelectionState PeerAddr peerconn -> Int)
-> ConsensusMode -> Events TestTraceEvent -> Signal Int
forall a.
Eq a =>
(forall peerconn. PeerSelectionState PeerAddr peerconn -> a)
-> ConsensusMode -> Events TestTraceEvent -> Signal a
selectGovState (PeerSelectionTargets -> Int
targetNumberOfEstablishedPeers (PeerSelectionTargets -> Int)
-> (PeerSelectionState PeerAddr peerconn -> PeerSelectionTargets)
-> PeerSelectionState PeerAddr peerconn
-> Int
forall b c a. (b -> c) -> (a -> b) -> a -> c
. PeerSelectionState PeerAddr peerconn -> PeerSelectionTargets
forall peeraddr peerconn.
PeerSelectionState peeraddr peerconn -> PeerSelectionTargets
Governor.targets)
(GovernorMockEnvironment -> ConsensusMode
consensusMode GovernorMockEnvironment
env)
Events TestTraceEvent
events
govKnownPeersSig :: Signal (Set PeerAddr)
govKnownPeersSig :: Signal (Set PeerAddr)
govKnownPeersSig =
(forall peerconn.
PeerSelectionState PeerAddr peerconn -> Set PeerAddr)
-> ConsensusMode -> Events TestTraceEvent -> Signal (Set PeerAddr)
forall a.
Eq a =>
(forall peerconn. PeerSelectionState PeerAddr peerconn -> a)
-> ConsensusMode -> Events TestTraceEvent -> Signal a
selectGovState ((PeerSelectionState PeerAddr peerconn -> Set PeerAddr)
-> PeerSelectionState PeerAddr peerconn -> Set PeerAddr
forall peerconn.
(PeerSelectionState PeerAddr peerconn -> Set PeerAddr)
-> PeerSelectionState PeerAddr peerconn -> Set PeerAddr
dropBigLedgerPeers ((PeerSelectionState PeerAddr peerconn -> Set PeerAddr)
-> PeerSelectionState PeerAddr peerconn -> Set PeerAddr)
-> (PeerSelectionState PeerAddr peerconn -> Set PeerAddr)
-> PeerSelectionState PeerAddr peerconn
-> Set PeerAddr
forall a b. (a -> b) -> a -> b
$
KnownPeers PeerAddr -> Set PeerAddr
forall peeraddr. KnownPeers peeraddr -> Set peeraddr
KnownPeers.toSet (KnownPeers PeerAddr -> Set PeerAddr)
-> (PeerSelectionState PeerAddr peerconn -> KnownPeers PeerAddr)
-> PeerSelectionState PeerAddr peerconn
-> Set PeerAddr
forall b c a. (b -> c) -> (a -> b) -> a -> c
. PeerSelectionState PeerAddr peerconn -> KnownPeers PeerAddr
forall peeraddr peerconn.
PeerSelectionState peeraddr peerconn -> KnownPeers peeraddr
Governor.knownPeers)
(GovernorMockEnvironment -> ConsensusMode
consensusMode GovernorMockEnvironment
env)
Events TestTraceEvent
events
govEstablishedPeersSig :: Signal (Set PeerAddr)
govEstablishedPeersSig :: Signal (Set PeerAddr)
govEstablishedPeersSig =
(forall peerconn.
PeerSelectionState PeerAddr peerconn -> Set PeerAddr)
-> ConsensusMode -> Events TestTraceEvent -> Signal (Set PeerAddr)
forall a.
Eq a =>
(forall peerconn. PeerSelectionState PeerAddr peerconn -> a)
-> ConsensusMode -> Events TestTraceEvent -> Signal a
selectGovState
(EstablishedPeers PeerAddr peerconn -> Set PeerAddr
forall peeraddr peerconn.
EstablishedPeers peeraddr peerconn -> Set peeraddr
EstablishedPeers.toSet (EstablishedPeers PeerAddr peerconn -> Set PeerAddr)
-> (PeerSelectionState PeerAddr peerconn
-> EstablishedPeers PeerAddr peerconn)
-> PeerSelectionState PeerAddr peerconn
-> Set PeerAddr
forall b c a. (b -> c) -> (a -> b) -> a -> c
. PeerSelectionState PeerAddr peerconn
-> EstablishedPeers PeerAddr peerconn
forall peeraddr peerconn.
PeerSelectionState peeraddr peerconn
-> EstablishedPeers peeraddr peerconn
Governor.establishedPeers)
(GovernorMockEnvironment -> ConsensusMode
consensusMode GovernorMockEnvironment
env)
Events TestTraceEvent
events
govEstablishedFailuresSig :: Signal (Set PeerAddr)
govEstablishedFailuresSig :: Signal (Set PeerAddr)
govEstablishedFailuresSig =
DiffTime
-> (Maybe (Set PeerAddr) -> Set PeerAddr)
-> Signal (Maybe (Set PeerAddr))
-> Signal (Set PeerAddr)
forall a b.
Ord b =>
DiffTime -> (a -> Set b) -> Signal a -> Signal (Set b)
Signal.keyedLinger
DiffTime
180
(Set PeerAddr -> Maybe (Set PeerAddr) -> Set PeerAddr
forall a. a -> Maybe a -> a
fromMaybe Set PeerAddr
forall a. Set a
Set.empty)
(Signal (Maybe (Set PeerAddr)) -> Signal (Set PeerAddr))
-> (Events TestTraceEvent -> Signal (Maybe (Set PeerAddr)))
-> Events TestTraceEvent
-> Signal (Set PeerAddr)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Events (Set PeerAddr) -> Signal (Maybe (Set PeerAddr))
forall a. Events a -> Signal (Maybe a)
Signal.fromEvents
(Events (Set PeerAddr) -> Signal (Maybe (Set PeerAddr)))
-> (Events TestTraceEvent -> Events (Set PeerAddr))
-> Events TestTraceEvent
-> Signal (Maybe (Set PeerAddr))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (TracePeerSelection PeerAddr -> Maybe (Set PeerAddr))
-> Events (TracePeerSelection PeerAddr) -> Events (Set PeerAddr)
forall a b. (a -> Maybe b) -> Events a -> Events b
Signal.selectEvents
(\case TracePromoteColdFailed Int
_ Int
_ PeerAddr
peer DiffTime
_ SomeException
_ ->
Set PeerAddr -> Maybe (Set PeerAddr)
forall a. a -> Maybe a
Just (Set PeerAddr -> Maybe (Set PeerAddr))
-> Set PeerAddr -> Maybe (Set PeerAddr)
forall a b. (a -> b) -> a -> b
$! PeerAddr -> Set PeerAddr
forall a. a -> Set a
Set.singleton PeerAddr
peer
TraceDemoteAsynchronous Map PeerAddr (PeerStatus, Maybe RepromoteDelay)
status
| Set PeerAddr -> Bool
forall a. Set a -> Bool
Set.null Set PeerAddr
failures -> Maybe (Set PeerAddr)
forall a. Maybe a
Nothing
| Bool
otherwise -> Set PeerAddr -> Maybe (Set PeerAddr)
forall a. a -> Maybe a
Just Set PeerAddr
failures
where
!failures :: Set PeerAddr
failures = Map PeerAddr PeerStatus -> Set PeerAddr
forall k a. Map k a -> Set k
Map.keysSet ((PeerStatus -> Bool)
-> Map PeerAddr PeerStatus -> Map PeerAddr PeerStatus
forall a k. (a -> Bool) -> Map k a -> Map k a
Map.filter (PeerStatus -> PeerStatus -> Bool
forall a. Eq a => a -> a -> Bool
==PeerStatus
PeerCooling) (Map PeerAddr PeerStatus -> Map PeerAddr PeerStatus)
-> (Map PeerAddr (PeerStatus, Maybe RepromoteDelay)
-> Map PeerAddr PeerStatus)
-> Map PeerAddr (PeerStatus, Maybe RepromoteDelay)
-> Map PeerAddr PeerStatus
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ((PeerStatus, Maybe RepromoteDelay) -> PeerStatus)
-> Map PeerAddr (PeerStatus, Maybe RepromoteDelay)
-> Map PeerAddr PeerStatus
forall a b. (a -> b) -> Map PeerAddr a -> Map PeerAddr b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (PeerStatus, Maybe RepromoteDelay) -> PeerStatus
forall a b. (a, b) -> a
fst (Map PeerAddr (PeerStatus, Maybe RepromoteDelay)
-> Map PeerAddr PeerStatus)
-> Map PeerAddr (PeerStatus, Maybe RepromoteDelay)
-> Map PeerAddr PeerStatus
forall a b. (a -> b) -> a -> b
$ Map PeerAddr (PeerStatus, Maybe RepromoteDelay)
status)
TraceDemoteLocalAsynchronous Map PeerAddr (PeerStatus, Maybe RepromoteDelay)
status
| Set PeerAddr -> Bool
forall a. Set a -> Bool
Set.null Set PeerAddr
failures -> Maybe (Set PeerAddr)
forall a. Maybe a
Nothing
| Bool
otherwise -> Set PeerAddr -> Maybe (Set PeerAddr)
forall a. a -> Maybe a
Just Set PeerAddr
failures
where
!failures :: Set PeerAddr
failures = Map PeerAddr PeerStatus -> Set PeerAddr
forall k a. Map k a -> Set k
Map.keysSet ((PeerStatus -> Bool)
-> Map PeerAddr PeerStatus -> Map PeerAddr PeerStatus
forall a k. (a -> Bool) -> Map k a -> Map k a
Map.filter (PeerStatus -> PeerStatus -> Bool
forall a. Eq a => a -> a -> Bool
==PeerStatus
PeerCooling) (Map PeerAddr PeerStatus -> Map PeerAddr PeerStatus)
-> (Map PeerAddr (PeerStatus, Maybe RepromoteDelay)
-> Map PeerAddr PeerStatus)
-> Map PeerAddr (PeerStatus, Maybe RepromoteDelay)
-> Map PeerAddr PeerStatus
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ((PeerStatus, Maybe RepromoteDelay) -> PeerStatus)
-> Map PeerAddr (PeerStatus, Maybe RepromoteDelay)
-> Map PeerAddr PeerStatus
forall a b. (a -> b) -> Map PeerAddr a -> Map PeerAddr b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (PeerStatus, Maybe RepromoteDelay) -> PeerStatus
forall a b. (a, b) -> a
fst (Map PeerAddr (PeerStatus, Maybe RepromoteDelay)
-> Map PeerAddr PeerStatus)
-> Map PeerAddr (PeerStatus, Maybe RepromoteDelay)
-> Map PeerAddr PeerStatus
forall a b. (a -> b) -> a -> b
$ Map PeerAddr (PeerStatus, Maybe RepromoteDelay)
status)
TracePromoteWarmFailed Int
_ Int
_ PeerAddr
peer SomeException
_ ->
Set PeerAddr -> Maybe (Set PeerAddr)
forall a. a -> Maybe a
Just (Set PeerAddr -> Maybe (Set PeerAddr))
-> Set PeerAddr -> Maybe (Set PeerAddr)
forall a b. (a -> b) -> a -> b
$! PeerAddr -> Set PeerAddr
forall a. a -> Set a
Set.singleton PeerAddr
peer
TraceDemoteWarmFailed Int
_ Int
_ PeerAddr
peer SomeException
_ ->
Set PeerAddr -> Maybe (Set PeerAddr)
forall a. a -> Maybe a
Just (Set PeerAddr -> Maybe (Set PeerAddr))
-> Set PeerAddr -> Maybe (Set PeerAddr)
forall a b. (a -> b) -> a -> b
$! PeerAddr -> Set PeerAddr
forall a. a -> Set a
Set.singleton PeerAddr
peer
TraceDemoteHotFailed Int
_ Int
_ PeerAddr
peer SomeException
_ ->
Set PeerAddr -> Maybe (Set PeerAddr)
forall a. a -> Maybe a
Just (Set PeerAddr -> Maybe (Set PeerAddr))
-> Set PeerAddr -> Maybe (Set PeerAddr)
forall a b. (a -> b) -> a -> b
$! PeerAddr -> Set PeerAddr
forall a. a -> Set a
Set.singleton PeerAddr
peer
TracePeerSelection PeerAddr
_ -> Maybe (Set PeerAddr)
forall a. Maybe a
Nothing
)
(Events (TracePeerSelection PeerAddr) -> Events (Set PeerAddr))
-> (Events TestTraceEvent -> Events (TracePeerSelection PeerAddr))
-> Events TestTraceEvent
-> Events (Set PeerAddr)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Events TestTraceEvent -> Events (TracePeerSelection PeerAddr)
selectGovEvents
(Events TestTraceEvent -> Signal (Set PeerAddr))
-> Events TestTraceEvent -> Signal (Set PeerAddr)
forall a b. (a -> b) -> a -> b
$ Events TestTraceEvent
events
promotionOpportunity :: Int -> Set a -> Set a -> Set a -> Set a
promotionOpportunity Int
target Set a
known Set a
established Set a
recentFailures
| Set a -> Int
forall a. Set a -> Int
Set.size Set a
established Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
>= Int
target
= Set a
forall a. Set a
Set.empty
| Bool
otherwise
= Set a
known Set a -> Set a -> Set a
forall a. Ord a => Set a -> Set a -> Set a
Set.\\ Set a
established
Set a -> Set a -> Set a
forall a. Ord a => Set a -> Set a -> Set a
Set.\\ Set a
recentFailures
promotionOpportunities :: Signal (Set PeerAddr)
promotionOpportunities :: Signal (Set PeerAddr)
promotionOpportunities =
Int -> Set PeerAddr -> Set PeerAddr -> Set PeerAddr -> Set PeerAddr
forall {a}. Ord a => Int -> Set a -> Set a -> Set a -> Set a
promotionOpportunity
(Int
-> Set PeerAddr -> Set PeerAddr -> Set PeerAddr -> Set PeerAddr)
-> Signal Int
-> Signal
(Set PeerAddr -> Set PeerAddr -> Set PeerAddr -> Set PeerAddr)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Signal Int
govTargetsSig
Signal
(Set PeerAddr -> Set PeerAddr -> Set PeerAddr -> Set PeerAddr)
-> Signal (Set PeerAddr)
-> Signal (Set PeerAddr -> Set PeerAddr -> Set PeerAddr)
forall a b. Signal (a -> b) -> Signal a -> Signal b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Signal (Set PeerAddr)
govKnownPeersSig
Signal (Set PeerAddr -> Set PeerAddr -> Set PeerAddr)
-> Signal (Set PeerAddr) -> Signal (Set PeerAddr -> Set PeerAddr)
forall a b. Signal (a -> b) -> Signal a -> Signal b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Signal (Set PeerAddr)
govEstablishedPeersSig
Signal (Set PeerAddr -> Set PeerAddr)
-> Signal (Set PeerAddr) -> Signal (Set PeerAddr)
forall a b. Signal (a -> b) -> Signal a -> Signal b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Signal (Set PeerAddr)
govEstablishedFailuresSig
promotionOpportunitiesIgnoredTooLong :: Signal (Set PeerAddr)
promotionOpportunitiesIgnoredTooLong :: Signal (Set PeerAddr)
promotionOpportunitiesIgnoredTooLong =
DiffTime
-> (Set PeerAddr -> Set PeerAddr)
-> Signal (Set PeerAddr)
-> Signal (Set PeerAddr)
forall a b.
Ord b =>
DiffTime -> (a -> Set b) -> Signal a -> Signal (Set b)
Signal.keyedTimeout
(RepromoteDelay -> DiffTime
repromoteDelay RepromoteDelay
config_REPROMOTE_DELAY DiffTime -> DiffTime -> DiffTime
forall a. Num a => a -> a -> a
+ DiffTime
20)
Set PeerAddr -> Set PeerAddr
forall a. a -> a
id
Signal (Set PeerAddr)
promotionOpportunities
in TestName -> Property -> Property
forall prop. Testable prop => TestName -> prop -> Property
counterexample
(TestName
"\nSignal key: (target, known peers, established peers, recent failures, " TestName -> TestName -> TestName
forall a. [a] -> [a] -> [a]
++
TestName
"opportunities, ignored too long)") (Property -> Property) -> Property -> Property
forall a b. (a -> b) -> a -> b
$
Int
-> ((Int, Set PeerAddr, Set PeerAddr, Set PeerAddr, Set PeerAddr,
Set PeerAddr)
-> TestName)
-> ((Int, Set PeerAddr, Set PeerAddr, Set PeerAddr, Set PeerAddr,
Set PeerAddr)
-> Bool)
-> Signal
(Int, Set PeerAddr, Set PeerAddr, Set PeerAddr, Set PeerAddr,
Set PeerAddr)
-> Property
forall a.
Int -> (a -> TestName) -> (a -> Bool) -> Signal a -> Property
signalProperty Int
20 (Int, Set PeerAddr, Set PeerAddr, Set PeerAddr, Set PeerAddr,
Set PeerAddr)
-> TestName
forall a. Show a => a -> TestName
show
(\(Int
_,Set PeerAddr
_,Set PeerAddr
_,Set PeerAddr
_,Set PeerAddr
_,Set PeerAddr
toolong) -> Set PeerAddr -> Bool
forall a. Set a -> Bool
Set.null Set PeerAddr
toolong)
((,,,,,) (Int
-> Set PeerAddr
-> Set PeerAddr
-> Set PeerAddr
-> Set PeerAddr
-> Set PeerAddr
-> (Int, Set PeerAddr, Set PeerAddr, Set PeerAddr, Set PeerAddr,
Set PeerAddr))
-> Signal Int
-> Signal
(Set PeerAddr
-> Set PeerAddr
-> Set PeerAddr
-> Set PeerAddr
-> Set PeerAddr
-> (Int, Set PeerAddr, Set PeerAddr, Set PeerAddr, Set PeerAddr,
Set PeerAddr))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Signal Int
govTargetsSig
Signal
(Set PeerAddr
-> Set PeerAddr
-> Set PeerAddr
-> Set PeerAddr
-> Set PeerAddr
-> (Int, Set PeerAddr, Set PeerAddr, Set PeerAddr, Set PeerAddr,
Set PeerAddr))
-> Signal (Set PeerAddr)
-> Signal
(Set PeerAddr
-> Set PeerAddr
-> Set PeerAddr
-> Set PeerAddr
-> (Int, Set PeerAddr, Set PeerAddr, Set PeerAddr, Set PeerAddr,
Set PeerAddr))
forall a b. Signal (a -> b) -> Signal a -> Signal b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Signal (Set PeerAddr)
govKnownPeersSig
Signal
(Set PeerAddr
-> Set PeerAddr
-> Set PeerAddr
-> Set PeerAddr
-> (Int, Set PeerAddr, Set PeerAddr, Set PeerAddr, Set PeerAddr,
Set PeerAddr))
-> Signal (Set PeerAddr)
-> Signal
(Set PeerAddr
-> Set PeerAddr
-> Set PeerAddr
-> (Int, Set PeerAddr, Set PeerAddr, Set PeerAddr, Set PeerAddr,
Set PeerAddr))
forall a b. Signal (a -> b) -> Signal a -> Signal b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Signal (Set PeerAddr)
govEstablishedPeersSig
Signal
(Set PeerAddr
-> Set PeerAddr
-> Set PeerAddr
-> (Int, Set PeerAddr, Set PeerAddr, Set PeerAddr, Set PeerAddr,
Set PeerAddr))
-> Signal (Set PeerAddr)
-> Signal
(Set PeerAddr
-> Set PeerAddr
-> (Int, Set PeerAddr, Set PeerAddr, Set PeerAddr, Set PeerAddr,
Set PeerAddr))
forall a b. Signal (a -> b) -> Signal a -> Signal b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Signal (Set PeerAddr)
govEstablishedFailuresSig
Signal
(Set PeerAddr
-> Set PeerAddr
-> (Int, Set PeerAddr, Set PeerAddr, Set PeerAddr, Set PeerAddr,
Set PeerAddr))
-> Signal (Set PeerAddr)
-> Signal
(Set PeerAddr
-> (Int, Set PeerAddr, Set PeerAddr, Set PeerAddr, Set PeerAddr,
Set PeerAddr))
forall a b. Signal (a -> b) -> Signal a -> Signal b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Signal (Set PeerAddr)
promotionOpportunities
Signal
(Set PeerAddr
-> (Int, Set PeerAddr, Set PeerAddr, Set PeerAddr, Set PeerAddr,
Set PeerAddr))
-> Signal (Set PeerAddr)
-> Signal
(Int, Set PeerAddr, Set PeerAddr, Set PeerAddr, Set PeerAddr,
Set PeerAddr)
forall a b. Signal (a -> b) -> Signal a -> Signal b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Signal (Set PeerAddr)
promotionOpportunitiesIgnoredTooLong)
prop_governor_target_established_big_ledger_peers_below
:: MaxTime -> GovernorMockEnvironment -> Property
prop_governor_target_established_big_ledger_peers_below :: MaxTime -> GovernorMockEnvironment -> Property
prop_governor_target_established_big_ledger_peers_below (MaxTime Time
maxTime) GovernorMockEnvironment
env =
let events :: Events TestTraceEvent
events = Time -> [(Time, TestTraceEvent)] -> Events TestTraceEvent
forall a. Time -> [(Time, a)] -> Events a
Signal.eventsFromListUpToTime Time
maxTime
([(Time, TestTraceEvent)] -> Events TestTraceEvent)
-> (GovernorMockEnvironment -> [(Time, TestTraceEvent)])
-> GovernorMockEnvironment
-> Events TestTraceEvent
forall b c a. (b -> c) -> (a -> b) -> a -> c
. SimTrace Void -> [(Time, TestTraceEvent)]
forall a. SimTrace a -> [(Time, TestTraceEvent)]
selectPeerSelectionTraceEvents
(SimTrace Void -> [(Time, TestTraceEvent)])
-> (GovernorMockEnvironment -> SimTrace Void)
-> GovernorMockEnvironment
-> [(Time, TestTraceEvent)]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. GovernorMockEnvironment -> SimTrace Void
runGovernorInMockEnvironment
(GovernorMockEnvironment -> Events TestTraceEvent)
-> GovernorMockEnvironment -> Events TestTraceEvent
forall a b. (a -> b) -> a -> b
$ GovernorMockEnvironment
env
govTargetsSig :: Signal Int
govTargetsSig :: Signal Int
govTargetsSig =
(forall peerconn. PeerSelectionState PeerAddr peerconn -> Int)
-> ConsensusMode -> Events TestTraceEvent -> Signal Int
forall a.
Eq a =>
(forall peerconn. PeerSelectionState PeerAddr peerconn -> a)
-> ConsensusMode -> Events TestTraceEvent -> Signal a
selectGovState (PeerSelectionTargets -> Int
targetNumberOfEstablishedBigLedgerPeers (PeerSelectionTargets -> Int)
-> (PeerSelectionState PeerAddr peerconn -> PeerSelectionTargets)
-> PeerSelectionState PeerAddr peerconn
-> Int
forall b c a. (b -> c) -> (a -> b) -> a -> c
. PeerSelectionState PeerAddr peerconn -> PeerSelectionTargets
forall peeraddr peerconn.
PeerSelectionState peeraddr peerconn -> PeerSelectionTargets
Governor.targets)
(GovernorMockEnvironment -> ConsensusMode
consensusMode GovernorMockEnvironment
env)
Events TestTraceEvent
events
govKnownPeersSig :: Signal (Set PeerAddr)
govKnownPeersSig :: Signal (Set PeerAddr)
govKnownPeersSig =
(forall peerconn.
PeerSelectionState PeerAddr peerconn -> Set PeerAddr)
-> ConsensusMode -> Events TestTraceEvent -> Signal (Set PeerAddr)
forall a.
Eq a =>
(forall peerconn. PeerSelectionState PeerAddr peerconn -> a)
-> ConsensusMode -> Events TestTraceEvent -> Signal a
selectGovState ((PeerSelectionState PeerAddr peerconn -> Set PeerAddr)
-> PeerSelectionState PeerAddr peerconn -> Set PeerAddr
forall peerconn.
(PeerSelectionState PeerAddr peerconn -> Set PeerAddr)
-> PeerSelectionState PeerAddr peerconn -> Set PeerAddr
takeBigLedgerPeers ((PeerSelectionState PeerAddr peerconn -> Set PeerAddr)
-> PeerSelectionState PeerAddr peerconn -> Set PeerAddr)
-> (PeerSelectionState PeerAddr peerconn -> Set PeerAddr)
-> PeerSelectionState PeerAddr peerconn
-> Set PeerAddr
forall a b. (a -> b) -> a -> b
$
KnownPeers PeerAddr -> Set PeerAddr
forall peeraddr. KnownPeers peeraddr -> Set peeraddr
KnownPeers.toSet (KnownPeers PeerAddr -> Set PeerAddr)
-> (PeerSelectionState PeerAddr peerconn -> KnownPeers PeerAddr)
-> PeerSelectionState PeerAddr peerconn
-> Set PeerAddr
forall b c a. (b -> c) -> (a -> b) -> a -> c
. PeerSelectionState PeerAddr peerconn -> KnownPeers PeerAddr
forall peeraddr peerconn.
PeerSelectionState peeraddr peerconn -> KnownPeers peeraddr
Governor.knownPeers)
(GovernorMockEnvironment -> ConsensusMode
consensusMode GovernorMockEnvironment
env)
Events TestTraceEvent
events
govEstablishedPeersSig :: Signal (Set PeerAddr)
govEstablishedPeersSig :: Signal (Set PeerAddr)
govEstablishedPeersSig =
(forall peerconn.
PeerSelectionState PeerAddr peerconn -> Set PeerAddr)
-> ConsensusMode -> Events TestTraceEvent -> Signal (Set PeerAddr)
forall a.
Eq a =>
(forall peerconn. PeerSelectionState PeerAddr peerconn -> a)
-> ConsensusMode -> Events TestTraceEvent -> Signal a
selectGovState
((PeerSelectionState PeerAddr peerconn -> Set PeerAddr)
-> PeerSelectionState PeerAddr peerconn -> Set PeerAddr
forall peerconn.
(PeerSelectionState PeerAddr peerconn -> Set PeerAddr)
-> PeerSelectionState PeerAddr peerconn -> Set PeerAddr
takeBigLedgerPeers ((PeerSelectionState PeerAddr peerconn -> Set PeerAddr)
-> PeerSelectionState PeerAddr peerconn -> Set PeerAddr)
-> (PeerSelectionState PeerAddr peerconn -> Set PeerAddr)
-> PeerSelectionState PeerAddr peerconn
-> Set PeerAddr
forall a b. (a -> b) -> a -> b
$
EstablishedPeers PeerAddr peerconn -> Set PeerAddr
forall peeraddr peerconn.
EstablishedPeers peeraddr peerconn -> Set peeraddr
EstablishedPeers.toSet (EstablishedPeers PeerAddr peerconn -> Set PeerAddr)
-> (PeerSelectionState PeerAddr peerconn
-> EstablishedPeers PeerAddr peerconn)
-> PeerSelectionState PeerAddr peerconn
-> Set PeerAddr
forall b c a. (b -> c) -> (a -> b) -> a -> c
. PeerSelectionState PeerAddr peerconn
-> EstablishedPeers PeerAddr peerconn
forall peeraddr peerconn.
PeerSelectionState peeraddr peerconn
-> EstablishedPeers peeraddr peerconn
Governor.establishedPeers)
(GovernorMockEnvironment -> ConsensusMode
consensusMode GovernorMockEnvironment
env)
Events TestTraceEvent
events
govEstablishedFailuresSig :: Signal (Set PeerAddr)
govEstablishedFailuresSig :: Signal (Set PeerAddr)
govEstablishedFailuresSig =
DiffTime
-> (Maybe (Set PeerAddr) -> Set PeerAddr)
-> Signal (Maybe (Set PeerAddr))
-> Signal (Set PeerAddr)
forall a b.
Ord b =>
DiffTime -> (a -> Set b) -> Signal a -> Signal (Set b)
Signal.keyedLinger
DiffTime
180
(Set PeerAddr -> Maybe (Set PeerAddr) -> Set PeerAddr
forall a. a -> Maybe a -> a
fromMaybe Set PeerAddr
forall a. Set a
Set.empty)
(Signal (Maybe (Set PeerAddr)) -> Signal (Set PeerAddr))
-> (Events TestTraceEvent -> Signal (Maybe (Set PeerAddr)))
-> Events TestTraceEvent
-> Signal (Set PeerAddr)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Events (Set PeerAddr) -> Signal (Maybe (Set PeerAddr))
forall a. Events a -> Signal (Maybe a)
Signal.fromEvents
(Events (Set PeerAddr) -> Signal (Maybe (Set PeerAddr)))
-> (Events TestTraceEvent -> Events (Set PeerAddr))
-> Events TestTraceEvent
-> Signal (Maybe (Set PeerAddr))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (TracePeerSelection PeerAddr -> Maybe (Set PeerAddr))
-> Events (TracePeerSelection PeerAddr) -> Events (Set PeerAddr)
forall a b. (a -> Maybe b) -> Events a -> Events b
Signal.selectEvents
(\case TracePromoteColdBigLedgerPeerFailed Int
_ Int
_ PeerAddr
peer DiffTime
_ SomeException
_ ->
Set PeerAddr -> Maybe (Set PeerAddr)
forall a. a -> Maybe a
Just (PeerAddr -> Set PeerAddr
forall a. a -> Set a
Set.singleton PeerAddr
peer)
TracePromoteWarmBigLedgerPeerFailed Int
_ Int
_ PeerAddr
peer SomeException
_ ->
Set PeerAddr -> Maybe (Set PeerAddr)
forall a. a -> Maybe a
Just (PeerAddr -> Set PeerAddr
forall a. a -> Set a
Set.singleton PeerAddr
peer)
TraceDemoteBigLedgerPeersAsynchronous Map PeerAddr (PeerStatus, Maybe RepromoteDelay)
status
| Set PeerAddr -> Bool
forall a. Set a -> Bool
Set.null Set PeerAddr
failures -> Maybe (Set PeerAddr)
forall a. Maybe a
Nothing
| Bool
otherwise -> Set PeerAddr -> Maybe (Set PeerAddr)
forall a. a -> Maybe a
Just Set PeerAddr
failures
where
failures :: Set PeerAddr
failures = Map PeerAddr PeerStatus -> Set PeerAddr
forall k a. Map k a -> Set k
Map.keysSet ((PeerStatus -> Bool)
-> Map PeerAddr PeerStatus -> Map PeerAddr PeerStatus
forall a k. (a -> Bool) -> Map k a -> Map k a
Map.filter (PeerStatus -> PeerStatus -> Bool
forall a. Eq a => a -> a -> Bool
==PeerStatus
PeerCooling) (Map PeerAddr PeerStatus -> Map PeerAddr PeerStatus)
-> (Map PeerAddr (PeerStatus, Maybe RepromoteDelay)
-> Map PeerAddr PeerStatus)
-> Map PeerAddr (PeerStatus, Maybe RepromoteDelay)
-> Map PeerAddr PeerStatus
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ((PeerStatus, Maybe RepromoteDelay) -> PeerStatus)
-> Map PeerAddr (PeerStatus, Maybe RepromoteDelay)
-> Map PeerAddr PeerStatus
forall a b. (a -> b) -> Map PeerAddr a -> Map PeerAddr b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (PeerStatus, Maybe RepromoteDelay) -> PeerStatus
forall a b. (a, b) -> a
fst (Map PeerAddr (PeerStatus, Maybe RepromoteDelay)
-> Map PeerAddr PeerStatus)
-> Map PeerAddr (PeerStatus, Maybe RepromoteDelay)
-> Map PeerAddr PeerStatus
forall a b. (a -> b) -> a -> b
$ Map PeerAddr (PeerStatus, Maybe RepromoteDelay)
status)
TraceDemoteLocalAsynchronous Map PeerAddr (PeerStatus, Maybe RepromoteDelay)
status
| Set PeerAddr -> Bool
forall a. Set a -> Bool
Set.null Set PeerAddr
failures -> Maybe (Set PeerAddr)
forall a. Maybe a
Nothing
| Bool
otherwise -> Set PeerAddr -> Maybe (Set PeerAddr)
forall a. a -> Maybe a
Just Set PeerAddr
failures
where
failures :: Set PeerAddr
failures = Map PeerAddr PeerStatus -> Set PeerAddr
forall k a. Map k a -> Set k
Map.keysSet ((PeerStatus -> Bool)
-> Map PeerAddr PeerStatus -> Map PeerAddr PeerStatus
forall a k. (a -> Bool) -> Map k a -> Map k a
Map.filter (PeerStatus -> PeerStatus -> Bool
forall a. Eq a => a -> a -> Bool
==PeerStatus
PeerCooling) (Map PeerAddr PeerStatus -> Map PeerAddr PeerStatus)
-> (Map PeerAddr (PeerStatus, Maybe RepromoteDelay)
-> Map PeerAddr PeerStatus)
-> Map PeerAddr (PeerStatus, Maybe RepromoteDelay)
-> Map PeerAddr PeerStatus
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ((PeerStatus, Maybe RepromoteDelay) -> PeerStatus)
-> Map PeerAddr (PeerStatus, Maybe RepromoteDelay)
-> Map PeerAddr PeerStatus
forall a b. (a -> b) -> Map PeerAddr a -> Map PeerAddr b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (PeerStatus, Maybe RepromoteDelay) -> PeerStatus
forall a b. (a, b) -> a
fst (Map PeerAddr (PeerStatus, Maybe RepromoteDelay)
-> Map PeerAddr PeerStatus)
-> Map PeerAddr (PeerStatus, Maybe RepromoteDelay)
-> Map PeerAddr PeerStatus
forall a b. (a -> b) -> a -> b
$ Map PeerAddr (PeerStatus, Maybe RepromoteDelay)
status)
TracePromoteWarmFailed Int
_ Int
_ PeerAddr
peer SomeException
_ ->
Set PeerAddr -> Maybe (Set PeerAddr)
forall a. a -> Maybe a
Just (PeerAddr -> Set PeerAddr
forall a. a -> Set a
Set.singleton PeerAddr
peer)
TraceDemoteWarmBigLedgerPeerFailed Int
_ Int
_ PeerAddr
peer SomeException
_ ->
Set PeerAddr -> Maybe (Set PeerAddr)
forall a. a -> Maybe a
Just (PeerAddr -> Set PeerAddr
forall a. a -> Set a
Set.singleton PeerAddr
peer)
TraceDemoteHotBigLedgerPeerFailed Int
_ Int
_ PeerAddr
peer SomeException
_ ->
Set PeerAddr -> Maybe (Set PeerAddr)
forall a. a -> Maybe a
Just (PeerAddr -> Set PeerAddr
forall a. a -> Set a
Set.singleton PeerAddr
peer)
TracePeerSelection PeerAddr
_ -> Maybe (Set PeerAddr)
forall a. Maybe a
Nothing
)
(Events (TracePeerSelection PeerAddr) -> Events (Set PeerAddr))
-> (Events TestTraceEvent -> Events (TracePeerSelection PeerAddr))
-> Events TestTraceEvent
-> Events (Set PeerAddr)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Events TestTraceEvent -> Events (TracePeerSelection PeerAddr)
selectGovEvents
(Events TestTraceEvent -> Signal (Set PeerAddr))
-> Events TestTraceEvent -> Signal (Set PeerAddr)
forall a b. (a -> b) -> a -> b
$ Events TestTraceEvent
events
promotionOpportunity :: Int -> Set a -> Set a -> Set a -> Set a
promotionOpportunity Int
target Set a
known Set a
established Set a
recentFailures
| Set a -> Int
forall a. Set a -> Int
Set.size Set a
established Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
>= Int
target
= Set a
forall a. Set a
Set.empty
| Bool
otherwise
= Set a
known Set a -> Set a -> Set a
forall a. Ord a => Set a -> Set a -> Set a
Set.\\ Set a
established
Set a -> Set a -> Set a
forall a. Ord a => Set a -> Set a -> Set a
Set.\\ Set a
recentFailures
promotionOpportunities :: Signal (Set PeerAddr)
promotionOpportunities :: Signal (Set PeerAddr)
promotionOpportunities =
Int -> Set PeerAddr -> Set PeerAddr -> Set PeerAddr -> Set PeerAddr
forall {a}. Ord a => Int -> Set a -> Set a -> Set a -> Set a
promotionOpportunity
(Int
-> Set PeerAddr -> Set PeerAddr -> Set PeerAddr -> Set PeerAddr)
-> Signal Int
-> Signal
(Set PeerAddr -> Set PeerAddr -> Set PeerAddr -> Set PeerAddr)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Signal Int
govTargetsSig
Signal
(Set PeerAddr -> Set PeerAddr -> Set PeerAddr -> Set PeerAddr)
-> Signal (Set PeerAddr)
-> Signal (Set PeerAddr -> Set PeerAddr -> Set PeerAddr)
forall a b. Signal (a -> b) -> Signal a -> Signal b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Signal (Set PeerAddr)
govKnownPeersSig
Signal (Set PeerAddr -> Set PeerAddr -> Set PeerAddr)
-> Signal (Set PeerAddr) -> Signal (Set PeerAddr -> Set PeerAddr)
forall a b. Signal (a -> b) -> Signal a -> Signal b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Signal (Set PeerAddr)
govEstablishedPeersSig
Signal (Set PeerAddr -> Set PeerAddr)
-> Signal (Set PeerAddr) -> Signal (Set PeerAddr)
forall a b. Signal (a -> b) -> Signal a -> Signal b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Signal (Set PeerAddr)
govEstablishedFailuresSig
promotionOpportunitiesIgnoredTooLong :: Signal (Set PeerAddr)
promotionOpportunitiesIgnoredTooLong :: Signal (Set PeerAddr)
promotionOpportunitiesIgnoredTooLong =
DiffTime
-> (Set PeerAddr -> Set PeerAddr)
-> Signal (Set PeerAddr)
-> Signal (Set PeerAddr)
forall a b.
Ord b =>
DiffTime -> (a -> Set b) -> Signal a -> Signal (Set b)
Signal.keyedTimeout
(RepromoteDelay -> DiffTime
repromoteDelay RepromoteDelay
config_REPROMOTE_DELAY DiffTime -> DiffTime -> DiffTime
forall a. Num a => a -> a -> a
+ DiffTime
20)
Set PeerAddr -> Set PeerAddr
forall a. a -> a
id
Signal (Set PeerAddr)
promotionOpportunities
in TestName -> Property -> Property
forall prop. Testable prop => TestName -> prop -> Property
counterexample
(TestName
"\nSignal key: (target, known big ledger peers, established big ledger peers, recent failures, " TestName -> TestName -> TestName
forall a. [a] -> [a] -> [a]
++
TestName
"opportunities, ignored too long)") (Property -> Property) -> Property -> Property
forall a b. (a -> b) -> a -> b
$
Int
-> ((Int, Set PeerAddr, Set PeerAddr, Set PeerAddr, Set PeerAddr,
Set PeerAddr)
-> TestName)
-> ((Int, Set PeerAddr, Set PeerAddr, Set PeerAddr, Set PeerAddr,
Set PeerAddr)
-> Bool)
-> Signal
(Int, Set PeerAddr, Set PeerAddr, Set PeerAddr, Set PeerAddr,
Set PeerAddr)
-> Property
forall a.
Int -> (a -> TestName) -> (a -> Bool) -> Signal a -> Property
signalProperty Int
20 (Int, Set PeerAddr, Set PeerAddr, Set PeerAddr, Set PeerAddr,
Set PeerAddr)
-> TestName
forall a. Show a => a -> TestName
show
(\(Int
_,Set PeerAddr
_,Set PeerAddr
_,Set PeerAddr
_,Set PeerAddr
_,Set PeerAddr
toolong) -> Set PeerAddr -> Bool
forall a. Set a -> Bool
Set.null Set PeerAddr
toolong)
((,,,,,) (Int
-> Set PeerAddr
-> Set PeerAddr
-> Set PeerAddr
-> Set PeerAddr
-> Set PeerAddr
-> (Int, Set PeerAddr, Set PeerAddr, Set PeerAddr, Set PeerAddr,
Set PeerAddr))
-> Signal Int
-> Signal
(Set PeerAddr
-> Set PeerAddr
-> Set PeerAddr
-> Set PeerAddr
-> Set PeerAddr
-> (Int, Set PeerAddr, Set PeerAddr, Set PeerAddr, Set PeerAddr,
Set PeerAddr))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Signal Int
govTargetsSig
Signal
(Set PeerAddr
-> Set PeerAddr
-> Set PeerAddr
-> Set PeerAddr
-> Set PeerAddr
-> (Int, Set PeerAddr, Set PeerAddr, Set PeerAddr, Set PeerAddr,
Set PeerAddr))
-> Signal (Set PeerAddr)
-> Signal
(Set PeerAddr
-> Set PeerAddr
-> Set PeerAddr
-> Set PeerAddr
-> (Int, Set PeerAddr, Set PeerAddr, Set PeerAddr, Set PeerAddr,
Set PeerAddr))
forall a b. Signal (a -> b) -> Signal a -> Signal b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Signal (Set PeerAddr)
govKnownPeersSig
Signal
(Set PeerAddr
-> Set PeerAddr
-> Set PeerAddr
-> Set PeerAddr
-> (Int, Set PeerAddr, Set PeerAddr, Set PeerAddr, Set PeerAddr,
Set PeerAddr))
-> Signal (Set PeerAddr)
-> Signal
(Set PeerAddr
-> Set PeerAddr
-> Set PeerAddr
-> (Int, Set PeerAddr, Set PeerAddr, Set PeerAddr, Set PeerAddr,
Set PeerAddr))
forall a b. Signal (a -> b) -> Signal a -> Signal b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Signal (Set PeerAddr)
govEstablishedPeersSig
Signal
(Set PeerAddr
-> Set PeerAddr
-> Set PeerAddr
-> (Int, Set PeerAddr, Set PeerAddr, Set PeerAddr, Set PeerAddr,
Set PeerAddr))
-> Signal (Set PeerAddr)
-> Signal
(Set PeerAddr
-> Set PeerAddr
-> (Int, Set PeerAddr, Set PeerAddr, Set PeerAddr, Set PeerAddr,
Set PeerAddr))
forall a b. Signal (a -> b) -> Signal a -> Signal b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Signal (Set PeerAddr)
govEstablishedFailuresSig
Signal
(Set PeerAddr
-> Set PeerAddr
-> (Int, Set PeerAddr, Set PeerAddr, Set PeerAddr, Set PeerAddr,
Set PeerAddr))
-> Signal (Set PeerAddr)
-> Signal
(Set PeerAddr
-> (Int, Set PeerAddr, Set PeerAddr, Set PeerAddr, Set PeerAddr,
Set PeerAddr))
forall a b. Signal (a -> b) -> Signal a -> Signal b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Signal (Set PeerAddr)
promotionOpportunities
Signal
(Set PeerAddr
-> (Int, Set PeerAddr, Set PeerAddr, Set PeerAddr, Set PeerAddr,
Set PeerAddr))
-> Signal (Set PeerAddr)
-> Signal
(Int, Set PeerAddr, Set PeerAddr, Set PeerAddr, Set PeerAddr,
Set PeerAddr)
forall a b. Signal (a -> b) -> Signal a -> Signal b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Signal (Set PeerAddr)
promotionOpportunitiesIgnoredTooLong)
prop_governor_target_active_below :: MaxTime -> GovernorMockEnvironment -> Property
prop_governor_target_active_below :: MaxTime -> GovernorMockEnvironment -> Property
prop_governor_target_active_below (MaxTime Time
maxTime) GovernorMockEnvironment
env =
let events :: Events TestTraceEvent
events = Time -> [(Time, TestTraceEvent)] -> Events TestTraceEvent
forall a. Time -> [(Time, a)] -> Events a
Signal.eventsFromListUpToTime Time
maxTime
([(Time, TestTraceEvent)] -> Events TestTraceEvent)
-> (GovernorMockEnvironment -> [(Time, TestTraceEvent)])
-> GovernorMockEnvironment
-> Events TestTraceEvent
forall b c a. (b -> c) -> (a -> b) -> a -> c
. SimTrace Void -> [(Time, TestTraceEvent)]
forall a. SimTrace a -> [(Time, TestTraceEvent)]
selectPeerSelectionTraceEvents
(SimTrace Void -> [(Time, TestTraceEvent)])
-> (GovernorMockEnvironment -> SimTrace Void)
-> GovernorMockEnvironment
-> [(Time, TestTraceEvent)]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. GovernorMockEnvironment -> SimTrace Void
runGovernorInMockEnvironment
(GovernorMockEnvironment -> Events TestTraceEvent)
-> GovernorMockEnvironment -> Events TestTraceEvent
forall a b. (a -> b) -> a -> b
$ GovernorMockEnvironment
env
govTargetsSig :: Signal Int
govTargetsSig :: Signal Int
govTargetsSig =
(forall peerconn. PeerSelectionState PeerAddr peerconn -> Int)
-> ConsensusMode -> Events TestTraceEvent -> Signal Int
forall a.
Eq a =>
(forall peerconn. PeerSelectionState PeerAddr peerconn -> a)
-> ConsensusMode -> Events TestTraceEvent -> Signal a
selectGovState (PeerSelectionTargets -> Int
targetNumberOfActivePeers (PeerSelectionTargets -> Int)
-> (PeerSelectionState PeerAddr peerconn -> PeerSelectionTargets)
-> PeerSelectionState PeerAddr peerconn
-> Int
forall b c a. (b -> c) -> (a -> b) -> a -> c
. PeerSelectionState PeerAddr peerconn -> PeerSelectionTargets
forall peeraddr peerconn.
PeerSelectionState peeraddr peerconn -> PeerSelectionTargets
Governor.targets)
(GovernorMockEnvironment -> ConsensusMode
consensusMode GovernorMockEnvironment
env)
Events TestTraceEvent
events
govLocalRootPeersSig :: Signal (LocalRootPeers.LocalRootPeers PeerAddr)
govLocalRootPeersSig :: Signal (LocalRootPeers PeerAddr)
govLocalRootPeersSig =
(forall peerconn.
PeerSelectionState PeerAddr peerconn -> LocalRootPeers PeerAddr)
-> ConsensusMode
-> Events TestTraceEvent
-> Signal (LocalRootPeers PeerAddr)
forall a.
Eq a =>
(forall peerconn. PeerSelectionState PeerAddr peerconn -> a)
-> ConsensusMode -> Events TestTraceEvent -> Signal a
selectGovState PeerSelectionState PeerAddr peerconn -> LocalRootPeers PeerAddr
forall peerconn.
PeerSelectionState PeerAddr peerconn -> LocalRootPeers PeerAddr
forall peeraddr peerconn.
PeerSelectionState peeraddr peerconn -> LocalRootPeers peeraddr
Governor.localRootPeers
(GovernorMockEnvironment -> ConsensusMode
consensusMode GovernorMockEnvironment
env)
Events TestTraceEvent
events
govInProgressDemoteToColdSig :: Signal (Set PeerAddr)
govInProgressDemoteToColdSig :: Signal (Set PeerAddr)
govInProgressDemoteToColdSig =
(forall peerconn.
PeerSelectionState PeerAddr peerconn -> Set PeerAddr)
-> ConsensusMode -> Events TestTraceEvent -> Signal (Set PeerAddr)
forall a.
Eq a =>
(forall peerconn. PeerSelectionState PeerAddr peerconn -> a)
-> ConsensusMode -> Events TestTraceEvent -> Signal a
selectGovState PeerSelectionState PeerAddr peerconn -> Set PeerAddr
forall peerconn.
PeerSelectionState PeerAddr peerconn -> Set PeerAddr
forall peeraddr peerconn.
PeerSelectionState peeraddr peerconn -> Set peeraddr
Governor.inProgressDemoteToCold
(GovernorMockEnvironment -> ConsensusMode
consensusMode GovernorMockEnvironment
env)
Events TestTraceEvent
events
govEstablishedPeersSig :: Signal (Set PeerAddr)
govEstablishedPeersSig :: Signal (Set PeerAddr)
govEstablishedPeersSig =
(forall peerconn.
PeerSelectionState PeerAddr peerconn -> Set PeerAddr)
-> ConsensusMode -> Events TestTraceEvent -> Signal (Set PeerAddr)
forall a.
Eq a =>
(forall peerconn. PeerSelectionState PeerAddr peerconn -> a)
-> ConsensusMode -> Events TestTraceEvent -> Signal a
selectGovState
((PeerSelectionState PeerAddr peerconn -> Set PeerAddr)
-> PeerSelectionState PeerAddr peerconn -> Set PeerAddr
forall peerconn.
(PeerSelectionState PeerAddr peerconn -> Set PeerAddr)
-> PeerSelectionState PeerAddr peerconn -> Set PeerAddr
dropBigLedgerPeers ((PeerSelectionState PeerAddr peerconn -> Set PeerAddr)
-> PeerSelectionState PeerAddr peerconn -> Set PeerAddr)
-> (PeerSelectionState PeerAddr peerconn -> Set PeerAddr)
-> PeerSelectionState PeerAddr peerconn
-> Set PeerAddr
forall a b. (a -> b) -> a -> b
$
EstablishedPeers PeerAddr peerconn -> Set PeerAddr
forall peeraddr peerconn.
EstablishedPeers peeraddr peerconn -> Set peeraddr
EstablishedPeers.toSet (EstablishedPeers PeerAddr peerconn -> Set PeerAddr)
-> (PeerSelectionState PeerAddr peerconn
-> EstablishedPeers PeerAddr peerconn)
-> PeerSelectionState PeerAddr peerconn
-> Set PeerAddr
forall b c a. (b -> c) -> (a -> b) -> a -> c
. PeerSelectionState PeerAddr peerconn
-> EstablishedPeers PeerAddr peerconn
forall peeraddr peerconn.
PeerSelectionState peeraddr peerconn
-> EstablishedPeers peeraddr peerconn
Governor.establishedPeers)
(GovernorMockEnvironment -> ConsensusMode
consensusMode GovernorMockEnvironment
env)
Events TestTraceEvent
events
govActivePeersSig :: Signal (Set PeerAddr)
govActivePeersSig :: Signal (Set PeerAddr)
govActivePeersSig =
(forall peerconn.
PeerSelectionState PeerAddr peerconn -> Set PeerAddr)
-> ConsensusMode -> Events TestTraceEvent -> Signal (Set PeerAddr)
forall a.
Eq a =>
(forall peerconn. PeerSelectionState PeerAddr peerconn -> a)
-> ConsensusMode -> Events TestTraceEvent -> Signal a
selectGovState ((PeerSelectionState PeerAddr peerconn -> Set PeerAddr)
-> PeerSelectionState PeerAddr peerconn -> Set PeerAddr
forall peerconn.
(PeerSelectionState PeerAddr peerconn -> Set PeerAddr)
-> PeerSelectionState PeerAddr peerconn -> Set PeerAddr
dropBigLedgerPeers PeerSelectionState PeerAddr peerconn -> Set PeerAddr
forall peeraddr peerconn.
PeerSelectionState peeraddr peerconn -> Set peeraddr
Governor.activePeers)
(GovernorMockEnvironment -> ConsensusMode
consensusMode GovernorMockEnvironment
env)
Events TestTraceEvent
events
govActiveFailuresSig :: Signal (Set PeerAddr)
govActiveFailuresSig :: Signal (Set PeerAddr)
govActiveFailuresSig =
DiffTime
-> (Maybe (Set PeerAddr) -> Set PeerAddr)
-> Signal (Maybe (Set PeerAddr))
-> Signal (Set PeerAddr)
forall a b.
Ord b =>
DiffTime -> (a -> Set b) -> Signal a -> Signal (Set b)
Signal.keyedLinger
DiffTime
180
(Set PeerAddr -> Maybe (Set PeerAddr) -> Set PeerAddr
forall a. a -> Maybe a -> a
fromMaybe Set PeerAddr
forall a. Set a
Set.empty)
(Signal (Maybe (Set PeerAddr)) -> Signal (Set PeerAddr))
-> (Events TestTraceEvent -> Signal (Maybe (Set PeerAddr)))
-> Events TestTraceEvent
-> Signal (Set PeerAddr)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Events (Set PeerAddr) -> Signal (Maybe (Set PeerAddr))
forall a. Events a -> Signal (Maybe a)
Signal.fromEvents
(Events (Set PeerAddr) -> Signal (Maybe (Set PeerAddr)))
-> (Events TestTraceEvent -> Events (Set PeerAddr))
-> Events TestTraceEvent
-> Signal (Maybe (Set PeerAddr))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (TracePeerSelection PeerAddr -> Maybe (Set PeerAddr))
-> Events (TracePeerSelection PeerAddr) -> Events (Set PeerAddr)
forall a b. (a -> Maybe b) -> Events a -> Events b
Signal.selectEvents
(\case TracePromoteWarmFailed Int
_ Int
_ PeerAddr
peer SomeException
_ ->
Set PeerAddr -> Maybe (Set PeerAddr)
forall a. a -> Maybe a
Just (Set PeerAddr -> Maybe (Set PeerAddr))
-> Set PeerAddr -> Maybe (Set PeerAddr)
forall a b. (a -> b) -> a -> b
$! PeerAddr -> Set PeerAddr
forall a. a -> Set a
Set.singleton PeerAddr
peer
TraceDemoteWarmFailed Int
_ Int
_ PeerAddr
peer SomeException
_ ->
Set PeerAddr -> Maybe (Set PeerAddr)
forall a. a -> Maybe a
Just (Set PeerAddr -> Maybe (Set PeerAddr))
-> Set PeerAddr -> Maybe (Set PeerAddr)
forall a b. (a -> b) -> a -> b
$! PeerAddr -> Set PeerAddr
forall a. a -> Set a
Set.singleton PeerAddr
peer
TraceDemoteHotFailed Int
_ Int
_ PeerAddr
peer SomeException
_ ->
Set PeerAddr -> Maybe (Set PeerAddr)
forall a. a -> Maybe a
Just (Set PeerAddr -> Maybe (Set PeerAddr))
-> Set PeerAddr -> Maybe (Set PeerAddr)
forall a b. (a -> b) -> a -> b
$! PeerAddr -> Set PeerAddr
forall a. a -> Set a
Set.singleton PeerAddr
peer
TraceDemoteAsynchronous Map PeerAddr (PeerStatus, Maybe RepromoteDelay)
status
| Set PeerAddr -> Bool
forall a. Set a -> Bool
Set.null Set PeerAddr
failures -> Maybe (Set PeerAddr)
forall a. Maybe a
Nothing
| Bool
otherwise -> Set PeerAddr -> Maybe (Set PeerAddr)
forall a. a -> Maybe a
Just Set PeerAddr
failures
where
!failures :: Set PeerAddr
failures = Map PeerAddr PeerStatus -> Set PeerAddr
forall k a. Map k a -> Set k
Map.keysSet ((PeerStatus -> Bool)
-> Map PeerAddr PeerStatus -> Map PeerAddr PeerStatus
forall a k. (a -> Bool) -> Map k a -> Map k a
Map.filter (PeerStatus -> PeerStatus -> Bool
forall a. Eq a => a -> a -> Bool
==PeerStatus
PeerWarm) (Map PeerAddr PeerStatus -> Map PeerAddr PeerStatus)
-> (Map PeerAddr (PeerStatus, Maybe RepromoteDelay)
-> Map PeerAddr PeerStatus)
-> Map PeerAddr (PeerStatus, Maybe RepromoteDelay)
-> Map PeerAddr PeerStatus
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ((PeerStatus, Maybe RepromoteDelay) -> PeerStatus)
-> Map PeerAddr (PeerStatus, Maybe RepromoteDelay)
-> Map PeerAddr PeerStatus
forall a b. (a -> b) -> Map PeerAddr a -> Map PeerAddr b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (PeerStatus, Maybe RepromoteDelay) -> PeerStatus
forall a b. (a, b) -> a
fst (Map PeerAddr (PeerStatus, Maybe RepromoteDelay)
-> Map PeerAddr PeerStatus)
-> Map PeerAddr (PeerStatus, Maybe RepromoteDelay)
-> Map PeerAddr PeerStatus
forall a b. (a -> b) -> a -> b
$ Map PeerAddr (PeerStatus, Maybe RepromoteDelay)
status)
TraceDemoteLocalAsynchronous Map PeerAddr (PeerStatus, Maybe RepromoteDelay)
status
| Set PeerAddr -> Bool
forall a. Set a -> Bool
Set.null Set PeerAddr
failures -> Maybe (Set PeerAddr)
forall a. Maybe a
Nothing
| Bool
otherwise -> Set PeerAddr -> Maybe (Set PeerAddr)
forall a. a -> Maybe a
Just Set PeerAddr
failures
where
!failures :: Set PeerAddr
failures = Map PeerAddr PeerStatus -> Set PeerAddr
forall k a. Map k a -> Set k
Map.keysSet ((PeerStatus -> Bool)
-> Map PeerAddr PeerStatus -> Map PeerAddr PeerStatus
forall a k. (a -> Bool) -> Map k a -> Map k a
Map.filter (PeerStatus -> PeerStatus -> Bool
forall a. Eq a => a -> a -> Bool
==PeerStatus
PeerWarm) (Map PeerAddr PeerStatus -> Map PeerAddr PeerStatus)
-> (Map PeerAddr (PeerStatus, Maybe RepromoteDelay)
-> Map PeerAddr PeerStatus)
-> Map PeerAddr (PeerStatus, Maybe RepromoteDelay)
-> Map PeerAddr PeerStatus
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ((PeerStatus, Maybe RepromoteDelay) -> PeerStatus)
-> Map PeerAddr (PeerStatus, Maybe RepromoteDelay)
-> Map PeerAddr PeerStatus
forall a b. (a -> b) -> Map PeerAddr a -> Map PeerAddr b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (PeerStatus, Maybe RepromoteDelay) -> PeerStatus
forall a b. (a, b) -> a
fst (Map PeerAddr (PeerStatus, Maybe RepromoteDelay)
-> Map PeerAddr PeerStatus)
-> Map PeerAddr (PeerStatus, Maybe RepromoteDelay)
-> Map PeerAddr PeerStatus
forall a b. (a -> b) -> a -> b
$ Map PeerAddr (PeerStatus, Maybe RepromoteDelay)
status)
TracePeerSelection PeerAddr
_ -> Maybe (Set PeerAddr)
forall a. Maybe a
Nothing
)
(Events (TracePeerSelection PeerAddr) -> Events (Set PeerAddr))
-> (Events TestTraceEvent -> Events (TracePeerSelection PeerAddr))
-> Events TestTraceEvent
-> Events (Set PeerAddr)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Events TestTraceEvent -> Events (TracePeerSelection PeerAddr)
selectGovEvents
(Events TestTraceEvent -> Signal (Set PeerAddr))
-> Events TestTraceEvent -> Signal (Set PeerAddr)
forall a b. (a -> b) -> a -> b
$ Events TestTraceEvent
events
promotionOpportunity :: Int
-> LocalRootPeers a -> Set a -> Set a -> Set a -> Set a -> Set a
promotionOpportunity Int
target LocalRootPeers a
local Set a
established Set a
active Set a
recentFailures Set a
inProgressDemoteToCold
| Set a -> Int
forall a. Set a -> Int
Set.size Set a
active Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
>= Int
target
= Set a
forall a. Set a
Set.empty
| Bool
otherwise
= Set a
established Set a -> Set a -> Set a
forall a. Ord a => Set a -> Set a -> Set a
Set.\\ Set a
active
Set a -> Set a -> Set a
forall a. Ord a => Set a -> Set a -> Set a
Set.\\ LocalRootPeers a -> Set a
forall peeraddr. LocalRootPeers peeraddr -> Set peeraddr
LocalRootPeers.keysSet LocalRootPeers a
local
Set a -> Set a -> Set a
forall a. Ord a => Set a -> Set a -> Set a
Set.\\ Set a
recentFailures
Set a -> Set a -> Set a
forall a. Ord a => Set a -> Set a -> Set a
Set.\\ Set a
inProgressDemoteToCold
promotionOpportunities :: Signal (Set PeerAddr)
promotionOpportunities :: Signal (Set PeerAddr)
promotionOpportunities =
Int
-> LocalRootPeers PeerAddr
-> Set PeerAddr
-> Set PeerAddr
-> Set PeerAddr
-> Set PeerAddr
-> Set PeerAddr
forall {a}.
Ord a =>
Int
-> LocalRootPeers a -> Set a -> Set a -> Set a -> Set a -> Set a
promotionOpportunity
(Int
-> LocalRootPeers PeerAddr
-> Set PeerAddr
-> Set PeerAddr
-> Set PeerAddr
-> Set PeerAddr
-> Set PeerAddr)
-> Signal Int
-> Signal
(LocalRootPeers PeerAddr
-> Set PeerAddr
-> Set PeerAddr
-> Set PeerAddr
-> Set PeerAddr
-> Set PeerAddr)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Signal Int
govTargetsSig
Signal
(LocalRootPeers PeerAddr
-> Set PeerAddr
-> Set PeerAddr
-> Set PeerAddr
-> Set PeerAddr
-> Set PeerAddr)
-> Signal (LocalRootPeers PeerAddr)
-> Signal
(Set PeerAddr
-> Set PeerAddr -> Set PeerAddr -> Set PeerAddr -> Set PeerAddr)
forall a b. Signal (a -> b) -> Signal a -> Signal b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Signal (LocalRootPeers PeerAddr)
govLocalRootPeersSig
Signal
(Set PeerAddr
-> Set PeerAddr -> Set PeerAddr -> Set PeerAddr -> Set PeerAddr)
-> Signal (Set PeerAddr)
-> Signal
(Set PeerAddr -> Set PeerAddr -> Set PeerAddr -> Set PeerAddr)
forall a b. Signal (a -> b) -> Signal a -> Signal b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Signal (Set PeerAddr)
govEstablishedPeersSig
Signal
(Set PeerAddr -> Set PeerAddr -> Set PeerAddr -> Set PeerAddr)
-> Signal (Set PeerAddr)
-> Signal (Set PeerAddr -> Set PeerAddr -> Set PeerAddr)
forall a b. Signal (a -> b) -> Signal a -> Signal b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Signal (Set PeerAddr)
govActivePeersSig
Signal (Set PeerAddr -> Set PeerAddr -> Set PeerAddr)
-> Signal (Set PeerAddr) -> Signal (Set PeerAddr -> Set PeerAddr)
forall a b. Signal (a -> b) -> Signal a -> Signal b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Signal (Set PeerAddr)
govActiveFailuresSig
Signal (Set PeerAddr -> Set PeerAddr)
-> Signal (Set PeerAddr) -> Signal (Set PeerAddr)
forall a b. Signal (a -> b) -> Signal a -> Signal b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Signal (Set PeerAddr)
govInProgressDemoteToColdSig
promotionOpportunitiesIgnoredTooLong :: Signal (Set PeerAddr)
promotionOpportunitiesIgnoredTooLong :: Signal (Set PeerAddr)
promotionOpportunitiesIgnoredTooLong =
DiffTime
-> (Set PeerAddr -> Set PeerAddr)
-> Signal (Set PeerAddr)
-> Signal (Set PeerAddr)
forall a b.
Ord b =>
DiffTime -> (a -> Set b) -> Signal a -> Signal (Set b)
Signal.keyedTimeout
DiffTime
15
Set PeerAddr -> Set PeerAddr
forall a. a -> a
id
Signal (Set PeerAddr)
promotionOpportunities
in TestName -> Property -> Property
forall prop. Testable prop => TestName -> prop -> Property
counterexample
(TestName
"\nSignal key: (target, local peers, established peers, " TestName -> TestName -> TestName
forall a. [a] -> [a] -> [a]
++
TestName
"active peers, recent failures, opportunities, ignored too long)") (Property -> Property) -> Property -> Property
forall a b. (a -> b) -> a -> b
$
Int
-> ((Int, LocalRootPeers PeerAddr, Set PeerAddr, Set PeerAddr,
Set PeerAddr, Set PeerAddr, Set PeerAddr)
-> TestName)
-> ((Int, LocalRootPeers PeerAddr, Set PeerAddr, Set PeerAddr,
Set PeerAddr, Set PeerAddr, Set PeerAddr)
-> Bool)
-> Signal
(Int, LocalRootPeers PeerAddr, Set PeerAddr, Set PeerAddr,
Set PeerAddr, Set PeerAddr, Set PeerAddr)
-> Property
forall a.
Int -> (a -> TestName) -> (a -> Bool) -> Signal a -> Property
signalProperty Int
20 (Int, LocalRootPeers PeerAddr, Set PeerAddr, Set PeerAddr,
Set PeerAddr, Set PeerAddr, Set PeerAddr)
-> TestName
forall a. Show a => a -> TestName
show
(\(Int
_,LocalRootPeers PeerAddr
_,Set PeerAddr
_,Set PeerAddr
_,Set PeerAddr
_,Set PeerAddr
_,Set PeerAddr
toolong) -> Set PeerAddr -> Bool
forall a. Set a -> Bool
Set.null Set PeerAddr
toolong)
((,,,,,,) (Int
-> LocalRootPeers PeerAddr
-> Set PeerAddr
-> Set PeerAddr
-> Set PeerAddr
-> Set PeerAddr
-> Set PeerAddr
-> (Int, LocalRootPeers PeerAddr, Set PeerAddr, Set PeerAddr,
Set PeerAddr, Set PeerAddr, Set PeerAddr))
-> Signal Int
-> Signal
(LocalRootPeers PeerAddr
-> Set PeerAddr
-> Set PeerAddr
-> Set PeerAddr
-> Set PeerAddr
-> Set PeerAddr
-> (Int, LocalRootPeers PeerAddr, Set PeerAddr, Set PeerAddr,
Set PeerAddr, Set PeerAddr, Set PeerAddr))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Signal Int
govTargetsSig
Signal
(LocalRootPeers PeerAddr
-> Set PeerAddr
-> Set PeerAddr
-> Set PeerAddr
-> Set PeerAddr
-> Set PeerAddr
-> (Int, LocalRootPeers PeerAddr, Set PeerAddr, Set PeerAddr,
Set PeerAddr, Set PeerAddr, Set PeerAddr))
-> Signal (LocalRootPeers PeerAddr)
-> Signal
(Set PeerAddr
-> Set PeerAddr
-> Set PeerAddr
-> Set PeerAddr
-> Set PeerAddr
-> (Int, LocalRootPeers PeerAddr, Set PeerAddr, Set PeerAddr,
Set PeerAddr, Set PeerAddr, Set PeerAddr))
forall a b. Signal (a -> b) -> Signal a -> Signal b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Signal (LocalRootPeers PeerAddr)
govLocalRootPeersSig
Signal
(Set PeerAddr
-> Set PeerAddr
-> Set PeerAddr
-> Set PeerAddr
-> Set PeerAddr
-> (Int, LocalRootPeers PeerAddr, Set PeerAddr, Set PeerAddr,
Set PeerAddr, Set PeerAddr, Set PeerAddr))
-> Signal (Set PeerAddr)
-> Signal
(Set PeerAddr
-> Set PeerAddr
-> Set PeerAddr
-> Set PeerAddr
-> (Int, LocalRootPeers PeerAddr, Set PeerAddr, Set PeerAddr,
Set PeerAddr, Set PeerAddr, Set PeerAddr))
forall a b. Signal (a -> b) -> Signal a -> Signal b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Signal (Set PeerAddr)
govEstablishedPeersSig
Signal
(Set PeerAddr
-> Set PeerAddr
-> Set PeerAddr
-> Set PeerAddr
-> (Int, LocalRootPeers PeerAddr, Set PeerAddr, Set PeerAddr,
Set PeerAddr, Set PeerAddr, Set PeerAddr))
-> Signal (Set PeerAddr)
-> Signal
(Set PeerAddr
-> Set PeerAddr
-> Set PeerAddr
-> (Int, LocalRootPeers PeerAddr, Set PeerAddr, Set PeerAddr,
Set PeerAddr, Set PeerAddr, Set PeerAddr))
forall a b. Signal (a -> b) -> Signal a -> Signal b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Signal (Set PeerAddr)
govActivePeersSig
Signal
(Set PeerAddr
-> Set PeerAddr
-> Set PeerAddr
-> (Int, LocalRootPeers PeerAddr, Set PeerAddr, Set PeerAddr,
Set PeerAddr, Set PeerAddr, Set PeerAddr))
-> Signal (Set PeerAddr)
-> Signal
(Set PeerAddr
-> Set PeerAddr
-> (Int, LocalRootPeers PeerAddr, Set PeerAddr, Set PeerAddr,
Set PeerAddr, Set PeerAddr, Set PeerAddr))
forall a b. Signal (a -> b) -> Signal a -> Signal b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Signal (Set PeerAddr)
govActiveFailuresSig
Signal
(Set PeerAddr
-> Set PeerAddr
-> (Int, LocalRootPeers PeerAddr, Set PeerAddr, Set PeerAddr,
Set PeerAddr, Set PeerAddr, Set PeerAddr))
-> Signal (Set PeerAddr)
-> Signal
(Set PeerAddr
-> (Int, LocalRootPeers PeerAddr, Set PeerAddr, Set PeerAddr,
Set PeerAddr, Set PeerAddr, Set PeerAddr))
forall a b. Signal (a -> b) -> Signal a -> Signal b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Signal (Set PeerAddr)
promotionOpportunities
Signal
(Set PeerAddr
-> (Int, LocalRootPeers PeerAddr, Set PeerAddr, Set PeerAddr,
Set PeerAddr, Set PeerAddr, Set PeerAddr))
-> Signal (Set PeerAddr)
-> Signal
(Int, LocalRootPeers PeerAddr, Set PeerAddr, Set PeerAddr,
Set PeerAddr, Set PeerAddr, Set PeerAddr)
forall a b. Signal (a -> b) -> Signal a -> Signal b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Signal (Set PeerAddr)
promotionOpportunitiesIgnoredTooLong)
prop_governor_target_active_big_ledger_peers_below
:: MaxTime -> GovernorMockEnvironment -> Property
prop_governor_target_active_big_ledger_peers_below :: MaxTime -> GovernorMockEnvironment -> Property
prop_governor_target_active_big_ledger_peers_below (MaxTime Time
maxTime) GovernorMockEnvironment
env =
let events :: Events TestTraceEvent
events = Time -> [(Time, TestTraceEvent)] -> Events TestTraceEvent
forall a. Time -> [(Time, a)] -> Events a
Signal.eventsFromListUpToTime Time
maxTime
([(Time, TestTraceEvent)] -> Events TestTraceEvent)
-> (GovernorMockEnvironment -> [(Time, TestTraceEvent)])
-> GovernorMockEnvironment
-> Events TestTraceEvent
forall b c a. (b -> c) -> (a -> b) -> a -> c
. SimTrace Void -> [(Time, TestTraceEvent)]
forall a. SimTrace a -> [(Time, TestTraceEvent)]
selectPeerSelectionTraceEvents
(SimTrace Void -> [(Time, TestTraceEvent)])
-> (GovernorMockEnvironment -> SimTrace Void)
-> GovernorMockEnvironment
-> [(Time, TestTraceEvent)]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. GovernorMockEnvironment -> SimTrace Void
runGovernorInMockEnvironment
(GovernorMockEnvironment -> Events TestTraceEvent)
-> GovernorMockEnvironment -> Events TestTraceEvent
forall a b. (a -> b) -> a -> b
$ GovernorMockEnvironment
env
govTargetsSig :: Signal Int
govTargetsSig :: Signal Int
govTargetsSig =
(forall peerconn. PeerSelectionState PeerAddr peerconn -> Int)
-> ConsensusMode -> Events TestTraceEvent -> Signal Int
forall a.
Eq a =>
(forall peerconn. PeerSelectionState PeerAddr peerconn -> a)
-> ConsensusMode -> Events TestTraceEvent -> Signal a
selectGovState (PeerSelectionTargets -> Int
targetNumberOfActiveBigLedgerPeers (PeerSelectionTargets -> Int)
-> (PeerSelectionState PeerAddr peerconn -> PeerSelectionTargets)
-> PeerSelectionState PeerAddr peerconn
-> Int
forall b c a. (b -> c) -> (a -> b) -> a -> c
. PeerSelectionState PeerAddr peerconn -> PeerSelectionTargets
forall peeraddr peerconn.
PeerSelectionState peeraddr peerconn -> PeerSelectionTargets
Governor.targets)
(GovernorMockEnvironment -> ConsensusMode
consensusMode GovernorMockEnvironment
env)
Events TestTraceEvent
events
govEstablishedPeersSig :: Signal (Set PeerAddr)
govEstablishedPeersSig :: Signal (Set PeerAddr)
govEstablishedPeersSig =
(forall peerconn.
PeerSelectionState PeerAddr peerconn -> Set PeerAddr)
-> ConsensusMode -> Events TestTraceEvent -> Signal (Set PeerAddr)
forall a.
Eq a =>
(forall peerconn. PeerSelectionState PeerAddr peerconn -> a)
-> ConsensusMode -> Events TestTraceEvent -> Signal a
selectGovState
((PeerSelectionState PeerAddr peerconn -> Set PeerAddr)
-> PeerSelectionState PeerAddr peerconn -> Set PeerAddr
forall peerconn.
(PeerSelectionState PeerAddr peerconn -> Set PeerAddr)
-> PeerSelectionState PeerAddr peerconn -> Set PeerAddr
takeBigLedgerPeers ((PeerSelectionState PeerAddr peerconn -> Set PeerAddr)
-> PeerSelectionState PeerAddr peerconn -> Set PeerAddr)
-> (PeerSelectionState PeerAddr peerconn -> Set PeerAddr)
-> PeerSelectionState PeerAddr peerconn
-> Set PeerAddr
forall a b. (a -> b) -> a -> b
$
EstablishedPeers PeerAddr peerconn -> Set PeerAddr
forall peeraddr peerconn.
EstablishedPeers peeraddr peerconn -> Set peeraddr
EstablishedPeers.toSet (EstablishedPeers PeerAddr peerconn -> Set PeerAddr)
-> (PeerSelectionState PeerAddr peerconn
-> EstablishedPeers PeerAddr peerconn)
-> PeerSelectionState PeerAddr peerconn
-> Set PeerAddr
forall b c a. (b -> c) -> (a -> b) -> a -> c
. PeerSelectionState PeerAddr peerconn
-> EstablishedPeers PeerAddr peerconn
forall peeraddr peerconn.
PeerSelectionState peeraddr peerconn
-> EstablishedPeers peeraddr peerconn
Governor.establishedPeers)
(GovernorMockEnvironment -> ConsensusMode
consensusMode GovernorMockEnvironment
env)
Events TestTraceEvent
events
govInProgressDemoteToColdSig :: Signal (Set PeerAddr)
govInProgressDemoteToColdSig :: Signal (Set PeerAddr)
govInProgressDemoteToColdSig =
(forall peerconn.
PeerSelectionState PeerAddr peerconn -> Set PeerAddr)
-> ConsensusMode -> Events TestTraceEvent -> Signal (Set PeerAddr)
forall a.
Eq a =>
(forall peerconn. PeerSelectionState PeerAddr peerconn -> a)
-> ConsensusMode -> Events TestTraceEvent -> Signal a
selectGovState PeerSelectionState PeerAddr peerconn -> Set PeerAddr
forall peerconn.
PeerSelectionState PeerAddr peerconn -> Set PeerAddr
forall peeraddr peerconn.
PeerSelectionState peeraddr peerconn -> Set peeraddr
Governor.inProgressDemoteToCold (GovernorMockEnvironment -> ConsensusMode
consensusMode GovernorMockEnvironment
env) Events TestTraceEvent
events
govActivePeersSig :: Signal (Set PeerAddr)
govActivePeersSig :: Signal (Set PeerAddr)
govActivePeersSig =
(forall peerconn.
PeerSelectionState PeerAddr peerconn -> Set PeerAddr)
-> ConsensusMode -> Events TestTraceEvent -> Signal (Set PeerAddr)
forall a.
Eq a =>
(forall peerconn. PeerSelectionState PeerAddr peerconn -> a)
-> ConsensusMode -> Events TestTraceEvent -> Signal a
selectGovState ((PeerSelectionState PeerAddr peerconn -> Set PeerAddr)
-> PeerSelectionState PeerAddr peerconn -> Set PeerAddr
forall peerconn.
(PeerSelectionState PeerAddr peerconn -> Set PeerAddr)
-> PeerSelectionState PeerAddr peerconn -> Set PeerAddr
takeBigLedgerPeers PeerSelectionState PeerAddr peerconn -> Set PeerAddr
forall peeraddr peerconn.
PeerSelectionState peeraddr peerconn -> Set peeraddr
Governor.activePeers)
(GovernorMockEnvironment -> ConsensusMode
consensusMode GovernorMockEnvironment
env)
Events TestTraceEvent
events
govActiveFailuresSig :: Signal (Set PeerAddr)
govActiveFailuresSig :: Signal (Set PeerAddr)
govActiveFailuresSig =
DiffTime
-> (Maybe (Set PeerAddr) -> Set PeerAddr)
-> Signal (Maybe (Set PeerAddr))
-> Signal (Set PeerAddr)
forall a b.
Ord b =>
DiffTime -> (a -> Set b) -> Signal a -> Signal (Set b)
Signal.keyedLinger
DiffTime
180
(Set PeerAddr -> Maybe (Set PeerAddr) -> Set PeerAddr
forall a. a -> Maybe a -> a
fromMaybe Set PeerAddr
forall a. Set a
Set.empty)
(Signal (Maybe (Set PeerAddr)) -> Signal (Set PeerAddr))
-> (Events TestTraceEvent -> Signal (Maybe (Set PeerAddr)))
-> Events TestTraceEvent
-> Signal (Set PeerAddr)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Events (Set PeerAddr) -> Signal (Maybe (Set PeerAddr))
forall a. Events a -> Signal (Maybe a)
Signal.fromEvents
(Events (Set PeerAddr) -> Signal (Maybe (Set PeerAddr)))
-> (Events TestTraceEvent -> Events (Set PeerAddr))
-> Events TestTraceEvent
-> Signal (Maybe (Set PeerAddr))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (TracePeerSelection PeerAddr -> Maybe (Set PeerAddr))
-> Events (TracePeerSelection PeerAddr) -> Events (Set PeerAddr)
forall a b. (a -> Maybe b) -> Events a -> Events b
Signal.selectEvents
(\case TracePromoteWarmFailed Int
_ Int
_ PeerAddr
peer SomeException
_ ->
Set PeerAddr -> Maybe (Set PeerAddr)
forall a. a -> Maybe a
Just (PeerAddr -> Set PeerAddr
forall a. a -> Set a
Set.singleton PeerAddr
peer)
TraceDemoteBigLedgerPeersAsynchronous Map PeerAddr (PeerStatus, Maybe RepromoteDelay)
status
| Set PeerAddr -> Bool
forall a. Set a -> Bool
Set.null Set PeerAddr
failures -> Maybe (Set PeerAddr)
forall a. Maybe a
Nothing
| Bool
otherwise -> Set PeerAddr -> Maybe (Set PeerAddr)
forall a. a -> Maybe a
Just Set PeerAddr
failures
where
failures :: Set PeerAddr
failures = Map PeerAddr PeerStatus -> Set PeerAddr
forall k a. Map k a -> Set k
Map.keysSet ((PeerStatus -> Bool)
-> Map PeerAddr PeerStatus -> Map PeerAddr PeerStatus
forall a k. (a -> Bool) -> Map k a -> Map k a
Map.filter (PeerStatus -> PeerStatus -> Bool
forall a. Eq a => a -> a -> Bool
==PeerStatus
PeerWarm) (Map PeerAddr PeerStatus -> Map PeerAddr PeerStatus)
-> (Map PeerAddr (PeerStatus, Maybe RepromoteDelay)
-> Map PeerAddr PeerStatus)
-> Map PeerAddr (PeerStatus, Maybe RepromoteDelay)
-> Map PeerAddr PeerStatus
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ((PeerStatus, Maybe RepromoteDelay) -> PeerStatus)
-> Map PeerAddr (PeerStatus, Maybe RepromoteDelay)
-> Map PeerAddr PeerStatus
forall a b. (a -> b) -> Map PeerAddr a -> Map PeerAddr b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (PeerStatus, Maybe RepromoteDelay) -> PeerStatus
forall a b. (a, b) -> a
fst (Map PeerAddr (PeerStatus, Maybe RepromoteDelay)
-> Map PeerAddr PeerStatus)
-> Map PeerAddr (PeerStatus, Maybe RepromoteDelay)
-> Map PeerAddr PeerStatus
forall a b. (a -> b) -> a -> b
$ Map PeerAddr (PeerStatus, Maybe RepromoteDelay)
status)
TracePeerSelection PeerAddr
_ -> Maybe (Set PeerAddr)
forall a. Maybe a
Nothing
)
(Events (TracePeerSelection PeerAddr) -> Events (Set PeerAddr))
-> (Events TestTraceEvent -> Events (TracePeerSelection PeerAddr))
-> Events TestTraceEvent
-> Events (Set PeerAddr)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Events TestTraceEvent -> Events (TracePeerSelection PeerAddr)
selectGovEvents
(Events TestTraceEvent -> Signal (Set PeerAddr))
-> Events TestTraceEvent -> Signal (Set PeerAddr)
forall a b. (a -> b) -> a -> b
$ Events TestTraceEvent
events
promotionOpportunity :: Int -> Set a -> Set a -> Set a -> Set a -> Set a
promotionOpportunity Int
target Set a
established Set a
active Set a
recentFailures Set a
inProgressDemoteToCold
| Set a -> Int
forall a. Set a -> Int
Set.size Set a
active Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
>= Int
target
= Set a
forall a. Set a
Set.empty
| Bool
otherwise
= Set a
established Set a -> Set a -> Set a
forall a. Ord a => Set a -> Set a -> Set a
Set.\\ Set a
active
Set a -> Set a -> Set a
forall a. Ord a => Set a -> Set a -> Set a
Set.\\ Set a
recentFailures
Set a -> Set a -> Set a
forall a. Ord a => Set a -> Set a -> Set a
Set.\\ Set a
inProgressDemoteToCold
promotionOpportunities :: Signal (Set PeerAddr)
promotionOpportunities :: Signal (Set PeerAddr)
promotionOpportunities =
Int
-> Set PeerAddr
-> Set PeerAddr
-> Set PeerAddr
-> Set PeerAddr
-> Set PeerAddr
forall {a}.
Ord a =>
Int -> Set a -> Set a -> Set a -> Set a -> Set a
promotionOpportunity
(Int
-> Set PeerAddr
-> Set PeerAddr
-> Set PeerAddr
-> Set PeerAddr
-> Set PeerAddr)
-> Signal Int
-> Signal
(Set PeerAddr
-> Set PeerAddr -> Set PeerAddr -> Set PeerAddr -> Set PeerAddr)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Signal Int
govTargetsSig
Signal
(Set PeerAddr
-> Set PeerAddr -> Set PeerAddr -> Set PeerAddr -> Set PeerAddr)
-> Signal (Set PeerAddr)
-> Signal
(Set PeerAddr -> Set PeerAddr -> Set PeerAddr -> Set PeerAddr)
forall a b. Signal (a -> b) -> Signal a -> Signal b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Signal (Set PeerAddr)
govEstablishedPeersSig
Signal
(Set PeerAddr -> Set PeerAddr -> Set PeerAddr -> Set PeerAddr)
-> Signal (Set PeerAddr)
-> Signal (Set PeerAddr -> Set PeerAddr -> Set PeerAddr)
forall a b. Signal (a -> b) -> Signal a -> Signal b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Signal (Set PeerAddr)
govActivePeersSig
Signal (Set PeerAddr -> Set PeerAddr -> Set PeerAddr)
-> Signal (Set PeerAddr) -> Signal (Set PeerAddr -> Set PeerAddr)
forall a b. Signal (a -> b) -> Signal a -> Signal b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Signal (Set PeerAddr)
govActiveFailuresSig
Signal (Set PeerAddr -> Set PeerAddr)
-> Signal (Set PeerAddr) -> Signal (Set PeerAddr)
forall a b. Signal (a -> b) -> Signal a -> Signal b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Signal (Set PeerAddr)
govInProgressDemoteToColdSig
promotionOpportunitiesIgnoredTooLong :: Signal (Set PeerAddr)
promotionOpportunitiesIgnoredTooLong :: Signal (Set PeerAddr)
promotionOpportunitiesIgnoredTooLong =
DiffTime
-> (Set PeerAddr -> Set PeerAddr)
-> Signal (Set PeerAddr)
-> Signal (Set PeerAddr)
forall a b.
Ord b =>
DiffTime -> (a -> Set b) -> Signal a -> Signal (Set b)
Signal.keyedTimeout
(RepromoteDelay -> DiffTime
repromoteDelay RepromoteDelay
config_REPROMOTE_DELAY DiffTime -> DiffTime -> DiffTime
forall a. Num a => a -> a -> a
+ DiffTime
20)
Set PeerAddr -> Set PeerAddr
forall a. a -> a
id
Signal (Set PeerAddr)
promotionOpportunities
in TestName -> Property -> Property
forall prop. Testable prop => TestName -> prop -> Property
counterexample
(TestName
"\nSignal key: (target, established big ledger peers, " TestName -> TestName -> TestName
forall a. [a] -> [a] -> [a]
++
TestName
"active peers, recent failures, opportunities, ignored too long)") (Property -> Property) -> Property -> Property
forall a b. (a -> b) -> a -> b
$
Int
-> ((Int, Set PeerAddr, Set PeerAddr, Set PeerAddr, Set PeerAddr,
Set PeerAddr)
-> TestName)
-> ((Int, Set PeerAddr, Set PeerAddr, Set PeerAddr, Set PeerAddr,
Set PeerAddr)
-> Bool)
-> Signal
(Int, Set PeerAddr, Set PeerAddr, Set PeerAddr, Set PeerAddr,
Set PeerAddr)
-> Property
forall a.
Int -> (a -> TestName) -> (a -> Bool) -> Signal a -> Property
signalProperty Int
20 (Int, Set PeerAddr, Set PeerAddr, Set PeerAddr, Set PeerAddr,
Set PeerAddr)
-> TestName
forall a. Show a => a -> TestName
show
(\(Int
_,Set PeerAddr
_,Set PeerAddr
_,Set PeerAddr
_,Set PeerAddr
_,Set PeerAddr
toolong) -> Set PeerAddr -> Bool
forall a. Set a -> Bool
Set.null Set PeerAddr
toolong)
((,,,,,) (Int
-> Set PeerAddr
-> Set PeerAddr
-> Set PeerAddr
-> Set PeerAddr
-> Set PeerAddr
-> (Int, Set PeerAddr, Set PeerAddr, Set PeerAddr, Set PeerAddr,
Set PeerAddr))
-> Signal Int
-> Signal
(Set PeerAddr
-> Set PeerAddr
-> Set PeerAddr
-> Set PeerAddr
-> Set PeerAddr
-> (Int, Set PeerAddr, Set PeerAddr, Set PeerAddr, Set PeerAddr,
Set PeerAddr))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Signal Int
govTargetsSig
Signal
(Set PeerAddr
-> Set PeerAddr
-> Set PeerAddr
-> Set PeerAddr
-> Set PeerAddr
-> (Int, Set PeerAddr, Set PeerAddr, Set PeerAddr, Set PeerAddr,
Set PeerAddr))
-> Signal (Set PeerAddr)
-> Signal
(Set PeerAddr
-> Set PeerAddr
-> Set PeerAddr
-> Set PeerAddr
-> (Int, Set PeerAddr, Set PeerAddr, Set PeerAddr, Set PeerAddr,
Set PeerAddr))
forall a b. Signal (a -> b) -> Signal a -> Signal b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Signal (Set PeerAddr)
govEstablishedPeersSig
Signal
(Set PeerAddr
-> Set PeerAddr
-> Set PeerAddr
-> Set PeerAddr
-> (Int, Set PeerAddr, Set PeerAddr, Set PeerAddr, Set PeerAddr,
Set PeerAddr))
-> Signal (Set PeerAddr)
-> Signal
(Set PeerAddr
-> Set PeerAddr
-> Set PeerAddr
-> (Int, Set PeerAddr, Set PeerAddr, Set PeerAddr, Set PeerAddr,
Set PeerAddr))
forall a b. Signal (a -> b) -> Signal a -> Signal b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Signal (Set PeerAddr)
govActivePeersSig
Signal
(Set PeerAddr
-> Set PeerAddr
-> Set PeerAddr
-> (Int, Set PeerAddr, Set PeerAddr, Set PeerAddr, Set PeerAddr,
Set PeerAddr))
-> Signal (Set PeerAddr)
-> Signal
(Set PeerAddr
-> Set PeerAddr
-> (Int, Set PeerAddr, Set PeerAddr, Set PeerAddr, Set PeerAddr,
Set PeerAddr))
forall a b. Signal (a -> b) -> Signal a -> Signal b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Signal (Set PeerAddr)
govActiveFailuresSig
Signal
(Set PeerAddr
-> Set PeerAddr
-> (Int, Set PeerAddr, Set PeerAddr, Set PeerAddr, Set PeerAddr,
Set PeerAddr))
-> Signal (Set PeerAddr)
-> Signal
(Set PeerAddr
-> (Int, Set PeerAddr, Set PeerAddr, Set PeerAddr, Set PeerAddr,
Set PeerAddr))
forall a b. Signal (a -> b) -> Signal a -> Signal b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Signal (Set PeerAddr)
promotionOpportunities
Signal
(Set PeerAddr
-> (Int, Set PeerAddr, Set PeerAddr, Set PeerAddr, Set PeerAddr,
Set PeerAddr))
-> Signal (Set PeerAddr)
-> Signal
(Int, Set PeerAddr, Set PeerAddr, Set PeerAddr, Set PeerAddr,
Set PeerAddr)
forall a b. Signal (a -> b) -> Signal a -> Signal b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Signal (Set PeerAddr)
promotionOpportunitiesIgnoredTooLong)
prop_governor_target_established_above :: MaxTime -> GovernorMockEnvironment -> Property
prop_governor_target_established_above :: MaxTime -> GovernorMockEnvironment -> Property
prop_governor_target_established_above (MaxTime Time
maxTime) GovernorMockEnvironment
env =
let events :: Events TestTraceEvent
events = Time -> [(Time, TestTraceEvent)] -> Events TestTraceEvent
forall a. Time -> [(Time, a)] -> Events a
Signal.eventsFromListUpToTime Time
maxTime
([(Time, TestTraceEvent)] -> Events TestTraceEvent)
-> (GovernorMockEnvironment -> [(Time, TestTraceEvent)])
-> GovernorMockEnvironment
-> Events TestTraceEvent
forall b c a. (b -> c) -> (a -> b) -> a -> c
. SimTrace Void -> [(Time, TestTraceEvent)]
forall a. SimTrace a -> [(Time, TestTraceEvent)]
selectPeerSelectionTraceEvents
(SimTrace Void -> [(Time, TestTraceEvent)])
-> (GovernorMockEnvironment -> SimTrace Void)
-> GovernorMockEnvironment
-> [(Time, TestTraceEvent)]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. GovernorMockEnvironment -> SimTrace Void
runGovernorInMockEnvironment
(GovernorMockEnvironment -> Events TestTraceEvent)
-> GovernorMockEnvironment -> Events TestTraceEvent
forall a b. (a -> b) -> a -> b
$ GovernorMockEnvironment
env
govTargetsSig :: Signal Int
govTargetsSig :: Signal Int
govTargetsSig =
(forall peerconn. PeerSelectionState PeerAddr peerconn -> Int)
-> ConsensusMode -> Events TestTraceEvent -> Signal Int
forall a.
Eq a =>
(forall peerconn. PeerSelectionState PeerAddr peerconn -> a)
-> ConsensusMode -> Events TestTraceEvent -> Signal a
selectGovState (PeerSelectionTargets -> Int
targetNumberOfEstablishedPeers (PeerSelectionTargets -> Int)
-> (PeerSelectionState PeerAddr peerconn -> PeerSelectionTargets)
-> PeerSelectionState PeerAddr peerconn
-> Int
forall b c a. (b -> c) -> (a -> b) -> a -> c
. PeerSelectionState PeerAddr peerconn -> PeerSelectionTargets
forall peeraddr peerconn.
PeerSelectionState peeraddr peerconn -> PeerSelectionTargets
Governor.targets)
(GovernorMockEnvironment -> ConsensusMode
consensusMode GovernorMockEnvironment
env)
Events TestTraceEvent
events
govInProgressDemoteToColdSig :: Signal (Set PeerAddr)
govInProgressDemoteToColdSig :: Signal (Set PeerAddr)
govInProgressDemoteToColdSig =
(forall peerconn.
PeerSelectionState PeerAddr peerconn -> Set PeerAddr)
-> ConsensusMode -> Events TestTraceEvent -> Signal (Set PeerAddr)
forall a.
Eq a =>
(forall peerconn. PeerSelectionState PeerAddr peerconn -> a)
-> ConsensusMode -> Events TestTraceEvent -> Signal a
selectGovState PeerSelectionState PeerAddr peerconn -> Set PeerAddr
forall peerconn.
PeerSelectionState PeerAddr peerconn -> Set PeerAddr
forall peeraddr peerconn.
PeerSelectionState peeraddr peerconn -> Set peeraddr
Governor.inProgressDemoteToCold
(GovernorMockEnvironment -> ConsensusMode
consensusMode GovernorMockEnvironment
env)
Events TestTraceEvent
events
govLocalRootPeersSig :: Signal (LocalRootPeers.LocalRootPeers PeerAddr)
govLocalRootPeersSig :: Signal (LocalRootPeers PeerAddr)
govLocalRootPeersSig =
(forall peerconn.
PeerSelectionState PeerAddr peerconn -> LocalRootPeers PeerAddr)
-> ConsensusMode
-> Events TestTraceEvent
-> Signal (LocalRootPeers PeerAddr)
forall a.
Eq a =>
(forall peerconn. PeerSelectionState PeerAddr peerconn -> a)
-> ConsensusMode -> Events TestTraceEvent -> Signal a
selectGovState PeerSelectionState PeerAddr peerconn -> LocalRootPeers PeerAddr
forall peerconn.
PeerSelectionState PeerAddr peerconn -> LocalRootPeers PeerAddr
forall peeraddr peerconn.
PeerSelectionState peeraddr peerconn -> LocalRootPeers peeraddr
Governor.localRootPeers
(GovernorMockEnvironment -> ConsensusMode
consensusMode GovernorMockEnvironment
env)
Events TestTraceEvent
events
govEstablishedPeersSig :: Signal (Set PeerAddr)
govEstablishedPeersSig :: Signal (Set PeerAddr)
govEstablishedPeersSig =
(forall peerconn.
PeerSelectionState PeerAddr peerconn -> Set PeerAddr)
-> ConsensusMode -> Events TestTraceEvent -> Signal (Set PeerAddr)
forall a.
Eq a =>
(forall peerconn. PeerSelectionState PeerAddr peerconn -> a)
-> ConsensusMode -> Events TestTraceEvent -> Signal a
selectGovState
((PeerSelectionState PeerAddr peerconn -> Set PeerAddr)
-> PeerSelectionState PeerAddr peerconn -> Set PeerAddr
forall peerconn.
(PeerSelectionState PeerAddr peerconn -> Set PeerAddr)
-> PeerSelectionState PeerAddr peerconn -> Set PeerAddr
dropBigLedgerPeers ((PeerSelectionState PeerAddr peerconn -> Set PeerAddr)
-> PeerSelectionState PeerAddr peerconn -> Set PeerAddr)
-> (PeerSelectionState PeerAddr peerconn -> Set PeerAddr)
-> PeerSelectionState PeerAddr peerconn
-> Set PeerAddr
forall a b. (a -> b) -> a -> b
$
EstablishedPeers PeerAddr peerconn -> Set PeerAddr
forall peeraddr peerconn.
EstablishedPeers peeraddr peerconn -> Set peeraddr
EstablishedPeers.toSet (EstablishedPeers PeerAddr peerconn -> Set PeerAddr)
-> (PeerSelectionState PeerAddr peerconn
-> EstablishedPeers PeerAddr peerconn)
-> PeerSelectionState PeerAddr peerconn
-> Set PeerAddr
forall b c a. (b -> c) -> (a -> b) -> a -> c
. PeerSelectionState PeerAddr peerconn
-> EstablishedPeers PeerAddr peerconn
forall peeraddr peerconn.
PeerSelectionState peeraddr peerconn
-> EstablishedPeers peeraddr peerconn
Governor.establishedPeers)
(GovernorMockEnvironment -> ConsensusMode
consensusMode GovernorMockEnvironment
env)
Events TestTraceEvent
events
govActivePeersSig :: Signal (Set PeerAddr)
govActivePeersSig :: Signal (Set PeerAddr)
govActivePeersSig =
(forall peerconn.
PeerSelectionState PeerAddr peerconn -> Set PeerAddr)
-> ConsensusMode -> Events TestTraceEvent -> Signal (Set PeerAddr)
forall a.
Eq a =>
(forall peerconn. PeerSelectionState PeerAddr peerconn -> a)
-> ConsensusMode -> Events TestTraceEvent -> Signal a
selectGovState ((PeerSelectionState PeerAddr peerconn -> Set PeerAddr)
-> PeerSelectionState PeerAddr peerconn -> Set PeerAddr
forall peerconn.
(PeerSelectionState PeerAddr peerconn -> Set PeerAddr)
-> PeerSelectionState PeerAddr peerconn -> Set PeerAddr
dropBigLedgerPeers PeerSelectionState PeerAddr peerconn -> Set PeerAddr
forall peeraddr peerconn.
PeerSelectionState peeraddr peerconn -> Set peeraddr
Governor.activePeers)
(GovernorMockEnvironment -> ConsensusMode
consensusMode GovernorMockEnvironment
env)
Events TestTraceEvent
events
demotionOpportunity :: Int -> LocalRootPeers a -> Set a -> Set a -> Set a -> Set a
demotionOpportunity Int
target LocalRootPeers a
local Set a
established Set a
active Set a
inProgressDemoteToCold
| Set a -> Int
forall a. Set a -> Int
Set.size Set a
established Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
<= Int
target
= Set a
forall a. Set a
Set.empty
| Bool
otherwise
= Set a
established Set a -> Set a -> Set a
forall a. Ord a => Set a -> Set a -> Set a
Set.\\ Set a
active
Set a -> Set a -> Set a
forall a. Ord a => Set a -> Set a -> Set a
Set.\\ LocalRootPeers a -> Set a
forall peeraddr. LocalRootPeers peeraddr -> Set peeraddr
LocalRootPeers.keysSet LocalRootPeers a
local
Set a -> Set a -> Set a
forall a. Ord a => Set a -> Set a -> Set a
Set.\\ Set a
inProgressDemoteToCold
demotionOpportunities :: Signal (Set PeerAddr)
demotionOpportunities :: Signal (Set PeerAddr)
demotionOpportunities =
Int
-> LocalRootPeers PeerAddr
-> Set PeerAddr
-> Set PeerAddr
-> Set PeerAddr
-> Set PeerAddr
forall {a}.
Ord a =>
Int -> LocalRootPeers a -> Set a -> Set a -> Set a -> Set a
demotionOpportunity
(Int
-> LocalRootPeers PeerAddr
-> Set PeerAddr
-> Set PeerAddr
-> Set PeerAddr
-> Set PeerAddr)
-> Signal Int
-> Signal
(LocalRootPeers PeerAddr
-> Set PeerAddr -> Set PeerAddr -> Set PeerAddr -> Set PeerAddr)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Signal Int
govTargetsSig
Signal
(LocalRootPeers PeerAddr
-> Set PeerAddr -> Set PeerAddr -> Set PeerAddr -> Set PeerAddr)
-> Signal (LocalRootPeers PeerAddr)
-> Signal
(Set PeerAddr -> Set PeerAddr -> Set PeerAddr -> Set PeerAddr)
forall a b. Signal (a -> b) -> Signal a -> Signal b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Signal (LocalRootPeers PeerAddr)
govLocalRootPeersSig
Signal
(Set PeerAddr -> Set PeerAddr -> Set PeerAddr -> Set PeerAddr)
-> Signal (Set PeerAddr)
-> Signal (Set PeerAddr -> Set PeerAddr -> Set PeerAddr)
forall a b. Signal (a -> b) -> Signal a -> Signal b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Signal (Set PeerAddr)
govEstablishedPeersSig
Signal (Set PeerAddr -> Set PeerAddr -> Set PeerAddr)
-> Signal (Set PeerAddr) -> Signal (Set PeerAddr -> Set PeerAddr)
forall a b. Signal (a -> b) -> Signal a -> Signal b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Signal (Set PeerAddr)
govActivePeersSig
Signal (Set PeerAddr -> Set PeerAddr)
-> Signal (Set PeerAddr) -> Signal (Set PeerAddr)
forall a b. Signal (a -> b) -> Signal a -> Signal b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Signal (Set PeerAddr)
govInProgressDemoteToColdSig
demotionOpportunitiesIgnoredTooLong :: Signal (Set PeerAddr)
demotionOpportunitiesIgnoredTooLong :: Signal (Set PeerAddr)
demotionOpportunitiesIgnoredTooLong =
DiffTime
-> (Set PeerAddr -> Set PeerAddr)
-> Signal (Set PeerAddr)
-> Signal (Set PeerAddr)
forall a b.
Ord b =>
DiffTime -> (a -> Set b) -> Signal a -> Signal (Set b)
Signal.keyedTimeout
DiffTime
10
Set PeerAddr -> Set PeerAddr
forall a. a -> a
id
Signal (Set PeerAddr)
demotionOpportunities
in TestName -> Property -> Property
forall prop. Testable prop => TestName -> prop -> Property
counterexample
(TestName
"\nSignal key: (target, local peers, established peers, active peers, " TestName -> TestName -> TestName
forall a. [a] -> [a] -> [a]
++
TestName
"demotion opportunities, ignored too long)") (Property -> Property) -> Property -> Property
forall a b. (a -> b) -> a -> b
$
Int
-> ((Int, [(HotValency, WarmValency, Set PeerAddr)], Set PeerAddr,
Set PeerAddr, Set PeerAddr, Set PeerAddr, Set PeerAddr)
-> TestName)
-> ((Int, [(HotValency, WarmValency, Set PeerAddr)], Set PeerAddr,
Set PeerAddr, Set PeerAddr, Set PeerAddr, Set PeerAddr)
-> Bool)
-> Signal
(Int, [(HotValency, WarmValency, Set PeerAddr)], Set PeerAddr,
Set PeerAddr, Set PeerAddr, Set PeerAddr, Set PeerAddr)
-> Property
forall a.
Int -> (a -> TestName) -> (a -> Bool) -> Signal a -> Property
signalProperty Int
20 (Int, [(HotValency, WarmValency, Set PeerAddr)], Set PeerAddr,
Set PeerAddr, Set PeerAddr, Set PeerAddr, Set PeerAddr)
-> TestName
forall a. Show a => a -> TestName
show
(\(Int
_,[(HotValency, WarmValency, Set PeerAddr)]
_,Set PeerAddr
_,Set PeerAddr
_,Set PeerAddr
_,Set PeerAddr
_,Set PeerAddr
toolong) -> Set PeerAddr -> Bool
forall a. Set a -> Bool
Set.null Set PeerAddr
toolong)
((,,,,,,) (Int
-> [(HotValency, WarmValency, Set PeerAddr)]
-> Set PeerAddr
-> Set PeerAddr
-> Set PeerAddr
-> Set PeerAddr
-> Set PeerAddr
-> (Int, [(HotValency, WarmValency, Set PeerAddr)], Set PeerAddr,
Set PeerAddr, Set PeerAddr, Set PeerAddr, Set PeerAddr))
-> Signal Int
-> Signal
([(HotValency, WarmValency, Set PeerAddr)]
-> Set PeerAddr
-> Set PeerAddr
-> Set PeerAddr
-> Set PeerAddr
-> Set PeerAddr
-> (Int, [(HotValency, WarmValency, Set PeerAddr)], Set PeerAddr,
Set PeerAddr, Set PeerAddr, Set PeerAddr, Set PeerAddr))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Signal Int
govTargetsSig
Signal
([(HotValency, WarmValency, Set PeerAddr)]
-> Set PeerAddr
-> Set PeerAddr
-> Set PeerAddr
-> Set PeerAddr
-> Set PeerAddr
-> (Int, [(HotValency, WarmValency, Set PeerAddr)], Set PeerAddr,
Set PeerAddr, Set PeerAddr, Set PeerAddr, Set PeerAddr))
-> Signal [(HotValency, WarmValency, Set PeerAddr)]
-> Signal
(Set PeerAddr
-> Set PeerAddr
-> Set PeerAddr
-> Set PeerAddr
-> Set PeerAddr
-> (Int, [(HotValency, WarmValency, Set PeerAddr)], Set PeerAddr,
Set PeerAddr, Set PeerAddr, Set PeerAddr, Set PeerAddr))
forall a b. Signal (a -> b) -> Signal a -> Signal b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (LocalRootPeers PeerAddr
-> [(HotValency, WarmValency, Set PeerAddr)]
forall peeraddr.
LocalRootPeers peeraddr
-> [(HotValency, WarmValency, Set peeraddr)]
LocalRootPeers.toGroupSets (LocalRootPeers PeerAddr
-> [(HotValency, WarmValency, Set PeerAddr)])
-> Signal (LocalRootPeers PeerAddr)
-> Signal [(HotValency, WarmValency, Set PeerAddr)]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Signal (LocalRootPeers PeerAddr)
govLocalRootPeersSig)
Signal
(Set PeerAddr
-> Set PeerAddr
-> Set PeerAddr
-> Set PeerAddr
-> Set PeerAddr
-> (Int, [(HotValency, WarmValency, Set PeerAddr)], Set PeerAddr,
Set PeerAddr, Set PeerAddr, Set PeerAddr, Set PeerAddr))
-> Signal (Set PeerAddr)
-> Signal
(Set PeerAddr
-> Set PeerAddr
-> Set PeerAddr
-> Set PeerAddr
-> (Int, [(HotValency, WarmValency, Set PeerAddr)], Set PeerAddr,
Set PeerAddr, Set PeerAddr, Set PeerAddr, Set PeerAddr))
forall a b. Signal (a -> b) -> Signal a -> Signal b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Signal (Set PeerAddr)
govEstablishedPeersSig
Signal
(Set PeerAddr
-> Set PeerAddr
-> Set PeerAddr
-> Set PeerAddr
-> (Int, [(HotValency, WarmValency, Set PeerAddr)], Set PeerAddr,
Set PeerAddr, Set PeerAddr, Set PeerAddr, Set PeerAddr))
-> Signal (Set PeerAddr)
-> Signal
(Set PeerAddr
-> Set PeerAddr
-> Set PeerAddr
-> (Int, [(HotValency, WarmValency, Set PeerAddr)], Set PeerAddr,
Set PeerAddr, Set PeerAddr, Set PeerAddr, Set PeerAddr))
forall a b. Signal (a -> b) -> Signal a -> Signal b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Signal (Set PeerAddr)
govActivePeersSig
Signal
(Set PeerAddr
-> Set PeerAddr
-> Set PeerAddr
-> (Int, [(HotValency, WarmValency, Set PeerAddr)], Set PeerAddr,
Set PeerAddr, Set PeerAddr, Set PeerAddr, Set PeerAddr))
-> Signal (Set PeerAddr)
-> Signal
(Set PeerAddr
-> Set PeerAddr
-> (Int, [(HotValency, WarmValency, Set PeerAddr)], Set PeerAddr,
Set PeerAddr, Set PeerAddr, Set PeerAddr, Set PeerAddr))
forall a b. Signal (a -> b) -> Signal a -> Signal b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Signal (Set PeerAddr)
demotionOpportunities
Signal
(Set PeerAddr
-> Set PeerAddr
-> (Int, [(HotValency, WarmValency, Set PeerAddr)], Set PeerAddr,
Set PeerAddr, Set PeerAddr, Set PeerAddr, Set PeerAddr))
-> Signal (Set PeerAddr)
-> Signal
(Set PeerAddr
-> (Int, [(HotValency, WarmValency, Set PeerAddr)], Set PeerAddr,
Set PeerAddr, Set PeerAddr, Set PeerAddr, Set PeerAddr))
forall a b. Signal (a -> b) -> Signal a -> Signal b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Signal (Set PeerAddr)
govInProgressDemoteToColdSig
Signal
(Set PeerAddr
-> (Int, [(HotValency, WarmValency, Set PeerAddr)], Set PeerAddr,
Set PeerAddr, Set PeerAddr, Set PeerAddr, Set PeerAddr))
-> Signal (Set PeerAddr)
-> Signal
(Int, [(HotValency, WarmValency, Set PeerAddr)], Set PeerAddr,
Set PeerAddr, Set PeerAddr, Set PeerAddr, Set PeerAddr)
forall a b. Signal (a -> b) -> Signal a -> Signal b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Signal (Set PeerAddr)
demotionOpportunitiesIgnoredTooLong)
prop_governor_target_established_big_ledger_peers_above
:: MaxTime -> GovernorMockEnvironment -> Property
prop_governor_target_established_big_ledger_peers_above :: MaxTime -> GovernorMockEnvironment -> Property
prop_governor_target_established_big_ledger_peers_above (MaxTime Time
maxTime) GovernorMockEnvironment
env =
let events :: Events TestTraceEvent
events = Time -> [(Time, TestTraceEvent)] -> Events TestTraceEvent
forall a. Time -> [(Time, a)] -> Events a
Signal.eventsFromListUpToTime Time
maxTime
([(Time, TestTraceEvent)] -> Events TestTraceEvent)
-> (GovernorMockEnvironment -> [(Time, TestTraceEvent)])
-> GovernorMockEnvironment
-> Events TestTraceEvent
forall b c a. (b -> c) -> (a -> b) -> a -> c
. SimTrace Void -> [(Time, TestTraceEvent)]
forall a. SimTrace a -> [(Time, TestTraceEvent)]
selectPeerSelectionTraceEvents
(SimTrace Void -> [(Time, TestTraceEvent)])
-> (GovernorMockEnvironment -> SimTrace Void)
-> GovernorMockEnvironment
-> [(Time, TestTraceEvent)]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. GovernorMockEnvironment -> SimTrace Void
runGovernorInMockEnvironment
(GovernorMockEnvironment -> Events TestTraceEvent)
-> GovernorMockEnvironment -> Events TestTraceEvent
forall a b. (a -> b) -> a -> b
$ GovernorMockEnvironment
env
govTargetsSig :: Signal Int
govTargetsSig :: Signal Int
govTargetsSig =
(forall peerconn. PeerSelectionState PeerAddr peerconn -> Int)
-> ConsensusMode -> Events TestTraceEvent -> Signal Int
forall a.
Eq a =>
(forall peerconn. PeerSelectionState PeerAddr peerconn -> a)
-> ConsensusMode -> Events TestTraceEvent -> Signal a
selectGovState (PeerSelectionTargets -> Int
targetNumberOfEstablishedBigLedgerPeers (PeerSelectionTargets -> Int)
-> (PeerSelectionState PeerAddr peerconn -> PeerSelectionTargets)
-> PeerSelectionState PeerAddr peerconn
-> Int
forall b c a. (b -> c) -> (a -> b) -> a -> c
. PeerSelectionState PeerAddr peerconn -> PeerSelectionTargets
forall peeraddr peerconn.
PeerSelectionState peeraddr peerconn -> PeerSelectionTargets
Governor.targets)
(GovernorMockEnvironment -> ConsensusMode
consensusMode GovernorMockEnvironment
env)
Events TestTraceEvent
events
govEstablishedPeersSig :: Signal (Set PeerAddr)
govEstablishedPeersSig :: Signal (Set PeerAddr)
govEstablishedPeersSig =
(forall peerconn.
PeerSelectionState PeerAddr peerconn -> Set PeerAddr)
-> ConsensusMode -> Events TestTraceEvent -> Signal (Set PeerAddr)
forall a.
Eq a =>
(forall peerconn. PeerSelectionState PeerAddr peerconn -> a)
-> ConsensusMode -> Events TestTraceEvent -> Signal a
selectGovState
((PeerSelectionState PeerAddr peerconn -> Set PeerAddr)
-> PeerSelectionState PeerAddr peerconn -> Set PeerAddr
forall peerconn.
(PeerSelectionState PeerAddr peerconn -> Set PeerAddr)
-> PeerSelectionState PeerAddr peerconn -> Set PeerAddr
takeBigLedgerPeers ((PeerSelectionState PeerAddr peerconn -> Set PeerAddr)
-> PeerSelectionState PeerAddr peerconn -> Set PeerAddr)
-> (PeerSelectionState PeerAddr peerconn -> Set PeerAddr)
-> PeerSelectionState PeerAddr peerconn
-> Set PeerAddr
forall a b. (a -> b) -> a -> b
$
EstablishedPeers PeerAddr peerconn -> Set PeerAddr
forall peeraddr peerconn.
EstablishedPeers peeraddr peerconn -> Set peeraddr
EstablishedPeers.toSet (EstablishedPeers PeerAddr peerconn -> Set PeerAddr)
-> (PeerSelectionState PeerAddr peerconn
-> EstablishedPeers PeerAddr peerconn)
-> PeerSelectionState PeerAddr peerconn
-> Set PeerAddr
forall b c a. (b -> c) -> (a -> b) -> a -> c
. PeerSelectionState PeerAddr peerconn
-> EstablishedPeers PeerAddr peerconn
forall peeraddr peerconn.
PeerSelectionState peeraddr peerconn
-> EstablishedPeers peeraddr peerconn
Governor.establishedPeers)
(GovernorMockEnvironment -> ConsensusMode
consensusMode GovernorMockEnvironment
env)
Events TestTraceEvent
events
govInProgressDemoteToColdSig :: Signal (Set PeerAddr)
govInProgressDemoteToColdSig :: Signal (Set PeerAddr)
govInProgressDemoteToColdSig =
(forall peerconn.
PeerSelectionState PeerAddr peerconn -> Set PeerAddr)
-> ConsensusMode -> Events TestTraceEvent -> Signal (Set PeerAddr)
forall a.
Eq a =>
(forall peerconn. PeerSelectionState PeerAddr peerconn -> a)
-> ConsensusMode -> Events TestTraceEvent -> Signal a
selectGovState PeerSelectionState PeerAddr peerconn -> Set PeerAddr
forall peerconn.
PeerSelectionState PeerAddr peerconn -> Set PeerAddr
forall peeraddr peerconn.
PeerSelectionState peeraddr peerconn -> Set peeraddr
Governor.inProgressDemoteToCold
(GovernorMockEnvironment -> ConsensusMode
consensusMode GovernorMockEnvironment
env)
Events TestTraceEvent
events
govActivePeersSig :: Signal (Set PeerAddr)
govActivePeersSig :: Signal (Set PeerAddr)
govActivePeersSig =
(forall peerconn.
PeerSelectionState PeerAddr peerconn -> Set PeerAddr)
-> ConsensusMode -> Events TestTraceEvent -> Signal (Set PeerAddr)
forall a.
Eq a =>
(forall peerconn. PeerSelectionState PeerAddr peerconn -> a)
-> ConsensusMode -> Events TestTraceEvent -> Signal a
selectGovState ((PeerSelectionState PeerAddr peerconn -> Set PeerAddr)
-> PeerSelectionState PeerAddr peerconn -> Set PeerAddr
forall peerconn.
(PeerSelectionState PeerAddr peerconn -> Set PeerAddr)
-> PeerSelectionState PeerAddr peerconn -> Set PeerAddr
takeBigLedgerPeers PeerSelectionState PeerAddr peerconn -> Set PeerAddr
forall peeraddr peerconn.
PeerSelectionState peeraddr peerconn -> Set peeraddr
Governor.activePeers)
(GovernorMockEnvironment -> ConsensusMode
consensusMode GovernorMockEnvironment
env)
Events TestTraceEvent
events
demotionOpportunity :: Int -> Set a -> Set a -> Set a -> Set a
demotionOpportunity Int
target Set a
established Set a
active Set a
inProgressDemoteToCold
| Set a -> Int
forall a. Set a -> Int
Set.size Set a
established Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
<= Int
target
= Set a
forall a. Set a
Set.empty
| Bool
otherwise
= Set a
established Set a -> Set a -> Set a
forall a. Ord a => Set a -> Set a -> Set a
Set.\\ Set a
active
Set a -> Set a -> Set a
forall a. Ord a => Set a -> Set a -> Set a
Set.\\ Set a
inProgressDemoteToCold
demotionOpportunities :: Signal (Set PeerAddr)
demotionOpportunities :: Signal (Set PeerAddr)
demotionOpportunities =
Int -> Set PeerAddr -> Set PeerAddr -> Set PeerAddr -> Set PeerAddr
forall {a}. Ord a => Int -> Set a -> Set a -> Set a -> Set a
demotionOpportunity
(Int
-> Set PeerAddr -> Set PeerAddr -> Set PeerAddr -> Set PeerAddr)
-> Signal Int
-> Signal
(Set PeerAddr -> Set PeerAddr -> Set PeerAddr -> Set PeerAddr)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Signal Int
govTargetsSig
Signal
(Set PeerAddr -> Set PeerAddr -> Set PeerAddr -> Set PeerAddr)
-> Signal (Set PeerAddr)
-> Signal (Set PeerAddr -> Set PeerAddr -> Set PeerAddr)
forall a b. Signal (a -> b) -> Signal a -> Signal b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Signal (Set PeerAddr)
govEstablishedPeersSig
Signal (Set PeerAddr -> Set PeerAddr -> Set PeerAddr)
-> Signal (Set PeerAddr) -> Signal (Set PeerAddr -> Set PeerAddr)
forall a b. Signal (a -> b) -> Signal a -> Signal b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Signal (Set PeerAddr)
govActivePeersSig
Signal (Set PeerAddr -> Set PeerAddr)
-> Signal (Set PeerAddr) -> Signal (Set PeerAddr)
forall a b. Signal (a -> b) -> Signal a -> Signal b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Signal (Set PeerAddr)
govInProgressDemoteToColdSig
demotionOpportunitiesIgnoredTooLong :: Signal (Set PeerAddr)
demotionOpportunitiesIgnoredTooLong :: Signal (Set PeerAddr)
demotionOpportunitiesIgnoredTooLong =
DiffTime
-> (Set PeerAddr -> Set PeerAddr)
-> Signal (Set PeerAddr)
-> Signal (Set PeerAddr)
forall a b.
Ord b =>
DiffTime -> (a -> Set b) -> Signal a -> Signal (Set b)
Signal.keyedTimeout
DiffTime
10
Set PeerAddr -> Set PeerAddr
forall a. a -> a
id
Signal (Set PeerAddr)
demotionOpportunities
in TestName -> Property -> Property
forall prop. Testable prop => TestName -> prop -> Property
counterexample
(TestName
"\nSignal key: (target, established big ledger peers, active big ledger peers, " TestName -> TestName -> TestName
forall a. [a] -> [a] -> [a]
++
TestName
"demotion opportunities, ignored too long)") (Property -> Property) -> Property -> Property
forall a b. (a -> b) -> a -> b
$
Int
-> ((Int, Set PeerAddr, Set PeerAddr, Set PeerAddr, Set PeerAddr)
-> TestName)
-> ((Int, Set PeerAddr, Set PeerAddr, Set PeerAddr, Set PeerAddr)
-> Bool)
-> Signal
(Int, Set PeerAddr, Set PeerAddr, Set PeerAddr, Set PeerAddr)
-> Property
forall a.
Int -> (a -> TestName) -> (a -> Bool) -> Signal a -> Property
signalProperty Int
20 (Int, Set PeerAddr, Set PeerAddr, Set PeerAddr, Set PeerAddr)
-> TestName
forall a. Show a => a -> TestName
show
(\(Int
_,Set PeerAddr
_,Set PeerAddr
_,Set PeerAddr
_,Set PeerAddr
toolong) -> Set PeerAddr -> Bool
forall a. Set a -> Bool
Set.null Set PeerAddr
toolong)
((,,,,) (Int
-> Set PeerAddr
-> Set PeerAddr
-> Set PeerAddr
-> Set PeerAddr
-> (Int, Set PeerAddr, Set PeerAddr, Set PeerAddr, Set PeerAddr))
-> Signal Int
-> Signal
(Set PeerAddr
-> Set PeerAddr
-> Set PeerAddr
-> Set PeerAddr
-> (Int, Set PeerAddr, Set PeerAddr, Set PeerAddr, Set PeerAddr))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Signal Int
govTargetsSig
Signal
(Set PeerAddr
-> Set PeerAddr
-> Set PeerAddr
-> Set PeerAddr
-> (Int, Set PeerAddr, Set PeerAddr, Set PeerAddr, Set PeerAddr))
-> Signal (Set PeerAddr)
-> Signal
(Set PeerAddr
-> Set PeerAddr
-> Set PeerAddr
-> (Int, Set PeerAddr, Set PeerAddr, Set PeerAddr, Set PeerAddr))
forall a b. Signal (a -> b) -> Signal a -> Signal b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Signal (Set PeerAddr)
govEstablishedPeersSig
Signal
(Set PeerAddr
-> Set PeerAddr
-> Set PeerAddr
-> (Int, Set PeerAddr, Set PeerAddr, Set PeerAddr, Set PeerAddr))
-> Signal (Set PeerAddr)
-> Signal
(Set PeerAddr
-> Set PeerAddr
-> (Int, Set PeerAddr, Set PeerAddr, Set PeerAddr, Set PeerAddr))
forall a b. Signal (a -> b) -> Signal a -> Signal b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Signal (Set PeerAddr)
govActivePeersSig
Signal
(Set PeerAddr
-> Set PeerAddr
-> (Int, Set PeerAddr, Set PeerAddr, Set PeerAddr, Set PeerAddr))
-> Signal (Set PeerAddr)
-> Signal
(Set PeerAddr
-> (Int, Set PeerAddr, Set PeerAddr, Set PeerAddr, Set PeerAddr))
forall a b. Signal (a -> b) -> Signal a -> Signal b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Signal (Set PeerAddr)
demotionOpportunities
Signal
(Set PeerAddr
-> (Int, Set PeerAddr, Set PeerAddr, Set PeerAddr, Set PeerAddr))
-> Signal (Set PeerAddr)
-> Signal
(Int, Set PeerAddr, Set PeerAddr, Set PeerAddr, Set PeerAddr)
forall a b. Signal (a -> b) -> Signal a -> Signal b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Signal (Set PeerAddr)
demotionOpportunitiesIgnoredTooLong)
prop_governor_target_active_above :: MaxTime -> GovernorMockEnvironment -> Property
prop_governor_target_active_above :: MaxTime -> GovernorMockEnvironment -> Property
prop_governor_target_active_above (MaxTime Time
maxTime) GovernorMockEnvironment
env =
let events :: Events TestTraceEvent
events = Time -> [(Time, TestTraceEvent)] -> Events TestTraceEvent
forall a. Time -> [(Time, a)] -> Events a
Signal.eventsFromListUpToTime Time
maxTime
([(Time, TestTraceEvent)] -> Events TestTraceEvent)
-> (GovernorMockEnvironment -> [(Time, TestTraceEvent)])
-> GovernorMockEnvironment
-> Events TestTraceEvent
forall b c a. (b -> c) -> (a -> b) -> a -> c
. SimTrace Void -> [(Time, TestTraceEvent)]
forall a. SimTrace a -> [(Time, TestTraceEvent)]
selectPeerSelectionTraceEvents
(SimTrace Void -> [(Time, TestTraceEvent)])
-> (GovernorMockEnvironment -> SimTrace Void)
-> GovernorMockEnvironment
-> [(Time, TestTraceEvent)]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. GovernorMockEnvironment -> SimTrace Void
runGovernorInMockEnvironment
(GovernorMockEnvironment -> Events TestTraceEvent)
-> GovernorMockEnvironment -> Events TestTraceEvent
forall a b. (a -> b) -> a -> b
$ GovernorMockEnvironment
env
govTargetsSig :: Signal Int
govTargetsSig :: Signal Int
govTargetsSig =
(forall peerconn. PeerSelectionState PeerAddr peerconn -> Int)
-> ConsensusMode -> Events TestTraceEvent -> Signal Int
forall a.
Eq a =>
(forall peerconn. PeerSelectionState PeerAddr peerconn -> a)
-> ConsensusMode -> Events TestTraceEvent -> Signal a
selectGovState (PeerSelectionTargets -> Int
targetNumberOfActivePeers (PeerSelectionTargets -> Int)
-> (PeerSelectionState PeerAddr peerconn -> PeerSelectionTargets)
-> PeerSelectionState PeerAddr peerconn
-> Int
forall b c a. (b -> c) -> (a -> b) -> a -> c
. PeerSelectionState PeerAddr peerconn -> PeerSelectionTargets
forall peeraddr peerconn.
PeerSelectionState peeraddr peerconn -> PeerSelectionTargets
Governor.targets)
(GovernorMockEnvironment -> ConsensusMode
consensusMode GovernorMockEnvironment
env)
Events TestTraceEvent
events
govLocalRootPeersSig :: Signal (LocalRootPeers.LocalRootPeers PeerAddr)
govLocalRootPeersSig :: Signal (LocalRootPeers PeerAddr)
govLocalRootPeersSig =
(forall peerconn.
PeerSelectionState PeerAddr peerconn -> LocalRootPeers PeerAddr)
-> ConsensusMode
-> Events TestTraceEvent
-> Signal (LocalRootPeers PeerAddr)
forall a.
Eq a =>
(forall peerconn. PeerSelectionState PeerAddr peerconn -> a)
-> ConsensusMode -> Events TestTraceEvent -> Signal a
selectGovState PeerSelectionState PeerAddr peerconn -> LocalRootPeers PeerAddr
forall peerconn.
PeerSelectionState PeerAddr peerconn -> LocalRootPeers PeerAddr
forall peeraddr peerconn.
PeerSelectionState peeraddr peerconn -> LocalRootPeers peeraddr
Governor.localRootPeers
(GovernorMockEnvironment -> ConsensusMode
consensusMode GovernorMockEnvironment
env)
Events TestTraceEvent
events
govActivePeersSig :: Signal (Set PeerAddr)
govActivePeersSig :: Signal (Set PeerAddr)
govActivePeersSig =
(forall peerconn.
PeerSelectionState PeerAddr peerconn -> Set PeerAddr)
-> ConsensusMode -> Events TestTraceEvent -> Signal (Set PeerAddr)
forall a.
Eq a =>
(forall peerconn. PeerSelectionState PeerAddr peerconn -> a)
-> ConsensusMode -> Events TestTraceEvent -> Signal a
selectGovState ((PeerSelectionState PeerAddr peerconn -> Set PeerAddr)
-> PeerSelectionState PeerAddr peerconn -> Set PeerAddr
forall peerconn.
(PeerSelectionState PeerAddr peerconn -> Set PeerAddr)
-> PeerSelectionState PeerAddr peerconn -> Set PeerAddr
dropBigLedgerPeers PeerSelectionState PeerAddr peerconn -> Set PeerAddr
forall peeraddr peerconn.
PeerSelectionState peeraddr peerconn -> Set peeraddr
Governor.activePeers)
(GovernorMockEnvironment -> ConsensusMode
consensusMode GovernorMockEnvironment
env)
Events TestTraceEvent
events
govInProgressDemoteToColdSig :: Signal (Set PeerAddr)
govInProgressDemoteToColdSig :: Signal (Set PeerAddr)
govInProgressDemoteToColdSig =
(forall peerconn.
PeerSelectionState PeerAddr peerconn -> Set PeerAddr)
-> ConsensusMode -> Events TestTraceEvent -> Signal (Set PeerAddr)
forall a.
Eq a =>
(forall peerconn. PeerSelectionState PeerAddr peerconn -> a)
-> ConsensusMode -> Events TestTraceEvent -> Signal a
selectGovState PeerSelectionState PeerAddr peerconn -> Set PeerAddr
forall peerconn.
PeerSelectionState PeerAddr peerconn -> Set PeerAddr
forall peeraddr peerconn.
PeerSelectionState peeraddr peerconn -> Set peeraddr
Governor.inProgressDemoteToCold
(GovernorMockEnvironment -> ConsensusMode
consensusMode GovernorMockEnvironment
env)
Events TestTraceEvent
events
demotionOpportunity :: Int -> LocalRootPeers a -> Set a -> Set a -> Set a
demotionOpportunity Int
target LocalRootPeers a
local Set a
active Set a
inProgressDemoteToCold
| (Set a -> Int
forall a. Set a -> Int
Set.size Set a
active Int -> Int -> Int
forall a. Num a => a -> a -> a
- Set a -> Int
forall a. Set a -> Int
Set.size Set a
inProgressDemoteToCold) Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
<= Int
target
= Set a
forall a. Set a
Set.empty
| Bool
otherwise
= Set a
active Set a -> Set a -> Set a
forall a. Ord a => Set a -> Set a -> Set a
Set.\\ LocalRootPeers a -> Set a
forall peeraddr. LocalRootPeers peeraddr -> Set peeraddr
LocalRootPeers.keysSet LocalRootPeers a
local
Set a -> Set a -> Set a
forall a. Ord a => Set a -> Set a -> Set a
Set.\\ Set a
inProgressDemoteToCold
demotionOpportunities :: Signal (Set PeerAddr)
demotionOpportunities :: Signal (Set PeerAddr)
demotionOpportunities =
Int
-> LocalRootPeers PeerAddr
-> Set PeerAddr
-> Set PeerAddr
-> Set PeerAddr
forall {a}.
Ord a =>
Int -> LocalRootPeers a -> Set a -> Set a -> Set a
demotionOpportunity
(Int
-> LocalRootPeers PeerAddr
-> Set PeerAddr
-> Set PeerAddr
-> Set PeerAddr)
-> Signal Int
-> Signal
(LocalRootPeers PeerAddr
-> Set PeerAddr -> Set PeerAddr -> Set PeerAddr)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Signal Int
govTargetsSig
Signal
(LocalRootPeers PeerAddr
-> Set PeerAddr -> Set PeerAddr -> Set PeerAddr)
-> Signal (LocalRootPeers PeerAddr)
-> Signal (Set PeerAddr -> Set PeerAddr -> Set PeerAddr)
forall a b. Signal (a -> b) -> Signal a -> Signal b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Signal (LocalRootPeers PeerAddr)
govLocalRootPeersSig
Signal (Set PeerAddr -> Set PeerAddr -> Set PeerAddr)
-> Signal (Set PeerAddr) -> Signal (Set PeerAddr -> Set PeerAddr)
forall a b. Signal (a -> b) -> Signal a -> Signal b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Signal (Set PeerAddr)
govActivePeersSig
Signal (Set PeerAddr -> Set PeerAddr)
-> Signal (Set PeerAddr) -> Signal (Set PeerAddr)
forall a b. Signal (a -> b) -> Signal a -> Signal b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Signal (Set PeerAddr)
govInProgressDemoteToColdSig
demotionOpportunitiesIgnoredTooLong :: Signal (Set PeerAddr)
demotionOpportunitiesIgnoredTooLong :: Signal (Set PeerAddr)
demotionOpportunitiesIgnoredTooLong =
DiffTime
-> (Set PeerAddr -> Set PeerAddr)
-> Signal (Set PeerAddr)
-> Signal (Set PeerAddr)
forall a b.
Ord b =>
DiffTime -> (a -> Set b) -> Signal a -> Signal (Set b)
Signal.keyedTimeout
DiffTime
15
Set PeerAddr -> Set PeerAddr
forall a. a -> a
id
Signal (Set PeerAddr)
demotionOpportunities
in TestName -> Property -> Property
forall prop. Testable prop => TestName -> prop -> Property
counterexample
(TestName
"\nSignal key: (target, local peers, active peers, " TestName -> TestName -> TestName
forall a. [a] -> [a] -> [a]
++
TestName
"demotion opportunities, ignored too long)") (Property -> Property) -> Property -> Property
forall a b. (a -> b) -> a -> b
$
Int
-> ((Int, [(HotValency, WarmValency, Set PeerAddr)], Set PeerAddr,
Set PeerAddr, Set PeerAddr)
-> TestName)
-> ((Int, [(HotValency, WarmValency, Set PeerAddr)], Set PeerAddr,
Set PeerAddr, Set PeerAddr)
-> Bool)
-> Signal
(Int, [(HotValency, WarmValency, Set PeerAddr)], Set PeerAddr,
Set PeerAddr, Set PeerAddr)
-> Property
forall a.
Int -> (a -> TestName) -> (a -> Bool) -> Signal a -> Property
signalProperty Int
20 (Int, [(HotValency, WarmValency, Set PeerAddr)], Set PeerAddr,
Set PeerAddr, Set PeerAddr)
-> TestName
forall a. Show a => a -> TestName
show
(\(Int
_,[(HotValency, WarmValency, Set PeerAddr)]
_,Set PeerAddr
_,Set PeerAddr
_,Set PeerAddr
toolong) -> Set PeerAddr -> Bool
forall a. Set a -> Bool
Set.null Set PeerAddr
toolong)
((,,,,) (Int
-> [(HotValency, WarmValency, Set PeerAddr)]
-> Set PeerAddr
-> Set PeerAddr
-> Set PeerAddr
-> (Int, [(HotValency, WarmValency, Set PeerAddr)], Set PeerAddr,
Set PeerAddr, Set PeerAddr))
-> Signal Int
-> Signal
([(HotValency, WarmValency, Set PeerAddr)]
-> Set PeerAddr
-> Set PeerAddr
-> Set PeerAddr
-> (Int, [(HotValency, WarmValency, Set PeerAddr)], Set PeerAddr,
Set PeerAddr, Set PeerAddr))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Signal Int
govTargetsSig
Signal
([(HotValency, WarmValency, Set PeerAddr)]
-> Set PeerAddr
-> Set PeerAddr
-> Set PeerAddr
-> (Int, [(HotValency, WarmValency, Set PeerAddr)], Set PeerAddr,
Set PeerAddr, Set PeerAddr))
-> Signal [(HotValency, WarmValency, Set PeerAddr)]
-> Signal
(Set PeerAddr
-> Set PeerAddr
-> Set PeerAddr
-> (Int, [(HotValency, WarmValency, Set PeerAddr)], Set PeerAddr,
Set PeerAddr, Set PeerAddr))
forall a b. Signal (a -> b) -> Signal a -> Signal b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (LocalRootPeers PeerAddr
-> [(HotValency, WarmValency, Set PeerAddr)]
forall peeraddr.
LocalRootPeers peeraddr
-> [(HotValency, WarmValency, Set peeraddr)]
LocalRootPeers.toGroupSets (LocalRootPeers PeerAddr
-> [(HotValency, WarmValency, Set PeerAddr)])
-> Signal (LocalRootPeers PeerAddr)
-> Signal [(HotValency, WarmValency, Set PeerAddr)]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Signal (LocalRootPeers PeerAddr)
govLocalRootPeersSig)
Signal
(Set PeerAddr
-> Set PeerAddr
-> Set PeerAddr
-> (Int, [(HotValency, WarmValency, Set PeerAddr)], Set PeerAddr,
Set PeerAddr, Set PeerAddr))
-> Signal (Set PeerAddr)
-> Signal
(Set PeerAddr
-> Set PeerAddr
-> (Int, [(HotValency, WarmValency, Set PeerAddr)], Set PeerAddr,
Set PeerAddr, Set PeerAddr))
forall a b. Signal (a -> b) -> Signal a -> Signal b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Signal (Set PeerAddr)
govActivePeersSig
Signal
(Set PeerAddr
-> Set PeerAddr
-> (Int, [(HotValency, WarmValency, Set PeerAddr)], Set PeerAddr,
Set PeerAddr, Set PeerAddr))
-> Signal (Set PeerAddr)
-> Signal
(Set PeerAddr
-> (Int, [(HotValency, WarmValency, Set PeerAddr)], Set PeerAddr,
Set PeerAddr, Set PeerAddr))
forall a b. Signal (a -> b) -> Signal a -> Signal b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Signal (Set PeerAddr)
demotionOpportunities
Signal
(Set PeerAddr
-> (Int, [(HotValency, WarmValency, Set PeerAddr)], Set PeerAddr,
Set PeerAddr, Set PeerAddr))
-> Signal (Set PeerAddr)
-> Signal
(Int, [(HotValency, WarmValency, Set PeerAddr)], Set PeerAddr,
Set PeerAddr, Set PeerAddr)
forall a b. Signal (a -> b) -> Signal a -> Signal b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Signal (Set PeerAddr)
demotionOpportunitiesIgnoredTooLong)
prop_governor_target_active_big_ledger_peers_above
:: MaxTime -> GovernorMockEnvironment -> Property
prop_governor_target_active_big_ledger_peers_above :: MaxTime -> GovernorMockEnvironment -> Property
prop_governor_target_active_big_ledger_peers_above (MaxTime Time
maxTime) GovernorMockEnvironment
env =
let events :: Events TestTraceEvent
events = Time -> [(Time, TestTraceEvent)] -> Events TestTraceEvent
forall a. Time -> [(Time, a)] -> Events a
Signal.eventsFromListUpToTime Time
maxTime
([(Time, TestTraceEvent)] -> Events TestTraceEvent)
-> (GovernorMockEnvironment -> [(Time, TestTraceEvent)])
-> GovernorMockEnvironment
-> Events TestTraceEvent
forall b c a. (b -> c) -> (a -> b) -> a -> c
. SimTrace Void -> [(Time, TestTraceEvent)]
forall a. SimTrace a -> [(Time, TestTraceEvent)]
selectPeerSelectionTraceEvents
(SimTrace Void -> [(Time, TestTraceEvent)])
-> (GovernorMockEnvironment -> SimTrace Void)
-> GovernorMockEnvironment
-> [(Time, TestTraceEvent)]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. GovernorMockEnvironment -> SimTrace Void
runGovernorInMockEnvironment
(GovernorMockEnvironment -> Events TestTraceEvent)
-> GovernorMockEnvironment -> Events TestTraceEvent
forall a b. (a -> b) -> a -> b
$ GovernorMockEnvironment
env
govTargetsSig :: Signal Int
govTargetsSig :: Signal Int
govTargetsSig =
(forall peerconn. PeerSelectionState PeerAddr peerconn -> Int)
-> ConsensusMode -> Events TestTraceEvent -> Signal Int
forall a.
Eq a =>
(forall peerconn. PeerSelectionState PeerAddr peerconn -> a)
-> ConsensusMode -> Events TestTraceEvent -> Signal a
selectGovState (PeerSelectionTargets -> Int
targetNumberOfActiveBigLedgerPeers (PeerSelectionTargets -> Int)
-> (PeerSelectionState PeerAddr peerconn -> PeerSelectionTargets)
-> PeerSelectionState PeerAddr peerconn
-> Int
forall b c a. (b -> c) -> (a -> b) -> a -> c
. PeerSelectionState PeerAddr peerconn -> PeerSelectionTargets
forall peeraddr peerconn.
PeerSelectionState peeraddr peerconn -> PeerSelectionTargets
Governor.targets)
(GovernorMockEnvironment -> ConsensusMode
consensusMode GovernorMockEnvironment
env)
Events TestTraceEvent
events
govActivePeersSig :: Signal (Set PeerAddr)
govActivePeersSig :: Signal (Set PeerAddr)
govActivePeersSig =
(forall peerconn.
PeerSelectionState PeerAddr peerconn -> Set PeerAddr)
-> ConsensusMode -> Events TestTraceEvent -> Signal (Set PeerAddr)
forall a.
Eq a =>
(forall peerconn. PeerSelectionState PeerAddr peerconn -> a)
-> ConsensusMode -> Events TestTraceEvent -> Signal a
selectGovState ((PeerSelectionState PeerAddr peerconn -> Set PeerAddr)
-> PeerSelectionState PeerAddr peerconn -> Set PeerAddr
forall peerconn.
(PeerSelectionState PeerAddr peerconn -> Set PeerAddr)
-> PeerSelectionState PeerAddr peerconn -> Set PeerAddr
takeBigLedgerPeers PeerSelectionState PeerAddr peerconn -> Set PeerAddr
forall peeraddr peerconn.
PeerSelectionState peeraddr peerconn -> Set peeraddr
Governor.activePeers)
(GovernorMockEnvironment -> ConsensusMode
consensusMode GovernorMockEnvironment
env)
Events TestTraceEvent
events
demotionOpportunity :: Int -> Set a -> Set a
demotionOpportunity Int
target Set a
active
| Set a -> Int
forall a. Set a -> Int
Set.size Set a
active Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
<= Int
target
= Set a
forall a. Set a
Set.empty
| Bool
otherwise
= Set a
active
demotionOpportunities :: Signal (Set PeerAddr)
demotionOpportunities :: Signal (Set PeerAddr)
demotionOpportunities =
Int -> Set PeerAddr -> Set PeerAddr
forall {a}. Int -> Set a -> Set a
demotionOpportunity
(Int -> Set PeerAddr -> Set PeerAddr)
-> Signal Int -> Signal (Set PeerAddr -> Set PeerAddr)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Signal Int
govTargetsSig
Signal (Set PeerAddr -> Set PeerAddr)
-> Signal (Set PeerAddr) -> Signal (Set PeerAddr)
forall a b. Signal (a -> b) -> Signal a -> Signal b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Signal (Set PeerAddr)
govActivePeersSig
demotionOpportunitiesIgnoredTooLong :: Signal (Set PeerAddr)
demotionOpportunitiesIgnoredTooLong :: Signal (Set PeerAddr)
demotionOpportunitiesIgnoredTooLong =
DiffTime
-> (Set PeerAddr -> Set PeerAddr)
-> Signal (Set PeerAddr)
-> Signal (Set PeerAddr)
forall a b.
Ord b =>
DiffTime -> (a -> Set b) -> Signal a -> Signal (Set b)
Signal.keyedTimeout
DiffTime
10
Set PeerAddr -> Set PeerAddr
forall a. a -> a
id
Signal (Set PeerAddr)
demotionOpportunities
in TestName -> Property -> Property
forall prop. Testable prop => TestName -> prop -> Property
counterexample
(TestName
"\nSignal key: (target, active big ledger peers, " TestName -> TestName -> TestName
forall a. [a] -> [a] -> [a]
++
TestName
"demotion opportunities, ignored too long)") (Property -> Property) -> Property -> Property
forall a b. (a -> b) -> a -> b
$
Int
-> ((Int, Set PeerAddr, Set PeerAddr, Set PeerAddr) -> TestName)
-> ((Int, Set PeerAddr, Set PeerAddr, Set PeerAddr) -> Bool)
-> Signal (Int, Set PeerAddr, Set PeerAddr, Set PeerAddr)
-> Property
forall a.
Int -> (a -> TestName) -> (a -> Bool) -> Signal a -> Property
signalProperty Int
20 (Int, Set PeerAddr, Set PeerAddr, Set PeerAddr) -> TestName
forall a. Show a => a -> TestName
show
(\(Int
_,Set PeerAddr
_,Set PeerAddr
_,Set PeerAddr
toolong) -> Set PeerAddr -> Bool
forall a. Set a -> Bool
Set.null Set PeerAddr
toolong)
((,,,) (Int
-> Set PeerAddr
-> Set PeerAddr
-> Set PeerAddr
-> (Int, Set PeerAddr, Set PeerAddr, Set PeerAddr))
-> Signal Int
-> Signal
(Set PeerAddr
-> Set PeerAddr
-> Set PeerAddr
-> (Int, Set PeerAddr, Set PeerAddr, Set PeerAddr))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Signal Int
govTargetsSig
Signal
(Set PeerAddr
-> Set PeerAddr
-> Set PeerAddr
-> (Int, Set PeerAddr, Set PeerAddr, Set PeerAddr))
-> Signal (Set PeerAddr)
-> Signal
(Set PeerAddr
-> Set PeerAddr -> (Int, Set PeerAddr, Set PeerAddr, Set PeerAddr))
forall a b. Signal (a -> b) -> Signal a -> Signal b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Signal (Set PeerAddr)
govActivePeersSig
Signal
(Set PeerAddr
-> Set PeerAddr -> (Int, Set PeerAddr, Set PeerAddr, Set PeerAddr))
-> Signal (Set PeerAddr)
-> Signal
(Set PeerAddr -> (Int, Set PeerAddr, Set PeerAddr, Set PeerAddr))
forall a b. Signal (a -> b) -> Signal a -> Signal b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Signal (Set PeerAddr)
demotionOpportunities
Signal
(Set PeerAddr -> (Int, Set PeerAddr, Set PeerAddr, Set PeerAddr))
-> Signal (Set PeerAddr)
-> Signal (Int, Set PeerAddr, Set PeerAddr, Set PeerAddr)
forall a b. Signal (a -> b) -> Signal a -> Signal b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Signal (Set PeerAddr)
demotionOpportunitiesIgnoredTooLong)
prop_governor_target_established_local :: MaxTime -> GovernorMockEnvironment -> Property
prop_governor_target_established_local :: MaxTime -> GovernorMockEnvironment -> Property
prop_governor_target_established_local (MaxTime Time
maxTime) GovernorMockEnvironment
env =
let events :: Events TestTraceEvent
events = Time -> [(Time, TestTraceEvent)] -> Events TestTraceEvent
forall a. Time -> [(Time, a)] -> Events a
Signal.eventsFromListUpToTime Time
maxTime
([(Time, TestTraceEvent)] -> Events TestTraceEvent)
-> (GovernorMockEnvironment -> [(Time, TestTraceEvent)])
-> GovernorMockEnvironment
-> Events TestTraceEvent
forall b c a. (b -> c) -> (a -> b) -> a -> c
. SimTrace Void -> [(Time, TestTraceEvent)]
forall a. SimTrace a -> [(Time, TestTraceEvent)]
selectPeerSelectionTraceEvents
(SimTrace Void -> [(Time, TestTraceEvent)])
-> (GovernorMockEnvironment -> SimTrace Void)
-> GovernorMockEnvironment
-> [(Time, TestTraceEvent)]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. GovernorMockEnvironment -> SimTrace Void
runGovernorInMockEnvironment
(GovernorMockEnvironment -> Events TestTraceEvent)
-> GovernorMockEnvironment -> Events TestTraceEvent
forall a b. (a -> b) -> a -> b
$ GovernorMockEnvironment
env
govLocalRootPeersSig :: Signal (LocalRootPeers PeerAddr)
govLocalRootPeersSig :: Signal (LocalRootPeers PeerAddr)
govLocalRootPeersSig =
(forall peerconn.
PeerSelectionState PeerAddr peerconn -> LocalRootPeers PeerAddr)
-> ConsensusMode
-> Events TestTraceEvent
-> Signal (LocalRootPeers PeerAddr)
forall a.
Eq a =>
(forall peerconn. PeerSelectionState PeerAddr peerconn -> a)
-> ConsensusMode -> Events TestTraceEvent -> Signal a
selectGovState PeerSelectionState PeerAddr peerconn -> LocalRootPeers PeerAddr
forall peerconn.
PeerSelectionState PeerAddr peerconn -> LocalRootPeers PeerAddr
forall peeraddr peerconn.
PeerSelectionState peeraddr peerconn -> LocalRootPeers peeraddr
Governor.localRootPeers
(GovernorMockEnvironment -> ConsensusMode
consensusMode GovernorMockEnvironment
env)
Events TestTraceEvent
events
govEstablishedPeersSig :: Signal (Set PeerAddr)
govEstablishedPeersSig :: Signal (Set PeerAddr)
govEstablishedPeersSig =
(forall peerconn.
PeerSelectionState PeerAddr peerconn -> Set PeerAddr)
-> ConsensusMode -> Events TestTraceEvent -> Signal (Set PeerAddr)
forall a.
Eq a =>
(forall peerconn. PeerSelectionState PeerAddr peerconn -> a)
-> ConsensusMode -> Events TestTraceEvent -> Signal a
selectGovState
(EstablishedPeers PeerAddr peerconn -> Set PeerAddr
forall peeraddr peerconn.
EstablishedPeers peeraddr peerconn -> Set peeraddr
EstablishedPeers.toSet (EstablishedPeers PeerAddr peerconn -> Set PeerAddr)
-> (PeerSelectionState PeerAddr peerconn
-> EstablishedPeers PeerAddr peerconn)
-> PeerSelectionState PeerAddr peerconn
-> Set PeerAddr
forall b c a. (b -> c) -> (a -> b) -> a -> c
. PeerSelectionState PeerAddr peerconn
-> EstablishedPeers PeerAddr peerconn
forall peeraddr peerconn.
PeerSelectionState peeraddr peerconn
-> EstablishedPeers peeraddr peerconn
Governor.establishedPeers)
(GovernorMockEnvironment -> ConsensusMode
consensusMode GovernorMockEnvironment
env)
Events TestTraceEvent
events
govInProgressPromoteColdSig :: Signal (Set PeerAddr)
govInProgressPromoteColdSig :: Signal (Set PeerAddr)
govInProgressPromoteColdSig =
(forall peerconn.
PeerSelectionState PeerAddr peerconn -> Set PeerAddr)
-> ConsensusMode -> Events TestTraceEvent -> Signal (Set PeerAddr)
forall a.
Eq a =>
(forall peerconn. PeerSelectionState PeerAddr peerconn -> a)
-> ConsensusMode -> Events TestTraceEvent -> Signal a
selectGovState
PeerSelectionState PeerAddr peerconn -> Set PeerAddr
forall peerconn.
PeerSelectionState PeerAddr peerconn -> Set PeerAddr
forall peeraddr peerconn.
PeerSelectionState peeraddr peerconn -> Set peeraddr
Governor.inProgressPromoteCold
(GovernorMockEnvironment -> ConsensusMode
consensusMode GovernorMockEnvironment
env)
Events TestTraceEvent
events
govEstablishedFailuresSig :: Signal (Set PeerAddr)
govEstablishedFailuresSig :: Signal (Set PeerAddr)
govEstablishedFailuresSig =
DiffTime
-> (Maybe (Set PeerAddr) -> Set PeerAddr)
-> Signal (Maybe (Set PeerAddr))
-> Signal (Set PeerAddr)
forall a b.
Ord b =>
DiffTime -> (a -> Set b) -> Signal a -> Signal (Set b)
Signal.keyedLinger
DiffTime
180
(Set PeerAddr -> Maybe (Set PeerAddr) -> Set PeerAddr
forall a. a -> Maybe a -> a
fromMaybe Set PeerAddr
forall a. Set a
Set.empty)
(Signal (Maybe (Set PeerAddr)) -> Signal (Set PeerAddr))
-> (Events TestTraceEvent -> Signal (Maybe (Set PeerAddr)))
-> Events TestTraceEvent
-> Signal (Set PeerAddr)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Events (Set PeerAddr) -> Signal (Maybe (Set PeerAddr))
forall a. Events a -> Signal (Maybe a)
Signal.fromEvents
(Events (Set PeerAddr) -> Signal (Maybe (Set PeerAddr)))
-> (Events TestTraceEvent -> Events (Set PeerAddr))
-> Events TestTraceEvent
-> Signal (Maybe (Set PeerAddr))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (TracePeerSelection PeerAddr -> Maybe (Set PeerAddr))
-> Events (TracePeerSelection PeerAddr) -> Events (Set PeerAddr)
forall a b. (a -> Maybe b) -> Events a -> Events b
Signal.selectEvents
(\case TracePromoteColdFailed Int
_ Int
_ PeerAddr
peer DiffTime
_ SomeException
_ ->
Set PeerAddr -> Maybe (Set PeerAddr)
forall a. a -> Maybe a
Just (PeerAddr -> Set PeerAddr
forall a. a -> Set a
Set.singleton PeerAddr
peer)
TraceDemoteAsynchronous Map PeerAddr (PeerStatus, Maybe RepromoteDelay)
status
| Set PeerAddr -> Bool
forall a. Set a -> Bool
Set.null Set PeerAddr
failures -> Maybe (Set PeerAddr)
forall a. Maybe a
Nothing
| Bool
otherwise -> Set PeerAddr -> Maybe (Set PeerAddr)
forall a. a -> Maybe a
Just Set PeerAddr
failures
where
failures :: Set PeerAddr
failures = Map PeerAddr PeerStatus -> Set PeerAddr
forall k a. Map k a -> Set k
Map.keysSet ((PeerStatus -> Bool)
-> Map PeerAddr PeerStatus -> Map PeerAddr PeerStatus
forall a k. (a -> Bool) -> Map k a -> Map k a
Map.filter (PeerStatus -> PeerStatus -> Bool
forall a. Eq a => a -> a -> Bool
==PeerStatus
PeerCooling) (Map PeerAddr PeerStatus -> Map PeerAddr PeerStatus)
-> (Map PeerAddr (PeerStatus, Maybe RepromoteDelay)
-> Map PeerAddr PeerStatus)
-> Map PeerAddr (PeerStatus, Maybe RepromoteDelay)
-> Map PeerAddr PeerStatus
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ((PeerStatus, Maybe RepromoteDelay) -> PeerStatus)
-> Map PeerAddr (PeerStatus, Maybe RepromoteDelay)
-> Map PeerAddr PeerStatus
forall a b. (a -> b) -> Map PeerAddr a -> Map PeerAddr b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (PeerStatus, Maybe RepromoteDelay) -> PeerStatus
forall a b. (a, b) -> a
fst (Map PeerAddr (PeerStatus, Maybe RepromoteDelay)
-> Map PeerAddr PeerStatus)
-> Map PeerAddr (PeerStatus, Maybe RepromoteDelay)
-> Map PeerAddr PeerStatus
forall a b. (a -> b) -> a -> b
$ Map PeerAddr (PeerStatus, Maybe RepromoteDelay)
status)
TraceDemoteLocalAsynchronous Map PeerAddr (PeerStatus, Maybe RepromoteDelay)
status
| Set PeerAddr -> Bool
forall a. Set a -> Bool
Set.null Set PeerAddr
failures -> Maybe (Set PeerAddr)
forall a. Maybe a
Nothing
| Bool
otherwise -> Set PeerAddr -> Maybe (Set PeerAddr)
forall a. a -> Maybe a
Just Set PeerAddr
failures
where
failures :: Set PeerAddr
failures = Map PeerAddr PeerStatus -> Set PeerAddr
forall k a. Map k a -> Set k
Map.keysSet ((PeerStatus -> Bool)
-> Map PeerAddr PeerStatus -> Map PeerAddr PeerStatus
forall a k. (a -> Bool) -> Map k a -> Map k a
Map.filter (PeerStatus -> PeerStatus -> Bool
forall a. Eq a => a -> a -> Bool
==PeerStatus
PeerCooling) (Map PeerAddr PeerStatus -> Map PeerAddr PeerStatus)
-> (Map PeerAddr (PeerStatus, Maybe RepromoteDelay)
-> Map PeerAddr PeerStatus)
-> Map PeerAddr (PeerStatus, Maybe RepromoteDelay)
-> Map PeerAddr PeerStatus
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ((PeerStatus, Maybe RepromoteDelay) -> PeerStatus)
-> Map PeerAddr (PeerStatus, Maybe RepromoteDelay)
-> Map PeerAddr PeerStatus
forall a b. (a -> b) -> Map PeerAddr a -> Map PeerAddr b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (PeerStatus, Maybe RepromoteDelay) -> PeerStatus
forall a b. (a, b) -> a
fst (Map PeerAddr (PeerStatus, Maybe RepromoteDelay)
-> Map PeerAddr PeerStatus)
-> Map PeerAddr (PeerStatus, Maybe RepromoteDelay)
-> Map PeerAddr PeerStatus
forall a b. (a -> b) -> a -> b
$ Map PeerAddr (PeerStatus, Maybe RepromoteDelay)
status)
TracePromoteWarmFailed Int
_ Int
_ PeerAddr
peer SomeException
_ ->
Set PeerAddr -> Maybe (Set PeerAddr)
forall a. a -> Maybe a
Just (PeerAddr -> Set PeerAddr
forall a. a -> Set a
Set.singleton PeerAddr
peer)
TracePeerSelection PeerAddr
_ -> Maybe (Set PeerAddr)
forall a. Maybe a
Nothing
)
(Events (TracePeerSelection PeerAddr) -> Events (Set PeerAddr))
-> (Events TestTraceEvent -> Events (TracePeerSelection PeerAddr))
-> Events TestTraceEvent
-> Events (Set PeerAddr)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Events TestTraceEvent -> Events (TracePeerSelection PeerAddr)
selectGovEvents
(Events TestTraceEvent -> Signal (Set PeerAddr))
-> Events TestTraceEvent -> Signal (Set PeerAddr)
forall a b. (a -> b) -> a -> b
$ Events TestTraceEvent
events
promotionOpportunities :: Signal (Set PeerAddr)
promotionOpportunities :: Signal (Set PeerAddr)
promotionOpportunities =
(\LocalRootPeers PeerAddr
local Set PeerAddr
established Set PeerAddr
recentFailures Set PeerAddr
inProgressPromoteCold ->
[Set PeerAddr] -> Set PeerAddr
forall (f :: * -> *) a. (Foldable f, Ord a) => f (Set a) -> Set a
Set.unions
[
if Set PeerAddr -> Int
forall a. Set a -> Int
Set.size Set PeerAddr
groupEstablished Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
>= Int
warmTarget'
then Set PeerAddr
forall a. Set a
Set.empty
else Set PeerAddr
group Set PeerAddr -> Set PeerAddr -> Set PeerAddr
forall a. Ord a => Set a -> Set a -> Set a
Set.\\ Set PeerAddr
established
Set PeerAddr -> Set PeerAddr -> Set PeerAddr
forall a. Ord a => Set a -> Set a -> Set a
Set.\\ Set PeerAddr
recentFailures
Set PeerAddr -> Set PeerAddr -> Set PeerAddr
forall a. Ord a => Set a -> Set a -> Set a
Set.\\ Set PeerAddr
inProgressPromoteCold
| (HotValency
_, WarmValency Int
warmTarget', Set PeerAddr
group) <- LocalRootPeers PeerAddr
-> [(HotValency, WarmValency, Set PeerAddr)]
forall peeraddr.
LocalRootPeers peeraddr
-> [(HotValency, WarmValency, Set peeraddr)]
LocalRootPeers.toGroupSets LocalRootPeers PeerAddr
local
, let groupEstablished :: Set PeerAddr
groupEstablished = Set PeerAddr
group Set PeerAddr -> Set PeerAddr -> Set PeerAddr
forall a. Ord a => Set a -> Set a -> Set a
`Set.intersection` Set PeerAddr
established
]
) (LocalRootPeers PeerAddr
-> Set PeerAddr -> Set PeerAddr -> Set PeerAddr -> Set PeerAddr)
-> Signal (LocalRootPeers PeerAddr)
-> Signal
(Set PeerAddr -> Set PeerAddr -> Set PeerAddr -> Set PeerAddr)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Signal (LocalRootPeers PeerAddr)
govLocalRootPeersSig
Signal
(Set PeerAddr -> Set PeerAddr -> Set PeerAddr -> Set PeerAddr)
-> Signal (Set PeerAddr)
-> Signal (Set PeerAddr -> Set PeerAddr -> Set PeerAddr)
forall a b. Signal (a -> b) -> Signal a -> Signal b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Signal (Set PeerAddr)
govEstablishedPeersSig
Signal (Set PeerAddr -> Set PeerAddr -> Set PeerAddr)
-> Signal (Set PeerAddr) -> Signal (Set PeerAddr -> Set PeerAddr)
forall a b. Signal (a -> b) -> Signal a -> Signal b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Signal (Set PeerAddr)
govEstablishedFailuresSig
Signal (Set PeerAddr -> Set PeerAddr)
-> Signal (Set PeerAddr) -> Signal (Set PeerAddr)
forall a b. Signal (a -> b) -> Signal a -> Signal b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Signal (Set PeerAddr)
govInProgressPromoteColdSig
promotionOpportunitiesIgnoredTooLong :: Signal (Set PeerAddr)
promotionOpportunitiesIgnoredTooLong :: Signal (Set PeerAddr)
promotionOpportunitiesIgnoredTooLong =
DiffTime
-> (Set PeerAddr -> Set PeerAddr)
-> Signal (Set PeerAddr)
-> Signal (Set PeerAddr)
forall a b.
Ord b =>
DiffTime -> (a -> Set b) -> Signal a -> Signal (Set b)
Signal.keyedTimeout
DiffTime
15
Set PeerAddr -> Set PeerAddr
forall a. a -> a
id
Signal (Set PeerAddr)
promotionOpportunities
in TestName -> Property -> Property
forall prop. Testable prop => TestName -> prop -> Property
counterexample
(TestName
"\nSignal key: (local root peers, established peers, " TestName -> TestName -> TestName
forall a. [a] -> [a] -> [a]
++
TestName
"recent failures, opportunities, ignored too long)") (Property -> Property) -> Property -> Property
forall a b. (a -> b) -> a -> b
$
Int
-> ((LocalRootPeers PeerAddr, Set PeerAddr, Set PeerAddr,
Set PeerAddr, Set PeerAddr, Set PeerAddr)
-> TestName)
-> ((LocalRootPeers PeerAddr, Set PeerAddr, Set PeerAddr,
Set PeerAddr, Set PeerAddr, Set PeerAddr)
-> Bool)
-> Signal
(LocalRootPeers PeerAddr, Set PeerAddr, Set PeerAddr, Set PeerAddr,
Set PeerAddr, Set PeerAddr)
-> Property
forall a.
Int -> (a -> TestName) -> (a -> Bool) -> Signal a -> Property
signalProperty Int
20 (LocalRootPeers PeerAddr, Set PeerAddr, Set PeerAddr, Set PeerAddr,
Set PeerAddr, Set PeerAddr)
-> TestName
forall a. Show a => a -> TestName
show
(\(LocalRootPeers PeerAddr
_,Set PeerAddr
_,Set PeerAddr
_,Set PeerAddr
_,Set PeerAddr
_,Set PeerAddr
toolong) -> Set PeerAddr -> Bool
forall a. Set a -> Bool
Set.null Set PeerAddr
toolong)
((,,,,,) (LocalRootPeers PeerAddr
-> Set PeerAddr
-> Set PeerAddr
-> Set PeerAddr
-> Set PeerAddr
-> Set PeerAddr
-> (LocalRootPeers PeerAddr, Set PeerAddr, Set PeerAddr,
Set PeerAddr, Set PeerAddr, Set PeerAddr))
-> Signal (LocalRootPeers PeerAddr)
-> Signal
(Set PeerAddr
-> Set PeerAddr
-> Set PeerAddr
-> Set PeerAddr
-> Set PeerAddr
-> (LocalRootPeers PeerAddr, Set PeerAddr, Set PeerAddr,
Set PeerAddr, Set PeerAddr, Set PeerAddr))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Signal (LocalRootPeers PeerAddr)
govLocalRootPeersSig
Signal
(Set PeerAddr
-> Set PeerAddr
-> Set PeerAddr
-> Set PeerAddr
-> Set PeerAddr
-> (LocalRootPeers PeerAddr, Set PeerAddr, Set PeerAddr,
Set PeerAddr, Set PeerAddr, Set PeerAddr))
-> Signal (Set PeerAddr)
-> Signal
(Set PeerAddr
-> Set PeerAddr
-> Set PeerAddr
-> Set PeerAddr
-> (LocalRootPeers PeerAddr, Set PeerAddr, Set PeerAddr,
Set PeerAddr, Set PeerAddr, Set PeerAddr))
forall a b. Signal (a -> b) -> Signal a -> Signal b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Signal (Set PeerAddr)
govEstablishedPeersSig
Signal
(Set PeerAddr
-> Set PeerAddr
-> Set PeerAddr
-> Set PeerAddr
-> (LocalRootPeers PeerAddr, Set PeerAddr, Set PeerAddr,
Set PeerAddr, Set PeerAddr, Set PeerAddr))
-> Signal (Set PeerAddr)
-> Signal
(Set PeerAddr
-> Set PeerAddr
-> Set PeerAddr
-> (LocalRootPeers PeerAddr, Set PeerAddr, Set PeerAddr,
Set PeerAddr, Set PeerAddr, Set PeerAddr))
forall a b. Signal (a -> b) -> Signal a -> Signal b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Signal (Set PeerAddr)
govEstablishedFailuresSig
Signal
(Set PeerAddr
-> Set PeerAddr
-> Set PeerAddr
-> (LocalRootPeers PeerAddr, Set PeerAddr, Set PeerAddr,
Set PeerAddr, Set PeerAddr, Set PeerAddr))
-> Signal (Set PeerAddr)
-> Signal
(Set PeerAddr
-> Set PeerAddr
-> (LocalRootPeers PeerAddr, Set PeerAddr, Set PeerAddr,
Set PeerAddr, Set PeerAddr, Set PeerAddr))
forall a b. Signal (a -> b) -> Signal a -> Signal b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Signal (Set PeerAddr)
govInProgressPromoteColdSig
Signal
(Set PeerAddr
-> Set PeerAddr
-> (LocalRootPeers PeerAddr, Set PeerAddr, Set PeerAddr,
Set PeerAddr, Set PeerAddr, Set PeerAddr))
-> Signal (Set PeerAddr)
-> Signal
(Set PeerAddr
-> (LocalRootPeers PeerAddr, Set PeerAddr, Set PeerAddr,
Set PeerAddr, Set PeerAddr, Set PeerAddr))
forall a b. Signal (a -> b) -> Signal a -> Signal b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Signal (Set PeerAddr)
promotionOpportunities
Signal
(Set PeerAddr
-> (LocalRootPeers PeerAddr, Set PeerAddr, Set PeerAddr,
Set PeerAddr, Set PeerAddr, Set PeerAddr))
-> Signal (Set PeerAddr)
-> Signal
(LocalRootPeers PeerAddr, Set PeerAddr, Set PeerAddr, Set PeerAddr,
Set PeerAddr, Set PeerAddr)
forall a b. Signal (a -> b) -> Signal a -> Signal b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Signal (Set PeerAddr)
promotionOpportunitiesIgnoredTooLong)
prop_governor_target_active_local_below :: MaxTime -> GovernorMockEnvironment -> Property
prop_governor_target_active_local_below :: MaxTime -> GovernorMockEnvironment -> Property
prop_governor_target_active_local_below (MaxTime Time
maxTime) GovernorMockEnvironment
env =
let events :: Events TestTraceEvent
events = Time -> [(Time, TestTraceEvent)] -> Events TestTraceEvent
forall a. Time -> [(Time, a)] -> Events a
Signal.eventsFromListUpToTime Time
maxTime
([(Time, TestTraceEvent)] -> Events TestTraceEvent)
-> (GovernorMockEnvironment -> [(Time, TestTraceEvent)])
-> GovernorMockEnvironment
-> Events TestTraceEvent
forall b c a. (b -> c) -> (a -> b) -> a -> c
. SimTrace Void -> [(Time, TestTraceEvent)]
forall a. SimTrace a -> [(Time, TestTraceEvent)]
selectPeerSelectionTraceEvents
(SimTrace Void -> [(Time, TestTraceEvent)])
-> (GovernorMockEnvironment -> SimTrace Void)
-> GovernorMockEnvironment
-> [(Time, TestTraceEvent)]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. GovernorMockEnvironment -> SimTrace Void
runGovernorInMockEnvironment
(GovernorMockEnvironment -> Events TestTraceEvent)
-> GovernorMockEnvironment -> Events TestTraceEvent
forall a b. (a -> b) -> a -> b
$ GovernorMockEnvironment
env
govLocalRootPeersSig :: Signal (LocalRootPeers.LocalRootPeers PeerAddr)
govLocalRootPeersSig :: Signal (LocalRootPeers PeerAddr)
govLocalRootPeersSig =
(forall peerconn.
PeerSelectionState PeerAddr peerconn -> LocalRootPeers PeerAddr)
-> ConsensusMode
-> Events TestTraceEvent
-> Signal (LocalRootPeers PeerAddr)
forall a.
Eq a =>
(forall peerconn. PeerSelectionState PeerAddr peerconn -> a)
-> ConsensusMode -> Events TestTraceEvent -> Signal a
selectGovState PeerSelectionState PeerAddr peerconn -> LocalRootPeers PeerAddr
forall peerconn.
PeerSelectionState PeerAddr peerconn -> LocalRootPeers PeerAddr
forall peeraddr peerconn.
PeerSelectionState peeraddr peerconn -> LocalRootPeers peeraddr
Governor.localRootPeers
(GovernorMockEnvironment -> ConsensusMode
consensusMode GovernorMockEnvironment
env)
Events TestTraceEvent
events
govEstablishedPeersSig :: Signal (Set PeerAddr)
govEstablishedPeersSig :: Signal (Set PeerAddr)
govEstablishedPeersSig =
(forall peerconn.
PeerSelectionState PeerAddr peerconn -> Set PeerAddr)
-> ConsensusMode -> Events TestTraceEvent -> Signal (Set PeerAddr)
forall a.
Eq a =>
(forall peerconn. PeerSelectionState PeerAddr peerconn -> a)
-> ConsensusMode -> Events TestTraceEvent -> Signal a
selectGovState
(EstablishedPeers PeerAddr peerconn -> Set PeerAddr
forall peeraddr peerconn.
EstablishedPeers peeraddr peerconn -> Set peeraddr
EstablishedPeers.toSet (EstablishedPeers PeerAddr peerconn -> Set PeerAddr)
-> (PeerSelectionState PeerAddr peerconn
-> EstablishedPeers PeerAddr peerconn)
-> PeerSelectionState PeerAddr peerconn
-> Set PeerAddr
forall b c a. (b -> c) -> (a -> b) -> a -> c
. PeerSelectionState PeerAddr peerconn
-> EstablishedPeers PeerAddr peerconn
forall peeraddr peerconn.
PeerSelectionState peeraddr peerconn
-> EstablishedPeers peeraddr peerconn
Governor.establishedPeers)
(GovernorMockEnvironment -> ConsensusMode
consensusMode GovernorMockEnvironment
env)
Events TestTraceEvent
events
govActivePeersSig :: Signal (Set PeerAddr)
govActivePeersSig :: Signal (Set PeerAddr)
govActivePeersSig =
(forall peerconn.
PeerSelectionState PeerAddr peerconn -> Set PeerAddr)
-> ConsensusMode -> Events TestTraceEvent -> Signal (Set PeerAddr)
forall a.
Eq a =>
(forall peerconn. PeerSelectionState PeerAddr peerconn -> a)
-> ConsensusMode -> Events TestTraceEvent -> Signal a
selectGovState PeerSelectionState PeerAddr peerconn -> Set PeerAddr
forall peerconn.
PeerSelectionState PeerAddr peerconn -> Set PeerAddr
forall peeraddr peerconn.
PeerSelectionState peeraddr peerconn -> Set peeraddr
Governor.activePeers (GovernorMockEnvironment -> ConsensusMode
consensusMode GovernorMockEnvironment
env) Events TestTraceEvent
events
govInProgressDemoteToColdSig :: Signal (Set PeerAddr)
govInProgressDemoteToColdSig :: Signal (Set PeerAddr)
govInProgressDemoteToColdSig =
(forall peerconn.
PeerSelectionState PeerAddr peerconn -> Set PeerAddr)
-> ConsensusMode -> Events TestTraceEvent -> Signal (Set PeerAddr)
forall a.
Eq a =>
(forall peerconn. PeerSelectionState PeerAddr peerconn -> a)
-> ConsensusMode -> Events TestTraceEvent -> Signal a
selectGovState PeerSelectionState PeerAddr peerconn -> Set PeerAddr
forall peerconn.
PeerSelectionState PeerAddr peerconn -> Set PeerAddr
forall peeraddr peerconn.
PeerSelectionState peeraddr peerconn -> Set peeraddr
Governor.inProgressDemoteToCold
(GovernorMockEnvironment -> ConsensusMode
consensusMode GovernorMockEnvironment
env)
Events TestTraceEvent
events
govActiveFailuresSig :: Signal (Set PeerAddr)
govActiveFailuresSig :: Signal (Set PeerAddr)
govActiveFailuresSig =
DiffTime
-> (Maybe (Set PeerAddr) -> Set PeerAddr)
-> Signal (Maybe (Set PeerAddr))
-> Signal (Set PeerAddr)
forall a b.
Ord b =>
DiffTime -> (a -> Set b) -> Signal a -> Signal (Set b)
Signal.keyedLinger
DiffTime
180
(Set PeerAddr -> Maybe (Set PeerAddr) -> Set PeerAddr
forall a. a -> Maybe a -> a
fromMaybe Set PeerAddr
forall a. Set a
Set.empty)
(Signal (Maybe (Set PeerAddr)) -> Signal (Set PeerAddr))
-> (Events TestTraceEvent -> Signal (Maybe (Set PeerAddr)))
-> Events TestTraceEvent
-> Signal (Set PeerAddr)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Events (Set PeerAddr) -> Signal (Maybe (Set PeerAddr))
forall a. Events a -> Signal (Maybe a)
Signal.fromEvents
(Events (Set PeerAddr) -> Signal (Maybe (Set PeerAddr)))
-> (Events TestTraceEvent -> Events (Set PeerAddr))
-> Events TestTraceEvent
-> Signal (Maybe (Set PeerAddr))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (TracePeerSelection PeerAddr -> Maybe (Set PeerAddr))
-> Events (TracePeerSelection PeerAddr) -> Events (Set PeerAddr)
forall a b. (a -> Maybe b) -> Events a -> Events b
Signal.selectEvents
(\case TracePromoteWarmFailed Int
_ Int
_ PeerAddr
peer SomeException
_ ->
Set PeerAddr -> Maybe (Set PeerAddr)
forall a. a -> Maybe a
Just (PeerAddr -> Set PeerAddr
forall a. a -> Set a
Set.singleton PeerAddr
peer)
TraceDemoteAsynchronous Map PeerAddr (PeerStatus, Maybe RepromoteDelay)
status
| Set PeerAddr -> Bool
forall a. Set a -> Bool
Set.null Set PeerAddr
failures -> Maybe (Set PeerAddr)
forall a. Maybe a
Nothing
| Bool
otherwise -> Set PeerAddr -> Maybe (Set PeerAddr)
forall a. a -> Maybe a
Just Set PeerAddr
failures
where
failures :: Set PeerAddr
failures = Map PeerAddr PeerStatus -> Set PeerAddr
forall k a. Map k a -> Set k
Map.keysSet ((PeerStatus -> Bool)
-> Map PeerAddr PeerStatus -> Map PeerAddr PeerStatus
forall a k. (a -> Bool) -> Map k a -> Map k a
Map.filter (PeerStatus -> PeerStatus -> Bool
forall a. Eq a => a -> a -> Bool
==PeerStatus
PeerWarm) (Map PeerAddr PeerStatus -> Map PeerAddr PeerStatus)
-> (Map PeerAddr (PeerStatus, Maybe RepromoteDelay)
-> Map PeerAddr PeerStatus)
-> Map PeerAddr (PeerStatus, Maybe RepromoteDelay)
-> Map PeerAddr PeerStatus
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ((PeerStatus, Maybe RepromoteDelay) -> PeerStatus)
-> Map PeerAddr (PeerStatus, Maybe RepromoteDelay)
-> Map PeerAddr PeerStatus
forall a b. (a -> b) -> Map PeerAddr a -> Map PeerAddr b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (PeerStatus, Maybe RepromoteDelay) -> PeerStatus
forall a b. (a, b) -> a
fst (Map PeerAddr (PeerStatus, Maybe RepromoteDelay)
-> Map PeerAddr PeerStatus)
-> Map PeerAddr (PeerStatus, Maybe RepromoteDelay)
-> Map PeerAddr PeerStatus
forall a b. (a -> b) -> a -> b
$ Map PeerAddr (PeerStatus, Maybe RepromoteDelay)
status)
TraceDemoteLocalAsynchronous Map PeerAddr (PeerStatus, Maybe RepromoteDelay)
status
| Set PeerAddr -> Bool
forall a. Set a -> Bool
Set.null Set PeerAddr
failures -> Maybe (Set PeerAddr)
forall a. Maybe a
Nothing
| Bool
otherwise -> Set PeerAddr -> Maybe (Set PeerAddr)
forall a. a -> Maybe a
Just Set PeerAddr
failures
where
failures :: Set PeerAddr
failures = Map PeerAddr PeerStatus -> Set PeerAddr
forall k a. Map k a -> Set k
Map.keysSet ((PeerStatus -> Bool)
-> Map PeerAddr PeerStatus -> Map PeerAddr PeerStatus
forall a k. (a -> Bool) -> Map k a -> Map k a
Map.filter (PeerStatus -> PeerStatus -> Bool
forall a. Eq a => a -> a -> Bool
==PeerStatus
PeerWarm) (Map PeerAddr PeerStatus -> Map PeerAddr PeerStatus)
-> (Map PeerAddr (PeerStatus, Maybe RepromoteDelay)
-> Map PeerAddr PeerStatus)
-> Map PeerAddr (PeerStatus, Maybe RepromoteDelay)
-> Map PeerAddr PeerStatus
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ((PeerStatus, Maybe RepromoteDelay) -> PeerStatus)
-> Map PeerAddr (PeerStatus, Maybe RepromoteDelay)
-> Map PeerAddr PeerStatus
forall a b. (a -> b) -> Map PeerAddr a -> Map PeerAddr b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (PeerStatus, Maybe RepromoteDelay) -> PeerStatus
forall a b. (a, b) -> a
fst (Map PeerAddr (PeerStatus, Maybe RepromoteDelay)
-> Map PeerAddr PeerStatus)
-> Map PeerAddr (PeerStatus, Maybe RepromoteDelay)
-> Map PeerAddr PeerStatus
forall a b. (a -> b) -> a -> b
$ Map PeerAddr (PeerStatus, Maybe RepromoteDelay)
status)
TracePeerSelection PeerAddr
_ -> Maybe (Set PeerAddr)
forall a. Maybe a
Nothing
)
(Events (TracePeerSelection PeerAddr) -> Events (Set PeerAddr))
-> (Events TestTraceEvent -> Events (TracePeerSelection PeerAddr))
-> Events TestTraceEvent
-> Events (Set PeerAddr)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Events TestTraceEvent -> Events (TracePeerSelection PeerAddr)
selectGovEvents
(Events TestTraceEvent -> Signal (Set PeerAddr))
-> Events TestTraceEvent -> Signal (Set PeerAddr)
forall a b. (a -> b) -> a -> b
$ Events TestTraceEvent
events
promotionOpportunities :: Signal (Set PeerAddr)
promotionOpportunities :: Signal (Set PeerAddr)
promotionOpportunities =
(\LocalRootPeers PeerAddr
local Set PeerAddr
established Set PeerAddr
active Set PeerAddr
recentFailures Set PeerAddr
inProgressDemoteToCold ->
[Set PeerAddr] -> Set PeerAddr
forall (f :: * -> *) a. (Foldable f, Ord a) => f (Set a) -> Set a
Set.unions
[
if Set PeerAddr -> Int
forall a. Set a -> Int
Set.size Set PeerAddr
groupActive Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
>= Int
hotTarget'
then Set PeerAddr
forall a. Set a
Set.empty
else Set PeerAddr
groupEstablished Set PeerAddr -> Set PeerAddr -> Set PeerAddr
forall a. Ord a => Set a -> Set a -> Set a
Set.\\ Set PeerAddr
active
Set PeerAddr -> Set PeerAddr -> Set PeerAddr
forall a. Ord a => Set a -> Set a -> Set a
Set.\\ Set PeerAddr
recentFailures
Set PeerAddr -> Set PeerAddr -> Set PeerAddr
forall a. Ord a => Set a -> Set a -> Set a
Set.\\ Set PeerAddr
inProgressDemoteToCold
| (HotValency Int
hotTarget', WarmValency
_, Set PeerAddr
group) <- LocalRootPeers PeerAddr
-> [(HotValency, WarmValency, Set PeerAddr)]
forall peeraddr.
LocalRootPeers peeraddr
-> [(HotValency, WarmValency, Set peeraddr)]
LocalRootPeers.toGroupSets LocalRootPeers PeerAddr
local
, let groupActive :: Set PeerAddr
groupActive = Set PeerAddr
group Set PeerAddr -> Set PeerAddr -> Set PeerAddr
forall a. Ord a => Set a -> Set a -> Set a
`Set.intersection` Set PeerAddr
active
groupEstablished :: Set PeerAddr
groupEstablished = Set PeerAddr
group Set PeerAddr -> Set PeerAddr -> Set PeerAddr
forall a. Ord a => Set a -> Set a -> Set a
`Set.intersection` Set PeerAddr
established
]
) (LocalRootPeers PeerAddr
-> Set PeerAddr
-> Set PeerAddr
-> Set PeerAddr
-> Set PeerAddr
-> Set PeerAddr)
-> Signal (LocalRootPeers PeerAddr)
-> Signal
(Set PeerAddr
-> Set PeerAddr -> Set PeerAddr -> Set PeerAddr -> Set PeerAddr)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Signal (LocalRootPeers PeerAddr)
govLocalRootPeersSig
Signal
(Set PeerAddr
-> Set PeerAddr -> Set PeerAddr -> Set PeerAddr -> Set PeerAddr)
-> Signal (Set PeerAddr)
-> Signal
(Set PeerAddr -> Set PeerAddr -> Set PeerAddr -> Set PeerAddr)
forall a b. Signal (a -> b) -> Signal a -> Signal b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Signal (Set PeerAddr)
govEstablishedPeersSig
Signal
(Set PeerAddr -> Set PeerAddr -> Set PeerAddr -> Set PeerAddr)
-> Signal (Set PeerAddr)
-> Signal (Set PeerAddr -> Set PeerAddr -> Set PeerAddr)
forall a b. Signal (a -> b) -> Signal a -> Signal b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Signal (Set PeerAddr)
govActivePeersSig
Signal (Set PeerAddr -> Set PeerAddr -> Set PeerAddr)
-> Signal (Set PeerAddr) -> Signal (Set PeerAddr -> Set PeerAddr)
forall a b. Signal (a -> b) -> Signal a -> Signal b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Signal (Set PeerAddr)
govActiveFailuresSig
Signal (Set PeerAddr -> Set PeerAddr)
-> Signal (Set PeerAddr) -> Signal (Set PeerAddr)
forall a b. Signal (a -> b) -> Signal a -> Signal b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Signal (Set PeerAddr)
govInProgressDemoteToColdSig
promotionOpportunitiesIgnoredTooLong :: Signal (Set PeerAddr)
promotionOpportunitiesIgnoredTooLong :: Signal (Set PeerAddr)
promotionOpportunitiesIgnoredTooLong =
DiffTime
-> (Set PeerAddr -> Set PeerAddr)
-> Signal (Set PeerAddr)
-> Signal (Set PeerAddr)
forall a b.
Ord b =>
DiffTime -> (a -> Set b) -> Signal a -> Signal (Set b)
Signal.keyedTimeout
(RepromoteDelay -> DiffTime
repromoteDelay RepromoteDelay
config_REPROMOTE_DELAY DiffTime -> DiffTime -> DiffTime
forall a. Num a => a -> a -> a
+ DiffTime
20)
Set PeerAddr -> Set PeerAddr
forall a. a -> a
id
Signal (Set PeerAddr)
promotionOpportunities
in TestName -> Property -> Property
forall prop. Testable prop => TestName -> prop -> Property
counterexample
(TestName
"\nSignal key: (local, established peers, active peers, " TestName -> TestName -> TestName
forall a. [a] -> [a] -> [a]
++
TestName
"recent failures, opportunities, ignored too long)") (Property -> Property) -> Property -> Property
forall a b. (a -> b) -> a -> b
$
Int
-> (([(HotValency, WarmValency, Set PeerAddr)], Set PeerAddr,
Set PeerAddr, Set PeerAddr, Set PeerAddr, Set PeerAddr)
-> TestName)
-> (([(HotValency, WarmValency, Set PeerAddr)], Set PeerAddr,
Set PeerAddr, Set PeerAddr, Set PeerAddr, Set PeerAddr)
-> Bool)
-> Signal
([(HotValency, WarmValency, Set PeerAddr)], Set PeerAddr,
Set PeerAddr, Set PeerAddr, Set PeerAddr, Set PeerAddr)
-> Property
forall a.
Int -> (a -> TestName) -> (a -> Bool) -> Signal a -> Property
signalProperty Int
20 ([(HotValency, WarmValency, Set PeerAddr)], Set PeerAddr,
Set PeerAddr, Set PeerAddr, Set PeerAddr, Set PeerAddr)
-> TestName
forall a. Show a => a -> TestName
show
(\([(HotValency, WarmValency, Set PeerAddr)]
_,Set PeerAddr
_,Set PeerAddr
_,Set PeerAddr
_,Set PeerAddr
_,Set PeerAddr
toolong) -> Set PeerAddr -> Bool
forall a. Set a -> Bool
Set.null Set PeerAddr
toolong)
((,,,,,) ([(HotValency, WarmValency, Set PeerAddr)]
-> Set PeerAddr
-> Set PeerAddr
-> Set PeerAddr
-> Set PeerAddr
-> Set PeerAddr
-> ([(HotValency, WarmValency, Set PeerAddr)], Set PeerAddr,
Set PeerAddr, Set PeerAddr, Set PeerAddr, Set PeerAddr))
-> Signal [(HotValency, WarmValency, Set PeerAddr)]
-> Signal
(Set PeerAddr
-> Set PeerAddr
-> Set PeerAddr
-> Set PeerAddr
-> Set PeerAddr
-> ([(HotValency, WarmValency, Set PeerAddr)], Set PeerAddr,
Set PeerAddr, Set PeerAddr, Set PeerAddr, Set PeerAddr))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (LocalRootPeers PeerAddr
-> [(HotValency, WarmValency, Set PeerAddr)]
forall peeraddr.
LocalRootPeers peeraddr
-> [(HotValency, WarmValency, Set peeraddr)]
LocalRootPeers.toGroupSets (LocalRootPeers PeerAddr
-> [(HotValency, WarmValency, Set PeerAddr)])
-> Signal (LocalRootPeers PeerAddr)
-> Signal [(HotValency, WarmValency, Set PeerAddr)]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Signal (LocalRootPeers PeerAddr)
govLocalRootPeersSig)
Signal
(Set PeerAddr
-> Set PeerAddr
-> Set PeerAddr
-> Set PeerAddr
-> Set PeerAddr
-> ([(HotValency, WarmValency, Set PeerAddr)], Set PeerAddr,
Set PeerAddr, Set PeerAddr, Set PeerAddr, Set PeerAddr))
-> Signal (Set PeerAddr)
-> Signal
(Set PeerAddr
-> Set PeerAddr
-> Set PeerAddr
-> Set PeerAddr
-> ([(HotValency, WarmValency, Set PeerAddr)], Set PeerAddr,
Set PeerAddr, Set PeerAddr, Set PeerAddr, Set PeerAddr))
forall a b. Signal (a -> b) -> Signal a -> Signal b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Signal (Set PeerAddr)
govEstablishedPeersSig
Signal
(Set PeerAddr
-> Set PeerAddr
-> Set PeerAddr
-> Set PeerAddr
-> ([(HotValency, WarmValency, Set PeerAddr)], Set PeerAddr,
Set PeerAddr, Set PeerAddr, Set PeerAddr, Set PeerAddr))
-> Signal (Set PeerAddr)
-> Signal
(Set PeerAddr
-> Set PeerAddr
-> Set PeerAddr
-> ([(HotValency, WarmValency, Set PeerAddr)], Set PeerAddr,
Set PeerAddr, Set PeerAddr, Set PeerAddr, Set PeerAddr))
forall a b. Signal (a -> b) -> Signal a -> Signal b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Signal (Set PeerAddr)
govActivePeersSig
Signal
(Set PeerAddr
-> Set PeerAddr
-> Set PeerAddr
-> ([(HotValency, WarmValency, Set PeerAddr)], Set PeerAddr,
Set PeerAddr, Set PeerAddr, Set PeerAddr, Set PeerAddr))
-> Signal (Set PeerAddr)
-> Signal
(Set PeerAddr
-> Set PeerAddr
-> ([(HotValency, WarmValency, Set PeerAddr)], Set PeerAddr,
Set PeerAddr, Set PeerAddr, Set PeerAddr, Set PeerAddr))
forall a b. Signal (a -> b) -> Signal a -> Signal b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Signal (Set PeerAddr)
govActiveFailuresSig
Signal
(Set PeerAddr
-> Set PeerAddr
-> ([(HotValency, WarmValency, Set PeerAddr)], Set PeerAddr,
Set PeerAddr, Set PeerAddr, Set PeerAddr, Set PeerAddr))
-> Signal (Set PeerAddr)
-> Signal
(Set PeerAddr
-> ([(HotValency, WarmValency, Set PeerAddr)], Set PeerAddr,
Set PeerAddr, Set PeerAddr, Set PeerAddr, Set PeerAddr))
forall a b. Signal (a -> b) -> Signal a -> Signal b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Signal (Set PeerAddr)
promotionOpportunities
Signal
(Set PeerAddr
-> ([(HotValency, WarmValency, Set PeerAddr)], Set PeerAddr,
Set PeerAddr, Set PeerAddr, Set PeerAddr, Set PeerAddr))
-> Signal (Set PeerAddr)
-> Signal
([(HotValency, WarmValency, Set PeerAddr)], Set PeerAddr,
Set PeerAddr, Set PeerAddr, Set PeerAddr, Set PeerAddr)
forall a b. Signal (a -> b) -> Signal a -> Signal b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Signal (Set PeerAddr)
promotionOpportunitiesIgnoredTooLong)
prop_governor_target_active_local_above :: MaxTime -> GovernorMockEnvironment -> Property
prop_governor_target_active_local_above :: MaxTime -> GovernorMockEnvironment -> Property
prop_governor_target_active_local_above (MaxTime Time
maxTime) GovernorMockEnvironment
env =
let events :: Events TestTraceEvent
events = Time -> [(Time, TestTraceEvent)] -> Events TestTraceEvent
forall a. Time -> [(Time, a)] -> Events a
Signal.eventsFromListUpToTime Time
maxTime
([(Time, TestTraceEvent)] -> Events TestTraceEvent)
-> (GovernorMockEnvironment -> [(Time, TestTraceEvent)])
-> GovernorMockEnvironment
-> Events TestTraceEvent
forall b c a. (b -> c) -> (a -> b) -> a -> c
. SimTrace Void -> [(Time, TestTraceEvent)]
forall a. SimTrace a -> [(Time, TestTraceEvent)]
selectPeerSelectionTraceEvents
(SimTrace Void -> [(Time, TestTraceEvent)])
-> (GovernorMockEnvironment -> SimTrace Void)
-> GovernorMockEnvironment
-> [(Time, TestTraceEvent)]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. GovernorMockEnvironment -> SimTrace Void
runGovernorInMockEnvironment
(GovernorMockEnvironment -> Events TestTraceEvent)
-> GovernorMockEnvironment -> Events TestTraceEvent
forall a b. (a -> b) -> a -> b
$ GovernorMockEnvironment
env
govLocalRootPeersSig :: Signal (LocalRootPeers.LocalRootPeers PeerAddr)
govLocalRootPeersSig :: Signal (LocalRootPeers PeerAddr)
govLocalRootPeersSig =
(forall peerconn.
PeerSelectionState PeerAddr peerconn -> LocalRootPeers PeerAddr)
-> ConsensusMode
-> Events TestTraceEvent
-> Signal (LocalRootPeers PeerAddr)
forall a.
Eq a =>
(forall peerconn. PeerSelectionState PeerAddr peerconn -> a)
-> ConsensusMode -> Events TestTraceEvent -> Signal a
selectGovState PeerSelectionState PeerAddr peerconn -> LocalRootPeers PeerAddr
forall peerconn.
PeerSelectionState PeerAddr peerconn -> LocalRootPeers PeerAddr
forall peeraddr peerconn.
PeerSelectionState peeraddr peerconn -> LocalRootPeers peeraddr
Governor.localRootPeers (GovernorMockEnvironment -> ConsensusMode
consensusMode GovernorMockEnvironment
env) Events TestTraceEvent
events
govActivePeersSig :: Signal (Set PeerAddr)
govActivePeersSig :: Signal (Set PeerAddr)
govActivePeersSig =
(forall peerconn.
PeerSelectionState PeerAddr peerconn -> Set PeerAddr)
-> ConsensusMode -> Events TestTraceEvent -> Signal (Set PeerAddr)
forall a.
Eq a =>
(forall peerconn. PeerSelectionState PeerAddr peerconn -> a)
-> ConsensusMode -> Events TestTraceEvent -> Signal a
selectGovState PeerSelectionState PeerAddr peerconn -> Set PeerAddr
forall peerconn.
PeerSelectionState PeerAddr peerconn -> Set PeerAddr
forall peeraddr peerconn.
PeerSelectionState peeraddr peerconn -> Set peeraddr
Governor.activePeers (GovernorMockEnvironment -> ConsensusMode
consensusMode GovernorMockEnvironment
env) Events TestTraceEvent
events
deomotionOpportunities :: Signal (Set PeerAddr)
deomotionOpportunities :: Signal (Set PeerAddr)
deomotionOpportunities =
(\LocalRootPeers PeerAddr
local Set PeerAddr
active ->
[Set PeerAddr] -> Set PeerAddr
forall (f :: * -> *) a. (Foldable f, Ord a) => f (Set a) -> Set a
Set.unions
[
if Set PeerAddr -> Int
forall a. Set a -> Int
Set.size Set PeerAddr
groupActive Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
<= Int
hotTarget'
then Set PeerAddr
forall a. Set a
Set.empty
else Set PeerAddr
groupActive
| (HotValency Int
hotTarget', WarmValency
_, Set PeerAddr
group) <- LocalRootPeers PeerAddr
-> [(HotValency, WarmValency, Set PeerAddr)]
forall peeraddr.
LocalRootPeers peeraddr
-> [(HotValency, WarmValency, Set peeraddr)]
LocalRootPeers.toGroupSets LocalRootPeers PeerAddr
local
, let groupActive :: Set PeerAddr
groupActive = Set PeerAddr
group Set PeerAddr -> Set PeerAddr -> Set PeerAddr
forall a. Ord a => Set a -> Set a -> Set a
`Set.intersection` Set PeerAddr
active
]
) (LocalRootPeers PeerAddr -> Set PeerAddr -> Set PeerAddr)
-> Signal (LocalRootPeers PeerAddr)
-> Signal (Set PeerAddr -> Set PeerAddr)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Signal (LocalRootPeers PeerAddr)
govLocalRootPeersSig
Signal (Set PeerAddr -> Set PeerAddr)
-> Signal (Set PeerAddr) -> Signal (Set PeerAddr)
forall a b. Signal (a -> b) -> Signal a -> Signal b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Signal (Set PeerAddr)
govActivePeersSig
demotionOpportunitiesIgnoredTooLong :: Signal (Set PeerAddr)
demotionOpportunitiesIgnoredTooLong :: Signal (Set PeerAddr)
demotionOpportunitiesIgnoredTooLong =
DiffTime
-> (Set PeerAddr -> Set PeerAddr)
-> Signal (Set PeerAddr)
-> Signal (Set PeerAddr)
forall a b.
Ord b =>
DiffTime -> (a -> Set b) -> Signal a -> Signal (Set b)
Signal.keyedTimeout
DiffTime
10
Set PeerAddr -> Set PeerAddr
forall a. a -> a
id
Signal (Set PeerAddr)
deomotionOpportunities
in TestName -> Property -> Property
forall prop. Testable prop => TestName -> prop -> Property
counterexample
(TestName
"\nSignal key: (local peers, active peers, " TestName -> TestName -> TestName
forall a. [a] -> [a] -> [a]
++
TestName
"demotion opportunities, ignored too long)") (Property -> Property) -> Property -> Property
forall a b. (a -> b) -> a -> b
$
Int
-> (([(HotValency, WarmValency, Set PeerAddr)], Set PeerAddr,
Set PeerAddr, Set PeerAddr)
-> TestName)
-> (([(HotValency, WarmValency, Set PeerAddr)], Set PeerAddr,
Set PeerAddr, Set PeerAddr)
-> Bool)
-> Signal
([(HotValency, WarmValency, Set PeerAddr)], Set PeerAddr,
Set PeerAddr, Set PeerAddr)
-> Property
forall a.
Int -> (a -> TestName) -> (a -> Bool) -> Signal a -> Property
signalProperty Int
20 ([(HotValency, WarmValency, Set PeerAddr)], Set PeerAddr,
Set PeerAddr, Set PeerAddr)
-> TestName
forall a. Show a => a -> TestName
show
(\([(HotValency, WarmValency, Set PeerAddr)]
_,Set PeerAddr
_,Set PeerAddr
_,Set PeerAddr
toolong) -> Set PeerAddr -> Bool
forall a. Set a -> Bool
Set.null Set PeerAddr
toolong)
((,,,) ([(HotValency, WarmValency, Set PeerAddr)]
-> Set PeerAddr
-> Set PeerAddr
-> Set PeerAddr
-> ([(HotValency, WarmValency, Set PeerAddr)], Set PeerAddr,
Set PeerAddr, Set PeerAddr))
-> Signal [(HotValency, WarmValency, Set PeerAddr)]
-> Signal
(Set PeerAddr
-> Set PeerAddr
-> Set PeerAddr
-> ([(HotValency, WarmValency, Set PeerAddr)], Set PeerAddr,
Set PeerAddr, Set PeerAddr))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (LocalRootPeers PeerAddr
-> [(HotValency, WarmValency, Set PeerAddr)]
forall peeraddr.
LocalRootPeers peeraddr
-> [(HotValency, WarmValency, Set peeraddr)]
LocalRootPeers.toGroupSets (LocalRootPeers PeerAddr
-> [(HotValency, WarmValency, Set PeerAddr)])
-> Signal (LocalRootPeers PeerAddr)
-> Signal [(HotValency, WarmValency, Set PeerAddr)]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Signal (LocalRootPeers PeerAddr)
govLocalRootPeersSig)
Signal
(Set PeerAddr
-> Set PeerAddr
-> Set PeerAddr
-> ([(HotValency, WarmValency, Set PeerAddr)], Set PeerAddr,
Set PeerAddr, Set PeerAddr))
-> Signal (Set PeerAddr)
-> Signal
(Set PeerAddr
-> Set PeerAddr
-> ([(HotValency, WarmValency, Set PeerAddr)], Set PeerAddr,
Set PeerAddr, Set PeerAddr))
forall a b. Signal (a -> b) -> Signal a -> Signal b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Signal (Set PeerAddr)
govActivePeersSig
Signal
(Set PeerAddr
-> Set PeerAddr
-> ([(HotValency, WarmValency, Set PeerAddr)], Set PeerAddr,
Set PeerAddr, Set PeerAddr))
-> Signal (Set PeerAddr)
-> Signal
(Set PeerAddr
-> ([(HotValency, WarmValency, Set PeerAddr)], Set PeerAddr,
Set PeerAddr, Set PeerAddr))
forall a b. Signal (a -> b) -> Signal a -> Signal b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Signal (Set PeerAddr)
deomotionOpportunities
Signal
(Set PeerAddr
-> ([(HotValency, WarmValency, Set PeerAddr)], Set PeerAddr,
Set PeerAddr, Set PeerAddr))
-> Signal (Set PeerAddr)
-> Signal
([(HotValency, WarmValency, Set PeerAddr)], Set PeerAddr,
Set PeerAddr, Set PeerAddr)
forall a b. Signal (a -> b) -> Signal a -> Signal b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Signal (Set PeerAddr)
demotionOpportunitiesIgnoredTooLong)
prop_governor_only_bootstrap_peers_in_fallback_state :: GovernorMockEnvironment -> Property
prop_governor_only_bootstrap_peers_in_fallback_state :: GovernorMockEnvironment -> Property
prop_governor_only_bootstrap_peers_in_fallback_state GovernorMockEnvironment
env =
let events :: Events TestTraceEvent
events = Time -> [(Time, TestTraceEvent)] -> Events TestTraceEvent
forall a. Time -> [(Time, a)] -> Events a
Signal.eventsFromListUpToTime (DiffTime -> Time
Time (DiffTime
10 DiffTime -> DiffTime -> DiffTime
forall a. Num a => a -> a -> a
* DiffTime
60 DiffTime -> DiffTime -> DiffTime
forall a. Num a => a -> a -> a
* DiffTime
60))
([(Time, TestTraceEvent)] -> Events TestTraceEvent)
-> (GovernorMockEnvironment -> [(Time, TestTraceEvent)])
-> GovernorMockEnvironment
-> Events TestTraceEvent
forall b c a. (b -> c) -> (a -> b) -> a -> c
. SimTrace Void -> [(Time, TestTraceEvent)]
forall a. SimTrace a -> [(Time, TestTraceEvent)]
selectPeerSelectionTraceEvents
(SimTrace Void -> [(Time, TestTraceEvent)])
-> (GovernorMockEnvironment -> SimTrace Void)
-> GovernorMockEnvironment
-> [(Time, TestTraceEvent)]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. GovernorMockEnvironment -> SimTrace Void
runGovernorInMockEnvironment
(GovernorMockEnvironment -> Events TestTraceEvent)
-> GovernorMockEnvironment -> Events TestTraceEvent
forall a b. (a -> b) -> a -> b
$ GovernorMockEnvironment
env
govUseBootstrapPeers :: Signal UseBootstrapPeers
govUseBootstrapPeers :: Signal UseBootstrapPeers
govUseBootstrapPeers =
(forall peerconn.
PeerSelectionState PeerAddr peerconn -> UseBootstrapPeers)
-> ConsensusMode
-> Events TestTraceEvent
-> Signal UseBootstrapPeers
forall a.
Eq a =>
(forall peerconn. PeerSelectionState PeerAddr peerconn -> a)
-> ConsensusMode -> Events TestTraceEvent -> Signal a
selectGovState PeerSelectionState PeerAddr peerconn -> UseBootstrapPeers
forall peerconn.
PeerSelectionState PeerAddr peerconn -> UseBootstrapPeers
forall peeraddr peerconn.
PeerSelectionState peeraddr peerconn -> UseBootstrapPeers
Governor.bootstrapPeersFlag (GovernorMockEnvironment -> ConsensusMode
consensusMode GovernorMockEnvironment
env) Events TestTraceEvent
events
govLedgerStateJudgement :: Signal LedgerStateJudgement
govLedgerStateJudgement :: Signal LedgerStateJudgement
govLedgerStateJudgement =
(forall peerconn.
PeerSelectionState PeerAddr peerconn -> LedgerStateJudgement)
-> ConsensusMode
-> Events TestTraceEvent
-> Signal LedgerStateJudgement
forall a.
Eq a =>
(forall peerconn. PeerSelectionState PeerAddr peerconn -> a)
-> ConsensusMode -> Events TestTraceEvent -> Signal a
selectGovState PeerSelectionState PeerAddr peerconn -> LedgerStateJudgement
forall peerconn.
PeerSelectionState PeerAddr peerconn -> LedgerStateJudgement
forall peeraddr peerconn.
PeerSelectionState peeraddr peerconn -> LedgerStateJudgement
Governor.ledgerStateJudgement (GovernorMockEnvironment -> ConsensusMode
consensusMode GovernorMockEnvironment
env) Events TestTraceEvent
events
govKnownPeers :: Signal (Set PeerAddr)
govKnownPeers :: Signal (Set PeerAddr)
govKnownPeers =
(forall peerconn.
PeerSelectionState PeerAddr peerconn -> Set PeerAddr)
-> ConsensusMode -> Events TestTraceEvent -> Signal (Set PeerAddr)
forall a.
Eq a =>
(forall peerconn. PeerSelectionState PeerAddr peerconn -> a)
-> ConsensusMode -> Events TestTraceEvent -> Signal a
selectGovState (KnownPeers PeerAddr -> Set PeerAddr
forall peeraddr. KnownPeers peeraddr -> Set peeraddr
KnownPeers.toSet (KnownPeers PeerAddr -> Set PeerAddr)
-> (PeerSelectionState PeerAddr peerconn -> KnownPeers PeerAddr)
-> PeerSelectionState PeerAddr peerconn
-> Set PeerAddr
forall b c a. (b -> c) -> (a -> b) -> a -> c
. PeerSelectionState PeerAddr peerconn -> KnownPeers PeerAddr
forall peeraddr peerconn.
PeerSelectionState peeraddr peerconn -> KnownPeers peeraddr
Governor.knownPeers)
(GovernorMockEnvironment -> ConsensusMode
consensusMode GovernorMockEnvironment
env)
Events TestTraceEvent
events
govTrustedPeers :: Signal (Set PeerAddr)
govTrustedPeers :: Signal (Set PeerAddr)
govTrustedPeers =
(forall peerconn.
PeerSelectionState PeerAddr peerconn -> Set PeerAddr)
-> ConsensusMode -> Events TestTraceEvent -> Signal (Set PeerAddr)
forall a.
Eq a =>
(forall peerconn. PeerSelectionState PeerAddr peerconn -> a)
-> ConsensusMode -> Events TestTraceEvent -> Signal a
selectGovState
(\PeerSelectionState PeerAddr peerconn
st -> LocalRootPeers PeerAddr -> Set PeerAddr
forall peeraddr. LocalRootPeers peeraddr -> Set peeraddr
LocalRootPeers.keysSet (LocalRootPeers PeerAddr -> LocalRootPeers PeerAddr
forall peeraddr.
Ord peeraddr =>
LocalRootPeers peeraddr -> LocalRootPeers peeraddr
LocalRootPeers.clampToTrustable (PeerSelectionState PeerAddr peerconn -> LocalRootPeers PeerAddr
forall peeraddr peerconn.
PeerSelectionState peeraddr peerconn -> LocalRootPeers peeraddr
Governor.localRootPeers PeerSelectionState PeerAddr peerconn
st))
Set PeerAddr -> Set PeerAddr -> Set PeerAddr
forall a. Semigroup a => a -> a -> a
<> PublicRootPeers PeerAddr -> Set PeerAddr
forall peeraddr. PublicRootPeers peeraddr -> Set peeraddr
PublicRootPeers.getBootstrapPeers (PeerSelectionState PeerAddr peerconn -> PublicRootPeers PeerAddr
forall peeraddr peerconn.
PeerSelectionState peeraddr peerconn -> PublicRootPeers peeraddr
Governor.publicRootPeers PeerSelectionState PeerAddr peerconn
st)
)
(GovernorMockEnvironment -> ConsensusMode
consensusMode GovernorMockEnvironment
env)
Events TestTraceEvent
events
keepNonTrustablePeersTooLong :: Signal (Set PeerAddr)
keepNonTrustablePeersTooLong :: Signal (Set PeerAddr)
keepNonTrustablePeersTooLong =
DiffTime
-> ((Set PeerAddr, UseBootstrapPeers, Set PeerAddr,
LedgerStateJudgement)
-> Set PeerAddr)
-> Signal
(Set PeerAddr, UseBootstrapPeers, Set PeerAddr,
LedgerStateJudgement)
-> Signal (Set PeerAddr)
forall a b.
Ord b =>
DiffTime -> (a -> Set b) -> Signal a -> Signal (Set b)
Signal.keyedTimeout
DiffTime
10
(\(Set PeerAddr
knownPeers, UseBootstrapPeers
useBootstrapPeers, Set PeerAddr
trustedPeers, LedgerStateJudgement
lsj) ->
if UseBootstrapPeers -> LedgerStateJudgement -> Bool
requiresBootstrapPeers UseBootstrapPeers
useBootstrapPeers LedgerStateJudgement
lsj
then Set PeerAddr
knownPeers Set PeerAddr -> Set PeerAddr -> Set PeerAddr
forall a. Ord a => Set a -> Set a -> Set a
`Set.difference` Set PeerAddr
trustedPeers
else Set PeerAddr
forall a. Set a
Set.empty
)
((,,,) (Set PeerAddr
-> UseBootstrapPeers
-> Set PeerAddr
-> LedgerStateJudgement
-> (Set PeerAddr, UseBootstrapPeers, Set PeerAddr,
LedgerStateJudgement))
-> Signal (Set PeerAddr)
-> Signal
(UseBootstrapPeers
-> Set PeerAddr
-> LedgerStateJudgement
-> (Set PeerAddr, UseBootstrapPeers, Set PeerAddr,
LedgerStateJudgement))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Signal (Set PeerAddr)
govKnownPeers
Signal
(UseBootstrapPeers
-> Set PeerAddr
-> LedgerStateJudgement
-> (Set PeerAddr, UseBootstrapPeers, Set PeerAddr,
LedgerStateJudgement))
-> Signal UseBootstrapPeers
-> Signal
(Set PeerAddr
-> LedgerStateJudgement
-> (Set PeerAddr, UseBootstrapPeers, Set PeerAddr,
LedgerStateJudgement))
forall a b. Signal (a -> b) -> Signal a -> Signal b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Signal UseBootstrapPeers
govUseBootstrapPeers
Signal
(Set PeerAddr
-> LedgerStateJudgement
-> (Set PeerAddr, UseBootstrapPeers, Set PeerAddr,
LedgerStateJudgement))
-> Signal (Set PeerAddr)
-> Signal
(LedgerStateJudgement
-> (Set PeerAddr, UseBootstrapPeers, Set PeerAddr,
LedgerStateJudgement))
forall a b. Signal (a -> b) -> Signal a -> Signal b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Signal (Set PeerAddr)
govTrustedPeers
Signal
(LedgerStateJudgement
-> (Set PeerAddr, UseBootstrapPeers, Set PeerAddr,
LedgerStateJudgement))
-> Signal LedgerStateJudgement
-> Signal
(Set PeerAddr, UseBootstrapPeers, Set PeerAddr,
LedgerStateJudgement)
forall a b. Signal (a -> b) -> Signal a -> Signal b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Signal LedgerStateJudgement
govLedgerStateJudgement
)
in Int
-> (Set PeerAddr -> TestName)
-> (Set PeerAddr -> Bool)
-> Signal (Set PeerAddr)
-> Property
forall a.
Int -> (a -> TestName) -> (a -> Bool) -> Signal a -> Property
signalProperty Int
20 Set PeerAddr -> TestName
forall a. Show a => a -> TestName
show
Set PeerAddr -> Bool
forall a. Set a -> Bool
Set.null
Signal (Set PeerAddr)
keepNonTrustablePeersTooLong
prop_governor_no_non_trustable_peers_before_caught_up_state :: GovernorMockEnvironment -> Property
prop_governor_no_non_trustable_peers_before_caught_up_state :: GovernorMockEnvironment -> Property
prop_governor_no_non_trustable_peers_before_caught_up_state GovernorMockEnvironment
env =
let events :: Events TestTraceEvent
events = Time -> [(Time, TestTraceEvent)] -> Events TestTraceEvent
forall a. Time -> [(Time, a)] -> Events a
Signal.eventsFromListUpToTime (DiffTime -> Time
Time (DiffTime
10 DiffTime -> DiffTime -> DiffTime
forall a. Num a => a -> a -> a
* DiffTime
60 DiffTime -> DiffTime -> DiffTime
forall a. Num a => a -> a -> a
* DiffTime
60))
([(Time, TestTraceEvent)] -> Events TestTraceEvent)
-> (GovernorMockEnvironment -> [(Time, TestTraceEvent)])
-> GovernorMockEnvironment
-> Events TestTraceEvent
forall b c a. (b -> c) -> (a -> b) -> a -> c
. SimTrace Void -> [(Time, TestTraceEvent)]
forall a. SimTrace a -> [(Time, TestTraceEvent)]
selectPeerSelectionTraceEvents
(SimTrace Void -> [(Time, TestTraceEvent)])
-> (GovernorMockEnvironment -> SimTrace Void)
-> GovernorMockEnvironment
-> [(Time, TestTraceEvent)]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. GovernorMockEnvironment -> SimTrace Void
runGovernorInMockEnvironment
(GovernorMockEnvironment -> Events TestTraceEvent)
-> GovernorMockEnvironment -> Events TestTraceEvent
forall a b. (a -> b) -> a -> b
$ GovernorMockEnvironment
env
govUseBootstrapPeers :: Signal UseBootstrapPeers
govUseBootstrapPeers :: Signal UseBootstrapPeers
govUseBootstrapPeers =
(forall peerconn.
PeerSelectionState PeerAddr peerconn -> UseBootstrapPeers)
-> ConsensusMode
-> Events TestTraceEvent
-> Signal UseBootstrapPeers
forall a.
Eq a =>
(forall peerconn. PeerSelectionState PeerAddr peerconn -> a)
-> ConsensusMode -> Events TestTraceEvent -> Signal a
selectGovState PeerSelectionState PeerAddr peerconn -> UseBootstrapPeers
forall peerconn.
PeerSelectionState PeerAddr peerconn -> UseBootstrapPeers
forall peeraddr peerconn.
PeerSelectionState peeraddr peerconn -> UseBootstrapPeers
Governor.bootstrapPeersFlag (GovernorMockEnvironment -> ConsensusMode
consensusMode GovernorMockEnvironment
env) Events TestTraceEvent
events
govLedgerStateJudgement :: Signal LedgerStateJudgement
govLedgerStateJudgement :: Signal LedgerStateJudgement
govLedgerStateJudgement =
(forall peerconn.
PeerSelectionState PeerAddr peerconn -> LedgerStateJudgement)
-> ConsensusMode
-> Events TestTraceEvent
-> Signal LedgerStateJudgement
forall a.
Eq a =>
(forall peerconn. PeerSelectionState PeerAddr peerconn -> a)
-> ConsensusMode -> Events TestTraceEvent -> Signal a
selectGovState PeerSelectionState PeerAddr peerconn -> LedgerStateJudgement
forall peerconn.
PeerSelectionState PeerAddr peerconn -> LedgerStateJudgement
forall peeraddr peerconn.
PeerSelectionState peeraddr peerconn -> LedgerStateJudgement
Governor.ledgerStateJudgement (GovernorMockEnvironment -> ConsensusMode
consensusMode GovernorMockEnvironment
env) Events TestTraceEvent
events
govKnownPeers :: Signal (Set PeerAddr)
govKnownPeers :: Signal (Set PeerAddr)
govKnownPeers =
(forall peerconn.
PeerSelectionState PeerAddr peerconn -> Set PeerAddr)
-> ConsensusMode -> Events TestTraceEvent -> Signal (Set PeerAddr)
forall a.
Eq a =>
(forall peerconn. PeerSelectionState PeerAddr peerconn -> a)
-> ConsensusMode -> Events TestTraceEvent -> Signal a
selectGovState (KnownPeers PeerAddr -> Set PeerAddr
forall peeraddr. KnownPeers peeraddr -> Set peeraddr
KnownPeers.toSet (KnownPeers PeerAddr -> Set PeerAddr)
-> (PeerSelectionState PeerAddr peerconn -> KnownPeers PeerAddr)
-> PeerSelectionState PeerAddr peerconn
-> Set PeerAddr
forall b c a. (b -> c) -> (a -> b) -> a -> c
. PeerSelectionState PeerAddr peerconn -> KnownPeers PeerAddr
forall peeraddr peerconn.
PeerSelectionState peeraddr peerconn -> KnownPeers peeraddr
Governor.knownPeers) (GovernorMockEnvironment -> ConsensusMode
consensusMode GovernorMockEnvironment
env) Events TestTraceEvent
events
govTrustedPeers :: Signal (Set PeerAddr)
govTrustedPeers :: Signal (Set PeerAddr)
govTrustedPeers =
(forall peerconn.
PeerSelectionState PeerAddr peerconn -> Set PeerAddr)
-> ConsensusMode -> Events TestTraceEvent -> Signal (Set PeerAddr)
forall a.
Eq a =>
(forall peerconn. PeerSelectionState PeerAddr peerconn -> a)
-> ConsensusMode -> Events TestTraceEvent -> Signal a
selectGovState
(\PeerSelectionState PeerAddr peerconn
st -> LocalRootPeers PeerAddr -> Set PeerAddr
forall peeraddr. LocalRootPeers peeraddr -> Set peeraddr
LocalRootPeers.keysSet (LocalRootPeers PeerAddr -> LocalRootPeers PeerAddr
forall peeraddr.
Ord peeraddr =>
LocalRootPeers peeraddr -> LocalRootPeers peeraddr
LocalRootPeers.clampToTrustable (PeerSelectionState PeerAddr peerconn -> LocalRootPeers PeerAddr
forall peeraddr peerconn.
PeerSelectionState peeraddr peerconn -> LocalRootPeers peeraddr
Governor.localRootPeers PeerSelectionState PeerAddr peerconn
st))
Set PeerAddr -> Set PeerAddr -> Set PeerAddr
forall a. Semigroup a => a -> a -> a
<> PublicRootPeers PeerAddr -> Set PeerAddr
forall peeraddr. PublicRootPeers peeraddr -> Set peeraddr
PublicRootPeers.getBootstrapPeers (PeerSelectionState PeerAddr peerconn -> PublicRootPeers PeerAddr
forall peeraddr peerconn.
PeerSelectionState peeraddr peerconn -> PublicRootPeers peeraddr
Governor.publicRootPeers PeerSelectionState PeerAddr peerconn
st)
)
(GovernorMockEnvironment -> ConsensusMode
consensusMode GovernorMockEnvironment
env)
Events TestTraceEvent
events
govHasOnlyBootstrapPeers :: Signal Bool
govHasOnlyBootstrapPeers :: Signal Bool
govHasOnlyBootstrapPeers =
(forall peerconn. PeerSelectionState PeerAddr peerconn -> Bool)
-> ConsensusMode -> Events TestTraceEvent -> Signal Bool
forall a.
Eq a =>
(forall peerconn. PeerSelectionState PeerAddr peerconn -> a)
-> ConsensusMode -> Events TestTraceEvent -> Signal a
selectGovState PeerSelectionState PeerAddr peerconn -> Bool
forall peerconn. PeerSelectionState PeerAddr peerconn -> Bool
forall peeraddr peerconn.
PeerSelectionState peeraddr peerconn -> Bool
Governor.hasOnlyBootstrapPeers
(GovernorMockEnvironment -> ConsensusMode
consensusMode GovernorMockEnvironment
env)
Events TestTraceEvent
events
keepNonTrustablePeersTooLong :: Signal (Set PeerAddr)
keepNonTrustablePeersTooLong :: Signal (Set PeerAddr)
keepNonTrustablePeersTooLong =
DiffTime
-> ((Set PeerAddr, Set PeerAddr, UseBootstrapPeers,
LedgerStateJudgement, Bool)
-> Set PeerAddr)
-> Signal
(Set PeerAddr, Set PeerAddr, UseBootstrapPeers,
LedgerStateJudgement, Bool)
-> Signal (Set PeerAddr)
forall a b.
Ord b =>
DiffTime -> (a -> Set b) -> Signal a -> Signal (Set b)
Signal.keyedTimeout
DiffTime
10
(\( Set PeerAddr
knownPeers, Set PeerAddr
trustedPeers
, UseBootstrapPeers
useBootstrapPeers, LedgerStateJudgement
lsj, Bool
hasOnlyBootstrapPeers) ->
if Bool
hasOnlyBootstrapPeers Bool -> Bool -> Bool
&& UseBootstrapPeers -> LedgerStateJudgement -> Bool
requiresBootstrapPeers UseBootstrapPeers
useBootstrapPeers LedgerStateJudgement
lsj
then Set PeerAddr -> Set PeerAddr -> Set PeerAddr
forall a. Ord a => Set a -> Set a -> Set a
Set.difference Set PeerAddr
knownPeers Set PeerAddr
trustedPeers
else Set PeerAddr
forall a. Set a
Set.empty
)
((,,,,) (Set PeerAddr
-> Set PeerAddr
-> UseBootstrapPeers
-> LedgerStateJudgement
-> Bool
-> (Set PeerAddr, Set PeerAddr, UseBootstrapPeers,
LedgerStateJudgement, Bool))
-> Signal (Set PeerAddr)
-> Signal
(Set PeerAddr
-> UseBootstrapPeers
-> LedgerStateJudgement
-> Bool
-> (Set PeerAddr, Set PeerAddr, UseBootstrapPeers,
LedgerStateJudgement, Bool))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Signal (Set PeerAddr)
govKnownPeers
Signal
(Set PeerAddr
-> UseBootstrapPeers
-> LedgerStateJudgement
-> Bool
-> (Set PeerAddr, Set PeerAddr, UseBootstrapPeers,
LedgerStateJudgement, Bool))
-> Signal (Set PeerAddr)
-> Signal
(UseBootstrapPeers
-> LedgerStateJudgement
-> Bool
-> (Set PeerAddr, Set PeerAddr, UseBootstrapPeers,
LedgerStateJudgement, Bool))
forall a b. Signal (a -> b) -> Signal a -> Signal b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Signal (Set PeerAddr)
govTrustedPeers
Signal
(UseBootstrapPeers
-> LedgerStateJudgement
-> Bool
-> (Set PeerAddr, Set PeerAddr, UseBootstrapPeers,
LedgerStateJudgement, Bool))
-> Signal UseBootstrapPeers
-> Signal
(LedgerStateJudgement
-> Bool
-> (Set PeerAddr, Set PeerAddr, UseBootstrapPeers,
LedgerStateJudgement, Bool))
forall a b. Signal (a -> b) -> Signal a -> Signal b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Signal UseBootstrapPeers
govUseBootstrapPeers
Signal
(LedgerStateJudgement
-> Bool
-> (Set PeerAddr, Set PeerAddr, UseBootstrapPeers,
LedgerStateJudgement, Bool))
-> Signal LedgerStateJudgement
-> Signal
(Bool
-> (Set PeerAddr, Set PeerAddr, UseBootstrapPeers,
LedgerStateJudgement, Bool))
forall a b. Signal (a -> b) -> Signal a -> Signal b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Signal LedgerStateJudgement
govLedgerStateJudgement
Signal
(Bool
-> (Set PeerAddr, Set PeerAddr, UseBootstrapPeers,
LedgerStateJudgement, Bool))
-> Signal Bool
-> Signal
(Set PeerAddr, Set PeerAddr, UseBootstrapPeers,
LedgerStateJudgement, Bool)
forall a b. Signal (a -> b) -> Signal a -> Signal b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Signal Bool
govHasOnlyBootstrapPeers
)
in Int
-> (Set PeerAddr -> TestName)
-> (Set PeerAddr -> Bool)
-> Signal (Set PeerAddr)
-> Property
forall a.
Int -> (a -> TestName) -> (a -> Bool) -> Signal a -> Property
signalProperty Int
20 Set PeerAddr -> TestName
forall a. Show a => a -> TestName
show
Set PeerAddr -> Bool
forall a. Set a -> Bool
Set.null
Signal (Set PeerAddr)
keepNonTrustablePeersTooLong
prop_governor_only_bootstrap_peers_in_clean_state :: GovernorMockEnvironment -> Property
prop_governor_only_bootstrap_peers_in_clean_state :: GovernorMockEnvironment -> Property
prop_governor_only_bootstrap_peers_in_clean_state GovernorMockEnvironment
env =
let events :: Events TestTraceEvent
events = Time -> [(Time, TestTraceEvent)] -> Events TestTraceEvent
forall a. Time -> [(Time, a)] -> Events a
Signal.eventsFromListUpToTime (DiffTime -> Time
Time (DiffTime
10 DiffTime -> DiffTime -> DiffTime
forall a. Num a => a -> a -> a
* DiffTime
60 DiffTime -> DiffTime -> DiffTime
forall a. Num a => a -> a -> a
* DiffTime
60))
([(Time, TestTraceEvent)] -> Events TestTraceEvent)
-> (GovernorMockEnvironment -> [(Time, TestTraceEvent)])
-> GovernorMockEnvironment
-> Events TestTraceEvent
forall b c a. (b -> c) -> (a -> b) -> a -> c
. SimTrace Void -> [(Time, TestTraceEvent)]
forall a. SimTrace a -> [(Time, TestTraceEvent)]
selectPeerSelectionTraceEvents
(SimTrace Void -> [(Time, TestTraceEvent)])
-> (GovernorMockEnvironment -> SimTrace Void)
-> GovernorMockEnvironment
-> [(Time, TestTraceEvent)]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. GovernorMockEnvironment -> SimTrace Void
runGovernorInMockEnvironment
(GovernorMockEnvironment -> Events TestTraceEvent)
-> GovernorMockEnvironment -> Events TestTraceEvent
forall a b. (a -> b) -> a -> b
$ GovernorMockEnvironment
env
govUseBootstrapPeers :: Signal UseBootstrapPeers
govUseBootstrapPeers :: Signal UseBootstrapPeers
govUseBootstrapPeers =
(forall peerconn.
PeerSelectionState PeerAddr peerconn -> UseBootstrapPeers)
-> ConsensusMode
-> Events TestTraceEvent
-> Signal UseBootstrapPeers
forall a.
Eq a =>
(forall peerconn. PeerSelectionState PeerAddr peerconn -> a)
-> ConsensusMode -> Events TestTraceEvent -> Signal a
selectGovState PeerSelectionState PeerAddr peerconn -> UseBootstrapPeers
forall peerconn.
PeerSelectionState PeerAddr peerconn -> UseBootstrapPeers
forall peeraddr peerconn.
PeerSelectionState peeraddr peerconn -> UseBootstrapPeers
Governor.bootstrapPeersFlag
(GovernorMockEnvironment -> ConsensusMode
consensusMode GovernorMockEnvironment
env)
Events TestTraceEvent
events
govLedgerStateJudgement :: Signal LedgerStateJudgement
govLedgerStateJudgement :: Signal LedgerStateJudgement
govLedgerStateJudgement =
(forall peerconn.
PeerSelectionState PeerAddr peerconn -> LedgerStateJudgement)
-> ConsensusMode
-> Events TestTraceEvent
-> Signal LedgerStateJudgement
forall a.
Eq a =>
(forall peerconn. PeerSelectionState PeerAddr peerconn -> a)
-> ConsensusMode -> Events TestTraceEvent -> Signal a
selectGovState PeerSelectionState PeerAddr peerconn -> LedgerStateJudgement
forall peerconn.
PeerSelectionState PeerAddr peerconn -> LedgerStateJudgement
forall peeraddr peerconn.
PeerSelectionState peeraddr peerconn -> LedgerStateJudgement
Governor.ledgerStateJudgement
(GovernorMockEnvironment -> ConsensusMode
consensusMode GovernorMockEnvironment
env)
Events TestTraceEvent
events
govKnownAndTrustedPeers :: Signal (Set PeerAddr, Set PeerAddr)
govKnownAndTrustedPeers :: Signal (Set PeerAddr, Set PeerAddr)
govKnownAndTrustedPeers =
(forall peerconn.
PeerSelectionState PeerAddr peerconn
-> (Set PeerAddr, Set PeerAddr))
-> ConsensusMode
-> Events TestTraceEvent
-> Signal (Set PeerAddr, Set PeerAddr)
forall a.
Eq a =>
(forall peerconn. PeerSelectionState PeerAddr peerconn -> a)
-> ConsensusMode -> Events TestTraceEvent -> Signal a
selectGovState
(\PeerSelectionState PeerAddr peerconn
st ->
( KnownPeers PeerAddr -> Set PeerAddr
forall peeraddr. KnownPeers peeraddr -> Set peeraddr
KnownPeers.toSet (PeerSelectionState PeerAddr peerconn -> KnownPeers PeerAddr
forall peeraddr peerconn.
PeerSelectionState peeraddr peerconn -> KnownPeers peeraddr
Governor.knownPeers PeerSelectionState PeerAddr peerconn
st)
,
LocalRootPeers PeerAddr -> Set PeerAddr
forall peeraddr. LocalRootPeers peeraddr -> Set peeraddr
LocalRootPeers.keysSet (LocalRootPeers PeerAddr -> LocalRootPeers PeerAddr
forall peeraddr.
Ord peeraddr =>
LocalRootPeers peeraddr -> LocalRootPeers peeraddr
LocalRootPeers.clampToTrustable (PeerSelectionState PeerAddr peerconn -> LocalRootPeers PeerAddr
forall peeraddr peerconn.
PeerSelectionState peeraddr peerconn -> LocalRootPeers peeraddr
Governor.localRootPeers PeerSelectionState PeerAddr peerconn
st))
Set PeerAddr -> Set PeerAddr -> Set PeerAddr
forall a. Semigroup a => a -> a -> a
<> PublicRootPeers PeerAddr -> Set PeerAddr
forall peeraddr. PublicRootPeers peeraddr -> Set peeraddr
PublicRootPeers.getBootstrapPeers (PeerSelectionState PeerAddr peerconn -> PublicRootPeers PeerAddr
forall peeraddr peerconn.
PeerSelectionState peeraddr peerconn -> PublicRootPeers peeraddr
Governor.publicRootPeers PeerSelectionState PeerAddr peerconn
st)
)
)
(GovernorMockEnvironment -> ConsensusMode
consensusMode GovernorMockEnvironment
env)
Events TestTraceEvent
events
configTrustedLocalRoots :: Signal (Set PeerAddr)
configTrustedLocalRoots :: Signal (Set PeerAddr)
configTrustedLocalRoots =
Set PeerAddr -> Events (Set PeerAddr) -> Signal (Set PeerAddr)
forall a. a -> Events a -> Signal a
Signal.fromChangeEvents Set PeerAddr
forall a. Set a
Set.empty
(Events (Set PeerAddr) -> Signal (Set PeerAddr))
-> (Events TestTraceEvent -> Events (Set PeerAddr))
-> Events TestTraceEvent
-> Signal (Set PeerAddr)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (TraceMockEnv -> Maybe (Set PeerAddr))
-> Events TraceMockEnv -> Events (Set PeerAddr)
forall a b. (a -> Maybe b) -> Events a -> Events b
Signal.selectEvents
(\case
TraceEnvSetLocalRoots (LocalRootPeers Map PeerAddr LocalRootConfig
peerMap [(HotValency, WarmValency, Set PeerAddr)]
_) ->
Set PeerAddr -> Maybe (Set PeerAddr)
forall a. a -> Maybe a
Just (Set PeerAddr -> Maybe (Set PeerAddr))
-> (Map PeerAddr LocalRootConfig -> Set PeerAddr)
-> Map PeerAddr LocalRootConfig
-> Maybe (Set PeerAddr)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Map PeerAddr LocalRootConfig -> Set PeerAddr
forall k a. Map k a -> Set k
Map.keysSet (Map PeerAddr LocalRootConfig -> Set PeerAddr)
-> (Map PeerAddr LocalRootConfig -> Map PeerAddr LocalRootConfig)
-> Map PeerAddr LocalRootConfig
-> Set PeerAddr
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (LocalRootConfig -> Bool)
-> Map PeerAddr LocalRootConfig -> Map PeerAddr LocalRootConfig
forall a k. (a -> Bool) -> Map k a -> Map k a
Map.filter LocalRootConfig -> Bool
isTrustable (Map PeerAddr LocalRootConfig -> Maybe (Set PeerAddr))
-> Map PeerAddr LocalRootConfig -> Maybe (Set PeerAddr)
forall a b. (a -> b) -> a -> b
$ Map PeerAddr LocalRootConfig
peerMap
TraceMockEnv
_ -> Maybe (Set PeerAddr)
forall a. Maybe a
Nothing)
(Events TraceMockEnv -> Events (Set PeerAddr))
-> (Events TestTraceEvent -> Events TraceMockEnv)
-> Events TestTraceEvent
-> Events (Set PeerAddr)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Events TestTraceEvent -> Events TraceMockEnv
selectEnvEvents
(Events TestTraceEvent -> Signal (Set PeerAddr))
-> Events TestTraceEvent -> Signal (Set PeerAddr)
forall a b. (a -> b) -> a -> b
$ Events TestTraceEvent
events
where
isTrustable :: LocalRootConfig -> Bool
isTrustable LocalRootConfig { peerTrustable :: LocalRootConfig -> PeerTrustable
peerTrustable = PeerTrustable
IsTrustable }
= Bool
True
isTrustable LocalRootConfig
_ = Bool
False
govHasOnlyBootstrapPeers :: Signal Bool
govHasOnlyBootstrapPeers :: Signal Bool
govHasOnlyBootstrapPeers =
(forall peerconn. PeerSelectionState PeerAddr peerconn -> Bool)
-> ConsensusMode -> Events TestTraceEvent -> Signal Bool
forall a.
Eq a =>
(forall peerconn. PeerSelectionState PeerAddr peerconn -> a)
-> ConsensusMode -> Events TestTraceEvent -> Signal a
selectGovState PeerSelectionState PeerAddr peerconn -> Bool
forall peerconn. PeerSelectionState PeerAddr peerconn -> Bool
forall peeraddr peerconn.
PeerSelectionState peeraddr peerconn -> Bool
Governor.hasOnlyBootstrapPeers (GovernorMockEnvironment -> ConsensusMode
consensusMode GovernorMockEnvironment
env) Events TestTraceEvent
events
isInCleanState :: Signal Bool
isInCleanState :: Signal Bool
isInCleanState =
(Set () -> Bool) -> Signal (Set ()) -> Signal Bool
forall a b. (a -> b) -> Signal a -> Signal b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (Bool -> Bool
not (Bool -> Bool) -> (Set () -> Bool) -> Set () -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Set () -> Bool
forall a. Set a -> Bool
Set.null)
(Signal (Set ()) -> Signal Bool) -> Signal (Set ()) -> Signal Bool
forall a b. (a -> b) -> a -> b
$ (((Set PeerAddr, Set PeerAddr), UseBootstrapPeers,
LedgerStateJudgement, Bool)
-> Set ())
-> (((Set PeerAddr, Set PeerAddr), UseBootstrapPeers,
LedgerStateJudgement, Bool)
-> Set ())
-> (((Set PeerAddr, Set PeerAddr), UseBootstrapPeers,
LedgerStateJudgement, Bool)
-> Bool)
-> Signal
((Set PeerAddr, Set PeerAddr), UseBootstrapPeers,
LedgerStateJudgement, Bool)
-> Signal (Set ())
forall a b.
Ord b =>
(a -> Set b)
-> (a -> Set b) -> (a -> Bool) -> Signal a -> Signal (Set b)
Signal.keyedUntil
(\((Set PeerAddr, Set PeerAddr)
_, UseBootstrapPeers
ubp, LedgerStateJudgement
lsj, Bool
hp) ->
if Bool
hp Bool -> Bool -> Bool
&& UseBootstrapPeers -> LedgerStateJudgement -> Bool
requiresBootstrapPeers UseBootstrapPeers
ubp LedgerStateJudgement
lsj
then () -> Set ()
forall a. a -> Set a
Set.singleton ()
else Set ()
forall a. Set a
Set.empty
)
(\((Set PeerAddr, Set PeerAddr)
_, UseBootstrapPeers
ubp, LedgerStateJudgement
lsj, Bool
_hp) ->
if Bool -> Bool
not (UseBootstrapPeers -> LedgerStateJudgement -> Bool
requiresBootstrapPeers UseBootstrapPeers
ubp LedgerStateJudgement
lsj)
then () -> Set ()
forall a. a -> Set a
Set.singleton ()
else Set ()
forall a. Set a
Set.empty
)
(Bool
-> ((Set PeerAddr, Set PeerAddr), UseBootstrapPeers,
LedgerStateJudgement, Bool)
-> Bool
forall a b. a -> b -> a
const Bool
False)
((,,,) ((Set PeerAddr, Set PeerAddr)
-> UseBootstrapPeers
-> LedgerStateJudgement
-> Bool
-> ((Set PeerAddr, Set PeerAddr), UseBootstrapPeers,
LedgerStateJudgement, Bool))
-> Signal (Set PeerAddr, Set PeerAddr)
-> Signal
(UseBootstrapPeers
-> LedgerStateJudgement
-> Bool
-> ((Set PeerAddr, Set PeerAddr), UseBootstrapPeers,
LedgerStateJudgement, Bool))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Signal (Set PeerAddr, Set PeerAddr)
govKnownAndTrustedPeers
Signal
(UseBootstrapPeers
-> LedgerStateJudgement
-> Bool
-> ((Set PeerAddr, Set PeerAddr), UseBootstrapPeers,
LedgerStateJudgement, Bool))
-> Signal UseBootstrapPeers
-> Signal
(LedgerStateJudgement
-> Bool
-> ((Set PeerAddr, Set PeerAddr), UseBootstrapPeers,
LedgerStateJudgement, Bool))
forall a b. Signal (a -> b) -> Signal a -> Signal b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Signal UseBootstrapPeers
govUseBootstrapPeers
Signal
(LedgerStateJudgement
-> Bool
-> ((Set PeerAddr, Set PeerAddr), UseBootstrapPeers,
LedgerStateJudgement, Bool))
-> Signal LedgerStateJudgement
-> Signal
(Bool
-> ((Set PeerAddr, Set PeerAddr), UseBootstrapPeers,
LedgerStateJudgement, Bool))
forall a b. Signal (a -> b) -> Signal a -> Signal b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Signal LedgerStateJudgement
govLedgerStateJudgement
Signal
(Bool
-> ((Set PeerAddr, Set PeerAddr), UseBootstrapPeers,
LedgerStateJudgement, Bool))
-> Signal Bool
-> Signal
((Set PeerAddr, Set PeerAddr), UseBootstrapPeers,
LedgerStateJudgement, Bool)
forall a b. Signal (a -> b) -> Signal a -> Signal b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Signal Bool
govHasOnlyBootstrapPeers
)
in Int
-> ((Bool, (Set PeerAddr, Set PeerAddr), Set PeerAddr) -> TestName)
-> ((Bool, (Set PeerAddr, Set PeerAddr), Set PeerAddr) -> Bool)
-> Signal (Bool, (Set PeerAddr, Set PeerAddr), Set PeerAddr)
-> Property
forall a.
Int -> (a -> TestName) -> (a -> Bool) -> Signal a -> Property
signalProperty Int
20 (Bool, (Set PeerAddr, Set PeerAddr), Set PeerAddr) -> TestName
forall a. Show a => a -> TestName
show
(\(Bool
b, (Set PeerAddr
kp, Set PeerAddr
tp), Set PeerAddr
fromConfigTrustedLocalRoots) ->
let kp' :: Set PeerAddr
kp' = Set PeerAddr
kp Set PeerAddr -> Set PeerAddr -> Set PeerAddr
forall a. Ord a => Set a -> Set a -> Set a
`Set.union` Set PeerAddr
fromConfigTrustedLocalRoots
in
(Bool
b Bool -> Bool -> Bool
&& Set PeerAddr
tp Set PeerAddr -> Set PeerAddr -> Bool
forall a. Ord a => Set a -> Set a -> Bool
`Set.isSubsetOf` Set PeerAddr
kp')
Bool -> Bool -> Bool
|| Bool -> Bool
not Bool
b)
((,,) (Bool
-> (Set PeerAddr, Set PeerAddr)
-> Set PeerAddr
-> (Bool, (Set PeerAddr, Set PeerAddr), Set PeerAddr))
-> Signal Bool
-> Signal
((Set PeerAddr, Set PeerAddr)
-> Set PeerAddr
-> (Bool, (Set PeerAddr, Set PeerAddr), Set PeerAddr))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Signal Bool
isInCleanState
Signal
((Set PeerAddr, Set PeerAddr)
-> Set PeerAddr
-> (Bool, (Set PeerAddr, Set PeerAddr), Set PeerAddr))
-> Signal (Set PeerAddr, Set PeerAddr)
-> Signal
(Set PeerAddr
-> (Bool, (Set PeerAddr, Set PeerAddr), Set PeerAddr))
forall a b. Signal (a -> b) -> Signal a -> Signal b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Signal (Set PeerAddr, Set PeerAddr)
govKnownAndTrustedPeers
Signal
(Set PeerAddr
-> (Bool, (Set PeerAddr, Set PeerAddr), Set PeerAddr))
-> Signal (Set PeerAddr)
-> Signal (Bool, (Set PeerAddr, Set PeerAddr), Set PeerAddr)
forall a b. Signal (a -> b) -> Signal a -> Signal b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Signal (Set PeerAddr)
configTrustedLocalRoots
)
prop_governor_stops_using_bootstrap_peers :: GovernorMockEnvironment -> Property
prop_governor_stops_using_bootstrap_peers :: GovernorMockEnvironment -> Property
prop_governor_stops_using_bootstrap_peers GovernorMockEnvironment
env =
let events :: Events TestTraceEvent
events = Time -> [(Time, TestTraceEvent)] -> Events TestTraceEvent
forall a. Time -> [(Time, a)] -> Events a
Signal.eventsFromListUpToTime (DiffTime -> Time
Time (DiffTime
10 DiffTime -> DiffTime -> DiffTime
forall a. Num a => a -> a -> a
* DiffTime
60 DiffTime -> DiffTime -> DiffTime
forall a. Num a => a -> a -> a
* DiffTime
60))
([(Time, TestTraceEvent)] -> Events TestTraceEvent)
-> (GovernorMockEnvironment -> [(Time, TestTraceEvent)])
-> GovernorMockEnvironment
-> Events TestTraceEvent
forall b c a. (b -> c) -> (a -> b) -> a -> c
. SimTrace Void -> [(Time, TestTraceEvent)]
forall a. SimTrace a -> [(Time, TestTraceEvent)]
selectPeerSelectionTraceEvents
(SimTrace Void -> [(Time, TestTraceEvent)])
-> (GovernorMockEnvironment -> SimTrace Void)
-> GovernorMockEnvironment
-> [(Time, TestTraceEvent)]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. GovernorMockEnvironment -> SimTrace Void
runGovernorInMockEnvironment
(GovernorMockEnvironment -> Events TestTraceEvent)
-> GovernorMockEnvironment -> Events TestTraceEvent
forall a b. (a -> b) -> a -> b
$ GovernorMockEnvironment
env
govUseBootstrapPeers :: Signal UseBootstrapPeers
govUseBootstrapPeers :: Signal UseBootstrapPeers
govUseBootstrapPeers =
(forall peerconn.
PeerSelectionState PeerAddr peerconn -> UseBootstrapPeers)
-> ConsensusMode
-> Events TestTraceEvent
-> Signal UseBootstrapPeers
forall a.
Eq a =>
(forall peerconn. PeerSelectionState PeerAddr peerconn -> a)
-> ConsensusMode -> Events TestTraceEvent -> Signal a
selectGovState PeerSelectionState PeerAddr peerconn -> UseBootstrapPeers
forall peerconn.
PeerSelectionState PeerAddr peerconn -> UseBootstrapPeers
forall peeraddr peerconn.
PeerSelectionState peeraddr peerconn -> UseBootstrapPeers
Governor.bootstrapPeersFlag (GovernorMockEnvironment -> ConsensusMode
consensusMode GovernorMockEnvironment
env) Events TestTraceEvent
events
govLedgerStateJudgement :: Signal LedgerStateJudgement
govLedgerStateJudgement :: Signal LedgerStateJudgement
govLedgerStateJudgement =
(forall peerconn.
PeerSelectionState PeerAddr peerconn -> LedgerStateJudgement)
-> ConsensusMode
-> Events TestTraceEvent
-> Signal LedgerStateJudgement
forall a.
Eq a =>
(forall peerconn. PeerSelectionState PeerAddr peerconn -> a)
-> ConsensusMode -> Events TestTraceEvent -> Signal a
selectGovState (PeerSelectionState PeerAddr peerconn -> LedgerStateJudgement
forall peeraddr peerconn.
PeerSelectionState peeraddr peerconn -> LedgerStateJudgement
Governor.ledgerStateJudgement) (GovernorMockEnvironment -> ConsensusMode
consensusMode GovernorMockEnvironment
env) Events TestTraceEvent
events
govKnownPeers :: Signal (Set PeerAddr)
govKnownPeers :: Signal (Set PeerAddr)
govKnownPeers =
(forall peerconn.
PeerSelectionState PeerAddr peerconn -> Set PeerAddr)
-> ConsensusMode -> Events TestTraceEvent -> Signal (Set PeerAddr)
forall a.
Eq a =>
(forall peerconn. PeerSelectionState PeerAddr peerconn -> a)
-> ConsensusMode -> Events TestTraceEvent -> Signal a
selectGovState (KnownPeers PeerAddr -> Set PeerAddr
forall peeraddr. KnownPeers peeraddr -> Set peeraddr
KnownPeers.toSet (KnownPeers PeerAddr -> Set PeerAddr)
-> (PeerSelectionState PeerAddr peerconn -> KnownPeers PeerAddr)
-> PeerSelectionState PeerAddr peerconn
-> Set PeerAddr
forall b c a. (b -> c) -> (a -> b) -> a -> c
. PeerSelectionState PeerAddr peerconn -> KnownPeers PeerAddr
forall peeraddr peerconn.
PeerSelectionState peeraddr peerconn -> KnownPeers peeraddr
Governor.knownPeers) (GovernorMockEnvironment -> ConsensusMode
consensusMode GovernorMockEnvironment
env) Events TestTraceEvent
events
govBootstrapPeers :: Signal (Set PeerAddr)
govBootstrapPeers :: Signal (Set PeerAddr)
govBootstrapPeers =
(forall peerconn.
PeerSelectionState PeerAddr peerconn -> Set PeerAddr)
-> ConsensusMode -> Events TestTraceEvent -> Signal (Set PeerAddr)
forall a.
Eq a =>
(forall peerconn. PeerSelectionState PeerAddr peerconn -> a)
-> ConsensusMode -> Events TestTraceEvent -> Signal a
selectGovState (PublicRootPeers PeerAddr -> Set PeerAddr
forall peeraddr. PublicRootPeers peeraddr -> Set peeraddr
PublicRootPeers.getBootstrapPeers (PublicRootPeers PeerAddr -> Set PeerAddr)
-> (PeerSelectionState PeerAddr peerconn
-> PublicRootPeers PeerAddr)
-> PeerSelectionState PeerAddr peerconn
-> Set PeerAddr
forall b c a. (b -> c) -> (a -> b) -> a -> c
. PeerSelectionState PeerAddr peerconn -> PublicRootPeers PeerAddr
forall peeraddr peerconn.
PeerSelectionState peeraddr peerconn -> PublicRootPeers peeraddr
Governor.publicRootPeers)
(GovernorMockEnvironment -> ConsensusMode
consensusMode GovernorMockEnvironment
env)
Events TestTraceEvent
events
govTrustableLocalRootPeers :: Signal (Set PeerAddr)
govTrustableLocalRootPeers :: Signal (Set PeerAddr)
govTrustableLocalRootPeers =
(forall peerconn.
PeerSelectionState PeerAddr peerconn -> Set PeerAddr)
-> ConsensusMode -> Events TestTraceEvent -> Signal (Set PeerAddr)
forall a.
Eq a =>
(forall peerconn. PeerSelectionState PeerAddr peerconn -> a)
-> ConsensusMode -> Events TestTraceEvent -> Signal a
selectGovState
(\PeerSelectionState PeerAddr peerconn
st -> LocalRootPeers PeerAddr -> Set PeerAddr
forall peeraddr. LocalRootPeers peeraddr -> Set peeraddr
LocalRootPeers.keysSet (LocalRootPeers PeerAddr -> LocalRootPeers PeerAddr
forall peeraddr.
Ord peeraddr =>
LocalRootPeers peeraddr -> LocalRootPeers peeraddr
LocalRootPeers.clampToTrustable (PeerSelectionState PeerAddr peerconn -> LocalRootPeers PeerAddr
forall peeraddr peerconn.
PeerSelectionState peeraddr peerconn -> LocalRootPeers peeraddr
Governor.localRootPeers PeerSelectionState PeerAddr peerconn
st))
)
(GovernorMockEnvironment -> ConsensusMode
consensusMode GovernorMockEnvironment
env)
Events TestTraceEvent
events
keepBootstrapPeersTooLong :: Signal (Set ())
keepBootstrapPeersTooLong :: Signal (Set ())
keepBootstrapPeersTooLong =
DiffTime
-> ((Set PeerAddr, Set PeerAddr, Set PeerAddr, UseBootstrapPeers,
LedgerStateJudgement)
-> Set ())
-> Signal
(Set PeerAddr, Set PeerAddr, Set PeerAddr, UseBootstrapPeers,
LedgerStateJudgement)
-> Signal (Set ())
forall a b.
Ord b =>
DiffTime -> (a -> Set b) -> Signal a -> Signal (Set b)
Signal.keyedTimeout
DiffTime
10
(\(Set PeerAddr
knownPeers, Set PeerAddr
trustableLocalRootPeers, Set PeerAddr
bootstrapPeers, UseBootstrapPeers
useBootstrapPeers, LedgerStateJudgement
lsj) ->
if UseBootstrapPeers -> LedgerStateJudgement -> Bool
requiresBootstrapPeers UseBootstrapPeers
useBootstrapPeers LedgerStateJudgement
lsj
then if Bool -> Bool
not (Set PeerAddr -> Bool
forall a. Set a -> Bool
Set.null (Set PeerAddr
knownPeers Set PeerAddr -> Set PeerAddr -> Set PeerAddr
forall a. Ord a => Set a -> Set a -> Set a
Set.\\ Set PeerAddr
bootstrapPeers Set PeerAddr -> Set PeerAddr -> Set PeerAddr
forall a. Ord a => Set a -> Set a -> Set a
Set.\\ Set PeerAddr
trustableLocalRootPeers))
Bool -> Bool -> Bool
|| Set PeerAddr -> Bool
forall a. Set a -> Bool
Set.null Set PeerAddr
knownPeers
then Set ()
forall a. Set a
Set.empty
else () -> Set ()
forall a. a -> Set a
Set.singleton ()
else Set ()
forall a. Set a
Set.empty
)
((,,,,) (Set PeerAddr
-> Set PeerAddr
-> Set PeerAddr
-> UseBootstrapPeers
-> LedgerStateJudgement
-> (Set PeerAddr, Set PeerAddr, Set PeerAddr, UseBootstrapPeers,
LedgerStateJudgement))
-> Signal (Set PeerAddr)
-> Signal
(Set PeerAddr
-> Set PeerAddr
-> UseBootstrapPeers
-> LedgerStateJudgement
-> (Set PeerAddr, Set PeerAddr, Set PeerAddr, UseBootstrapPeers,
LedgerStateJudgement))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Signal (Set PeerAddr)
govKnownPeers
Signal
(Set PeerAddr
-> Set PeerAddr
-> UseBootstrapPeers
-> LedgerStateJudgement
-> (Set PeerAddr, Set PeerAddr, Set PeerAddr, UseBootstrapPeers,
LedgerStateJudgement))
-> Signal (Set PeerAddr)
-> Signal
(Set PeerAddr
-> UseBootstrapPeers
-> LedgerStateJudgement
-> (Set PeerAddr, Set PeerAddr, Set PeerAddr, UseBootstrapPeers,
LedgerStateJudgement))
forall a b. Signal (a -> b) -> Signal a -> Signal b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Signal (Set PeerAddr)
govTrustableLocalRootPeers
Signal
(Set PeerAddr
-> UseBootstrapPeers
-> LedgerStateJudgement
-> (Set PeerAddr, Set PeerAddr, Set PeerAddr, UseBootstrapPeers,
LedgerStateJudgement))
-> Signal (Set PeerAddr)
-> Signal
(UseBootstrapPeers
-> LedgerStateJudgement
-> (Set PeerAddr, Set PeerAddr, Set PeerAddr, UseBootstrapPeers,
LedgerStateJudgement))
forall a b. Signal (a -> b) -> Signal a -> Signal b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Signal (Set PeerAddr)
govBootstrapPeers
Signal
(UseBootstrapPeers
-> LedgerStateJudgement
-> (Set PeerAddr, Set PeerAddr, Set PeerAddr, UseBootstrapPeers,
LedgerStateJudgement))
-> Signal UseBootstrapPeers
-> Signal
(LedgerStateJudgement
-> (Set PeerAddr, Set PeerAddr, Set PeerAddr, UseBootstrapPeers,
LedgerStateJudgement))
forall a b. Signal (a -> b) -> Signal a -> Signal b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Signal UseBootstrapPeers
govUseBootstrapPeers
Signal
(LedgerStateJudgement
-> (Set PeerAddr, Set PeerAddr, Set PeerAddr, UseBootstrapPeers,
LedgerStateJudgement))
-> Signal LedgerStateJudgement
-> Signal
(Set PeerAddr, Set PeerAddr, Set PeerAddr, UseBootstrapPeers,
LedgerStateJudgement)
forall a b. Signal (a -> b) -> Signal a -> Signal b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Signal LedgerStateJudgement
govLedgerStateJudgement
)
in Int
-> (Set () -> TestName)
-> (Set () -> Bool)
-> Signal (Set ())
-> Property
forall a.
Int -> (a -> TestName) -> (a -> Bool) -> Signal a -> Property
signalProperty Int
20 Set () -> TestName
forall a. Show a => a -> TestName
show
Set () -> Bool
forall a. Set a -> Bool
Set.null
Signal (Set ())
keepBootstrapPeersTooLong
prop_governor_uses_ledger_peers :: GovernorMockEnvironment -> Property
prop_governor_uses_ledger_peers :: GovernorMockEnvironment -> Property
prop_governor_uses_ledger_peers GovernorMockEnvironment
env =
let events :: Events TestTraceEvent
events = Time -> [(Time, TestTraceEvent)] -> Events TestTraceEvent
forall a. Time -> [(Time, a)] -> Events a
Signal.eventsFromListUpToTime (DiffTime -> Time
Time (DiffTime
10 DiffTime -> DiffTime -> DiffTime
forall a. Num a => a -> a -> a
* DiffTime
60 DiffTime -> DiffTime -> DiffTime
forall a. Num a => a -> a -> a
* DiffTime
60))
([(Time, TestTraceEvent)] -> Events TestTraceEvent)
-> (GovernorMockEnvironment -> [(Time, TestTraceEvent)])
-> GovernorMockEnvironment
-> Events TestTraceEvent
forall b c a. (b -> c) -> (a -> b) -> a -> c
. SimTrace Void -> [(Time, TestTraceEvent)]
forall a. SimTrace a -> [(Time, TestTraceEvent)]
selectPeerSelectionTraceEvents
(SimTrace Void -> [(Time, TestTraceEvent)])
-> (GovernorMockEnvironment -> SimTrace Void)
-> GovernorMockEnvironment
-> [(Time, TestTraceEvent)]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. GovernorMockEnvironment -> SimTrace Void
runGovernorInMockEnvironment
(GovernorMockEnvironment -> Events TestTraceEvent)
-> GovernorMockEnvironment -> Events TestTraceEvent
forall a b. (a -> b) -> a -> b
$ GovernorMockEnvironment
env
govUseBootstrapPeers :: Signal UseBootstrapPeers
govUseBootstrapPeers :: Signal UseBootstrapPeers
govUseBootstrapPeers =
(forall peerconn.
PeerSelectionState PeerAddr peerconn -> UseBootstrapPeers)
-> ConsensusMode
-> Events TestTraceEvent
-> Signal UseBootstrapPeers
forall a.
Eq a =>
(forall peerconn. PeerSelectionState PeerAddr peerconn -> a)
-> ConsensusMode -> Events TestTraceEvent -> Signal a
selectGovState PeerSelectionState PeerAddr peerconn -> UseBootstrapPeers
forall peerconn.
PeerSelectionState PeerAddr peerconn -> UseBootstrapPeers
forall peeraddr peerconn.
PeerSelectionState peeraddr peerconn -> UseBootstrapPeers
Governor.bootstrapPeersFlag (GovernorMockEnvironment -> ConsensusMode
consensusMode GovernorMockEnvironment
env) Events TestTraceEvent
events
govLedgerStateJudgement :: Signal LedgerStateJudgement
govLedgerStateJudgement :: Signal LedgerStateJudgement
govLedgerStateJudgement =
(forall peerconn.
PeerSelectionState PeerAddr peerconn -> LedgerStateJudgement)
-> ConsensusMode
-> Events TestTraceEvent
-> Signal LedgerStateJudgement
forall a.
Eq a =>
(forall peerconn. PeerSelectionState PeerAddr peerconn -> a)
-> ConsensusMode -> Events TestTraceEvent -> Signal a
selectGovState PeerSelectionState PeerAddr peerconn -> LedgerStateJudgement
forall peerconn.
PeerSelectionState PeerAddr peerconn -> LedgerStateJudgement
forall peeraddr peerconn.
PeerSelectionState peeraddr peerconn -> LedgerStateJudgement
Governor.ledgerStateJudgement (GovernorMockEnvironment -> ConsensusMode
consensusMode GovernorMockEnvironment
env) Events TestTraceEvent
events
govPublicRootPeersResultsSig :: Signal (PublicRootPeers PeerAddr)
govPublicRootPeersResultsSig :: Signal (PublicRootPeers PeerAddr)
govPublicRootPeersResultsSig =
PublicRootPeers PeerAddr
-> Events (PublicRootPeers PeerAddr)
-> Signal (PublicRootPeers PeerAddr)
forall a. a -> Events a -> Signal a
Signal.fromEventsWith (PublicRootPeers PeerAddr
forall peeraddr. PublicRootPeers peeraddr
PublicRootPeers.empty)
(Events (PublicRootPeers PeerAddr)
-> Signal (PublicRootPeers PeerAddr))
-> (Events TestTraceEvent -> Events (PublicRootPeers PeerAddr))
-> Events TestTraceEvent
-> Signal (PublicRootPeers PeerAddr)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (TracePeerSelection PeerAddr -> Maybe (PublicRootPeers PeerAddr))
-> Events (TracePeerSelection PeerAddr)
-> Events (PublicRootPeers PeerAddr)
forall a b. (a -> Maybe b) -> Events a -> Events b
Signal.selectEvents
(\case
TracePublicRootsResults PublicRootPeers PeerAddr
prp Int
_ DiffTime
_ -> PublicRootPeers PeerAddr -> Maybe (PublicRootPeers PeerAddr)
forall a. a -> Maybe a
Just PublicRootPeers PeerAddr
prp
TracePeerSelection PeerAddr
_ -> Maybe (PublicRootPeers PeerAddr)
forall a. Maybe a
Nothing
)
(Events (TracePeerSelection PeerAddr)
-> Events (PublicRootPeers PeerAddr))
-> (Events TestTraceEvent -> Events (TracePeerSelection PeerAddr))
-> Events TestTraceEvent
-> Events (PublicRootPeers PeerAddr)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Events TestTraceEvent -> Events (TracePeerSelection PeerAddr)
selectGovEvents
(Events TestTraceEvent -> Signal (PublicRootPeers PeerAddr))
-> Events TestTraceEvent -> Signal (PublicRootPeers PeerAddr)
forall a b. (a -> b) -> a -> b
$ Events TestTraceEvent
events
usesLedgerPeers :: [(Time, Bool)]
usesLedgerPeers =
Events Bool -> [(Time, Bool)]
forall a. Events a -> [(Time, a)]
Signal.eventsToList
(Events Bool -> [(Time, Bool)]) -> Events Bool -> [(Time, Bool)]
forall a b. (a -> b) -> a -> b
$ Signal Bool -> Events Bool
forall a. Signal a -> Events a
Signal.toChangeEvents
(Signal Bool -> Events Bool) -> Signal Bool -> Events Bool
forall a b. (a -> b) -> a -> b
$ ((\UseBootstrapPeers
ubp LedgerStateJudgement
lsj PublicRootPeers PeerAddr
prp ->
if Bool -> Bool
not (UseBootstrapPeers -> LedgerStateJudgement -> Bool
requiresBootstrapPeers UseBootstrapPeers
ubp LedgerStateJudgement
lsj)
then Set PeerAddr -> Bool
forall a. Set a -> Bool
Set.null (PublicRootPeers PeerAddr -> Set PeerAddr
forall peeraddr. PublicRootPeers peeraddr -> Set peeraddr
PublicRootPeers.getBootstrapPeers PublicRootPeers PeerAddr
prp)
else Bool
True)
(UseBootstrapPeers
-> LedgerStateJudgement -> PublicRootPeers PeerAddr -> Bool)
-> Signal UseBootstrapPeers
-> Signal
(LedgerStateJudgement -> PublicRootPeers PeerAddr -> Bool)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Signal UseBootstrapPeers
govUseBootstrapPeers
Signal (LedgerStateJudgement -> PublicRootPeers PeerAddr -> Bool)
-> Signal LedgerStateJudgement
-> Signal (PublicRootPeers PeerAddr -> Bool)
forall a b. Signal (a -> b) -> Signal a -> Signal b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Signal LedgerStateJudgement
govLedgerStateJudgement
Signal (PublicRootPeers PeerAddr -> Bool)
-> Signal (PublicRootPeers PeerAddr) -> Signal Bool
forall a b. Signal (a -> b) -> Signal a -> Signal b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Signal (PublicRootPeers PeerAddr)
govPublicRootPeersResultsSig
)
in TestName -> Bool -> Property
forall prop. Testable prop => TestName -> prop -> Property
counterexample (TestName -> [TestName] -> TestName
forall a. [a] -> [[a]] -> [a]
intercalate TestName
"\n" ([TestName] -> TestName) -> [TestName] -> TestName
forall a b. (a -> b) -> a -> b
$ ((Time, Bool) -> TestName) -> [(Time, Bool)] -> [TestName]
forall a b. (a -> b) -> [a] -> [b]
map (Time, Bool) -> TestName
forall a. Show a => a -> TestName
show ([(Time, Bool)] -> [TestName]) -> [(Time, Bool)] -> [TestName]
forall a b. (a -> b) -> a -> b
$ [(Time, Bool)]
usesLedgerPeers)
(Bool -> Property) -> Bool -> Property
forall a b. (a -> b) -> a -> b
$ ((Time, Bool) -> Bool) -> [(Time, Bool)] -> Bool
forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
all (Time, Bool) -> Bool
forall a b. (a, b) -> b
snd [(Time, Bool)]
usesLedgerPeers
prop_governor_association_mode :: GovernorMockEnvironment -> Property
prop_governor_association_mode :: GovernorMockEnvironment -> Property
prop_governor_association_mode GovernorMockEnvironment
env =
let events :: Events TestTraceEvent
events = Time -> [(Time, TestTraceEvent)] -> Events TestTraceEvent
forall a. Time -> [(Time, a)] -> Events a
Signal.eventsFromListUpToTime (DiffTime -> Time
Time (DiffTime
10 DiffTime -> DiffTime -> DiffTime
forall a. Num a => a -> a -> a
* DiffTime
60 DiffTime -> DiffTime -> DiffTime
forall a. Num a => a -> a -> a
* DiffTime
60))
([(Time, TestTraceEvent)] -> Events TestTraceEvent)
-> (GovernorMockEnvironment -> [(Time, TestTraceEvent)])
-> GovernorMockEnvironment
-> Events TestTraceEvent
forall b c a. (b -> c) -> (a -> b) -> a -> c
. SimTrace Void -> [(Time, TestTraceEvent)]
forall a. SimTrace a -> [(Time, TestTraceEvent)]
selectPeerSelectionTraceEvents
(SimTrace Void -> [(Time, TestTraceEvent)])
-> (GovernorMockEnvironment -> SimTrace Void)
-> GovernorMockEnvironment
-> [(Time, TestTraceEvent)]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. GovernorMockEnvironment -> SimTrace Void
runGovernorInMockEnvironment
(GovernorMockEnvironment -> Events TestTraceEvent)
-> GovernorMockEnvironment -> Events TestTraceEvent
forall a b. (a -> b) -> a -> b
$ GovernorMockEnvironment
env
counters :: Signal (PeerSelectionSetsWithSizes PeerAddr)
counters :: Signal (PeerSelectionSetsWithSizes PeerAddr)
counters =
(forall peerconn.
PeerSelectionState PeerAddr peerconn
-> PeerSelectionSetsWithSizes PeerAddr)
-> ConsensusMode
-> Events TestTraceEvent
-> Signal (PeerSelectionSetsWithSizes PeerAddr)
forall a.
Eq a =>
(forall peerconn. PeerSelectionState PeerAddr peerconn -> a)
-> ConsensusMode -> Events TestTraceEvent -> Signal a
selectGovState PeerSelectionState PeerAddr peerconn
-> PeerSelectionSetsWithSizes PeerAddr
forall peerconn.
PeerSelectionState PeerAddr peerconn
-> PeerSelectionSetsWithSizes PeerAddr
forall peeraddr peerconn.
Ord peeraddr =>
PeerSelectionState peeraddr peerconn
-> PeerSelectionSetsWithSizes peeraddr
peerSelectionStateToView (GovernorMockEnvironment -> ConsensusMode
consensusMode GovernorMockEnvironment
env) Events TestTraceEvent
events
localRoots :: Signal (Set PeerAddr)
localRoots :: Signal (Set PeerAddr)
localRoots =
(Maybe TestTraceEvent -> Set PeerAddr)
-> (Maybe TestTraceEvent -> Set PeerAddr)
-> (Maybe TestTraceEvent -> Bool)
-> Signal (Maybe TestTraceEvent)
-> Signal (Set PeerAddr)
forall a b.
Ord b =>
(a -> Set b)
-> (a -> Set b) -> (a -> Bool) -> Signal a -> Signal (Set b)
Signal.keyedUntil
(\case
Just (GovernorEvent (TraceLocalRootPeersChanged LocalRootPeers PeerAddr
a LocalRootPeers PeerAddr
_)) -> LocalRootPeers PeerAddr -> Set PeerAddr
forall peeraddr. LocalRootPeers peeraddr -> Set peeraddr
LocalRootPeers.keysSet LocalRootPeers PeerAddr
a
Just (MockEnvEvent (TraceEnvSetLocalRoots LocalRootPeers PeerAddr
a)) -> LocalRootPeers PeerAddr -> Set PeerAddr
forall peeraddr. LocalRootPeers peeraddr -> Set peeraddr
LocalRootPeers.keysSet LocalRootPeers PeerAddr
a
Maybe TestTraceEvent
_ -> Set PeerAddr
forall a. Set a
Set.empty
)
(\Maybe TestTraceEvent
_ -> Set PeerAddr
forall a. Set a
Set.empty)
(\Maybe TestTraceEvent
_ -> Bool
False)
(Signal (Maybe TestTraceEvent) -> Signal (Set PeerAddr))
-> (Events TestTraceEvent -> Signal (Maybe TestTraceEvent))
-> Events TestTraceEvent
-> Signal (Set PeerAddr)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Maybe TestTraceEvent
-> Events (Maybe TestTraceEvent) -> Signal (Maybe TestTraceEvent)
forall a. a -> Events a -> Signal a
Signal.fromChangeEvents Maybe TestTraceEvent
forall a. Maybe a
Nothing
(Events (Maybe TestTraceEvent) -> Signal (Maybe TestTraceEvent))
-> (Events TestTraceEvent -> Events (Maybe TestTraceEvent))
-> Events TestTraceEvent
-> Signal (Maybe TestTraceEvent)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (TestTraceEvent -> Maybe TestTraceEvent)
-> Events TestTraceEvent -> Events (Maybe TestTraceEvent)
forall a b. (a -> b) -> Events a -> Events b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap TestTraceEvent -> Maybe TestTraceEvent
forall a. a -> Maybe a
Just
(Events TestTraceEvent -> Signal (Set PeerAddr))
-> Events TestTraceEvent -> Signal (Set PeerAddr)
forall a b. (a -> b) -> a -> b
$ Events TestTraceEvent
events
publicRoots :: Signal (Set PeerAddr)
publicRoots :: Signal (Set PeerAddr)
publicRoots =
(PublicRootPeers PeerAddr -> Set PeerAddr)
-> (PublicRootPeers PeerAddr -> Set PeerAddr)
-> (PublicRootPeers PeerAddr -> Bool)
-> Signal (PublicRootPeers PeerAddr)
-> Signal (Set PeerAddr)
forall a b.
Ord b =>
(a -> Set b)
-> (a -> Set b) -> (a -> Bool) -> Signal a -> Signal (Set b)
Signal.keyedUntil
PublicRootPeers PeerAddr -> Set PeerAddr
forall peeraddr.
Ord peeraddr =>
PublicRootPeers peeraddr -> Set peeraddr
PublicRootPeers.toSet
(\PublicRootPeers PeerAddr
_ -> Set PeerAddr
forall a. Set a
Set.empty)
(\PublicRootPeers PeerAddr
_ -> Bool
False)
(Signal (PublicRootPeers PeerAddr) -> Signal (Set PeerAddr))
-> (Events TestTraceEvent -> Signal (PublicRootPeers PeerAddr))
-> Events TestTraceEvent
-> Signal (Set PeerAddr)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (forall peerconn.
PeerSelectionState PeerAddr peerconn -> PublicRootPeers PeerAddr)
-> ConsensusMode
-> Events TestTraceEvent
-> Signal (PublicRootPeers PeerAddr)
forall a.
Eq a =>
(forall peerconn. PeerSelectionState PeerAddr peerconn -> a)
-> ConsensusMode -> Events TestTraceEvent -> Signal a
selectGovState PeerSelectionState PeerAddr peerconn -> PublicRootPeers PeerAddr
forall peerconn.
PeerSelectionState PeerAddr peerconn -> PublicRootPeers PeerAddr
forall peeraddr peerconn.
PeerSelectionState peeraddr peerconn -> PublicRootPeers peeraddr
Governor.publicRootPeers
(GovernorMockEnvironment -> ConsensusMode
consensusMode GovernorMockEnvironment
env)
(Events TestTraceEvent -> Signal (Set PeerAddr))
-> Events TestTraceEvent -> Signal (Set PeerAddr)
forall a b. (a -> b) -> a -> b
$ Events TestTraceEvent
events
associationMode :: Signal AssociationMode
associationMode :: Signal AssociationMode
associationMode =
AssociationMode -> Events AssociationMode -> Signal AssociationMode
forall a. a -> Events a -> Signal a
Signal.fromChangeEvents AssociationMode
Unrestricted
(Events AssociationMode -> Signal AssociationMode)
-> Events AssociationMode -> Signal AssociationMode
forall a b. (a -> b) -> a -> b
$ Events TestTraceEvent -> Events AssociationMode
selectGovAssociationMode Events TestTraceEvent
events
in TestName -> Property -> Property
forall prop. Testable prop => TestName -> prop -> Property
counterexample (TestName -> [TestName] -> TestName
forall a. [a] -> [[a]] -> [a]
intercalate TestName
"\n" ([TestName] -> TestName) -> [TestName] -> TestName
forall a b. (a -> b) -> a -> b
$ (Time, TestTraceEvent) -> TestName
forall a. Show a => a -> TestName
show ((Time, TestTraceEvent) -> TestName)
-> [(Time, TestTraceEvent)] -> [TestName]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Events TestTraceEvent -> [(Time, TestTraceEvent)]
forall a. Events a -> [(Time, a)]
Signal.eventsToList Events TestTraceEvent
events)
(Property -> Property) -> Property -> Property
forall a b. (a -> b) -> a -> b
$ Int
-> ((PeerSelectionSetsWithSizes PeerAddr, Set PeerAddr,
Set PeerAddr, AssociationMode)
-> TestName)
-> ((PeerSelectionSetsWithSizes PeerAddr, Set PeerAddr,
Set PeerAddr, AssociationMode)
-> Bool)
-> Signal
(PeerSelectionSetsWithSizes PeerAddr, Set PeerAddr, Set PeerAddr,
AssociationMode)
-> Property
forall a.
Int -> (a -> TestName) -> (a -> Bool) -> Signal a -> Property
signalProperty Int
20 (PeerSelectionSetsWithSizes PeerAddr, Set PeerAddr, Set PeerAddr,
AssociationMode)
-> TestName
forall a. Show a => a -> TestName
show
(\(PeerSelectionSetsWithSizes PeerAddr
cs, Set PeerAddr
localRootSet, Set PeerAddr
publicRootSet, AssociationMode
am) ->
case AssociationMode
am of
AssociationMode
LocalRootsOnly ->
Set PeerAddr -> Bool
forall a. Set a -> Bool
Set.null ((Set PeerAddr, Int) -> Set PeerAddr
forall a b. (a, b) -> a
fst (PeerSelectionSetsWithSizes PeerAddr -> (Set PeerAddr, Int)
forall a. PeerSelectionView a -> a
viewKnownBootstrapPeers PeerSelectionSetsWithSizes PeerAddr
cs)
Set PeerAddr -> Set PeerAddr -> Set PeerAddr
forall a. Ord a => Set a -> Set a -> Set a
Set.\\ Set PeerAddr
localRootSet
Set PeerAddr -> Set PeerAddr -> Set PeerAddr
forall a. Ord a => Set a -> Set a -> Set a
Set.\\ Set PeerAddr
publicRootSet)
Bool -> Bool -> Bool
&& Set PeerAddr -> Bool
forall a. Set a -> Bool
Set.null ((Set PeerAddr, Int) -> Set PeerAddr
forall a b. (a, b) -> a
fst (PeerSelectionSetsWithSizes PeerAddr -> (Set PeerAddr, Int)
forall a. PeerSelectionView a -> a
viewKnownBigLedgerPeers PeerSelectionSetsWithSizes PeerAddr
cs)
Set PeerAddr -> Set PeerAddr -> Set PeerAddr
forall a. Ord a => Set a -> Set a -> Set a
Set.\\ Set PeerAddr
localRootSet
Set PeerAddr -> Set PeerAddr -> Set PeerAddr
forall a. Ord a => Set a -> Set a -> Set a
Set.\\ Set PeerAddr
publicRootSet)
Bool -> Bool -> Bool
&& Set PeerAddr -> Bool
forall a. Set a -> Bool
Set.null ((Set PeerAddr, Int) -> Set PeerAddr
forall a b. (a, b) -> a
fst (PeerSelectionSetsWithSizes PeerAddr -> (Set PeerAddr, Int)
forall a. PeerSelectionView a -> a
viewKnownNonRootPeers PeerSelectionSetsWithSizes PeerAddr
cs)
Set PeerAddr -> Set PeerAddr -> Set PeerAddr
forall a. Ord a => Set a -> Set a -> Set a
Set.\\ Set PeerAddr
localRootSet
Set PeerAddr -> Set PeerAddr -> Set PeerAddr
forall a. Ord a => Set a -> Set a -> Set a
Set.\\ Set PeerAddr
publicRootSet)
AssociationMode
Unrestricted -> Bool
True
)
((,,,) (PeerSelectionSetsWithSizes PeerAddr
-> Set PeerAddr
-> Set PeerAddr
-> AssociationMode
-> (PeerSelectionSetsWithSizes PeerAddr, Set PeerAddr,
Set PeerAddr, AssociationMode))
-> Signal (PeerSelectionSetsWithSizes PeerAddr)
-> Signal
(Set PeerAddr
-> Set PeerAddr
-> AssociationMode
-> (PeerSelectionSetsWithSizes PeerAddr, Set PeerAddr,
Set PeerAddr, AssociationMode))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Signal (PeerSelectionSetsWithSizes PeerAddr)
counters
Signal
(Set PeerAddr
-> Set PeerAddr
-> AssociationMode
-> (PeerSelectionSetsWithSizes PeerAddr, Set PeerAddr,
Set PeerAddr, AssociationMode))
-> Signal (Set PeerAddr)
-> Signal
(Set PeerAddr
-> AssociationMode
-> (PeerSelectionSetsWithSizes PeerAddr, Set PeerAddr,
Set PeerAddr, AssociationMode))
forall a b. Signal (a -> b) -> Signal a -> Signal b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Signal (Set PeerAddr)
localRoots
Signal
(Set PeerAddr
-> AssociationMode
-> (PeerSelectionSetsWithSizes PeerAddr, Set PeerAddr,
Set PeerAddr, AssociationMode))
-> Signal (Set PeerAddr)
-> Signal
(AssociationMode
-> (PeerSelectionSetsWithSizes PeerAddr, Set PeerAddr,
Set PeerAddr, AssociationMode))
forall a b. Signal (a -> b) -> Signal a -> Signal b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Signal (Set PeerAddr)
publicRoots
Signal
(AssociationMode
-> (PeerSelectionSetsWithSizes PeerAddr, Set PeerAddr,
Set PeerAddr, AssociationMode))
-> Signal AssociationMode
-> Signal
(PeerSelectionSetsWithSizes PeerAddr, Set PeerAddr, Set PeerAddr,
AssociationMode)
forall a b. Signal (a -> b) -> Signal a -> Signal b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Signal AssociationMode
associationMode)
takeFirstNHours :: DiffTime -> [(Time, a)] -> [(Time, a)]
takeFirstNHours :: forall a. DiffTime -> [(Time, a)] -> [(Time, a)]
takeFirstNHours DiffTime
h = ((Time, a) -> Bool) -> [(Time, a)] -> [(Time, a)]
forall a. (a -> Bool) -> [a] -> [a]
takeWhile (\(Time
t,a
_) -> Time
t Time -> Time -> Bool
forall a. Ord a => a -> a -> Bool
< DiffTime -> Time
Time (DiffTime
60DiffTime -> DiffTime -> DiffTime
forall a. Num a => a -> a -> a
*DiffTime
60DiffTime -> DiffTime -> DiffTime
forall a. Num a => a -> a -> a
*DiffTime
h))
selectEnvEvents :: Events TestTraceEvent -> Events TraceMockEnv
selectEnvEvents :: Events TestTraceEvent -> Events TraceMockEnv
selectEnvEvents = (TestTraceEvent -> Maybe TraceMockEnv)
-> Events TestTraceEvent -> Events TraceMockEnv
forall a b. (a -> Maybe b) -> Events a -> Events b
Signal.selectEvents
(\case MockEnvEvent TraceMockEnv
e -> TraceMockEnv -> Maybe TraceMockEnv
forall a. a -> Maybe a
Just (TraceMockEnv -> Maybe TraceMockEnv)
-> TraceMockEnv -> Maybe TraceMockEnv
forall a b. (a -> b) -> a -> b
$! TraceMockEnv
e
TestTraceEvent
_ -> Maybe TraceMockEnv
forall a. Maybe a
Nothing)
selectGovEvents :: Events TestTraceEvent
-> Events (TracePeerSelection PeerAddr)
selectGovEvents :: Events TestTraceEvent -> Events (TracePeerSelection PeerAddr)
selectGovEvents = (TestTraceEvent -> Maybe (TracePeerSelection PeerAddr))
-> Events TestTraceEvent -> Events (TracePeerSelection PeerAddr)
forall a b. (a -> Maybe b) -> Events a -> Events b
Signal.selectEvents
(\case GovernorEvent TracePeerSelection PeerAddr
e -> TracePeerSelection PeerAddr -> Maybe (TracePeerSelection PeerAddr)
forall a. a -> Maybe a
Just (TracePeerSelection PeerAddr
-> Maybe (TracePeerSelection PeerAddr))
-> TracePeerSelection PeerAddr
-> Maybe (TracePeerSelection PeerAddr)
forall a b. (a -> b) -> a -> b
$! TracePeerSelection PeerAddr
e
TestTraceEvent
_ -> Maybe (TracePeerSelection PeerAddr)
forall a. Maybe a
Nothing)
selectGovCounters :: Events TestTraceEvent
-> Events PeerSelectionCounters
selectGovCounters :: Events TestTraceEvent -> Events PeerSelectionCounters
selectGovCounters = (TestTraceEvent -> Maybe PeerSelectionCounters)
-> Events TestTraceEvent -> Events PeerSelectionCounters
forall a b. (a -> Maybe b) -> Events a -> Events b
Signal.selectEvents
(\case GovernorCounters PeerSelectionCounters
e -> PeerSelectionCounters -> Maybe PeerSelectionCounters
forall a. a -> Maybe a
Just (PeerSelectionCounters -> Maybe PeerSelectionCounters)
-> PeerSelectionCounters -> Maybe PeerSelectionCounters
forall a b. (a -> b) -> a -> b
$! PeerSelectionCounters
e
TestTraceEvent
_ -> Maybe PeerSelectionCounters
forall a. Maybe a
Nothing)
selectGovAssociationMode :: Events TestTraceEvent
-> Events AssociationMode
selectGovAssociationMode :: Events TestTraceEvent -> Events AssociationMode
selectGovAssociationMode = (TestTraceEvent -> Maybe AssociationMode)
-> Events TestTraceEvent -> Events AssociationMode
forall a b. (a -> Maybe b) -> Events a -> Events b
Signal.selectEvents
(\case GovernorAssociationMode AssociationMode
e -> AssociationMode -> Maybe AssociationMode
forall a. a -> Maybe a
Just (AssociationMode -> Maybe AssociationMode)
-> AssociationMode -> Maybe AssociationMode
forall a b. (a -> b) -> a -> b
$! AssociationMode
e
TestTraceEvent
_ -> Maybe AssociationMode
forall a. Maybe a
Nothing)
selectGovState :: Eq a
=> (forall peerconn. Governor.PeerSelectionState PeerAddr peerconn -> a)
-> ConsensusMode
-> Events TestTraceEvent
-> Signal a
selectGovState :: forall a.
Eq a =>
(forall peerconn. PeerSelectionState PeerAddr peerconn -> a)
-> ConsensusMode -> Events TestTraceEvent -> Signal a
selectGovState forall peerconn. PeerSelectionState PeerAddr peerconn -> a
f ConsensusMode
consensusMode =
Signal a -> Signal a
forall a. Eq a => Signal a -> Signal a
Signal.nub
(Signal a -> Signal a)
-> (Events TestTraceEvent -> Signal a)
-> Events TestTraceEvent
-> Signal a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> Events a -> Signal a
forall a. a -> Events a -> Signal a
Signal.fromChangeEvents (PeerSelectionState PeerAddr Any -> a
forall peerconn. PeerSelectionState PeerAddr peerconn -> a
f (PeerSelectionState PeerAddr Any -> a)
-> PeerSelectionState PeerAddr Any -> a
forall a b. (a -> b) -> a -> b
$! StdGen
-> ConsensusMode
-> MinBigLedgerPeersForTrustedState
-> PeerSelectionState PeerAddr Any
forall peeraddr peerconn.
StdGen
-> ConsensusMode
-> MinBigLedgerPeersForTrustedState
-> PeerSelectionState peeraddr peerconn
Governor.emptyPeerSelectionState (Int -> StdGen
mkStdGen Int
42) ConsensusMode
consensusMode (Int -> MinBigLedgerPeersForTrustedState
MinBigLedgerPeersForTrustedState Int
0))
(Events a -> Signal a)
-> (Events TestTraceEvent -> Events a)
-> Events TestTraceEvent
-> Signal a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (TestTraceEvent -> Maybe a) -> Events TestTraceEvent -> Events a
forall a b. (a -> Maybe b) -> Events a -> Events b
Signal.selectEvents
(\case GovernorDebug (TraceGovernorState Time
_ Maybe DiffTime
_ PeerSelectionState PeerAddr peerconn
st) -> a -> Maybe a
forall a. a -> Maybe a
Just (a -> Maybe a) -> a -> Maybe a
forall a b. (a -> b) -> a -> b
$! PeerSelectionState PeerAddr peerconn -> a
forall peerconn. PeerSelectionState PeerAddr peerconn -> a
f PeerSelectionState PeerAddr peerconn
st
TestTraceEvent
_ -> Maybe a
forall a. Maybe a
Nothing)
selectEnvTargets :: Eq a
=> (PeerSelectionTargets -> a)
-> Events TestTraceEvent
-> Signal a
selectEnvTargets :: forall a.
Eq a =>
(PeerSelectionTargets -> a) -> Events TestTraceEvent -> Signal a
selectEnvTargets PeerSelectionTargets -> a
f =
Signal a -> Signal a
forall a. Eq a => Signal a -> Signal a
Signal.nub
(Signal a -> Signal a)
-> (Events TestTraceEvent -> Signal a)
-> Events TestTraceEvent
-> Signal a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (PeerSelectionTargets -> a)
-> Signal PeerSelectionTargets -> Signal a
forall a b. (a -> b) -> Signal a -> Signal b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap PeerSelectionTargets -> a
f
(Signal PeerSelectionTargets -> Signal a)
-> (Events TestTraceEvent -> Signal PeerSelectionTargets)
-> Events TestTraceEvent
-> Signal a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. PeerSelectionTargets
-> Events PeerSelectionTargets -> Signal PeerSelectionTargets
forall a. a -> Events a -> Signal a
Signal.fromChangeEvents PeerSelectionTargets
nullPeerSelectionTargets
(Events PeerSelectionTargets -> Signal PeerSelectionTargets)
-> (Events TestTraceEvent -> Events PeerSelectionTargets)
-> Events TestTraceEvent
-> Signal PeerSelectionTargets
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (TraceMockEnv -> Maybe PeerSelectionTargets)
-> Events TraceMockEnv -> Events PeerSelectionTargets
forall a b. (a -> Maybe b) -> Events a -> Events b
Signal.selectEvents
(\case TraceEnvSetTargets PeerSelectionTargets
targets -> PeerSelectionTargets -> Maybe PeerSelectionTargets
forall a. a -> Maybe a
Just (PeerSelectionTargets -> Maybe PeerSelectionTargets)
-> PeerSelectionTargets -> Maybe PeerSelectionTargets
forall a b. (a -> b) -> a -> b
$! PeerSelectionTargets
targets
TraceMockEnv
_ -> Maybe PeerSelectionTargets
forall a. Maybe a
Nothing)
(Events TraceMockEnv -> Events PeerSelectionTargets)
-> (Events TestTraceEvent -> Events TraceMockEnv)
-> Events TestTraceEvent
-> Events PeerSelectionTargets
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Events TestTraceEvent -> Events TraceMockEnv
selectEnvEvents
_governorFindingPublicRoots :: Int
-> STM IO (Map RelayAccessPoint PeerAdvertise)
-> STM IO UseBootstrapPeers
-> STM IO LedgerStateJudgement
-> PeerSharing
-> StrictTVar IO OutboundConnectionsState
-> ConsensusMode
-> IO Void
_governorFindingPublicRoots :: Int
-> STM IO (Map RelayAccessPoint PeerAdvertise)
-> STM IO UseBootstrapPeers
-> STM IO LedgerStateJudgement
-> PeerSharing
-> StrictTVar IO OutboundConnectionsState
-> ConsensusMode
-> IO Void
_governorFindingPublicRoots Int
targetNumberOfRootPeers STM IO (Map RelayAccessPoint PeerAdvertise)
readDomains STM IO UseBootstrapPeers
readUseBootstrapPeers STM IO LedgerStateJudgement
readLedgerStateJudgement PeerSharing
peerSharing StrictTVar IO OutboundConnectionsState
olocVar ConsensusMode
consensusMode = do
countersVar <- PeerSelectionCounters -> IO (StrictTVar IO PeerSelectionCounters)
forall (m :: * -> *) a. MonadSTM m => a -> m (StrictTVar m a)
newTVarIO PeerSelectionCounters
emptyPeerSelectionCounters
publicStateVar <- makePublicPeerSelectionStateVar
debugStateVar <- newTVarIO $ emptyPeerSelectionState (mkStdGen 42) consensusMode (MinBigLedgerPeersForTrustedState 0)
dnsSemaphore <- newLedgerAndPublicRootDNSSemaphore
let interfaces = PeerSelectionInterfaces {
StrictTVar IO PeerSelectionCounters
countersVar :: StrictTVar IO PeerSelectionCounters
countersVar :: StrictTVar IO PeerSelectionCounters
countersVar,
StrictTVar IO (PublicPeerSelectionState SockAddr)
publicStateVar :: StrictTVar IO (PublicPeerSelectionState SockAddr)
publicStateVar :: StrictTVar IO (PublicPeerSelectionState SockAddr)
publicStateVar,
StrictTVar IO (PeerSelectionState SockAddr PeerSharing)
debugStateVar :: StrictTVar IO (PeerSelectionState SockAddr PeerSharing)
debugStateVar :: StrictTVar IO (PeerSelectionState SockAddr PeerSharing)
debugStateVar,
readUseLedgerPeers :: STM IO UseLedgerPeers
readUseLedgerPeers = UseLedgerPeers -> STM UseLedgerPeers
forall a. a -> STM a
forall (m :: * -> *) a. Monad m => a -> m a
return UseLedgerPeers
DontUseLedgerPeers
}
publicRootPeersProvider
tracer
(curry IP.toSockAddr)
dnsSemaphore
DNS.defaultResolvConf
readDomains
(ioDNSActions LookupReqAAndAAAA) $ \Int -> IO (Map SockAddr PeerAdvertise, DiffTime)
requestPublicRootPeers -> do
Tracer IO (TracePeerSelection SockAddr)
-> Tracer IO (DebugPeerSelection SockAddr)
-> Tracer IO PeerSelectionCounters
-> StdGen
-> ConsensusMode
-> MinBigLedgerPeersForTrustedState
-> PeerSelectionActions SockAddr PeerSharing IO
-> PeerSelectionPolicy SockAddr IO
-> PeerSelectionInterfaces SockAddr PeerSharing IO
-> IO Void
forall (m :: * -> *) peeraddr peerconn.
(Alternative (STM m), MonadAsync m, MonadDelay m,
MonadLabelledSTM m, MonadMask m, MonadTimer m, Ord peeraddr,
Show peerconn, Hashable peeraddr) =>
Tracer m (TracePeerSelection peeraddr)
-> Tracer m (DebugPeerSelection peeraddr)
-> Tracer m PeerSelectionCounters
-> StdGen
-> ConsensusMode
-> MinBigLedgerPeersForTrustedState
-> PeerSelectionActions peeraddr peerconn m
-> PeerSelectionPolicy peeraddr m
-> PeerSelectionInterfaces peeraddr peerconn m
-> m Void
peerSelectionGovernor
Tracer IO (TracePeerSelection SockAddr)
forall a. Show a => Tracer IO a
tracer Tracer IO (DebugPeerSelection SockAddr)
forall a. Show a => Tracer IO a
tracer Tracer IO PeerSelectionCounters
forall a. Show a => Tracer IO a
tracer
(Int -> StdGen
mkStdGen Int
42)
ConsensusMode
consensusMode
(Int -> MinBigLedgerPeersForTrustedState
MinBigLedgerPeersForTrustedState Int
0)
PeerSelectionActions SockAddr PeerSharing IO
actions
{ requestPublicRootPeers = \LedgerPeersKind
_ ->
(Int -> IO (Map SockAddr PeerAdvertise, DiffTime))
-> Int -> IO (PublicRootPeers SockAddr, DiffTime)
forall {b}.
(Int -> IO (Map SockAddr PeerAdvertise, b))
-> Int -> IO (PublicRootPeers SockAddr, b)
transformPeerSelectionAction Int -> IO (Map SockAddr PeerAdvertise, DiffTime)
requestPublicRootPeers }
PeerSelectionPolicy SockAddr IO
policy
PeerSelectionInterfaces SockAddr PeerSharing IO
interfaces
where
tracer :: Show a => Tracer IO a
tracer :: forall a. Show a => Tracer IO a
tracer = (a -> IO ()) -> Tracer IO a
forall (m :: * -> *) a. (a -> m ()) -> Tracer m a
Tracer (ByteString -> IO ()
BS.putStrLn (ByteString -> IO ()) -> (a -> ByteString) -> a -> IO ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. TestName -> ByteString
BS.pack (TestName -> ByteString) -> (a -> TestName) -> a -> ByteString
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> TestName
forall a. Show a => a -> TestName
show)
actions :: PeerSelectionActions SockAddr PeerSharing IO
actions :: PeerSelectionActions SockAddr PeerSharing IO
actions = PeerSelectionActions {
ConsensusModePeerTargets
peerTargets :: ConsensusModePeerTargets
peerTargets :: ConsensusModePeerTargets
peerTargets,
readLocalRootPeers :: STM IO (Config SockAddr)
readLocalRootPeers = Config SockAddr -> STM (Config SockAddr)
forall a. a -> STM a
forall (m :: * -> *) a. Monad m => a -> m a
return [],
peerSharing :: PeerSharing
peerSharing = PeerSharing
peerSharing,
readPeerSelectionTargets :: STM IO PeerSelectionTargets
readPeerSelectionTargets = PeerSelectionTargets -> STM PeerSelectionTargets
forall a. a -> STM a
forall (m :: * -> *) a. Monad m => a -> m a
return PeerSelectionTargets
targets,
requestPeerShare :: PeerSharingAmount -> SockAddr -> IO (PeerSharingResult SockAddr)
requestPeerShare = \PeerSharingAmount
_ SockAddr
_ -> PeerSharingResult SockAddr -> IO (PeerSharingResult SockAddr)
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return ([SockAddr] -> PeerSharingResult SockAddr
forall peerAddress. [peerAddress] -> PeerSharingResult peerAddress
PeerSharingResult []),
peerConnToPeerSharing :: PeerSharing -> PeerSharing
peerConnToPeerSharing = PeerSharing -> PeerSharing
forall a. a -> a
id,
requestPublicRootPeers :: LedgerPeersKind -> Int -> IO (PublicRootPeers SockAddr, DiffTime)
requestPublicRootPeers = \LedgerPeersKind
_ Int
_ -> (PublicRootPeers SockAddr, DiffTime)
-> IO (PublicRootPeers SockAddr, DiffTime)
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return (PublicRootPeers SockAddr
forall peeraddr. PublicRootPeers peeraddr
PublicRootPeers.empty, DiffTime
0),
peerStateActions :: PeerStateActions SockAddr PeerSharing IO
peerStateActions = PeerStateActions {
establishPeerConnection :: IsBigLedgerPeer -> DiffusionMode -> SockAddr -> IO PeerSharing
establishPeerConnection = TestName
-> IsBigLedgerPeer -> DiffusionMode -> SockAddr -> IO PeerSharing
forall a. HasCallStack => TestName -> a
error TestName
"establishPeerConnection",
monitorPeerConnection :: PeerSharing -> STM IO (PeerStatus, Maybe RepromoteDelay)
monitorPeerConnection = TestName -> PeerSharing -> STM (PeerStatus, Maybe RepromoteDelay)
forall a. HasCallStack => TestName -> a
error TestName
"monitorPeerConnection",
activatePeerConnection :: IsBigLedgerPeer -> PeerSharing -> IO ()
activatePeerConnection = TestName -> IsBigLedgerPeer -> PeerSharing -> IO ()
forall a. HasCallStack => TestName -> a
error TestName
"activatePeerConnection",
deactivatePeerConnection :: PeerSharing -> IO ()
deactivatePeerConnection = TestName -> PeerSharing -> IO ()
forall a. HasCallStack => TestName -> a
error TestName
"deactivatePeerConnection",
closePeerConnection :: PeerSharing -> IO ()
closePeerConnection = TestName -> PeerSharing -> IO ()
forall a. HasCallStack => TestName -> a
error TestName
"closePeerConnection"
},
STM IO UseBootstrapPeers
readUseBootstrapPeers :: STM IO UseBootstrapPeers
readUseBootstrapPeers :: STM IO UseBootstrapPeers
readUseBootstrapPeers,
readInboundPeers :: IO (Map SockAddr PeerSharing)
readInboundPeers = Map SockAddr PeerSharing -> IO (Map SockAddr PeerSharing)
forall a. a -> IO a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Map SockAddr PeerSharing
forall k a. Map k a
Map.empty,
updateOutboundConnectionsState :: OutboundConnectionsState -> STM IO ()
updateOutboundConnectionsState = \OutboundConnectionsState
a -> do
a' <- StrictTVar IO OutboundConnectionsState
-> STM IO OutboundConnectionsState
forall (m :: * -> *) a. MonadSTM m => StrictTVar m a -> STM m a
readTVar StrictTVar IO OutboundConnectionsState
olocVar
when (a /= a') $
writeTVar olocVar a,
getLedgerStateCtx :: LedgerPeersConsensusInterface IO
getLedgerStateCtx =
LedgerPeersConsensusInterface {
lpGetLatestSlot :: STM IO (WithOrigin SlotNo)
lpGetLatestSlot = WithOrigin SlotNo -> STM (WithOrigin SlotNo)
forall a. a -> STM a
forall (f :: * -> *) a. Applicative f => a -> f a
pure WithOrigin SlotNo
forall t. WithOrigin t
Origin,
lpGetLedgerStateJudgement :: STM IO LedgerStateJudgement
lpGetLedgerStateJudgement = STM IO LedgerStateJudgement
readLedgerStateJudgement,
lpGetLedgerPeers :: STM IO [(PoolStake, NonEmpty RelayAccessPoint)]
lpGetLedgerPeers = [(PoolStake, NonEmpty RelayAccessPoint)]
-> STM [(PoolStake, NonEmpty RelayAccessPoint)]
forall a. a -> STM a
forall (f :: * -> *) a. Applicative f => a -> f a
pure [] },
readLedgerPeerSnapshot :: STM IO (Maybe LedgerPeerSnapshot)
readLedgerPeerSnapshot = Maybe LedgerPeerSnapshot -> STM (Maybe LedgerPeerSnapshot)
forall a. a -> STM a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Maybe LedgerPeerSnapshot
forall a. Maybe a
Nothing
}
targets :: PeerSelectionTargets
targets :: PeerSelectionTargets
targets = PeerSelectionTargets
nullPeerSelectionTargets {
targetNumberOfRootPeers = targetNumberOfRootPeers,
targetNumberOfKnownPeers = targetNumberOfRootPeers
}
peerTargets :: ConsensusModePeerTargets
peerTargets = ConsensusModePeerTargets {
deadlineTargets :: PeerSelectionTargets
deadlineTargets = PeerSelectionTargets
targets,
syncTargets :: PeerSelectionTargets
syncTargets = PeerSelectionTargets
targets}
policy :: PeerSelectionPolicy SockAddr IO
policy :: PeerSelectionPolicy SockAddr IO
policy = PeerSelectionPolicy {
policyPickKnownPeersForPeerShare :: PickPolicy SockAddr (STM IO)
policyPickKnownPeersForPeerShare = \SockAddr -> PeerSource
_ SockAddr -> Int
_ SockAddr -> Bool
_ -> Set SockAddr -> Int -> STM (Set SockAddr)
Set SockAddr -> Int -> STM IO (Set SockAddr)
forall (m :: * -> *).
Applicative m =>
Set SockAddr -> Int -> m (Set SockAddr)
pickTrivially,
policyPickColdPeersToForget :: PickPolicy SockAddr (STM IO)
policyPickColdPeersToForget = \SockAddr -> PeerSource
_ SockAddr -> Int
_ SockAddr -> Bool
_ -> Set SockAddr -> Int -> STM (Set SockAddr)
Set SockAddr -> Int -> STM IO (Set SockAddr)
forall (m :: * -> *).
Applicative m =>
Set SockAddr -> Int -> m (Set SockAddr)
pickTrivially,
policyPickColdPeersToPromote :: PickPolicy SockAddr (STM IO)
policyPickColdPeersToPromote = \SockAddr -> PeerSource
_ SockAddr -> Int
_ SockAddr -> Bool
_ -> Set SockAddr -> Int -> STM (Set SockAddr)
Set SockAddr -> Int -> STM IO (Set SockAddr)
forall (m :: * -> *).
Applicative m =>
Set SockAddr -> Int -> m (Set SockAddr)
pickTrivially,
policyPickWarmPeersToPromote :: PickPolicy SockAddr (STM IO)
policyPickWarmPeersToPromote = \SockAddr -> PeerSource
_ SockAddr -> Int
_ SockAddr -> Bool
_ -> Set SockAddr -> Int -> STM (Set SockAddr)
Set SockAddr -> Int -> STM IO (Set SockAddr)
forall (m :: * -> *).
Applicative m =>
Set SockAddr -> Int -> m (Set SockAddr)
pickTrivially,
policyPickHotPeersToDemote :: PickPolicy SockAddr (STM IO)
policyPickHotPeersToDemote = \SockAddr -> PeerSource
_ SockAddr -> Int
_ SockAddr -> Bool
_ -> Set SockAddr -> Int -> STM (Set SockAddr)
Set SockAddr -> Int -> STM IO (Set SockAddr)
forall (m :: * -> *).
Applicative m =>
Set SockAddr -> Int -> m (Set SockAddr)
pickTrivially,
policyPickWarmPeersToDemote :: PickPolicy SockAddr (STM IO)
policyPickWarmPeersToDemote = \SockAddr -> PeerSource
_ SockAddr -> Int
_ SockAddr -> Bool
_ -> Set SockAddr -> Int -> STM (Set SockAddr)
Set SockAddr -> Int -> STM IO (Set SockAddr)
forall (m :: * -> *).
Applicative m =>
Set SockAddr -> Int -> m (Set SockAddr)
pickTrivially,
policyPickInboundPeers :: PickPolicy SockAddr (STM IO)
policyPickInboundPeers = \SockAddr -> PeerSource
_ SockAddr -> Int
_ SockAddr -> Bool
_ -> Set SockAddr -> Int -> STM (Set SockAddr)
Set SockAddr -> Int -> STM IO (Set SockAddr)
forall (m :: * -> *).
Applicative m =>
Set SockAddr -> Int -> m (Set SockAddr)
pickTrivially,
policyFindPublicRootTimeout :: DiffTime
policyFindPublicRootTimeout = DiffTime
5,
policyMaxInProgressPeerShareReqs :: Int
policyMaxInProgressPeerShareReqs = Int
0,
policyPeerShareRetryTime :: DiffTime
policyPeerShareRetryTime = DiffTime
0,
policyPeerShareBatchWaitTime :: DiffTime
policyPeerShareBatchWaitTime = DiffTime
0,
policyPeerShareOverallTimeout :: DiffTime
policyPeerShareOverallTimeout = DiffTime
0,
policyPeerShareActivationDelay :: DiffTime
policyPeerShareActivationDelay = DiffTime
2,
policyErrorDelay :: DiffTime
policyErrorDelay = DiffTime
0
}
pickTrivially :: Applicative m => Set SockAddr -> Int -> m (Set SockAddr)
pickTrivially :: forall (m :: * -> *).
Applicative m =>
Set SockAddr -> Int -> m (Set SockAddr)
pickTrivially Set SockAddr
m Int
n = Set SockAddr -> m (Set SockAddr)
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Set SockAddr -> m (Set SockAddr))
-> (Set SockAddr -> Set SockAddr)
-> Set SockAddr
-> m (Set SockAddr)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> Set SockAddr -> Set SockAddr
forall {a}. Int -> Set a -> Set a
Set.take Int
n (Set SockAddr -> m (Set SockAddr))
-> Set SockAddr -> m (Set SockAddr)
forall a b. (a -> b) -> a -> b
$ Set SockAddr
m
transformPeerSelectionAction :: (Int -> IO (Map SockAddr PeerAdvertise, b))
-> Int -> IO (PublicRootPeers SockAddr, b)
transformPeerSelectionAction = (IO (Map SockAddr PeerAdvertise, b)
-> IO (PublicRootPeers SockAddr, b))
-> (Int -> IO (Map SockAddr PeerAdvertise, b))
-> Int
-> IO (PublicRootPeers SockAddr, b)
forall a b. (a -> b) -> (Int -> a) -> Int -> b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (((Map SockAddr PeerAdvertise, b) -> (PublicRootPeers SockAddr, b))
-> IO (Map SockAddr PeerAdvertise, b)
-> IO (PublicRootPeers SockAddr, b)
forall a b. (a -> b) -> IO a -> IO b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (\(Map SockAddr PeerAdvertise
a, b
b) -> (Map SockAddr PeerAdvertise
-> Set SockAddr
-> Set SockAddr
-> Set SockAddr
-> PublicRootPeers SockAddr
forall peeraddr.
Ord peeraddr =>
Map peeraddr PeerAdvertise
-> Set peeraddr
-> Set peeraddr
-> Set peeraddr
-> PublicRootPeers peeraddr
PublicRootPeers.fromMapAndSet Map SockAddr PeerAdvertise
a Set SockAddr
forall a. Set a
Set.empty Set SockAddr
forall a. Set a
Set.empty Set SockAddr
forall a. Set a
Set.empty, b
b)))
prop_issue_3550 :: Property
prop_issue_3550 :: Property
prop_issue_3550 = MaxTime -> GovernorMockEnvironment -> Property
prop_governor_target_established_below MaxTime
defaultMaxTime (GovernorMockEnvironment -> Property)
-> GovernorMockEnvironment -> Property
forall a b. (a -> b) -> a -> b
$
GovernorMockEnvironment {
peerGraph :: PeerGraph
peerGraph = [(PeerAddr, [PeerAddr], PeerInfo)] -> PeerGraph
PeerGraph
[ (Int -> PeerAddr
PeerAddr Int
4,[],GovernorScripts {peerShareScript :: PeerShareScript
peerShareScript = NonEmpty (Maybe ([PeerAddr], PeerShareTime)) -> PeerShareScript
forall a. NonEmpty a -> Script a
Script (([PeerAddr], PeerShareTime) -> Maybe ([PeerAddr], PeerShareTime)
forall a. a -> Maybe a
Just ([],PeerShareTime
PeerShareTimeSlow) Maybe ([PeerAddr], PeerShareTime)
-> [Maybe ([PeerAddr], PeerShareTime)]
-> NonEmpty (Maybe ([PeerAddr], PeerShareTime))
forall a. a -> [a] -> NonEmpty a
:| []), peerSharingScript :: PeerSharingScript
peerSharingScript = NonEmpty PeerSharing -> PeerSharingScript
forall a. NonEmpty a -> Script a
Script (PeerSharing
PeerSharingDisabled PeerSharing -> [PeerSharing] -> NonEmpty PeerSharing
forall a. a -> [a] -> NonEmpty a
:| []), connectionScript :: ConnectionScript
connectionScript = NonEmpty (AsyncDemotion, ScriptDelay) -> ConnectionScript
forall a. NonEmpty a -> Script a
Script ((AsyncDemotion
Noop,ScriptDelay
NoDelay) (AsyncDemotion, ScriptDelay)
-> [(AsyncDemotion, ScriptDelay)]
-> NonEmpty (AsyncDemotion, ScriptDelay)
forall a. a -> [a] -> NonEmpty a
:| [])}),
(Int -> PeerAddr
PeerAddr Int
14,[],GovernorScripts {peerShareScript :: PeerShareScript
peerShareScript = NonEmpty (Maybe ([PeerAddr], PeerShareTime)) -> PeerShareScript
forall a. NonEmpty a -> Script a
Script (Maybe ([PeerAddr], PeerShareTime)
forall a. Maybe a
Nothing Maybe ([PeerAddr], PeerShareTime)
-> [Maybe ([PeerAddr], PeerShareTime)]
-> NonEmpty (Maybe ([PeerAddr], PeerShareTime))
forall a. a -> [a] -> NonEmpty a
:| []), peerSharingScript :: PeerSharingScript
peerSharingScript = NonEmpty PeerSharing -> PeerSharingScript
forall a. NonEmpty a -> Script a
Script (PeerSharing
PeerSharingDisabled PeerSharing -> [PeerSharing] -> NonEmpty PeerSharing
forall a. a -> [a] -> NonEmpty a
:| []), connectionScript :: ConnectionScript
connectionScript = NonEmpty (AsyncDemotion, ScriptDelay) -> ConnectionScript
forall a. NonEmpty a -> Script a
Script ((AsyncDemotion
Noop,ScriptDelay
NoDelay) (AsyncDemotion, ScriptDelay)
-> [(AsyncDemotion, ScriptDelay)]
-> NonEmpty (AsyncDemotion, ScriptDelay)
forall a. a -> [a] -> NonEmpty a
:| [])}),
(Int -> PeerAddr
PeerAddr Int
16,[],GovernorScripts {peerShareScript :: PeerShareScript
peerShareScript = NonEmpty (Maybe ([PeerAddr], PeerShareTime)) -> PeerShareScript
forall a. NonEmpty a -> Script a
Script (Maybe ([PeerAddr], PeerShareTime)
forall a. Maybe a
Nothing Maybe ([PeerAddr], PeerShareTime)
-> [Maybe ([PeerAddr], PeerShareTime)]
-> NonEmpty (Maybe ([PeerAddr], PeerShareTime))
forall a. a -> [a] -> NonEmpty a
:| []), peerSharingScript :: PeerSharingScript
peerSharingScript = NonEmpty PeerSharing -> PeerSharingScript
forall a. NonEmpty a -> Script a
Script (PeerSharing
PeerSharingDisabled PeerSharing -> [PeerSharing] -> NonEmpty PeerSharing
forall a. a -> [a] -> NonEmpty a
:| []), connectionScript :: ConnectionScript
connectionScript = NonEmpty (AsyncDemotion, ScriptDelay) -> ConnectionScript
forall a. NonEmpty a -> Script a
Script ((AsyncDemotion
Noop,ScriptDelay
NoDelay) (AsyncDemotion, ScriptDelay)
-> [(AsyncDemotion, ScriptDelay)]
-> NonEmpty (AsyncDemotion, ScriptDelay)
forall a. a -> [a] -> NonEmpty a
:| [])}),
(Int -> PeerAddr
PeerAddr Int
29,[],GovernorScripts {peerShareScript :: PeerShareScript
peerShareScript = NonEmpty (Maybe ([PeerAddr], PeerShareTime)) -> PeerShareScript
forall a. NonEmpty a -> Script a
Script (Maybe ([PeerAddr], PeerShareTime)
forall a. Maybe a
Nothing Maybe ([PeerAddr], PeerShareTime)
-> [Maybe ([PeerAddr], PeerShareTime)]
-> NonEmpty (Maybe ([PeerAddr], PeerShareTime))
forall a. a -> [a] -> NonEmpty a
:| []), peerSharingScript :: PeerSharingScript
peerSharingScript = NonEmpty PeerSharing -> PeerSharingScript
forall a. NonEmpty a -> Script a
Script (PeerSharing
PeerSharingDisabled PeerSharing -> [PeerSharing] -> NonEmpty PeerSharing
forall a. a -> [a] -> NonEmpty a
:| []), connectionScript :: ConnectionScript
connectionScript = NonEmpty (AsyncDemotion, ScriptDelay) -> ConnectionScript
forall a. NonEmpty a -> Script a
Script ((AsyncDemotion
ToWarm,ScriptDelay
NoDelay) (AsyncDemotion, ScriptDelay)
-> [(AsyncDemotion, ScriptDelay)]
-> NonEmpty (AsyncDemotion, ScriptDelay)
forall a. a -> [a] -> NonEmpty a
:| [(AsyncDemotion
ToCold,ScriptDelay
NoDelay),(AsyncDemotion
Noop,ScriptDelay
NoDelay)])})
],
localRootPeers :: LocalRootPeers PeerAddr
localRootPeers = [(HotValency, WarmValency, Map PeerAddr LocalRootConfig)]
-> LocalRootPeers PeerAddr
forall peeraddr.
Ord peeraddr =>
[(HotValency, WarmValency, Map peeraddr LocalRootConfig)]
-> LocalRootPeers peeraddr
LocalRootPeers.fromGroups
[ (HotValency
1, WarmValency
1, [(PeerAddr, LocalRootConfig)] -> Map PeerAddr LocalRootConfig
forall k a. Ord k => [(k, a)] -> Map k a
Map.fromList [(Int -> PeerAddr
PeerAddr Int
16, PeerAdvertise -> PeerTrustable -> DiffusionMode -> LocalRootConfig
LocalRootConfig PeerAdvertise
DoAdvertisePeer PeerTrustable
IsNotTrustable DiffusionMode
InitiatorAndResponderDiffusionMode)])
, (HotValency
1, WarmValency
1, [(PeerAddr, LocalRootConfig)] -> Map PeerAddr LocalRootConfig
forall k a. Ord k => [(k, a)] -> Map k a
Map.fromList [(Int -> PeerAddr
PeerAddr Int
4, PeerAdvertise -> PeerTrustable -> DiffusionMode -> LocalRootConfig
LocalRootConfig PeerAdvertise
DoAdvertisePeer PeerTrustable
IsNotTrustable DiffusionMode
InitiatorAndResponderDiffusionMode)])
],
publicRootPeers :: PublicRootPeers PeerAddr
publicRootPeers = Map PeerAddr PeerAdvertise -> PublicRootPeers PeerAddr
forall peeraddr.
Map peeraddr PeerAdvertise -> PublicRootPeers peeraddr
PublicRootPeers.fromPublicRootPeers
([(PeerAddr, PeerAdvertise)] -> Map PeerAddr PeerAdvertise
forall k a. Ord k => [(k, a)] -> Map k a
Map.fromList [ (Int -> PeerAddr
PeerAddr Int
14, PeerAdvertise
DoNotAdvertisePeer)
, (Int -> PeerAddr
PeerAddr Int
29, PeerAdvertise
DoNotAdvertisePeer)
]
),
targets :: TimedScript ConsensusModePeerTargets
targets = NonEmpty (ConsensusModePeerTargets, ScriptDelay)
-> TimedScript ConsensusModePeerTargets
forall a. NonEmpty a -> Script a
Script
((ConsensusModePeerTargets {
deadlineTargets :: PeerSelectionTargets
deadlineTargets = PeerSelectionTargets
nullPeerSelectionTargets {
targetNumberOfRootPeers = 1,
targetNumberOfKnownPeers = 4,
targetNumberOfEstablishedPeers = 4,
targetNumberOfActivePeers = 3 },
syncTargets :: PeerSelectionTargets
syncTargets = PeerSelectionTargets
nullPeerSelectionTargets },
ScriptDelay
NoDelay) (ConsensusModePeerTargets, ScriptDelay)
-> [(ConsensusModePeerTargets, ScriptDelay)]
-> NonEmpty (ConsensusModePeerTargets, ScriptDelay)
forall a. a -> [a] -> NonEmpty a
:| []),
pickKnownPeersForPeerShare :: PickScript PeerAddr
pickKnownPeersForPeerShare = NonEmpty (PickMembers PeerAddr) -> PickScript PeerAddr
forall a. NonEmpty a -> Script a
Script (PickMembers PeerAddr
forall peeraddr. PickMembers peeraddr
PickFirst PickMembers PeerAddr
-> [PickMembers PeerAddr] -> NonEmpty (PickMembers PeerAddr)
forall a. a -> [a] -> NonEmpty a
:| []),
pickColdPeersToPromote :: PickScript PeerAddr
pickColdPeersToPromote = NonEmpty (PickMembers PeerAddr) -> PickScript PeerAddr
forall a. NonEmpty a -> Script a
Script (PickMembers PeerAddr
forall peeraddr. PickMembers peeraddr
PickFirst PickMembers PeerAddr
-> [PickMembers PeerAddr] -> NonEmpty (PickMembers PeerAddr)
forall a. a -> [a] -> NonEmpty a
:| []),
pickWarmPeersToPromote :: PickScript PeerAddr
pickWarmPeersToPromote = NonEmpty (PickMembers PeerAddr) -> PickScript PeerAddr
forall a. NonEmpty a -> Script a
Script (PickMembers PeerAddr
forall peeraddr. PickMembers peeraddr
PickFirst PickMembers PeerAddr
-> [PickMembers PeerAddr] -> NonEmpty (PickMembers PeerAddr)
forall a. a -> [a] -> NonEmpty a
:| []),
pickHotPeersToDemote :: PickScript PeerAddr
pickHotPeersToDemote = NonEmpty (PickMembers PeerAddr) -> PickScript PeerAddr
forall a. NonEmpty a -> Script a
Script (Set PeerAddr -> PickMembers PeerAddr
forall peeraddr. Set peeraddr -> PickMembers peeraddr
PickSome ([PeerAddr] -> Set PeerAddr
forall a. Ord a => [a] -> Set a
Set.fromList [Int -> PeerAddr
PeerAddr Int
29]) PickMembers PeerAddr
-> [PickMembers PeerAddr] -> NonEmpty (PickMembers PeerAddr)
forall a. a -> [a] -> NonEmpty a
:| []),
pickWarmPeersToDemote :: PickScript PeerAddr
pickWarmPeersToDemote = NonEmpty (PickMembers PeerAddr) -> PickScript PeerAddr
forall a. NonEmpty a -> Script a
Script (PickMembers PeerAddr
forall peeraddr. PickMembers peeraddr
PickFirst PickMembers PeerAddr
-> [PickMembers PeerAddr] -> NonEmpty (PickMembers PeerAddr)
forall a. a -> [a] -> NonEmpty a
:| []),
pickColdPeersToForget :: PickScript PeerAddr
pickColdPeersToForget = NonEmpty (PickMembers PeerAddr) -> PickScript PeerAddr
forall a. NonEmpty a -> Script a
Script (PickMembers PeerAddr
forall peeraddr. PickMembers peeraddr
PickFirst PickMembers PeerAddr
-> [PickMembers PeerAddr] -> NonEmpty (PickMembers PeerAddr)
forall a. a -> [a] -> NonEmpty a
:| []),
pickInboundPeers :: PickScript PeerAddr
pickInboundPeers = NonEmpty (PickMembers PeerAddr) -> PickScript PeerAddr
forall a. NonEmpty a -> Script a
Script (PickMembers PeerAddr
forall peeraddr. PickMembers peeraddr
PickFirst PickMembers PeerAddr
-> [PickMembers PeerAddr] -> NonEmpty (PickMembers PeerAddr)
forall a. a -> [a] -> NonEmpty a
:| []),
peerSharingFlag :: PeerSharing
peerSharingFlag = PeerSharing
PeerSharingEnabled,
consensusMode :: ConsensusMode
consensusMode = ConsensusMode
PraosMode,
useBootstrapPeers :: TimedScript UseBootstrapPeers
useBootstrapPeers = NonEmpty (UseBootstrapPeers, ScriptDelay)
-> TimedScript UseBootstrapPeers
forall a. NonEmpty a -> Script a
Script ((UseBootstrapPeers
DontUseBootstrapPeers, ScriptDelay
NoDelay) (UseBootstrapPeers, ScriptDelay)
-> [(UseBootstrapPeers, ScriptDelay)]
-> NonEmpty (UseBootstrapPeers, ScriptDelay)
forall a. a -> [a] -> NonEmpty a
:| []),
useLedgerPeers :: TimedScript UseLedgerPeers
useLedgerPeers = NonEmpty (UseLedgerPeers, ScriptDelay)
-> TimedScript UseLedgerPeers
forall a. NonEmpty a -> Script a
Script ((AfterSlot -> UseLedgerPeers
UseLedgerPeers AfterSlot
Always, ScriptDelay
NoDelay) (UseLedgerPeers, ScriptDelay)
-> [(UseLedgerPeers, ScriptDelay)]
-> NonEmpty (UseLedgerPeers, ScriptDelay)
forall a. a -> [a] -> NonEmpty a
:| []),
ledgerStateJudgement :: TimedScript LedgerStateJudgement
ledgerStateJudgement = NonEmpty (LedgerStateJudgement, ScriptDelay)
-> TimedScript LedgerStateJudgement
forall a. NonEmpty a -> Script a
Script ((LedgerStateJudgement
YoungEnough, ScriptDelay
NoDelay) (LedgerStateJudgement, ScriptDelay)
-> [(LedgerStateJudgement, ScriptDelay)]
-> NonEmpty (LedgerStateJudgement, ScriptDelay)
forall a. a -> [a] -> NonEmpty a
:| [])
}
prop_issue_3515 :: Property
prop_issue_3515 :: Property
prop_issue_3515 = GovernorMockEnvironment -> Property
prop_governor_nolivelock (GovernorMockEnvironment -> Property)
-> GovernorMockEnvironment -> Property
forall a b. (a -> b) -> a -> b
$
GovernorMockEnvironment {
peerGraph :: PeerGraph
peerGraph = [(PeerAddr, [PeerAddr], PeerInfo)] -> PeerGraph
PeerGraph
[(Int -> PeerAddr
PeerAddr Int
10,[],GovernorScripts {
peerShareScript :: PeerShareScript
peerShareScript = NonEmpty (Maybe ([PeerAddr], PeerShareTime)) -> PeerShareScript
forall a. NonEmpty a -> Script a
Script (Maybe ([PeerAddr], PeerShareTime)
forall a. Maybe a
Nothing Maybe ([PeerAddr], PeerShareTime)
-> [Maybe ([PeerAddr], PeerShareTime)]
-> NonEmpty (Maybe ([PeerAddr], PeerShareTime))
forall a. a -> [a] -> NonEmpty a
:| []),
peerSharingScript :: PeerSharingScript
peerSharingScript = NonEmpty PeerSharing -> PeerSharingScript
forall a. NonEmpty a -> Script a
Script (PeerSharing
PeerSharingDisabled PeerSharing -> [PeerSharing] -> NonEmpty PeerSharing
forall a. a -> [a] -> NonEmpty a
:| []),
connectionScript :: ConnectionScript
connectionScript = NonEmpty (AsyncDemotion, ScriptDelay) -> ConnectionScript
forall a. NonEmpty a -> Script a
Script ((AsyncDemotion
ToCold,ScriptDelay
NoDelay) (AsyncDemotion, ScriptDelay)
-> [(AsyncDemotion, ScriptDelay)]
-> NonEmpty (AsyncDemotion, ScriptDelay)
forall a. a -> [a] -> NonEmpty a
:| [(AsyncDemotion
Noop,ScriptDelay
NoDelay)])
})],
localRootPeers :: LocalRootPeers PeerAddr
localRootPeers = [(HotValency, WarmValency, Map PeerAddr LocalRootConfig)]
-> LocalRootPeers PeerAddr
forall peeraddr.
Ord peeraddr =>
[(HotValency, WarmValency, Map peeraddr LocalRootConfig)]
-> LocalRootPeers peeraddr
LocalRootPeers.fromGroups [(HotValency
1,WarmValency
1,[(PeerAddr, LocalRootConfig)] -> Map PeerAddr LocalRootConfig
forall k a. Ord k => [(k, a)] -> Map k a
Map.fromList [(Int -> PeerAddr
PeerAddr Int
10, PeerAdvertise -> PeerTrustable -> DiffusionMode -> LocalRootConfig
LocalRootConfig PeerAdvertise
DoAdvertisePeer PeerTrustable
IsNotTrustable DiffusionMode
InitiatorAndResponderDiffusionMode)])],
publicRootPeers :: PublicRootPeers PeerAddr
publicRootPeers = PublicRootPeers PeerAddr
forall peeraddr. PublicRootPeers peeraddr
PublicRootPeers.empty,
targets :: TimedScript ConsensusModePeerTargets
targets = NonEmpty (ConsensusModePeerTargets, ScriptDelay)
-> TimedScript ConsensusModePeerTargets
forall a. NonEmpty a -> Script a
Script (NonEmpty (ConsensusModePeerTargets, ScriptDelay)
-> TimedScript ConsensusModePeerTargets)
-> ([(ConsensusModePeerTargets, ScriptDelay)]
-> NonEmpty (ConsensusModePeerTargets, ScriptDelay))
-> [(ConsensusModePeerTargets, ScriptDelay)]
-> TimedScript ConsensusModePeerTargets
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [(ConsensusModePeerTargets, ScriptDelay)]
-> NonEmpty (ConsensusModePeerTargets, ScriptDelay)
forall a. HasCallStack => [a] -> NonEmpty a
NonEmpty.fromList ([(ConsensusModePeerTargets, ScriptDelay)]
-> TimedScript ConsensusModePeerTargets)
-> [(ConsensusModePeerTargets, ScriptDelay)]
-> TimedScript ConsensusModePeerTargets
forall a b. (a -> b) -> a -> b
$ [(ConsensusModePeerTargets, ScriptDelay)]
targets'',
pickKnownPeersForPeerShare :: PickScript PeerAddr
pickKnownPeersForPeerShare = NonEmpty (PickMembers PeerAddr) -> PickScript PeerAddr
forall a. NonEmpty a -> Script a
Script (PickMembers PeerAddr
forall peeraddr. PickMembers peeraddr
PickFirst PickMembers PeerAddr
-> [PickMembers PeerAddr] -> NonEmpty (PickMembers PeerAddr)
forall a. a -> [a] -> NonEmpty a
:| []),
pickColdPeersToPromote :: PickScript PeerAddr
pickColdPeersToPromote = NonEmpty (PickMembers PeerAddr) -> PickScript PeerAddr
forall a. NonEmpty a -> Script a
Script (PickMembers PeerAddr
forall peeraddr. PickMembers peeraddr
PickFirst PickMembers PeerAddr
-> [PickMembers PeerAddr] -> NonEmpty (PickMembers PeerAddr)
forall a. a -> [a] -> NonEmpty a
:| []),
pickWarmPeersToPromote :: PickScript PeerAddr
pickWarmPeersToPromote = NonEmpty (PickMembers PeerAddr) -> PickScript PeerAddr
forall a. NonEmpty a -> Script a
Script (PickMembers PeerAddr
forall peeraddr. PickMembers peeraddr
PickFirst PickMembers PeerAddr
-> [PickMembers PeerAddr] -> NonEmpty (PickMembers PeerAddr)
forall a. a -> [a] -> NonEmpty a
:| []),
pickHotPeersToDemote :: PickScript PeerAddr
pickHotPeersToDemote = NonEmpty (PickMembers PeerAddr) -> PickScript PeerAddr
forall a. NonEmpty a -> Script a
Script (PickMembers PeerAddr
forall peeraddr. PickMembers peeraddr
PickFirst PickMembers PeerAddr
-> [PickMembers PeerAddr] -> NonEmpty (PickMembers PeerAddr)
forall a. a -> [a] -> NonEmpty a
:| []),
pickWarmPeersToDemote :: PickScript PeerAddr
pickWarmPeersToDemote = NonEmpty (PickMembers PeerAddr) -> PickScript PeerAddr
forall a. NonEmpty a -> Script a
Script (PickMembers PeerAddr
forall peeraddr. PickMembers peeraddr
PickFirst PickMembers PeerAddr
-> [PickMembers PeerAddr] -> NonEmpty (PickMembers PeerAddr)
forall a. a -> [a] -> NonEmpty a
:| []),
pickColdPeersToForget :: PickScript PeerAddr
pickColdPeersToForget = NonEmpty (PickMembers PeerAddr) -> PickScript PeerAddr
forall a. NonEmpty a -> Script a
Script (PickMembers PeerAddr
forall peeraddr. PickMembers peeraddr
PickFirst PickMembers PeerAddr
-> [PickMembers PeerAddr] -> NonEmpty (PickMembers PeerAddr)
forall a. a -> [a] -> NonEmpty a
:| []),
pickInboundPeers :: PickScript PeerAddr
pickInboundPeers = NonEmpty (PickMembers PeerAddr) -> PickScript PeerAddr
forall a. NonEmpty a -> Script a
Script (PickMembers PeerAddr
forall peeraddr. PickMembers peeraddr
PickFirst PickMembers PeerAddr
-> [PickMembers PeerAddr] -> NonEmpty (PickMembers PeerAddr)
forall a. a -> [a] -> NonEmpty a
:| []),
peerSharingFlag :: PeerSharing
peerSharingFlag = PeerSharing
PeerSharingEnabled,
consensusMode :: ConsensusMode
consensusMode = ConsensusMode
PraosMode,
useBootstrapPeers :: TimedScript UseBootstrapPeers
useBootstrapPeers = NonEmpty (UseBootstrapPeers, ScriptDelay)
-> TimedScript UseBootstrapPeers
forall a. NonEmpty a -> Script a
Script ((UseBootstrapPeers
DontUseBootstrapPeers, ScriptDelay
NoDelay) (UseBootstrapPeers, ScriptDelay)
-> [(UseBootstrapPeers, ScriptDelay)]
-> NonEmpty (UseBootstrapPeers, ScriptDelay)
forall a. a -> [a] -> NonEmpty a
:| []),
useLedgerPeers :: TimedScript UseLedgerPeers
useLedgerPeers = NonEmpty (UseLedgerPeers, ScriptDelay)
-> TimedScript UseLedgerPeers
forall a. NonEmpty a -> Script a
Script ((AfterSlot -> UseLedgerPeers
UseLedgerPeers AfterSlot
Always, ScriptDelay
NoDelay) (UseLedgerPeers, ScriptDelay)
-> [(UseLedgerPeers, ScriptDelay)]
-> NonEmpty (UseLedgerPeers, ScriptDelay)
forall a. a -> [a] -> NonEmpty a
:| []),
ledgerStateJudgement :: TimedScript LedgerStateJudgement
ledgerStateJudgement = NonEmpty (LedgerStateJudgement, ScriptDelay)
-> TimedScript LedgerStateJudgement
forall a. NonEmpty a -> Script a
Script ((LedgerStateJudgement
YoungEnough, ScriptDelay
NoDelay) (LedgerStateJudgement, ScriptDelay)
-> [(LedgerStateJudgement, ScriptDelay)]
-> NonEmpty (LedgerStateJudgement, ScriptDelay)
forall a. a -> [a] -> NonEmpty a
:| [])
}
where
targets' :: [(PeerSelectionTargets, ScriptDelay)]
targets' =
[( PeerSelectionTargets
nullPeerSelectionTargets { targetNumberOfKnownPeers = 1 }, ScriptDelay
ShortDelay),
( PeerSelectionTargets
nullPeerSelectionTargets { targetNumberOfKnownPeers = 1 }, ScriptDelay
ShortDelay),
( PeerSelectionTargets
nullPeerSelectionTargets, ScriptDelay
NoDelay),
( PeerSelectionTargets
nullPeerSelectionTargets { targetNumberOfKnownPeers = 1 }, ScriptDelay
NoDelay) ]
targets'' :: [(ConsensusModePeerTargets, ScriptDelay)]
targets'' =
[(ConsensusModePeerTargets { PeerSelectionTargets
deadlineTargets :: PeerSelectionTargets
deadlineTargets :: PeerSelectionTargets
deadlineTargets, syncTargets :: PeerSelectionTargets
syncTargets = PeerSelectionTargets
nullPeerSelectionTargets }, ScriptDelay
delay)
| (PeerSelectionTargets
deadlineTargets, ScriptDelay
delay) <- [(PeerSelectionTargets, ScriptDelay)]
targets']
prop_issue_3494 :: Property
prop_issue_3494 :: Property
prop_issue_3494 = GovernorMockEnvironment -> Property
prop_governor_nofail (GovernorMockEnvironment -> Property)
-> GovernorMockEnvironment -> Property
forall a b. (a -> b) -> a -> b
$
GovernorMockEnvironment {
peerGraph :: PeerGraph
peerGraph = [(PeerAddr, [PeerAddr], PeerInfo)] -> PeerGraph
PeerGraph [(Int -> PeerAddr
PeerAddr Int
64,[],GovernorScripts {
peerShareScript :: PeerShareScript
peerShareScript = NonEmpty (Maybe ([PeerAddr], PeerShareTime)) -> PeerShareScript
forall a. NonEmpty a -> Script a
Script (Maybe ([PeerAddr], PeerShareTime)
forall a. Maybe a
Nothing Maybe ([PeerAddr], PeerShareTime)
-> [Maybe ([PeerAddr], PeerShareTime)]
-> NonEmpty (Maybe ([PeerAddr], PeerShareTime))
forall a. a -> [a] -> NonEmpty a
:| []),
peerSharingScript :: PeerSharingScript
peerSharingScript = NonEmpty PeerSharing -> PeerSharingScript
forall a. NonEmpty a -> Script a
Script (PeerSharing
PeerSharingDisabled PeerSharing -> [PeerSharing] -> NonEmpty PeerSharing
forall a. a -> [a] -> NonEmpty a
:| []),
connectionScript :: ConnectionScript
connectionScript = NonEmpty (AsyncDemotion, ScriptDelay) -> ConnectionScript
forall a. NonEmpty a -> Script a
Script ((AsyncDemotion
ToCold,ScriptDelay
NoDelay) (AsyncDemotion, ScriptDelay)
-> [(AsyncDemotion, ScriptDelay)]
-> NonEmpty (AsyncDemotion, ScriptDelay)
forall a. a -> [a] -> NonEmpty a
:| [(AsyncDemotion
Noop,ScriptDelay
NoDelay)])
})],
localRootPeers :: LocalRootPeers PeerAddr
localRootPeers = [(HotValency, WarmValency, Map PeerAddr LocalRootConfig)]
-> LocalRootPeers PeerAddr
forall peeraddr.
Ord peeraddr =>
[(HotValency, WarmValency, Map peeraddr LocalRootConfig)]
-> LocalRootPeers peeraddr
LocalRootPeers.fromGroups [(HotValency
1,WarmValency
1,[(PeerAddr, LocalRootConfig)] -> Map PeerAddr LocalRootConfig
forall k a. Ord k => [(k, a)] -> Map k a
Map.fromList [(Int -> PeerAddr
PeerAddr Int
64, PeerAdvertise -> PeerTrustable -> DiffusionMode -> LocalRootConfig
LocalRootConfig PeerAdvertise
DoAdvertisePeer PeerTrustable
IsNotTrustable DiffusionMode
InitiatorAndResponderDiffusionMode)])],
publicRootPeers :: PublicRootPeers PeerAddr
publicRootPeers = PublicRootPeers PeerAddr
forall peeraddr. PublicRootPeers peeraddr
PublicRootPeers.empty,
targets :: TimedScript ConsensusModePeerTargets
targets = NonEmpty (ConsensusModePeerTargets, ScriptDelay)
-> TimedScript ConsensusModePeerTargets
forall a. NonEmpty a -> Script a
Script (NonEmpty (ConsensusModePeerTargets, ScriptDelay)
-> TimedScript ConsensusModePeerTargets)
-> ([(ConsensusModePeerTargets, ScriptDelay)]
-> NonEmpty (ConsensusModePeerTargets, ScriptDelay))
-> [(ConsensusModePeerTargets, ScriptDelay)]
-> TimedScript ConsensusModePeerTargets
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [(ConsensusModePeerTargets, ScriptDelay)]
-> NonEmpty (ConsensusModePeerTargets, ScriptDelay)
forall a. HasCallStack => [a] -> NonEmpty a
NonEmpty.fromList ([(ConsensusModePeerTargets, ScriptDelay)]
-> TimedScript ConsensusModePeerTargets)
-> [(ConsensusModePeerTargets, ScriptDelay)]
-> TimedScript ConsensusModePeerTargets
forall a b. (a -> b) -> a -> b
$ [(ConsensusModePeerTargets, ScriptDelay)]
targets'',
pickKnownPeersForPeerShare :: PickScript PeerAddr
pickKnownPeersForPeerShare = NonEmpty (PickMembers PeerAddr) -> PickScript PeerAddr
forall a. NonEmpty a -> Script a
Script (PickMembers PeerAddr
forall peeraddr. PickMembers peeraddr
PickFirst PickMembers PeerAddr
-> [PickMembers PeerAddr] -> NonEmpty (PickMembers PeerAddr)
forall a. a -> [a] -> NonEmpty a
:| []),
pickColdPeersToPromote :: PickScript PeerAddr
pickColdPeersToPromote = NonEmpty (PickMembers PeerAddr) -> PickScript PeerAddr
forall a. NonEmpty a -> Script a
Script (PickMembers PeerAddr
forall peeraddr. PickMembers peeraddr
PickFirst PickMembers PeerAddr
-> [PickMembers PeerAddr] -> NonEmpty (PickMembers PeerAddr)
forall a. a -> [a] -> NonEmpty a
:| []),
pickWarmPeersToPromote :: PickScript PeerAddr
pickWarmPeersToPromote = NonEmpty (PickMembers PeerAddr) -> PickScript PeerAddr
forall a. NonEmpty a -> Script a
Script (PickMembers PeerAddr
forall peeraddr. PickMembers peeraddr
PickFirst PickMembers PeerAddr
-> [PickMembers PeerAddr] -> NonEmpty (PickMembers PeerAddr)
forall a. a -> [a] -> NonEmpty a
:| []),
pickHotPeersToDemote :: PickScript PeerAddr
pickHotPeersToDemote = NonEmpty (PickMembers PeerAddr) -> PickScript PeerAddr
forall a. NonEmpty a -> Script a
Script (PickMembers PeerAddr
forall peeraddr. PickMembers peeraddr
PickFirst PickMembers PeerAddr
-> [PickMembers PeerAddr] -> NonEmpty (PickMembers PeerAddr)
forall a. a -> [a] -> NonEmpty a
:| []),
pickWarmPeersToDemote :: PickScript PeerAddr
pickWarmPeersToDemote = NonEmpty (PickMembers PeerAddr) -> PickScript PeerAddr
forall a. NonEmpty a -> Script a
Script (PickMembers PeerAddr
forall peeraddr. PickMembers peeraddr
PickFirst PickMembers PeerAddr
-> [PickMembers PeerAddr] -> NonEmpty (PickMembers PeerAddr)
forall a. a -> [a] -> NonEmpty a
:| []),
pickColdPeersToForget :: PickScript PeerAddr
pickColdPeersToForget = NonEmpty (PickMembers PeerAddr) -> PickScript PeerAddr
forall a. NonEmpty a -> Script a
Script (PickMembers PeerAddr
forall peeraddr. PickMembers peeraddr
PickFirst PickMembers PeerAddr
-> [PickMembers PeerAddr] -> NonEmpty (PickMembers PeerAddr)
forall a. a -> [a] -> NonEmpty a
:| []),
pickInboundPeers :: PickScript PeerAddr
pickInboundPeers = NonEmpty (PickMembers PeerAddr) -> PickScript PeerAddr
forall a. NonEmpty a -> Script a
Script (PickMembers PeerAddr
forall peeraddr. PickMembers peeraddr
PickFirst PickMembers PeerAddr
-> [PickMembers PeerAddr] -> NonEmpty (PickMembers PeerAddr)
forall a. a -> [a] -> NonEmpty a
:| []),
peerSharingFlag :: PeerSharing
peerSharingFlag = PeerSharing
PeerSharingEnabled,
consensusMode :: ConsensusMode
consensusMode = ConsensusMode
PraosMode,
useBootstrapPeers :: TimedScript UseBootstrapPeers
useBootstrapPeers = NonEmpty (UseBootstrapPeers, ScriptDelay)
-> TimedScript UseBootstrapPeers
forall a. NonEmpty a -> Script a
Script ((UseBootstrapPeers
DontUseBootstrapPeers, ScriptDelay
NoDelay) (UseBootstrapPeers, ScriptDelay)
-> [(UseBootstrapPeers, ScriptDelay)]
-> NonEmpty (UseBootstrapPeers, ScriptDelay)
forall a. a -> [a] -> NonEmpty a
:| []),
useLedgerPeers :: TimedScript UseLedgerPeers
useLedgerPeers = NonEmpty (UseLedgerPeers, ScriptDelay)
-> TimedScript UseLedgerPeers
forall a. NonEmpty a -> Script a
Script ((AfterSlot -> UseLedgerPeers
UseLedgerPeers AfterSlot
Always, ScriptDelay
NoDelay) (UseLedgerPeers, ScriptDelay)
-> [(UseLedgerPeers, ScriptDelay)]
-> NonEmpty (UseLedgerPeers, ScriptDelay)
forall a. a -> [a] -> NonEmpty a
:| []),
ledgerStateJudgement :: TimedScript LedgerStateJudgement
ledgerStateJudgement = NonEmpty (LedgerStateJudgement, ScriptDelay)
-> TimedScript LedgerStateJudgement
forall a. NonEmpty a -> Script a
Script ((LedgerStateJudgement
YoungEnough, ScriptDelay
NoDelay) (LedgerStateJudgement, ScriptDelay)
-> [(LedgerStateJudgement, ScriptDelay)]
-> NonEmpty (LedgerStateJudgement, ScriptDelay)
forall a. a -> [a] -> NonEmpty a
:| [])
}
where
targets' :: [(PeerSelectionTargets, ScriptDelay)]
targets' =
[(PeerSelectionTargets
nullPeerSelectionTargets,ScriptDelay
NoDelay),
(PeerSelectionTargets
nullPeerSelectionTargets { targetNumberOfKnownPeers = 1 },ScriptDelay
ShortDelay),
(PeerSelectionTargets
nullPeerSelectionTargets { targetNumberOfKnownPeers = 1 },ScriptDelay
ShortDelay),
(PeerSelectionTargets
nullPeerSelectionTargets,ScriptDelay
NoDelay),
(PeerSelectionTargets
nullPeerSelectionTargets,ScriptDelay
NoDelay),
(PeerSelectionTargets
nullPeerSelectionTargets { targetNumberOfKnownPeers = 1 },ScriptDelay
NoDelay) ]
targets'' :: [(ConsensusModePeerTargets, ScriptDelay)]
targets'' =
[(ConsensusModePeerTargets { PeerSelectionTargets
deadlineTargets :: PeerSelectionTargets
deadlineTargets :: PeerSelectionTargets
deadlineTargets, syncTargets :: PeerSelectionTargets
syncTargets = PeerSelectionTargets
nullPeerSelectionTargets }, ScriptDelay
delay)
| (PeerSelectionTargets
deadlineTargets, ScriptDelay
delay) <- [(PeerSelectionTargets, ScriptDelay)]
targets']
prop_issue_3233 :: Property
prop_issue_3233 :: Property
prop_issue_3233 = GovernorMockEnvironment -> Property
prop_governor_nolivelock (GovernorMockEnvironment -> Property)
-> GovernorMockEnvironment -> Property
forall a b. (a -> b) -> a -> b
$
GovernorMockEnvironment {
peerGraph :: PeerGraph
peerGraph = [(PeerAddr, [PeerAddr], PeerInfo)] -> PeerGraph
PeerGraph
[(Int -> PeerAddr
PeerAddr Int
4,[],GovernorScripts {
peerShareScript :: PeerShareScript
peerShareScript = NonEmpty (Maybe ([PeerAddr], PeerShareTime)) -> PeerShareScript
forall a. NonEmpty a -> Script a
Script (Maybe ([PeerAddr], PeerShareTime)
forall a. Maybe a
Nothing Maybe ([PeerAddr], PeerShareTime)
-> [Maybe ([PeerAddr], PeerShareTime)]
-> NonEmpty (Maybe ([PeerAddr], PeerShareTime))
forall a. a -> [a] -> NonEmpty a
:| []),
peerSharingScript :: PeerSharingScript
peerSharingScript = NonEmpty PeerSharing -> PeerSharingScript
forall a. NonEmpty a -> Script a
Script (PeerSharing
PeerSharingDisabled PeerSharing -> [PeerSharing] -> NonEmpty PeerSharing
forall a. a -> [a] -> NonEmpty a
:| []),
connectionScript :: ConnectionScript
connectionScript = NonEmpty (AsyncDemotion, ScriptDelay) -> ConnectionScript
forall a. NonEmpty a -> Script a
Script ((AsyncDemotion
ToCold,ScriptDelay
NoDelay)
(AsyncDemotion, ScriptDelay)
-> [(AsyncDemotion, ScriptDelay)]
-> NonEmpty (AsyncDemotion, ScriptDelay)
forall a. a -> [a] -> NonEmpty a
:| [(AsyncDemotion
ToCold,ScriptDelay
NoDelay),
(AsyncDemotion
Noop,ScriptDelay
NoDelay),
(AsyncDemotion
ToWarm,ScriptDelay
NoDelay),
(AsyncDemotion
ToCold,ScriptDelay
NoDelay),
(AsyncDemotion
Noop,ScriptDelay
NoDelay)
])
}),
(Int -> PeerAddr
PeerAddr Int
13,[],GovernorScripts {peerShareScript :: PeerShareScript
peerShareScript = NonEmpty (Maybe ([PeerAddr], PeerShareTime)) -> PeerShareScript
forall a. NonEmpty a -> Script a
Script (Maybe ([PeerAddr], PeerShareTime)
forall a. Maybe a
Nothing Maybe ([PeerAddr], PeerShareTime)
-> [Maybe ([PeerAddr], PeerShareTime)]
-> NonEmpty (Maybe ([PeerAddr], PeerShareTime))
forall a. a -> [a] -> NonEmpty a
:| []), peerSharingScript :: PeerSharingScript
peerSharingScript = NonEmpty PeerSharing -> PeerSharingScript
forall a. NonEmpty a -> Script a
Script (PeerSharing
PeerSharingDisabled PeerSharing -> [PeerSharing] -> NonEmpty PeerSharing
forall a. a -> [a] -> NonEmpty a
:| []), connectionScript :: ConnectionScript
connectionScript = NonEmpty (AsyncDemotion, ScriptDelay) -> ConnectionScript
forall a. NonEmpty a -> Script a
Script ((AsyncDemotion
Noop,ScriptDelay
NoDelay) (AsyncDemotion, ScriptDelay)
-> [(AsyncDemotion, ScriptDelay)]
-> NonEmpty (AsyncDemotion, ScriptDelay)
forall a. a -> [a] -> NonEmpty a
:| [])}),
(Int -> PeerAddr
PeerAddr Int
15,[],GovernorScripts {peerShareScript :: PeerShareScript
peerShareScript = NonEmpty (Maybe ([PeerAddr], PeerShareTime)) -> PeerShareScript
forall a. NonEmpty a -> Script a
Script (([PeerAddr], PeerShareTime) -> Maybe ([PeerAddr], PeerShareTime)
forall a. a -> Maybe a
Just ([],PeerShareTime
PeerShareTimeSlow) Maybe ([PeerAddr], PeerShareTime)
-> [Maybe ([PeerAddr], PeerShareTime)]
-> NonEmpty (Maybe ([PeerAddr], PeerShareTime))
forall a. a -> [a] -> NonEmpty a
:| []), peerSharingScript :: PeerSharingScript
peerSharingScript = NonEmpty PeerSharing -> PeerSharingScript
forall a. NonEmpty a -> Script a
Script (PeerSharing
PeerSharingDisabled PeerSharing -> [PeerSharing] -> NonEmpty PeerSharing
forall a. a -> [a] -> NonEmpty a
:| []), connectionScript :: ConnectionScript
connectionScript = NonEmpty (AsyncDemotion, ScriptDelay) -> ConnectionScript
forall a. NonEmpty a -> Script a
Script ((AsyncDemotion
Noop,ScriptDelay
NoDelay) (AsyncDemotion, ScriptDelay)
-> [(AsyncDemotion, ScriptDelay)]
-> NonEmpty (AsyncDemotion, ScriptDelay)
forall a. a -> [a] -> NonEmpty a
:| [])})
],
localRootPeers :: LocalRootPeers PeerAddr
localRootPeers = [(HotValency, WarmValency, Map PeerAddr LocalRootConfig)]
-> LocalRootPeers PeerAddr
forall peeraddr.
Ord peeraddr =>
[(HotValency, WarmValency, Map peeraddr LocalRootConfig)]
-> LocalRootPeers peeraddr
LocalRootPeers.fromGroups
[ (HotValency
1, WarmValency
1, [(PeerAddr, LocalRootConfig)] -> Map PeerAddr LocalRootConfig
forall k a. Ord k => [(k, a)] -> Map k a
Map.fromList [(Int -> PeerAddr
PeerAddr Int
15, PeerAdvertise -> PeerTrustable -> DiffusionMode -> LocalRootConfig
LocalRootConfig PeerAdvertise
DoAdvertisePeer PeerTrustable
IsNotTrustable DiffusionMode
InitiatorAndResponderDiffusionMode)])
, (HotValency
1, WarmValency
1, [(PeerAddr, LocalRootConfig)] -> Map PeerAddr LocalRootConfig
forall k a. Ord k => [(k, a)] -> Map k a
Map.fromList [(Int -> PeerAddr
PeerAddr Int
13, PeerAdvertise -> PeerTrustable -> DiffusionMode -> LocalRootConfig
LocalRootConfig PeerAdvertise
DoAdvertisePeer PeerTrustable
IsNotTrustable DiffusionMode
InitiatorAndResponderDiffusionMode)])
],
publicRootPeers :: PublicRootPeers PeerAddr
publicRootPeers = Map PeerAddr PeerAdvertise -> PublicRootPeers PeerAddr
forall peeraddr.
Map peeraddr PeerAdvertise -> PublicRootPeers peeraddr
PublicRootPeers.fromPublicRootPeers
([(PeerAddr, PeerAdvertise)] -> Map PeerAddr PeerAdvertise
forall k a. Ord k => [(k, a)] -> Map k a
Map.fromList [(Int -> PeerAddr
PeerAddr Int
4, PeerAdvertise
DoNotAdvertisePeer)]),
targets :: TimedScript ConsensusModePeerTargets
targets = NonEmpty (ConsensusModePeerTargets, ScriptDelay)
-> TimedScript ConsensusModePeerTargets
forall a. NonEmpty a -> Script a
Script (NonEmpty (ConsensusModePeerTargets, ScriptDelay)
-> TimedScript ConsensusModePeerTargets)
-> ([(ConsensusModePeerTargets, ScriptDelay)]
-> NonEmpty (ConsensusModePeerTargets, ScriptDelay))
-> [(ConsensusModePeerTargets, ScriptDelay)]
-> TimedScript ConsensusModePeerTargets
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [(ConsensusModePeerTargets, ScriptDelay)]
-> NonEmpty (ConsensusModePeerTargets, ScriptDelay)
forall a. HasCallStack => [a] -> NonEmpty a
NonEmpty.fromList ([(ConsensusModePeerTargets, ScriptDelay)]
-> TimedScript ConsensusModePeerTargets)
-> [(ConsensusModePeerTargets, ScriptDelay)]
-> TimedScript ConsensusModePeerTargets
forall a b. (a -> b) -> a -> b
$ [(ConsensusModePeerTargets, ScriptDelay)]
targets'',
pickKnownPeersForPeerShare :: PickScript PeerAddr
pickKnownPeersForPeerShare = NonEmpty (PickMembers PeerAddr) -> PickScript PeerAddr
forall a. NonEmpty a -> Script a
Script (PickMembers PeerAddr
forall peeraddr. PickMembers peeraddr
PickFirst PickMembers PeerAddr
-> [PickMembers PeerAddr] -> NonEmpty (PickMembers PeerAddr)
forall a. a -> [a] -> NonEmpty a
:| []),
pickColdPeersToPromote :: PickScript PeerAddr
pickColdPeersToPromote = NonEmpty (PickMembers PeerAddr) -> PickScript PeerAddr
forall a. NonEmpty a -> Script a
Script (PickMembers PeerAddr
forall peeraddr. PickMembers peeraddr
PickFirst PickMembers PeerAddr
-> [PickMembers PeerAddr] -> NonEmpty (PickMembers PeerAddr)
forall a. a -> [a] -> NonEmpty a
:| []),
pickWarmPeersToPromote :: PickScript PeerAddr
pickWarmPeersToPromote = NonEmpty (PickMembers PeerAddr) -> PickScript PeerAddr
forall a. NonEmpty a -> Script a
Script (PickMembers PeerAddr
forall peeraddr. PickMembers peeraddr
PickFirst PickMembers PeerAddr
-> [PickMembers PeerAddr] -> NonEmpty (PickMembers PeerAddr)
forall a. a -> [a] -> NonEmpty a
:| []),
pickHotPeersToDemote :: PickScript PeerAddr
pickHotPeersToDemote = NonEmpty (PickMembers PeerAddr) -> PickScript PeerAddr
forall a. NonEmpty a -> Script a
Script (PickMembers PeerAddr
forall peeraddr. PickMembers peeraddr
PickFirst PickMembers PeerAddr
-> [PickMembers PeerAddr] -> NonEmpty (PickMembers PeerAddr)
forall a. a -> [a] -> NonEmpty a
:| []),
pickWarmPeersToDemote :: PickScript PeerAddr
pickWarmPeersToDemote = NonEmpty (PickMembers PeerAddr) -> PickScript PeerAddr
forall a. NonEmpty a -> Script a
Script (PickMembers PeerAddr
forall peeraddr. PickMembers peeraddr
PickFirst PickMembers PeerAddr
-> [PickMembers PeerAddr] -> NonEmpty (PickMembers PeerAddr)
forall a. a -> [a] -> NonEmpty a
:| []),
pickColdPeersToForget :: PickScript PeerAddr
pickColdPeersToForget = NonEmpty (PickMembers PeerAddr) -> PickScript PeerAddr
forall a. NonEmpty a -> Script a
Script (PickMembers PeerAddr
forall peeraddr. PickMembers peeraddr
PickFirst PickMembers PeerAddr
-> [PickMembers PeerAddr] -> NonEmpty (PickMembers PeerAddr)
forall a. a -> [a] -> NonEmpty a
:| []),
pickInboundPeers :: PickScript PeerAddr
pickInboundPeers = NonEmpty (PickMembers PeerAddr) -> PickScript PeerAddr
forall a. NonEmpty a -> Script a
Script (PickMembers PeerAddr
forall peeraddr. PickMembers peeraddr
PickFirst PickMembers PeerAddr
-> [PickMembers PeerAddr] -> NonEmpty (PickMembers PeerAddr)
forall a. a -> [a] -> NonEmpty a
:| []),
peerSharingFlag :: PeerSharing
peerSharingFlag = PeerSharing
PeerSharingEnabled,
consensusMode :: ConsensusMode
consensusMode = ConsensusMode
PraosMode,
useBootstrapPeers :: TimedScript UseBootstrapPeers
useBootstrapPeers = NonEmpty (UseBootstrapPeers, ScriptDelay)
-> TimedScript UseBootstrapPeers
forall a. NonEmpty a -> Script a
Script ((UseBootstrapPeers
DontUseBootstrapPeers, ScriptDelay
NoDelay) (UseBootstrapPeers, ScriptDelay)
-> [(UseBootstrapPeers, ScriptDelay)]
-> NonEmpty (UseBootstrapPeers, ScriptDelay)
forall a. a -> [a] -> NonEmpty a
:| []),
useLedgerPeers :: TimedScript UseLedgerPeers
useLedgerPeers = NonEmpty (UseLedgerPeers, ScriptDelay)
-> TimedScript UseLedgerPeers
forall a. NonEmpty a -> Script a
Script ((AfterSlot -> UseLedgerPeers
UseLedgerPeers AfterSlot
Always, ScriptDelay
NoDelay) (UseLedgerPeers, ScriptDelay)
-> [(UseLedgerPeers, ScriptDelay)]
-> NonEmpty (UseLedgerPeers, ScriptDelay)
forall a. a -> [a] -> NonEmpty a
:| []),
ledgerStateJudgement :: TimedScript LedgerStateJudgement
ledgerStateJudgement = NonEmpty (LedgerStateJudgement, ScriptDelay)
-> TimedScript LedgerStateJudgement
forall a. NonEmpty a -> Script a
Script ((LedgerStateJudgement
YoungEnough, ScriptDelay
NoDelay) (LedgerStateJudgement, ScriptDelay)
-> [(LedgerStateJudgement, ScriptDelay)]
-> NonEmpty (LedgerStateJudgement, ScriptDelay)
forall a. a -> [a] -> NonEmpty a
:| [])
}
where
targets' :: [(PeerSelectionTargets, ScriptDelay)]
targets' =
[(PeerSelectionTargets
nullPeerSelectionTargets, ScriptDelay
NoDelay),
(PeerSelectionTargets
nullPeerSelectionTargets {
targetNumberOfRootPeers = 1,
targetNumberOfKnownPeers = 3,
targetNumberOfEstablishedPeers = 3
}, ScriptDelay
LongDelay),
(PeerSelectionTargets
nullPeerSelectionTargets, ScriptDelay
NoDelay),
(PeerSelectionTargets
nullPeerSelectionTargets, ScriptDelay
NoDelay),
(PeerSelectionTargets
nullPeerSelectionTargets {
targetNumberOfRootPeers = 1,
targetNumberOfKnownPeers = 3,
targetNumberOfEstablishedPeers = 3,
targetNumberOfActivePeers = 2
}, ScriptDelay
NoDelay)]
targets'' :: [(ConsensusModePeerTargets, ScriptDelay)]
targets'' =
[(ConsensusModePeerTargets { PeerSelectionTargets
deadlineTargets :: PeerSelectionTargets
deadlineTargets :: PeerSelectionTargets
deadlineTargets, syncTargets :: PeerSelectionTargets
syncTargets = PeerSelectionTargets
nullPeerSelectionTargets }, ScriptDelay
delay)
| (PeerSelectionTargets
deadlineTargets, ScriptDelay
delay) <- [(PeerSelectionTargets, ScriptDelay)]
targets']
prop_governor_repromote_delay :: MaxTime -> GovernorMockEnvironment -> Property
prop_governor_repromote_delay :: MaxTime -> GovernorMockEnvironment -> Property
prop_governor_repromote_delay (MaxTime Time
maxTime) GovernorMockEnvironment
env =
let evs :: Events TestTraceEvent
evs = Time -> [(Time, TestTraceEvent)] -> Events TestTraceEvent
forall a. Time -> [(Time, a)] -> Events a
Signal.eventsFromListUpToTime Time
maxTime
([(Time, TestTraceEvent)] -> Events TestTraceEvent)
-> (GovernorMockEnvironment -> [(Time, TestTraceEvent)])
-> GovernorMockEnvironment
-> Events TestTraceEvent
forall b c a. (b -> c) -> (a -> b) -> a -> c
. SimTrace Void -> [(Time, TestTraceEvent)]
forall a. SimTrace a -> [(Time, TestTraceEvent)]
selectPeerSelectionTraceEvents
(SimTrace Void -> [(Time, TestTraceEvent)])
-> (GovernorMockEnvironment -> SimTrace Void)
-> GovernorMockEnvironment
-> [(Time, TestTraceEvent)]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. GovernorMockEnvironment -> SimTrace Void
runGovernorInMockEnvironment
(GovernorMockEnvironment -> Events TestTraceEvent)
-> GovernorMockEnvironment -> Events TestTraceEvent
forall a b. (a -> b) -> a -> b
$ GovernorMockEnvironment
env
in All -> Property
forall prop. Testable prop => prop -> Property
property
(All -> Property)
-> (Events TestTraceEvent -> All)
-> Events TestTraceEvent
-> Property
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (TracePeerSelection PeerAddr -> All)
-> Events (TracePeerSelection PeerAddr) -> All
forall m a. Monoid m => (a -> m) -> Events a -> m
forall (t :: * -> *) m a.
(Foldable t, Monoid m) =>
(a -> m) -> t a -> m
foldMap (\case
TraceDemoteAsynchronous Map PeerAddr (PeerStatus, Maybe RepromoteDelay)
m ->
((PeerStatus, Maybe RepromoteDelay) -> All)
-> Map PeerAddr (PeerStatus, Maybe RepromoteDelay) -> All
forall m a. Monoid m => (a -> m) -> Map PeerAddr a -> m
forall (t :: * -> *) m a.
(Foldable t, Monoid m) =>
(a -> m) -> t a -> m
foldMap
(\(PeerStatus
st, Maybe RepromoteDelay
mx) -> All -> (RepromoteDelay -> All) -> Maybe RepromoteDelay -> All
forall b a. b -> (a -> b) -> Maybe a -> b
maybe All
forall a. Monoid a => a
mempty (\RepromoteDelay
x -> Property -> All
forall p. Testable p => p -> All
All
(Property -> All) -> Property -> All
forall a b. (a -> b) -> a -> b
$ TestName -> Property -> Property
forall prop. Testable prop => TestName -> prop -> Property
counterexample (PeerStatus -> TestName
forall a. Show a => a -> TestName
show PeerStatus
st)
(Property -> Property) -> Property -> Property
forall a b. (a -> b) -> a -> b
$ RepromoteDelay
x RepromoteDelay -> RepromoteDelay -> Property
forall a. (Eq a, Show a) => a -> a -> Property
=/= RepromoteDelay
config_REPROMOTE_DELAY) Maybe RepromoteDelay
mx)
Map PeerAddr (PeerStatus, Maybe RepromoteDelay)
m
TraceDemoteLocalAsynchronous Map PeerAddr (PeerStatus, Maybe RepromoteDelay)
m ->
((PeerStatus, Maybe RepromoteDelay) -> All)
-> Map PeerAddr (PeerStatus, Maybe RepromoteDelay) -> All
forall m a. Monoid m => (a -> m) -> Map PeerAddr a -> m
forall (t :: * -> *) m a.
(Foldable t, Monoid m) =>
(a -> m) -> t a -> m
foldMap
(\(PeerStatus
st, Maybe RepromoteDelay
mx) -> All -> (RepromoteDelay -> All) -> Maybe RepromoteDelay -> All
forall b a. b -> (a -> b) -> Maybe a -> b
maybe All
forall a. Monoid a => a
mempty (\RepromoteDelay
x -> Property -> All
forall p. Testable p => p -> All
All
(Property -> All) -> Property -> All
forall a b. (a -> b) -> a -> b
$ TestName -> Property -> Property
forall prop. Testable prop => TestName -> prop -> Property
counterexample (PeerStatus -> TestName
forall a. Show a => a -> TestName
show PeerStatus
st)
(Property -> Property) -> Property -> Property
forall a b. (a -> b) -> a -> b
$ RepromoteDelay
x RepromoteDelay -> RepromoteDelay -> Property
forall a. (Eq a, Show a) => a -> a -> Property
=/= RepromoteDelay
config_REPROMOTE_DELAY) Maybe RepromoteDelay
mx)
Map PeerAddr (PeerStatus, Maybe RepromoteDelay)
m
TraceDemoteBigLedgerPeersAsynchronous Map PeerAddr (PeerStatus, Maybe RepromoteDelay)
m ->
((PeerStatus, Maybe RepromoteDelay) -> All)
-> Map PeerAddr (PeerStatus, Maybe RepromoteDelay) -> All
forall m a. Monoid m => (a -> m) -> Map PeerAddr a -> m
forall (t :: * -> *) m a.
(Foldable t, Monoid m) =>
(a -> m) -> t a -> m
foldMap
(\(PeerStatus
st, Maybe RepromoteDelay
mx) -> All -> (RepromoteDelay -> All) -> Maybe RepromoteDelay -> All
forall b a. b -> (a -> b) -> Maybe a -> b
maybe All
forall a. Monoid a => a
mempty (\RepromoteDelay
x -> Property -> All
forall p. Testable p => p -> All
All
(Property -> All) -> Property -> All
forall a b. (a -> b) -> a -> b
$ TestName -> Property -> Property
forall prop. Testable prop => TestName -> prop -> Property
counterexample (PeerStatus -> TestName
forall a. Show a => a -> TestName
show PeerStatus
st)
(Property -> Property) -> Property -> Property
forall a b. (a -> b) -> a -> b
$ RepromoteDelay
x RepromoteDelay -> RepromoteDelay -> Property
forall a. (Eq a, Show a) => a -> a -> Property
=/= RepromoteDelay
config_REPROMOTE_DELAY) Maybe RepromoteDelay
mx)
Map PeerAddr (PeerStatus, Maybe RepromoteDelay)
m
TracePeerSelection PeerAddr
_ -> All
forall a. Monoid a => a
mempty
)
(Events (TracePeerSelection PeerAddr) -> All)
-> (Events TestTraceEvent -> Events (TracePeerSelection PeerAddr))
-> Events TestTraceEvent
-> All
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Events TestTraceEvent -> Events (TracePeerSelection PeerAddr)
selectGovEvents
(Events TestTraceEvent -> Property)
-> Events TestTraceEvent -> Property
forall a b. (a -> b) -> a -> b
$ Events TestTraceEvent
evs
newtype MaxTime = MaxTime { MaxTime -> Time
getTime :: Time }
deriving (Int -> MaxTime -> TestName -> TestName
[MaxTime] -> TestName -> TestName
MaxTime -> TestName
(Int -> MaxTime -> TestName -> TestName)
-> (MaxTime -> TestName)
-> ([MaxTime] -> TestName -> TestName)
-> Show MaxTime
forall a.
(Int -> a -> TestName -> TestName)
-> (a -> TestName) -> ([a] -> TestName -> TestName) -> Show a
$cshowsPrec :: Int -> MaxTime -> TestName -> TestName
showsPrec :: Int -> MaxTime -> TestName -> TestName
$cshow :: MaxTime -> TestName
show :: MaxTime -> TestName
$cshowList :: [MaxTime] -> TestName -> TestName
showList :: [MaxTime] -> TestName -> TestName
Show)
defaultMaxTime :: MaxTime
defaultMaxTime :: MaxTime
defaultMaxTime = Time -> MaxTime
MaxTime (DiffTime -> Time
Time (DiffTime
10 DiffTime -> DiffTime -> DiffTime
forall a. Num a => a -> a -> a
* DiffTime
3600))
instance Arbitrary MaxTime where
arbitrary :: Gen MaxTime
arbitrary = MaxTime -> Gen MaxTime
forall a. a -> Gen a
forall (f :: * -> *) a. Applicative f => a -> f a
pure MaxTime
defaultMaxTime
shrink :: MaxTime -> [MaxTime]
shrink (MaxTime (Time DiffTime
t)) =
[ Time -> MaxTime
MaxTime (DiffTime -> Time
Time (Int -> DiffTime
microsecondsAsIntToDiffTime Int
t'))
| Int
t' <- Int -> [Int]
forall a. Arbitrary a => a -> [a]
shrink (DiffTime -> Int
diffTimeToMicrosecondsAsInt DiffTime
t)
]
takeBigLedgerPeers
:: (Governor.PeerSelectionState PeerAddr peerconn -> Set PeerAddr)
-> Governor.PeerSelectionState PeerAddr peerconn -> Set PeerAddr
takeBigLedgerPeers :: forall peerconn.
(PeerSelectionState PeerAddr peerconn -> Set PeerAddr)
-> PeerSelectionState PeerAddr peerconn -> Set PeerAddr
takeBigLedgerPeers PeerSelectionState PeerAddr peerconn -> Set PeerAddr
f =
\PeerSelectionState PeerAddr peerconn
st -> PeerSelectionState PeerAddr peerconn -> Set PeerAddr
f PeerSelectionState PeerAddr peerconn
st Set PeerAddr -> Set PeerAddr -> Set PeerAddr
forall a. Ord a => Set a -> Set a -> Set a
`Set.intersection` (PublicRootPeers PeerAddr -> Set PeerAddr
forall peeraddr. PublicRootPeers peeraddr -> Set peeraddr
PublicRootPeers.getBigLedgerPeers (PublicRootPeers PeerAddr -> Set PeerAddr)
-> (PeerSelectionState PeerAddr peerconn
-> PublicRootPeers PeerAddr)
-> PeerSelectionState PeerAddr peerconn
-> Set PeerAddr
forall b c a. (b -> c) -> (a -> b) -> a -> c
. PeerSelectionState PeerAddr peerconn -> PublicRootPeers PeerAddr
forall peeraddr peerconn.
PeerSelectionState peeraddr peerconn -> PublicRootPeers peeraddr
Governor.publicRootPeers) PeerSelectionState PeerAddr peerconn
st
dropBigLedgerPeers
:: (Governor.PeerSelectionState PeerAddr peerconn -> Set PeerAddr)
-> Governor.PeerSelectionState PeerAddr peerconn -> Set PeerAddr
dropBigLedgerPeers :: forall peerconn.
(PeerSelectionState PeerAddr peerconn -> Set PeerAddr)
-> PeerSelectionState PeerAddr peerconn -> Set PeerAddr
dropBigLedgerPeers PeerSelectionState PeerAddr peerconn -> Set PeerAddr
f =
\PeerSelectionState PeerAddr peerconn
st -> PeerSelectionState PeerAddr peerconn -> Set PeerAddr
f PeerSelectionState PeerAddr peerconn
st Set PeerAddr -> Set PeerAddr -> Set PeerAddr
forall a. Ord a => Set a -> Set a -> Set a
Set.\\ (PublicRootPeers PeerAddr -> Set PeerAddr
forall peeraddr. PublicRootPeers peeraddr -> Set peeraddr
PublicRootPeers.getBigLedgerPeers (PublicRootPeers PeerAddr -> Set PeerAddr)
-> (PeerSelectionState PeerAddr peerconn
-> PublicRootPeers PeerAddr)
-> PeerSelectionState PeerAddr peerconn
-> Set PeerAddr
forall b c a. (b -> c) -> (a -> b) -> a -> c
. PeerSelectionState PeerAddr peerconn -> PublicRootPeers PeerAddr
forall peeraddr peerconn.
PeerSelectionState peeraddr peerconn -> PublicRootPeers peeraddr
Governor.publicRootPeers) PeerSelectionState PeerAddr peerconn
st