ouroboros-network-0.1.0.0: A networking layer for the Ouroboros blockchain protocol
Safe HaskellNone
LanguageHaskell2010

Ouroboros.Network.MockChain.Chain

Description

Reference implementation of a representation of a block chain

Synopsis

Chain type and fundamental operations

data Chain block Source #

Constructors

Genesis 
(Chain block) :> block infixl 5 

Instances

Instances details
Functor Chain Source # 
Instance details

Defined in Ouroboros.Network.MockChain.Chain

Methods

fmap ∷ (a → b) → Chain a → Chain b Source #

(<$) ∷ a → Chain b → Chain a Source #

Eq block ⇒ Eq (Chain block) Source # 
Instance details

Defined in Ouroboros.Network.MockChain.Chain

Methods

(==)Chain block → Chain block → Bool Source #

(/=)Chain block → Chain block → Bool Source #

Ord block ⇒ Ord (Chain block) Source # 
Instance details

Defined in Ouroboros.Network.MockChain.Chain

Methods

compareChain block → Chain block → Ordering Source #

(<)Chain block → Chain block → Bool Source #

(<=)Chain block → Chain block → Bool Source #

(>)Chain block → Chain block → Bool Source #

(>=)Chain block → Chain block → Bool Source #

maxChain block → Chain block → Chain block Source #

minChain block → Chain block → Chain block Source #

Show block ⇒ Show (Chain block) Source # 
Instance details

Defined in Ouroboros.Network.MockChain.Chain

Methods

showsPrecIntChain block → ShowS Source #

showChain block → String Source #

showList ∷ [Chain block] → ShowS Source #

Serialise block ⇒ Serialise (Chain block) Source # 
Instance details

Defined in Ouroboros.Network.MockChain.Chain

Methods

encodeChain block → Encoding #

decode ∷ Decoder s (Chain block) #

encodeList ∷ [Chain block] → Encoding #

decodeList ∷ Decoder s [Chain block] #

validHasFullHeader block ⇒ Chain block → Bool Source #

validExtension ∷ (HasCallStack, HasFullHeader block) ⇒ Chain block → block → Bool Source #

foldChain ∷ (a → b → a) → a → Chain b → a Source #

chainToListChain block → [block] Source #

Make a list from a Chain, in newest-to-oldest order.

Block re-exports

class (StandardHash b, Typeable b) ⇒ HasHeader b where Source #

Abstract over the shape of blocks (or indeed just block headers)

type family HeaderHash b ∷ Type Source #

Header hash

Instances

Instances details
type HeaderHash BlockHeader Source # 
Instance details

Defined in Ouroboros.Network.Testing.ConcreteBlock

type HeaderHash Block Source # 
Instance details

Defined in Ouroboros.Network.Testing.ConcreteBlock

type HeaderHash (Serialised block) Source # 
Instance details

Defined in Ouroboros.Network.Block

type HeaderHash (Serialised block) = HeaderHash block
type HeaderHash (HeaderFields b) Source # 
Instance details

Defined in Ouroboros.Network.Block

Point type

newtype Point block Source #

A point on the chain is identified by its Slot and HeaderHash.

The Slot tells us where to look and the HeaderHash either simply serves as a check, or in some contexts it disambiguates blocks from different forks that were in the same slot.

It's a newtype rather than a type synonym, because using a type synonym would lead to ambiguity, since HeaderHash is a non-injective type family.

Constructors

Point 

Fields

Instances

Instances details
StandardHash block ⇒ Eq (Point block) Source # 
Instance details

Defined in Ouroboros.Network.Block

Methods

(==)Point block → Point block → Bool Source #

(/=)Point block → Point block → Bool Source #

StandardHash block ⇒ Ord (Point block) Source # 
Instance details

Defined in Ouroboros.Network.Block

Methods

comparePoint block → Point block → Ordering Source #

(<)Point block → Point block → Bool Source #

(<=)Point block → Point block → Bool Source #

(>)Point block → Point block → Bool Source #

(>=)Point block → Point block → Bool Source #

maxPoint block → Point block → Point block Source #

minPoint block → Point block → Point block Source #

StandardHash block ⇒ Show (Point block) Source # 
Instance details

