ouroboros-network
Safe HaskellNone
LanguageHaskell2010

Ouroboros.Network.PeerSelection.LedgerPeers

Synopsis

Documentation

data DomainAccessPoint #

A product of a Domain and PortNumber. After resolving the domain we will use the PortNumber to form SockAddr.

Instances

Instances details
FromJSON DomainAccessPoint 
Instance details

Defined in Ouroboros.Network.PeerSelection.RelayAccessPoint

ToJSON DomainAccessPoint 
Instance details

Defined in Ouroboros.Network.PeerSelection.RelayAccessPoint

Show DomainAccessPoint 
Instance details

Defined in Ouroboros.Network.PeerSelection.RelayAccessPoint

Eq DomainAccessPoint 
Instance details

Defined in Ouroboros.Network.PeerSelection.RelayAccessPoint

Ord DomainAccessPoint 
Instance details

Defined in Ouroboros.Network.PeerSelection.RelayAccessPoint

data IP #

A unified IP data for IPv4 and IPv6. To create this, use the data constructors. Or use read "192.0.2.1" :: IP, for example. Also, "192.0.2.1" can be used as literal with OverloadedStrings.

>>> (read "192.0.2.1" :: IP) == IPv4 (read "192.0.2.1" :: IPv4)
True
>>> (read "2001:db8:00:00:00:00:00:01" :: IP) == IPv6 (read "2001:db8:00:00:00:00:00:01" :: IPv6)
True

Constructors

IPv4 

Fields

IPv6 

Fields

Instances

Instances details
Data IP 
Instance details

Defined in Data.IP.Addr

Methods

gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> IP -> c IP #

gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c IP #

toConstr :: IP -> Constr #

dataTypeOf :: IP -> DataType #

dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c IP) #

dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c IP) #

gmapT :: (forall b. Data b => b -> b) -> IP -> IP #

gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> IP -> r #

gmapQr :: forall r r'. (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> IP -> r #

gmapQ :: (forall d. Data d => d -> u) -> IP -> [u] #

gmapQi :: Int -> (forall d. Data d => d -> u) -> IP -> u #

gmapM :: Monad m => (forall d. Data d => d -> m d) -> IP -> m IP #

gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> IP -> m IP #

gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> IP -> m IP #

IsString IP 
Instance details

Defined in Data.IP.Addr

Methods

fromString :: String -> IP #

Enum IP 
Instance details

Defined in Data.IP.Addr

Methods

succ :: IP -> IP #

pred :: IP -> IP #

toEnum :: Int -> IP #

fromEnum :: IP -> Int #

enumFrom :: IP -> [IP] #

enumFromThen :: IP -> IP -> [IP] #

enumFromTo :: IP -> IP -> [IP] #

enumFromThenTo :: IP -> IP -> IP -> [IP] #

Generic IP 
Instance details

Defined in Data.IP.Addr

Associated Types

type Rep IP 
Instance details

Defined in Data.IP.Addr

type Rep IP = D1 ('MetaData "IP" "Data.IP.Addr" "iproute-1.7.12-d41755f9302e1993407507681e30b3bc13ae12497cd5c62c21eb74709e2da91f" 'False) (C1 ('MetaCons "IPv4" 'PrefixI 'True) (S1 ('MetaSel ('Just "ipv4") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedUnpack) (Rec0 IPv4)) :+: C1 ('MetaCons "IPv6" 'PrefixI 'True) (S1 ('MetaSel ('Just "ipv6") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedStrict) (Rec0 IPv6)))

Methods

from :: IP -> Rep IP x #

to :: Rep IP x -> IP #

Read IP 
Instance details

Defined in Data.IP.Addr

Show IP 
Instance details

Defined in Data.IP.Addr

Methods

showsPrec :: Int -> IP -> ShowS #

show :: IP -> String #

showList :: [IP] -> ShowS #

Eq IP

Equality over IP addresses. Correctly compare IPv4 and IPv4-embedded-in-IPv6 addresses.

