Skip to content

Commit

Permalink
Merge pull request #4901 from IntersectMBO/karknu/merg_tst
Browse files Browse the repository at this point in the history
8.12.x changes to master
  • Loading branch information
karknu authored Jul 2, 2024
2 parents bee883f + d88a587 commit e28027d
Show file tree
Hide file tree
Showing 8 changed files with 60 additions and 33 deletions.
8 changes: 8 additions & 0 deletions ouroboros-network-framework/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@

## next release

## 0.13.2.1 -- 2024-06-26

### Breaking changes

### Non-breaking changes

- Fix `InboundGovernorCounters`

## 0.13.2.0 -- 2024-06-07

### Breaking changes
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
cabal-version: 3.0
name: ouroboros-network-framework
version: 0.13.2.0
version: 0.13.2.1
synopsis: Ouroboros network framework
description: Ouroboros network framework.
license: Apache-2.0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,14 +163,6 @@ withInboundGovernor trTracer tracer debugTracer inboundInfoChannel
-> InboundGovernorState muxMode initiatorCtx peerAddr versionData m a b
-> m Void
inboundGovernorLoop var !state = do
mapTraceWithCache TrInboundGovernorCounters
tracer
(igsCountersCache state)
(inboundGovernorCounters state)
traceWith tracer $ TrRemoteState $
mkRemoteSt . csRemoteState
<$> igsConnections state

time <- getMonotonicTime
inactivityVar <- registerDelay inactionTimeout

