| Safe Haskell | None |
|---|---|
| Language | Haskell2010 |
Test.Ouroboros.Network.TxSubmission.Impaired
Description
Test-only impairment shims for TxSubmissionClient. They wrap an
existing outbound peer with behavioural faults at the typed-protocol
level: delayBodies adds latency to body replies, omitBodies drops
bodies probabilistically. Both pass txid replies through unchanged so
the impaired peer still advertises promptly.
The wrappers are polymorphic in txid and tx and depend only on the
TxSubmission2 client types.
Synopsis
- delayBodies :: forall txid tx (m :: Type -> Type) a. MonadDelay m => DiffTime -> TxSubmissionClient txid tx m a -> TxSubmissionClient txid tx m a
- omitBodies :: forall txid tx (m :: Type -> Type) a. MonadSTM m => StrictTVar m StdGen -> Double -> TxSubmissionClient txid tx m a -> TxSubmissionClient txid tx m a
- extraTxIds :: forall txid tx (m :: Type -> Type) a. Monad m => Word16 -> TxSubmissionClient txid tx m a -> TxSubmissionClient txid tx m a
- unrequestedTx :: forall txid tx (m :: Type -> Type) a. Monad m => ([txid] -> tx -> tx) -> TxSubmissionClient txid tx m a -> TxSubmissionClient txid tx m a
- data Impairment = Impairment {}
- noImpairment :: Impairment
- validImpairment :: Impairment -> Bool
- applyImpairment :: (MonadDelay m, MonadSTM m) => Impairment -> ([txid] -> tx -> tx) -> TxSubmissionClient txid tx m a -> m (TxSubmissionClient txid tx m a)
- genOneImpairment :: Gen Impairment
- shrinkImpairment :: Impairment -> [Impairment]
- kindOf :: Impairment -> String
Documentation
delayBodies :: forall txid tx (m :: Type -> Type) a. MonadDelay m => DiffTime -> TxSubmissionClient txid tx m a -> TxSubmissionClient txid tx m a Source #
Add a fixed delay before every MsgReplyTxs (body reply); txid
replies pass through unchanged. Models a peer that advertises promptly
but is slow to deliver bodies.
The wrapper is recursive: every ClientStIdle continuation produced
by the inner peer is wrapped in turn, so the delay applies to every
body reply through the protocol session - not just the first.
Arguments
| :: forall txid tx (m :: Type -> Type) a. MonadSTM m | |
| => StrictTVar m StdGen | |
| -> Double | drop probability for each body, in [0, 1] |
| -> TxSubmissionClient txid tx m a | |
| -> TxSubmissionClient txid tx m a |
Drop each body in MsgReplyTxs independently with the given
probability; txid replies pass through unchanged. Models a peer whose
mempool evicts entries between advertise and fetch - the receiver sees
a body list that is a subset of what it requested.
Randomness is threaded through a StrictTVar so the test can seed it
from a QuickCheck-generated value and produce reproducible drop
patterns. Each body is decided independently.
Recursive in the same way as delayBodies.
extraTxIds :: forall txid tx (m :: Type -> Type) a. Monad m => Word16 -> TxSubmissionClient txid tx m a -> TxSubmissionClient txid tx m a Source #
Pad each non-empty MsgReplyTxIds reply so the total length is at
least req + n, where req is the count the inbound asked for.
Padding entries are duplicates of the first reply entry. Replies that
are already empty pass through unchanged.
Triggers ProtocolErrorTxIdsNotRequested on the inbound side as soon
as n > 0.
unrequestedTx :: forall txid tx (m :: Type -> Type) a. Monad m => ([txid] -> tx -> tx) -> TxSubmissionClient txid tx m a -> TxSubmissionClient txid tx m a Source #
Append a fabricated body to each non-empty MsgReplyTxs whose txid
is not in the corresponding request list. Models a peer that replies
with bodies that were never asked for.
Triggers ProtocolErrorTxNotRequested on the inbound side. The
fabricated body is produced by mkBad reqs orig where orig is the
first legitimate body in the reply (used as a template).
data Impairment Source #
Behavioural fault injection on a peer's outbound TxSubmissionClient.
Peers configured with noImpairment run unwrapped.
Constructors
| Impairment | |
Fields
| |
Instances
| Show Impairment Source # | |
Defined in Test.Ouroboros.Network.TxSubmission.Impaired Methods showsPrec :: Int -> Impairment -> ShowS # show :: Impairment -> String # showList :: [Impairment] -> ShowS # | |
| Eq Impairment Source # | |
Defined in Test.Ouroboros.Network.TxSubmission.Impaired | |
noImpairment :: Impairment Source #
The neutral impairment: no delay, no omission. Equivalent to running the client unwrapped.
validImpairment :: Impairment -> Bool Source #
The invariants the Arbitrary generator and shrinkImpairment must
preserve: the omission probability is in [0, 1] and any body delay is
strictly positive. The seed, the duplicate count (impairExtraTxIds is
a Word16, so always non-negative) and the unrequested-tx flag are
unconstrained.
applyImpairment :: (MonadDelay m, MonadSTM m) => Impairment -> ([txid] -> tx -> tx) -> TxSubmissionClient txid tx m a -> m (TxSubmissionClient txid tx m a) Source #
Wrap a TxSubmissionClient with the given Impairment. Allocates a
per-peer StdGen TVar only when the omission rate is non-zero. The
mkBad argument is consulted only when impairUnrequestedTx is set;
it produces a body whose txid is not in the request list.
genOneImpairment :: Gen Impairment Source #
Generate a single Impairment: a mix of body delay, per-body
omission, txid overflow, or unrequested body injection.
shrinkImpairment :: Impairment -> [Impairment] Source #
Shrink an Impairment towards noImpairment.
kindOf :: Impairment -> String Source #
A short label classifying an Impairment, for test labelling.