ouroboros-network-mock
Safe HaskellNone
LanguageHaskell2010

Ouroboros.Network.Mock.ProducerState

Synopsis

Documentation

data ChainProducerState block Source #

Instances

Instances details
(StandardHash block, Show block) => Show (ChainProducerState block) Source # 
Instance details

Defined in Ouroboros.Network.Mock.ProducerState

(StandardHash block, Eq block) => Eq (ChainProducerState block) Source # 
Instance details

Defined in Ouroboros.Network.Mock.ProducerState

type FollowerStates block = Map FollowerId (FollowerState block) Source #

Followers are represented here as a relation.

data FollowerState block Source #

Producer keeps track of consumer chain. The only information for a producer to know is

  • followerPoint: (some) intersection point of consumer's chain and producer's chain;
  • followerNext: information what to do on next instruction: either roll forward from the intersection point or roll back to it.

The second piece of information is needed to distinguish the following two cases:

  • consumer chain is a subchain of the producer chain
  • it is a fork.

Since consumer is following the producer chain, the producer has this information at its end. If producer updates its chain to use another fork it may happen that the follower pointer is not on the new chain. In this case the producer will set RollBackTo and find intersection of the two chains for followerPoint. And upon consumer's request will replay with MsgRollBackward followerPoint. After sending this message, the producer assumes that the the consumer is following the protocol (i.e. will rollback its chain) and will reset the followerNext field to FollowerForwardFrom. The second case: when the followerNext is FollowerForwardFrom, then when sending next instruction the producer will either:

  • take the next block (or header) on its chain imediatelly folowing the followerPoint, updtate followerPoint to the point of the new value and send MsgRollForward with the new block (or header).
  • if there is no block, which means that the consumer side and producer side are synchornized, the producer will send MsgAwaitResponse and will wait until its chain is updated: either by a fork or by a new block.

In this implementation a map from FollowerId to FollowerState is shared between all producers running on a single node; hence the unique identifier FollowerId for each follower: this is an implementation detail.

Constructors

FollowerState 

Fields

  • followerPoint :: Point block

    Where the chain of the consumer and producer intersect. If the consumer is on the chain then this is the consumer's chain head, but if the consumer's chain is off the producer's chain then this is the point the consumer will need to rollback to.

  • followerNext :: FollowerNext

    Where the will go next, roll back to the follower point, or roll forward from the follower point.

Instances

Instances details
StandardHash block => Show (FollowerState block) Source # 
Instance details

Defined in Ouroboros.Network.Mock.ProducerState

Methods

showsPrec :: Int -> FollowerState block -> ShowS #

show :: FollowerState block -> String #

showList :: [FollowerState block] -> ShowS #

StandardHash block => Eq (FollowerState block) Source # 
Instance details

Defined in Ouroboros.Network.Mock.ProducerState

Methods

(==) :: FollowerState block -> FollowerState block -> Bool #

(/=) :: FollowerState block -> FollowerState block -> Bool #

initChainProducerState :: Chain block -> ChainProducerState block Source #

Initialise ChainProducerState with a given Chain and empty list of followers.

lookupFollower :: ChainProducerState block -> FollowerId -> FollowerState block Source #

Get the recorded state of a chain consumer. The FollowerId is assumed to exist.

followerExists :: FollowerId -> ChainProducerState block -> Bool Source #

Return True when a follower with the given FollowerId exists.

findFirstPoint :: HasHeader block => [Point block] -> ChainProducerState block -> Maybe (Point block) Source #

initFollower :: HasHeader block => Point block -> ChainProducerState block -> (ChainProducerState block, FollowerId) Source #

Add a new follower with the given intersection point and return the new FollowerId.

deleteFollower :: FollowerId -> ChainProducerState block -> ChainProducerState block Source #

Delete an existing follower. The FollowerId is assumed to exist.

updateFollower Source #

Arguments

:: HasHeader block 
=> FollowerId 
-> Point block

new follower intersection point

-> ChainProducerState block 
-> ChainProducerState block 

Change the intersection point of a follower. This also puts it into the FollowerBackTo state.

switchFork :: HasHeader block => Chain block -> ChainProducerState block -> ChainProducerState block Source #

Switch chains and update followers; if a follower point falls out of the chain, replace it with the intersection of both chains and put it in the FollowerBackTo state, otherwise preserve follower state.

followerInstruction :: HasHeader block => FollowerId -> ChainProducerState block -> Maybe (ChainUpdate block block, ChainProducerState block) Source #

What a follower needs to do next. Should they move on to the next block or do they need to roll back to a previous point on their chain. It also updates the producer's state assuming that the follower follows its instruction.

addBlock :: HasHeader block => block -> ChainProducerState block -> ChainProducerState block Source #

Add a block to the chain. It does not require any follower's state changes.

rollback :: (HasHeader block, HeaderHash block ~ HeaderHash block') => Point block' -> ChainProducerState block -> Maybe (ChainProducerState block) Source #

Rollback producer chain. It requires to update follower states, since some followerPoints may not be on the new chain; in this case find intersection of the two chains and set followerNext to FollowerBackTo.

applyChainUpdate :: (HasHeader block, HeaderHash block ~ HeaderHash block') => ChainUpdate block' block -> ChainProducerState block -> Maybe (ChainProducerState block) Source #

Convenient function which combines both addBlock and rollback.

applyChainUpdates :: (HasHeader block, HeaderHash block ~ HeaderHash block') => [ChainUpdate block' block] -> ChainProducerState block -> Maybe (ChainProducerState block) Source #

Apply a list of ChainUpdates.