Safe Haskell | Safe-Inferred |
---|---|
Language | Haskell2010 |
Synopsis
- data family BlockConfig blk
- newtype ChainLength = ChainLength Int
- data family CodecConfig blk
- data EBB
- = EBB !EpochNo
- | RegularBlock
- data family Header blk
- data family StorageConfig blk
- data TestBlock = TestBlock {}
- data TestBody = TestBody {}
- newtype TestBodyHash = TestBodyHash Int
- data TestHeader = TestHeader {}
- newtype TestHeaderHash = TestHeaderHash Int
- firstBlock ∷ SlotNo → TestBody → TestBlock
- firstEBB ∷ (SlotNo → Bool) → TestBody → TestBlock
- mkBlock ∷ HasCallStack ⇒ (SlotNo → Bool) → TestBody → ChainHash TestHeader → SlotNo → BlockNo → ChainLength → Maybe EpochNo → TestBlock
- mkNextBlock ∷ TestBlock → SlotNo → TestBody → TestBlock
- mkNextBlock' ∷ (HeaderFields TestBlock, ChainLength) → SlotNo → TestBody → TestBlock
- mkNextEBB ∷ (SlotNo → Bool) → TestBlock → SlotNo → EpochNo → TestBody → TestBlock
- mkNextEBB' ∷ (SlotNo → Bool) → (HeaderFields TestBlock, ChainLength) → SlotNo → EpochNo → TestBody → TestBlock
- testBlockChainLength ∷ TestBlock → ChainLength
- testBlockIsEBB ∷ TestBlock → IsEBB
- testBlockIsValid ∷ TestBlock → Bool
- testBlockFromLazyByteString ∷ HasCallStack ⇒ ByteString → TestBlock
- testBlockToBuilder ∷ TestBlock → Builder
- testBlockToLazyByteString ∷ TestBlock → ByteString
- data TestBlockError
- data TestBlockOtherHeaderEnvelopeError = UnexpectedEBBInSlot !SlotNo
- mkTestConfig ∷ SecurityParam → ChunkSize → TopLevelConfig TestBlock
- testInitExtLedger ∷ ExtLedgerState TestBlock
- type Corruptions = NonEmpty (FileCorruption, FsPath)
- data FileCorruption
- corruptFile ∷ MonadThrow m ⇒ HasFS m h → FileCorruption → FsPath → m Bool
- corruptionFiles ∷ Corruptions → [FsPath]
- generateCorruptions ∷ NonEmpty FsPath → Gen Corruptions
- shrinkCorruptions ∷ Corruptions → [Corruptions]
Test block
data family BlockConfig blk Source #
Static configuration required to work with this type of blocks
Instances
newtype ChainLength Source #
In chain selection, we use BlockNo
as a proxy for the block length.
This is entirely correct, except for those dreadful EBBs, which share their
block number with their predecessor. So it is possible that two chains with
the same BlockNo
at the tip have a different length because the longer
chain contains more EBBs than the shorter.
For example:
.. :> EBB (100, slotNo 10, blockNo 1) :> (400, slotNo 10, blockNo 2) .. :> (999, slotNo 10, blockNo 2)
The chain selection for this TestBlock
looks at the hashes in case of a
BlockNo
tie (after prefering the chain ending with an EBB) and will pick
the block with the highest hash. This is to have a more deterministic chain
selection (less implementation specific) which will keep the model better
in sync with the implementation.
In the example above, that would mean picking the second chain, /even though it is shorter/! The implementation does not support switching to a shorter chain.
Note that this is not a problem for Byron, because we don't look at the hashes or anything else in case of a tie (we just prefer a chain ending with an EBB, which must be longer).
Note that is not a problem for Shelley either, where we do look at the certificate number and VRF hash in case of a tie, because there are no EBBs.
This is only an issue when:
* There can be EBBs in the chain
* In case of equal blockNo
s, we still prefer one over the other because
of some additional condition.
Which is the case for this TestBlock.
To solve this, we store the real chain length inside the block. The only
difference with the BlockNo
is that ChainLength
takes EBBs into account.
When there is BlockNo
tie as in the example above and we would look at
the hashes, we will first look at the ChainLength
(and prefer the longest
one). Only if that is equal do we actually look at the hashes. This
guarantees that we never prefer a chain that is shorter.
NOTE: we start counting from 1 (unlike BlockNo
, which starts from 0),
because it corresponds to the length.
Instances
data family CodecConfig blk Source #
Static configuration required for serialisation and deserialisation of types pertaining to this type of block.
Data family instead of type family to get better type inference.
Instances
Strict variant of Maybe EpochNo
Instances
Generic EBB Source # | |
Show EBB Source # | |
Eq EBB Source # | |
Hashable EBB Source # | |
NoThunks EBB Source # | |
Serialise EBB Source # | |
ToExpr EBB Source # | |
type Rep EBB Source # | |
Defined in Test.Ouroboros.Storage.TestBlock type Rep EBB = D1 ('MetaData "EBB" "Test.Ouroboros.Storage.TestBlock" "ouroboros-consensus-0.21.0.0-inplace-storage-test" 'False) (C1 ('MetaCons "EBB" 'PrefixI 'False) (S1 ('MetaSel ('Nothing ∷ Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 EpochNo)) :+: C1 ('MetaCons "RegularBlock" 'PrefixI 'False) (U1 ∷ Type → Type)) |
data family Header blk Source #
Instances
data family StorageConfig blk Source #
Config needed for the
NodeInitStorage
class. Defined here to
avoid circular dependencies.
Instances
Instances
TestBody | |
|
Instances
Generic TestBody Source # | |
Show TestBody Source # | |
Eq TestBody Source # | |
Hashable TestBody Source # | |
NoThunks TestBody Source # | |
Serialise TestBody Source # | |
ToExpr TestBody Source # | |
type Rep TestBody Source # | |
Defined in Test.Ouroboros.Storage.TestBlock type Rep TestBody = D1 ('MetaData "TestBody" "Test.Ouroboros.Storage.TestBlock" "ouroboros-consensus-0.21.0.0-inplace-storage-test" 'False) (C1 ('MetaCons "TestBody" 'PrefixI 'True) (S1 ('MetaSel ('Just "tbForkNo") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Word) :*: S1 ('MetaSel ('Just "tbIsValid") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Bool))) |
newtype TestBodyHash Source #
Hash of a TestBody
Instances
data TestHeader Source #
TestHeader | |
|
Instances
newtype TestHeaderHash Source #
Hash of a TestHeader
Instances
Construction
firstBlock ∷ SlotNo → TestBody → TestBlock Source #
Note the first block need not be an EBB, see firstEBB
.
∷ HasCallStack | |
⇒ (SlotNo → Bool) | Is this slot allowed contain an EBB? This argument is used primarily to detect the generation of invalid blocks
with different kind of |
→ TestBody | |
→ ChainHash TestHeader | Hash of previous header |
→ SlotNo | |
→ BlockNo | |
→ ChainLength | |
→ Maybe EpochNo | |
→ TestBlock |
Variant of mkNextBlock
that takes the entire previous block.
∷ (HeaderFields TestBlock, ChainLength) | Information about the previous block |
→ SlotNo | |
→ TestBody | |
→ TestBlock |
Variant of mkNextEBB
that takes the entire previous block.
∷ (SlotNo → Bool) | |
→ (HeaderFields TestBlock, ChainLength) | Information about the previous block |
→ SlotNo | |
→ EpochNo | |
→ TestBody | |
→ TestBlock |
Note that in various places, e.g., the ImmutableDB, we rely on the fact
that the slotNo
should correspond to the first slot number of the epoch,
as is the case for real EBBs.
Query
testBlockIsValid ∷ TestBlock → Bool Source #
Check whether the header matches its hash and whether the body matches its hash.
Serialisation
Ledger
data TestBlockError Source #
InvalidHash | The hashes don't line up |
InvalidBlock | The block itself is invalid |
Instances
data TestBlockOtherHeaderEnvelopeError Source #
Instances
Generic TestBlockOtherHeaderEnvelopeError Source # | |
Show TestBlockOtherHeaderEnvelopeError Source # | |
Eq TestBlockOtherHeaderEnvelopeError Source # | |
NoThunks TestBlockOtherHeaderEnvelopeError Source # | |
ToExpr TestBlockOtherHeaderEnvelopeError Source # | |
type Rep TestBlockOtherHeaderEnvelopeError Source # | |
Defined in Test.Ouroboros.Storage.TestBlock type Rep TestBlockOtherHeaderEnvelopeError = D1 ('MetaData "TestBlockOtherHeaderEnvelopeError" "Test.Ouroboros.Storage.TestBlock" "ouroboros-consensus-0.21.0.0-inplace-storage-test" 'False) (C1 ('MetaCons "UnexpectedEBBInSlot" 'PrefixI 'False) (S1 ('MetaSel ('Nothing ∷ Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 SlotNo))) |
Corruptions
type Corruptions = NonEmpty (FileCorruption, FsPath) Source #
Multiple corruptions
data FileCorruption Source #
DeleteFile | |
DropLastBytes Word64 | Drop the last |
Corrupt Word64 | Corrupt the file by adding 1 to the byte at the given location (modulo the file size). |
Instances
Arbitrary FileCorruption Source # | |
Defined in Test.Ouroboros.Storage.TestBlock | |
Show FileCorruption Source # | |
Defined in Test.Ouroboros.Storage.TestBlock showsPrec ∷ Int → FileCorruption → ShowS # show ∷ FileCorruption → String # showList ∷ [FileCorruption] → ShowS # | |
Eq FileCorruption Source # | |
Defined in Test.Ouroboros.Storage.TestBlock (==) ∷ FileCorruption → FileCorruption → Bool # (/=) ∷ FileCorruption → FileCorruption → Bool # |
corruptFile ∷ MonadThrow m ⇒ HasFS m h → FileCorruption → FsPath → m Bool Source #
Returns True
when something was actually corrupted. For example, when
drop the last bytes of an empty file, we don't actually corrupt it.
corruptionFiles ∷ Corruptions → [FsPath] Source #
Return a list of all files that will be corrupted
generateCorruptions ∷ NonEmpty FsPath → Gen Corruptions Source #
The same file will not occur twice.
Orphan instances
Hashable BlockNo Source # | |
Hashable SlotNo Source # | |
Hashable IsEBB Source # | |
ToExpr FsPath Source # | |
ToExpr IsEBB Source # | |
ToExpr BftValidationErr Source # | |
toExpr ∷ BftValidationErr → Expr Source # listToExpr ∷ [BftValidationErr] → Expr Source # | |
ToExpr BinaryBlockInfo Source # | |
toExpr ∷ BinaryBlockInfo → Expr Source # listToExpr ∷ [BinaryBlockInfo] → Expr Source # | |
ToExpr BlocksPerFile Source # | |
toExpr ∷ BlocksPerFile → Expr Source # listToExpr ∷ [BlocksPerFile] → Expr Source # | |
(StandardHash b, Hashable (HeaderHash b)) ⇒ Hashable (ChainHash b) Source # | |