Safe Haskell | None |
---|---|
Language | Haskell2010 |
Concrete block
The network library should not export a concrete block type at all, except that it might need one in its tests (but not exported). Right now this module serves to isolate this in a specific module so we can identify easily where it is used; eventually it should be simplified and then moved to the network layer tests; the more sophiscated block abstraction (abstracted over an Ouroboros protocol) will live in the consensus layer.
Synopsis
- data Block = Block {}
- data BlockHeader = BlockHeader {}
- newtype BlockBody = BlockBody ByteString
- hashHeader :: BlockHeader -> ConcreteHeaderHash
- newtype BodyHash = BodyHash Int
- newtype ConcreteHeaderHash = HeaderHash Int
- hashBody :: Hashable body => body -> BodyHash
- convertSlotToTimeForTestsAssumingNoHardFork :: SlotNo -> UTCTime
- mkChain :: [(SlotNo, BlockBody)] -> Chain Block
- mkChainSimple :: [BlockBody] -> Chain Block
- mkAnchoredFragment :: Anchor Block -> [(SlotNo, BlockBody)] -> AnchoredFragment Block
- mkAnchoredFragmentSimple :: [BlockBody] -> AnchoredFragment Block
- mkPartialBlock :: SlotNo -> BlockBody -> Block
- mkPartialBlockHeader :: SlotNo -> BlockBody -> BlockHeader
- fixupBlock :: HeaderHash block ~ HeaderHash BlockHeader => Anchor block -> Block -> Block
- fixupBlockHeader :: HeaderHash block ~ HeaderHash BlockHeader => Anchor block -> BlockHeader -> BlockHeader
- fixupBlockAfterBlock :: Block -> Block -> Block
- fixupChain :: HasFullHeader b => (Anchor b -> b -> b) -> [b] -> Chain b
- fixupAnchoredFragmentFrom :: HasFullHeader b => Anchor b -> (Anchor b -> b -> b) -> [b] -> AnchoredFragment b
Documentation
Our highly-simplified version of a block. It retains the separation between a block header and body, which is a detail needed for the protocols.
Instances
data BlockHeader Source #
A block header. It retains simplified versions of all the essential elements.
BlockHeader | |
|
Instances
Generic BlockHeader Source # | |||||
Defined in Ouroboros.Network.Mock.ConcreteBlock
from :: BlockHeader -> Rep BlockHeader x # to :: Rep BlockHeader x -> BlockHeader # | |||||
Show BlockHeader Source # | |||||
Defined in Ouroboros.Network.Mock.ConcreteBlock showsPrec :: Int -> BlockHeader -> ShowS # show :: BlockHeader -> String # showList :: [BlockHeader] -> ShowS # | |||||
Eq BlockHeader Source # | |||||
Defined in Ouroboros.Network.Mock.ConcreteBlock (==) :: BlockHeader -> BlockHeader -> Bool # (/=) :: BlockHeader -> BlockHeader -> Bool # | |||||
HasFullHeader BlockHeader Source # | |||||
Defined in Ouroboros.Network.Mock.ConcreteBlock blockPrevHash :: BlockHeader -> ChainHash BlockHeader # blockInvariant :: BlockHeader -> Bool # | |||||
HasHeader BlockHeader Source # | |||||
Defined in Ouroboros.Network.Mock.ConcreteBlock | |||||
Serialise BlockHeader Source # | |||||
Defined in Ouroboros.Network.Mock.ConcreteBlock encode :: BlockHeader -> Encoding # decode :: Decoder s BlockHeader # encodeList :: [BlockHeader] -> Encoding # decodeList :: Decoder s [BlockHeader] # | |||||
StandardHash BlockHeader Source # | |||||
Defined in Ouroboros.Network.Mock.ConcreteBlock | |||||
ShowProxy BlockHeader Source # | |||||
Defined in Ouroboros.Network.Mock.ConcreteBlock showProxy :: Proxy BlockHeader -> String # | |||||
type Rep BlockHeader Source # | |||||
Defined in Ouroboros.Network.Mock.ConcreteBlock type Rep BlockHeader = D1 ('MetaData "BlockHeader" "Ouroboros.Network.Mock.ConcreteBlock" "ouroboros-network-mock-0.1.1.2-inplace" 'False) (C1 ('MetaCons "BlockHeader" 'PrefixI 'True) ((S1 ('MetaSel ('Just "headerHash") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (HeaderHash BlockHeader)) :*: S1 ('MetaSel ('Just "headerPrevHash") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (ChainHash BlockHeader))) :*: (S1 ('MetaSel ('Just "headerSlot") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 SlotNo) :*: (S1 ('MetaSel ('Just "headerBlockNo") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 BlockNo) :*: S1 ('MetaSel ('Just "headerBodyHash") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 BodyHash))))) | |||||
type HeaderHash BlockHeader Source # | |||||
Defined in Ouroboros.Network.Mock.ConcreteBlock |
Instances
IsString BlockBody Source # | |||||
Defined in Ouroboros.Network.Mock.ConcreteBlock fromString :: String -> BlockBody # | |||||
Generic BlockBody Source # | |||||
Defined in Ouroboros.Network.Mock.ConcreteBlock
| |||||
Show BlockBody Source # | |||||
Eq BlockBody Source # | |||||
Ord BlockBody Source # | |||||
Defined in Ouroboros.Network.Mock.ConcreteBlock | |||||
Hashable BlockBody Source # | |||||
Defined in Ouroboros.Network.Mock.ConcreteBlock | |||||
Serialise BlockBody Source # | |||||
type Rep BlockBody Source # | |||||
Defined in Ouroboros.Network.Mock.ConcreteBlock type Rep BlockBody = D1 ('MetaData "BlockBody" "Ouroboros.Network.Mock.ConcreteBlock" "ouroboros-network-mock-0.1.1.2-inplace" 'True) (C1 ('MetaCons "BlockBody" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 ByteString))) |
hashHeader :: BlockHeader -> ConcreteHeaderHash Source #
Compute the HeaderHash
of the BlockHeader
.
The hash of all the information in a BlockBody
.
Instances
Generic BodyHash Source # | |||||
Defined in Ouroboros.Network.Mock.ConcreteBlock
| |||||
Show BodyHash Source # | |||||
Eq BodyHash Source # | |||||
Ord BodyHash Source # | |||||
Defined in Ouroboros.Network.Mock.ConcreteBlock | |||||
Hashable BodyHash Source # | |||||
Defined in Ouroboros.Network.Mock.ConcreteBlock | |||||
Serialise BodyHash Source # | |||||
type Rep BodyHash Source # | |||||
Defined in Ouroboros.Network.Mock.ConcreteBlock |
newtype ConcreteHeaderHash Source #
The hash of all the information in a BlockHeader
.
Instances
Generic ConcreteHeaderHash Source # | |||||
Defined in Ouroboros.Network.Mock.ConcreteBlock
from :: ConcreteHeaderHash -> Rep ConcreteHeaderHash x # to :: Rep ConcreteHeaderHash x -> ConcreteHeaderHash # | |||||
Show ConcreteHeaderHash Source # | |||||
Defined in Ouroboros.Network.Mock.ConcreteBlock showsPrec :: Int -> ConcreteHeaderHash -> ShowS # show :: ConcreteHeaderHash -> String # showList :: [ConcreteHeaderHash] -> ShowS # | |||||
Eq ConcreteHeaderHash Source # | |||||
Defined in Ouroboros.Network.Mock.ConcreteBlock (==) :: ConcreteHeaderHash -> ConcreteHeaderHash -> Bool # (/=) :: ConcreteHeaderHash -> ConcreteHeaderHash -> Bool # | |||||
Ord ConcreteHeaderHash Source # | |||||
Defined in Ouroboros.Network.Mock.ConcreteBlock compare :: ConcreteHeaderHash -> ConcreteHeaderHash -> Ordering # (<) :: ConcreteHeaderHash -> ConcreteHeaderHash -> Bool # (<=) :: ConcreteHeaderHash -> ConcreteHeaderHash -> Bool # (>) :: ConcreteHeaderHash -> ConcreteHeaderHash -> Bool # (>=) :: ConcreteHeaderHash -> ConcreteHeaderHash -> Bool # max :: ConcreteHeaderHash -> ConcreteHeaderHash -> ConcreteHeaderHash # min :: ConcreteHeaderHash -> ConcreteHeaderHash -> ConcreteHeaderHash # | |||||
Hashable ConcreteHeaderHash Source # | |||||
Defined in Ouroboros.Network.Mock.ConcreteBlock hashWithSalt :: Int -> ConcreteHeaderHash -> Int # hash :: ConcreteHeaderHash -> Int # | |||||
NoThunks ConcreteHeaderHash Source # | |||||
Defined in Ouroboros.Network.Mock.ConcreteBlock noThunks :: Context -> ConcreteHeaderHash -> IO (Maybe ThunkInfo) # wNoThunks :: Context -> ConcreteHeaderHash -> IO (Maybe ThunkInfo) # showTypeOf :: Proxy ConcreteHeaderHash -> String # | |||||
Serialise ConcreteHeaderHash Source # | |||||
Defined in Ouroboros.Network.Mock.ConcreteBlock encode :: ConcreteHeaderHash -> Encoding # decode :: Decoder s ConcreteHeaderHash # encodeList :: [ConcreteHeaderHash] -> Encoding # decodeList :: Decoder s [ConcreteHeaderHash] # | |||||
type Rep ConcreteHeaderHash Source # | |||||
Defined in Ouroboros.Network.Mock.ConcreteBlock type Rep ConcreteHeaderHash = D1 ('MetaData "ConcreteHeaderHash" "Ouroboros.Network.Mock.ConcreteBlock" "ouroboros-network-mock-0.1.1.2-inplace" 'True) (C1 ('MetaCons "HeaderHash" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Int))) |
Converting slots to times
convertSlotToTimeForTestsAssumingNoHardFork :: SlotNo -> UTCTime Source #
Arbitrarily but consistently converts slots UTCTimes.
It is only intended for use in tests. Notably it assumes a fixed system start time, slot length, and the absence of a hard fork (ie no HardForkCombinator). This is how it's available as a pure function.
Creating sample chains
mkChain :: [(SlotNo, BlockBody)] -> Chain Block Source #
This takes the blocks in order from oldest to newest.
mkAnchoredFragment :: Anchor Block -> [(SlotNo, BlockBody)] -> AnchoredFragment Block Source #
Generator utilities
mkPartialBlockHeader :: SlotNo -> BlockBody -> BlockHeader Source #
fixupBlock :: HeaderHash block ~ HeaderHash BlockHeader => Anchor block -> Block -> Block Source #
Fix up a block so that it fits on top of the given anchor. Only the block number, the previous hash and the block hash are updated; the slot number and the signers are kept intact.
fixupBlockHeader :: HeaderHash block ~ HeaderHash BlockHeader => Anchor block -> BlockHeader -> BlockHeader Source #
Fixup block header to fit it on top of a chain. Only block number and previous hash are updated; the slot and signer are kept unchanged.
fixupBlockAfterBlock :: Block -> Block -> Block Source #
Fixup a block so to fit it on top of a given previous block.
fixupChain :: HasFullHeader b => (Anchor b -> b -> b) -> [b] -> Chain b Source #
fixupAnchoredFragmentFrom :: HasFullHeader b => Anchor b -> (Anchor b -> b -> b) -> [b] -> AnchoredFragment b Source #
Orphan instances
Hashable BlockNo Source # | |
Hashable SlotNo Source # | |
(StandardHash b, Hashable (HeaderHash b)) => Hashable (ChainHash b) Source # |
We don't insist that This requires |