Skip to content

Commit c59a4f1

Browse files
Merge pull request #5209 from IntersectMBO/mw/test-false-positive
Peer selection bugfix and testing updates
2 parents 6e915d1 + 0ddc581 commit c59a4f1

File tree

11 files changed

+983
-651
lines changed

11 files changed

+983
-651
lines changed
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<!--
2+
A new scriv changelog fragment.
3+
4+
Uncomment the section that is right (remove the HTML comment wrapper).
5+
For top level release notes, leave all the headers commented out.
6+
-->
7+
8+
<!--
9+
### Breaking
10+
-->
11+
12+
### Non-Breaking
13+
14+
- fixed false positive in `prop_diffusion_target_active_below` testnet test
15+
- improved approach in general to target-chasing tests in diffusion testnet
16+
and PeerSelection mock environment tests.

cardano-diffusion/tests/lib/Test/Cardano/Network/Diffusion/Testnet.hs

Lines changed: 261 additions & 288 deletions
Large diffs are not rendered by default.

cardano-diffusion/tests/lib/Test/Cardano/Network/PeerSelection.hs

Lines changed: 563 additions & 264 deletions
Large diffs are not rendered by default.

cardano-diffusion/tests/lib/Test/Cardano/Network/PeerSelection/MockEnvironment.hs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -529,10 +529,7 @@ mockPeerSelectionActions' tracer
529529
Cardano.PublicRootPeers.fromPublicRootPeers publicConfigPeers
530530
| otherwise ->
531531
PublicRootPeers.fromLedgerPeers ledgerPeers
532-
BigLedgerPeers
533-
| Set.null ledgerPeers ->
534-
Cardano.PublicRootPeers.fromPublicRootPeers publicConfigPeers
535-
| otherwise ->
532+
BigLedgerPeers ->
536533
PublicRootPeers.fromBigLedgerPeers bigLedgerPeers
537534

538535
traceWith tracer (TraceEnvRootsResult (Set.toList (PublicRootPeers.toSet Cardano.ExtraPeers.toSet result)))
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<!--
2+
A new scriv changelog fragment.
3+
4+
Uncomment the section that is right (remove the HTML comment wrapper).
5+
For top level release notes, leave all the headers commented out.
6+
-->
7+
8+
### Breaking
9+
10+
- `linger` function's arm callback now returns a `Maybe Bool`
11+
- `keyedLinger'`s arm callback now returns a `Maybe (Set b)`
12+
- `keyedLinger'`'s arm callback now returns a `Maybe (Set b, DiffTime))`
13+
- The above changes allow those functions to reset signal state on `Nothing`
14+
15+
### Non-Breaking
16+
17+
- Added latch function to `Signal`
18+
- bugfix missed promotion/demotion opportunities in:
19+
- `ActivePeers.aboveTargetBigLedgerPeers`
20+
- `ActivePeers.aboveTargetOther`
21+
- `EstablishedPeers.aboveTargetOther`
22+
- `EstablishedPeers.aboveTargetBigLedgerPeers`
23+
- `EstablishedPeers.belowTargetLocal`
24+
- `EstablishedPeers.belowTargetOther`
25+
- `ActivePeers.belowTargetLocal`

ouroboros-network/lib/Ouroboros/Network/PeerSelection/Governor/ActivePeers.hs

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -259,11 +259,12 @@ belowTargetLocal actions@PeerSelectionActions {
259259
Set.\\ inProgressPromoteWarm
260260
Set.\\ inProgressDemoteWarm
261261
Set.\\ inProgressDemoteToCold
262-
numPromoteInProgress = Set.size inProgressPromoteWarm
263262
, not (Set.null availableToPromote)
264263
, (HotValency hotTarget, members, membersActive) <- groupsBelowTarget
265264
, let membersAvailableToPromote = Set.intersection
266265
members availableToPromote
266+
numPromoteInProgress = Set.size (Set.intersection
267+
inProgressPromoteWarm members)
267268
numMembersToPromote = hotTarget
268269
- Set.size membersActive
269270
- numPromoteInProgress
@@ -686,20 +687,25 @@ aboveTargetBigLedgerPeers actions@PeerSelectionActions {
686687
}
687688
-- Are we above the general target for number of active peers?
688689
| numActiveBigLedgerPeers > targetNumberOfActiveBigLedgerPeers
689-
690-
-- Would we demote any if we could?
691-
, let numPeersToDemote = numActiveBigLedgerPeers
690+
, let activeBigLedger = activePeers
691+
`Set.intersection` bigLedgerPeersSet
692+
-- Would we demote any if we could?
693+
numPeersToDemote = numActiveBigLedgerPeers
692694
- targetNumberOfActiveBigLedgerPeers
693695
- numDemoteInProgressBigLedgerPeers
696+
-- don't drop too many and don't fail to take an opportunity
697+
-- if there are warm peers which are async demoted
698+
- Set.size (Set.intersection
699+
inProgressDemoteToCold
700+
activeBigLedger)
694701
, numPeersToDemote > 0
695702

696703
-- Are there any hot peers we actually can pick to demote?
697704
-- For the moment we say we cannot demote local root peers.
698705
-- TODO: review this decision. If we want to be able to demote local root
699706
-- peers, e.g. for churn and improved selection, then we'll need an extra
700707
-- mechanism to avoid promotion/demotion loops for local peers.
701-
, let availableToDemote = activePeers
702-
`Set.intersection` bigLedgerPeersSet
708+
, let availableToDemote = activeBigLedger
703709
Set.\\ inProgressDemoteHot
704710
Set.\\ inProgressDemoteToCold
705711
Set.\\ LocalRootPeers.keysSet localRootPeers
@@ -890,23 +896,26 @@ aboveTargetOther actions@PeerSelectionActions {
890896
}
891897
-- Are we above the general target for number of active peers?
892898
| numActivePeers > targetNumberOfActivePeers
893-
894-
-- Would we demote any if we could?
895-
, let numPeersToDemote = numActivePeers
899+
, let activeNonBig = activePeers Set.\\ bigLedgerPeersSet
900+
-- Would we demote any if we could?
901+
numPeersToDemote = numActivePeers
896902
- targetNumberOfActivePeers
897903
- numDemoteInProgress
898-
- (Set.size inProgressDemoteToCold)
904+
-- don't drop too many and don't fail to take an opportunity
905+
-- if there are warm peers which are async demoted
906+
- Set.size (Set.intersection
907+
inProgressDemoteToCold
908+
activeNonBig)
899909
, numPeersToDemote > 0
900910

901911
-- Are there any hot peers we actually can pick to demote?
902912
-- For the moment we say we cannot demote local root peers.
903913
-- TODO: review this decision. If we want to be able to demote local root
904914
-- peers, e.g. for churn and improved selection, then we'll need an extra
905915
-- mechanism to avoid promotion/demotion loops for local peers.
906-
, let availableToDemote = activePeers
916+
, let availableToDemote = activeNonBig
907917
Set.\\ inProgressDemoteHot
908918
Set.\\ LocalRootPeers.keysSet localRootPeers
909-
Set.\\ bigLedgerPeersSet
910919
Set.\\ inProgressDemoteToCold
911920
, not (Set.null availableToDemote)
912921
= Guarded Nothing $ do

0 commit comments

Comments
 (0)