Skip to content

Commit

Permalink
fix(shwap/bitswap): close acccessor in Blockstore (#3535)
Browse files Browse the repository at this point in the history
  • Loading branch information
Wondertan authored Jul 23, 2024
1 parent d807843 commit 5aaa106
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
8 changes: 4 additions & 4 deletions share/shwap/p2p/bitswap/block_fetch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ func TestFetch_Duplicates(t *testing.T) {
func newExchangeOverEDS(ctx context.Context, t *testing.T, rsmt2d *rsmt2d.ExtendedDataSquare) exchange.SessionExchange {
bstore := &Blockstore{
Getter: testAccessorGetter{
Accessor: &eds.Rsmt2D{ExtendedDataSquare: rsmt2d},
AccessorStreamer: &eds.Rsmt2D{ExtendedDataSquare: rsmt2d},
},
}
return newExchange(ctx, t, bstore)
Expand Down Expand Up @@ -163,11 +163,11 @@ func newClient(ctx context.Context, host host.Host, store blockstore.Blockstore)
}

type testAccessorGetter struct {
eds.Accessor
eds.AccessorStreamer
}

func (t testAccessorGetter) GetByHeight(context.Context, uint64) (eds.Accessor, error) {
return t.Accessor, nil
func (t testAccessorGetter) GetByHeight(context.Context, uint64) (eds.AccessorStreamer, error) {
return t.AccessorStreamer, nil
}

type testFetcher struct {
Expand Down
7 changes: 6 additions & 1 deletion share/shwap/p2p/bitswap/block_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
// network height.
type AccessorGetter interface {
// GetByHeight returns an Accessor by its height.
GetByHeight(ctx context.Context, height uint64) (eds.Accessor, error)
GetByHeight(ctx context.Context, height uint64) (eds.AccessorStreamer, error)
}

// Blockstore implements generalized Bitswap compatible storage over Shwap containers
Expand All @@ -38,6 +38,11 @@ func (b *Blockstore) getBlock(ctx context.Context, cid cid.Cid) (blocks.Block, e
if err != nil {
return nil, fmt.Errorf("getting EDS Accessor for height %v: %w", blk.Height(), err)
}
defer func() {
if err := eds.Close(); err != nil {
log.Warnf("failed to close EDS accessor for height %v: %s", blk.Height(), err)
}
}()

if err = blk.Populate(ctx, eds); err != nil {
return nil, fmt.Errorf("failed to populate Shwap Block on height %v for %s: %w", blk.Height(), spec.String(), err)
Expand Down

0 comments on commit 5aaa106

Please sign in to comment.