From cc72bb7bf22a85a34e586b91bc1e76337c1bf787 Mon Sep 17 00:00:00 2001 From: Marcin Szamotulski Date: Thu, 5 Dec 2024 08:26:51 +0100 Subject: [PATCH] outbound-governor: configurable DiffusionMode for local root peers --- .../demo/connection-manager.hs | 5 +- .../ouroboros-network-framework.cabal | 1 + .../Ouroboros/Network/ConnectionManager.hs | 3 +- .../Test/Ouroboros/Network/Server2/Sim.hs | 3 +- .../Network/ConnectionManager/Core.hs | 16 ++++-- .../Network/ConnectionManager/Types.hs | 3 +- .../ConnectionManager/Test/Experiments.hs | 5 +- ouroboros-network/CHANGELOG.md | 1 + .../Test/Ouroboros/Network/PeerSelection.hs | 13 ++--- .../Network/PeerSelection/Instances.hs | 18 ++++--- .../Network/PeerSelection/MockEnvironment.hs | 5 +- .../Network/PeerSelection/RootPeersDNS.hs | 5 +- .../Test/Ouroboros/Network/Testnet.hs | 50 +++++++++---------- .../Governor/EstablishedPeers.hs | 17 ++++--- .../Network/PeerSelection/Governor/Types.hs | 2 + .../Network/PeerSelection/PeerStateActions.hs | 9 +++- .../Network/PeerSelection/State/KnownPeers.hs | 1 + .../PeerSelection/State/LocalRootPeers.hs | 4 +- 18 files changed, 101 insertions(+), 60 deletions(-) diff --git a/ouroboros-network-framework/demo/connection-manager.hs b/ouroboros-network-framework/demo/connection-manager.hs index f05892a373e..e01a5ba19bc 100644 --- a/ouroboros-network-framework/demo/connection-manager.hs +++ b/ouroboros-network-framework/demo/connection-manager.hs @@ -65,6 +65,7 @@ import Ouroboros.Network.Context import Ouroboros.Network.IOManager import Ouroboros.Network.Mux import Ouroboros.Network.MuxMode +import Ouroboros.Network.NodeToNode.Version (DiffusionMode (..)) import Ouroboros.Network.Protocol.Handshake import Ouroboros.Network.Protocol.Handshake.Codec (timeLimitsHandshake) import Ouroboros.Network.Protocol.Handshake.Unversioned @@ -541,9 +542,9 @@ bidirectionalExperiment Mux.InitiatorResponderMode UnversionedProtocol)) connect n cm | n <= 1 = - acquireOutboundConnection cm remoteAddr + acquireOutboundConnection cm InitiatorAndResponderDiffusionMode remoteAddr connect n cm = - acquireOutboundConnection cm remoteAddr + acquireOutboundConnection cm InitiatorAndResponderDiffusionMode remoteAddr `catch` \(_ :: IOException) -> threadDelay 1 >> connect (pred n) cm `catch` \(_ :: Mux.Error) -> threadDelay 1 diff --git a/ouroboros-network-framework/ouroboros-network-framework.cabal b/ouroboros-network-framework/ouroboros-network-framework.cabal index 580e3acfbbb..3fe5620c7e0 100644 --- a/ouroboros-network-framework/ouroboros-network-framework.cabal +++ b/ouroboros-network-framework/ouroboros-network-framework.cabal @@ -195,6 +195,7 @@ test-suite sim-tests monoidal-synchronisation, network, network-mux, + ouroboros-network-api, ouroboros-network-framework, ouroboros-network-framework:testlib, ouroboros-network-testing, diff --git a/ouroboros-network-framework/sim-tests/Test/Ouroboros/Network/ConnectionManager.hs b/ouroboros-network-framework/sim-tests/Test/Ouroboros/Network/ConnectionManager.hs index 0e6c9e49ed5..bd9b2fe1aeb 100644 --- a/ouroboros-network-framework/sim-tests/Test/Ouroboros/Network/ConnectionManager.hs +++ b/ouroboros-network-framework/sim-tests/Test/Ouroboros/Network/ConnectionManager.hs @@ -62,6 +62,7 @@ import Ouroboros.Network.ConnectionManager.Core qualified as CM import Ouroboros.Network.ConnectionManager.Test.Utils (verifyAbstractTransition) import Ouroboros.Network.ConnectionManager.Types import Ouroboros.Network.MuxMode +import Ouroboros.Network.NodeToNode.Version (DiffusionMode (..)) import Ouroboros.Network.Server.RateLimiting import Ouroboros.Network.Snocket (Accept (..), Accepted (..), AddressFamily (TestFamily), Snocket (..), TestAddress (..)) @@ -811,7 +812,7 @@ prop_valid_transitions (Fixed rnd) (SkewedBool bindToLocalAddress) scheduleMap = -- handshake negotiation. timeout (1 + 5 + testTimeWaitTimeout) (acquireOutboundConnection - connectionManager addr)) + connectionManager InitiatorAndResponderDiffusionMode addr)) `catches` [ Handler $ \(e :: IOException) -> return (Left (toException e)) , Handler $ \(e :: SomeConnectionManagerError) -> diff --git a/ouroboros-network-framework/sim-tests/Test/Ouroboros/Network/Server2/Sim.hs b/ouroboros-network-framework/sim-tests/Test/Ouroboros/Network/Server2/Sim.hs index bbb968f1b03..5d0e334e1c7 100644 --- a/ouroboros-network-framework/sim-tests/Test/Ouroboros/Network/Server2/Sim.hs +++ b/ouroboros-network-framework/sim-tests/Test/Ouroboros/Network/Server2/Sim.hs @@ -80,6 +80,7 @@ import Ouroboros.Network.InboundGovernor.State (ConnectionState (..)) import Ouroboros.Network.InboundGovernor.State qualified as IG import Ouroboros.Network.Mux import Ouroboros.Network.MuxMode +import Ouroboros.Network.NodeToNode.Version (DiffusionMode (..)) import Ouroboros.Network.Protocol.Handshake.Codec (noTimeLimitsHandshake, timeLimitsHandshake) import Ouroboros.Network.Protocol.Handshake.Unversioned @@ -869,7 +870,7 @@ multinodeExperiment inboundTrTracer trTracer inboundTracer debugTracer cmTracer case fromException e of Just SomeAsyncException {} -> Nothing _ -> Just e) - $ acquireOutboundConnection cm remoteAddr + $ acquireOutboundConnection cm InitiatorAndResponderDiffusionMode remoteAddr case connHandle of Left _ -> go connMap diff --git a/ouroboros-network-framework/src/Ouroboros/Network/ConnectionManager/Core.hs b/ouroboros-network-framework/src/Ouroboros/Network/ConnectionManager/Core.hs index 8b461a6e7f0..f56c9fb165e 100644 --- a/ouroboros-network-framework/src/Ouroboros/Network/ConnectionManager/Core.hs +++ b/ouroboros-network-framework/src/Ouroboros/Network/ConnectionManager/Core.hs @@ -67,6 +67,7 @@ import Ouroboros.Network.ConnectionManager.State qualified as State import Ouroboros.Network.ConnectionManager.Types import Ouroboros.Network.InboundGovernor.Event (NewConnectionInfo (..)) import Ouroboros.Network.MuxMode +import Ouroboros.Network.NodeToNode.Version (DiffusionMode (..)) import Ouroboros.Network.Server.RateLimiting (AcceptedConnectionsLimit (..)) import Ouroboros.Network.Snocket @@ -1311,9 +1312,10 @@ with args@Arguments { -> StrictTMVar m (ConnectionManagerState peerAddr handle handleError version m) -> StrictTVar m StdGen -> ConnectionHandlerFn handlerTrace socket peerAddr handle handleError (version, versionData) m + -> DiffusionMode -> peerAddr -> m (Connected peerAddr handle handleError) - acquireOutboundConnectionImpl freshIdSupply stateVar stdGenVar handler peerAddr = do + acquireOutboundConnectionImpl freshIdSupply stateVar stdGenVar handler diffusionMode peerAddr = do let provenance = Outbound traceWith tracer (TrIncludeConnection provenance peerAddr) (trace, mutableConnState@MutableConnState { connVar } @@ -1510,14 +1512,20 @@ with args@Arguments { Just IPv4Address -> ipv4Address Just IPv6Address -> ipv6Address configureSocket socket addr + -- only bind to the ip address if: + -- * the diffusion is given `ipv4/6` addresses; + -- * `diffusionMode` for this connection is + -- `InitiatorAndResponderMode`. case addressType peerAddr of - Nothing -> pure () - Just IPv4Address -> + Just IPv4Address | InitiatorAndResponderDiffusionMode + <- diffusionMode -> traverse_ (bind snocket socket) ipv4Address - Just IPv6Address -> + Just IPv6Address | InitiatorAndResponderDiffusionMode + <- diffusionMode -> traverse_ (bind snocket socket) ipv6Address + _ -> pure () traceWith tracer (TrConnect addr peerAddr) connect snocket socket peerAddr diff --git a/ouroboros-network-framework/src/Ouroboros/Network/ConnectionManager/Types.hs b/ouroboros-network-framework/src/Ouroboros/Network/ConnectionManager/Types.hs index 0e51c54129a..3faeb727abd 100644 --- a/ouroboros-network-framework/src/Ouroboros/Network/ConnectionManager/Types.hs +++ b/ouroboros-network-framework/src/Ouroboros/Network/ConnectionManager/Types.hs @@ -180,6 +180,7 @@ import Network.Mux.Types qualified as Mux import Ouroboros.Network.ConnectionId (ConnectionId (..)) import Ouroboros.Network.ConnectionManager.ConnMap (ConnMap) import Ouroboros.Network.MuxMode +import Ouroboros.Network.NodeToNode.Version (DiffusionMode (..)) -- | Connection manager supports `IPv4` and `IPv6` addresses. @@ -495,7 +496,7 @@ data Connected peerAddr handle handleError = type AcquireOutboundConnection peerAddr handle handleError m - = peerAddr -> m (Connected peerAddr handle handleError) + = DiffusionMode -> peerAddr -> m (Connected peerAddr handle handleError) type IncludeInboundConnection socket peerAddr handle handleError m = Word32 -- ^ inbound connections hard limit. diff --git a/ouroboros-network-framework/testlib/Ouroboros/Network/ConnectionManager/Test/Experiments.hs b/ouroboros-network-framework/testlib/Ouroboros/Network/ConnectionManager/Test/Experiments.hs index aa962773b63..a16e354837d 100644 --- a/ouroboros-network-framework/testlib/Ouroboros/Network/ConnectionManager/Test/Experiments.hs +++ b/ouroboros-network-framework/testlib/Ouroboros/Network/ConnectionManager/Test/Experiments.hs @@ -81,6 +81,7 @@ import Ouroboros.Network.Driver.Limits import Ouroboros.Network.InboundGovernor qualified as InboundGovernor import Ouroboros.Network.Mux import Ouroboros.Network.MuxMode +import Ouroboros.Network.NodeToNode.Version (DiffusionMode (..)) import Ouroboros.Network.Protocol.Handshake import Ouroboros.Network.Protocol.Handshake.Codec (cborTermVersionDataCodec, noTimeLimitsHandshake, timeLimitsHandshake) @@ -735,7 +736,7 @@ unidirectionalExperiment stdGen timeouts snocket makeBearer confSock socket clie replicateM (numberOfRounds clientAndServerData) (bracket - (acquireOutboundConnection connectionManager serverAddr) + (acquireOutboundConnection connectionManager InitiatorOnlyDiffusionMode serverAddr) (\case Connected connId _ _ -> releaseOutboundConnection connectionManager connId Disconnected {} -> error "unidirectionalExperiment: impossible happened") @@ -836,6 +837,7 @@ bidirectionalExperiment (withLock useLock lock (acquireOutboundConnection connectionManager0 + InitiatorAndResponderDiffusionMode localAddr1)) (\case Connected connId _ _ -> @@ -861,6 +863,7 @@ bidirectionalExperiment (withLock useLock lock (acquireOutboundConnection connectionManager1 + InitiatorAndResponderDiffusionMode localAddr0)) (\case Connected connId _ _ -> diff --git a/ouroboros-network/CHANGELOG.md b/ouroboros-network/CHANGELOG.md index 2b02d9611ab..baa3154e46e 100644 --- a/ouroboros-network/CHANGELOG.md +++ b/ouroboros-network/CHANGELOG.md @@ -9,6 +9,7 @@ * Addapted to `network-mux` changes in https://github.com/IntersectMBO/ouroboros-network/pull/4999 * Addapted to `network-mux` changes in https://github.com/IntersectMBO/ouroboros-network/pull/4997 * Use `LocalRootConfig` instead of a tuple. +* Extended `LocalRootConfig` with `diffusionMode :: DiffusionMode` field. ### Non-Breaking changes diff --git a/ouroboros-network/sim-tests-lib/Test/Ouroboros/Network/PeerSelection.hs b/ouroboros-network/sim-tests-lib/Test/Ouroboros/Network/PeerSelection.hs index 4f5b4e3ea05..caa4d881ab1 100644 --- a/ouroboros-network/sim-tests-lib/Test/Ouroboros/Network/PeerSelection.hs +++ b/ouroboros-network/sim-tests-lib/Test/Ouroboros/Network/PeerSelection.hs @@ -59,6 +59,7 @@ 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 (..), @@ -3875,8 +3876,8 @@ prop_issue_3550 = prop_governor_target_established_below defaultMaxTime $ (PeerAddr 29,[],GovernorScripts {peerShareScript = Script (Nothing :| []), peerSharingScript = Script (PeerSharingDisabled :| []), connectionScript = Script ((ToWarm,NoDelay) :| [(ToCold,NoDelay),(Noop,NoDelay)])}) ], localRootPeers = LocalRootPeers.fromGroups - [ (1, 1, Map.fromList [(PeerAddr 16, LocalRootConfig DoAdvertisePeer IsNotTrustable)]) - , (1, 1, Map.fromList [(PeerAddr 4, LocalRootConfig DoAdvertisePeer IsNotTrustable)]) + [ (1, 1, Map.fromList [(PeerAddr 16, LocalRootConfig DoAdvertisePeer IsNotTrustable InitiatorAndResponderDiffusionMode)]) + , (1, 1, Map.fromList [(PeerAddr 4, LocalRootConfig DoAdvertisePeer IsNotTrustable InitiatorAndResponderDiffusionMode)]) ], publicRootPeers = PublicRootPeers.fromPublicRootPeers (Map.fromList [ (PeerAddr 14, DoNotAdvertisePeer) @@ -3923,7 +3924,7 @@ prop_issue_3515 = prop_governor_nolivelock $ peerSharingScript = Script (PeerSharingDisabled :| []), connectionScript = Script ((ToCold,NoDelay) :| [(Noop,NoDelay)]) })], - localRootPeers = LocalRootPeers.fromGroups [(1,1,Map.fromList [(PeerAddr 10, LocalRootConfig DoAdvertisePeer IsNotTrustable)])], + localRootPeers = LocalRootPeers.fromGroups [(1,1,Map.fromList [(PeerAddr 10, LocalRootConfig DoAdvertisePeer IsNotTrustable InitiatorAndResponderDiffusionMode)])], publicRootPeers = PublicRootPeers.empty, targets = Script . NonEmpty.fromList $ targets'', pickKnownPeersForPeerShare = Script (PickFirst :| []), @@ -3964,7 +3965,7 @@ prop_issue_3494 = prop_governor_nofail $ peerSharingScript = Script (PeerSharingDisabled :| []), connectionScript = Script ((ToCold,NoDelay) :| [(Noop,NoDelay)]) })], - localRootPeers = LocalRootPeers.fromGroups [(1,1,Map.fromList [(PeerAddr 64, LocalRootConfig DoAdvertisePeer IsNotTrustable)])], + localRootPeers = LocalRootPeers.fromGroups [(1,1,Map.fromList [(PeerAddr 64, LocalRootConfig DoAdvertisePeer IsNotTrustable InitiatorAndResponderDiffusionMode)])], publicRootPeers = PublicRootPeers.empty, targets = Script . NonEmpty.fromList $ targets'', pickKnownPeersForPeerShare = Script (PickFirst :| []), @@ -4013,8 +4014,8 @@ prop_issue_3233 = prop_governor_nolivelock $ (PeerAddr 15,[],GovernorScripts {peerShareScript = Script (Just ([],PeerShareTimeSlow) :| []), peerSharingScript = Script (PeerSharingDisabled :| []), connectionScript = Script ((Noop,NoDelay) :| [])}) ], localRootPeers = LocalRootPeers.fromGroups - [ (1, 1, Map.fromList [(PeerAddr 15, LocalRootConfig DoAdvertisePeer IsNotTrustable)]) - , (1, 1, Map.fromList [(PeerAddr 13, LocalRootConfig DoAdvertisePeer IsNotTrustable)]) + [ (1, 1, Map.fromList [(PeerAddr 15, LocalRootConfig DoAdvertisePeer IsNotTrustable InitiatorAndResponderDiffusionMode)]) + , (1, 1, Map.fromList [(PeerAddr 13, LocalRootConfig DoAdvertisePeer IsNotTrustable InitiatorAndResponderDiffusionMode)]) ], publicRootPeers = PublicRootPeers.fromPublicRootPeers (Map.fromList [(PeerAddr 4, DoNotAdvertisePeer)]), diff --git a/ouroboros-network/sim-tests-lib/Test/Ouroboros/Network/PeerSelection/Instances.hs b/ouroboros-network/sim-tests-lib/Test/Ouroboros/Network/PeerSelection/Instances.hs index c91f3b7f2f0..4aa2f959aaf 100644 --- a/ouroboros-network/sim-tests-lib/Test/Ouroboros/Network/PeerSelection/Instances.hs +++ b/ouroboros-network/sim-tests-lib/Test/Ouroboros/Network/PeerSelection/Instances.hs @@ -17,17 +17,17 @@ module Test.Ouroboros.Network.PeerSelection.Instances , prop_shrink_PeerSelectionTargets ) where +import Data.Hashable +import Data.IP qualified as IP import Data.Text.Encoding (encodeUtf8) import Data.Word (Word32, Word64) import Cardano.Slotting.Slot (SlotNo (..)) -import Ouroboros.Network.PeerSelection.Governor - -import Data.Hashable -import Data.IP qualified as IP import Ouroboros.Network.ConsensusMode +import Ouroboros.Network.NodeToNode.Version (DiffusionMode (..)) import Ouroboros.Network.PeerSelection.Bootstrap (UseBootstrapPeers (..)) +import Ouroboros.Network.PeerSelection.Governor import Ouroboros.Network.PeerSelection.LedgerPeers.Type (AfterSlot (..), UseLedgerPeers (..)) import Ouroboros.Network.PeerSelection.PeerAdvertise (PeerAdvertise (..)) @@ -192,8 +192,8 @@ prop_shrink_PeerSelectionTargets x = instance Arbitrary LocalRootConfig where - arbitrary = LocalRootConfig <$> arbitrary <*> arbitrary - shrink a@LocalRootConfig { peerAdvertise, peerTrustable } = + arbitrary = LocalRootConfig <$> arbitrary <*> arbitrary <*> elements [InitiatorAndResponderDiffusionMode, InitiatorOnlyDiffusionMode] + shrink a@LocalRootConfig { peerAdvertise, peerTrustable, diffusionMode } = [ a { peerTrustable = peerTrustable' } | peerTrustable' <- shrink peerTrustable ] @@ -201,3 +201,9 @@ instance Arbitrary LocalRootConfig where [ a { peerAdvertise = peerAdvertise' } | peerAdvertise' <- shrink peerAdvertise ] + ++ + [ a { diffusionMode = diffusionMode' } + | diffusionMode' <- case diffusionMode of + InitiatorOnlyDiffusionMode -> [] + InitiatorAndResponderDiffusionMode -> [InitiatorOnlyDiffusionMode] + ] diff --git a/ouroboros-network/sim-tests-lib/Test/Ouroboros/Network/PeerSelection/MockEnvironment.hs b/ouroboros-network/sim-tests-lib/Test/Ouroboros/Network/PeerSelection/MockEnvironment.hs index 5433bf2668b..77525938f93 100644 --- a/ouroboros-network/sim-tests-lib/Test/Ouroboros/Network/PeerSelection/MockEnvironment.hs +++ b/ouroboros-network/sim-tests-lib/Test/Ouroboros/Network/PeerSelection/MockEnvironment.hs @@ -60,6 +60,7 @@ import Control.Monad.IOSim import Control.Tracer (Tracer (..), contramap, traceWith) import Ouroboros.Network.ExitPolicy +import Ouroboros.Network.NodeToNode.Version (DiffusionMode) import Ouroboros.Network.PeerSelection.Governor hiding (PeerSelectionState (..)) import Ouroboros.Network.PeerSelection.Governor qualified as Governor import Ouroboros.Network.PeerSelection.State.LocalRootPeers qualified as LocalRootPeers @@ -515,8 +516,8 @@ mockPeerSelectionActions' tracer traceWith tracer (TraceEnvPeerShareResult addr peeraddrs) return (PeerSharingResult peeraddrs) - establishPeerConnection :: IsBigLedgerPeer -> PeerAddr -> m (PeerConn m) - establishPeerConnection _ peeraddr = do + establishPeerConnection :: IsBigLedgerPeer -> DiffusionMode -> PeerAddr -> m (PeerConn m) + establishPeerConnection _ _ peeraddr = do --TODO: add support for variable delays and synchronous failure traceWith tracer (TraceEnvEstablishConn peeraddr) threadDelay 1 diff --git a/ouroboros-network/sim-tests-lib/Test/Ouroboros/Network/PeerSelection/RootPeersDNS.hs b/ouroboros-network/sim-tests-lib/Test/Ouroboros/Network/PeerSelection/RootPeersDNS.hs index e9c318d842e..68b092bb625 100644 --- a/ouroboros-network/sim-tests-lib/Test/Ouroboros/Network/PeerSelection/RootPeersDNS.hs +++ b/ouroboros-network/sim-tests-lib/Test/Ouroboros/Network/PeerSelection/RootPeersDNS.hs @@ -57,6 +57,7 @@ import Control.Tracer (Tracer (Tracer), contramap, nullTracer, traceWith) import Control.Concurrent.Class.MonadSTM qualified as LazySTM import Data.List (intercalate) import Data.List.NonEmpty (NonEmpty (..)) +import Ouroboros.Network.NodeToNode.Version (DiffusionMode (..)) import Ouroboros.Network.PeerSelection.LedgerPeers import Ouroboros.Network.PeerSelection.PeerAdvertise (PeerAdvertise (..)) import Ouroboros.Network.PeerSelection.PeerTrustable (PeerTrustable (..)) @@ -238,10 +239,10 @@ simpleMockRoots = MockRoots localRootPeers dnsMap Map.empty (singletonScript Map [ ( 2, 2 , Map.fromList [ ( RelayAccessAddress (read "192.0.2.1") (read "3333") - , LocalRootConfig DoAdvertisePeer IsNotTrustable + , LocalRootConfig DoAdvertisePeer IsNotTrustable InitiatorAndResponderDiffusionMode ) , ( RelayAccessDomain "test.domain" (read "4444") - , LocalRootConfig DoNotAdvertisePeer IsNotTrustable + , LocalRootConfig DoNotAdvertisePeer IsNotTrustable InitiatorAndResponderDiffusionMode ) ] ) diff --git a/ouroboros-network/sim-tests-lib/Test/Ouroboros/Network/Testnet.hs b/ouroboros-network/sim-tests-lib/Test/Ouroboros/Network/Testnet.hs index 4635a188ee7..94dab0b8ebc 100644 --- a/ouroboros-network/sim-tests-lib/Test/Ouroboros/Network/Testnet.hs +++ b/ouroboros-network/sim-tests-lib/Test/Ouroboros/Network/Testnet.hs @@ -730,8 +730,8 @@ unit_4177 = prop_inbound_governor_transitions_coverage absNoAttenuation script (Script (UseBootstrapPeers [RelayAccessDomain "bootstrap" 00000] :| [])) (TestAddress (IPAddr (read "0:7:0:7::") 65533)) PeerSharingDisabled - [ (1,1,Map.fromList [(RelayAccessDomain "test2" 65535,LocalRootConfig DoNotAdvertisePeer IsNotTrustable) - , (RelayAccessAddress "0:6:0:3:0:6:0:5" 65530,LocalRootConfig DoNotAdvertisePeer IsNotTrustable)]) + [ (1,1,Map.fromList [(RelayAccessDomain "test2" 65535,LocalRootConfig DoNotAdvertisePeer IsNotTrustable InitiatorAndResponderDiffusionMode) + , (RelayAccessAddress "0:6:0:3:0:6:0:5" 65530,LocalRootConfig DoNotAdvertisePeer IsNotTrustable InitiatorAndResponderDiffusionMode)]) ] (Script (LedgerPools [] :| [])) ConsensusModePeerTargets { @@ -750,11 +750,11 @@ unit_4177 = prop_inbound_governor_transitions_coverage absNoAttenuation script False (Script (FetchModeDeadline :| [])) , [JoinNetwork 1.742857142857 - ,Reconfigure 6.33333333333 [(1,1,Map.fromList [(RelayAccessDomain "test2" 65535,LocalRootConfig DoAdvertisePeer IsNotTrustable)]), - (1,1,Map.fromList [(RelayAccessAddress "0:6:0:3:0:6:0:5" 65530,LocalRootConfig DoAdvertisePeer IsNotTrustable) + ,Reconfigure 6.33333333333 [(1,1,Map.fromList [(RelayAccessDomain "test2" 65535,LocalRootConfig DoAdvertisePeer IsNotTrustable InitiatorAndResponderDiffusionMode)]), + (1,1,Map.fromList [(RelayAccessAddress "0:6:0:3:0:6:0:5" 65530,LocalRootConfig DoAdvertisePeer IsNotTrustable InitiatorAndResponderDiffusionMode) ])] - ,Reconfigure 23.88888888888 [(1,1,Map.empty),(1,1,Map.fromList [(RelayAccessAddress "0:6:0:3:0:6:0:5" 65530,LocalRootConfig DoAdvertisePeer IsNotTrustable)])] - ,Reconfigure 4.870967741935 [(1,1,Map.fromList [(RelayAccessDomain "test2" 65535,LocalRootConfig DoAdvertisePeer IsNotTrustable)])] + ,Reconfigure 23.88888888888 [(1,1,Map.empty),(1,1,Map.fromList [(RelayAccessAddress "0:6:0:3:0:6:0:5" 65530,LocalRootConfig DoAdvertisePeer IsNotTrustable InitiatorAndResponderDiffusionMode)])] + ,Reconfigure 4.870967741935 [(1,1,Map.fromList [(RelayAccessDomain "test2" 65535,LocalRootConfig DoAdvertisePeer IsNotTrustable InitiatorAndResponderDiffusionMode)])] ] ) , ( NodeArgs 1 InitiatorAndResponderDiffusionMode (Just 135) @@ -1335,8 +1335,8 @@ unit_4191 = testWithIOSim prop_diffusion_dns_can_recover 125000 absInfo script (Script (UseBootstrapPeers [RelayAccessDomain "bootstrap" 00000] :| [])) (TestAddress (IPAddr (read "0.0.1.236") 65527)) PeerSharingDisabled - [ (2,2,Map.fromList [ (RelayAccessDomain "test2" 15,LocalRootConfig DoNotAdvertisePeer IsNotTrustable) - , (RelayAccessDomain "test3" 4,LocalRootConfig DoAdvertisePeer IsNotTrustable)]) + [ (2,2,Map.fromList [ (RelayAccessDomain "test2" 15,LocalRootConfig DoNotAdvertisePeer IsNotTrustable InitiatorAndResponderDiffusionMode) + , (RelayAccessDomain "test3" 4,LocalRootConfig DoAdvertisePeer IsNotTrustable InitiatorAndResponderDiffusionMode)]) ] (Script (LedgerPools [] :| [])) ConsensusModePeerTargets { @@ -1386,7 +1386,7 @@ unit_4191 = testWithIOSim prop_diffusion_dns_can_recover 125000 absInfo script , Reconfigure 0.415384615384 [(1,1,Map.fromList []) , (1,1,Map.empty)] , Reconfigure 15.550561797752 [(1,1,Map.fromList []) - , (1,1,Map.fromList [(RelayAccessDomain "test2" 15,LocalRootConfig DoAdvertisePeer IsNotTrustable)])] + , (1,1,Map.fromList [(RelayAccessDomain "test2" 15,LocalRootConfig DoAdvertisePeer IsNotTrustable InitiatorAndResponderDiffusionMode)])] , Reconfigure 82.85714285714 [] ]) ] @@ -1470,7 +1470,7 @@ prop_connect_failure (AbsIOError ioerr) = naBootstrapPeers = Script (DontUseBootstrapPeers :| []), naAddr = TestAddress (IPAddr nodeIP nodePort), naPeerSharing = PeerSharingDisabled, - naLocalRootPeers = [(1,1,Map.fromList [(RelayAccessAddress relayIP relayPort,LocalRootConfig DoNotAdvertisePeer IsNotTrustable)])], + naLocalRootPeers = [(1,1,Map.fromList [(RelayAccessAddress relayIP relayPort,LocalRootConfig DoNotAdvertisePeer IsNotTrustable InitiatorAndResponderDiffusionMode)])], naLedgerPeers = Script (LedgerPools [] :| []), naPeerTargets = ConsensusModePeerTargets { deadlineTargets = PeerSelectionTargets { @@ -1602,7 +1602,7 @@ prop_accept_failure (AbsIOError ioerr) = naBootstrapPeers = Script (DontUseBootstrapPeers :| []), naAddr = TestAddress (IPAddr nodeIP nodePort), naPeerSharing = PeerSharingDisabled, - naLocalRootPeers = [(1,1,Map.fromList [(RelayAccessAddress relayIP relayPort,LocalRootConfig DoNotAdvertisePeer IsNotTrustable)])], + naLocalRootPeers = [(1,1,Map.fromList [(RelayAccessAddress relayIP relayPort,LocalRootConfig DoNotAdvertisePeer IsNotTrustable InitiatorAndResponderDiffusionMode)])], naLedgerPeers = Script (LedgerPools [] :| []), naPeerTargets = ConsensusModePeerTargets { deadlineTargets = PeerSelectionTargets { @@ -2549,21 +2549,21 @@ async_demotion_network_script = ] ) , ( common { naAddr = addr2, - naLocalRootPeers = [(1,1, Map.fromList [(ra_addr1, LocalRootConfig DoNotAdvertisePeer IsNotTrustable)])] } + naLocalRootPeers = [(1,1, Map.fromList [(ra_addr1, LocalRootConfig DoNotAdvertisePeer IsNotTrustable InitiatorAndResponderDiffusionMode)])] } , [JoinNetwork 0, Kill 5, JoinNetwork 20] ) , ( common { naAddr = addr3, - naLocalRootPeers = [(1,1, Map.fromList [(ra_addr1, LocalRootConfig DoNotAdvertisePeer IsNotTrustable)])] } + naLocalRootPeers = [(1,1, Map.fromList [(ra_addr1, LocalRootConfig DoNotAdvertisePeer IsNotTrustable InitiatorAndResponderDiffusionMode)])] } , [JoinNetwork 0] ) ] where addr1 = TestAddress (IPAddr (read "10.0.0.1") 3000) ra_addr1 = RelayAccessAddress (read "10.0.0.1") 3000 - localRoots1 = [(2,2, Map.fromList [(ra_addr2, LocalRootConfig DoNotAdvertisePeer IsNotTrustable) - ,(ra_addr3, LocalRootConfig DoNotAdvertisePeer IsNotTrustable)])] - localRoots1' = [(2,2, Map.fromList [(ra_addr2, LocalRootConfig DoAdvertisePeer IsNotTrustable) - ,(ra_addr3, LocalRootConfig DoAdvertisePeer IsNotTrustable)])] + localRoots1 = [(2,2, Map.fromList [(ra_addr2, LocalRootConfig DoNotAdvertisePeer IsNotTrustable InitiatorAndResponderDiffusionMode) + ,(ra_addr3, LocalRootConfig DoNotAdvertisePeer IsNotTrustable InitiatorAndResponderDiffusionMode)])] + localRoots1' = [(2,2, Map.fromList [(ra_addr2, LocalRootConfig DoAdvertisePeer IsNotTrustable InitiatorAndResponderDiffusionMode) + ,(ra_addr3, LocalRootConfig DoAdvertisePeer IsNotTrustable InitiatorAndResponderDiffusionMode)])] addr2 = TestAddress (IPAddr (read "10.0.0.2") 3000) ra_addr2 = RelayAccessAddress (read "10.0.0.2") 3000 @@ -3129,7 +3129,7 @@ prop_unit_4258 = (Script (UseBootstrapPeers [RelayAccessDomain "bootstrap" 00000] :| [])) (TestAddress (IPAddr (read "0.0.0.4") 9)) PeerSharingDisabled - [(1,1,Map.fromList [(RelayAccessAddress "0.0.0.8" 65531,LocalRootConfig DoNotAdvertisePeer IsNotTrustable)])] + [(1,1,Map.fromList [(RelayAccessAddress "0.0.0.8" 65531,LocalRootConfig DoNotAdvertisePeer IsNotTrustable InitiatorAndResponderDiffusionMode)])] (Script (LedgerPools [] :| [])) ConsensusModePeerTargets { deadlineTargets = nullPeerSelectionTargets { @@ -3164,7 +3164,7 @@ prop_unit_4258 = (Script (UseBootstrapPeers [RelayAccessDomain "bootstrap" 00000] :| [])) (TestAddress (IPAddr (read "0.0.0.8") 65531)) PeerSharingDisabled - [(1,1,Map.fromList [(RelayAccessAddress "0.0.0.4" 9,LocalRootConfig DoNotAdvertisePeer IsNotTrustable)])] + [(1,1,Map.fromList [(RelayAccessAddress "0.0.0.4" 9,LocalRootConfig DoNotAdvertisePeer IsNotTrustable InitiatorAndResponderDiffusionMode)])] (Script (LedgerPools [] :| [])) ConsensusModePeerTargets { deadlineTargets = nullPeerSelectionTargets { @@ -3195,7 +3195,7 @@ prop_unit_4258 = False (Script (FetchModeDeadline :| [])) , [ JoinNetwork 3.384615384615, - Reconfigure 3.583333333333 [(1,1,Map.fromList [(RelayAccessAddress "0.0.0.4" 9,LocalRootConfig DoNotAdvertisePeer IsNotTrustable)])], + Reconfigure 3.583333333333 [(1,1,Map.fromList [(RelayAccessAddress "0.0.0.4" 9,LocalRootConfig DoNotAdvertisePeer IsNotTrustable InitiatorAndResponderDiffusionMode)])], Kill 15.55555555555, JoinNetwork 30.53333333333, Kill 71.11111111111 @@ -3237,8 +3237,8 @@ prop_unit_reconnect = (Script (DontUseBootstrapPeers :| [])) (TestAddress (IPAddr (read "0.0.0.0") 0)) PeerSharingDisabled - [ (2,2,Map.fromList [ (RelayAccessAddress "0.0.0.1" 0,LocalRootConfig DoNotAdvertisePeer IsNotTrustable) - , (RelayAccessAddress "0.0.0.2" 0,LocalRootConfig DoNotAdvertisePeer IsNotTrustable) + [ (2,2,Map.fromList [ (RelayAccessAddress "0.0.0.1" 0,LocalRootConfig DoNotAdvertisePeer IsNotTrustable InitiatorAndResponderDiffusionMode) + , (RelayAccessAddress "0.0.0.2" 0,LocalRootConfig DoNotAdvertisePeer IsNotTrustable InitiatorAndResponderDiffusionMode) ]) ] (Script (LedgerPools [] :| [])) @@ -3269,7 +3269,7 @@ prop_unit_reconnect = (Script (DontUseBootstrapPeers :| [])) (TestAddress (IPAddr (read "0.0.0.1") 0)) PeerSharingDisabled - [(1,1,Map.fromList [(RelayAccessAddress "0.0.0.0" 0,LocalRootConfig DoNotAdvertisePeer IsNotTrustable)])] + [(1,1,Map.fromList [(RelayAccessAddress "0.0.0.0" 0,LocalRootConfig DoNotAdvertisePeer IsNotTrustable InitiatorAndResponderDiffusionMode)])] (Script (LedgerPools [] :| [])) ConsensusModePeerTargets { deadlineTargets = PeerSelectionTargets { @@ -3704,7 +3704,7 @@ unit_peer_sharing = (mainnetSimArgs 3) (singletonScript (mempty, ShortDelay)) [ ( (defaultNodeArgs GenesisMode) { naAddr = ip_0, - naLocalRootPeers = [(1, 1, Map.fromList [(ra_1, LocalRootConfig DoNotAdvertisePeer IsNotTrustable)])], + naLocalRootPeers = [(1, 1, Map.fromList [(ra_1, LocalRootConfig DoNotAdvertisePeer IsNotTrustable InitiatorAndResponderDiffusionMode)])], naPeerTargets = targets 1 } , [JoinNetwork 0] @@ -3716,7 +3716,7 @@ unit_peer_sharing = , [JoinNetwork 0] ) , ( (defaultNodeArgs GenesisMode) { naAddr = ip_2, - naLocalRootPeers = [(1, 1, Map.fromList [(ra_1, LocalRootConfig DoNotAdvertisePeer IsNotTrustable)])], + naLocalRootPeers = [(1, 1, Map.fromList [(ra_1, LocalRootConfig DoNotAdvertisePeer IsNotTrustable InitiatorAndResponderDiffusionMode)])], naPeerTargets = targets 2 } , [JoinNetwork 0] diff --git a/ouroboros-network/src/Ouroboros/Network/PeerSelection/Governor/EstablishedPeers.hs b/ouroboros-network/src/Ouroboros/Network/PeerSelection/Governor/EstablishedPeers.hs index 7d72d67697f..1c07b934c6a 100644 --- a/ouroboros-network/src/Ouroboros/Network/PeerSelection/Governor/EstablishedPeers.hs +++ b/ouroboros-network/src/Ouroboros/Network/PeerSelection/Governor/EstablishedPeers.hs @@ -21,6 +21,7 @@ import Control.Monad.Class.MonadSTM import Control.Monad.Class.MonadTime.SI import System.Random (randomR) +import Ouroboros.Network.NodeToNode.Version (DiffusionMode (..)) import Ouroboros.Network.PeerSelection.Bootstrap (requiresBootstrapPeers) import Ouroboros.Network.PeerSelection.Governor.Types import Ouroboros.Network.PeerSelection.LedgerPeers.Type (IsBigLedgerPeer (..)) @@ -129,8 +130,11 @@ belowTargetLocal actions inProgressPromoteCold = inProgressPromoteCold <> selectedToPromote }, - decisionJobs = [ jobPromoteColdPeer actions policy peer IsNotBigLedgerPeer - | peer <- Set.toList selectedToPromote ] + decisionJobs = [ jobPromoteColdPeer actions policy peer IsNotBigLedgerPeer diffusionMode + | peer <- Set.toList selectedToPromote + , let diffusionMode = LocalRootPeers.diffusionMode + $ LocalRootPeers.toMap localRootPeers Map.! peer + ] } -- If we could promote except that there are no peers currently available @@ -217,7 +221,7 @@ belowTargetOther actions inProgressPromoteCold = inProgressPromoteCold <> selectedToPromote }, - decisionJobs = [ jobPromoteColdPeer actions policy peer IsNotBigLedgerPeer + decisionJobs = [ jobPromoteColdPeer actions policy peer IsNotBigLedgerPeer InitiatorAndResponderDiffusionMode | peer <- Set.toList selectedToPromote ] } @@ -305,7 +309,7 @@ belowTargetBigLedgerPeers actions inProgressPromoteCold = inProgressPromoteCold <> selectedToPromote }, - decisionJobs = [ jobPromoteColdPeer actions policy peer IsBigLedgerPeer + decisionJobs = [ jobPromoteColdPeer actions policy peer IsBigLedgerPeer InitiatorAndResponderDiffusionMode | peer <- Set.toList selectedToPromote ] } @@ -343,13 +347,14 @@ jobPromoteColdPeer :: forall peeraddr peerconn m. -> PeerSelectionPolicy peeraddr m -> peeraddr -> IsBigLedgerPeer + -> DiffusionMode -> Job () m (Completion m peeraddr peerconn) jobPromoteColdPeer PeerSelectionActions { peerStateActions = PeerStateActions {establishPeerConnection}, peerConnToPeerSharing } PeerSelectionPolicy { policyPeerShareActivationDelay } - peeraddr isBigLedgerPeer = + peeraddr isBigLedgerPeer diffusionMode = Job job handler () "promoteColdPeer" where handler :: SomeException -> m (Completion m peeraddr peerconn) @@ -408,7 +413,7 @@ jobPromoteColdPeer PeerSelectionActions { job = do --TODO: decide if we should do timeouts here or if we should make that -- the responsibility of establishPeerConnection - peerconn <- establishPeerConnection isBigLedgerPeer peeraddr + peerconn <- establishPeerConnection isBigLedgerPeer diffusionMode peeraddr let !peerSharing = peerConnToPeerSharing peerconn return $ Completion $ \st@PeerSelectionState { diff --git a/ouroboros-network/src/Ouroboros/Network/PeerSelection/Governor/Types.hs b/ouroboros-network/src/Ouroboros/Network/PeerSelection/Governor/Types.hs index d03d4c710db..15a03b3a846 100644 --- a/ouroboros-network/src/Ouroboros/Network/PeerSelection/Governor/Types.hs +++ b/ouroboros-network/src/Ouroboros/Network/PeerSelection/Governor/Types.hs @@ -144,6 +144,7 @@ import System.Random (StdGen) import Control.Concurrent.Class.MonadSTM.Strict import Ouroboros.Network.ConsensusMode import Ouroboros.Network.ExitPolicy +import Ouroboros.Network.NodeToNode.Version (DiffusionMode) import Ouroboros.Network.PeerSelection.Bootstrap (UseBootstrapPeers (..)) import Ouroboros.Network.PeerSelection.LedgerPeers.Type import Ouroboros.Network.PeerSelection.LocalRootPeers (OutboundConnectionsState) @@ -446,6 +447,7 @@ data PeerStateActions peeraddr peerconn m = PeerStateActions { -- mini-protocol callbacks. -- establishPeerConnection :: IsBigLedgerPeer + -> DiffusionMode -> peeraddr -> m peerconn, -- | Activate a connection: warm to hot promotion. diff --git a/ouroboros-network/src/Ouroboros/Network/PeerSelection/PeerStateActions.hs b/ouroboros-network/src/Ouroboros/Network/PeerSelection/PeerStateActions.hs index fec2e79be89..b8584ed70ef 100644 --- a/ouroboros-network/src/Ouroboros/Network/PeerSelection/PeerStateActions.hs +++ b/ouroboros-network/src/Ouroboros/Network/PeerSelection/PeerStateActions.hs @@ -55,6 +55,7 @@ import Ouroboros.Network.Context import Ouroboros.Network.ControlMessage (ControlMessage (..)) import Ouroboros.Network.ExitPolicy import Ouroboros.Network.Mux +import Ouroboros.Network.NodeToNode.Version (DiffusionMode (..)) import Ouroboros.Network.PeerSelection.Governor (PeerStateActions (..)) import Ouroboros.Network.Protocol.Handshake (HandshakeException) import Ouroboros.Network.RethrowPolicy @@ -724,16 +725,20 @@ withPeerStateActions PeerStateActionsArguments { establishPeerConnection :: JobPool () m (Maybe SomeException) -> IsBigLedgerPeer + -> DiffusionMode -> peerAddr -> m (PeerConnectionHandle muxMode responderCtx peerAddr versionData ByteString m a b) - establishPeerConnection jobPool isBigLedgerPeer remotePeerAddr = + establishPeerConnection jobPool isBigLedgerPeer diffusionMode remotePeerAddr = -- Protect consistency of the peer state with 'bracketOnError' if -- opening a connection fails. bracketOnError (newTVarIO PeerCold) (\peerStateVar -> atomically $ writeTVar peerStateVar PeerCold) $ \peerStateVar -> do - res <- try $ acquireOutboundConnection spsConnectionManager remotePeerAddr + res <- try $ acquireOutboundConnection + spsConnectionManager + diffusionMode + remotePeerAddr case res of Left e -> do traceWith spsTracer (AcquireConnectionError e) diff --git a/ouroboros-network/src/Ouroboros/Network/PeerSelection/State/KnownPeers.hs b/ouroboros-network/src/Ouroboros/Network/PeerSelection/State/KnownPeers.hs index 5f6e4b6541a..537a439f3ca 100644 --- a/ouroboros-network/src/Ouroboros/Network/PeerSelection/State/KnownPeers.hs +++ b/ouroboros-network/src/Ouroboros/Network/PeerSelection/State/KnownPeers.hs @@ -171,6 +171,7 @@ alterKnownPeerInfo (peerSharing, peerAdvertise) peerLookupResult = , knownSuccessfulConnection = False } Just kpi -> Just $ + -- pick first known value kpi { knownPeerSharing = maybeToStrictMaybe peerSharing <|> knownPeerSharing kpi diff --git a/ouroboros-network/src/Ouroboros/Network/PeerSelection/State/LocalRootPeers.hs b/ouroboros-network/src/Ouroboros/Network/PeerSelection/State/LocalRootPeers.hs index c6993f47bec..6dc3a699155 100644 --- a/ouroboros-network/src/Ouroboros/Network/PeerSelection/State/LocalRootPeers.hs +++ b/ouroboros-network/src/Ouroboros/Network/PeerSelection/State/LocalRootPeers.hs @@ -37,6 +37,7 @@ import Data.Map.Strict qualified as Map import Data.Set (Set) import Data.Set qualified as Set +import Ouroboros.Network.NodeToNode.Version (DiffusionMode) import Ouroboros.Network.PeerSelection.PeerAdvertise (PeerAdvertise) import Ouroboros.Network.PeerSelection.PeerTrustable (PeerTrustable (..)) @@ -47,7 +48,8 @@ import Ouroboros.Network.PeerSelection.PeerTrustable (PeerTrustable (..)) data LocalRootConfig = LocalRootConfig { peerAdvertise :: !PeerAdvertise, - peerTrustable :: !PeerTrustable + peerTrustable :: !PeerTrustable, + diffusionMode :: !DiffusionMode } deriving (Show, Eq)