Safe Haskell | None |
---|---|
Language | Haskell2010 |
Ouroboros.Network.TxSubmission.Inbound.V2.State
Synopsis
- data SharedTxState peeraddr txid tx = SharedTxState {
- peerTxStates :: !(Map peeraddr (PeerTxState txid tx))
- inflightTxs :: !(Map txid Int)
- inflightTxsSize :: !SizeInBytes
- bufferedTxs :: !(Map txid (Maybe tx))
- referenceCounts :: !(Map txid Int)
- timedTxs :: !(Map Time [txid])
- inSubmissionToMempoolTxs :: !(Map txid Int)
- peerRng :: !StdGen
- data PeerTxState txid tx = PeerTxState {
- unacknowledgedTxIds :: !(StrictSeq txid)
- availableTxIds :: !(Map txid SizeInBytes)
- requestedTxIdsInflight :: !NumTxIdsToReq
- requestedTxsInflightSize :: !SizeInBytes
- requestedTxsInflight :: !(Set txid)
- unknownTxs :: !(Set txid)
- score :: !Double
- scoreTs :: !Time
- downloadedTxs :: !(Map txid tx)
- toMempoolTxs :: !(Map txid tx)
- type SharedTxStateVar (m :: Type -> Type) peeraddr txid tx = StrictTVar m (SharedTxState peeraddr txid tx)
- newSharedTxStateVar :: MonadSTM m => StdGen -> m (SharedTxStateVar m peeraddr txid tx)
- receivedTxIds :: forall m peeraddr idx tx txid. (MonadSTM m, Ord txid, Ord peeraddr) => Tracer m (TraceTxLogic peeraddr txid tx) -> SharedTxStateVar m peeraddr txid tx -> STM m (MempoolSnapshot txid tx idx) -> peeraddr -> NumTxIdsToReq -> StrictSeq txid -> Map txid SizeInBytes -> m ()
- collectTxs :: forall m peeraddr tx txid. (MonadSTM m, Ord txid, Ord peeraddr, Show txid, Typeable txid) => Tracer m (TraceTxLogic peeraddr txid tx) -> (tx -> SizeInBytes) -> SharedTxStateVar m peeraddr txid tx -> peeraddr -> Map txid SizeInBytes -> Map txid tx -> m (Maybe TxSubmissionProtocolError)
- acknowledgeTxIds :: forall peeraddr tx txid. (Ord txid, HasCallStack) => TxDecisionPolicy -> SharedTxState peeraddr txid tx -> PeerTxState txid tx -> (NumTxIdsToAck, NumTxIdsToReq, TxsToMempool txid tx, RefCountDiff txid, PeerTxState txid tx)
- splitAcknowledgedTxIds :: (Ord txid, HasCallStack) => TxDecisionPolicy -> SharedTxState peer txid tx -> PeerTxState txid tx -> (NumTxIdsToReq, StrictSeq txid, StrictSeq txid)
- tickTimedTxs :: forall peeraddr tx txid. Ord txid => Time -> SharedTxState peeraddr txid tx -> SharedTxState peeraddr txid tx
- const_MAX_TX_SIZE_DISCREPENCY :: SizeInBytes
- newtype RefCountDiff txid = RefCountDiff {
- txIdsToAck :: Map txid Int
- updateRefCounts :: Ord txid => Map txid Int -> RefCountDiff txid -> Map txid Int
- receivedTxIdsImpl :: forall peeraddr tx txid. (Ord txid, Ord peeraddr, HasCallStack) => (txid -> Bool) -> peeraddr -> NumTxIdsToReq -> StrictSeq txid -> Map txid SizeInBytes -> SharedTxState peeraddr txid tx -> SharedTxState peeraddr txid tx
- collectTxsImpl :: forall peeraddr tx txid. (Ord peeraddr, Ord txid, Show txid, Typeable txid) => (tx -> SizeInBytes) -> peeraddr -> Map txid SizeInBytes -> Map txid tx -> SharedTxState peeraddr txid tx -> Either TxSubmissionProtocolError (SharedTxState peeraddr txid tx)
Core API
data SharedTxState peeraddr txid tx Source #
Shared state of all TxSubmission
clients.
New txid
enters unacknowledgedTxIds
it is also added to availableTxIds
and referenceCounts
(see acknowledgeTxIdsImpl
).
When a txid
id is selected to be downloaded, it's added to
requestedTxsInflightSize
(see
pickTxsToDownload
).
When the request arrives, the txid
is removed from inflightTxs
. It
might be added to unknownTxs
if the server didn't have that txid
, or
it's added to bufferedTxs
(see collectTxsImpl
).
Whenever we choose txid
to acknowledge (either in acknowledtxsIdsImpl
,
collectTxsImpl
or
pickTxsToDownload
, we also
recalculate referenceCounts
and only keep live txid
s in other maps (e.g.
availableTxIds
, bufferedTxs
, unknownTxs
).
Constructors
SharedTxState | |
Fields
|
Instances
data PeerTxState txid tx Source #
Constructors
PeerTxState | |
Fields
|
Instances
type SharedTxStateVar (m :: Type -> Type) peeraddr txid tx = StrictTVar m (SharedTxState peeraddr txid tx) Source #
newSharedTxStateVar :: MonadSTM m => StdGen -> m (SharedTxStateVar m peeraddr txid tx) Source #
Arguments
:: forall m peeraddr idx tx txid. (MonadSTM m, Ord txid, Ord peeraddr) | |
=> Tracer m (TraceTxLogic peeraddr txid tx) | |
-> SharedTxStateVar m peeraddr txid tx | |
-> STM m (MempoolSnapshot txid tx idx) | |
-> peeraddr | |
-> NumTxIdsToReq | number of requests to subtract from
|
-> StrictSeq txid | sequence of received |
-> Map txid SizeInBytes | received |
-> m () |
Acknowledge txid
s, return the number of txids
to be acknowledged to the
remote side.
Arguments
:: forall m peeraddr tx txid. (MonadSTM m, Ord txid, Ord peeraddr, Show txid, Typeable txid) | |
=> Tracer m (TraceTxLogic peeraddr txid tx) | |
-> (tx -> SizeInBytes) | |
-> SharedTxStateVar m peeraddr txid tx | |
-> peeraddr | |
-> Map txid SizeInBytes | set of requested txids with their announced size |
-> Map txid tx | received txs |
-> m (Maybe TxSubmissionProtocolError) | number of txids to be acknowledged and txs to be added to the mempool |
Include received tx
s in SharedTxState
. Return number of txids
to be acknowledged and list of tx
to be added to the mempool.
Arguments
:: forall peeraddr tx txid. (Ord txid, HasCallStack) | |
=> TxDecisionPolicy | |
-> SharedTxState peeraddr txid tx | |
-> PeerTxState txid tx | |
-> (NumTxIdsToAck, NumTxIdsToReq, TxsToMempool txid tx, RefCountDiff txid, PeerTxState txid tx) | number of txid to acknowledge, requests, txs which we can submit to the mempool, txids to acknowledge with multiplicities, updated PeerTxState. |
splitAcknowledgedTxIds Source #
Arguments
:: (Ord txid, HasCallStack) | |
=> TxDecisionPolicy | |
-> SharedTxState peer txid tx | |
-> PeerTxState txid tx | |
-> (NumTxIdsToReq, StrictSeq txid, StrictSeq txid) | number of txids to request, acknowledged txids, unacknowledged txids |
Split unacknowledged txids into acknowledged and unacknowledged parts, also return number of txids which can be requested.
tickTimedTxs :: forall peeraddr tx txid. Ord txid => Time -> SharedTxState peeraddr txid tx -> SharedTxState peeraddr txid tx Source #
const_MAX_TX_SIZE_DISCREPENCY :: SizeInBytes Source #
We check advertised sizes up in a fuzzy way. The advertised and received
sizes need to agree up to const_MAX_TX_SIZE_DISCREPENCY
.
Internals, only exported for testing purposes:
newtype RefCountDiff txid Source #
RefCountDiff
represents a map of txid
which can be acknowledged
together with their multiplicities.
Constructors
RefCountDiff | |
Fields
|
updateRefCounts :: Ord txid => Map txid Int -> RefCountDiff txid -> Map txid Int Source #
Arguments
:: forall peeraddr tx txid. (Ord txid, Ord peeraddr, HasCallStack) | |
=> (txid -> Bool) | check if txid is in the mempool, ref
|
-> peeraddr | |
-> NumTxIdsToReq | number of requests to subtract from
|
-> StrictSeq txid | sequence of received |
-> Map txid SizeInBytes | received |
-> SharedTxState peeraddr txid tx | |
-> SharedTxState peeraddr txid tx |
Insert received txid
s and return the number of txids to be acknowledged
and the updated SharedTxState
.
Arguments
:: forall peeraddr tx txid. (Ord peeraddr, Ord txid, Show txid, Typeable txid) | |
=> (tx -> SizeInBytes) | compute tx size |
-> peeraddr | |
-> Map txid SizeInBytes | requested txids |
-> Map txid tx | received txs |
-> SharedTxState peeraddr txid tx | |
-> Either TxSubmissionProtocolError (SharedTxState peeraddr txid tx) | Return list of |