@@ -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
1615type 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
182179func 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}
0 commit comments