@@ -32,10 +32,10 @@ func handleChunk(
32
32
errs := make ([]error , 0 )
33
33
34
34
// Get block data from the node
35
- blocks , err := getBlocksFromBatch (info .chunkRange , client )
35
+ blocks , err := getBlocksFromBatch (ctx , info .chunkRange , client )
36
36
errs = append (errs , err )
37
37
38
- results , err := getTxResultFromBatch (blocks , client )
38
+ results , err := getTxResultFromBatch (ctx , blocks , client )
39
39
errs = append (errs , err )
40
40
41
41
return & chunk {
@@ -61,7 +61,7 @@ func handleChunk(
61
61
// getBlocksFromBatch gets the blocks using batch requests.
62
62
// In case of encountering an error during fetching (remote temporarily closed, batch error...),
63
63
// the fetch is attempted again using sequential block fetches
64
- func getBlocksFromBatch (chunkRange chunkRange , client Client ) ([]* types.Block , error ) {
64
+ func getBlocksFromBatch (ctx context. Context , chunkRange chunkRange , client Client ) ([]* types.Block , error ) {
65
65
var (
66
66
batch = client .CreateBatch ()
67
67
fetchedBlocks = make ([]* types.Block , 0 )
@@ -82,7 +82,7 @@ func getBlocksFromBatch(chunkRange chunkRange, client Client) ([]*types.Block, e
82
82
blocksRaw , err := batch .Execute (context .Background ())
83
83
if err != nil {
84
84
// Try to fetch sequentially
85
- return getBlocksSequentially (chunkRange , client )
85
+ return getBlocksSequentially (ctx , chunkRange , client )
86
86
}
87
87
88
88
// Extract the blocks
@@ -100,15 +100,15 @@ func getBlocksFromBatch(chunkRange chunkRange, client Client) ([]*types.Block, e
100
100
}
101
101
102
102
// getBlocksSequentially attempts to fetch blocks from the client, using sequential requests
103
- func getBlocksSequentially (chunkRange chunkRange , client Client ) ([]* types.Block , error ) {
103
+ func getBlocksSequentially (ctx context. Context , chunkRange chunkRange , client Client ) ([]* types.Block , error ) {
104
104
var (
105
105
errs = make ([]error , 0 )
106
106
blocks = make ([]* types.Block , 0 )
107
107
)
108
108
109
109
for blockNum := chunkRange .from ; blockNum <= chunkRange .to ; blockNum ++ {
110
110
// Get block info from the chain
111
- block , err := client .GetBlock (blockNum )
111
+ block , err := client .GetBlock (ctx , blockNum )
112
112
if err != nil {
113
113
errs = append (errs , fmt .Errorf ("unable to get block %d, %w" , blockNum , err ))
114
114
@@ -124,7 +124,7 @@ func getBlocksSequentially(chunkRange chunkRange, client Client) ([]*types.Block
124
124
// getTxResultFromBatch gets the tx results using batch requests.
125
125
// In case of encountering an error during fetching (remote temporarily closed, batch error...),
126
126
// the fetch is attempted again using sequential tx result fetches
127
- func getTxResultFromBatch (blocks []* types.Block , client Client ) ([][]* types.TxResult , error ) {
127
+ func getTxResultFromBatch (ctx context. Context , blocks []* types.Block , client Client ) ([][]* types.TxResult , error ) {
128
128
var (
129
129
batch = client .CreateBatch ()
130
130
fetchedResults = make ([][]* types.TxResult , len (blocks ))
@@ -158,7 +158,7 @@ func getTxResultFromBatch(blocks []*types.Block, client Client) ([][]*types.TxRe
158
158
blockResultsRaw , err := batch .Execute (context .Background ())
159
159
if err != nil {
160
160
// Try to fetch sequentially
161
- return getTxResultsSequentially (blocks , client )
161
+ return getTxResultsSequentially (ctx , blocks , client )
162
162
}
163
163
164
164
indexOfBlockHeight := make (map [int64 ]int , len (blocks ))
@@ -198,7 +198,7 @@ func getTxResultFromBatch(blocks []*types.Block, client Client) ([][]*types.TxRe
198
198
}
199
199
200
200
// getTxResultsSequentially attempts to fetch tx results from the client, using sequential requests
201
- func getTxResultsSequentially (blocks []* types.Block , client Client ) ([][]* types.TxResult , error ) {
201
+ func getTxResultsSequentially (ctx context. Context , blocks []* types.Block , client Client ) ([][]* types.TxResult , error ) {
202
202
var (
203
203
errs = make ([]error , 0 )
204
204
results = make ([][]* types.TxResult , len (blocks ))
@@ -210,7 +210,7 @@ func getTxResultsSequentially(blocks []*types.Block, client Client) ([][]*types.
210
210
}
211
211
212
212
// Get the transaction execution results
213
- blockResults , err := client .GetBlockResults (uint64 (block .Height ))
213
+ blockResults , err := client .GetBlockResults (ctx , uint64 (block .Height ))
214
214
if err != nil {
215
215
errs = append (
216
216
errs ,
0 commit comments