Skip to content

Commit

Permalink
Change all 'gossip' words to 'Peer Share'
Browse files Browse the repository at this point in the history
  • Loading branch information
bolt12 committed Sep 30, 2022
1 parent 84ac3d8 commit 3836cdb
Show file tree
Hide file tree
Showing 13 changed files with 454 additions and 450 deletions.
Expand Up @@ -163,7 +163,7 @@ playTimedScript tracer (Script ((x0,d0) :| script)) = do
-- Pick scripts
--

-- | A pick script is used to interpret the 'policyPickKnownPeersForGossip' and
-- | A pick script is used to interpret the 'policyPickKnownPeersForPeerShare' and
-- the 'policyPickColdPeersToForget'. It selects elements from the given
-- choices by their index (modulo the number of choices). This representation
-- was chosen because it allows easy shrinking.
Expand Down
24 changes: 12 additions & 12 deletions ouroboros-network/src/Ouroboros/Network/Diffusion/Policies.hs
Expand Up @@ -78,21 +78,21 @@ simplePeerSelectionPolicy :: forall m peerAddr.
-> ReconnectDelay
-> PeerSelectionPolicy peerAddr m
simplePeerSelectionPolicy rngVar getChurnMode metrics errorDelay = PeerSelectionPolicy {
policyPickKnownPeersForGossip = simplePromotionPolicy,
policyPickColdPeersToPromote = simplePromotionPolicy,
policyPickWarmPeersToPromote = simplePromotionPolicy,
policyPickKnownPeersForPeerShare = simplePromotionPolicy,
policyPickColdPeersToPromote = simplePromotionPolicy,
policyPickWarmPeersToPromote = simplePromotionPolicy,

policyPickHotPeersToDemote = hotDemotionPolicy,
policyPickWarmPeersToDemote = warmDemotionPolicy,
policyPickColdPeersToForget = coldForgetPolicy,
policyPickHotPeersToDemote = hotDemotionPolicy,
policyPickWarmPeersToDemote = warmDemotionPolicy,
policyPickColdPeersToForget = coldForgetPolicy,

policyFindPublicRootTimeout = 5, -- seconds
policyMaxInProgressGossipReqs = 2,
policyGossipRetryTime = 3600, -- seconds
policyGossipBatchWaitTime = 3, -- seconds
policyGossipOverallTimeout = 10, -- seconds
policyFindPublicRootTimeout = 5, -- seconds
policyMaxInProgressPeerShareReqs = 2,
policyPeerShareRetryTime = 3600, -- seconds
policyPeerShareBatchWaitTime = 3, -- seconds
policyPeerShareOverallTimeout = 10, -- seconds

policyErrorDelay = ExitPolicy.reconnectDelay errorDelay
policyErrorDelay = ExitPolicy.reconnectDelay errorDelay
}
where

Expand Down
Expand Up @@ -23,10 +23,10 @@ module Ouroboros.Network.PeerSelection.EstablishedPeers
, setActivateTimes
-- ** Tracking when we can (re)activate
, minActivateTime
-- ** Tracking when we can gossip
, minGossipTime
, setGossipTime
, availableForGossip
-- ** Tracking when we can peer share
, minPeerShareTime
, setPeerShareTime
, availableForPeerShare
, invariant
) where

Expand Down Expand Up @@ -54,54 +54,54 @@ import Control.Monad.Class.MonadTime
--
-- It has one special feature:
--
-- * It tracks which peers we are permitted to gossip with now, or for peers
-- we cannot gossip with now the time at which we would next be allowed to
-- do so.
-- * It tracks which peers we are permitted to ask for peers now, or for peers
-- we cannot issue share requests with now the time at which we would next be
-- allowed to do so.
--
data EstablishedPeers peeraddr peerconn = EstablishedPeers {
-- | Peers which are either ready to become active or are active.
--
allPeers :: !(Map peeraddr peerconn),
allPeers :: !(Map peeraddr peerconn),

-- | The subset of established peers that we would be allowed to gossip with
-- now. This is because we have not gossiped with them recently.
-- | The subset of established peers that we would be allowed to peer share
-- with now. This is because we have not peer shared with them recently.
--
availableForGossip :: !(Set peeraddr),
availableForPeerShare :: !(Set peeraddr),

-- | The subset of established peers that we cannot gossip with now. It
-- keeps track of the next time we are allowed to gossip with them.
-- | The subset of established peers that we cannot peer share with now. It
-- keeps track of the next time we are allowed to peer share with them.
--
nextGossipTimes :: !(OrdPSQ peeraddr Time ()),
nextPeerShareTimes :: !(OrdPSQ peeraddr Time ()),


-- | Peers which are not ready to become active.
nextActivateTimes :: !(OrdPSQ peeraddr Time ())
nextActivateTimes :: !(OrdPSQ peeraddr Time ())
}
deriving (Show, Functor)


