| Safe Haskell | None |
|---|---|
| Language | Haskell2010 |
Ouroboros.Network.Mock.ConcreteBlock
Description
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 {
- headerHash :: HeaderHash BlockHeader
- headerPrevHash :: ChainHash BlockHeader
- headerSlot :: SlotNo
- headerBlockNo :: BlockNo
- headerBodyHash :: BodyHash
- 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.
Constructors
| Block | |
Fields | |
Instances
data BlockHeader Source #
A block header. It retains simplified versions of all the essential elements.
Constructors
| BlockHeader | |
Fields
| |
Instances
| Arbitrary BlockHeader Source # | |||||
Defined in Ouroboros.Network.Mock.ChainGenerators | |||||
| CoArbitrary BlockHeader Source # | |||||
Defined in Ouroboros.Network.Mock.ChainGenerators Methods coarbitrary :: BlockHeader -> Gen b -> Gen b # | |||||
| Generic BlockHeader Source # | |||||
Defined in Ouroboros.Network.Mock.ConcreteBlock Associated Types
| |||||
| Show BlockHeader Source # | |||||
Defined in Ouroboros.Network.Mock.ConcreteBlock Methods showsPrec :: Int -> BlockHeader -> ShowS # show :: BlockHeader -> String # showList :: [BlockHeader] -> ShowS # | |||||
| Eq BlockHeader Source # | |||||
Defined in Ouroboros.Network.Mock.ConcreteBlock | |||||
| HasFullHeader BlockHeader Source # | |||||
Defined in Ouroboros.Network.Mock.ConcreteBlock | |||||
| HasHeader BlockHeader Source # | |||||
Defined in Ouroboros.Network.Mock.ConcreteBlock Methods getHeaderFields :: BlockHeader -> HeaderFields BlockHeader # | |||||
| Serialise BlockHeader Source # | |||||
Defined in Ouroboros.Network.Mock.ConcreteBlock Methods 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 Methods showProxy :: Proxy BlockHeader -> String | |||||
| Arbitrary (Point BlockHeader) Source # | |||||
Defined in Ouroboros.Network.Mock.ChainGenerators | |||||
| CoArbitrary (ChainHash BlockHeader) Source # | |||||
Defined in Ouroboros.Network.Mock.ChainGenerators Methods coarbitrary :: ChainHash BlockHeader -> Gen b -> Gen b # | |||||
| type Rep BlockHeader Source # | |||||
Defined in Ouroboros.Network.Mock.ConcreteBlock type Rep BlockHeader = D1 ('MetaData "BlockHeader" "Ouroboros.Network.Mock.ConcreteBlock" "ouroboros-network-0.23.0.0-inplace-api-tests-lib" '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 | |||||
Constructors
| BlockBody ByteString |
Instances
| Arbitrary BlockBody Source # | |||||
| CoArbitrary BlockBody Source # | |||||
Defined in Ouroboros.Network.Mock.ChainGenerators Methods coarbitrary :: BlockBody -> Gen b -> Gen b # | |||||
| IsString BlockBody Source # | |||||
Defined in Ouroboros.Network.Mock.ConcreteBlock Methods fromString :: String -> BlockBody # | |||||
| Generic BlockBody Source # | |||||
Defined in Ouroboros.Network.Mock.ConcreteBlock Associated Types
| |||||
| 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-0.23.0.0-inplace-api-tests-lib" '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
| CoArbitrary BodyHash Source # | |||||
Defined in Ouroboros.Network.Mock.ChainGenerators Methods coarbitrary :: BodyHash -> Gen b -> Gen b # | |||||
| Generic BodyHash Source # | |||||
Defined in Ouroboros.Network.Mock.ConcreteBlock Associated Types
| |||||
| 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.
Constructors
| HeaderHash Int |
Instances
| Arbitrary ConcreteHeaderHash Source # | |||||
Defined in Ouroboros.Network.Mock.ChainGenerators | |||||
| CoArbitrary ConcreteHeaderHash Source # | |||||
Defined in Ouroboros.Network.Mock.ChainGenerators Methods coarbitrary :: ConcreteHeaderHash -> Gen b -> Gen b # | |||||
| Generic ConcreteHeaderHash Source # | |||||
Defined in Ouroboros.Network.Mock.ConcreteBlock Associated Types
Methods from :: ConcreteHeaderHash -> Rep ConcreteHeaderHash x # to :: Rep ConcreteHeaderHash x -> ConcreteHeaderHash # | |||||
| Show ConcreteHeaderHash Source # | |||||
Defined in Ouroboros.Network.Mock.ConcreteBlock Methods showsPrec :: Int -> ConcreteHeaderHash -> ShowS # show :: ConcreteHeaderHash -> String # showList :: [ConcreteHeaderHash] -> ShowS # | |||||
| Eq ConcreteHeaderHash Source # | |||||
Defined in Ouroboros.Network.Mock.ConcreteBlock Methods (==) :: ConcreteHeaderHash -> ConcreteHeaderHash -> Bool # (/=) :: ConcreteHeaderHash -> ConcreteHeaderHash -> Bool # | |||||
| Ord ConcreteHeaderHash Source # | |||||
Defined in Ouroboros.Network.Mock.ConcreteBlock Methods 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 | |||||
| NoThunks ConcreteHeaderHash Source # | |||||
Defined in Ouroboros.Network.Mock.ConcreteBlock Methods 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 Methods 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-0.23.0.0-inplace-api-tests-lib" '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.
mkAnchoredFragmentSimple :: [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 |