Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Diffusion improvements #5070

Merged
merged 7 commits into from
Feb 11, 2025
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1229,7 +1229,7 @@ diffusionSimulation
, Churn.consensusMode = consensusMode
}

arguments :: Node.Arguments (Cardano.ExtraArguments m) (Churn.ExtraArguments m) PeerTrustable m
arguments :: Node.Arguments (Churn.ExtraArguments m) PeerTrustable m
arguments =
Node.Arguments
{ Node.aIPAddress = addr
Expand All @@ -1250,7 +1250,6 @@ diffusionSimulation
, Node.aDNSLookupDelayScript = dnsLookupDelay
, Node.aDebugTracer = (\s -> WithTime (Time (-1)) (WithName addr (DiffusionDebugTrace s)))
`contramap` nodeTracer
, Node.aExtraArgs = cardanoExtraArgs
, Node.aExtraChurnArgs = cardanoChurnArgs
}

Expand All @@ -1267,16 +1266,10 @@ diffusionSimulation
interfaces
arguments
(ExtraState.empty consensusMode (NumberOfBigLedgerPeers 0))
(Cardano.cardanoExtraArgsToPeerSelectionActions cardanoExtraArgs)
ExtraSizes.empty
Cardano.cardanoPublicRootPeersAPI
(Cardano.cardanoPeerSelectionGovernorArgs
readUseLedgerPeers
peerSharing
( Cardano.updateOutboundConnectionsState
$ lpExtraAPI
$ Node.iLedgerPeersConsensusInterface
$ interfaces)
(Cardano.cardanoExtraArgsToPeerSelectionActions cardanoExtraArgs)
)
Cardano.cardanoPeerSelectionStatetoCounters
(flip Cardano.ExtraPeers Set.empty)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ data Interfaces extraAPI m = Interfaces
type NtNFD m = FD m NtNAddr
type NtCFD m = FD m NtCAddr

data Arguments extraArgs extraChurnArgs extraFlags m = Arguments
data Arguments extraChurnArgs extraFlags m = Arguments
{ aIPAddress :: NtNAddr
, aAcceptedLimits :: AcceptedConnectionsLimit
, aDiffusionMode :: DiffusionMode
Expand All @@ -161,7 +161,6 @@ data Arguments extraArgs extraChurnArgs extraFlags m = Arguments
, aDNSTimeoutScript :: Script DNSTimeout
, aDNSLookupDelayScript :: Script DNSLookupDelay
, aDebugTracer :: Tracer m String
, aExtraArgs :: extraArgs
, aExtraChurnArgs :: extraChurnArgs
}

Expand All @@ -170,7 +169,7 @@ data Arguments extraArgs extraChurnArgs extraFlags m = Arguments
--
type ResolverException = SomeException

