@@ -148,8 +148,10 @@ func (s *blockService) AddBlock(o blocks.Block) error {
148148
149149 log .Event (context .TODO (), "BlockService.BlockAdded" , c )
150150
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+ }
153155 }
154156
155157 return nil
@@ -184,10 +186,12 @@ func (s *blockService) AddBlocks(bs []blocks.Block) error {
184186 return err
185187 }
186188
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+ }
191195 }
192196 }
193197 return nil
@@ -250,7 +254,12 @@ func getBlock(ctx context.Context, c cid.Cid, bs blockstore.Blockstore, fget fun
250254// the returned channel.
251255// NB: No guarantees are made about order.
252256func (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
254263}
255264
256265func 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
285294 }
286295 }
287296
288- if len (misses ) == 0 {
297+ if len (misses ) == 0 || fget == nil {
289298 return
290299 }
291300
0 commit comments