Skip to content

Commit d77be01

Browse files
authored
fix: expose Byron block number (#970)
Signed-off-by: Aurora Gaffney <[email protected]>
1 parent 81ece9d commit d77be01

File tree

2 files changed

+9
-9
lines changed

2 files changed

+9
-9
lines changed

cmd/gouroboros/chainsync.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -279,17 +279,19 @@ func chainSyncRollForwardHandler(
279279
case ledger.BlockTypeByronEbb:
280280
byronEbbBlock := block.(*ledger.ByronEpochBoundaryBlock)
281281
fmt.Printf(
282-
"era = Byron (EBB), epoch = %d, slot = %d, id = %s\n",
282+
"era = Byron (EBB), epoch = %d, slot = %d, block_no = %d, id = %s\n",
283283
byronEbbBlock.BlockHeader.ConsensusData.Epoch,
284284
byronEbbBlock.SlotNumber(),
285+
byronEbbBlock.BlockNumber(),
285286
byronEbbBlock.Hash(),
286287
)
287288
case ledger.BlockTypeByronMain:
288289
byronBlock := block.(*ledger.ByronMainBlock)
289290
fmt.Printf(
290-
"era = Byron, epoch = %d, slot = %d, id = %s\n",
291+
"era = Byron, epoch = %d, slot = %d, block_no = %d, id = %s\n",
291292
byronBlock.BlockHeader.ConsensusData.SlotId.Epoch,
292293
byronBlock.SlotNumber(),
294+
byronBlock.BlockNumber(),
293295
byronBlock.Hash(),
294296
)
295297
default:
@@ -314,9 +316,9 @@ func blockFetchBlockHandler(
314316
) error {
315317
switch block := blockData.(type) {
316318
case *ledger.ByronEpochBoundaryBlock:
317-
fmt.Printf("era = Byron (EBB), epoch = %d, slot = %d, id = %s\n", block.BlockHeader.ConsensusData.Epoch, block.SlotNumber(), block.Hash())
319+
fmt.Printf("era = Byron (EBB), epoch = %d, slot = %d, block_no = %d, id = %s\n", block.BlockHeader.ConsensusData.Epoch, block.SlotNumber(), block.BlockNumber(), block.Hash())
318320
case *ledger.ByronMainBlock:
319-
fmt.Printf("era = Byron, epoch = %d, slot = %d, id = %s\n", block.BlockHeader.ConsensusData.SlotId.Epoch, block.SlotNumber(), block.Hash())
321+
fmt.Printf("era = Byron, epoch = %d, slot = %d, block_no = %d, id = %s\n", block.BlockHeader.ConsensusData.SlotId.Epoch, block.SlotNumber(), block.BlockNumber(), block.Hash())
320322
case ledger.Block:
321323
fmt.Printf("era = %s, slot = %d, block_no = %d, id = %s\n", block.Era().Name, block.SlotNumber(), block.BlockNumber(), block.Hash())
322324
}

ledger/byron/byron.go

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ type ByronMainBlockHeader struct {
6666
PubKey []byte
6767
Difficulty struct {
6868
cbor.StructAsArray
69-
Unknown uint64
69+
Value uint64
7070
}
7171
BlockSig []interface{}
7272
}
@@ -105,8 +105,7 @@ func (h *ByronMainBlockHeader) PrevHash() string {
105105
}
106106

107107
func (h *ByronMainBlockHeader) BlockNumber() uint64 {
108-
// Byron blocks don't store the block number in the block
109-
return 0
108+
return h.ConsensusData.Difficulty.Value
110109
}
111110

112111
func (h *ByronMainBlockHeader) SlotNumber() uint64 {
@@ -538,8 +537,7 @@ func (h *ByronEpochBoundaryBlockHeader) PrevHash() string {
538537
}
539538

540539
func (h *ByronEpochBoundaryBlockHeader) BlockNumber() uint64 {
541-
// Byron blocks don't store the block number in the block
542-
return 0
540+
return h.ConsensusData.Difficulty.Value
543541
}
544542

545543
func (h *ByronEpochBoundaryBlockHeader) SlotNumber() uint64 {

0 commit comments

Comments
 (0)