|
6 | 6 | "fmt" |
7 | 7 | "github.com/cloudstruct/go-cardano-ledger" |
8 | 8 | ouroboros "github.com/cloudstruct/go-ouroboros-network" |
9 | | - "github.com/cloudstruct/go-ouroboros-network/protocol/blockfetch" |
10 | 9 | "github.com/cloudstruct/go-ouroboros-network/protocol/chainsync" |
11 | 10 | "github.com/cloudstruct/go-ouroboros-network/protocol/common" |
12 | 11 | "os" |
@@ -86,15 +85,6 @@ func buildChainSyncConfig() chainsync.Config { |
86 | 85 | ) |
87 | 86 | } |
88 | 87 |
|
89 | | -func buildBlockFetchConfig() blockfetch.Config { |
90 | | - return blockfetch.NewConfig( |
91 | | - blockfetch.WithStartBatchFunc(blockFetchStartBatchHandler), |
92 | | - blockfetch.WithNoBlocksFunc(blockFetchNoBlocksHandler), |
93 | | - blockfetch.WithBlockFunc(blockFetchBlockHandler), |
94 | | - blockfetch.WithBatchDoneFunc(blockFetchBatchDoneHandler), |
95 | | - ) |
96 | | -} |
97 | | - |
98 | 88 | func testChainSync(f *globalFlags) { |
99 | 89 | chainSyncFlags := newChainSyncFlags() |
100 | 90 | err := chainSyncFlags.flagset.Parse(f.flagset.Args()[1:]) |
@@ -133,7 +123,6 @@ func testChainSync(f *globalFlags) { |
133 | 123 | ouroboros.WithErrorChan(errorChan), |
134 | 124 | ouroboros.WithNodeToNode(f.ntnProto), |
135 | 125 | ouroboros.WithKeepAlive(true), |
136 | | - ouroboros.WithBlockFetchConfig(buildBlockFetchConfig()), |
137 | 126 | ouroboros.WithChainSyncConfig(buildChainSyncConfig()), |
138 | 127 | ) |
139 | 128 | if err != nil { |
@@ -177,72 +166,46 @@ func chainSyncRollBackwardHandler(point common.Point, tip chainsync.Tip) error { |
177 | 166 | } |
178 | 167 |
|
179 | 168 | func chainSyncRollForwardHandler(blockType uint, blockData interface{}, tip chainsync.Tip) error { |
| 169 | + var block ledger.Block |
180 | 170 | switch v := blockData.(type) { |
181 | 171 | 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 | | - } |
| 172 | + block = v |
192 | 173 | case ledger.BlockHeader: |
193 | 174 | var blockSlot uint64 |
194 | 175 | var blockHash []byte |
195 | 176 | switch blockType { |
196 | 177 | case ledger.BLOCK_TYPE_BYRON_EBB: |
197 | 178 | byronEbbHeader := v.(*ledger.ByronEpochBoundaryBlockHeader) |
198 | | - //fmt.Printf("era = Byron (EBB), epoch = %d, id = %s\n", h.ConsensusData.Epoch, h.Hash()) |
199 | 179 | if syncState.byronEpochSlot > 0 { |
200 | 180 | syncState.byronEpochBaseSlot += syncState.byronEpochSlot + 1 |
201 | 181 | } |
202 | 182 | blockSlot = syncState.byronEpochBaseSlot |
203 | 183 | blockHash, _ = hex.DecodeString(byronEbbHeader.Hash()) |
204 | 184 | case ledger.BLOCK_TYPE_BYRON_MAIN: |
205 | 185 | 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 | 186 | syncState.byronEpochSlot = uint64(byronHeader.ConsensusData.SlotId.Slot) |
208 | 187 | blockSlot = syncState.byronEpochBaseSlot + syncState.byronEpochSlot |
209 | 188 | blockHash, _ = hex.DecodeString(byronHeader.Hash()) |
210 | 189 | default: |
211 | 190 | blockSlot = v.SlotNumber() |
212 | 191 | blockHash, _ = hex.DecodeString(v.Hash()) |
213 | 192 | } |
214 | | - if err := syncState.oConn.BlockFetch().Client.RequestRange([]interface{}{blockSlot, blockHash}, []interface{}{blockSlot, blockHash}); err != nil { |
215 | | - fmt.Printf("error calling RequestRange: %s\n", err) |
| 193 | + var err error |
| 194 | + block, err = syncState.oConn.BlockFetch().Client.GetBlock(common.NewPoint(blockSlot, blockHash)) |
| 195 | + if err != nil { |
216 | 196 | return err |
217 | 197 | } |
218 | 198 | } |
219 | | - return nil |
220 | | -} |
221 | | - |
222 | | -func blockFetchStartBatchHandler() error { |
223 | | - return nil |
224 | | -} |
225 | | - |
226 | | -func blockFetchNoBlocksHandler() error { |
227 | | - fmt.Printf("blockFetchNoBlocksHandler()\n") |
228 | | - return nil |
229 | | -} |
230 | | - |
231 | | -func blockFetchBlockHandler(blockType uint, blockData interface{}) error { |
| 199 | + // Display block info |
232 | 200 | switch blockType { |
233 | 201 | case ledger.BLOCK_TYPE_BYRON_EBB: |
234 | | - b := blockData.(*ledger.ByronEpochBoundaryBlock) |
235 | | - fmt.Printf("era = Byron (EBB), id = %s\n", b.Hash()) |
| 202 | + byronEbbBlock := block.(*ledger.ByronEpochBoundaryBlock) |
| 203 | + fmt.Printf("era = Byron (EBB), epoch = %d, id = %s\n", byronEbbBlock.Header.ConsensusData.Epoch, byronEbbBlock.Hash()) |
236 | 204 | case ledger.BLOCK_TYPE_BYRON_MAIN: |
237 | | - b := blockData.(*ledger.ByronMainBlock) |
238 | | - fmt.Printf("era = Byron, epoch = %d, slot = %d, id = %s\n", b.Header.ConsensusData.SlotId.Epoch, b.SlotNumber(), b.Hash()) |
| 205 | + byronBlock := block.(*ledger.ByronMainBlock) |
| 206 | + fmt.Printf("era = Byron, epoch = %d, slot = %d, id = %s\n", byronBlock.Header.ConsensusData.SlotId.Epoch, byronBlock.SlotNumber(), byronBlock.Hash()) |
239 | 207 | default: |
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()) |
| 208 | + fmt.Printf("era = %s, slot = %d, block_no = %d, id = %s\n", block.Era().Name, block.SlotNumber(), block.BlockNumber(), block.Hash()) |
242 | 209 | } |
243 | 210 | return nil |
244 | 211 | } |
245 | | - |
246 | | -func blockFetchBatchDoneHandler() error { |
247 | | - return nil |
248 | | -} |
0 commit comments