Safe Haskell | None |
---|---|
Language | Haskell2010 |
Synopsis
-
newtype
HashHeader
crypto =
HashHeader
{
- unHashHeader :: Hash crypto EraIndependentBlockHeader
-
data
PrevHash
crypto
- = GenesisHash
- | BlockHash !( HashHeader crypto)
- data BHeader crypto where
-
data
BHBody
crypto =
BHBody
{
- bheaderBlockNo :: ! BlockNo
- bheaderSlotNo :: ! SlotNo
- bheaderPrev :: !( PrevHash crypto)
- bheaderVk :: !( VKey ' BlockIssuer crypto)
- bheaderVrfVk :: !( VerKeyVRF crypto)
- bheaderEta :: !( CertifiedVRF crypto Nonce )
- bheaderL :: !( CertifiedVRF crypto Natural )
- bsize :: ! Natural
- bhash :: !( Hash crypto EraIndependentBlockBody )
- bheaderOCert :: !( OCert crypto)
- bprotver :: ! ProtVer
-
data
LastAppliedBlock
crypto =
LastAppliedBlock
{
- labBlockNo :: ! BlockNo
- labSlotNo :: ! SlotNo
- labHash :: !( HashHeader crypto)
- data BoundedNatural
- assertBoundedNatural :: Natural -> Natural -> BoundedNatural
- lastAppliedHash :: WithOrigin ( LastAppliedBlock crypto) -> PrevHash crypto
- issuerIDfromBHBody :: Crypto crypto => BHBody crypto -> KeyHash ' BlockIssuer crypto
- checkLeaderValue :: forall v. VRFAlgorithm v => OutputVRF v -> Rational -> ActiveSlotCoeff -> Bool
- checkLeaderNatValue :: BoundedNatural -> Rational -> ActiveSlotCoeff -> Bool
- bhHash :: Crypto crypto => BHeader crypto -> HashHeader crypto
- hashHeaderToNonce :: HashHeader crypto -> Nonce
- prevHashToNonce :: PrevHash crypto -> Nonce
- bHeaderSize :: forall crypto. BHeader crypto -> Int
- bhbody :: Crypto crypto => BHeader crypto -> BHBody crypto
- hBbsize :: BHBody crypto -> Natural
- seedEta :: Nonce
- seedL :: Nonce
- mkSeed :: Nonce -> SlotNo -> Nonce -> Seed
- bnonce :: BHBody crypto -> Nonce
- makeHeaderView :: Crypto crypto => BHeader crypto -> BHeaderView crypto
Documentation
newtype HashHeader crypto Source #
The hash of a Block Header
HashHeader | |
|
Instances
The previous hash of a block
GenesisHash | |
BlockHash !( HashHeader crypto) |
Instances
data BHeader crypto where Source #
pattern BHeader :: Crypto crypto => BHBody crypto -> SignedKES crypto ( BHBody crypto) -> BHeader crypto |
Instances
BHBody | |
|
Instances
data LastAppliedBlock crypto Source #
LastAppliedBlock | |
|
Instances
data BoundedNatural Source #
Natural value with some additional bound. It must always be the base that 'bvValue <= bvMaxValue'. The creator is responsible for checking this value.
:: Natural |
Maximum bound |
-> Natural |
Value |
-> BoundedNatural |
Assert that a natural is bounded by a certain value. Throws an error when this is not the case.
lastAppliedHash :: WithOrigin ( LastAppliedBlock crypto) -> PrevHash crypto Source #
issuerIDfromBHBody :: Crypto crypto => BHBody crypto -> KeyHash ' BlockIssuer crypto Source #
Retrieve the issuer id (the hash of the cold key) from the body of the block header. This corresponds to either a genesis/core node or a stake pool.
checkLeaderValue :: forall v. VRFAlgorithm v => OutputVRF v -> Rational -> ActiveSlotCoeff -> Bool Source #
Check that the certified VRF output, when used as a natural, is valid for being slot leader.
:: BoundedNatural |
Certified nat value |
-> Rational |
Stake proportion |
-> ActiveSlotCoeff | |
-> Bool |
Check that the certified input natural is valid for being slot leader. This means we check that
p < 1 - (1 - f)^σ
where p = certNat / certNatMax.
The calculation is done using the following optimization:
let q = 1 - p and c = ln(1 - f)
then p < 1 - (1 - f)^σ = 1 / (1 - p) < exp(-σ * c) = 1 / q < exp(-σ * c)
This can be efficiently be computed by
taylorExpCmp
which returns
ABOVE
in case the reference value `1 / (1 - p)` is above the exponential function
at `-σ * c`,
BELOW
if it is below or
MaxReached
if it couldn't
conclusively compute this within the given iteration bounds.
Note that 1 1 1 certNatMax --- = ----- = ---------------------------- = ---------------------- q 1 - p 1 - (certNat / certNatMax) (certNatMax - certNat)
hashHeaderToNonce :: HashHeader crypto -> Nonce Source #
HashHeader to Nonce What is going on here? This is here because the surrounding code is parametrized in the hash algorithm used, but the nonce is hard-coded to Blake2b_256. We require the nonce to have the right length (the size of a Blake2b_256 hash), so if the hash size differs, we pad or remove bytes accordingly.
prevHashToNonce :: PrevHash crypto -> Nonce Source #
bHeaderSize :: forall crypto. BHeader crypto -> Int Source #
Construct a seed to use in the VRF computation.
makeHeaderView :: Crypto crypto => BHeader crypto -> BHeaderView crypto Source #