From 8669bbf34028cee2ce2eab05e2efd2bcd8d68367 Mon Sep 17 00:00:00 2001 From: Chris Gianelloni Date: Mon, 16 Oct 2023 18:20:31 -0400 Subject: [PATCH] feat: add issuer's vkey and block body size to block interface Signed-off-by: Chris Gianelloni --- ledger/allegra.go | 8 ++++++++ ledger/alonzo.go | 8 ++++++++ ledger/babbage.go | 26 +++++++++++++++++++++----- ledger/block.go | 2 ++ ledger/byron.go | 36 ++++++++++++++++++++++++++++++++++++ ledger/mary.go | 8 ++++++++ ledger/shelley.go | 26 +++++++++++++++++++++----- 7 files changed, 104 insertions(+), 10 deletions(-) diff --git a/ledger/allegra.go b/ledger/allegra.go index 547ac023..1c56200b 100644 --- a/ledger/allegra.go +++ b/ledger/allegra.go @@ -55,6 +55,14 @@ func (b *AllegraBlock) SlotNumber() uint64 { return b.Header.SlotNumber() } +func (b *AllegraBlock) IssuerVkey() []byte { + return b.Header.IssuerVkey() +} + +func (b *AllegraBlock) BlockBodySize() uint64 { + return b.Header.BlockBodySize() +} + func (b *AllegraBlock) Era() Era { return eras[EraIdAllegra] } diff --git a/ledger/alonzo.go b/ledger/alonzo.go index 20c70e34..4d2f2e52 100644 --- a/ledger/alonzo.go +++ b/ledger/alonzo.go @@ -57,6 +57,14 @@ func (b *AlonzoBlock) SlotNumber() uint64 { return b.Header.SlotNumber() } +func (b *AlonzoBlock) IssuerVkey() []byte { + return b.Header.IssuerVkey() +} + +func (b *AlonzoBlock) BlockBodySize() uint64 { + return b.Header.BlockBodySize() +} + func (b *AlonzoBlock) Era() Era { return eras[EraIdAlonzo] } diff --git a/ledger/babbage.go b/ledger/babbage.go index 5ef4bc0d..3cd868bb 100644 --- a/ledger/babbage.go +++ b/ledger/babbage.go @@ -57,6 +57,14 @@ func (b *BabbageBlock) SlotNumber() uint64 { return b.Header.SlotNumber() } +func (b *BabbageBlock) IssuerVkey() []byte { + return b.Header.IssuerVkey() +} + +func (b *BabbageBlock) BlockBodySize() uint64 { + return b.Header.BlockBodySize() +} + func (b *BabbageBlock) Era() Era { return eras[EraIdBabbage] } @@ -91,17 +99,17 @@ type BabbageBlockHeader struct { BlockNumber uint64 Slot uint64 PrevHash Blake2b256 - IssuerVkey interface{} - VrfKey interface{} + IssuerVkey []byte + VrfKey []byte VrfResult interface{} - BlockBodySize uint32 + BlockBodySize uint64 BlockBodyHash Blake2b256 OpCert struct { cbor.StructAsArray - HotVkey interface{} + HotVkey []byte SequenceNumber uint32 KesPeriod uint32 - Signature interface{} + Signature []byte } ProtoVersion struct { cbor.StructAsArray @@ -131,6 +139,14 @@ func (h *BabbageBlockHeader) SlotNumber() uint64 { return h.Body.Slot } +func (h *BabbageBlockHeader) IssuerVkey() []byte { + return h.Body.IssuerVkey +} + +func (h *BabbageBlockHeader) BlockBodySize() uint64 { + return h.Body.BlockBodySize +} + func (h *BabbageBlockHeader) Era() Era { return eras[EraIdBabbage] } diff --git a/ledger/block.go b/ledger/block.go index c1773eda..37f80a6d 100644 --- a/ledger/block.go +++ b/ledger/block.go @@ -30,6 +30,8 @@ type BlockHeader interface { Hash() string BlockNumber() uint64 SlotNumber() uint64 + IssuerVkey() []byte + BlockBodySize() uint64 Era() Era Cbor() []byte } diff --git a/ledger/byron.go b/ledger/byron.go index c44d3db7..9731ea92 100644 --- a/ledger/byron.go +++ b/ledger/byron.go @@ -96,6 +96,16 @@ func (h *ByronMainBlockHeader) SlotNumber() uint64 { return uint64((h.ConsensusData.SlotId.Epoch * ByronSlotsPerEpoch) + uint64(h.ConsensusData.SlotId.Slot)) } +func (h *ByronMainBlockHeader) IssuerVkey() []byte { + // Byron blocks don't have an issuer + return nil +} + +func (h *ByronMainBlockHeader) BlockBodySize() uint64 { + // TODO: calculate this + return 0 +} + func (h *ByronMainBlockHeader) Era() Era { return eras[EraIdByron] } @@ -183,6 +193,16 @@ func (h *ByronEpochBoundaryBlockHeader) SlotNumber() uint64 { return uint64(h.ConsensusData.Epoch * ByronSlotsPerEpoch) } +func (h *ByronEpochBoundaryBlockHeader) IssuerVkey() []byte { + // Byron blocks don't have an issuer + return nil +} + +func (h *ByronEpochBoundaryBlockHeader) BlockBodySize() uint64 { + // TODO: calculate this + return 0 +} + func (h *ByronEpochBoundaryBlockHeader) Era() Era { return eras[EraIdByron] } @@ -211,6 +231,14 @@ func (b *ByronMainBlock) SlotNumber() uint64 { return b.Header.SlotNumber() } +func (b *ByronMainBlock) IssuerVkey() []byte { + return b.Header.IssuerVkey() +} + +func (b *ByronMainBlock) BlockBodySize() uint64 { + return b.Header.BlockBodySize() +} + func (b *ByronMainBlock) Era() Era { return b.Header.Era() } @@ -244,6 +272,14 @@ func (b *ByronEpochBoundaryBlock) SlotNumber() uint64 { return b.Header.SlotNumber() } +func (b *ByronEpochBoundaryBlock) IssuerVkey() []byte { + return b.Header.IssuerVkey() +} + +func (b *ByronEpochBoundaryBlock) BlockBodySize() uint64 { + return b.Header.BlockBodySize() +} + func (b *ByronEpochBoundaryBlock) Era() Era { return b.Header.Era() } diff --git a/ledger/mary.go b/ledger/mary.go index 91ee5224..497ce917 100644 --- a/ledger/mary.go +++ b/ledger/mary.go @@ -56,6 +56,14 @@ func (b *MaryBlock) SlotNumber() uint64 { return b.Header.SlotNumber() } +func (b *MaryBlock) IssuerVkey() []byte { + return b.Header.IssuerVkey() +} + +func (b *MaryBlock) BlockBodySize() uint64 { + return b.Header.BlockBodySize() +} + func (b *MaryBlock) Era() Era { return eras[EraIdMary] } diff --git a/ledger/shelley.go b/ledger/shelley.go index d126104b..15b83c01 100644 --- a/ledger/shelley.go +++ b/ledger/shelley.go @@ -55,6 +55,14 @@ func (b *ShelleyBlock) SlotNumber() uint64 { return b.Header.SlotNumber() } +func (b *ShelleyBlock) IssuerVkey() []byte { + return b.Header.IssuerVkey() +} + +func (b *ShelleyBlock) BlockBodySize() uint64 { + return b.Header.BlockBodySize() +} + func (b *ShelleyBlock) Era() Era { return eras[EraIdShelley] } @@ -81,16 +89,16 @@ type ShelleyBlockHeader struct { BlockNumber uint64 Slot uint64 PrevHash Blake2b256 - IssuerVkey interface{} - VrfKey interface{} + IssuerVkey []byte + VrfKey []byte NonceVrf interface{} LeaderVrf interface{} - BlockBodySize uint32 + BlockBodySize uint64 BlockBodyHash Blake2b256 - OpCertHotVkey interface{} + OpCertHotVkey []byte OpCertSequenceNumber uint32 OpCertKesPeriod uint32 - OpCertSignature interface{} + OpCertSignature []byte ProtoMajorVersion uint64 ProtoMinorVersion uint64 } @@ -116,6 +124,14 @@ func (h *ShelleyBlockHeader) SlotNumber() uint64 { return h.Body.Slot } +func (h *ShelleyBlockHeader) IssuerVkey() []byte { + return h.Body.IssuerVkey +} + +func (h *ShelleyBlockHeader) BlockBodySize() uint64 { + return h.Body.BlockBodySize +} + func (h *ShelleyBlockHeader) Era() Era { return eras[EraIdShelley] }