empty :: EstablishedPeers peeraddr perconn
empty = EstablishedPeers {
allPeers = Map.empty,
availableForGossip = Set.empty,
nextGossipTimes = PSQ.empty,
nextActivateTimes = PSQ.empty
allPeers = Map.empty,
availableForPeerShare = Set.empty,
nextPeerShareTimes = PSQ.empty,
nextActivateTimes = PSQ.empty
}


invariant :: Ord peeraddr
=> EstablishedPeers peeraddr peerconn
-> Bool
invariant EstablishedPeers {..} =
-- The combo of the gossip set + psq = the whole set of peers
availableForGossip
<> Set.fromList (PSQ.keys nextGossipTimes)
-- The combo of the peer share set + psq = the whole set of peers
availableForPeerShare
<> Set.fromList (PSQ.keys nextPeerShareTimes)
== Map.keysSet allPeers
-- The gossip set and psq do not overlap
-- The peer share set and psq do not overlap
&& Set.null
(Set.intersection
availableForGossip
(Set.fromList (PSQ.keys nextGossipTimes)))
availableForPeerShare
(Set.fromList (PSQ.keys nextPeerShareTimes)))
-- nextActivateTimes is a subset of allPeers
&& Set.fromList (PSQ.keys nextActivateTimes)
`Set.isSubsetOf`
Expand Down Expand Up @@ -160,32 +160,32 @@ insert :: Ord peeraddr
-> peerconn
-> EstablishedPeers peeraddr peerconn
-> EstablishedPeers peeraddr peerconn
insert peeraddr peerconn ep@EstablishedPeers { allPeers, availableForGossip } =
insert peeraddr peerconn ep@EstablishedPeers { allPeers, availableForPeerShare } =
ep { allPeers = Map.insert peeraddr peerconn allPeers,

-- The sets tracking peers ready for gossip need to be updated with any
-- The sets tracking peers ready for peer share need to be updated with any
-- /fresh/ peers, but any already present are ignored since they are
-- either already in these sets or they are in the corresponding PSQs,
-- for which we also preserve existing info.
availableForGossip =
availableForPeerShare =
if Map.member peeraddr allPeers
then availableForGossip
else Set.insert peeraddr availableForGossip
then availableForPeerShare
else Set.insert peeraddr availableForPeerShare
}