>>> (read "2001:db8:00:00:00:00:00:01" :: IP) == (read "2001:db8:00:00:00:00:00:01" :: IP)
True
>>> (read "2001:db8:00:00:00:00:00:01" :: IP) == (read "2001:db8:00:00:00:00:00:05" :: IP)
False
>>> (read "127.0.0.1" :: IP) == (read "127.0.0.1" :: IP)
True
>>> (read "127.0.0.1" :: IP) == (read "10.0.0.1" :: IP)
False
>>> (read "::ffff:127.0.0.1" :: IP) == (read "127.0.0.1" :: IP)
True
>>> (read "::ffff:127.0.0.1" :: IP) == (read "127.0.0.9" :: IP)
False
>>> (read "::ffff:127.0.0.1" :: IP) >= (read "127.0.0.1" :: IP)
True
>>> (read "::ffff:127.0.0.1" :: IP) <= (read "127.0.0.1" :: IP)
True
Instance details

Defined in Data.IP.Addr

Methods

(==) :: IP -> IP -> Bool #

(/=) :: IP -> IP -> Bool #

Ord IP 
Instance details

Defined in Data.IP.Addr

Methods

compare :: IP -> IP -> Ordering #

(<) :: IP -> IP -> Bool #

(<=) :: IP -> IP -> Bool #

(>) :: IP -> IP -> Bool #

(>=) :: IP -> IP -> Bool #

max :: IP -> IP -> IP #

min :: IP -> IP -> IP #

type Rep IP 
Instance details

Defined in Data.IP.Addr

type Rep IP = D1 ('MetaData "IP" "Data.IP.Addr" "iproute-1.7.12-d41755f9302e1993407507681e30b3bc13ae12497cd5c62c21eb74709e2da91f" 'False) (C1 ('MetaCons "IPv4" 'PrefixI 'True) (S1 ('MetaSel ('Just "ipv4") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedUnpack) (Rec0 IPv4)) :+: C1 ('MetaCons "IPv6" 'PrefixI 'True) (S1 ('MetaSel ('Just "ipv6") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedStrict) (Rec0 IPv6)))

data LedgerPeers Source #

Ledger Peer request result

Constructors

LedgerPeers 

Fields

BeforeSlot

No result because the node is still before the configured UseLedgerAfter slot number

getLedgerPeers :: forall (m :: Type -> Type). MonadSTM m => LedgerPeersConsensusInterface m -> AfterSlot -> STM m LedgerPeers Source #

Internal API to deal with UseLedgerAfter configuration option

Receiving the LedgerPeersConsensusInterface we are able to compute a function that given a SlotNo will give us LedgerPeers according to the following invariants:

  • BeforeSlot is returned iff the latest slot is before the slotNo;
  • 'LedgerPeers lsj peers' is returned iff the latest slot is after the slotNo.

data RelayAccessPoint #

A relay can have either an IP address and a port number or a domain with a port number

Bundled Patterns

pattern RelayDomainAccessPoint :: DomainAccessPoint -> RelayAccessPoint

RelayDomainAccessPoint a bidirectional pattern which links RelayAccessDomain and DomainAccessPoint.

Instances

Instances details
FromJSON RelayAccessPoint 
Instance details

Defined in Ouroboros.Network.PeerSelection.RelayAccessPoint

ToJSON RelayAccessPoint 
Instance details

Defined in Ouroboros.Network.PeerSelection.RelayAccessPoint

NFData RelayAccessPoint 
Instance details

Defined in Ouroboros.Network.PeerSelection.RelayAccessPoint

Methods

rnf :: RelayAccessPoint -> () #

Show RelayAccessPoint 
Instance details

Defined in Ouroboros.Network.PeerSelection.RelayAccessPoint

Eq RelayAccessPoint 
Instance details

Defined in Ouroboros.Network.PeerSelection.RelayAccessPoint

Ord RelayAccessPoint 
Instance details

Defined in Ouroboros.Network.PeerSelection.RelayAccessPoint

newtype PoolStake #

The relative stake of a stakepool in relation to the total amount staked. A value in the [0, 1] range.

