5
5
"context"
6
6
"errors"
7
7
"fmt"
8
- "strings"
9
8
"time"
10
9
11
10
"github.com/rs/zerolog"
@@ -72,10 +71,6 @@ func (r *DARetriever) RetrieveFromDA(ctx context.Context, daHeight uint64) ([]co
72
71
73
72
blobsResp , err := r .fetchBlobs (ctx , daHeight )
74
73
if err != nil {
75
- if strings .Contains (err .Error (), coreda .ErrHeightFromFuture .Error ()) {
76
- return nil , fmt .Errorf ("%w: height from future" , coreda .ErrHeightFromFuture )
77
- }
78
-
79
74
return nil , err
80
75
}
81
76
@@ -84,11 +79,6 @@ func (r *DARetriever) RetrieveFromDA(ctx context.Context, daHeight uint64) ([]co
84
79
return nil , err
85
80
}
86
81
87
- if blobsResp .Code == coreda .StatusNotFound {
88
- r .logger .Debug ().Uint64 ("da_height" , daHeight ).Msg ("no blob data found" )
89
- return nil , coreda .ErrBlobNotFound
90
- }
91
-
92
82
r .logger .Debug ().Int ("blobs" , len (blobsResp .Data )).Uint64 ("da_height" , daHeight ).Msg ("retrieved blob data" )
93
83
return r .processBlobs (ctx , blobsResp .Data , daHeight ), nil
94
84
}
@@ -107,13 +97,15 @@ func (r *DARetriever) fetchBlobs(ctx context.Context, daHeight uint64) (coreda.R
107
97
108
98
// Validate responses
109
99
headerErr := r .validateBlobResponse (headerRes , daHeight )
110
- dataErr := r .validateBlobResponse (dataRes , daHeight )
100
+ // ignoring error not found, as data can have data
101
+ if headerErr != nil && ! errors .Is (headerErr , coreda .ErrBlobNotFound ) {
102
+ return headerRes , headerErr
103
+ }
111
104
112
- // Handle errors
113
- if errors .Is (headerErr , coreda .ErrHeightFromFuture ) || errors .Is (dataErr , coreda .ErrHeightFromFuture ) {
114
- return coreda.ResultRetrieve {
115
- BaseResult : coreda.BaseResult {Code : coreda .StatusHeightFromFuture },
116
- }, fmt .Errorf ("%w: height from future" , coreda .ErrHeightFromFuture )
105
+ dataErr := r .validateBlobResponse (dataRes , daHeight )
106
+ // ignoring error not found, as header can have data
107
+ if dataErr != nil && ! errors .Is (dataErr , coreda .ErrBlobNotFound ) {
108
+ return dataRes , dataErr
117
109
}
118
110
119
111
// Combine successful results
@@ -127,28 +119,35 @@ func (r *DARetriever) fetchBlobs(ctx context.Context, daHeight uint64) (coreda.R
127
119
128
120
if headerRes .Code == coreda .StatusSuccess {
129
121
combinedResult .Data = append (combinedResult .Data , headerRes .Data ... )
130
- if len (headerRes .IDs ) > 0 {
131
- combinedResult .IDs = append (combinedResult .IDs , headerRes .IDs ... )
132
- }
122
+ combinedResult .IDs = append (combinedResult .IDs , headerRes .IDs ... )
133
123
}
134
124
135
125
if dataRes .Code == coreda .StatusSuccess {
136
126
combinedResult .Data = append (combinedResult .Data , dataRes .Data ... )
137
- if len (dataRes .IDs ) > 0 {
138
- combinedResult .IDs = append (combinedResult .IDs , dataRes .IDs ... )
139
- }
127
+ combinedResult .IDs = append (combinedResult .IDs , dataRes .IDs ... )
128
+ }
129
+
130
+ // Re-throw error not found if both were not found.
131
+ if len (combinedResult .Data ) == 0 && len (combinedResult .IDs ) == 0 {
132
+ r .logger .Debug ().Uint64 ("da_height" , daHeight ).Msg ("no blob data found" )
133
+ combinedResult .Code = coreda .StatusNotFound
134
+ combinedResult .Message = coreda .ErrBlobNotFound .Error ()
135
+ return combinedResult , coreda .ErrBlobNotFound
140
136
}
141
137
142
138
return combinedResult , nil
143
139
}
144
140
145
141
// validateBlobResponse validates a blob response from DA layer
142
+ // those are the only error code returned by da.RetrieveWithHelpers
146
143
func (r * DARetriever ) validateBlobResponse (res coreda.ResultRetrieve , daHeight uint64 ) error {
147
144
switch res .Code {
148
145
case coreda .StatusError :
149
146
return fmt .Errorf ("DA retrieval failed: %s" , res .Message )
150
147
case coreda .StatusHeightFromFuture :
151
148
return fmt .Errorf ("%w: height from future" , coreda .ErrHeightFromFuture )
149
+ case coreda .StatusNotFound :
150
+ return fmt .Errorf ("%w: blob not found" , coreda .ErrBlobNotFound )
152
151
case coreda .StatusSuccess :
153
152
r .logger .Debug ().Uint64 ("da_height" , daHeight ).Msg ("successfully retrieved from DA" )
154
153
return nil
0 commit comments