Defined in Ouroboros.Network.Block

Methods

showsPrecIntPoint block → ShowS Source #

showPoint block → String Source #

showList ∷ [Point block] → ShowS Source #

Generic (Point block) Source # 
Instance details

Defined in Ouroboros.Network.Block

Associated Types

type Rep (Point block) ∷ TypeType Source #

Methods

fromPoint block → Rep (Point block) x Source #

toRep (Point block) x → Point block Source #

Serialise (HeaderHash block) ⇒ Serialise (Point block) Source # 
Instance details

Defined in Ouroboros.Network.Block

Methods

encodePoint block → Encoding #

decode ∷ Decoder s (Point block) #

encodeList ∷ [Point block] → Encoding #

decodeList ∷ Decoder s [Point block] #

StandardHash block ⇒ NoThunks (Point block) Source # 
Instance details

Defined in Ouroboros.Network.Block

Methods

noThunks ∷ Context → Point block → IO (Maybe ThunkInfo)

wNoThunks ∷ Context → Point block → IO (Maybe ThunkInfo)

showTypeOfProxy (Point block) → String

ShowProxy block ⇒ ShowProxy (Point block ∷ Type) Source # 
Instance details

Defined in Ouroboros.Network.Block

Methods

showProxyProxy (Point block) → String Source #

type Rep (Point block) Source # 
Instance details

Defined in Ouroboros.Network.Block

