@@ -75,13 +75,18 @@ func WithProofsCache(ac AccessorStreamer) AccessorStreamer {
75
75
}
76
76
}
77
77
78
- func (c * proofsCache ) Size (ctx context.Context ) int {
78
+ func (c * proofsCache ) Size (ctx context.Context ) ( int , error ) {
79
79
size := c .size .Load ()
80
- if size == 0 {
81
- size = int32 (c .inner .Size (ctx ))
82
- c .size .Store (size )
80
+ if size != 0 {
81
+ return int (size ), nil
83
82
}
84
- return int (size )
83
+
84
+ loaded , err := c .inner .Size (ctx )
85
+ if err != nil {
86
+ return 0 , fmt .Errorf ("loading size from inner accessor: %w" , err )
87
+ }
88
+ c .size .Store (int32 (loaded ))
89
+ return loaded , nil
85
90
}
86
91
87
92
func (c * proofsCache ) DataHash (ctx context.Context ) (share.DataHash , error ) {
@@ -121,7 +126,11 @@ func (c *proofsCache) Sample(ctx context.Context, idx shwap.SampleCoords) (shwap
121
126
122
127
// build share proof from proofs cached for given axis
123
128
share := ax .shares [shrIdx ]
124
- proofs , err := ipld .GetProof (ctx , ax .proofs , ax .root , shrIdx , c .Size (ctx ))
129
+ size , err := c .Size (ctx )
130
+ if err != nil {
131
+ return shwap.Sample {}, fmt .Errorf ("getting size: %w" , err )
132
+ }
133
+ proofs , err := ipld .GetProof (ctx , ax .proofs , ax .root , shrIdx , size )
125
134
if err != nil {
126
135
return shwap.Sample {}, fmt .Errorf ("building proof from cache: %w" , err )
127
136
}
@@ -159,9 +168,13 @@ func (c *proofsCache) axisWithProofs(ctx context.Context, axisType rsmt2d.Axis,
159
168
}
160
169
161
170
// build proofs from Shares and cache them
162
- adder := ipld .NewProofsAdder (c .Size (ctx ), true )
171
+ size , err := c .Size (ctx )
172
+ if err != nil {
173
+ return axisWithProofs {}, fmt .Errorf ("getting size: %w" , err )
174
+ }
175
+ adder := ipld .NewProofsAdder (size , true )
163
176
tree := wrapper .NewErasuredNamespacedMerkleTree (
164
- uint64 (c . Size ( ctx ) / 2 ),
177
+ uint64 (size / 2 ),
165
178
uint (axisIdx ),
166
179
nmt .NodeVisitor (adder .VisitFn ()),
167
180
)
@@ -221,7 +234,11 @@ func (c *proofsCache) RowNamespaceData(
221
234
return shwap.RowNamespaceData {}, err
222
235
}
223
236
224
- row , proof , err := ipld .GetSharesByNamespace (ctx , ax .proofs , ax .root , namespace , c .Size (ctx ))
237
+ size , err := c .Size (ctx )
238
+ if err != nil {
239
+ return shwap.RowNamespaceData {}, fmt .Errorf ("getting size: %w" , err )
240
+ }
241
+ row , proof , err := ipld .GetSharesByNamespace (ctx , ax .proofs , ax .root , namespace , size )
225
242
if err != nil {
226
243
return shwap.RowNamespaceData {}, fmt .Errorf ("shares by namespace %s for row %v: %w" , namespace .String (), rowIdx , err )
227
244
}
@@ -233,9 +250,13 @@ func (c *proofsCache) RowNamespaceData(
233
250
}
234
251
235
252
func (c * proofsCache ) Shares (ctx context.Context ) ([]libshare.Share , error ) {
236
- odsSize := c .Size (ctx ) / 2
253
+ size , err := c .Size (ctx )
254
+ if err != nil {
255
+ return nil , fmt .Errorf ("getting size: %w" , err )
256
+ }
257
+ odsSize := size / 2
237
258
shares := make ([]libshare.Share , 0 , odsSize * odsSize )
238
- for i := 0 ; i < c . Size ( ctx ) / 2 ; i ++ {
259
+ for i := 0 ; i < odsSize ; i ++ {
239
260
ax , err := c .AxisHalf (ctx , rsmt2d .Row , i )
240
261
if err != nil {
241
262
return nil , err
@@ -256,7 +277,11 @@ func (c *proofsCache) Shares(ctx context.Context) ([]libshare.Share, error) {
256
277
}
257
278
258
279
func (c * proofsCache ) Reader () (io.Reader , error ) {
259
- odsSize := c .Size (context .TODO ()) / 2
280
+ size , err := c .Size (context .TODO ())
281
+ if err != nil {
282
+ return nil , fmt .Errorf ("getting size: %w" , err )
283
+ }
284
+ odsSize := size / 2
260
285
reader := NewShareReader (odsSize , c .getShare )
261
286
return reader , nil
262
287
}
@@ -307,7 +332,11 @@ func (c *proofsCache) getAxisFromCache(axisType rsmt2d.Axis, axisIdx int) (axisW
307
332
308
333
func (c * proofsCache ) getShare (rowIdx , colIdx int ) (libshare.Share , error ) {
309
334
ctx := context .TODO ()
310
- odsSize := c .Size (ctx ) / 2
335
+ size , err := c .Size (ctx )
336
+ if err != nil {
337
+ return libshare.Share {}, fmt .Errorf ("getting size: %w" , err )
338
+ }
339
+ odsSize := size / 2
311
340
half , err := c .AxisHalf (ctx , rsmt2d .Row , rowIdx )
312
341
if err != nil {
313
342
return libshare.Share {}, fmt .Errorf ("reading axis half: %w" , err )
0 commit comments