consensus-test
Safe HaskellSafe-Inferred
LanguageHaskell2010

Test.Consensus.PointSchedule.SinglePeer

Description

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

Documentation

data IsTrunk Source #

Constructors

IsTrunk 
IsBranch 

Instances

Instances details
Arbitrary IsTrunk Source # 
Instance details

Defined in Test.Consensus.PointSchedule.Tests

Show IsTrunk Source # 
Instance details

Defined in Test.Consensus.PointSchedule.SinglePeer

Methods

showsPrecIntIsTrunkShowS #

showIsTrunkString #

showList ∷ [IsTrunk] → ShowS #

Eq IsTrunk Source # 
Instance details

Defined in Test.Consensus.PointSchedule.SinglePeer

Methods

(==)IsTrunkIsTrunkBool #

(/=)IsTrunkIsTrunkBool #

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.

Constructors

PeerScheduleParams 

Fields

  • pspSlotLengthDiffTime
     
  • pspTipDelayInterval ∷ (DiffTime, DiffTime)

    Each of these pairs specifies a range of delays for a point. The actual delay is chosen uniformly at random from the range.

    For tip points, the delay is relative to the slot of the tip point.

  • pspHeaderDelayInterval ∷ (DiffTime, DiffTime)

    For header points, the delay is relative to the previous header point or the tip point that advertises the existence of the header (whichever happened most recently).

  • pspBlockDelayInterval ∷ (DiffTime, DiffTime)

    For block points, the delay is relative to the previous block point or the header point that advertises the existence of the block (whichever happened most recently).

data SchedulePoint blk Source #

A point in the schedule of a single peer.

Instances

Instances details
Show blk ⇒ Show (SchedulePoint blk) Source # 
Instance details

Defined in Test.Consensus.PointSchedule.SinglePeer

Methods

showsPrecIntSchedulePoint blk → ShowS #

showSchedulePoint blk → String #

showList ∷ [SchedulePoint blk] → ShowS #

Eq blk ⇒ Eq (SchedulePoint blk) Source # 
Instance details

Defined in Test.Consensus.PointSchedule.SinglePeer

Methods

(==)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.

singleJumpPeerSchedule ∷ (StatefulGen g m, HasHeader blk) ⇒ g → PeerScheduleParamsAnchoredFragment 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

mergeOnOrd b ⇒ (a → b) → [a] → [a] → [a] Source #

Merge two sorted lists.

PRECONDITION: The lists are sorted.

zipMany ∷ [a] → [[b]] → [[(a, b)]] Source #