@@ -149,8 +149,10 @@ func (s *blockService) AddBlock(o blocks.Block) error {
149
149
150
150
log .Event (context .TODO (), "BlockService.BlockAdded" , c )
151
151
152
- if err := s .exchange .HasBlock (o ); err != nil {
153
- log .Errorf ("HasBlock: %s" , err .Error ())
152
+ if s .exchange != nil {
153
+ if err := s .exchange .HasBlock (o ); err != nil {
154
+ log .Errorf ("HasBlock: %s" , err .Error ())
155
+ }
154
156
}
155
157
156
158
return nil
@@ -189,10 +191,12 @@ func (s *blockService) AddBlocks(bs []blocks.Block) error {
189
191
return err
190
192
}
191
193
192
- for _ , o := range toput {
193
- log .Event (context .TODO (), "BlockService.BlockAdded" , o .Cid ())
194
- if err := s .exchange .HasBlock (o ); err != nil {
195
- log .Errorf ("HasBlock: %s" , err .Error ())
194
+ if s .exchange != nil {
195
+ for _ , o := range toput {
196
+ log .Event (context .TODO (), "BlockService.BlockAdded" , o .Cid ())
197
+ if err := s .exchange .HasBlock (o ); err != nil {
198
+ log .Errorf ("HasBlock: %s" , err .Error ())
199
+ }
196
200
}
197
201
}
198
202
return nil
@@ -255,7 +259,12 @@ func getBlock(ctx context.Context, c cid.Cid, bs blockstore.Blockstore, fget fun
255
259
// the returned channel.
256
260
// NB: No guarantees are made about order.
257
261
func (s * blockService ) GetBlocks (ctx context.Context , ks []cid.Cid ) <- chan blocks.Block {
258
- return getBlocks (ctx , ks , s .blockstore , s .getExchange ) // hash security
262
+ var f func () exchange.Fetcher
263
+ if s .exchange != nil {
264
+ f = s .getExchange
265
+ }
266
+
267
+ return getBlocks (ctx , ks , s .blockstore , f ) // hash security
259
268
}
260
269
261
270
func getBlocks (ctx context.Context , ks []cid.Cid , bs blockstore.Blockstore , fget func () exchange.Fetcher ) <- chan blocks.Block {
@@ -290,7 +299,7 @@ func getBlocks(ctx context.Context, ks []cid.Cid, bs blockstore.Blockstore, fget
290
299
}
291
300
}
292
301
293
- if len (misses ) == 0 {
302
+ if len (misses ) == 0 || fget == nil {
294
303
return
295
304
}
296
305
0 commit comments