ouroboros-network:sim-tests-lib
Safe HaskellNone
LanguageHaskell2010

Ouroboros.Network.MockNode

Description

A mock (and naive) node implentation. It only implements the chain-sync protocol using the Chain module. The module is used to build tests on randomly generated graphs of nodes, see MockNoder.

A historical note: this was the very first node implemntation that pre-dates 'typed-protocols'.

Synopsis

Documentation

data NodeId Source #

Constructors

CoreId Int 
RelayId Int 

Instances

Instances details
Generic NodeId Source # 
Instance details

Defined in Ouroboros.Network.MockNode

Associated Types

type Rep NodeId 
Instance details

Defined in Ouroboros.Network.MockNode

type Rep NodeId = D1 ('MetaData "NodeId" "Ouroboros.Network.MockNode" "ouroboros-network-0.17.1.1-inplace-sim-tests-lib" 'False) (C1 ('MetaCons "CoreId" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Int)) :+: C1 ('MetaCons "RelayId" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Int)))

Methods

from :: NodeId -> Rep NodeId x #

to :: Rep NodeId x -> NodeId #

Show NodeId Source # 
Instance details

Defined in Ouroboros.Network.MockNode

Eq NodeId Source # 
Instance details

Defined in Ouroboros.Network.MockNode

Methods

(==) :: NodeId -> NodeId -> Bool #

(/=) :: NodeId -> NodeId -> Bool #

Ord NodeId Source # 
Instance details

Defined in Ouroboros.Network.MockNode

Hashable NodeId Source # 
Instance details

Defined in Ouroboros.Network.MockNode

Methods

hashWithSalt :: Int -> NodeId -> Int #

hash :: NodeId -> Int #

type Rep NodeId Source # 
Instance details

Defined in Ouroboros.Network.MockNode

type Rep NodeId = D1 ('MetaData "NodeId" "Ouroboros.Network.MockNode" "ouroboros-network-0.17.1.1-inplace-sim-tests-lib" 'False) (C1 ('MetaCons "CoreId" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Int)) :+: C1 ('MetaCons "RelayId" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Int)))

longestChainSelection :: (HasHeader block, MonadSTM m) => [StrictTVar m (Maybe (Chain block))] -> StrictTVar m (ChainProducerState block) -> m () Source #

State-full chain selection (ChainProducerState).

chainValidation :: (HasFullHeader block, MonadSTM m) => StrictTVar m (Chain block) -> StrictTVar m (Maybe (Chain block)) -> m () Source #

data NodeChannels (m :: Type -> Type) (block :: k) (tip :: k2) Source #

Simulated network channels for a given network node.

Constructors

NodeChannels 

Fields

Instances

Instances details
Monoid (NodeChannels m block tip) Source # 
Instance details

Defined in Ouroboros.Network.MockNode

Methods

mempty :: NodeChannels m block tip #

mappend :: NodeChannels m block tip -> NodeChannels m block tip -> NodeChannels m block tip #

mconcat :: [NodeChannels m block tip] -> NodeChannels m block tip #

Semigroup (NodeChannels m block tip) Source # 
Instance details

Defined in Ouroboros.Network.MockNode

Methods

(<>) :: NodeChannels m block tip -> NodeChannels m block tip -> NodeChannels m block tip #

sconcat :: NonEmpty (NodeChannels m block tip) -> NodeChannels m block tip #

stimes :: Integral b => b -> NodeChannels m block tip -> NodeChannels m block tip #

createOneWaySubscriptionChannels :: forall {k} {k2} (block :: k) (tip :: k2) m. (MonadSTM m, MonadDelay m, MonadTimer m) => DiffTime -> DiffTime -> m (NodeChannels m block tip, NodeChannels m block tip) Source #

Create channels n1 → n2, where n1 is a producer and n2 is the consumer.