type Rep (Point block) = D1 ('MetaData "Point" "Ouroboros.Network.Block" "ouroboros-network-0.1.0.0-inplace" 'True) (C1 ('MetaCons "Point" 'PrefixI 'True) (S1 ('MetaSel ('Just "getPoint") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (WithOrigin (Block SlotNo (HeaderHash block))))))

blockPointHasHeader block ⇒ block → Point block Source #

Chain construction and inspection

Genesis

Head inspection

headPointHasHeader block ⇒ Chain block → Point block Source #

headSlotHasHeader block ⇒ Chain block → WithOrigin SlotNo Source #

headHashHasHeader block ⇒ Chain block → ChainHash block Source #

headTipHasHeader block ⇒ Chain block → Tip block Source #

headAnchorHasHeader block ⇒ Chain block → Anchor block Source #

Basic operations

headChain b → Maybe b Source #

toNewestFirstChain block → [block] Source #

Produce the list of blocks, from most recent back to genesis

toOldestFirstChain block → [block] Source #

Produce the list of blocks, from genesis to the most recent

fromNewestFirstHasHeader block ⇒ [block] → Chain block Source #

Make a chain from a list of blocks. The head of the list is the head of the chain.

fromOldestFirstHasHeader block ⇒ [block] → Chain block Source #

Construct chain from list of blocks from oldest to newest

dropIntChain block → Chain block Source #

lengthChain block → Int Source #

nullChain block → Bool Source #

Update type and operations

data ChainUpdate block a Source #

A representation of two actions to update a chain: add a block or roll back to a previous point.

The type parameter a is there to allow a Functor instance. Typically, it will be instantiated with block itself.

Constructors

AddBlock a 
RollBack (Point block) 

Instances

Instances details
Functor (ChainUpdate block) Source # 
Instance details

Defined in Ouroboros.Network.Block

Methods

fmap ∷ (a → b) → ChainUpdate block a → ChainUpdate block b Source #

(<$) ∷ a → ChainUpdate block b → ChainUpdate block a Source #

Foldable (ChainUpdate block) Source # 
Instance details

Defined in Ouroboros.Network.Block

Methods

foldMonoid m ⇒ ChainUpdate block m → m Source #

foldMapMonoid m ⇒ (a → m) → ChainUpdate block a → m Source #

foldMap'Monoid m ⇒ (a → m) → ChainUpdate block a → m Source #

foldr ∷ (a → b → b) → b → ChainUpdate block a → b Source #

foldr' ∷ (a → b → b) → b → ChainUpdate block a → b Source #

foldl ∷ (b → a → b) → b → ChainUpdate block a → b Source #

foldl' ∷ (b → a → b) → b → ChainUpdate block a → b Source #

foldr1 ∷ (a → a → a) → ChainUpdate block a → a Source #

foldl1 ∷ (a → a → a) → ChainUpdate block a → a Source #

toListChainUpdate block a → [a] Source #

nullChainUpdate block a → Bool Source #

lengthChainUpdate block a → Int Source #

elemEq a ⇒ a → ChainUpdate block a → Bool Source #

maximumOrd a ⇒ ChainUpdate block a → a Source #

minimumOrd a ⇒ ChainUpdate block a → a Source #

sumNum a ⇒ ChainUpdate block a → a Source #

productNum a ⇒ ChainUpdate block a → a Source #

Traversable (ChainUpdate block) Source # 
Instance details

Defined in Ouroboros.Network.Block

Methods

traverseApplicative f ⇒ (a → f b) → ChainUpdate block a → f (ChainUpdate block b) Source #

sequenceAApplicative f ⇒ ChainUpdate block (f a) → f (ChainUpdate block a) Source #

mapMMonad m ⇒ (a → m b) → ChainUpdate block a → m (ChainUpdate block b) Source #

sequenceMonad m ⇒ ChainUpdate block (m a) → m (ChainUpdate block a) Source #

(StandardHash block, Eq a) ⇒ Eq (ChainUpdate block a) Source # 
Instance details

Defined in Ouroboros.Network.Block

Methods

(==)ChainUpdate block a → ChainUpdate block a → Bool Source #

(/=)ChainUpdate block a → ChainUpdate block a → Bool Source #

(StandardHash block, Show a) ⇒ Show (ChainUpdate block a) Source # 
Instance details

Defined in Ouroboros.Network.Block

Methods

showsPrecIntChainUpdate block a → ShowS Source #

showChainUpdate block a → String Source #

showList ∷ [ChainUpdate block a] → ShowS Source #

addBlockHasHeader block ⇒ block → Chain block → Chain block Source #

rollbackHasHeader block ⇒ Point block → Chain block → Maybe (Chain block) Source #

applyChainUpdateHasHeader block ⇒ ChainUpdate block block → Chain block → Maybe (Chain block) Source #

applyChainUpdatesHasHeader block ⇒ [ChainUpdate block block] → Chain block → Maybe (Chain block) Source #

Special operations

pointOnChainHasHeader block ⇒ Point block → Chain block → Bool Source #

pointIsAfterHasHeader block ⇒ Point block → Point block → Chain block → Bool Source #

Check whether the first point is after the second point on the chain. Usually, this can simply be checked using the SlotNos, but some blocks may have the same SlotNo.

When the first point equals the second point, the answer will be False.

PRECONDITION: both points are on the chain.

successorBlockHasHeader block ⇒ Point block → Chain block → Maybe block Source #

selectChainHasHeader block ⇒ Chain block → Chain block → Chain block Source #

selectPointsHasHeader block ⇒ [Int] → Chain block → [Point block] Source #

Select a bunch of Points based on offsets from the head of the chain. This is used in the chain consumer protocol as part of finding the intersection between a local and remote chain.

The typical pattern is to use a selection of offsets covering the last K blocks, biased towards more recent blocks. For example:

selectPoints (0 : [ fib n | n <- [1 .. 17] ])

findBlock ∷ (block → Bool) → Chain block → Maybe block Source #

selectBlockRangeHasHeader block ⇒ Chain block → Point block → Point block → Maybe [block] Source #

findFirstPointHasHeader block ⇒ [Point block] → Chain block → Maybe (Point block) Source #

intersectChainsHasHeader block ⇒ Chain block → Chain block → Maybe (Point block) Source #

isPrefixOfEq block ⇒ Chain block → Chain block → Bool Source #

Conversion to/from AnchoredFragment

fromAnchoredFragmentHasHeader block ⇒ AnchoredFragment block → Maybe (Chain block) Source #

Convert an AnchoredFragment to a Chain.

The anchor of the fragment must be genesisPoint, otherwise Nothing is returned.

toAnchoredFragmentHasHeader block ⇒ Chain block → AnchoredFragment block Source #

Convert a Chain to an AnchoredFragment.

The anchor of the fragment will be genesisPoint.

Helper functions

prettyPrintChainString → (block → String) → Chain block → String Source #