Skip to content
This repository has been archived by the owner on Jun 27, 2023. It is now read-only.

Commit

Permalink
write blocks retrieved from the exchange to the blockstore
Browse files Browse the repository at this point in the history
This follows the change in bitswap where that responsibility was removed.
  • Loading branch information
MichaelMure committed Jul 8, 2022
1 parent 4f6b81e commit c519ec9
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions blockservice.go
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,11 @@ func getBlock(ctx context.Context, c cid.Cid, bs blockstore.Blockstore, fget fun
if err != nil {
return nil, err
}
// also write in the blockstore for caching
err = bs.Put(ctx, blk)
if err != nil {
return nil, err
}
logger.Debugf("BlockService.BlockFetched %s", c)
return blk, nil
}
Expand Down Expand Up @@ -326,6 +331,15 @@ func getBlocks(ctx context.Context, ks []cid.Cid, bs blockstore.Blockstore, fget

for b := range rblocks {
logger.Debugf("BlockService.BlockFetched %s", b.Cid())

// also write in the blockstore for caching
// TODO: for performance reason, it might make sense to batch those writes
err = bs.Put(ctx, b)
if err != nil {
logger.Errorf("could not write blocks from the network to the blockstore: %s", err)
return
}

select {
case out <- b:
case <-ctx.Done():
Expand Down

0 comments on commit c519ec9

Please sign in to comment.