Expand Down Expand Up @@ -526,6 +518,14 @@ withInboundGovernor trTracer tracer debugTracer inboundInfoChannel
Just cid -> traceWith trTracer (mkRemoteTransitionTrace cid state state')
Nothing -> pure ()

mapTraceWithCache TrInboundGovernorCounters
tracer
(igsCountersCache state')
(inboundGovernorCounters state')
traceWith tracer $ TrRemoteState $
mkRemoteSt . csRemoteState
<$> igsConnections state'

-- Update Inbound Governor Counters cache values
let newCounters = inboundGovernorCounters state'
Cache oldCounters = igsCountersCache state'
Expand Down
9 changes: 9 additions & 0 deletions ouroboros-network/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,15 @@
* Refactored signature of `LedgerPeers.ledgerPeersThread` for concision
and use of previously created records for shunting related values around.

## 0.16.1.1 -- 2024-06-28

### Breaking changes

### Non-Breaking changes

- Increase the target number of active peers during bulk sync to account for hot
trusted localroot peers.

## 0.16.1.0 -- 2024-06-07

### Breaking changes
Expand Down
2 changes: 1 addition & 1 deletion ouroboros-network/ouroboros-network.cabal
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
cabal-version: 3.0
name: ouroboros-network
version: 0.16.1.0
version: 0.16.1.1
synopsis: A networking layer for the Ouroboros blockchain protocol
description: A networking layer for the Ouroboros blockchain protocol.
license: Apache-2.0
Expand Down
12 changes: 5 additions & 7 deletions ouroboros-network/src/Ouroboros/Network/Diffusion/P2P.hs
Original file line number Diff line number Diff line change
Expand Up @@ -807,12 +807,9 @@ runM Interfaces

churnModeVar <- newTVarIO ChurnModeNormal

peerSelectionTargetsVar <- newTVarIO $ daPeerSelectionTargets {
-- Start with a smaller number of active peers, the churn governor
-- will increase it to the configured value after a delay.
targetNumberOfActivePeers =
min 2 (targetNumberOfActivePeers daPeerSelectionTargets)
}
localRootsVar <- newTVarIO mempty

peerSelectionTargetsVar <- newTVarIO $ daPeerSelectionTargets

countersVar <- newTVarIO emptyPeerSelectionCounters

Expand Down Expand Up @@ -965,7 +962,7 @@ runM Interfaces
-- (only if local root peers were non-empty).
-> m c
withPeerSelectionActions' readInboundPeers =
withPeerSelectionActions PeerActionsDNS {
withPeerSelectionActions localRootsVar PeerActionsDNS {
paToPeerAddr = diNtnToPeerAddr,
paDnsActions = diDnsActions lookupReqs,
paDnsSemaphore = dnsSemaphore }
Expand Down Expand Up @@ -1032,6 +1029,7 @@ runM Interfaces
peerSelectionTargetsVar
(readTVar countersVar)
daReadUseBootstrapPeers
((LocalRootPeers.hotTarget . LocalRootPeers.clampToTrustable . LocalRootPeers.fromGroups) <$> (readTVar localRootsVar))

--
-- Two functions only used in InitiatorAndResponder mode
Expand Down
38 changes: 25 additions & 13 deletions ouroboros-network/src/Ouroboros/Network/PeerSelection/Churn.hs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import Ouroboros.Network.Diffusion.Policies (churnEstablishConnectionTimeout,
import Ouroboros.Network.PeerSelection.Bootstrap (UseBootstrapPeers (..))
import Ouroboros.Network.PeerSelection.Governor.Types hiding (targets)
import Ouroboros.Network.PeerSelection.PeerMetric
import Ouroboros.Network.PeerSelection.State.LocalRootPeers (HotValency (..))


type ModifyPeerSelectionTargets = PeerSelectionTargets -> PeerSelectionTargets
Expand Down Expand Up @@ -73,29 +74,37 @@ peerChurnGovernor :: forall m peeraddr.
-> StrictTVar m PeerSelectionTargets
-> STM m PeerSelectionCounters
-> STM m UseBootstrapPeers
-> STM m HotValency
-> m Void
peerChurnGovernor tracer churnTracer
deadlineChurnInterval bulkChurnInterval requestPeersTimeout
_metrics churnModeVar inRng getFetchMode base
peerSelectionVar readCounters
getUseBootstrapPeers = do
getUseBootstrapPeers getLocalRootHotTarget = do
-- Wait a while so that not only the closest peers have had the time
-- to become warm.
startTs0 <- getMonotonicTime
-- TODO: revisit the policy once we have local root peers in the governor.
-- The intention is to give local root peers give head start and avoid
-- giving advantage to hostile and quick root peers.
threadDelay 3
(mode, ubp) <- atomically ((,) <$> updateChurnMode
<*> getUseBootstrapPeers)
(mode, ubp, ltt) <- atomically getExtState
traceWith tracer $ TraceChurnMode mode
atomically $ do
modifyTVar peerSelectionVar ( increaseActivePeers mode
modifyTVar peerSelectionVar ( increaseActivePeers mode ltt
. increaseEstablishedPeers mode ubp )
endTs0 <- getMonotonicTime
fuzzyDelay inRng (endTs0 `diffTime` startTs0) >>= churnLoop

where

getExtState :: STM m (ChurnMode, UseBootstrapPeers, HotValency)
getExtState = do
cm <- updateChurnMode
bp <- getUseBootstrapPeers
ltt <- getLocalRootHotTarget
return (cm, bp, ltt)

updateChurnMode :: STM m ChurnMode
updateChurnMode = do
fm <- getFetchMode
Expand Down Expand Up @@ -160,17 +169,18 @@ peerChurnGovernor tracer churnTracer

-- TODO: #3396 revisit the policy for genesis
increaseActivePeers :: ChurnMode
-> HotValency
-> ModifyPeerSelectionTargets
increaseActivePeers
mode targets
mode (HotValency ltt) targets
=
targets {
targetNumberOfActivePeers =
case mode of
ChurnModeNormal ->
targetNumberOfActivePeers base
ChurnModeBulkSync ->
min 2 (targetNumberOfActivePeers base)
min ((max 1 ltt) + 1) (targetNumberOfActivePeers base)
}

checkActivePeersIncreased :: CheckPeerSelectionCounters
Expand All @@ -181,15 +191,17 @@ peerChurnGovernor tracer churnTracer
numberOfActivePeers >= targetNumberOfActivePeers


decreaseActivePeers :: ChurnMode -> ModifyPeerSelectionTargets
decreaseActivePeers mode targets =
decreaseActivePeers :: ChurnMode
-> HotValency
-> ModifyPeerSelectionTargets
decreaseActivePeers mode (HotValency ltt) targets =
targets {
targetNumberOfActivePeers =
case mode of
ChurnModeNormal ->
decrease $ targetNumberOfActivePeers base
ChurnModeBulkSync ->
min 1 (targetNumberOfActivePeers base - 1)
min (max 1 ltt) (targetNumberOfActivePeers base - 1)
}

checkActivePeersDecreased :: CheckPeerSelectionCounters
Expand Down Expand Up @@ -417,22 +429,22 @@ peerChurnGovernor tracer churnTracer
churnLoop !rng = do
startTs <- getMonotonicTime

(churnMode, ubp) <- atomically ((,) <$> updateChurnMode
<*> getUseBootstrapPeers)
(churnMode, ubp, ltt) <- atomically getExtState

traceWith tracer $ TraceChurnMode churnMode

-- Purge the worst active peers.
updateTargets DecreasedActivePeers
numberOfActivePeers
deactivateTimeout -- chainsync might timeout after 5mins
(decreaseActivePeers churnMode)
(decreaseActivePeers churnMode ltt)
checkActivePeersDecreased

-- Pick new active peers.
updateTargets IncreasedActivePeers
numberOfActivePeers
shortTimeout
(increaseActivePeers churnMode)
(increaseActivePeers churnMode ltt)
checkActivePeersIncreased

-- Purge the worst active big ledger peers.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,8 @@ withPeerSelectionActions
, Ord peeraddr
, Exception exception
)
=> PeerActionsDNS peeraddr resolver exception m
=> StrictTVar m (Config peeraddr)
-> PeerActionsDNS peeraddr resolver exception m
-> PeerSelectionActionsArgs peeraddr peerconn exception m
-> WithLedgerPeersArgs m
-> PeerSelectionActionsDiffusionMode peeraddr peerconn m
Expand All @@ -104,6 +105,7 @@ withPeerSelectionActions
-- (only if local root peers were non-empty).
-> m a
withPeerSelectionActions
localRootsVar
paDNS@PeerActionsDNS { paToPeerAddr = toPeerAddr, paDnsActions = dnsActions, paDnsSemaphore = dnsSemaphore }
PeerSelectionActionsArgs {
psLocalRootPeersTracer = localTracer,
Expand All @@ -121,8 +123,6 @@ withPeerSelectionActions
ledgerPeersArgs
PeerSelectionActionsDiffusionMode { psPeerStateActions = peerStateActions }
k = do
localRootsVar <- newTVarIO mempty

withLedgerPeers
paDNS
ledgerPeersArgs
Expand Down

0 comments on commit e28027d

Please sign in to comment.