Constructors

PoolStake 

Instances

Instances details
NFData PoolStake 
Instance details

Defined in Ouroboros.Network.PeerSelection.LedgerPeers.Type

Methods

rnf :: PoolStake -> () #

Num PoolStake 
Instance details

Defined in Ouroboros.Network.PeerSelection.LedgerPeers.Type

Fractional PoolStake 
Instance details

Defined in Ouroboros.Network.PeerSelection.LedgerPeers.Type

Show PoolStake 
Instance details

Defined in Ouroboros.Network.PeerSelection.LedgerPeers.Type

Eq PoolStake 
Instance details

Defined in Ouroboros.Network.PeerSelection.LedgerPeers.Type

Ord PoolStake 
Instance details

Defined in Ouroboros.Network.PeerSelection.LedgerPeers.Type

newtype AccPoolStake #

The accumulated relative stake of a stake pool, like PoolStake but it also includes the relative stake of all preceding pools. A value in the range [0, 1].

Constructors

AccPoolStake 

Instances

Instances details
Num AccPoolStake 
Instance details

Defined in Ouroboros.Network.PeerSelection.LedgerPeers.Type

Fractional AccPoolStake 
Instance details

Defined in Ouroboros.Network.PeerSelection.LedgerPeers.Type

Show AccPoolStake 
Instance details

Defined in Ouroboros.Network.PeerSelection.LedgerPeers.Type

Eq AccPoolStake 
Instance details

Defined in Ouroboros.Network.PeerSelection.LedgerPeers.Type

Ord AccPoolStake 
Instance details

Defined in Ouroboros.Network.PeerSelection.LedgerPeers.Type

data TraceLedgerPeers Source #

Trace LedgerPeers events.

Constructors

PickedBigLedgerPeer RelayAccessPoint AccPoolStake PoolStake

Trace for a significant ledger peer picked with accumulated and relative stake of its pool.

PickedLedgerPeer RelayAccessPoint AccPoolStake PoolStake

Trace for a ledger peer picked with accumulated and relative stake of its pool.

PickedBigLedgerPeers NumberOfPeers [RelayAccessPoint] 
PickedLedgerPeers NumberOfPeers [RelayAccessPoint]

Trace for the number of peers and we wanted to pick and the list of peers picked.

FetchingNewLedgerState Int Int

Trace for fetching a new list of peers from the ledger. The first Int is the number of ledger peers returned the latter is the number of big ledger peers.

TraceLedgerPeersDomains [DomainAccessPoint] 
TraceLedgerPeersResult Domain [(IP, TTL)] 
TraceLedgerPeersFailure Domain DNSError 
DisabledLedgerPeers

Trace for when getting peers from the ledger is disabled, that is DontUseLedgerPeers.

TraceUseLedgerPeers UseLedgerPeers

Trace UseLedgerPeers value

WaitingOnRequest 
RequestForPeers NumberOfPeers 
ReusingLedgerState Int DiffTime 
FallingBackToPublicRootPeers 
NotEnoughBigLedgerPeers NumberOfPeers Int 
NotEnoughLedgerPeers NumberOfPeers Int 
UsingBigLedgerPeerSnapshot 

data LedgerPeersKind #

Which ledger peers to pick.

Ledger Peers specific functions

accPoolStake :: [(PoolStake, NonEmpty RelayAccessPoint)] -> Map AccPoolStake (PoolStake, NonEmpty RelayAccessPoint) Source #

Convert a list of pools with stake to a Map keyed on the accumulated stake. Consensus provides a list of pairs of relative stake and corresponding relays for all usable registered pools. By creating a Map keyed on the AccPoolStake that is the sum of the pool's relative stake and the stake of all preceding pools we can support weighted random selection in O(log n) time by taking advantage of Map.lookupGE (returns the smallest key greater or equal to the provided value).

accumulateBigLedgerStake :: [(PoolStake, NonEmpty RelayAccessPoint)] -> [(AccPoolStake, (PoolStake, NonEmpty RelayAccessPoint))] #

