ouroboros-network
Safe HaskellNone
LanguageHaskell2010

Ouroboros.Network.TxSubmission.Inbound.V2.Registry

Synopsis

Documentation

type SharedTxStateVar (m :: Type -> Type) peeraddr txid = StrictTVar m (SharedTxState peeraddr txid) Source #

Shared STM handle for V2 coordination state.

type PeerTxRegistry (m :: Type -> Type) peeraddr = StrictTVar m (Map peeraddr (PeerTxInFlightVar m, TxSubmissionCountersVar m)) Source #

Registry of every live peer's coordination TVars: its in-flight contributions and its private counters cell.

withPeer adds the pair on bracket-enter and removes it on bracket-exit (after scrubbing any contributions the peer still has to shared state and flushing its counters into the retired accumulator). snapshotLiveReferences reads the in-flight vars to compute the liveAdvertised union; snapshotCounters reads the counter cells to aggregate for emission.

data PeerTxAPI (m :: Type -> Type) txid tx Source #

Peer-facing coordination API.

The peer thread keeps its local protocol state in a local variable. Registry helpers operate only on the shared STM state and the per-peer PeerTxInFlight TVar (closure-captured); any helper that needs peer-local state should take it explicitly as an argument.

Constructors

PeerTxAPI 

Fields

type TxSubmissionCountersVar (m :: Type -> Type) = StrictTVar m TxSubmissionCounters Source #

STM handle for V2 monotonic counters. Used both for each peer's private counters cell and for the shared retired-peers accumulator (see withPeer and txCountersThreadV2).

newSharedTxStateVar :: MonadSTM m => SharedTxState peeraddr txid -> m (SharedTxStateVar m peeraddr txid) Source #

txCountersThreadV2 :: forall m peeraddr txid tx. (MonadDelay m, MonadSTM m, HasRawTxId txid) => TxDecisionPolicy -> Tracer m TxSubmissionCounters -> Tracer m (TraceTxLogic peeraddr txid tx) -> TxSubmissionCountersVar m -> SharedTxStateVar m peeraddr txid -> PeerTxRegistry m peeraddr -> m Void Source #

Central bookkeeping thread for V2.

Wakes every bufferedTxsMinLifetime policy / 4 seconds (capped between 100 ms and 1 s) to run sweepSharedState on the shared tx state. The sweep needs the union of every live peer's pifAdvertised to decide which entries are still wanted; the registry is read inside the same STM transaction as the sweep so the snapshot is coherent. On a slower cadence (every countersInterval seconds of elapsed time) it also emits the aggregated counters -- the retired-peers accumulator plus every live peer's cell -- when they differ from the last emission, and a TraceSharedTxState snapshot when sharedRevision or sharedGeneration has moved since the last emission.

withPeer :: forall peeraddr txid tx idx m a. (MonadMask m, MonadTimer m, Ord peeraddr, Show peeraddr, Ord txid, HasRawTxId txid) => TxDecisionPolicy -> TxSubmissionMempoolReader txid tx idx m -> SharedTxStateVar m peeraddr txid -> PeerTxRegistry m peeraddr -> TxSubmissionCountersVar m -> peeraddr -> (PeerTxAPI m txid tx -> m a) -> m a Source #

A bracket function which registers / de-registers a new peer in SharedTxStateVar, which exposes PeerTxStateAPI. PeerTxStateAPI is only safe inside the withPeer scope.