Safe Haskell | None |
---|---|
Language | Haskell2010 |
Synopsis
-
data
ChainProducerState
block =
ChainProducerState
{
- chainState :: Chain block
- chainFollowers :: FollowerStates block
- nextFollowerId :: FollowerId
- type FollowerStates block = Map FollowerId ( FollowerState block)
- type FollowerId = Int
-
data
FollowerState
block =
FollowerState
{
- followerPoint :: Point block
- followerNext :: FollowerNext
- data FollowerNext
- invChainProducerState :: HasFullHeader block => ChainProducerState block -> Bool
- invFollowerStates :: HasHeader block => Chain block -> FollowerStates block -> Bool
- initChainProducerState :: Chain block -> ChainProducerState block
- lookupFollower :: ChainProducerState block -> FollowerId -> FollowerState block
- followerExists :: FollowerId -> ChainProducerState block -> Bool
- producerChain :: ChainProducerState block -> Chain block
- findFirstPoint :: HasHeader block => [ Point block] -> ChainProducerState block -> Maybe ( Point block)
- initFollower :: HasHeader block => Point block -> ChainProducerState block -> ( ChainProducerState block, FollowerId )
- deleteFollower :: FollowerId -> ChainProducerState block -> ChainProducerState block
- updateFollower :: HasHeader block => FollowerId -> Point block -> ChainProducerState block -> ChainProducerState block
- switchFork :: HasHeader block => Chain block -> ChainProducerState block -> ChainProducerState block
- followerInstruction :: HasHeader block => FollowerId -> ChainProducerState block -> Maybe ( ChainUpdate block block, ChainProducerState block)
- addBlock :: HasHeader block => block -> ChainProducerState block -> ChainProducerState block
- rollback :: ( HasHeader block, HeaderHash block ~ HeaderHash block') => Point block' -> ChainProducerState block -> Maybe ( ChainProducerState block)
- applyChainUpdate :: ( HasHeader block, HeaderHash block ~ HeaderHash block') => ChainUpdate block' block -> ChainProducerState block -> Maybe ( ChainProducerState block)
- applyChainUpdates :: ( HasHeader block, HeaderHash block ~ HeaderHash block') => [ ChainUpdate block' block] -> ChainProducerState block -> Maybe ( ChainProducerState block)
Documentation
data ChainProducerState block Source #
ChainProducerState | |
|
Instances
( StandardHash block, Eq block) => Eq ( ChainProducerState block) Source # | |
Defined in Ouroboros.Network.MockChain.ProducerState (==) :: ChainProducerState block -> ChainProducerState block -> Bool Source # (/=) :: ChainProducerState block -> ChainProducerState block -> Bool Source # |
|
( StandardHash block, Show block) => Show ( ChainProducerState block) Source # | |
Defined in Ouroboros.Network.MockChain.ProducerState |
type FollowerStates block = Map FollowerId ( FollowerState block) Source #
Followers are represented here as a relation.
type FollowerId = Int Source #
data FollowerState block Source #
Producer keeps track of consumer chain. The only information for a producer
to know is
*
: (some) intersection point of consumer's chain and
producer's chain;
*
followerPoint
: information what to do on next instruction: either roll
forward from the intersection point or roll back to it.
followerNext
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
and find intersection of the two chains for
RollBackTo
. And upon consumer's request will replay with
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
MsgRollBackward
followerPoint
field to
followerNext
.
The second case: when the
FollowerForwardFrom
is
followerNext
, then when
sending next instruction the producer will either:
FollowerForwardFrom
-
take the next block (or header) on its chain imediatelly folowing the
followerPoint
followerPoint
MsgRollForward
-
if there is no block, which means that the consumer side and producer
side are synchornized, the producer will send
MsgAwaitResponse
In this implementation a map from
to
FollowerId
is shared
between all producers running on a single node; hence the unique identifier
FollowerState
for each follower: this is an implementation detail.
FollowerId
FollowerState | |
|
Instances
StandardHash block => Eq ( FollowerState block) Source # | |
Defined in Ouroboros.Network.MockChain.ProducerState (==) :: FollowerState block -> FollowerState block -> Bool Source # (/=) :: FollowerState block -> FollowerState block -> Bool Source # |
|
StandardHash block => Show ( FollowerState block) Source # | |
Defined in Ouroboros.Network.MockChain.ProducerState |
data FollowerNext Source #
Instances
Eq FollowerNext Source # | |
Defined in Ouroboros.Network.MockChain.ProducerState (==) :: FollowerNext -> FollowerNext -> Bool Source # (/=) :: FollowerNext -> FollowerNext -> Bool Source # |
|
Show FollowerNext Source # | |
Defined in Ouroboros.Network.MockChain.ProducerState |
invChainProducerState :: HasFullHeader block => ChainProducerState block -> Bool Source #
invFollowerStates :: HasHeader block => Chain block -> FollowerStates block -> Bool Source #
initChainProducerState :: Chain block -> ChainProducerState block Source #
Initialise
with a given
ChainProducerState
and empty list of
followers.
Chain
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.
producerChain :: ChainProducerState block -> Chain block Source #
Extract
from
Chain
.
ChainProducerState
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.
:: 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
s may not be on the new chain; in this case find intersection
of the two chains and set
followerPoint
to
followerNext
.
FollowerBackTo
applyChainUpdate :: ( HasHeader block, HeaderHash block ~ HeaderHash block') => ChainUpdate block' block -> ChainProducerState block -> Maybe ( ChainProducerState block) Source #
applyChainUpdates :: ( HasHeader block, HeaderHash block ~ HeaderHash block') => [ ChainUpdate block' block] -> ChainProducerState block -> Maybe ( ChainProducerState block) Source #
Apply a list of
s.
ChainUpdate