Skip to content

Commit

Permalink
Pass maybe Peer Advertise value to EstablishedPeers tasks
Browse files Browse the repository at this point in the history
  • Loading branch information
bolt12 committed Oct 26, 2023
1 parent 739c034 commit 519a137
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 8 deletions.
1 change: 1 addition & 0 deletions ouroboros-network/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
* Adds ledger peers to diffusion simulation
* Fix diffusion tests.
* `demo-chain-sync`: added option parser, added new options.
* Preserve `PeerAdvertise` information when connecting to peers.

## 0.9.1.0 -- 2023-08-22

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import System.Random (randomR)
import Ouroboros.Network.PeerSelection.Governor.Types
import Ouroboros.Network.PeerSelection.LedgerPeers
(IsBigLedgerPeer (..))
import Ouroboros.Network.PeerSelection.PeerAdvertise (PeerAdvertise)
import qualified Ouroboros.Network.PeerSelection.State.EstablishedPeers as EstablishedPeers
import qualified Ouroboros.Network.PeerSelection.State.KnownPeers as KnownPeers
import Ouroboros.Network.PeerSelection.State.LocalRootPeers
Expand Down Expand Up @@ -125,8 +126,9 @@ belowTargetLocal actions
inProgressPromoteCold = inProgressPromoteCold
<> selectedToPromote
},
decisionJobs = [ jobPromoteColdPeer actions peer IsNotBigLedgerPeer
| peer <- Set.toList selectedToPromote ]
decisionJobs = [ jobPromoteColdPeer actions peer mbPeerAdvertise IsNotBigLedgerPeer
| peer <- Set.toList selectedToPromote
, let mbPeerAdvertise = KnownPeers.lookupPeerAdvertise peer knownPeers ]
}

-- If we could promote except that there are no peers currently available
Expand Down Expand Up @@ -215,8 +217,10 @@ belowTargetOther actions
inProgressPromoteCold = inProgressPromoteCold
<> selectedToPromote
},
decisionJobs = [ jobPromoteColdPeer actions peer IsNotBigLedgerPeer
| peer <- Set.toList selectedToPromote ]
decisionJobs = [ jobPromoteColdPeer actions peer mbPeerAdvertise IsNotBigLedgerPeer
| peer <- Set.toList selectedToPromote
, let mbPeerAdvertise = KnownPeers.lookupPeerAdvertise peer knownPeers
]
}

-- If we could connect except that there are no peers currently available
Expand Down Expand Up @@ -294,8 +298,10 @@ belowTargetBigLedgerPeers actions
inProgressPromoteCold = inProgressPromoteCold
<> selectedToPromote
},
decisionJobs = [ jobPromoteColdPeer actions peer IsBigLedgerPeer
| peer <- Set.toList selectedToPromote ]
decisionJobs = [ jobPromoteColdPeer actions peer mbPeerAdvertise IsBigLedgerPeer
| peer <- Set.toList selectedToPromote
, let mbPeerAdvertise = KnownPeers.lookupPeerAdvertise peer knownPeers
]
}

-- If we could connect except that there are no peers currently available
Expand Down Expand Up @@ -335,12 +341,13 @@ jobPromoteColdPeer :: forall peeraddr peerconn m.
(Monad m, Ord peeraddr)
=> PeerSelectionActions peeraddr peerconn m
-> peeraddr
-> Maybe PeerAdvertise
-> IsBigLedgerPeer
-> Job () m (Completion m peeraddr peerconn)
jobPromoteColdPeer PeerSelectionActions {
peerStateActions = PeerStateActions {establishPeerConnection},
peerConnToPeerSharing
} peeraddr isBigLedgerPeer =
} peeraddr mbPeerAdvertise isBigLedgerPeer =
Job job handler () "promoteColdPeer"
where
handler :: SomeException -> m (Completion m peeraddr peerconn)
Expand Down Expand Up @@ -415,7 +422,7 @@ jobPromoteColdPeer PeerSelectionActions {
-- Update PeerSharing value in KnownPeers
-- This will compute the appropriate peer sharing value using
-- 'combinePeerInformation'
knownPeers' = KnownPeers.insert (Map.singleton peeraddr (Just peerSharing, Nothing, Nothing))
knownPeers' = KnownPeers.insert (Map.singleton peeraddr (Just peerSharing, mbPeerAdvertise, Nothing))
$ KnownPeers.clearTepidFlag peeraddr $
KnownPeers.resetFailCount
peeraddr
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ module Ouroboros.Network.PeerSelection.State.KnownPeers
, resetFailCount
, lookupFailCount
, lookupTepidFlag
, lookupPeerAdvertise
, setTepidFlag
, clearTepidFlag
-- ** Tracking when we can (re)connect
Expand Down Expand Up @@ -312,6 +313,13 @@ lookupTepidFlag :: Ord peeraddr
lookupTepidFlag peeraddr KnownPeers{allPeers} =
knownPeerTepid <$> Map.lookup peeraddr allPeers

lookupPeerAdvertise :: Ord peeraddr
=> peeraddr
-> KnownPeers peeraddr
-> Maybe PeerAdvertise
lookupPeerAdvertise peeraddr KnownPeers{allPeers} =
knownPeerAdvertise <$> Map.lookup peeraddr allPeers

setTepidFlag' :: Ord peeraddr
=> Bool
-> peeraddr
Expand Down

0 comments on commit 519a137

Please sign in to comment.