@@ -149,8 +149,9 @@ func (c *client) Submit(ctx context.Context, data [][]byte, gasPrice float64, na
149149}
150150
151151// Retrieve retrieves blobs from the DA layer at the specified height and namespace.
152- // Each request (GetIDs and each batch of Get) has its own independent timeout,
153- // ensuring that retrieval of heights with many blobs doesn't fail due to an overall timeout.
152+ // Each request (GetIDs and each batch of Get) has its own per-request timeout
153+ // while still respecting parent cancellations, ensuring long retrievals don't ignore
154+ // upstream deadlines.
154155func (c * client ) Retrieve (ctx context.Context , height uint64 , namespace []byte ) coreda.ResultRetrieve {
155156 // Check for parent context cancellation before starting
156157 if err := ctx .Err (); err != nil {
@@ -164,8 +165,8 @@ func (c *client) Retrieve(ctx context.Context, height uint64, namespace []byte)
164165 }
165166 }
166167
167- // 1. Get IDs with per-request timeout (independent of parent context deadline)
168- getIDsCtx , cancel := context .WithTimeout (context . Background () , c .defaultTimeout )
168+ // 1. Get IDs with per-request timeout that still respects parent cancellation
169+ getIDsCtx , cancel := context .WithTimeout (ctx , c .defaultTimeout )
169170 idsResult , err := c .da .GetIDs (getIDsCtx , height , namespace )
170171 cancel ()
171172 if err != nil {
@@ -229,7 +230,7 @@ func (c *client) Retrieve(ctx context.Context, height uint64, namespace []byte)
229230 }
230231
231232 // 2. Get Blobs using the retrieved IDs in batches
232- // Each batch has its own independent timeout to ensure large retrievals don't timeout
233+ // Each batch has its own timeout while keeping the link to the parent context
233234 batchSize := 100
234235 blobs := make ([][]byte , 0 , len (idsResult .IDs ))
235236 for i := 0 ; i < len (idsResult .IDs ); i += batchSize {
@@ -248,9 +249,8 @@ func (c *client) Retrieve(ctx context.Context, height uint64, namespace []byte)
248249
249250 end := min (i + batchSize , len (idsResult .IDs ))
250251
251- // Use context.Background() for timeout to ensure each batch gets a fresh timeout
252- // independent of any parent context deadline
253- getBlobsCtx , cancel := context .WithTimeout (context .Background (), c .defaultTimeout )
252+ // Derive timeout from parent so cancellation still propagates
253+ getBlobsCtx , cancel := context .WithTimeout (ctx , c .defaultTimeout )
254254 batchBlobs , err := c .da .Get (getBlobsCtx , idsResult .IDs [i :end ], namespace )
255255 cancel ()
256256 if err != nil {
0 commit comments