Safe Haskell | Safe-Inferred |
---|---|
Language | Haskell2010 |
This module contains functions for generating random point schedules.
A point schedule is a set of tables, having one table per simulated peer. Each row of a table correspond to a point in time, also called a tick.
Each tick has a timestamp and a state to set for the corresponding peer at that time. The state of each peer is described by three blocks points related to the peer's hypothetical chain selection:
- Tip Point: the tip of the hypothetical chain selection. This tip is advertised to the node under test in ChainSync client exchanges.
- Header Point: the most recent header that the peer should send to the node under test. Any newer headers should wait until the Header Point is updated to newer headers.
- Block Point: the most recent block that the peer should send to the node under test. Any newer blocks should wait until the Block Point is updated to newer headers.
Given a chain selection like this:
Genesis -> A -> B -> C -> D
The point schedule of a peer might look like this:
+--------+----------------+----------------+----------------+ | Tick | Tip Point | Header Point | Block Point | +--------+----------------+----------------+----------------+ | 0.0s | Genesis | Genesis | Genesis | +--------+----------------+----------------+----------------+ | 1.2s | D | Genesis | Genesis | +--------+----------------+----------------+----------------+ | 1.3s | D | C | Genesis | +--------+----------------+----------------+----------------+ | 1.6s | D | C | B | +--------+----------------+----------------+----------------+ | 2.0s | D | C | C | +--------+----------------+----------------+----------------+ | 2.2s | D | D | D | +--------+----------------+----------------+----------------+
Some rules apply to how the point schedule progresses, although exceptions might be tested occasionally. In general,
- The Tip Point is set first
- Header points are not allowed to point to newer blocks than the tip point
- Block points are not allowed to point to newer blocks than the header point
The following is an example with rollbacks:
Genesis -> A -> B -> C -> D \-> C' -> D' -> E
+--------+----------------+----------------+----------------+ | Tick | Tip Point | Header Point | Block Point | +--------+----------------+----------------+----------------+ | 0.0s | Genesis | Genesis | Genesis | +--------+----------------+----------------+----------------+ | 1.2s | D | Genesis | Genesis | +--------+----------------+----------------+----------------+ | 1.3s | D | C | Genesis | +--------+----------------+----------------+----------------+ | 1.6s | D | C | B | +--------+----------------+----------------+----------------+ | 2.0s | D | C | C | +--------+----------------+----------------+----------------+ | 2.1s | D | D | C | +--------+----------------+----------------+----------------+ | 2.3s | D | D | D | +--------+----------------+----------------+----------------+ | 2.4s | E | D | D | +--------+----------------+----------------+----------------+ | 2.6s | E | D' | D | +--------+----------------+----------------+----------------+ | 2.7s | E | D' | C' | +--------+----------------+----------------+----------------+ | 2.9s | E | D' | D' | +--------+----------------+----------------+----------------+ | 3.0s | E | E | D' | +--------+----------------+----------------+----------------+ | 3.1s | E | E | E | +--------+----------------+----------------+----------------+
Synopsis
- data IsTrunk
- data PeerScheduleParams = PeerScheduleParams {}
- data SchedulePoint blk
- = ScheduleTipPoint (WithOrigin blk)
- | ScheduleHeaderPoint (WithOrigin blk)
- | ScheduleBlockPoint (WithOrigin blk)
- defaultPeerScheduleParams ∷ PeerScheduleParams
- peerScheduleFromTipPoints ∷ (StatefulGen g m, HasHeader blk) ⇒ g → PeerScheduleParams → [(IsTrunk, [Int])] → AnchoredFragment blk → [AnchoredFragment blk] → m [(Time, SchedulePoint blk)]
- schedulePointToBlock ∷ SchedulePoint blk → WithOrigin blk
- singleJumpPeerSchedule ∷ (StatefulGen g m, HasHeader blk) ⇒ g → PeerScheduleParams → AnchoredFragment blk → m [(Time, SchedulePoint blk)]
- mergeOn ∷ Ord b ⇒ (a → b) → [a] → [a] → [a]
- scheduleBlockPoint ∷ blk → SchedulePoint blk
- scheduleHeaderPoint ∷ blk → SchedulePoint blk
- scheduleTipPoint ∷ blk → SchedulePoint blk
- zipMany ∷ [a] → [[b]] → [[(a, b)]]
Documentation
data PeerScheduleParams Source #
Parameters for generating a schedule for a single peer.
In the most general form, the caller provides a list of tip points and the schedule is generated by following the given tip points. All headers points and block points are sent eventually, but the points are delayed according to these parameters.
PeerScheduleParams | |
|
Instances
Show PeerScheduleParams Source # | |
Defined in Test.Consensus.PointSchedule.SinglePeer showsPrec ∷ Int → PeerScheduleParams → ShowS # show ∷ PeerScheduleParams → String # showList ∷ [PeerScheduleParams] → ShowS # |
data SchedulePoint blk Source #
A point in the schedule of a single peer.
ScheduleTipPoint (WithOrigin blk) | |
ScheduleHeaderPoint (WithOrigin blk) | |
ScheduleBlockPoint (WithOrigin blk) |
Instances
Show blk ⇒ Show (SchedulePoint blk) Source # | |
Defined in Test.Consensus.PointSchedule.SinglePeer showsPrec ∷ Int → SchedulePoint blk → ShowS # show ∷ SchedulePoint blk → String # showList ∷ [SchedulePoint blk] → ShowS # | |
Eq blk ⇒ Eq (SchedulePoint blk) Source # | |
Defined in Test.Consensus.PointSchedule.SinglePeer (==) ∷ SchedulePoint blk → SchedulePoint blk → Bool # (/=) ∷ SchedulePoint blk → SchedulePoint blk → Bool # |
peerScheduleFromTipPoints ∷ (StatefulGen g m, HasHeader blk) ⇒ g → PeerScheduleParams → [(IsTrunk, [Int])] → AnchoredFragment blk → [AnchoredFragment blk] → m [(Time, SchedulePoint blk)] Source #
peerScheduleFromTipPoints g params tps trunk branches
generates a
schedule for a single peer that follows the given tip points.
tps
contains the tip points for each fragment. The indices correspond to
the fragments in branches and go from 0
to length branch - 1
.
trunk
is the fragment for the honest chain
branches
contains the fragments for the alternative chains in ascending
order of their intersections with the honest chain. Each fragment is anchored
at the intersection, and therefore their first block must be the first block
after the intersection.
schedulePointToBlock ∷ SchedulePoint blk → WithOrigin blk Source #
singleJumpPeerSchedule ∷ (StatefulGen g m, HasHeader blk) ⇒ g → PeerScheduleParams → AnchoredFragment blk → m [(Time, SchedulePoint blk)] Source #
Generate a schedule for a single peer that jumps once to the middle of a sequence of blocks.
See peerScheduleFromTipPoints
for generation of schedules with rollbacks
Exposed for testing
mergeOn ∷ Ord b ⇒ (a → b) → [a] → [a] → [a] Source #
Merge two sorted lists.
PRECONDITION: The lists are sorted.
scheduleBlockPoint ∷ blk → SchedulePoint blk Source #
scheduleHeaderPoint ∷ blk → SchedulePoint blk Source #
scheduleTipPoint ∷ blk → SchedulePoint blk Source #