@@ -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