@@ -148,8 +148,10 @@ func (s *blockService) AddBlock(o blocks.Block) error {
148
148
149
149
log .Event (context .TODO (), "BlockService.BlockAdded" , c )
150
150
151
- if err := s .exchange .HasBlock (o ); err != nil {
152
- log .Errorf ("HasBlock: %s" , err .Error ())
151
+ if s .exchange != nil {
152
+ if err := s .exchange .HasBlock (o ); err != nil {
153
+ log .Errorf ("HasBlock: %s" , err .Error ())
154
+ }
153
155
}
154
156
155
157
return nil
@@ -184,10 +186,12 @@ func (s *blockService) AddBlocks(bs []blocks.Block) error {
184
186
return err
185
187
}
186
188
187
- for _ , o := range toput {
188
- log .Event (context .TODO (), "BlockService.BlockAdded" , o .Cid ())
189
- if err := s .exchange .HasBlock (o ); err != nil {
190
- log .Errorf ("HasBlock: %s" , err .Error ())
189
+ if s .exchange != nil {
190
+ for _ , o := range toput {
191
+ log .Event (context .TODO (), "BlockService.BlockAdded" , o .Cid ())
192
+ if err := s .exchange .HasBlock (o ); err != nil {
193
+ log .Errorf ("HasBlock: %s" , err .Error ())
194
+ }
191
195
}
192
196
}
193
197
return nil
@@ -250,7 +254,12 @@ func getBlock(ctx context.Context, c cid.Cid, bs blockstore.Blockstore, fget fun
250
254
// the returned channel.
251
255
// NB: No guarantees are made about order.
252
256
func (s * blockService ) GetBlocks (ctx context.Context , ks []cid.Cid ) <- chan blocks.Block {
253
- return getBlocks (ctx , ks , s .blockstore , s .getExchange ) // hash security
257
+ var f func () exchange.Fetcher
258
+ if s .exchange != nil {
259
+ f = s .getExchange
260
+ }
261
+
262
+ return getBlocks (ctx , ks , s .blockstore , f ) // hash security
254
263
}
255
264
256
265
func getBlocks (ctx context.Context , ks []cid.Cid , bs blockstore.Blockstore , fget func () exchange.Fetcher ) <- chan blocks.Block {
@@ -285,7 +294,7 @@ func getBlocks(ctx context.Context, ks []cid.Cid, bs blockstore.Blockstore, fget
285
294
}
286
295
}
287
296
288
- if len (misses ) == 0 {
297
+ if len (misses ) == 0 || fget == nil {
289
298
return
290
299
}
291
300
0 commit comments