createTwoWaySubscriptionChannels :: forall {k} {k2} (block :: k) (tip :: k2) m. (MonadDelay m, MonadSTM m, MonadTimer m) => DiffTime -> DiffTime -> m (NodeChannels m block tip, NodeChannels m block tip) Source #

Create channels for n1 ↔ n2 where both nodes are a consumer and a producer simultaneously.

blockGenerator Source #

Arguments

:: (HasHeader block, MonadDelay m, MonadSTM m, MonadFork m, MonadTimer m) 
=> DiffTime

slot duration

-> [block]

The list of blocks to generate in increasing slot order. This allows for upstream users to generate "half chains" in case we want to simulate nodes having access to already part of the overall chain.

-> m (STM m (Maybe block))

returns an stm transaction which returns block. Nothing signifies that there will be no more blocks. It is the caller responsibility to read this transaction untill Nothing is returned.

Generate a block from a given chain. Each block is produced at slotDuration * blockSlot block time.

observeChainProducerState :: forall m block. (HasHeader block, MonadSTM m) => NodeId -> StrictTVar m [(NodeId, Chain block)] -> StrictTVar m (ChainProducerState block) -> m () Source #

Observe StrictTVar (ChainProducerState block), and whenever the StrictTVar mutates, write the result to the supplied Probe.

forkRelayKernel Source #

Arguments

:: (HasFullHeader block, MonadSTM m, MonadFork m) 
=> [StrictTVar m (Chain block)]

These will track the upstream producers.

-> StrictTVar m (ChainProducerState block)

This is tracking the current node and the downstream.

-> m () 

Relay node, which takes NodeChannels to communicate with its peers (upstream and downstream). If it is subscribed to n nodes and has m subscriptions, it will run n consumer end protocols which listen for updates; verify chains and select the longest one and feed it to the producer side which sends updates to its m subscribers.

The main thread of the relayNode is not blocking; it will return StrictTVar (ChainProducerState block). This allows to extend the relay node to a core node.

relayNode :: (MonadSTM m, MonadFork m, MonadTimer m, MonadThrow m, MonadSay m, HasFullHeader block, Show block, ShowProxy block) => NodeId -> Chain block -> NodeChannels m block (Tip block) -> m (StrictTVar m (ChainProducerState block)) Source #

Relay node, which takes NodeChannels to communicate with its peers (upstream and downstream). If it is subscribed to n nodes and has m subscriptions, it will run n consumer end protocols which listen for updates; verify chains and select the longest one and feed it to the producer side which sends updates to its m subscribers.

The main thread of the relayNode is not blocking; it will return StrictTVar (ChainProducerState block). This allows to extend the relay node to a core node.

forkCoreKernel Source #

Arguments

:: (HasFullHeader block, MonadDelay m, MonadSTM m, MonadFork m, MonadTimer m) 
=> DiffTime

slot duration

-> [block]

Blocks to produce (in order they should be produced)

-> (Chain block -> block -> block) 
-> StrictTVar m (ChainProducerState block) 
-> m () 

Core node simulation. Given a chain it will generate a block at its slot time (i.e. slotDuration * blockSlot block). When the node finds out that the slot for which it was supposed to generate a block was already occupied, it will replace it with its block.

TODO: This should not take a list of blocks, but rather a monadic action to generate the blocks. At that point the fixup argument can go also. Alternatively, we should move this to the tests, and remove it from the public network layer altogether.

coreNode Source #

Arguments

:: (MonadDelay m, MonadSTM m, MonadFork m, MonadThrow m, MonadTimer m, MonadSay m) 
=> NodeId 
-> DiffTime

slot duration

-> [Block] 
-> NodeChannels m Block (Tip Block) 
-> m (StrictTVar m (ChainProducerState Block)) 

Core node simulation. Given a chain it will generate a block at its slot time (i.e. slotDuration * blockSlot block). When the node finds out that the slot for which it was supposed to generate a block was already occupied, it will replace it with its block.