Blocks¶
The block follows mostly the definition of the Shelley specification. One notable difference is that the size and the hash of the block body are fields of the block, instead of functions.
record BHBody : Type where
field
bvkcold : VKey
bsize : ℕ
slot : Slot
bhash : KeyHash
hBbsize : ℕ
record BHeader : Type where
field
bhbody : BHBody
bhsig : Sig
record Block : Type where
field
bheader : BHeader
ts : List Tx
bBodySize : ℕ
bBodyHash : KeyHash
≡-bBodySize : bBodySize ≡ BHBody.hBbsize (BHeader.bhbody bheader)
≡-bBodyHash : bBodyHash ≡ BHBody.bhash (BHeader.bhbody bheader)
Block Body Transition¶
The Block Body Transition updates the block body state which comprises the
ledger state and the map describing the produced blocks. The environment of the
BBODY
transition includes the protocol parameters and the accounting
state.
The helper function incrBlocks
counts the number of
non-overlay blocks produced by each stake pool.
The signal of the BBODY
rule is a block from which we extract:
- the sequence of transactions,
txs
=block
.ts
, of the block; - the block header body
bhb
=block
.bheader
.bhbody
; - the hash of the verification key of the issuer of the block,
hk
=hash
(bhb
.bvkcold
).
The transition is executed if the following preconditions are met:
- The size of the block body matches the value given in the block header body.
- The hash of the block body matches the value given in the block header body.
- The
LEDGERS
transition succeeds.
After this, the transition system updates the mapping of the hashed stake pool
keys to the incremented value of produced blocks n + 1
, provided the current
slot is not an overlay slot.
The BBODY
rule has two predicate failures:
- if the size of the block body in the header is not equal to the real size of the block body, there is a WrongBlockBodySize failure.
- if the hash of the block body is not also the hash of transactions, there is an InvalidBodyHash failure.
BBodyEnv : Type
BBodyEnv = EnactState × Acnt
BBodyState : Type
BBodyState = LState × BlocksMade
incrBlocks : KeyHash → BlocksMade → BlocksMade
incrBlocks hk b = b ∪⁺ singletonᵐ hk 1
data _⊢_⇀⦇_,BBODY⦈_
: BBodyEnv → BBodyState → Block → BBodyState → Type where
BBODY-Block-Body : ∀ {acnt ls ls' b block es} →
let
open BHeader
open BHBody
open Block
open EnactState
txs = block .ts
bhb = block .bheader .bhbody
hk = hash (bhb .bvkcold)
pp = PParamsOf es
Γ = ⟦ bhb .slot , ∣ es .constitution ∣ , pp , es , TreasuryOf acnt ⟧
in
∙ block .bBodySize ≡ bhb .hBbsize
∙ block .bBodyHash ≡ bhb .bhash
∙ Γ ⊢ ls ⇀⦇ txs ,LEDGERS⦈ ls'
────────────────────────────────
(es , acnt) ⊢ ls , b ⇀⦇ block ,BBODY⦈ (ls' , incrBlocks hk b)