ouroboros-consensus
Safe HaskellNone
LanguageHaskell2010

Ouroboros.Consensus.MiniProtocol.LeiosFetch.Kernel

Description

The node's LeiosFetch state, which all its LeiosFetch clients share, and the threads that maintain it: the decision loop, which assigns the peers' offers to requests, and the worker that acts on new announcements.

Synopsis

Documentation

data LeiosFetchKernel (m ∷ Type → Type) peer blk Source #

The node's LeiosFetch state, which all its LeiosFetch clients share.

Constructors

MkLeiosFetchKernel 

Fields

data LeiosFetchPeer (m ∷ Type → Type) blk Source #

What the node's LeiosFetch state holds about one upstream peer.

Constructors

MkLeiosFetchPeer 

Fields

data LeiosPeerLifetimeId peer Source #

Identifies one registration of an upstream peer with the decision loop, from when the first of its mini-protocols registers it until it is unregistered; see withLeiosFetchPeer. The decision loop's state is keyed by it rather than by the peer, which the peer's later registrations share.

The peer alone would not do, even though connections whose mini-protocols run at the same time have different ConnectionIds: that covers only the mini-protocols' own threads. The LeiosDB writes asynchronously, so for each reply a LeiosFetch client forks a thread that waits for the write and then updates the decision loop's state for the peer, and that thread may outlive the client. By then the peer may have registered again, after the mux restarted its mini-protocols or after it reconnected with the same ConnectionId, and the update would act on that registration instead.

Constructors

MkLeiosPeerLifetimeId !peer !Word64 

newLeiosFetchKernel Source #

Arguments

∷ (IOLike m, LedgerSupportsProtocol blk) 
⇒ ChainDB m blk 
→ LeiosDbHandle m 
→ StdGen

Seeds the decision loop's PRNG.

→ (StrictMVar m (LeiosOutstanding (LeiosPeerLifetimeId peer)) → StrictMVar m () → LeiosFetchClientContext m (LeiosPeerLifetimeId peer))

Everything of the clients' context but the state this creates.

→ m (LeiosFetchKernel m peer blk) 

The node's LeiosFetch state, seeded with the complete closures its LeiosDB holds whose announcements the immutable tip has not passed, so that it neither fetches them nor emits their acquisitions again.

withLeiosFetchPeer ∷ (IOLike m, Ord peer) ⇒ LeiosFetchKernel m peer blk → peer → IsBigLedgerPeer → (LeiosPeerLifetimeId peer → LeiosFetchPeer m blk → m a) → m a Source #

Run the action with this peer's LeiosFetch state and the LeiosPeerLifetimeId of its registration, registering it with the decision loop if no other mini-protocol of the peer has.

There is no reference count: the first of the peer's mini-protocols to end unregisters it, and cancels what it had in flight, so that other peers are asked instead. Any of its mini-protocols still running keep their state, but the decision loop no longer assigns them anything.

A connection's mini-protocols find its registration by peer, so connections whose mini-protocols run at the same time must have different peers. Their ConnectionIds differ, by the exclusivity of ConnectionIds (see Ouroboros.Network.ConnectionId).

recordLeiosOffer ∷ IOLike m ⇒ LeiosFetchKernel m peer blk → LeiosFetchPeer m blk → LeiosPoint → PeerOffer → m () Source #

Record a peer's offer, which an earlier offer of the same point merges with, unless the point is older than what has been pruned, and wake the decision loop.

recordLeiosCertOffer Source #

Arguments

∷ ∀ m peer blk. (IOLike m, BlockSupportsProtocol blk) 
⇒ TopLevelConfig blk 
→ LeiosFetchKernel m peer blk 
→ LeiosFetchPeer m blk 
→ Header blk 
→ HeaderStateWithTime blk

The state as of the header's predecessor

→ m () 

Record the offer a peer makes by rolling forward a header that claims its block contains a Leios certificate: the endorser block the certificate certifies, both its body, at the size its announcement names, and its closure.

That endorser block is read from the state as of the header's predecessor, which announced it, so the peer chose which header to roll forward but not what its predecessor announced. The certificate has not been verified yet, so this only offers: what the node fetches is still up to each election's focus.

recordLeiosJumpOffers ∷ (IOLike m, LedgerSupportsProtocol blk) ⇒ TopLevelConfig blk → LeiosFetchKernel m peer blk → LeiosFetchPeer m blk → JumpInfo blk → m () Source #

recordLeiosCertOffer for each header of a ChainSync jump the peer accepted that its earlier jumps did not already cover.

Successive jumps along one chain overlap in all but their newest headers. If this jump's fragment holds the newest header of the previous jump, it holds the same headers before that one too, so those are skipped.

enqueueLeiosAnnouncement ∷ ∀ (m ∷ Type → Type) peer blk. IOLike m ⇒ LeiosFetchKernel m peer blk → ValidAnnouncement blk → STM m () Source #

Commit, within the transaction in which onValidAnnouncement accepts this announcement as new and as proving no equivocation, to leiosFetchAnnouncementFocuser acting on it.

leiosFetchAnnouncementFocuser ∷ IOLike m ⇒ LeiosFetchKernel m peer blk → m Void Source #

Act on each announcement enqueueLeiosAnnouncement commits to, in turn.

This thread must be carefully arranged to die if and only if the node is shutting down. Then the transaction that accepts an announcement need only include an enqueue, which this thread will definitely eventually handle.

The queue doesn't need an explicit bound, because it's only written to after dedup and age checks, and only for an election's first announcement, so it can't have more entries than there are volatile elections (at most ~10000).

onForgedLeiosEb ∷ IOLike m ⇒ LeiosFetchKernel m peer blk → AnnouncingHeader blk → ForgedEndorserBlock → m () Source #

The forge's counterpart to receiving an announcement and its endorser block from a peer: take in the endorser block the node's own forge produced, with the header announcing it, with no peer (acquireForgedEb).

The header must announce this endorser block.

leiosFetchCertificateFocuser Source #

Arguments

∷ IOLike m 
⇒ m (NonEmpty (LeiosClaim, LeiosAnnouncement))

The claims of the new Leios certifications validated since this last returned, each with the announcement it certifies, blocking until there is one

→ LeiosFetchKernel m peer blk 
→ m Void 

Move each election's focus onto the endorser block a verified certificate certifies, as ChainSel verifies such certificates.

This is how a node that only saw some other announcement for the election, or none, because the announcing block has been on its selection since before it started, comes to fetch the certified one. Each iteration focuses the elections certified since the one before, so a certificate verified after the offer arrived still moves the focus.

leiosFetchDecisionLoop ∷ (IOLike m, Ord peer, LedgerSupportsProtocol blk, HasHardForkHistory blk) ⇒ TopLevelConfig blk → ChainDB m blk → BlockchainTime m → LeiosFetchKernel m peer blk → m Void Source #

Each time something might give a peer something new to do, decide what to request from every peer, at most twice a second.

pruneLeiosFetchToImmTip ∷ IOLike m ⇒ LeiosFetchKernel m peer blk → SlotNo → m () Source #

Prune the node's LeiosFetch state, the peers' offers and claims, and the LeiosTxCache to the immutable tip's slot.

The ChainDB prunes the LeiosDB only to the slot of the blocks it has copied to the ImmutableDB, after a delay, so pruning the LeiosTxCache as soon as the immutable tip advances usually comes first; see evictOlderThanFoldl'.