Skip to content

Commit 410f7b4

Browse files
committed
chore: update cloudstruct/go-cardano-ledger to v0.5.0
This also updates the test program to take advantage of the new ledger version
1 parent 87808a1 commit 410f7b4

File tree

3 files changed

+30
-68
lines changed

3 files changed

+30
-68
lines changed

cmd/go-ouroboros-network/chainsync.go

Lines changed: 27 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,11 @@ import (
99
"github.com/cloudstruct/go-ouroboros-network/protocol/blockfetch"
1010
"github.com/cloudstruct/go-ouroboros-network/protocol/chainsync"
1111
"github.com/cloudstruct/go-ouroboros-network/protocol/common"
12-
"github.com/cloudstruct/go-ouroboros-network/utils"
1312
"os"
1413
)
1514

1615
type chainSyncState struct {
1716
oConn *ouroboros.Ouroboros
18-
nodeToNode bool
1917
byronEpochBaseSlot uint64
2018
byronEpochSlot uint64
2119
}
@@ -148,7 +146,6 @@ func testChainSync(f *globalFlags) {
148146
}
149147

150148
syncState.oConn = o
151-
syncState.nodeToNode = f.ntnProto
152149
var point common.Point
153150
if chainSyncFlags.tip {
154151
tip, err := o.ChainSync().Client.GetCurrentTip()
@@ -180,64 +177,44 @@ func chainSyncRollBackwardHandler(point common.Point, tip chainsync.Tip) error {
180177
}
181178

182179
func chainSyncRollForwardHandler(blockType uint, blockData interface{}, tip chainsync.Tip) error {
183-
if syncState.nodeToNode {
180+
switch v := blockData.(type) {
181+
case ledger.Block:
182+
switch blockType {
183+
case ledger.BLOCK_TYPE_BYRON_EBB:
184+
byronEbbBlock := v.(*ledger.ByronEpochBoundaryBlock)
185+
fmt.Printf("era = Byron (EBB), epoch = %d, id = %s\n", byronEbbBlock.Header.ConsensusData.Epoch, byronEbbBlock.Hash())
186+
case ledger.BLOCK_TYPE_BYRON_MAIN:
187+
byronBlock := v.(*ledger.ByronMainBlock)
188+
fmt.Printf("era = Byron, epoch = %d, slot = %d, id = %s\n", byronBlock.Header.ConsensusData.SlotId.Epoch, byronBlock.SlotNumber(), byronBlock.Hash())
189+
default:
190+
fmt.Printf("era = %s, slot = %d, block_no = %d, id = %s\n", v.Era().Name, v.SlotNumber(), v.BlockNumber(), v.Hash())
191+
}
192+
case ledger.BlockHeader:
184193
var blockSlot uint64
185194
var blockHash []byte
186195
switch blockType {
187196
case ledger.BLOCK_TYPE_BYRON_EBB:
188-
h := blockData.(*ledger.ByronEpochBoundaryBlockHeader)
189-
//fmt.Printf("era = Byron (EBB), epoch = %d, id = %s\n", h.ConsensusData.Epoch, h.Id())
197+
byronEbbHeader := v.(*ledger.ByronEpochBoundaryBlockHeader)
198+
//fmt.Printf("era = Byron (EBB), epoch = %d, id = %s\n", h.ConsensusData.Epoch, h.Hash())
190199
if syncState.byronEpochSlot > 0 {
191200
syncState.byronEpochBaseSlot += syncState.byronEpochSlot + 1
192201
}
193202
blockSlot = syncState.byronEpochBaseSlot
194-
blockHash, _ = hex.DecodeString(h.Id())
203+
blockHash, _ = hex.DecodeString(byronEbbHeader.Hash())
195204
case ledger.BLOCK_TYPE_BYRON_MAIN:
196-
h := blockData.(*ledger.ByronMainBlockHeader)
197-
//fmt.Printf("era = Byron, epoch = %d, slot = %d, id = %s\n", h.ConsensusData.SlotId.Epoch, h.ConsensusData.SlotId.Slot, h.Id())
198-
syncState.byronEpochSlot = uint64(h.ConsensusData.SlotId.Slot)
205+
byronHeader := v.(*ledger.ByronMainBlockHeader)
206+
//fmt.Printf("era = Byron, epoch = %d, slot = %d, id = %s\n", h.ConsensusData.SlotId.Epoch, h.ConsensusData.SlotId.Slot, h.Hash())
207+
syncState.byronEpochSlot = uint64(byronHeader.ConsensusData.SlotId.Slot)
199208
blockSlot = syncState.byronEpochBaseSlot + syncState.byronEpochSlot
200-
blockHash, _ = hex.DecodeString(h.Id())
201-
case ledger.BLOCK_TYPE_SHELLEY, ledger.BLOCK_TYPE_ALLEGRA, ledger.BLOCK_TYPE_MARY, ledger.BLOCK_TYPE_ALONZO:
202-
h := blockData.(*ledger.ShelleyBlockHeader)
203-
blockSlot = h.Body.Slot
204-
blockHash, _ = hex.DecodeString(h.Id())
205-
case ledger.BLOCK_TYPE_BABBAGE:
206-
h := blockData.(*ledger.BabbageBlockHeader)
207-
blockSlot = h.Body.Slot
208-
blockHash, _ = hex.DecodeString(h.Id())
209+
blockHash, _ = hex.DecodeString(byronHeader.Hash())
210+
default:
211+
blockSlot = v.SlotNumber()
212+
blockHash, _ = hex.DecodeString(v.Hash())
209213
}
210214
if err := syncState.oConn.BlockFetch().Client.RequestRange([]interface{}{blockSlot, blockHash}, []interface{}{blockSlot, blockHash}); err != nil {
211215
fmt.Printf("error calling RequestRange: %s\n", err)
212216
return err
213217
}
214-
} else {
215-
switch blockType {
216-
case ledger.BLOCK_TYPE_BYRON_EBB:
217-
b := blockData.(*ledger.ByronEpochBoundaryBlock)
218-
fmt.Printf("era = Byron (EBB), epoch = %d, id = %s\n", b.Header.ConsensusData.Epoch, b.Id())
219-
case ledger.BLOCK_TYPE_BYRON_MAIN:
220-
b := blockData.(*ledger.ByronMainBlock)
221-
fmt.Printf("era = Byron, epoch = %d, slot = %d, id = %s\n", b.Header.ConsensusData.SlotId.Epoch, b.Header.ConsensusData.SlotId.Slot, b.Id())
222-
case ledger.BLOCK_TYPE_SHELLEY:
223-
b := blockData.(*ledger.ShelleyBlock)
224-
fmt.Printf("era = Shelley, slot = %d, block_no = %d, id = %s\n", b.Header.Body.Slot, b.Header.Body.BlockNumber, b.Id())
225-
case ledger.BLOCK_TYPE_ALLEGRA:
226-
b := blockData.(*ledger.AllegraBlock)
227-
fmt.Printf("era = Allegra, slot = %d, block_no = %d, id = %s\n", b.Header.Body.Slot, b.Header.Body.BlockNumber, b.Id())
228-
case ledger.BLOCK_TYPE_MARY:
229-
b := blockData.(*ledger.MaryBlock)
230-
fmt.Printf("era = Mary, slot = %d, block_no = %d, id = %s\n", b.Header.Body.Slot, b.Header.Body.BlockNumber, b.Id())
231-
case ledger.BLOCK_TYPE_ALONZO:
232-
b := blockData.(*ledger.AlonzoBlock)
233-
fmt.Printf("era = Alonzo, slot = %d, block_no = %d, id = %s\n", b.Header.Body.Slot, b.Header.Body.BlockNumber, b.Id())
234-
case ledger.BLOCK_TYPE_BABBAGE:
235-
b := blockData.(*ledger.BabbageBlock)
236-
fmt.Printf("era = Babbage, slot = %d, block_no = %d, id = %s\n", b.Header.Body.Slot, b.Header.Body.BlockNumber, b.Id())
237-
default:
238-
fmt.Printf("unsupported (so far) block type %d\n", blockType)
239-
fmt.Printf("%s\n", utils.DumpCborStructure(blockData, ""))
240-
}
241218
}
242219
return nil
243220
}
@@ -255,28 +232,13 @@ func blockFetchBlockHandler(blockType uint, blockData interface{}) error {
255232
switch blockType {
256233
case ledger.BLOCK_TYPE_BYRON_EBB:
257234
b := blockData.(*ledger.ByronEpochBoundaryBlock)
258-
fmt.Printf("era = Byron (EBB), id = %s\n", b.Id())
235+
fmt.Printf("era = Byron (EBB), id = %s\n", b.Hash())
259236
case ledger.BLOCK_TYPE_BYRON_MAIN:
260237
b := blockData.(*ledger.ByronMainBlock)
261-
fmt.Printf("era = Byron, epoch = %d, slot = %d, id = %s\n", b.Header.ConsensusData.SlotId.Epoch, b.Header.ConsensusData.SlotId.Slot, b.Id())
262-
case ledger.BLOCK_TYPE_SHELLEY:
263-
b := blockData.(*ledger.ShelleyBlock)
264-
fmt.Printf("era = Shelley, slot = %d, block_no = %d, id = %s\n", b.Header.Body.Slot, b.Header.Body.BlockNumber, b.Id())
265-
case ledger.BLOCK_TYPE_ALLEGRA:
266-
b := blockData.(*ledger.AllegraBlock)
267-
fmt.Printf("era = Allegra, slot = %d, block_no = %d, id = %s\n", b.Header.Body.Slot, b.Header.Body.BlockNumber, b.Id())
268-
case ledger.BLOCK_TYPE_MARY:
269-
b := blockData.(*ledger.MaryBlock)
270-
fmt.Printf("era = Mary, slot = %d, block_no = %d, id = %s\n", b.Header.Body.Slot, b.Header.Body.BlockNumber, b.Id())
271-
case ledger.BLOCK_TYPE_ALONZO:
272-
b := blockData.(*ledger.AlonzoBlock)
273-
fmt.Printf("era = Alonzo, slot = %d, block_no = %d, id = %s\n", b.Header.Body.Slot, b.Header.Body.BlockNumber, b.Id())
274-
case ledger.BLOCK_TYPE_BABBAGE:
275-
b := blockData.(*ledger.BabbageBlock)
276-
fmt.Printf("era = Babbage, slot = %d, block_no = %d, id = %s\n", b.Header.Body.Slot, b.Header.Body.BlockNumber, b.Id())
238+
fmt.Printf("era = Byron, epoch = %d, slot = %d, id = %s\n", b.Header.ConsensusData.SlotId.Epoch, b.SlotNumber(), b.Hash())
277239
default:
278-
fmt.Printf("unsupported (so far) block type %d\n", blockType)
279-
fmt.Printf("%s\n", utils.DumpCborStructure(blockData, ""))
240+
b := blockData.(ledger.Block)
241+
fmt.Printf("era = %s, slot = %d, block_no = %d, id = %s\n", b.Era().Name, b.SlotNumber(), b.BlockNumber(), b.Hash())
280242
}
281243
return nil
282244
}

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ module github.com/cloudstruct/go-ouroboros-network
33
go 1.17
44

55
require (
6-
github.com/cloudstruct/go-cardano-ledger v0.4.0
6+
github.com/cloudstruct/go-cardano-ledger v0.5.0
77
github.com/fxamacker/cbor/v2 v2.4.0
88
golang.org/x/crypto v0.0.0-20220824171710-5757bc0c5503
99
)

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
github.com/cloudstruct/go-cardano-ledger v0.4.0 h1:4BZvwZSM82r/Bt+W4XHTstJEABg0jXcougcZgDmZBo0=
2-
github.com/cloudstruct/go-cardano-ledger v0.4.0/go.mod h1:EBB9JG+3nBs3IV0p751yz1468XYkzJce1/A2X+xH8L8=
1+
github.com/cloudstruct/go-cardano-ledger v0.5.0 h1:Qrib0BejPHJgZqndI5Ils6J/+TeuvXxJWx6nDChrsxc=
2+
github.com/cloudstruct/go-cardano-ledger v0.5.0/go.mod h1:EBB9JG+3nBs3IV0p751yz1468XYkzJce1/A2X+xH8L8=
33
github.com/fxamacker/cbor/v2 v2.4.0 h1:ri0ArlOR+5XunOP8CRUowT0pSJOwhW098ZCUyskZD88=
44
github.com/fxamacker/cbor/v2 v2.4.0/go.mod h1:TA1xS00nchWmaBnEIxPSE5oHLuJBAVvqrtAnWBwBCVo=
55
github.com/x448/float16 v0.8.4 h1:qLwI1I70+NjRFUR3zs1JPUCgaCXSh3SW62uAKT1mSBM=

0 commit comments

Comments
 (0)