consensus-test
Safe HaskellSafe-Inferred
LanguageHaskell2010

Test.Consensus.PeerSimulator.Handlers

Description

Business logic of the ChainSync and BlockFetch protocol handlers that operate on the NodeState of a point schedule.

These are separated from the scheduling related mechanics of the server mocks that the peer simulator uses, in Test.Consensus.PeerSimulator.ScheduledChainSyncServer and Test.Consensus.PeerSimulator.ScheduledBlockFetchServer.

Synopsis

Documentation

handlerBlockFetch Source #

Arguments

∷ ∀ m blk. (IOLike m, HasHeader blk) 
BlockTree blk

The tree of blocks in this scenario -- aka. the “universe”.

ChainRange (Point blk)

A requested range of blocks. If the client behaves correctly, they correspond to headers that have been sent before, and if the scheduled ChainSync server behaves correctly, then they are all in the block tree.

NodeState blk

The current advertised points (tip point, header point and block point). They are in the block tree.

STM m (Maybe (BlockFetch blk), [TraceScheduledBlockFetchServerEvent (NodeState blk) blk]) 

Handle the BlockFetch message (it actually has only one unnamed entry point).

If the requested range ends not after the block point, send them. If the block point moved to a fork without serving all blocks corresponding to advertised headers, serve them. Otherwise, stall.

handlerFindIntersection ∷ (IOLike m, HasHeader blk) ⇒ StrictTVar m (Point blk) → BlockTree blk → [Point blk] → NodeState blk → STM m (Maybe (FindIntersect blk), [TraceScheduledChainSyncServerEvent (NodeState blk) blk]) Source #

Handle a MsgFindIntersect message.

Extracts the fragment up to the current advertised tip from the block tree, then searches for any of the client's points in it.

handlerRequestNext ∷ ∀ m. IOLike m ⇒ StrictTVar m (Point TestBlock) → BlockTree TestBlockNodeState TestBlockSTM m (Maybe (RequestNext TestBlock), [TraceScheduledChainSyncServerEvent (NodeState TestBlock) TestBlock]) Source #

Handle a MsgRequestNext message.

Finds the potential path from the current intersection to the advertised header point for this turn, which can have four distinct configurations for the anchor point and the path:

  • Anchor == intersection == header point
  • header point after intersection == header point
  • header point before intersection (special case for the point scheduler architecture)
  • Anchor != intersection