run :: forall extraArgs extraState extraDebugState extraActions extraAPI
run :: forall extraState extraDebugState extraAPI
extraPeers extraFlags extraChurnArgs extraCounters
exception resolver resolverError m.
( Alternative (STM m)
Expand Down Expand Up @@ -201,16 +200,14 @@ run :: forall extraArgs extraState extraDebugState extraActions extraAPI
=> Node.BlockGeneratorArgs Block StdGen
-> Node.LimitsAndTimeouts BlockHeader Block
-> Interfaces extraAPI m
-> Arguments extraArgs extraChurnArgs extraFlags m
-> Arguments extraChurnArgs extraFlags m
-> extraState
-> extraActions
-> extraCounters
-> PublicExtraPeersAPI extraPeers NtNAddr
-> (forall muxMode responderCtx ntnVersionData bytes a b .
PeerSelectionGovernorArgs
extraState
extraDebugState
extraActions
extraFlags
extraPeers
extraAPI
Expand Down Expand Up @@ -254,7 +251,7 @@ run :: forall extraArgs extraState extraDebugState extraActions extraAPI
-> Tracer m (TraceLabelPeer NtNAddr (TraceFetchClientState BlockHeader))
-> m Void
run blockGeneratorArgs limits ni na
emptyExtraState extraActions emptyExtraCounters
emptyExtraState emptyExtraCounters
extraPeersAPI psArgs psToExtraCounters
toExtraPeers requestPublicRootPeers peerChurnGovernor
tracersExtra tracerBlockFetch =
Expand Down Expand Up @@ -457,7 +454,7 @@ run blockGeneratorArgs limits ni na
}

argsExtra :: Common.ArgumentsExtra
extraArgs extraState extraDebugState extraActions
extraState extraDebugState
extraFlags extraPeers extraAPI
extraChurnArgs extraCounters exception
NtNAddr resolver resolverError m
Expand All @@ -475,9 +472,7 @@ run blockGeneratorArgs limits ni na
, Common.daEmptyExtraState = emptyExtraState
, Common.daEmptyExtraCounters = emptyExtraCounters
, Common.daExtraPeersAPI = extraPeersAPI
, Common.daExtraActions = extraActions
, Common.daExtraChurnArgs = aExtraChurnArgs na
, Common.daExtraArgs = aExtraArgs na
, Common.daToExtraPeers = toExtraPeers
, Common.daRequestPublicRootPeers = Just requestPublicRootPeers
, Common.daPeerChurnGovernor = peerChurnGovernor
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4011,9 +4011,10 @@ _governorFindingPublicRoots targetNumberOfRootPeers readDomains readUseBootstrap

peerSelectionGovernorArgs =
Cardano.cardanoPeerSelectionGovernorArgs
(return DontUseLedgerPeers)
peerSharing
(Cardano.updateOutboundConnectionsState (lpExtraAPI (getLedgerStateCtx actions)))
Cardano.ExtraPeerSelectionActions {
genesisPeerTargets = targets,
readUseBootstrapPeers = readUseBootstrapPeers
}


publicRootPeersProvider
Expand Down Expand Up @@ -4045,7 +4046,6 @@ _governorFindingPublicRoots targetNumberOfRootPeers readDomains readUseBootstrap
actions
:: PeerSelectionActions
Cardano.ExtraState
(Cardano.ExtraPeerSelectionActions IO)
PeerTrustable
(Cardano.ExtraPeers SockAddr)
(Cardano.LedgerPeersConsensusInterface IO)
Expand Down Expand Up @@ -4083,10 +4083,6 @@ _governorFindingPublicRoots targetNumberOfRootPeers readDomains readUseBootstrap
},
peerSelectionTargets = targets,
readLedgerPeerSnapshot = pure Nothing,
extraActions = Cardano.ExtraPeerSelectionActions {
genesisPeerTargets = targets,
readUseBootstrapPeers = readUseBootstrapPeers
},
extraStateToExtraCounters = ExtraSizes.cardanoPeerSelectionStatetoCounters,
extraPeersAPI = ExtraPeers.cardanoPublicRootPeersAPI
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,7 @@ governorAction mockEnv@GovernorMockEnvironment {
(useLedgerPeers mockEnv)
usbVar <- playTimedScript (contramap TraceEnvSetUseBootstrapPeers tracerMockEnv)
(useBootstrapPeers mockEnv)
let readUseBootstrapPeers = readTVar usbVar
-- todo: make NumberOfBigLedgerPeers come from quickcheck
debugStateVar <- StrictTVar.newTVarIO (emptyPeerSelectionState (mkStdGen 42) (ExtraState.empty consensusMode (NumberOfBigLedgerPeers 0)) ExtraPeers.empty)
countersVar <- StrictTVar.newTVarIO (emptyPeerSelectionCounters ExtraSizes.empty)
Expand All @@ -260,7 +261,7 @@ governorAction mockEnv@GovernorMockEnvironment {
(first fst <$> targets mockEnv)
mockPeerSelectionActions tracerMockEnv mockEnv
initialPeerTargets
(readTVar usbVar)
readUseBootstrapPeers
(readTVar lpVar)
(readTVar lsjVar)
(readTVar targetsVar)
Expand Down Expand Up @@ -293,9 +294,10 @@ governorAction mockEnv@GovernorMockEnvironment {

peerSelectionGovernorArgs =
Cardano.cardanoPeerSelectionGovernorArgs
(readTVar lpVar)
(peerSharing actions)
(Cardano.updateOutboundConnectionsState (lpExtraAPI (getLedgerStateCtx actions)))
Cardano.ExtraPeerSelectionActions {
Cardano.genesisPeerTargets = snd initialPeerTargets,
Cardano.readUseBootstrapPeers = readUseBootstrapPeers
}


exploreRaces -- explore races within the governor
Expand Down Expand Up @@ -360,7 +362,6 @@ mockPeerSelectionActions :: forall m.
-> STM m PeerSelectionTargets
-> m (PeerSelectionActions
Cardano.ExtraState
(Cardano.ExtraPeerSelectionActions m)
PeerTrustable
(Cardano.ExtraPeers PeerAddr)
(Cardano.LedgerPeersConsensusInterface m)
Expand Down Expand Up @@ -439,7 +440,6 @@ mockPeerSelectionActions' :: forall m.
-> TVar m OutboundConnectionsState
-> PeerSelectionActions
Cardano.ExtraState
(Cardano.ExtraPeerSelectionActions m)
PeerTrustable
(Cardano.ExtraPeers PeerAddr)
(Cardano.LedgerPeersConsensusInterface m)
Expand All @@ -453,7 +453,7 @@ mockPeerSelectionActions' tracer
publicRootPeers,
peerSharingFlag
}
(originalPeerTargets, peerTargets)
(originalPeerTargets, _peerTargets)
scripts
readTargets
readUseBootstrapPeers
Expand Down Expand Up @@ -498,10 +498,6 @@ mockPeerSelectionActions' tracer
readInboundPeers = pure Map.empty,
readLedgerPeerSnapshot = pure Nothing,
peerSelectionTargets = originalPeerTargets,
extraActions = Cardano.ExtraPeerSelectionActions {
Cardano.genesisPeerTargets = peerTargets,
Cardano.readUseBootstrapPeers = readUseBootstrapPeers
},
extraPeersAPI = ExtraPeers.cardanoPublicRootPeersAPI,
extraStateToExtraCounters = Cardano.cardanoPeerSelectionStatetoCounters
}
Expand Down Expand Up @@ -828,7 +824,6 @@ traceAssociationMode
(IOSim s)
-> PeerSelectionActions
Cardano.ExtraState
extraActions
extraFlags
extraPeers
extraAPI
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,9 @@ governor_BOOTSTRAP_PEERS_TIMEOUT = 15 * 60
-- set of target peers.
targetPeers
:: (MonadSTM m, Ord peeraddr)
=> PeerSelectionActions
=> Cardano.ExtraPeerSelectionActions m
-> PeerSelectionActions
Cardano.ExtraState
(Cardano.ExtraPeerSelectionActions m)
extraFlags
extraPeers
extraAPI
Expand All @@ -89,13 +89,14 @@ targetPeers
-> Guarded (STM m)
(TimedDecision m Cardano.ExtraState extraDebugState PeerTrustable
extraPeers peeraddr peerconn)
targetPeers PeerSelectionActions{ peerSelectionTargets,
readPeerSelectionTargets,
extraActions = Cardano.ExtraPeerSelectionActions {
Cardano.genesisPeerTargets
},
extraPeersAPI
}
targetPeers Cardano.ExtraPeerSelectionActions {
Cardano.genesisPeerTargets
}
PeerSelectionActions {
peerSelectionTargets,
readPeerSelectionTargets,
extraPeersAPI
}
st@PeerSelectionState{
publicRootPeers,
localRootPeers,
Expand Down Expand Up @@ -182,11 +183,10 @@ targetPeers PeerSelectionActions{ peerSelectionTargets,
-- trusted, however we will keep a connection to it until the outbound
-- governor notices it and disconnects from it.
localRoots
:: forall extraDebugState extraActions extraAPI extraCounters peeraddr peerconn m.
:: forall extraDebugState extraAPI extraCounters peeraddr peerconn m.
(MonadSTM m, Ord peeraddr)
=> PeerSelectionActions
Cardano.ExtraState
extraActions
PeerTrustable
(Cardano.ExtraPeers peeraddr)
extraAPI
Expand Down Expand Up @@ -380,9 +380,10 @@ monitorBootstrapPeersFlag
:: ( MonadSTM m
, Ord peeraddr
)
=> PeerSelectionActions
=> Cardano.ExtraPeerSelectionActions m
-> PeerSelectionActions
Cardano.ExtraState
(Cardano.ExtraPeerSelectionActions m)

extraFlags
(Cardano.ExtraPeers peeraddr)
extraAPI
Expand All @@ -399,11 +400,8 @@ monitorBootstrapPeersFlag
-> Guarded (STM m)
(TimedDecision m Cardano.ExtraState extraDebugState extraFlags
(Cardano.ExtraPeers peeraddr) peeraddr peerconn)
monitorBootstrapPeersFlag PeerSelectionActions { extraActions = Cardano.ExtraPeerSelectionActions {
Cardano.readUseBootstrapPeers
}
, extraPeersAPI
}
monitorBootstrapPeersFlag Cardano.ExtraPeerSelectionActions { Cardano.readUseBootstrapPeers }
PeerSelectionActions { extraPeersAPI }
st@PeerSelectionState { knownPeers
, establishedPeers
, publicRootPeers
Expand Down Expand Up @@ -465,11 +463,10 @@ monitorBootstrapPeersFlag PeerSelectionActions { extraActions = Cardano.ExtraPee
--
monitorLedgerStateJudgement
:: ( MonadSTM m
, Ord peeraddr
)
, Ord peeraddr
)
=> PeerSelectionActions
Cardano.ExtraState
(Cardano.ExtraPeerSelectionActions m)
extraFlags
(Cardano.ExtraPeers peeraddr)
(Cardano.LedgerPeersConsensusInterface m)
Expand Down Expand Up @@ -605,8 +602,8 @@ monitorLedgerStateJudgement PeerSelectionActions{
--
waitForSystemToQuiesce
:: ( MonadSTM m
, Ord peeraddr
)
, Ord peeraddr
)
=> PeerSelectionState
Cardano.ExtraState
PeerTrustable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,11 @@ import Ouroboros.Cardano.Network.PublicRootPeers qualified as Cardano
import Ouroboros.Network.PeerSelection.Governor (readAssociationMode)
import Ouroboros.Network.PeerSelection.Governor.Types (AssociationMode (..),
BootstrapPeersCriticalTimeoutError (..), ExtraGuardedDecisions (..),
PeerSelectionGovernorArgs (..), PeerSelectionSetsWithSizes,
PeerSelectionActions (..), PeerSelectionGovernorArgs (..),
PeerSelectionInterfaces (..), PeerSelectionSetsWithSizes,
PeerSelectionState (..), PeerSelectionView (..))
import Ouroboros.Network.PeerSelection.LedgerPeers.Type (UseLedgerPeers)
import Ouroboros.Network.PeerSelection.PeerSharing (PeerSharing)
import Ouroboros.Network.PeerSelection.LedgerPeers
(LedgerPeersConsensusInterface (lpExtraAPI))
import Ouroboros.Network.PeerSelection.PublicRootPeers qualified as PublicRootPeers
import Ouroboros.Network.PeerSelection.State.EstablishedPeers qualified as EstablishedPeers
import Ouroboros.Network.PeerSelection.State.LocalRootPeers qualified as LocalRootPeers
Expand Down Expand Up @@ -186,13 +187,10 @@ cardanoPeerSelectionGovernorArgs
, Alternative (STM m)
, Ord peeraddr
)
=> STM m UseLedgerPeers
-> PeerSharing
-> (OutboundConnectionsState -> STM m ())
=> Cardano.ExtraPeerSelectionActions m
-> PeerSelectionGovernorArgs
Cardano.ExtraState
extraDebugState
(Cardano.ExtraPeerSelectionActions m)
PeerTrustable
(Cardano.ExtraPeers peeraddr)
(Cardano.LedgerPeersConsensusInterface m)
Expand All @@ -201,7 +199,7 @@ cardanoPeerSelectionGovernorArgs
peerconn
BootstrapPeersCriticalTimeoutError
m
cardanoPeerSelectionGovernorArgs readUseLedgerPeers peerSharing updateOutboundConnectionsState =
cardanoPeerSelectionGovernorArgs extraActions =
PeerSelectionGovernorArgs {
-- If by any chance the node takes more than 15 minutes to converge to a
-- clean state, we crash the node. This could happen in very rare
Expand All @@ -214,21 +212,25 @@ cardanoPeerSelectionGovernorArgs readUseLedgerPeers peerSharing updateOutboundCo
Just t
| blockedAt >= t -> Just BootstrapPeersCriticalTimeoutError
| otherwise -> Nothing
, updateWithState = \psv st -> do
, updateWithState = \PeerSelectionInterfaces { readUseLedgerPeers }
PeerSelectionActions { getLedgerStateCtx,
peerSharing }
psv st -> do
associationMode <- readAssociationMode readUseLedgerPeers
peerSharing
(Cardano.bootstrapPeersFlag (extraState st))
updateOutboundConnectionsState
Cardano.updateOutboundConnectionsState
(lpExtraAPI getLedgerStateCtx)
Comment on lines +215 to +223
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice!

(outboundConnectionsState associationMode psv st)
, extraDecisions =
ExtraGuardedDecisions {
preBlocking = \_ psa pst ->
monitorBootstrapPeersFlag psa pst
monitorBootstrapPeersFlag extraActions psa pst
<> monitorLedgerStateJudgement psa pst
<> waitForSystemToQuiesce pst
, postBlocking = mempty
, postNonBlocking = mempty
, customTargetsAction = Just $ \_ -> Cardano.targetPeers
, customTargetsAction = Just $ \_ -> Cardano.targetPeers extraActions
, customLocalRootsAction = Just $ \_ -> Cardano.localRoots
, enableProgressMakingActions = \st ->
not (requiresBootstrapPeers (Cardano.bootstrapPeersFlag st) (Cardano.ledgerStateJudgement st))
Expand Down
Loading