{-# LANGUAGE DataKinds #-}
{-# LANGUAGE LambdaCase #-}
module Ouroboros.Consensus.MiniProtocol.LeiosFetch.Decision
(
LeiosFetchRequest (..)
, LeiosBlockRequest (..)
, LeiosBlockTxsRequest (..)
, OfferedHalves (..)
, PeerOffer (..)
, OfferPrune (..)
, pruneOffers
, LeiosOutstanding (..)
, EbState (..)
, EbFetchState (..)
, ebStateOnset
, emptyLeiosOutstanding
, initializeLeiosOutstanding
, newLeiosJobPool
, acquireEbBody
, holdForgedEb
, recordReferencedPoint
, focusElectionIfUnfocused
, focusCertifiedEb
, trackCertifiedEb
, focusElection
, isFocusedPoint
, pruneOutstandingToImmTip
, removePeerFromOutstanding
, refundEbRequest
, refundTxRequest
, completeTxRequest
, LeiosFetchStaticEnv (..)
, defaultLeiosFetchStaticEnv
, leiosFetchLogicIteration
, fetchPriorityTiers
, peerBudget
) where
import Cardano.Slotting.Slot (SlotNo (..))
import qualified Data.Foldable as F
import Data.IntMap.NonEmpty (NEIntMap)
import qualified Data.IntMap.NonEmpty as NEIntMap
import qualified Data.IntMap.Strict as IntMap
import qualified Data.IntSet as IntSet
import Data.IntSet.NonEmpty (NEIntSet)
import qualified Data.IntSet.NonEmpty as NEIntSet
import Data.List (partition, sortOn)
import Data.List.NonEmpty (NonEmpty ((:|)), nonEmpty)
import Data.Map.NonEmpty (NEMap)
import qualified Data.Map.NonEmpty as NEMap
import Data.Map.Strict (Map)
import qualified Data.Map.Strict as Map
import Data.Maybe.Strict (StrictMaybe (..))
import Data.Ord (Down (..))
import Data.Sequence (Seq)
import qualified Data.Sequence as Seq
import Data.Sequence.NonEmpty (NESeq)
import qualified Data.Sequence.NonEmpty as NESeq
import Data.Set (Set)
import qualified Data.Set as Set
import Data.Set.NonEmpty (NESet)
import qualified Data.Set.NonEmpty as NESet
import Data.Word (Word64)
import Ouroboros.Consensus.BlockchainTime.WallClock.Types (RelativeTime)
import Ouroboros.Consensus.Forecast (OutsideForecastRange)
import Ouroboros.Consensus.Leios.Acquisitions (LeiosAcquisition (..))
import Ouroboros.Consensus.Leios.Types
( BytesSize
, ElectionId (..)
, EndorserBlockHash
, LeiosEbByteSizes
, LeiosPoint (..)
, SizeRole (..)
, TxHash
)
import qualified Ouroboros.Consensus.MiniProtocol.LeiosFetch.Jobs as Jobs
import Ouroboros.Consensus.MiniProtocol.LeiosFetch.Type (maxLeiosTxsRequestBytesSize)
import Ouroboros.Network.PeerSelection.LedgerPeers.Type (IsBigLedgerPeer (..))
import System.Random (StdGen)
data LeiosFetchRequest
= LeiosBlockRequest LeiosBlockRequest
| LeiosBlockTxsRequest LeiosBlockTxsRequest
data LeiosBlockRequest = MkLeiosBlockRequest
{ LeiosBlockRequest -> LeiosPoint
lbrPoint :: !LeiosPoint
, LeiosBlockRequest -> Word32
lbrOfferedSize :: !BytesSize
, LeiosBlockRequest -> LeiosEbByteSizes 'SizeLimit
lbrEbBounds :: !(LeiosEbByteSizes SizeLimit)
}
data LeiosBlockTxsRequest
= MkLeiosBlockTxsRequest
!LeiosPoint
!(NEIntMap Jobs.LeiosJob)
data OfferedHalves
=
OfferedBody !BytesSize
|
OfferedClosure
|
OfferedBodyAndClosure !BytesSize
deriving (OfferedHalves -> OfferedHalves -> Bool
(OfferedHalves -> OfferedHalves -> Bool)
-> (OfferedHalves -> OfferedHalves -> Bool) -> Eq OfferedHalves
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: OfferedHalves -> OfferedHalves -> Bool
== :: OfferedHalves -> OfferedHalves -> Bool
$c/= :: OfferedHalves -> OfferedHalves -> Bool
/= :: OfferedHalves -> OfferedHalves -> Bool
Eq, Int -> OfferedHalves -> ShowS
[OfferedHalves] -> ShowS
OfferedHalves -> String
(Int -> OfferedHalves -> ShowS)
-> (OfferedHalves -> String)
-> ([OfferedHalves] -> ShowS)
-> Show OfferedHalves
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> OfferedHalves -> ShowS
showsPrec :: Int -> OfferedHalves -> ShowS
$cshow :: OfferedHalves -> String
show :: OfferedHalves -> String
$cshowList :: [OfferedHalves] -> ShowS
showList :: [OfferedHalves] -> ShowS
Show)
instance Semigroup OfferedHalves where
OfferedBody Word32
size <> :: OfferedHalves -> OfferedHalves -> OfferedHalves
<> OfferedBody Word32
_ = Word32 -> OfferedHalves
OfferedBody Word32
size
OfferedBody Word32
size <> OfferedHalves
OfferedClosure = Word32 -> OfferedHalves
OfferedBodyAndClosure Word32
size
OfferedBody Word32
size <> OfferedBodyAndClosure Word32
_ = Word32 -> OfferedHalves
OfferedBodyAndClosure Word32
size
OfferedHalves
OfferedClosure <> OfferedBody Word32
size = Word32 -> OfferedHalves
OfferedBodyAndClosure Word32
size
OfferedHalves
OfferedClosure <> OfferedHalves
OfferedClosure = OfferedHalves
OfferedClosure
OfferedHalves
OfferedClosure <> OfferedBodyAndClosure Word32
size = Word32 -> OfferedHalves
OfferedBodyAndClosure Word32
size
OfferedBodyAndClosure Word32
size <> OfferedBody Word32
_ = Word32 -> OfferedHalves
OfferedBodyAndClosure Word32
size
OfferedBodyAndClosure Word32
size <> OfferedHalves
OfferedClosure = Word32 -> OfferedHalves
OfferedBodyAndClosure Word32
size
OfferedBodyAndClosure Word32
size <> OfferedBodyAndClosure Word32
_ = Word32 -> OfferedHalves
OfferedBodyAndClosure Word32
size
data PeerOffer = MkPeerOffer
{ PeerOffer -> StrictMaybe (LeiosEbByteSizes 'SizeLimit)
poEbBounds :: !(StrictMaybe (LeiosEbByteSizes SizeLimit))
, PeerOffer -> OfferedHalves
poOffered :: !OfferedHalves
}
deriving (PeerOffer -> PeerOffer -> Bool
(PeerOffer -> PeerOffer -> Bool)
-> (PeerOffer -> PeerOffer -> Bool) -> Eq PeerOffer
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: PeerOffer -> PeerOffer -> Bool
== :: PeerOffer -> PeerOffer -> Bool
$c/= :: PeerOffer -> PeerOffer -> Bool
/= :: PeerOffer -> PeerOffer -> Bool
Eq, Int -> PeerOffer -> ShowS
[PeerOffer] -> ShowS
PeerOffer -> String
(Int -> PeerOffer -> ShowS)
-> (PeerOffer -> String)
-> ([PeerOffer] -> ShowS)
-> Show PeerOffer
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> PeerOffer -> ShowS
showsPrec :: Int -> PeerOffer -> ShowS
$cshow :: PeerOffer -> String
show :: PeerOffer -> String
$cshowList :: [PeerOffer] -> ShowS
showList :: [PeerOffer] -> ShowS
Show)
data OfferPrune
=
PruneOffer
|
PruneOfferedBody
deriving (OfferPrune -> OfferPrune -> Bool
(OfferPrune -> OfferPrune -> Bool)
-> (OfferPrune -> OfferPrune -> Bool) -> Eq OfferPrune
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: OfferPrune -> OfferPrune -> Bool
== :: OfferPrune -> OfferPrune -> Bool
$c/= :: OfferPrune -> OfferPrune -> Bool
/= :: OfferPrune -> OfferPrune -> Bool
Eq, Int -> OfferPrune -> ShowS
[OfferPrune] -> ShowS
OfferPrune -> String
(Int -> OfferPrune -> ShowS)
-> (OfferPrune -> String)
-> ([OfferPrune] -> ShowS)
-> Show OfferPrune
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> OfferPrune -> ShowS
showsPrec :: Int -> OfferPrune -> ShowS
$cshow :: OfferPrune -> String
show :: OfferPrune -> String
$cshowList :: [OfferPrune] -> ShowS
showList :: [OfferPrune] -> ShowS
Show)
pruneOffers :: Map LeiosPoint OfferPrune -> Map LeiosPoint PeerOffer -> Map LeiosPoint PeerOffer
pruneOffers :: Map LeiosPoint OfferPrune
-> Map LeiosPoint PeerOffer -> Map LeiosPoint PeerOffer
pruneOffers Map LeiosPoint OfferPrune
prunes Map LeiosPoint PeerOffer
offers = (Map LeiosPoint PeerOffer
-> LeiosPoint -> OfferPrune -> Map LeiosPoint PeerOffer)
-> Map LeiosPoint PeerOffer
-> Map LeiosPoint OfferPrune
-> Map LeiosPoint PeerOffer
forall a k b. (a -> k -> b -> a) -> a -> Map k b -> a
Map.foldlWithKey' Map LeiosPoint PeerOffer
-> LeiosPoint -> OfferPrune -> Map LeiosPoint PeerOffer
forall {k}.
Ord k =>
Map k PeerOffer -> k -> OfferPrune -> Map k PeerOffer
prune Map LeiosPoint PeerOffer
offers Map LeiosPoint OfferPrune
prunes
where
prune :: Map k PeerOffer -> k -> OfferPrune -> Map k PeerOffer
prune Map k PeerOffer
acc k
point = \case
OfferPrune
PruneOffer -> k -> Map k PeerOffer -> Map k PeerOffer
forall k a. Ord k => k -> Map k a -> Map k a
Map.delete k
point Map k PeerOffer
acc
OfferPrune
PruneOfferedBody -> (PeerOffer -> Maybe PeerOffer)
-> k -> Map k PeerOffer -> Map k PeerOffer
forall k a. Ord k => (a -> Maybe a) -> k -> Map k a -> Map k a
Map.update PeerOffer -> Maybe PeerOffer
withoutBody k
point Map k PeerOffer
acc
withoutBody :: PeerOffer -> Maybe PeerOffer
withoutBody PeerOffer
offer = case PeerOffer -> OfferedHalves
poOffered PeerOffer
offer of
OfferedBody Word32
_size -> Maybe PeerOffer
forall a. Maybe a
Nothing
OfferedHalves
OfferedClosure -> PeerOffer -> Maybe PeerOffer
forall a. a -> Maybe a
Just PeerOffer
offer
OfferedBodyAndClosure Word32
_size -> PeerOffer -> Maybe PeerOffer
forall a. a -> Maybe a
Just PeerOffer
offer{poOffered = OfferedClosure}
instance Semigroup PeerOffer where
MkPeerOffer StrictMaybe (LeiosEbByteSizes 'SizeLimit)
b1 OfferedHalves
o1 <> :: PeerOffer -> PeerOffer -> PeerOffer
<> MkPeerOffer StrictMaybe (LeiosEbByteSizes 'SizeLimit)
b2 OfferedHalves
o2 =
StrictMaybe (LeiosEbByteSizes 'SizeLimit)
-> OfferedHalves -> PeerOffer
MkPeerOffer (StrictMaybe (LeiosEbByteSizes 'SizeLimit)
-> StrictMaybe (LeiosEbByteSizes 'SizeLimit)
-> StrictMaybe (LeiosEbByteSizes 'SizeLimit)
forall {a}. StrictMaybe a -> StrictMaybe a -> StrictMaybe a
pickBounds StrictMaybe (LeiosEbByteSizes 'SizeLimit)
b1 StrictMaybe (LeiosEbByteSizes 'SizeLimit)
b2) (OfferedHalves
o1 OfferedHalves -> OfferedHalves -> OfferedHalves
forall a. Semigroup a => a -> a -> a
<> OfferedHalves
o2)
where
pickBounds :: StrictMaybe a -> StrictMaybe a -> StrictMaybe a
pickBounds StrictMaybe a
SNothing StrictMaybe a
y = StrictMaybe a
y
pickBounds x :: StrictMaybe a
x@SJust{} StrictMaybe a
_ = StrictMaybe a
x
data LeiosOutstanding peer = MkLeiosOutstanding
{ forall peer. LeiosOutstanding peer -> Map LeiosPoint EbState
ebState :: !(Map LeiosPoint EbState)
, forall peer.
LeiosOutstanding peer -> Map ElectionId EndorserBlockHash
elFocus :: !(Map ElectionId EndorserBlockHash)
, forall peer. LeiosOutstanding peer -> SlotNo
outstandingPrunedSlot :: !SlotNo
, forall peer. LeiosOutstanding peer -> Map LeiosPoint (Set peer)
requestedEbPeers :: !(Map LeiosPoint (Set peer))
, forall peer. LeiosOutstanding peer -> Map peer (NESet LeiosPoint)
requestedEbsPerPeer :: !(Map peer (NESet LeiosPoint))
, forall peer. LeiosOutstanding peer -> Map peer Word32
requestedBytesSizePerPeer :: !(Map peer BytesSize)
, forall peer.
LeiosOutstanding peer -> Map peer (Map LeiosPoint NEIntSet)
requestedJobsPerPeer :: !(Map peer (Map LeiosPoint NEIntSet))
, forall peer. LeiosOutstanding peer -> StdGen
leiosFetchPrng :: !StdGen
}
emptyLeiosOutstanding :: StdGen -> SlotNo -> LeiosOutstanding peer
emptyLeiosOutstanding :: forall peer. StdGen -> SlotNo -> LeiosOutstanding peer
emptyLeiosOutstanding StdGen
prng SlotNo
prunedSlot =
MkLeiosOutstanding
{ ebState :: Map LeiosPoint EbState
ebState = Map LeiosPoint EbState
forall k a. Map k a
Map.empty
, elFocus :: Map ElectionId EndorserBlockHash
elFocus = Map ElectionId EndorserBlockHash
forall k a. Map k a
Map.empty
, outstandingPrunedSlot :: SlotNo
outstandingPrunedSlot = SlotNo
prunedSlot
, requestedEbPeers :: Map LeiosPoint (Set peer)
requestedEbPeers = Map LeiosPoint (Set peer)
forall k a. Map k a
Map.empty
, requestedEbsPerPeer :: Map peer (NESet LeiosPoint)
requestedEbsPerPeer = Map peer (NESet LeiosPoint)
forall k a. Map k a
Map.empty
, requestedBytesSizePerPeer :: Map peer Word32
requestedBytesSizePerPeer = Map peer Word32
forall k a. Map k a
Map.empty
, requestedJobsPerPeer :: Map peer (Map LeiosPoint NEIntSet)
requestedJobsPerPeer = Map peer (Map LeiosPoint NEIntSet)
forall k a. Map k a
Map.empty
, leiosFetchPrng :: StdGen
leiosFetchPrng = StdGen
prng
}
data EbState
= MkEbState
!(StrictMaybe RelativeTime)
!EbFetchState
deriving (EbState -> EbState -> Bool
(EbState -> EbState -> Bool)
-> (EbState -> EbState -> Bool) -> Eq EbState
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: EbState -> EbState -> Bool
== :: EbState -> EbState -> Bool
$c/= :: EbState -> EbState -> Bool
/= :: EbState -> EbState -> Bool
Eq, Int -> EbState -> ShowS
[EbState] -> ShowS
EbState -> String
(Int -> EbState -> ShowS)
-> (EbState -> String) -> ([EbState] -> ShowS) -> Show EbState
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> EbState -> ShowS
showsPrec :: Int -> EbState -> ShowS
$cshow :: EbState -> String
show :: EbState -> String
$cshowList :: [EbState] -> ShowS
showList :: [EbState] -> ShowS
Show)
data EbFetchState
=
NoBody
|
BodyAcquired !Jobs.LeiosJobPool
deriving (EbFetchState -> EbFetchState -> Bool
(EbFetchState -> EbFetchState -> Bool)
-> (EbFetchState -> EbFetchState -> Bool) -> Eq EbFetchState
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: EbFetchState -> EbFetchState -> Bool
== :: EbFetchState -> EbFetchState -> Bool
$c/= :: EbFetchState -> EbFetchState -> Bool
/= :: EbFetchState -> EbFetchState -> Bool
Eq, Int -> EbFetchState -> ShowS
[EbFetchState] -> ShowS
EbFetchState -> String
(Int -> EbFetchState -> ShowS)
-> (EbFetchState -> String)
-> ([EbFetchState] -> ShowS)
-> Show EbFetchState
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> EbFetchState -> ShowS
showsPrec :: Int -> EbFetchState -> ShowS
$cshow :: EbFetchState -> String
show :: EbFetchState -> String
$cshowList :: [EbFetchState] -> ShowS
showList :: [EbFetchState] -> ShowS
Show)
ebStateOnset :: EbState -> StrictMaybe RelativeTime
ebStateOnset :: EbState -> StrictMaybe RelativeTime
ebStateOnset (MkEbState StrictMaybe RelativeTime
onset EbFetchState
_fetchState) = StrictMaybe RelativeTime
onset
newLeiosJobPool ::
LeiosFetchStaticEnv ->
IntMap.IntMap (TxHash, BytesSize) ->
Jobs.LeiosJobPool
newLeiosJobPool :: LeiosFetchStaticEnv -> IntMap (TxHash, Word32) -> LeiosJobPool
newLeiosJobPool LeiosFetchStaticEnv
env = Word32 -> Int -> IntMap (TxHash, Word32) -> LeiosJobPool
Jobs.mkJobPool (LeiosFetchStaticEnv -> Word32
maxJobBytesSize LeiosFetchStaticEnv
env) (LeiosFetchStaticEnv -> Int
maxJobTxCount LeiosFetchStaticEnv
env)
acquireEbBody ::
LeiosPoint ->
Jobs.LeiosJobPool ->
LeiosOutstanding peer ->
LeiosOutstanding peer
acquireEbBody :: forall peer.
LeiosPoint
-> LeiosJobPool -> LeiosOutstanding peer -> LeiosOutstanding peer
acquireEbBody LeiosPoint
point LeiosJobPool
jobPool =
LeiosPoint
-> (Maybe EbState -> Maybe EbState)
-> LeiosOutstanding peer
-> LeiosOutstanding peer
forall peer.
LeiosPoint
-> (Maybe EbState -> Maybe EbState)
-> LeiosOutstanding peer
-> LeiosOutstanding peer
alterEbState LeiosPoint
point ((Maybe EbState -> Maybe EbState)
-> LeiosOutstanding peer -> LeiosOutstanding peer)
-> (Maybe EbState -> Maybe EbState)
-> LeiosOutstanding peer
-> LeiosOutstanding peer
forall a b. (a -> b) -> a -> b
$ \case
Maybe EbState
Nothing -> Maybe EbState
forall a. Maybe a
Nothing
Just st :: EbState
st@(MkEbState StrictMaybe RelativeTime
onset EbFetchState
fetchState) -> case EbFetchState
fetchState of
EbFetchState
NoBody -> EbState -> Maybe EbState
forall a. a -> Maybe a
Just (EbState -> Maybe EbState) -> EbState -> Maybe EbState
forall a b. (a -> b) -> a -> b
$ StrictMaybe RelativeTime -> EbFetchState -> EbState
MkEbState StrictMaybe RelativeTime
onset (LeiosJobPool -> EbFetchState
BodyAcquired LeiosJobPool
jobPool)
BodyAcquired{} -> EbState -> Maybe EbState
forall a. a -> Maybe a
Just EbState
st
holdForgedEb ::
ElectionId ->
EndorserBlockHash ->
BytesSize ->
LeiosOutstanding peer ->
(LeiosOutstanding peer, [LeiosAcquisition])
holdForgedEb :: forall peer.
ElectionId
-> EndorserBlockHash
-> Word32
-> LeiosOutstanding peer
-> (LeiosOutstanding peer, [LeiosAcquisition])
holdForgedEb ElectionId
elId EndorserBlockHash
ebHash Word32
size LeiosOutstanding peer
outstanding
| ElectionId -> SlotNo
electionSlot ElectionId
elId SlotNo -> SlotNo -> Bool
forall a. Ord a => a -> a -> Bool
< LeiosOutstanding peer -> SlotNo
forall peer. LeiosOutstanding peer -> SlotNo
outstandingPrunedSlot LeiosOutstanding peer
outstanding = (LeiosOutstanding peer
outstanding, [])
| Bool
otherwise =
( ElectionId
-> EndorserBlockHash
-> LeiosOutstanding peer
-> LeiosOutstanding peer
forall peer.
ElectionId
-> EndorserBlockHash
-> LeiosOutstanding peer
-> LeiosOutstanding peer
focusElectionIfUnfocused ElectionId
elId EndorserBlockHash
ebHash (LeiosOutstanding peer -> LeiosOutstanding peer)
-> LeiosOutstanding peer -> LeiosOutstanding peer
forall a b. (a -> b) -> a -> b
$
LeiosPoint
-> (Maybe EbState -> Maybe EbState)
-> LeiosOutstanding peer
-> LeiosOutstanding peer
forall peer.
LeiosPoint
-> (Maybe EbState -> Maybe EbState)
-> LeiosOutstanding peer
-> LeiosOutstanding peer
alterEbState LeiosPoint
point (\Maybe EbState
_ -> EbState -> Maybe EbState
forall a. a -> Maybe a
Just (EbState -> Maybe EbState) -> EbState -> Maybe EbState
forall a b. (a -> b) -> a -> b
$ StrictMaybe RelativeTime -> EbFetchState -> EbState
MkEbState StrictMaybe RelativeTime
onset (LeiosJobPool -> EbFetchState
BodyAcquired LeiosJobPool
Jobs.emptyJobPool)) LeiosOutstanding peer
outstanding
, [LeiosAcquisition]
acquired
)
where
point :: LeiosPoint
point = SlotNo -> EndorserBlockHash -> LeiosPoint
MkLeiosPoint (ElectionId -> SlotNo
electionSlot ElectionId
elId) EndorserBlockHash
ebHash
(StrictMaybe RelativeTime
onset, [LeiosAcquisition]
acquired) = case LeiosPoint -> Map LeiosPoint EbState -> Maybe EbState
forall k a. Ord k => k -> Map k a -> Maybe a
Map.lookup LeiosPoint
point (LeiosOutstanding peer -> Map LeiosPoint EbState
forall peer. LeiosOutstanding peer -> Map LeiosPoint EbState
ebState LeiosOutstanding peer
outstanding) of
Just (MkEbState StrictMaybe RelativeTime
onset' (BodyAcquired LeiosJobPool
jobPool))
| LeiosJobPool -> Bool
Jobs.nullJobPool LeiosJobPool
jobPool -> (StrictMaybe RelativeTime
onset', [])
| Bool
otherwise -> (StrictMaybe RelativeTime
onset', [LeiosPoint -> LeiosAcquisition
AcquiredEbTxs LeiosPoint
point])
Just (MkEbState StrictMaybe RelativeTime
onset' EbFetchState
NoBody) -> (StrictMaybe RelativeTime
onset', [LeiosPoint -> Word32 -> LeiosAcquisition
AcquiredEb LeiosPoint
point Word32
size, LeiosPoint -> LeiosAcquisition
AcquiredEbTxs LeiosPoint
point])
Maybe EbState
Nothing -> (StrictMaybe RelativeTime
forall a. StrictMaybe a
SNothing, [LeiosPoint -> Word32 -> LeiosAcquisition
AcquiredEb LeiosPoint
point Word32
size, LeiosPoint -> LeiosAcquisition
AcquiredEbTxs LeiosPoint
point])
recordReferencedPoint ::
LeiosPoint ->
StrictMaybe RelativeTime ->
LeiosOutstanding peer ->
LeiosOutstanding peer
recordReferencedPoint :: forall peer.
LeiosPoint
-> StrictMaybe RelativeTime
-> LeiosOutstanding peer
-> LeiosOutstanding peer
recordReferencedPoint LeiosPoint
point StrictMaybe RelativeTime
onset =
LeiosPoint
-> (Maybe EbState -> Maybe EbState)
-> LeiosOutstanding peer
-> LeiosOutstanding peer
forall peer.
LeiosPoint
-> (Maybe EbState -> Maybe EbState)
-> LeiosOutstanding peer
-> LeiosOutstanding peer
alterEbState LeiosPoint
point ((Maybe EbState -> Maybe EbState)
-> LeiosOutstanding peer -> LeiosOutstanding peer)
-> (Maybe EbState -> Maybe EbState)
-> LeiosOutstanding peer
-> LeiosOutstanding peer
forall a b. (a -> b) -> a -> b
$ \case
Maybe EbState
Nothing -> EbState -> Maybe EbState
forall a. a -> Maybe a
Just (EbState -> Maybe EbState) -> EbState -> Maybe EbState
forall a b. (a -> b) -> a -> b
$ StrictMaybe RelativeTime -> EbFetchState -> EbState
MkEbState StrictMaybe RelativeTime
onset EbFetchState
NoBody
Just (MkEbState StrictMaybe RelativeTime
SNothing EbFetchState
fetchState) | SJust{} <- StrictMaybe RelativeTime
onset -> EbState -> Maybe EbState
forall a. a -> Maybe a
Just (EbState -> Maybe EbState) -> EbState -> Maybe EbState
forall a b. (a -> b) -> a -> b
$ StrictMaybe RelativeTime -> EbFetchState -> EbState
MkEbState StrictMaybe RelativeTime
onset EbFetchState
fetchState
Just st :: EbState
st@MkEbState{} -> EbState -> Maybe EbState
forall a. a -> Maybe a
Just EbState
st
initializeLeiosOutstanding ::
StdGen -> [LeiosPoint] -> SlotNo -> LeiosOutstanding peer
initializeLeiosOutstanding :: forall peer.
StdGen -> [LeiosPoint] -> SlotNo -> LeiosOutstanding peer
initializeLeiosOutstanding StdGen
prng [LeiosPoint]
points SlotNo
immTipSlot =
(LeiosOutstanding peer -> LeiosPoint -> LeiosOutstanding peer)
-> LeiosOutstanding peer -> [LeiosPoint] -> LeiosOutstanding peer
forall b a. (b -> a -> b) -> b -> [a] -> b
forall (t :: * -> *) b a.
Foldable t =>
(b -> a -> b) -> b -> t a -> b
F.foldl' ((LeiosPoint -> LeiosOutstanding peer -> LeiosOutstanding peer)
-> LeiosOutstanding peer -> LeiosPoint -> LeiosOutstanding peer
forall a b c. (a -> b -> c) -> b -> a -> c
flip LeiosPoint -> LeiosOutstanding peer -> LeiosOutstanding peer
forall {peer}.
LeiosPoint -> LeiosOutstanding peer -> LeiosOutstanding peer
seed1) (StdGen -> SlotNo -> LeiosOutstanding peer
forall peer. StdGen -> SlotNo -> LeiosOutstanding peer
emptyLeiosOutstanding StdGen
prng SlotNo
immTipSlot) [LeiosPoint]
points
where
seed1 :: LeiosPoint -> LeiosOutstanding peer -> LeiosOutstanding peer
seed1 LeiosPoint
point =
LeiosPoint
-> LeiosJobPool -> LeiosOutstanding peer -> LeiosOutstanding peer
forall peer.
LeiosPoint
-> LeiosJobPool -> LeiosOutstanding peer -> LeiosOutstanding peer
acquireEbBody LeiosPoint
point LeiosJobPool
Jobs.emptyJobPool
(LeiosOutstanding peer -> LeiosOutstanding peer)
-> (LeiosOutstanding peer -> LeiosOutstanding peer)
-> LeiosOutstanding peer
-> LeiosOutstanding peer
forall b c a. (b -> c) -> (a -> b) -> a -> c
. LeiosPoint
-> StrictMaybe RelativeTime
-> LeiosOutstanding peer
-> LeiosOutstanding peer
forall peer.
LeiosPoint
-> StrictMaybe RelativeTime
-> LeiosOutstanding peer
-> LeiosOutstanding peer
recordReferencedPoint LeiosPoint
point StrictMaybe RelativeTime
forall a. StrictMaybe a
SNothing
focusElectionIfUnfocused ::
ElectionId -> EndorserBlockHash -> LeiosOutstanding peer -> LeiosOutstanding peer
focusElectionIfUnfocused :: forall peer.
ElectionId
-> EndorserBlockHash
-> LeiosOutstanding peer
-> LeiosOutstanding peer
focusElectionIfUnfocused ElectionId
elId EndorserBlockHash
ebHash LeiosOutstanding peer
outstanding
| ElectionId -> Map ElectionId EndorserBlockHash -> Bool
forall k a. Ord k => k -> Map k a -> Bool
Map.member ElectionId
elId (LeiosOutstanding peer -> Map ElectionId EndorserBlockHash
forall peer.
LeiosOutstanding peer -> Map ElectionId EndorserBlockHash
elFocus LeiosOutstanding peer
outstanding) = LeiosOutstanding peer
outstanding
| Bool
otherwise = ElectionId
-> EndorserBlockHash
-> LeiosOutstanding peer
-> LeiosOutstanding peer
forall peer.
ElectionId
-> EndorserBlockHash
-> LeiosOutstanding peer
-> LeiosOutstanding peer
focusElection ElectionId
elId EndorserBlockHash
ebHash LeiosOutstanding peer
outstanding
focusCertifiedEb ::
ElectionId -> EndorserBlockHash -> LeiosOutstanding peer -> LeiosOutstanding peer
focusCertifiedEb :: forall peer.
ElectionId
-> EndorserBlockHash
-> LeiosOutstanding peer
-> LeiosOutstanding peer
focusCertifiedEb ElectionId
elId EndorserBlockHash
ebHash LeiosOutstanding peer
outstanding
| ElectionId -> SlotNo
electionSlot ElectionId
elId SlotNo -> SlotNo -> Bool
forall a. Ord a => a -> a -> Bool
< LeiosOutstanding peer -> SlotNo
forall peer. LeiosOutstanding peer -> SlotNo
outstandingPrunedSlot LeiosOutstanding peer
outstanding = LeiosOutstanding peer
outstanding
| Bool
otherwise =
ElectionId
-> EndorserBlockHash
-> LeiosOutstanding peer
-> LeiosOutstanding peer
forall peer.
ElectionId
-> EndorserBlockHash
-> LeiosOutstanding peer
-> LeiosOutstanding peer
focusElection ElectionId
elId EndorserBlockHash
ebHash (LeiosOutstanding peer -> LeiosOutstanding peer)
-> LeiosOutstanding peer -> LeiosOutstanding peer
forall a b. (a -> b) -> a -> b
$
LeiosPoint -> LeiosOutstanding peer -> LeiosOutstanding peer
forall {peer}.
LeiosPoint -> LeiosOutstanding peer -> LeiosOutstanding peer
trackCertifiedEb (SlotNo -> EndorserBlockHash -> LeiosPoint
MkLeiosPoint (ElectionId -> SlotNo
electionSlot ElectionId
elId) EndorserBlockHash
ebHash) LeiosOutstanding peer
outstanding
trackCertifiedEb :: LeiosPoint -> LeiosOutstanding peer -> LeiosOutstanding peer
trackCertifiedEb :: forall {peer}.
LeiosPoint -> LeiosOutstanding peer -> LeiosOutstanding peer
trackCertifiedEb LeiosPoint
point LeiosOutstanding peer
outstanding
| LeiosPoint -> SlotNo
pointSlotNo LeiosPoint
point SlotNo -> SlotNo -> Bool
forall a. Ord a => a -> a -> Bool
< LeiosOutstanding peer -> SlotNo
forall peer. LeiosOutstanding peer -> SlotNo
outstandingPrunedSlot LeiosOutstanding peer
outstanding = LeiosOutstanding peer
outstanding
| Bool
otherwise = LeiosPoint
-> StrictMaybe RelativeTime
-> LeiosOutstanding peer
-> LeiosOutstanding peer
forall peer.
LeiosPoint
-> StrictMaybe RelativeTime
-> LeiosOutstanding peer
-> LeiosOutstanding peer
recordReferencedPoint LeiosPoint
point StrictMaybe RelativeTime
forall a. StrictMaybe a
SNothing LeiosOutstanding peer
outstanding
focusElection ::
ElectionId -> EndorserBlockHash -> LeiosOutstanding peer -> LeiosOutstanding peer
focusElection :: forall peer.
ElectionId
-> EndorserBlockHash
-> LeiosOutstanding peer
-> LeiosOutstanding peer
focusElection ElectionId
elId EndorserBlockHash
ebHash LeiosOutstanding peer
outstanding = case ElectionId
-> Map ElectionId EndorserBlockHash -> Maybe EndorserBlockHash
forall k a. Ord k => k -> Map k a -> Maybe a
Map.lookup ElectionId
elId (LeiosOutstanding peer -> Map ElectionId EndorserBlockHash
forall peer.
LeiosOutstanding peer -> Map ElectionId EndorserBlockHash
elFocus LeiosOutstanding peer
outstanding) of
Just EndorserBlockHash
oldEbHash | EndorserBlockHash
oldEbHash EndorserBlockHash -> EndorserBlockHash -> Bool
forall a. Eq a => a -> a -> Bool
== EndorserBlockHash
ebHash -> LeiosOutstanding peer
outstanding
Maybe EndorserBlockHash
_ -> LeiosOutstanding peer
outstanding{elFocus = Map.insert elId ebHash (elFocus outstanding)}
isFocusedPoint :: LeiosPoint -> LeiosOutstanding peer -> Bool
isFocusedPoint :: forall peer. LeiosPoint -> LeiosOutstanding peer -> Bool
isFocusedPoint (MkLeiosPoint SlotNo
slot EndorserBlockHash
ebHash) =
EndorserBlockHash -> Map ElectionId EndorserBlockHash -> Bool
forall a. Eq a => a -> Map ElectionId a -> Bool
forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
elem EndorserBlockHash
ebHash
(Map ElectionId EndorserBlockHash -> Bool)
-> (LeiosOutstanding peer -> Map ElectionId EndorserBlockHash)
-> LeiosOutstanding peer
-> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (ElectionId -> Bool)
-> Map ElectionId EndorserBlockHash
-> Map ElectionId EndorserBlockHash
forall k a. (k -> Bool) -> Map k a -> Map k a
Map.takeWhileAntitone ((SlotNo -> SlotNo -> Bool
forall a. Eq a => a -> a -> Bool
== SlotNo
slot) (SlotNo -> Bool) -> (ElectionId -> SlotNo) -> ElectionId -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ElectionId -> SlotNo
electionSlot)
(Map ElectionId EndorserBlockHash
-> Map ElectionId EndorserBlockHash)
-> (LeiosOutstanding peer -> Map ElectionId EndorserBlockHash)
-> LeiosOutstanding peer
-> Map ElectionId EndorserBlockHash
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (ElectionId -> Bool)
-> Map ElectionId EndorserBlockHash
-> Map ElectionId EndorserBlockHash
forall k a. (k -> Bool) -> Map k a -> Map k a
Map.dropWhileAntitone ((SlotNo -> SlotNo -> Bool
forall a. Ord a => a -> a -> Bool
< SlotNo
slot) (SlotNo -> Bool) -> (ElectionId -> SlotNo) -> ElectionId -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ElectionId -> SlotNo
electionSlot)
(Map ElectionId EndorserBlockHash
-> Map ElectionId EndorserBlockHash)
-> (LeiosOutstanding peer -> Map ElectionId EndorserBlockHash)
-> LeiosOutstanding peer
-> Map ElectionId EndorserBlockHash
forall b c a. (b -> c) -> (a -> b) -> a -> c
. LeiosOutstanding peer -> Map ElectionId EndorserBlockHash
forall peer.
LeiosOutstanding peer -> Map ElectionId EndorserBlockHash
elFocus
alterEbState ::
LeiosPoint ->
(Maybe EbState -> Maybe EbState) ->
LeiosOutstanding peer ->
LeiosOutstanding peer
alterEbState :: forall peer.
LeiosPoint
-> (Maybe EbState -> Maybe EbState)
-> LeiosOutstanding peer
-> LeiosOutstanding peer
alterEbState LeiosPoint
point Maybe EbState -> Maybe EbState
f LeiosOutstanding peer
outstanding =
LeiosOutstanding peer
outstanding{ebState = Map.alter f point (ebState outstanding)}
pruneOutstandingToImmTip :: SlotNo -> LeiosOutstanding peer -> LeiosOutstanding peer
pruneOutstandingToImmTip :: forall peer.
SlotNo -> LeiosOutstanding peer -> LeiosOutstanding peer
pruneOutstandingToImmTip SlotNo
immTipSlot LeiosOutstanding peer
outstanding =
LeiosOutstanding peer
outstanding
{ ebState = Map.dropWhileAntitone ((< immTipSlot) . pointSlotNo) (ebState outstanding)
, elFocus = Map.dropWhileAntitone ((< immTipSlot) . electionSlot) (elFocus outstanding)
, outstandingPrunedSlot = max (outstandingPrunedSlot outstanding) immTipSlot
}
delIf :: (a -> Bool) -> a -> Maybe a
delIf :: forall a. (a -> Bool) -> a -> Maybe a
delIf a -> Bool
predicate a
x = if a -> Bool
predicate a
x then Maybe a
forall a. Maybe a
Nothing else a -> Maybe a
forall a. a -> Maybe a
Just a
x
removePeerFromOutstanding ::
Ord peer =>
peer ->
LeiosOutstanding peer ->
LeiosOutstanding peer
removePeerFromOutstanding :: forall peer.
Ord peer =>
peer -> LeiosOutstanding peer -> LeiosOutstanding peer
removePeerFromOutstanding peer
peer LeiosOutstanding peer
o =
LeiosOutstanding peer
o
{ requestedBytesSizePerPeer = Map.delete peer (requestedBytesSizePerPeer o)
, requestedEbPeers =
F.foldl'
(flip $ Map.update (delIf Set.null . Set.delete peer))
(requestedEbPeers o)
(maybe Set.empty NESet.toSet (Map.lookup peer (requestedEbsPerPeer o)))
, requestedEbsPerPeer = Map.delete peer (requestedEbsPerPeer o)
, requestedJobsPerPeer = Map.delete peer (requestedJobsPerPeer o)
, ebState =
Map.foldrWithKey
(\LeiosPoint
point NEIntSet
jobIds -> (EbState -> EbState)
-> LeiosPoint -> Map LeiosPoint EbState -> Map LeiosPoint EbState
forall k a. Ord k => (a -> a) -> k -> Map k a -> Map k a
Map.adjust (NEIntSet -> EbState -> EbState
releaseJobs NEIntSet
jobIds) LeiosPoint
point)
(ebState o)
(Map.findWithDefault Map.empty peer (requestedJobsPerPeer o))
}
where
releaseJobs :: NEIntSet -> EbState -> EbState
releaseJobs NEIntSet
jobIds (MkEbState StrictMaybe RelativeTime
onset EbFetchState
fetchState) =
StrictMaybe RelativeTime -> EbFetchState -> EbState
MkEbState StrictMaybe RelativeTime
onset (EbFetchState -> EbState) -> EbFetchState -> EbState
forall a b. (a -> b) -> a -> b
$ case EbFetchState
fetchState of
EbFetchState
NoBody -> EbFetchState
NoBody
BodyAcquired LeiosJobPool
jobPool -> LeiosJobPool -> EbFetchState
BodyAcquired (LeiosJobPool -> EbFetchState) -> LeiosJobPool -> EbFetchState
forall a b. (a -> b) -> a -> b
$! LeiosJobPool -> LeiosJobPool
release LeiosJobPool
jobPool
where
release :: LeiosJobPool -> LeiosJobPool
release LeiosJobPool
jobPool =
(LeiosJobPool -> Int -> LeiosJobPool)
-> LeiosJobPool -> NEIntSet -> LeiosJobPool
forall a. (a -> Int -> a) -> a -> NEIntSet -> a
NEIntSet.foldl' ((Int -> LeiosJobPool -> LeiosJobPool)
-> LeiosJobPool -> Int -> LeiosJobPool
forall a b c. (a -> b -> c) -> b -> a -> c
flip ((Int -> LeiosJobPool -> LeiosJobPool)
-> LeiosJobPool -> Int -> LeiosJobPool)
-> (Int -> LeiosJobPool -> LeiosJobPool)
-> LeiosJobPool
-> Int
-> LeiosJobPool
forall a b. (a -> b) -> a -> b
$ LeiosJobId -> LeiosJobPool -> LeiosJobPool
Jobs.unpickJob (LeiosJobId -> LeiosJobPool -> LeiosJobPool)
-> (Int -> LeiosJobId) -> Int -> LeiosJobPool -> LeiosJobPool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> LeiosJobId
Jobs.MkLeiosJobId) LeiosJobPool
jobPool NEIntSet
jobIds
refundEbRequest ::
Ord peer =>
peer ->
LeiosPoint ->
BytesSize ->
LeiosOutstanding peer ->
LeiosOutstanding peer
refundEbRequest :: forall peer.
Ord peer =>
peer
-> LeiosPoint
-> Word32
-> LeiosOutstanding peer
-> LeiosOutstanding peer
refundEbRequest peer
peer LeiosPoint
point Word32
ebBytesSize LeiosOutstanding peer
o
| peer -> Map peer Word32 -> Bool
forall k a. Ord k => k -> Map k a -> Bool
Map.member peer
peer (LeiosOutstanding peer -> Map peer Word32
forall peer. LeiosOutstanding peer -> Map peer Word32
requestedBytesSizePerPeer LeiosOutstanding peer
o) =
LeiosOutstanding peer
o
{ requestedBytesSizePerPeer =
Map.update (\Word32
x -> (Word32 -> Bool) -> Word32 -> Maybe Word32
forall a. (a -> Bool) -> a -> Maybe a
delIf (Word32 -> Word32 -> Bool
forall a. Eq a => a -> a -> Bool
== Word32
0) (Word32
x Word32 -> Word32 -> Word32
forall a. Num a => a -> a -> a
- Word32
ebBytesSize)) peer (requestedBytesSizePerPeer o)
, requestedEbPeers =
Map.update (delIf Set.null . Set.delete peer) point (requestedEbPeers o)
, requestedEbsPerPeer =
Map.update (NESet.nonEmptySet . NESet.delete point) peer (requestedEbsPerPeer o)
}
| Bool
otherwise = LeiosOutstanding peer
o
refundTxRequest ::
Ord peer =>
peer ->
BytesSize ->
LeiosOutstanding peer ->
LeiosOutstanding peer
refundTxRequest :: forall peer.
Ord peer =>
peer -> Word32 -> LeiosOutstanding peer -> LeiosOutstanding peer
refundTxRequest peer
peer Word32
txsBytesSize LeiosOutstanding peer
o
| peer -> Map peer Word32 -> Bool
forall k a. Ord k => k -> Map k a -> Bool
Map.member peer
peer (LeiosOutstanding peer -> Map peer Word32
forall peer. LeiosOutstanding peer -> Map peer Word32
requestedBytesSizePerPeer LeiosOutstanding peer
o) =
LeiosOutstanding peer
o
{ requestedBytesSizePerPeer =
Map.update (\Word32
x -> (Word32 -> Bool) -> Word32 -> Maybe Word32
forall a. (a -> Bool) -> a -> Maybe a
delIf (Word32 -> Word32 -> Bool
forall a. Eq a => a -> a -> Bool
== Word32
0) (Word32
x Word32 -> Word32 -> Word32
forall a. Num a => a -> a -> a
- Word32
txsBytesSize)) peer (requestedBytesSizePerPeer o)
}
| Bool
otherwise = LeiosOutstanding peer
o
completeTxRequest ::
Ord peer =>
peer ->
LeiosBlockTxsRequest ->
LeiosOutstanding peer ->
LeiosOutstanding peer
completeTxRequest :: forall peer.
Ord peer =>
peer
-> LeiosBlockTxsRequest
-> LeiosOutstanding peer
-> LeiosOutstanding peer
completeTxRequest peer
peer (MkLeiosBlockTxsRequest LeiosPoint
point NEIntMap LeiosJob
jobs) LeiosOutstanding peer
o =
LeiosOutstanding peer
o
{ ebState = Map.adjust completeInJobPool point (ebState o)
, requestedJobsPerPeer =
Map.update (nonEmptyMap . Map.update dropJobs point) peer (requestedJobsPerPeer o)
}
where
jobIds :: NEIntSet
jobIds = NEIntMap LeiosJob -> NEIntSet
forall a. NEIntMap a -> NEIntSet
NEIntMap.keysSet NEIntMap LeiosJob
jobs
completeInJobPool :: EbState -> EbState
completeInJobPool (MkEbState StrictMaybe RelativeTime
onset EbFetchState
fetchState) =
StrictMaybe RelativeTime -> EbFetchState -> EbState
MkEbState StrictMaybe RelativeTime
onset (EbFetchState -> EbState) -> EbFetchState -> EbState
forall a b. (a -> b) -> a -> b
$ case EbFetchState
fetchState of
EbFetchState
NoBody -> EbFetchState
NoBody
BodyAcquired LeiosJobPool
jobPool -> LeiosJobPool -> EbFetchState
BodyAcquired (LeiosJobPool -> EbFetchState) -> LeiosJobPool -> EbFetchState
forall a b. (a -> b) -> a -> b
$! LeiosJobPool -> LeiosJobPool
complete LeiosJobPool
jobPool
where
complete :: LeiosJobPool -> LeiosJobPool
complete LeiosJobPool
jobPool =
(LeiosJobPool -> Int -> LeiosJobPool)
-> LeiosJobPool -> NEIntSet -> LeiosJobPool
forall a. (a -> Int -> a) -> a -> NEIntSet -> a
NEIntSet.foldl' ((Int -> LeiosJobPool -> LeiosJobPool)
-> LeiosJobPool -> Int -> LeiosJobPool
forall a b c. (a -> b -> c) -> b -> a -> c
flip ((Int -> LeiosJobPool -> LeiosJobPool)
-> LeiosJobPool -> Int -> LeiosJobPool)
-> (Int -> LeiosJobPool -> LeiosJobPool)
-> LeiosJobPool
-> Int
-> LeiosJobPool
forall a b. (a -> b) -> a -> b
$ LeiosJobId -> LeiosJobPool -> LeiosJobPool
Jobs.completeJob (LeiosJobId -> LeiosJobPool -> LeiosJobPool)
-> (Int -> LeiosJobId) -> Int -> LeiosJobPool -> LeiosJobPool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> LeiosJobId
Jobs.MkLeiosJobId) LeiosJobPool
jobPool NEIntSet
jobIds
dropJobs :: NEIntSet -> Maybe NEIntSet
dropJobs NEIntSet
held =
IntSet -> Maybe NEIntSet
NEIntSet.nonEmptySet (IntSet -> IntSet -> IntSet
IntSet.difference (NEIntSet -> IntSet
NEIntSet.toSet NEIntSet
held) (NEIntSet -> IntSet
NEIntSet.toSet NEIntSet
jobIds))
nonEmptyMap :: Map k a -> Maybe (Map k a)
nonEmptyMap Map k a
m = if Map k a -> Bool
forall k a. Map k a -> Bool
Map.null Map k a
m then Maybe (Map k a)
forall a. Maybe a
Nothing else Map k a -> Maybe (Map k a)
forall a. a -> Maybe a
Just Map k a
m
data LeiosFetchStaticEnv = MkLeiosFetchStaticEnv
{ LeiosFetchStaticEnv -> Word32
maxRequestedBytesSizePerPeer :: BytesSize
, LeiosFetchStaticEnv -> Word32
maxRequestedBytesSizePerBigLedgerPeer :: BytesSize
, LeiosFetchStaticEnv -> Word32
maxRequestBytesSize :: BytesSize
, LeiosFetchStaticEnv -> Word32
maxJobBytesSize :: BytesSize
, LeiosFetchStaticEnv -> Int
maxJobTxCount :: Int
}
defaultLeiosFetchStaticEnv :: BytesSize -> LeiosFetchStaticEnv
defaultLeiosFetchStaticEnv :: Word32 -> LeiosFetchStaticEnv
defaultLeiosFetchStaticEnv Word32
maxPerBigLedgerPeer =
MkLeiosFetchStaticEnv
{ maxRequestedBytesSizePerPeer :: Word32
maxRequestedBytesSizePerPeer = Word32
5 Word32 -> Word32 -> Word32
forall a. Num a => a -> a -> a
* Word32
forall a. Num a => a
million
, maxRequestedBytesSizePerBigLedgerPeer :: Word32
maxRequestedBytesSizePerBigLedgerPeer = Word32
maxPerBigLedgerPeer
, maxRequestBytesSize :: Word32
maxRequestBytesSize = Word32
maxLeiosTxsRequestBytesSize
, maxJobBytesSize :: Word32
maxJobBytesSize = Word32
64 Word32 -> Word32 -> Word32
forall a. Num a => a -> a -> a
* Word32
forall a. Num a => a
thousandBase2
, maxJobTxCount :: Int
maxJobTxCount = Int
20000
}
where
million :: Num a => a
million :: forall a. Num a => a
million = a
10 a -> Int -> a
forall a b. (Num a, Integral b) => a -> b -> a
^ (Int
6 :: Int)
thousandBase2 :: Num a => a
thousandBase2 :: forall a. Num a => a
thousandBase2 = a
2 a -> Int -> a
forall a b. (Num a, Integral b) => a -> b -> a
^ (Int
10 :: Int)
leiosFetchLogicIteration ::
Ord peer =>
LeiosFetchStaticEnv ->
(SlotNo -> Either OutsideForecastRange (LeiosEbByteSizes SizeLimit)) ->
Maybe (SlotNo, Word64) ->
Map peer (Map LeiosPoint PeerOffer) ->
Map peer IsBigLedgerPeer ->
LeiosOutstanding peer ->
( LeiosOutstanding peer
, Map peer (NESeq LeiosFetchRequest)
, Map peer (NEMap LeiosPoint OfferPrune)
)
leiosFetchLogicIteration :: forall peer.
Ord peer =>
LeiosFetchStaticEnv
-> (SlotNo
-> Either OutsideForecastRange (LeiosEbByteSizes 'SizeLimit))
-> Maybe (SlotNo, Word64)
-> Map peer (Map LeiosPoint PeerOffer)
-> Map peer IsBigLedgerPeer
-> LeiosOutstanding peer
-> (LeiosOutstanding peer, Map peer (NESeq LeiosFetchRequest),
Map peer (NEMap LeiosPoint OfferPrune))
leiosFetchLogicIteration LeiosFetchStaticEnv
env SlotNo -> Either OutsideForecastRange (LeiosEbByteSizes 'SizeLimit)
forecastEbBounds Maybe (SlotNo, Word64)
mbHorizon Map peer (Map LeiosPoint PeerOffer)
offerings Map peer IsBigLedgerPeer
bigLedgerPeers = \LeiosOutstanding peer
acc0 ->
((LeiosOutstanding peer, Map peer (NESeq LeiosFetchRequest),
Map peer (NEMap LeiosPoint OfferPrune))
-> peer
-> Map LeiosPoint PeerOffer
-> (LeiosOutstanding peer, Map peer (NESeq LeiosFetchRequest),
Map peer (NEMap LeiosPoint OfferPrune)))
-> (LeiosOutstanding peer, Map peer (NESeq LeiosFetchRequest),
Map peer (NEMap LeiosPoint OfferPrune))
-> Map peer (Map LeiosPoint PeerOffer)
-> (LeiosOutstanding peer, Map peer (NESeq LeiosFetchRequest),
Map peer (NEMap LeiosPoint OfferPrune))
forall a k b. (a -> k -> b -> a) -> a -> Map k b -> a
Map.foldlWithKey'
( \(LeiosOutstanding peer
acc, Map peer (NESeq LeiosFetchRequest)
reqs, Map peer (NEMap LeiosPoint OfferPrune)
drops) peer
peer Map LeiosPoint PeerOffer
offers ->
let isBig :: IsBigLedgerPeer
isBig = IsBigLedgerPeer
-> peer -> Map peer IsBigLedgerPeer -> IsBigLedgerPeer
forall k a. Ord k => a -> k -> Map k a -> a
Map.findWithDefault IsBigLedgerPeer
IsNotBigLedgerPeer peer
peer Map peer IsBigLedgerPeer
bigLedgerPeers
(LeiosOutstanding peer
acc', Seq LeiosFetchRequest
peerReqs, Map LeiosPoint OfferPrune
peerDrops) =
LeiosFetchStaticEnv
-> (SlotNo
-> Either OutsideForecastRange (LeiosEbByteSizes 'SizeLimit))
-> Maybe (SlotNo, Word64)
-> IsBigLedgerPeer
-> peer
-> Map LeiosPoint PeerOffer
-> LeiosOutstanding peer
-> (LeiosOutstanding peer, Seq LeiosFetchRequest,
Map LeiosPoint OfferPrune)
forall peer.
Ord peer =>
LeiosFetchStaticEnv
-> (SlotNo
-> Either OutsideForecastRange (LeiosEbByteSizes 'SizeLimit))
-> Maybe (SlotNo, Word64)
-> IsBigLedgerPeer
-> peer
-> Map LeiosPoint PeerOffer
-> LeiosOutstanding peer
-> (LeiosOutstanding peer, Seq LeiosFetchRequest,
Map LeiosPoint OfferPrune)
assignPeer LeiosFetchStaticEnv
env SlotNo -> Either OutsideForecastRange (LeiosEbByteSizes 'SizeLimit)
forecastEbBounds Maybe (SlotNo, Word64)
mbHorizon IsBigLedgerPeer
isBig peer
peer Map LeiosPoint PeerOffer
offers LeiosOutstanding peer
acc
in ( LeiosOutstanding peer
acc'
, case Seq LeiosFetchRequest -> Maybe (NESeq LeiosFetchRequest)
forall a. Seq a -> Maybe (NESeq a)
NESeq.nonEmptySeq Seq LeiosFetchRequest
peerReqs of
Maybe (NESeq LeiosFetchRequest)
Nothing -> Map peer (NESeq LeiosFetchRequest)
reqs
Just NESeq LeiosFetchRequest
neReqs -> peer
-> NESeq LeiosFetchRequest
-> Map peer (NESeq LeiosFetchRequest)
-> Map peer (NESeq LeiosFetchRequest)
forall k a. Ord k => k -> a -> Map k a -> Map k a
Map.insert peer
peer NESeq LeiosFetchRequest
neReqs Map peer (NESeq LeiosFetchRequest)
reqs
, case Map LeiosPoint OfferPrune -> Maybe (NEMap LeiosPoint OfferPrune)
forall k a. Map k a -> Maybe (NEMap k a)
NEMap.nonEmptyMap Map LeiosPoint OfferPrune
peerDrops of
Maybe (NEMap LeiosPoint OfferPrune)
Nothing -> Map peer (NEMap LeiosPoint OfferPrune)
drops
Just NEMap LeiosPoint OfferPrune
nes -> peer
-> NEMap LeiosPoint OfferPrune
-> Map peer (NEMap LeiosPoint OfferPrune)
-> Map peer (NEMap LeiosPoint OfferPrune)
forall k a. Ord k => k -> a -> Map k a -> Map k a
Map.insert peer
peer NEMap LeiosPoint OfferPrune
nes Map peer (NEMap LeiosPoint OfferPrune)
drops
)
)
(LeiosOutstanding peer
acc0, Map peer (NESeq LeiosFetchRequest)
forall k a. Map k a
Map.empty, Map peer (NEMap LeiosPoint OfferPrune)
forall k a. Map k a
Map.empty)
Map peer (Map LeiosPoint PeerOffer)
offerings
peerBudget ::
Ord peer => LeiosFetchStaticEnv -> IsBigLedgerPeer -> LeiosOutstanding peer -> peer -> Int
peerBudget :: forall peer.
Ord peer =>
LeiosFetchStaticEnv
-> IsBigLedgerPeer -> LeiosOutstanding peer -> peer -> Int
peerBudget LeiosFetchStaticEnv
env IsBigLedgerPeer
isBig LeiosOutstanding peer
acc peer
peer =
Word32 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word32
cap
Int -> Int -> Int
forall a. Num a => a -> a -> a
- Word32 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Word32 -> peer -> Map peer Word32 -> Word32
forall k a. Ord k => a -> k -> Map k a -> a
Map.findWithDefault Word32
0 peer
peer (LeiosOutstanding peer -> Map peer Word32
forall peer. LeiosOutstanding peer -> Map peer Word32
requestedBytesSizePerPeer LeiosOutstanding peer
acc))
where
cap :: Word32
cap = case IsBigLedgerPeer
isBig of
IsBigLedgerPeer
IsBigLedgerPeer -> LeiosFetchStaticEnv -> Word32
maxRequestedBytesSizePerBigLedgerPeer LeiosFetchStaticEnv
env
IsBigLedgerPeer
IsNotBigLedgerPeer -> LeiosFetchStaticEnv -> Word32
maxRequestedBytesSizePerPeer LeiosFetchStaticEnv
env
fetchPriorityTiers :: Maybe (SlotNo, Word64) -> [(SlotNo, v)] -> ([v], [v])
fetchPriorityTiers :: forall v. Maybe (SlotNo, Word64) -> [(SlotNo, v)] -> ([v], [v])
fetchPriorityTiers Maybe (SlotNo, Word64)
mbHorizon [(SlotNo, v)]
offers =
( ((SlotNo, v) -> v) -> [(SlotNo, v)] -> [v]
forall a b. (a -> b) -> [a] -> [b]
map (SlotNo, v) -> v
forall a b. (a, b) -> b
snd ([(SlotNo, v)] -> [v]) -> [(SlotNo, v)] -> [v]
forall a b. (a -> b) -> a -> b
$ ((SlotNo, v) -> SlotNo) -> [(SlotNo, v)] -> [(SlotNo, v)]
forall b a. Ord b => (a -> b) -> [a] -> [a]
sortOn (SlotNo, v) -> SlotNo
forall a b. (a, b) -> a
fst [(SlotNo, v)]
high
, ((SlotNo, v) -> v) -> [(SlotNo, v)] -> [v]
forall a b. (a -> b) -> [a] -> [b]
map (SlotNo, v) -> v
forall a b. (a, b) -> b
snd ([(SlotNo, v)] -> [v]) -> [(SlotNo, v)] -> [v]
forall a b. (a -> b) -> a -> b
$ ((SlotNo, v) -> Down SlotNo) -> [(SlotNo, v)] -> [(SlotNo, v)]
forall b a. Ord b => (a -> b) -> [a] -> [a]
sortOn (SlotNo -> Down SlotNo
forall a. a -> Down a
Down (SlotNo -> Down SlotNo)
-> ((SlotNo, v) -> SlotNo) -> (SlotNo, v) -> Down SlotNo
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (SlotNo, v) -> SlotNo
forall a b. (a, b) -> a
fst) [(SlotNo, v)]
low
)
where
([(SlotNo, v)]
high, [(SlotNo, v)]
low) = ((SlotNo, v) -> Bool)
-> [(SlotNo, v)] -> ([(SlotNo, v)], [(SlotNo, v)])
forall a. (a -> Bool) -> [a] -> ([a], [a])
partition (Bool -> Bool
not (Bool -> Bool) -> ((SlotNo, v) -> Bool) -> (SlotNo, v) -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. SlotNo -> Bool
stale (SlotNo -> Bool) -> ((SlotNo, v) -> SlotNo) -> (SlotNo, v) -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (SlotNo, v) -> SlotNo
forall a b. (a, b) -> a
fst) [(SlotNo, v)]
offers
stale :: SlotNo -> Bool
stale (SlotNo Word64
a) = case Maybe (SlotNo, Word64)
mbHorizon of
Maybe (SlotNo, Word64)
Nothing -> Bool
False
Just (SlotNo Word64
s, Word64
l) -> Word64
a Word64 -> Word64 -> Word64
forall a. Num a => a -> a -> a
+ Word64
l Word64 -> Word64 -> Bool
forall a. Ord a => a -> a -> Bool
< Word64
s
assignPeer ::
Ord peer =>
LeiosFetchStaticEnv ->
(SlotNo -> Either OutsideForecastRange (LeiosEbByteSizes SizeLimit)) ->
Maybe (SlotNo, Word64) ->
IsBigLedgerPeer ->
peer ->
Map LeiosPoint PeerOffer ->
LeiosOutstanding peer ->
(LeiosOutstanding peer, Seq LeiosFetchRequest, Map LeiosPoint OfferPrune)
assignPeer :: forall peer.
Ord peer =>
LeiosFetchStaticEnv
-> (SlotNo
-> Either OutsideForecastRange (LeiosEbByteSizes 'SizeLimit))
-> Maybe (SlotNo, Word64)
-> IsBigLedgerPeer
-> peer
-> Map LeiosPoint PeerOffer
-> LeiosOutstanding peer
-> (LeiosOutstanding peer, Seq LeiosFetchRequest,
Map LeiosPoint OfferPrune)
assignPeer LeiosFetchStaticEnv
env SlotNo -> Either OutsideForecastRange (LeiosEbByteSizes 'SizeLimit)
forecastEbBounds Maybe (SlotNo, Word64)
mbHorizon IsBigLedgerPeer
isBig peer
peer Map LeiosPoint PeerOffer
offers LeiosOutstanding peer
acc =
(LeiosOutstanding peer, Seq LeiosFetchRequest,
Map LeiosPoint OfferPrune)
-> [(LeiosPoint, PeerOffer)]
-> (LeiosOutstanding peer, Seq LeiosFetchRequest,
Map LeiosPoint OfferPrune)
go (LeiosOutstanding peer
acc, Seq LeiosFetchRequest
forall a. Seq a
Seq.empty, Map LeiosPoint OfferPrune
forall k a. Map k a
Map.empty) ([(LeiosPoint, PeerOffer)]
highTier [(LeiosPoint, PeerOffer)]
-> [(LeiosPoint, PeerOffer)] -> [(LeiosPoint, PeerOffer)]
forall a. Semigroup a => a -> a -> a
<> [(LeiosPoint, PeerOffer)]
lowTier)
where
([(LeiosPoint, PeerOffer)]
highTier, [(LeiosPoint, PeerOffer)]
lowTier) =
Maybe (SlotNo, Word64)
-> [(SlotNo, (LeiosPoint, PeerOffer))]
-> ([(LeiosPoint, PeerOffer)], [(LeiosPoint, PeerOffer)])
forall v. Maybe (SlotNo, Word64) -> [(SlotNo, v)] -> ([v], [v])
fetchPriorityTiers
Maybe (SlotNo, Word64)
mbHorizon
[ (LeiosPoint -> SlotNo
pointSlotNo LeiosPoint
point, (LeiosPoint
point, PeerOffer
offer))
| (LeiosPoint
point, PeerOffer
offer) <- Map LeiosPoint PeerOffer -> [(LeiosPoint, PeerOffer)]
forall k a. Map k a -> [(k, a)]
Map.toList Map LeiosPoint PeerOffer
offers
, LeiosPoint -> LeiosOutstanding peer -> Bool
forall peer. LeiosPoint -> LeiosOutstanding peer -> Bool
isFocusedPoint LeiosPoint
point LeiosOutstanding peer
acc
]
go :: (LeiosOutstanding peer, Seq LeiosFetchRequest,
Map LeiosPoint OfferPrune)
-> [(LeiosPoint, PeerOffer)]
-> (LeiosOutstanding peer, Seq LeiosFetchRequest,
Map LeiosPoint OfferPrune)
go (LeiosOutstanding peer, Seq LeiosFetchRequest,
Map LeiosPoint OfferPrune)
st = \case
[] -> (LeiosOutstanding peer, Seq LeiosFetchRequest,
Map LeiosPoint OfferPrune)
st
(LeiosPoint
point, PeerOffer
offerKind) : [(LeiosPoint, PeerOffer)]
rest -> case LeiosPoint
-> PeerOffer
-> (LeiosOutstanding peer, Seq LeiosFetchRequest,
Map LeiosPoint OfferPrune)
-> ((LeiosOutstanding peer, Seq LeiosFetchRequest,
Map LeiosPoint OfferPrune),
WhetherPeerSaturated)
classify LeiosPoint
point PeerOffer
offerKind (LeiosOutstanding peer, Seq LeiosFetchRequest,
Map LeiosPoint OfferPrune)
st of
((LeiosOutstanding peer, Seq LeiosFetchRequest,
Map LeiosPoint OfferPrune)
st', WhetherPeerSaturated
PeerSaturated) -> (LeiosOutstanding peer, Seq LeiosFetchRequest,
Map LeiosPoint OfferPrune)
st'
((LeiosOutstanding peer, Seq LeiosFetchRequest,
Map LeiosPoint OfferPrune)
st', WhetherPeerSaturated
PeerNotSaturated) -> (LeiosOutstanding peer, Seq LeiosFetchRequest,
Map LeiosPoint OfferPrune)
-> [(LeiosPoint, PeerOffer)]
-> (LeiosOutstanding peer, Seq LeiosFetchRequest,
Map LeiosPoint OfferPrune)
go (LeiosOutstanding peer, Seq LeiosFetchRequest,
Map LeiosPoint OfferPrune)
st' [(LeiosPoint, PeerOffer)]
rest
classify :: LeiosPoint
-> PeerOffer
-> (LeiosOutstanding peer, Seq LeiosFetchRequest,
Map LeiosPoint OfferPrune)
-> ((LeiosOutstanding peer, Seq LeiosFetchRequest,
Map LeiosPoint OfferPrune),
WhetherPeerSaturated)
classify LeiosPoint
point PeerOffer
offerKind (LeiosOutstanding peer
acc1, Seq LeiosFetchRequest
dec1, Map LeiosPoint OfferPrune
drops) =
case LeiosPoint -> Map LeiosPoint EbState -> Maybe EbState
forall k a. Ord k => k -> Map k a -> Maybe a
Map.lookup LeiosPoint
point (LeiosOutstanding peer -> Map LeiosPoint EbState
forall peer. LeiosOutstanding peer -> Map LeiosPoint EbState
ebState LeiosOutstanding peer
acc1) of
Maybe EbState
Nothing ->
((LeiosOutstanding peer, Seq LeiosFetchRequest,
Map LeiosPoint OfferPrune),
WhetherPeerSaturated)
pruneThisOffer
Just (MkEbState StrictMaybe RelativeTime
onset EbFetchState
fetchState) -> case (EbFetchState
fetchState, PeerOffer -> OfferedHalves
poOffered PeerOffer
offerKind) of
(EbFetchState
NoBody, OfferedBody Word32
size) ->
Word32
-> ((LeiosOutstanding peer, Seq LeiosFetchRequest,
Map LeiosPoint OfferPrune),
WhetherPeerSaturated)
requestBodyAndPrune Word32
size
(EbFetchState
NoBody, OfferedHalves
OfferedClosure) ->
(LeiosOutstanding peer, Seq LeiosFetchRequest,
Map LeiosPoint OfferPrune)
-> ((LeiosOutstanding peer, Seq LeiosFetchRequest,
Map LeiosPoint OfferPrune),
WhetherPeerSaturated)
forall {a}. a -> (a, WhetherPeerSaturated)
continue (LeiosOutstanding peer
acc1, Seq LeiosFetchRequest
dec1, Map LeiosPoint OfferPrune
drops)
(EbFetchState
NoBody, OfferedBodyAndClosure Word32
size) ->
Word32
-> ((LeiosOutstanding peer, Seq LeiosFetchRequest,
Map LeiosPoint OfferPrune),
WhetherPeerSaturated)
requestBodyAndPrune Word32
size
(BodyAcquired LeiosJobPool
_jobPool, OfferedBody Word32
_size) ->
(LeiosOutstanding peer, Seq LeiosFetchRequest,
Map LeiosPoint OfferPrune)
-> ((LeiosOutstanding peer, Seq LeiosFetchRequest,
Map LeiosPoint OfferPrune),
WhetherPeerSaturated)
forall {a}. a -> (a, WhetherPeerSaturated)
continue (LeiosOutstanding peer
acc1, Seq LeiosFetchRequest
dec1, LeiosPoint
-> OfferPrune
-> Map LeiosPoint OfferPrune
-> Map LeiosPoint OfferPrune
forall k a. Ord k => k -> a -> Map k a -> Map k a
Map.insert LeiosPoint
point OfferPrune
PruneOfferedBody Map LeiosPoint OfferPrune
drops)
(BodyAcquired LeiosJobPool
jobPool, OfferedHalves
OfferedClosure) -> StrictMaybe RelativeTime
-> LeiosJobPool
-> ((LeiosOutstanding peer, Seq LeiosFetchRequest,
Map LeiosPoint OfferPrune),
WhetherPeerSaturated)
requestClosure StrictMaybe RelativeTime
onset LeiosJobPool
jobPool
(BodyAcquired LeiosJobPool
jobPool, OfferedBodyAndClosure Word32
_size) -> StrictMaybe RelativeTime
-> LeiosJobPool
-> ((LeiosOutstanding peer, Seq LeiosFetchRequest,
Map LeiosPoint OfferPrune),
WhetherPeerSaturated)
requestClosure StrictMaybe RelativeTime
onset LeiosJobPool
jobPool
where
budget :: Int
budget = LeiosFetchStaticEnv
-> IsBigLedgerPeer -> LeiosOutstanding peer -> peer -> Int
forall peer.
Ord peer =>
LeiosFetchStaticEnv
-> IsBigLedgerPeer -> LeiosOutstanding peer -> peer -> Int
peerBudget LeiosFetchStaticEnv
env IsBigLedgerPeer
isBig LeiosOutstanding peer
acc1 peer
peer
continue :: a -> (a, WhetherPeerSaturated)
continue a
st = (a
st, WhetherPeerSaturated
PeerNotSaturated)
pruneThisOffer :: ((LeiosOutstanding peer, Seq LeiosFetchRequest,
Map LeiosPoint OfferPrune),
WhetherPeerSaturated)
pruneThisOffer = (LeiosOutstanding peer, Seq LeiosFetchRequest,
Map LeiosPoint OfferPrune)
-> ((LeiosOutstanding peer, Seq LeiosFetchRequest,
Map LeiosPoint OfferPrune),
WhetherPeerSaturated)
forall {a}. a -> (a, WhetherPeerSaturated)
continue (LeiosOutstanding peer
acc1, Seq LeiosFetchRequest
dec1, LeiosPoint
-> OfferPrune
-> Map LeiosPoint OfferPrune
-> Map LeiosPoint OfferPrune
forall k a. Ord k => k -> a -> Map k a -> Map k a
Map.insert LeiosPoint
point OfferPrune
PruneOffer Map LeiosPoint OfferPrune
drops)
requestBodyAndPrune :: Word32
-> ((LeiosOutstanding peer, Seq LeiosFetchRequest,
Map LeiosPoint OfferPrune),
WhetherPeerSaturated)
requestBodyAndPrune Word32
size =
case (SlotNo
-> Either OutsideForecastRange (LeiosEbByteSizes 'SizeLimit))
-> Int
-> peer
-> LeiosPoint
-> StrictMaybe (LeiosEbByteSizes 'SizeLimit)
-> Word32
-> (LeiosOutstanding peer, Seq LeiosFetchRequest)
-> AssignedBody peer
forall peer.
Ord peer =>
(SlotNo
-> Either OutsideForecastRange (LeiosEbByteSizes 'SizeLimit))
-> Int
-> peer
-> LeiosPoint
-> StrictMaybe (LeiosEbByteSizes 'SizeLimit)
-> Word32
-> (LeiosOutstanding peer, Seq LeiosFetchRequest)
-> AssignedBody peer
assignBody SlotNo -> Either OutsideForecastRange (LeiosEbByteSizes 'SizeLimit)
forecastEbBounds Int
budget peer
peer LeiosPoint
point (PeerOffer -> StrictMaybe (LeiosEbByteSizes 'SizeLimit)
poEbBounds PeerOffer
offerKind) Word32
size (LeiosOutstanding peer
acc1, Seq LeiosFetchRequest
dec1) of
AssignedBody peer
BodyNotRequested -> (LeiosOutstanding peer, Seq LeiosFetchRequest,
Map LeiosPoint OfferPrune)
-> ((LeiosOutstanding peer, Seq LeiosFetchRequest,
Map LeiosPoint OfferPrune),
WhetherPeerSaturated)
forall {a}. a -> (a, WhetherPeerSaturated)
continue (LeiosOutstanding peer
acc1, Seq LeiosFetchRequest
dec1, Map LeiosPoint OfferPrune
drops)
AssignedBody peer
BodyOverBudget -> ((LeiosOutstanding peer
acc1, Seq LeiosFetchRequest
dec1, Map LeiosPoint OfferPrune
drops), WhetherPeerSaturated
PeerSaturated)
BodyRequested LeiosOutstanding peer
acc2 Seq LeiosFetchRequest
dec2 -> (LeiosOutstanding peer, Seq LeiosFetchRequest,
Map LeiosPoint OfferPrune)
-> ((LeiosOutstanding peer, Seq LeiosFetchRequest,
Map LeiosPoint OfferPrune),
WhetherPeerSaturated)
forall {a}. a -> (a, WhetherPeerSaturated)
continue (LeiosOutstanding peer
acc2, Seq LeiosFetchRequest
dec2, LeiosPoint
-> OfferPrune
-> Map LeiosPoint OfferPrune
-> Map LeiosPoint OfferPrune
forall k a. Ord k => k -> a -> Map k a -> Map k a
Map.insert LeiosPoint
point OfferPrune
PruneOfferedBody Map LeiosPoint OfferPrune
drops)
requestClosure :: StrictMaybe RelativeTime
-> LeiosJobPool
-> ((LeiosOutstanding peer, Seq LeiosFetchRequest,
Map LeiosPoint OfferPrune),
WhetherPeerSaturated)
requestClosure StrictMaybe RelativeTime
onset LeiosJobPool
jobPool
| LeiosJobPool -> Bool
Jobs.nullJobPool LeiosJobPool
jobPool =
((LeiosOutstanding peer, Seq LeiosFetchRequest,
Map LeiosPoint OfferPrune),
WhetherPeerSaturated)
pruneThisOffer
| Bool
otherwise =
let ((LeiosOutstanding peer
acc2, Seq LeiosFetchRequest
dec2), WhyPickingStopped
stopped) = LeiosFetchStaticEnv
-> IsBigLedgerPeer
-> peer
-> LeiosPoint
-> StrictMaybe RelativeTime
-> LeiosJobPool
-> (LeiosOutstanding peer, Seq LeiosFetchRequest)
-> ((LeiosOutstanding peer, Seq LeiosFetchRequest),
WhyPickingStopped)
forall peer.
Ord peer =>
LeiosFetchStaticEnv
-> IsBigLedgerPeer
-> peer
-> LeiosPoint
-> StrictMaybe RelativeTime
-> LeiosJobPool
-> (LeiosOutstanding peer, Seq LeiosFetchRequest)
-> ((LeiosOutstanding peer, Seq LeiosFetchRequest),
WhyPickingStopped)
assignClosure LeiosFetchStaticEnv
env IsBigLedgerPeer
isBig peer
peer LeiosPoint
point StrictMaybe RelativeTime
onset LeiosJobPool
jobPool (LeiosOutstanding peer
acc1, Seq LeiosFetchRequest
dec1)
in case WhyPickingStopped
stopped of
WhyPickingStopped
PeerEbExhausted -> (LeiosOutstanding peer, Seq LeiosFetchRequest,
Map LeiosPoint OfferPrune)
-> ((LeiosOutstanding peer, Seq LeiosFetchRequest,
Map LeiosPoint OfferPrune),
WhetherPeerSaturated)
forall {a}. a -> (a, WhetherPeerSaturated)
continue (LeiosOutstanding peer
acc2, Seq LeiosFetchRequest
dec2, LeiosPoint
-> OfferPrune
-> Map LeiosPoint OfferPrune
-> Map LeiosPoint OfferPrune
forall k a. Ord k => k -> a -> Map k a -> Map k a
Map.insert LeiosPoint
point OfferPrune
PruneOffer Map LeiosPoint OfferPrune
drops)
WhyPickingStopped
NextJobOverBudget -> ((LeiosOutstanding peer
acc2, Seq LeiosFetchRequest
dec2, Map LeiosPoint OfferPrune
drops), WhetherPeerSaturated
PeerSaturated)
data WhetherPeerSaturated = PeerSaturated | PeerNotSaturated
assignBody ::
Ord peer =>
(SlotNo -> Either OutsideForecastRange (LeiosEbByteSizes SizeLimit)) ->
Int ->
peer ->
LeiosPoint ->
StrictMaybe (LeiosEbByteSizes SizeLimit) ->
BytesSize ->
(LeiosOutstanding peer, Seq LeiosFetchRequest) ->
AssignedBody peer
assignBody :: forall peer.
Ord peer =>
(SlotNo
-> Either OutsideForecastRange (LeiosEbByteSizes 'SizeLimit))
-> Int
-> peer
-> LeiosPoint
-> StrictMaybe (LeiosEbByteSizes 'SizeLimit)
-> Word32
-> (LeiosOutstanding peer, Seq LeiosFetchRequest)
-> AssignedBody peer
assignBody SlotNo -> Either OutsideForecastRange (LeiosEbByteSizes 'SizeLimit)
forecastEbBounds Int
budget peer
peer LeiosPoint
point StrictMaybe (LeiosEbByteSizes 'SizeLimit)
offerBounds Word32
size (LeiosOutstanding peer
acc, Seq LeiosFetchRequest
dec)
| peer
peer peer -> Set peer -> Bool
forall a. Ord a => a -> Set a -> Bool
`Set.member` Set peer -> LeiosPoint -> Map LeiosPoint (Set peer) -> Set peer
forall k a. Ord k => a -> k -> Map k a -> a
Map.findWithDefault Set peer
forall a. Set a
Set.empty LeiosPoint
point (LeiosOutstanding peer -> Map LeiosPoint (Set peer)
forall peer. LeiosOutstanding peer -> Map LeiosPoint (Set peer)
requestedEbPeers LeiosOutstanding peer
acc) =
AssignedBody peer
forall peer. AssignedBody peer
BodyNotRequested
| Bool
otherwise = case Either OutsideForecastRange (LeiosEbByteSizes 'SizeLimit)
eEbBounds of
Left OutsideForecastRange
_outsideRange -> AssignedBody peer
forall peer. AssignedBody peer
BodyNotRequested
Right LeiosEbByteSizes 'SizeLimit
bounds
| Word32 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word32
size Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
> Int
budget -> AssignedBody peer
forall peer. AssignedBody peer
BodyOverBudget
| Bool
otherwise ->
let acc' :: LeiosOutstanding peer
acc' =
LeiosOutstanding peer
acc
{ requestedEbPeers =
Map.insertWith Set.union point (Set.singleton peer) (requestedEbPeers acc)
, requestedEbsPerPeer =
Map.insertWith NESet.union peer (NESet.singleton point) (requestedEbsPerPeer acc)
, requestedBytesSizePerPeer =
Map.insertWith (+) peer size (requestedBytesSizePerPeer acc)
}
in LeiosOutstanding peer -> Seq LeiosFetchRequest -> AssignedBody peer
forall peer.
LeiosOutstanding peer -> Seq LeiosFetchRequest -> AssignedBody peer
BodyRequested
LeiosOutstanding peer
acc'
( Seq LeiosFetchRequest
dec
Seq LeiosFetchRequest -> LeiosFetchRequest -> Seq LeiosFetchRequest
forall a. Seq a -> a -> Seq a
Seq.|> LeiosBlockRequest -> LeiosFetchRequest
LeiosBlockRequest
MkLeiosBlockRequest
{ lbrPoint :: LeiosPoint
lbrPoint = LeiosPoint
point
, lbrOfferedSize :: Word32
lbrOfferedSize = Word32
size
, lbrEbBounds :: LeiosEbByteSizes 'SizeLimit
lbrEbBounds = LeiosEbByteSizes 'SizeLimit
bounds
}
)
where
eEbBounds :: Either OutsideForecastRange (LeiosEbByteSizes 'SizeLimit)
eEbBounds = case StrictMaybe (LeiosEbByteSizes 'SizeLimit)
offerBounds of
SJust LeiosEbByteSizes 'SizeLimit
x -> LeiosEbByteSizes 'SizeLimit
-> Either OutsideForecastRange (LeiosEbByteSizes 'SizeLimit)
forall a b. b -> Either a b
Right LeiosEbByteSizes 'SizeLimit
x
StrictMaybe (LeiosEbByteSizes 'SizeLimit)
SNothing -> SlotNo -> Either OutsideForecastRange (LeiosEbByteSizes 'SizeLimit)
forecastEbBounds (LeiosPoint -> SlotNo
pointSlotNo LeiosPoint
point)
data AssignedBody peer
=
BodyRequested (LeiosOutstanding peer) (Seq LeiosFetchRequest)
|
BodyNotRequested
|
BodyOverBudget
data WhyPickingStopped
=
PeerEbExhausted
|
NextJobOverBudget
assignClosure ::
Ord peer =>
LeiosFetchStaticEnv ->
IsBigLedgerPeer ->
peer ->
LeiosPoint ->
StrictMaybe RelativeTime ->
Jobs.LeiosJobPool ->
(LeiosOutstanding peer, Seq LeiosFetchRequest) ->
((LeiosOutstanding peer, Seq LeiosFetchRequest), WhyPickingStopped)
assignClosure :: forall peer.
Ord peer =>
LeiosFetchStaticEnv
-> IsBigLedgerPeer
-> peer
-> LeiosPoint
-> StrictMaybe RelativeTime
-> LeiosJobPool
-> (LeiosOutstanding peer, Seq LeiosFetchRequest)
-> ((LeiosOutstanding peer, Seq LeiosFetchRequest),
WhyPickingStopped)
assignClosure LeiosFetchStaticEnv
env IsBigLedgerPeer
isBig peer
peer LeiosPoint
point StrictMaybe RelativeTime
onset LeiosJobPool
jobPool st :: (LeiosOutstanding peer, Seq LeiosFetchRequest)
st@(LeiosOutstanding peer
acc, Seq LeiosFetchRequest
dec) =
let inflightJobs :: IntSet
inflightJobs =
IntSet -> (NEIntSet -> IntSet) -> Maybe NEIntSet -> IntSet
forall b a. b -> (a -> b) -> Maybe a -> b
maybe IntSet
IntSet.empty NEIntSet -> IntSet
NEIntSet.toSet (Maybe NEIntSet -> IntSet) -> Maybe NEIntSet -> IntSet
forall a b. (a -> b) -> a -> b
$
LeiosPoint -> Map LeiosPoint NEIntSet -> Maybe NEIntSet
forall k a. Ord k => k -> Map k a -> Maybe a
Map.lookup LeiosPoint
point (Map LeiosPoint NEIntSet -> Maybe NEIntSet)
-> Maybe (Map LeiosPoint NEIntSet) -> Maybe NEIntSet
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< peer
-> Map peer (Map LeiosPoint NEIntSet)
-> Maybe (Map LeiosPoint NEIntSet)
forall k a. Ord k => k -> Map k a -> Maybe a
Map.lookup peer
peer (LeiosOutstanding peer -> Map peer (Map LeiosPoint NEIntSet)
forall peer.
LeiosOutstanding peer -> Map peer (Map LeiosPoint NEIntSet)
requestedJobsPerPeer LeiosOutstanding peer
acc)
([(LeiosJobId, LeiosJob)]
picked, LeiosJobPool
jobPool', StdGen
prng', WhyPickingStopped
stopped) =
StdGen
-> IntSet
-> LeiosJobPool
-> Int
-> ([(LeiosJobId, LeiosJob)], LeiosJobPool, StdGen,
WhyPickingStopped)
pickJobs (LeiosOutstanding peer -> StdGen
forall peer. LeiosOutstanding peer -> StdGen
leiosFetchPrng LeiosOutstanding peer
acc) IntSet
inflightJobs LeiosJobPool
jobPool (LeiosFetchStaticEnv
-> IsBigLedgerPeer -> LeiosOutstanding peer -> peer -> Int
forall peer.
Ord peer =>
LeiosFetchStaticEnv
-> IsBigLedgerPeer -> LeiosOutstanding peer -> peer -> Int
peerBudget LeiosFetchStaticEnv
env IsBigLedgerPeer
isBig LeiosOutstanding peer
acc peer
peer)
in ((LeiosOutstanding peer, Seq LeiosFetchRequest)
-> WhyPickingStopped
-> ((LeiosOutstanding peer, Seq LeiosFetchRequest),
WhyPickingStopped))
-> WhyPickingStopped
-> (LeiosOutstanding peer, Seq LeiosFetchRequest)
-> ((LeiosOutstanding peer, Seq LeiosFetchRequest),
WhyPickingStopped)
forall a b c. (a -> b -> c) -> b -> a -> c
flip (,) WhyPickingStopped
stopped ((LeiosOutstanding peer, Seq LeiosFetchRequest)
-> ((LeiosOutstanding peer, Seq LeiosFetchRequest),
WhyPickingStopped))
-> (LeiosOutstanding peer, Seq LeiosFetchRequest)
-> ((LeiosOutstanding peer, Seq LeiosFetchRequest),
WhyPickingStopped)
forall a b. (a -> b) -> a -> b
$ case [(LeiosJobId, LeiosJob)] -> Maybe (NonEmpty (LeiosJobId, LeiosJob))
forall a. [a] -> Maybe (NonEmpty a)
nonEmpty [(LeiosJobId, LeiosJob)]
picked of
Maybe (NonEmpty (LeiosJobId, LeiosJob))
Nothing -> (LeiosOutstanding peer, Seq LeiosFetchRequest)
st
Just NonEmpty (LeiosJobId, LeiosJob)
nePicked ->
let acc' :: LeiosOutstanding peer
acc' =
LeiosOutstanding peer
acc
{ ebState =
Map.insert
point
(MkEbState onset (BodyAcquired jobPool'))
(ebState acc)
, requestedJobsPerPeer =
Map.insertWith
(Map.unionWith NEIntSet.union)
peer
( Map.singleton point $
NEIntSet.fromList $
fmap (\(Jobs.MkLeiosJobId Int
i, LeiosJob
_) -> Int
i) nePicked
)
(requestedJobsPerPeer acc)
, requestedBytesSizePerPeer =
Map.insertWith
(+)
peer
(sum $ fmap (\(LeiosJobId
_, Jobs.MkLeiosJob IntSet
_ Word32
bytes JobCommitment
_) -> Word32
bytes) nePicked)
(requestedBytesSizePerPeer acc)
, leiosFetchPrng = prng'
}
reqs :: [LeiosFetchRequest]
reqs = LeiosFetchStaticEnv
-> LeiosPoint
-> NonEmpty (LeiosJobId, LeiosJob)
-> [LeiosFetchRequest]
batchTxsRequests LeiosFetchStaticEnv
env LeiosPoint
point NonEmpty (LeiosJobId, LeiosJob)
nePicked
in (LeiosOutstanding peer
acc', Seq LeiosFetchRequest
dec Seq LeiosFetchRequest
-> Seq LeiosFetchRequest -> Seq LeiosFetchRequest
forall a. Semigroup a => a -> a -> a
<> [LeiosFetchRequest] -> Seq LeiosFetchRequest
forall a. [a] -> Seq a
Seq.fromList [LeiosFetchRequest]
reqs)
pickJobs ::
StdGen ->
IntSet.IntSet ->
Jobs.LeiosJobPool ->
Int ->
([(Jobs.LeiosJobId, Jobs.LeiosJob)], Jobs.LeiosJobPool, StdGen, WhyPickingStopped)
pickJobs :: StdGen
-> IntSet
-> LeiosJobPool
-> Int
-> ([(LeiosJobId, LeiosJob)], LeiosJobPool, StdGen,
WhyPickingStopped)
pickJobs StdGen
prng0 IntSet
inflightJobs0 LeiosJobPool
jobPool0 Int
budget0 =
StdGen
-> IntSet
-> LeiosJobPool
-> Int
-> [(LeiosJobId, LeiosJob)]
-> ([(LeiosJobId, LeiosJob)], LeiosJobPool, StdGen,
WhyPickingStopped)
forall {t}.
(Ord t, Num t) =>
StdGen
-> IntSet
-> LeiosJobPool
-> t
-> [(LeiosJobId, LeiosJob)]
-> ([(LeiosJobId, LeiosJob)], LeiosJobPool, StdGen,
WhyPickingStopped)
go StdGen
prng0 IntSet
inflightJobs0 LeiosJobPool
jobPool0 Int
budget0 []
where
go :: StdGen
-> IntSet
-> LeiosJobPool
-> t
-> [(LeiosJobId, LeiosJob)]
-> ([(LeiosJobId, LeiosJob)], LeiosJobPool, StdGen,
WhyPickingStopped)
go StdGen
prng IntSet
inflightJobs LeiosJobPool
jobPool t
budget [(LeiosJobId, LeiosJob)]
acc =
case StdGen
-> IntSet
-> LeiosJobPool
-> Maybe (LeiosJobId, LeiosJob, LeiosJobPool, StdGen)
Jobs.pickLeastRequestedJobExcept StdGen
prng IntSet
inflightJobs LeiosJobPool
jobPool of
Maybe (LeiosJobId, LeiosJob, LeiosJobPool, StdGen)
Nothing -> ([(LeiosJobId, LeiosJob)] -> [(LeiosJobId, LeiosJob)]
forall a. [a] -> [a]
reverse [(LeiosJobId, LeiosJob)]
acc, LeiosJobPool
jobPool, StdGen
prng, WhyPickingStopped
PeerEbExhausted)
Just (jid :: LeiosJobId
jid@(Jobs.MkLeiosJobId Int
i), job :: LeiosJob
job@(Jobs.MkLeiosJob IntSet
_offsets Word32
bytes JobCommitment
_commitment), LeiosJobPool
jobPool', StdGen
prng')
| Word32 -> t
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word32
bytes t -> t -> Bool
forall a. Ord a => a -> a -> Bool
> t
budget ->
([(LeiosJobId, LeiosJob)] -> [(LeiosJobId, LeiosJob)]
forall a. [a] -> [a]
reverse [(LeiosJobId, LeiosJob)]
acc, LeiosJobPool
jobPool, StdGen
prng, WhyPickingStopped
NextJobOverBudget)
| Bool
otherwise ->
StdGen
-> IntSet
-> LeiosJobPool
-> t
-> [(LeiosJobId, LeiosJob)]
-> ([(LeiosJobId, LeiosJob)], LeiosJobPool, StdGen,
WhyPickingStopped)
go
StdGen
prng'
(Int -> IntSet -> IntSet
IntSet.insert Int
i IntSet
inflightJobs)
LeiosJobPool
jobPool'
(t
budget t -> t -> t
forall a. Num a => a -> a -> a
- Word32 -> t
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word32
bytes)
((LeiosJobId
jid, LeiosJob
job) (LeiosJobId, LeiosJob)
-> [(LeiosJobId, LeiosJob)] -> [(LeiosJobId, LeiosJob)]
forall a. a -> [a] -> [a]
: [(LeiosJobId, LeiosJob)]
acc)
batchTxsRequests ::
LeiosFetchStaticEnv ->
LeiosPoint ->
NonEmpty (Jobs.LeiosJobId, Jobs.LeiosJob) ->
[LeiosFetchRequest]
batchTxsRequests :: LeiosFetchStaticEnv
-> LeiosPoint
-> NonEmpty (LeiosJobId, LeiosJob)
-> [LeiosFetchRequest]
batchTxsRequests LeiosFetchStaticEnv
env LeiosPoint
point ((LeiosJobId, LeiosJob)
j0 :| [(LeiosJobId, LeiosJob)]
rest0) =
(LeiosJobId, LeiosJob)
-> [(LeiosJobId, LeiosJob)]
-> Int
-> [(LeiosJobId, LeiosJob)]
-> [LeiosFetchRequest]
go (LeiosJobId, LeiosJob)
j0 [] ((LeiosJobId, LeiosJob) -> Int
forall {a}. (a, LeiosJob) -> Int
jobBytes (LeiosJobId, LeiosJob)
j0) [(LeiosJobId, LeiosJob)]
rest0
where
cap :: Int
cap = Word32 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral (LeiosFetchStaticEnv -> Word32
maxRequestBytesSize LeiosFetchStaticEnv
env) :: Int
jobBytes :: (a, LeiosJob) -> Int
jobBytes (a
_jid, Jobs.MkLeiosJob IntSet
_offs Word32
bytes JobCommitment
_commitment) = Word32 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word32
bytes :: Int
flush :: (LeiosJobId, LeiosJob)
-> [(LeiosJobId, LeiosJob)] -> LeiosFetchRequest
flush (LeiosJobId, LeiosJob)
seed [(LeiosJobId, LeiosJob)]
accRev =
LeiosBlockTxsRequest -> LeiosFetchRequest
LeiosBlockTxsRequest (LeiosBlockTxsRequest -> LeiosFetchRequest)
-> LeiosBlockTxsRequest -> LeiosFetchRequest
forall a b. (a -> b) -> a -> b
$
LeiosPoint -> NEIntMap LeiosJob -> LeiosBlockTxsRequest
MkLeiosBlockTxsRequest
LeiosPoint
point
(NonEmpty (Int, LeiosJob) -> NEIntMap LeiosJob
forall a. NonEmpty (Int, a) -> NEIntMap a
NEIntMap.fromList (((LeiosJobId, LeiosJob) -> (Int, LeiosJob))
-> NonEmpty (LeiosJobId, LeiosJob) -> NonEmpty (Int, LeiosJob)
forall a b. (a -> b) -> NonEmpty a -> NonEmpty b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (\(Jobs.MkLeiosJobId Int
i, LeiosJob
job) -> (Int
i, LeiosJob
job)) ((LeiosJobId, LeiosJob)
seed (LeiosJobId, LeiosJob)
-> [(LeiosJobId, LeiosJob)] -> NonEmpty (LeiosJobId, LeiosJob)
forall a. a -> [a] -> NonEmpty a
:| [(LeiosJobId, LeiosJob)] -> [(LeiosJobId, LeiosJob)]
forall a. [a] -> [a]
reverse [(LeiosJobId, LeiosJob)]
accRev)))
go :: (LeiosJobId, LeiosJob)
-> [(LeiosJobId, LeiosJob)]
-> Int
-> [(LeiosJobId, LeiosJob)]
-> [LeiosFetchRequest]
go (LeiosJobId, LeiosJob)
seed [(LeiosJobId, LeiosJob)]
accRev Int
_curBytes [] = [(LeiosJobId, LeiosJob)
-> [(LeiosJobId, LeiosJob)] -> LeiosFetchRequest
flush (LeiosJobId, LeiosJob)
seed [(LeiosJobId, LeiosJob)]
accRev]
go (LeiosJobId, LeiosJob)
seed [(LeiosJobId, LeiosJob)]
accRev Int
curBytes ((LeiosJobId, LeiosJob)
j : [(LeiosJobId, LeiosJob)]
rest)
| Int
curBytes Int -> Int -> Int
forall a. Num a => a -> a -> a
+ (LeiosJobId, LeiosJob) -> Int
forall {a}. (a, LeiosJob) -> Int
jobBytes (LeiosJobId, LeiosJob)
j Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
> Int
cap = (LeiosJobId, LeiosJob)
-> [(LeiosJobId, LeiosJob)] -> LeiosFetchRequest
flush (LeiosJobId, LeiosJob)
seed [(LeiosJobId, LeiosJob)]
accRev LeiosFetchRequest -> [LeiosFetchRequest] -> [LeiosFetchRequest]
forall a. a -> [a] -> [a]
: (LeiosJobId, LeiosJob)
-> [(LeiosJobId, LeiosJob)]
-> Int
-> [(LeiosJobId, LeiosJob)]
-> [LeiosFetchRequest]
go (LeiosJobId, LeiosJob)
j [] ((LeiosJobId, LeiosJob) -> Int
forall {a}. (a, LeiosJob) -> Int
jobBytes (LeiosJobId, LeiosJob)
j) [(LeiosJobId, LeiosJob)]
rest
| Bool
otherwise = (LeiosJobId, LeiosJob)
-> [(LeiosJobId, LeiosJob)]
-> Int
-> [(LeiosJobId, LeiosJob)]
-> [LeiosFetchRequest]
go (LeiosJobId, LeiosJob)
seed ((LeiosJobId, LeiosJob)
j (LeiosJobId, LeiosJob)
-> [(LeiosJobId, LeiosJob)] -> [(LeiosJobId, LeiosJob)]
forall a. a -> [a] -> [a]
: [(LeiosJobId, LeiosJob)]
accRev) (Int
curBytes Int -> Int -> Int
forall a. Num a => a -> a -> a
+ (LeiosJobId, LeiosJob) -> Int
forall {a}. (a, LeiosJob) -> Int
jobBytes (LeiosJobId, LeiosJob)
j) [(LeiosJobId, LeiosJob)]
rest