delete :: Ord peeraddr
=> peeraddr
-> EstablishedPeers peeraddr peerconn
-> EstablishedPeers peeraddr peerconn
delete peeraddr es@EstablishedPeers { allPeers
, availableForGossip
, nextGossipTimes
, availableForPeerShare
, nextPeerShareTimes
, nextActivateTimes
} =
es { allPeers = Map.delete peeraddr allPeers,
availableForGossip = Set.delete peeraddr availableForGossip,
nextGossipTimes = PSQ.delete peeraddr nextGossipTimes,
nextActivateTimes = PSQ.delete peeraddr nextActivateTimes
es { allPeers = Map.delete peeraddr allPeers,
availableForPeerShare = Set.delete peeraddr availableForPeerShare,
nextPeerShareTimes = PSQ.delete peeraddr nextPeerShareTimes,
nextActivateTimes = PSQ.delete peeraddr nextActivateTimes
}


Expand All @@ -197,15 +197,15 @@ deletePeers :: Ord peeraddr
-> EstablishedPeers peeraddr peerconn
-> EstablishedPeers peeraddr peerconn
deletePeers peeraddrs es@EstablishedPeers { allPeers
, availableForGossip
, nextGossipTimes
, availableForPeerShare
, nextPeerShareTimes
, nextActivateTimes
} =
es { allPeers = Map.withoutKeys allPeers peeraddrs,
availableForGossip = Set.difference availableForGossip peeraddrs,
nextGossipTimes =
List.foldl' (flip PSQ.delete) nextGossipTimes peeraddrs,
nextActivateTimes =
es { allPeers = Map.withoutKeys allPeers peeraddrs,
availableForPeerShare = Set.difference availableForPeerShare peeraddrs,
nextPeerShareTimes =
List.foldl' (flip PSQ.delete) nextPeerShareTimes peeraddrs,
nextActivateTimes =
List.foldl' (flip PSQ.delete) nextActivateTimes peeraddrs
}

Expand All @@ -218,33 +218,33 @@ setCurrentTime :: Ord peeraddr
=> Time
-> EstablishedPeers peeraddr peerconn
-> EstablishedPeers peeraddr peerconn
setCurrentTime now ep@EstablishedPeers { nextGossipTimes
setCurrentTime now ep@EstablishedPeers { nextPeerShareTimes
, nextActivateTimes
}
-- Efficient check for the common case of there being nothing to do:
| Just (Min t) <- (f <$> PSQ.minView nextGossipTimes)
| Just (Min t) <- (f <$> PSQ.minView nextPeerShareTimes)
<> (f <$> PSQ.minView nextActivateTimes)
, t > now
= ep
where
f (_,t,_,_) = Min t

setCurrentTime now ep@EstablishedPeers { nextGossipTimes
, availableForGossip
setCurrentTime now ep@EstablishedPeers { nextPeerShareTimes
, availableForPeerShare
, nextActivateTimes
} =
let ep' = ep { nextGossipTimes = nextGossipTimes'
, availableForGossip = availableForGossip'
, nextActivateTimes = nextActivateTimes'
let ep' = ep { nextPeerShareTimes = nextPeerShareTimes'
, availableForPeerShare = availableForPeerShare'
, nextActivateTimes = nextActivateTimes'
}
in assert (invariant ep') ep'
where
(nowAvailableForGossip, nextGossipTimes') =
PSQ.atMostView now nextGossipTimes
(nowAvailableForPeerShare, nextPeerShareTimes') =
PSQ.atMostView now nextPeerShareTimes

availableForGossip' =
availableForGossip
<> Set.fromList [ peeraddr | (peeraddr, _, _) <- nowAvailableForGossip ]
availableForPeerShare' =
availableForPeerShare
<> Set.fromList [ peeraddr | (peeraddr, _, _) <- nowAvailableForPeerShare ]

(_, nextActivateTimes') = PSQ.atMostView now nextActivateTimes

Expand Down Expand Up @@ -283,45 +283,46 @@ setActivateTimes times ep@EstablishedPeers { nextActivateTimes } =
$ ep'

-------------------------------
-- Tracking when we can gossip
-- Tracking when we can peer share
--

-- | The first time that a peer will become available for gossip. If peers are
-- already available for gossip, or there are no peers at all then the
-- result is @Nothing@.
-- | The first time that a peer will become available for peer sharing. If
-- peers are already available for peer share, or there are no peers at all
-- then the result is @Nothing@.
--
minGossipTime :: Ord peeraddr => EstablishedPeers peeraddr peercon -> Maybe Time
minGossipTime EstablishedPeers {
availableForGossip,
nextGossipTimes
}
| Set.null availableForGossip
, Just (_k, t, _, _psq) <- PSQ.minView nextGossipTimes
minPeerShareTime :: Ord peeraddr
=> EstablishedPeers peeraddr peercon
-> Maybe Time
minPeerShareTime EstablishedPeers { availableForPeerShare,
nextPeerShareTimes
}
| Set.null availableForPeerShare
, Just (_k, t, _, _psq) <- PSQ.minView nextPeerShareTimes
= Just t

| otherwise
= Nothing

setGossipTime :: Ord peeraddr
=> Set peeraddr
-> Time
-> EstablishedPeers peeraddr peercon
-> EstablishedPeers peeraddr peercon
setGossipTime peeraddrs time
knownPeers@EstablishedPeers {
allPeers,
availableForGossip,
nextGossipTimes
} =
setPeerShareTime :: Ord peeraddr
=> Set peeraddr
-> Time
-> EstablishedPeers peeraddr peercon
-> EstablishedPeers peeraddr peercon
setPeerShareTime peeraddrs time
knownPeers@EstablishedPeers {
allPeers,
availableForPeerShare,
nextPeerShareTimes
} =
assert (all (`Map.member` allPeers) peeraddrs) $
let knownPeers' = knownPeers {
availableForGossip =
availableForGossip
availableForPeerShare =
availableForPeerShare
Set.\\ peeraddrs,

nextGossipTimes =
nextPeerShareTimes =
List.foldl' (\psq peeraddr -> PSQ.insert peeraddr time () psq)
nextGossipTimes
nextPeerShareTimes
peeraddrs
}
in assert (invariant knownPeers') knownPeers'
Expand Down
Expand Up @@ -73,15 +73,15 @@ We have a number of requirements for constructing our connectivity graphs:
[\"Small world" graph theory](https://press.princeton.edu/books/paperback/9780691117041/small-worlds)
tells us that we can use random graph construction to make graphs with a low
characteristic path length (i.e. hop count). We can build random graphs with
random gossip techniques. This deals with our requirement for decentralisation
peer sharing techniques. This deals with our requirement for decentralisation
and our goal of low hop counts.
The remaining significant issues are:
* the goal of short hop lengths, and
* avoiding and recovering from partitions and eclipse attacks.
Our design is to augment random gossip with two /governors/ (control loops) to
Our design is to augment random peer sharing with two /governors/ (control loops) to
address these two issues. The design is relatively simple, and has the virtue
that the policy for the governors can be adjusted with relatively few
compatibility impacts. This should enable the policy to be optimised based on
Expand Down Expand Up @@ -113,11 +113,11 @@ new nodes must do.
For an individual node to join the network, the bootstrapping phase starts by
contacting root nodes and requesting sets of other peers. Newly discovered
peers are added to the cold peer set. It proceeds iteratively by randomly
selecting other peers to contact to request more known peers. This gossip
selecting other peers to contact to request more known peers. This peer sharing
process is controlled by a governor that has a target to find and maintain a
certain number of cold peers. Bootstrapping is not a special mode, rather it is
just a phase for the governor following starting with a cold peers set
consisting only of the root nodes. This gossiping aspect is closely analogous
consisting only of the root nodes. This peer sharing aspect is closely analogous
to the first stage of Kademlia, but with random selection rather than selection
directed towards finding peers in an artificial metric space.
Expand All @@ -129,7 +129,7 @@ the software.
The peer selection governor engages in the following activities:
* the random gossip used to discover more cold peers;
* the random peer share used to discover more cold peers;
* promotion of cold peers to be warm peers;
* demotion of warm peers to cold peers;
* promotion of warm peers to hot peers; and
Expand Down Expand Up @@ -163,7 +163,7 @@ that sends the block header.
While the purpose of cold and hot peers is clear, the purpose of warm peers
requires further explanation. The primary purpose is to address the challenge
of avoiding too many long hops in the graph. The random gossip is oblivious to
of avoiding too many long hops in the graph. The random peer share is oblivious to
hop distance. By actually connecting to a selection of peers and measuring the
round trip delays we can start to establish which peers are near or far. The
policy for selecting which warm peers to promote to hot peers will take into
Expand Down Expand Up @@ -307,7 +307,7 @@ We will consider each case.
There are two main mechanisms by which we discover cold peers:
* Externally supplied peer root set
* Peer gossip
* Peer Share
=== Externally supplied peer root set
Expand All @@ -333,7 +333,7 @@ set of addresses, and the peer selection governor observes the time-varying
value. This allows multiple implementations of the root set provider, which
deal with the various sources.
=== Peer gossip
=== Peer Share
We can ask peers to give us a sample of their set of known peers.
Expand Down

0 comments on commit 3836cdb

Please sign in to comment.