| Safe Haskell | None |
|---|---|
| Language | Haskell2010 |
Test.Ouroboros.Network.TxSubmission.TxLogic
Synopsis
- tests :: TestTree
- newtype ArbTxDecisionPolicy = ArbTxDecisionPolicy TxDecisionPolicy
- type PeerAddr = Int
- newtype ArbSharedTxState = ArbSharedTxState (SharedTxState PeerAddr TxId)
- newtype ArbPeerTxLocalState = ArbPeerTxLocalState (PeerTxLocalState (Tx TxId))
- data ReceiveDuplicateFixture
- data PeerActionFixture
- data FanoutFixture
- mkReceiveDuplicateFixture :: Int -> Int -> ReceiveDuplicateFixture
- mkResolvedAckFixture :: Int -> Int -> PeerActionFixture
- mkForeignRejectedFixture :: Int -> Int -> PeerActionFixture
- mkFanoutFixture :: Int -> Int -> FanoutFixture
- runReceiveDuplicateLoop :: Int -> ReceiveDuplicateFixture -> IO ()
- runPeerActionLoop :: Int -> PeerActionFixture -> IO ()
- runFanoutLoop :: Int -> FanoutFixture -> IO ()
- sharedTxStateInvariant :: (Ord peeraddr, Ord txid, HasRawTxId txid, Show peeraddr, Show txid) => SharedTxState peeraddr txid -> Property
- peerTxLocalStateInvariant :: NoThunks tx => TxDecisionPolicy -> PeerTxLocalState tx -> Property
- peerTxInFlightInvariant :: PeerTxInFlight -> Property
- combinedStateInvariant :: (Ord peeraddr, Ord txid, HasRawTxId txid, Show peeraddr, Show txid, NoThunks tx) => TxDecisionPolicy -> Map peeraddr (PeerTxLocalState tx, PeerTxInFlight) -> SharedTxState peeraddr txid -> Property
- combinedStateInvariantStep :: (Ord peeraddr, Ord txid, HasRawTxId txid, Show peeraddr, Show txid, NoThunks tx) => TxDecisionPolicy -> Map peeraddr (PeerTxLocalState tx, PeerTxInFlight) -> SharedTxState peeraddr txid -> SharedTxState peeraddr txid -> Property
- sharedGenerationBumpInvariant :: (Eq peeraddr, Eq txid, HasRawTxId txid) => SharedTxState peeraddr txid -> SharedTxState peeraddr txid -> Property
Documentation
newtype ArbTxDecisionPolicy Source #
Constructors
| ArbTxDecisionPolicy TxDecisionPolicy |
Instances
| Arbitrary ArbTxDecisionPolicy Source # | |
Defined in Test.Ouroboros.Network.TxSubmission.TxLogic Methods | |
| Show ArbTxDecisionPolicy Source # | |
Defined in Test.Ouroboros.Network.TxSubmission.TxLogic Methods showsPrec :: Int -> ArbTxDecisionPolicy -> ShowS # show :: ArbTxDecisionPolicy -> String # showList :: [ArbTxDecisionPolicy] -> ShowS # | |
| Eq ArbTxDecisionPolicy Source # | |
Defined in Test.Ouroboros.Network.TxSubmission.TxLogic Methods (==) :: ArbTxDecisionPolicy -> ArbTxDecisionPolicy -> Bool # (/=) :: ArbTxDecisionPolicy -> ArbTxDecisionPolicy -> Bool # | |
newtype ArbSharedTxState Source #
Constructors
| ArbSharedTxState (SharedTxState PeerAddr TxId) |
Instances
newtype ArbPeerTxLocalState Source #
Constructors
| ArbPeerTxLocalState (PeerTxLocalState (Tx TxId)) |
Instances
| Arbitrary ArbPeerTxLocalState Source # | |
Defined in Test.Ouroboros.Network.TxSubmission.TxLogic Methods | |
| Show ArbPeerTxLocalState Source # | |
Defined in Test.Ouroboros.Network.TxSubmission.TxLogic Methods showsPrec :: Int -> ArbPeerTxLocalState -> ShowS # show :: ArbPeerTxLocalState -> String # showList :: [ArbPeerTxLocalState] -> ShowS # | |
data ReceiveDuplicateFixture Source #
Instances
| NFData ReceiveDuplicateFixture Source # | |
Defined in Test.Ouroboros.Network.TxSubmission.TxLogic Methods rnf :: ReceiveDuplicateFixture -> () # | |
data PeerActionFixture Source #
Instances
| NFData PeerActionFixture Source # | |
Defined in Test.Ouroboros.Network.TxSubmission.TxLogic Methods rnf :: PeerActionFixture -> () # | |
data FanoutFixture Source #
Instances
| NFData FanoutFixture Source # | |
Defined in Test.Ouroboros.Network.TxSubmission.TxLogic Methods rnf :: FanoutFixture -> () # | |
mkResolvedAckFixture :: Int -> Int -> PeerActionFixture Source #
mkForeignRejectedFixture :: Int -> Int -> PeerActionFixture Source #
Compatibility alias for the previous benchmark helper name.
mkFanoutFixture :: Int -> Int -> FanoutFixture Source #
runReceiveDuplicateLoop :: Int -> ReceiveDuplicateFixture -> IO () Source #
runPeerActionLoop :: Int -> PeerActionFixture -> IO () Source #
runFanoutLoop :: Int -> FanoutFixture -> IO () Source #
sharedTxStateInvariant :: (Ord peeraddr, Ord txid, HasRawTxId txid, Show peeraddr, Show txid) => SharedTxState peeraddr txid -> Property Source #
InboundState invariant.
peerTxLocalStateInvariant :: NoThunks tx => TxDecisionPolicy -> PeerTxLocalState tx -> Property Source #
PeerTxLocalState invariant.
Consistency constraints between the peer-local bookkeeping maps:
- Every available or downloaded key is still tracked in the unacknowledged queue.
- Every requested key is also available (a key can only be requested while its advertised size is still known).
- Downloaded keys are disjoint from available and from requested (a key moves out of available/requested exactly when its body lands in downloaded).
peerRequestedTxsequals the union of allrequestedTxBatchSets andpeerRequestedTxsSizeequals the sum of all batch sizes.peerAdvertisedTxKeysis a subset of the unacknowledged queue (a peer can only advertise keys it has actually received and not yet acked).
peerTxInFlightInvariant :: PeerTxInFlight -> Property Source #
Per-peer PeerTxInFlight invariant.
A peer's attempting and submitting sets must be disjoint (a key is
in at most one phase per peer); pifLeased is a subset of their
union; and pifAdvertised is a subset of pifAcksPending (every
advertised key is still pending an ack).
combinedStateInvariant :: (Ord peeraddr, Ord txid, HasRawTxId txid, Show peeraddr, Show txid, NoThunks tx) => TxDecisionPolicy -> Map peeraddr (PeerTxLocalState tx, PeerTxInFlight) -> SharedTxState peeraddr txid -> Property Source #
Combined invariant over SharedTxState and a snapshot of every
live peer's (PeerTxLocalState, PeerTxInFlight).
Runs the per-piece invariants (peerTxLocalStateInvariant,
peerTxInFlightInvariant, sharedTxStateInvariant) and adds the
cross-state coherence constraints that need both shared and per-peer
views to express:
- Every key in any peer's
pifAdvertisedreferences an active entry or a retained one (never falls out of both). - Each entry's
txAttemptequals the number of peers in the map whosepifAttemptingcontains the key. - Each entry's
txInSubmissionis true iff some peer in the map has the key in itspifSubmitting. - If an entry is 'TxLeased peer _' and that peer is in the map,
the peer's
pifLeasedcontains the key. Stale leases (peer'spifLeasedhas a key that the entry no longer leases to them) are tolerated since theft via inflight-cap bumps does not proactively scrub the loser's set. - Each peer's
pifAcksPendingis a subset of the keys in itspeerUnacknowledgedTxIdsqueue.
Single-peer call sites pass a Map.singleton; multi-peer scenarios
pass the full schedule snapshot so the cross-peer counter checks
are exercised.
combinedStateInvariantStep Source #
Arguments
| :: (Ord peeraddr, Ord txid, HasRawTxId txid, Show peeraddr, Show txid, NoThunks tx) | |
| => TxDecisionPolicy | |
| -> Map peeraddr (PeerTxLocalState tx, PeerTxInFlight) | |
| -> SharedTxState peeraddr txid | before |
| -> SharedTxState peeraddr txid | after |
| -> Property |
Step-level variant of combinedStateInvariant: runs the standard
invariant on the after-state and adds the sharedGeneration bump
check across the step. Use at any call site where a pure transition
produces both a before and an after state.
sharedGenerationBumpInvariant Source #
Arguments
| :: (Eq peeraddr, Eq txid, HasRawTxId txid) | |
| => SharedTxState peeraddr txid | before |
| -> SharedTxState peeraddr txid | after |
| -> Property |
Cross-step invariant on shared state: any change to fields other
than the two counters (sharedGeneration and sharedRevision) must
advance at least one of them.
writeSharedStateIfChanged (Registry.hs) treats the pair as a dirty
bit: a pure transition whose new state matches the old on both
counters is silently dropped at commit time. Forgetting to bump
either counter in a transition that mutates shared state therefore
loses the update in production while still passing the structural
single-state sharedTxStateInvariant.
The check is one-directional: a counter may also bump when no other
field changed (e.g. handleReceivedTxs bumps unconditionally).
Spurious bumps only cost wake-ups and are not asserted against.