Sort ascendingly a given list of pools with stake, and tag each one with cumulative stake, with a cutoff at bigLedgerPeerQuota

accBigPoolStakeMap :: [(PoolStake, NonEmpty RelayAccessPoint)] -> Map AccPoolStake (PoolStake, NonEmpty RelayAccessPoint) Source #

Take the result of accBigPoolStake and turn it into

bigLedgerPeerQuota :: AccPoolStake #

The total accumulated stake of big ledger peers.

stakeMapWithSlotOverSource :: StakeMapOverSource -> (Map AccPoolStake (PoolStake, NonEmpty RelayAccessPoint), Map AccPoolStake (PoolStake, NonEmpty RelayAccessPoint), Maybe SlotNo) Source #

Build up a stake map to sample ledger peers from. The SlotNo, if different from 0, indicates that the maps are the stake pools from the snapshot taken from the particular slot number.

DNS based provider for ledger root peers

data WithLedgerPeersArgs (m :: Type -> Type) Source #

Argument record for withLedgerPeers

Constructors

WithLedgerPeersArgs 

Fields

withLedgerPeers :: forall peerAddr resolver exception m a. (MonadAsync m, MonadThrow m, MonadMonotonicTime m, Exception exception, Ord peerAddr) => PeerActionsDNS peerAddr resolver exception m -> WithLedgerPeersArgs m -> ((NumberOfPeers -> LedgerPeersKind -> m (Maybe (Set peerAddr, DiffTime))) -> Async m Void -> m a) -> m a Source #

For a LedgerPeers worker thread and submit request and receive responses.

data LedgerPeers Source #

Ledger Peer request result

Constructors

LedgerPeers 

Fields

BeforeSlot

No result because the node is still before the configured UseLedgerAfter slot number

data TraceLedgerPeers Source #

Trace LedgerPeers events.

Constructors

PickedBigLedgerPeer RelayAccessPoint AccPoolStake PoolStake

Trace for a significant ledger peer picked with accumulated and relative stake of its pool.

PickedLedgerPeer RelayAccessPoint AccPoolStake PoolStake

Trace for a ledger peer picked with accumulated and relative stake of its pool.

PickedBigLedgerPeers NumberOfPeers [RelayAccessPoint] 
PickedLedgerPeers NumberOfPeers [RelayAccessPoint]

Trace for the number of peers and we wanted to pick and the list of peers picked.

FetchingNewLedgerState Int Int

Trace for fetching a new list of peers from the ledger. The first Int is the number of ledger peers returned the latter is the number of big ledger peers.

TraceLedgerPeersDomains [DomainAccessPoint] 
TraceLedgerPeersResult Domain [(IP, TTL)] 
TraceLedgerPeersFailure Domain DNSError 
DisabledLedgerPeers

Trace for when getting peers from the ledger is disabled, that is DontUseLedgerPeers.

TraceUseLedgerPeers UseLedgerPeers

Trace UseLedgerPeers value

WaitingOnRequest 
RequestForPeers NumberOfPeers 
ReusingLedgerState Int DiffTime 
FallingBackToPublicRootPeers 
NotEnoughBigLedgerPeers NumberOfPeers Int 
NotEnoughLedgerPeers NumberOfPeers Int 
UsingBigLedgerPeerSnapshot 

data IsLedgerPeer Source #

Identifies a peer as coming from ledger or not

Constructors

IsLedgerPeer

a ledger peer.

IsNotLedgerPeer 

Internal only exported for testing purposes

resolveLedgerPeers :: forall m peerAddr resolver exception. (Ord peerAddr, MonadThrow m, MonadAsync m, Exception exception) => Tracer m TraceLedgerPeers -> (IP -> PortNumber -> peerAddr) -> DNSSemaphore m -> ResolvConf -> DNSActions resolver exception m -> [DomainAccessPoint] -> m (Map DomainAccessPoint (Set peerAddr)) Source #

Provides DNS resolution functionality.

Concurrently resolve DNS names, respecting the maxDNSConcurrency limit.