Skip to content

Commit

Permalink
fix: gateway/blocks-backend: GetBlock should not perform IPLD decoding (
Browse files Browse the repository at this point in the history
#845)

* gateway/blocks-backend: GetBlock should not perform IPLD decoding #673
  • Loading branch information
gsergey418alt authored Feb 18, 2025
1 parent 7e1c654 commit 7c3ac0d
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ The following emojis are used to highlight certain changes:

- Fix memory leaks due to not cleaning up wantlists [#829](https://github.com/ipfs/boxo/pull/829), [#833](https://github.com/ipfs/boxo/pull/833)
- `ipns`: Improved interop with legacy clients by restoring support for `[]byte` CID in `Value` field. `Value()` will convert it to a valid `path.Path`. Empty `Value()` will produce `NoopPath` (`/ipfs/bafkqaaa`) to avoid breaking existing code that expects a valid record to always produce a valid content path. [#830](https://github.com/ipfs/boxo/pull/830)
- `gateway/blocks-backend`: Removed IPLD decoding in GetBlock funciton in gateway's BlocksBackend. Now it's querying the blockService directly instead of dagService. [#845](https://github.com/ipfs/boxo/pull/845)


## [v0.27.3]
Expand Down
17 changes: 15 additions & 2 deletions gateway/backend_blocks.go
Original file line number Diff line number Diff line change
Expand Up @@ -211,12 +211,25 @@ func (bb *BlocksBackend) GetAll(ctx context.Context, path path.ImmutablePath) (C
}

func (bb *BlocksBackend) GetBlock(ctx context.Context, path path.ImmutablePath) (ContentPathMetadata, files.File, error) {
md, nd, err := bb.getNode(ctx, path)
roots, lastSeg, remainder, err := bb.getPathRoots(ctx, path)
if err != nil {
return ContentPathMetadata{}, nil, err
}

md := ContentPathMetadata{
PathSegmentRoots: roots,
LastSegment: lastSeg,
LastSegmentRemainder: remainder,
}

lastRoot := lastSeg.RootCid()

b, err := bb.blockService.GetBlock(ctx, lastRoot)
if err != nil {
return md, nil, err
}

return md, files.NewBytesFile(nd.RawData()), nil
return md, files.NewBytesFile(b.RawData()), nil
}

func (bb *BlocksBackend) Head(ctx context.Context, path path.ImmutablePath) (ContentPathMetadata, *HeadResponse, error) {
Expand Down

0 comments on commit 7c3ac0d

Please sign in to comment.