Skip to content

Commit 18c30ce

Browse files
authored
feat: handle retrieval queries for unindexed identity payload CIDs (#747)
* feat: handle retrieval queries for unindexed identity payload CIDs There are valid cases where a CAR may have an identity CID as its root that is not represented as a 'block' within the CAR body and therefore isn't indexed by the dagstore. In this case, we inspect the identity CID content and treat the query as a query for the intersection of all of the links within the block. Ref: filecoin-project/boost#715 * fix: refactor out multiple calls to dagStore.GetPiecesContainingBlock 1. to support identity PayloadCID without having to duplicate decode & lookup logic 2. because it's not cheap, especially for identity PayloadCIDs with lots of links The tradeoff is that in some cases we end up calling the PieceStore more than we otherwise would. * feat: impose limits on identity PayloadCIDs * Byte limit (2048) * Link limit (32) * feat: handle retrievals for nested identity CIDs * chore: expand testing to cover dag-pb identity CIDs
1 parent 10e86a0 commit 18c30ce

File tree

7 files changed

+406
-88
lines changed

7 files changed

+406
-88
lines changed

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ require (
4040
github.com/ipfs/go-unixfs v0.3.1
4141
github.com/ipld/go-car v0.4.0
4242
github.com/ipld/go-car/v2 v2.4.1
43+
github.com/ipld/go-codec-dagpb v1.3.1
4344
github.com/ipld/go-ipld-prime v0.17.0
4445
github.com/jbenet/go-random v0.0.0-20190219211222-123a90aedc0c
4546
github.com/jpillora/backoff v1.0.0
@@ -98,7 +99,6 @@ require (
9899
github.com/ipfs/go-peertaskqueue v0.7.1 // indirect
99100
github.com/ipfs/go-unixfsnode v1.4.0 // indirect
100101
github.com/ipfs/go-verifcid v0.0.1 // indirect
101-
github.com/ipld/go-codec-dagpb v1.3.1 // indirect
102102
github.com/jackpal/go-nat-pmp v1.0.2 // indirect
103103
github.com/jbenet/goprocess v0.1.4 // indirect
104104
github.com/klauspost/cpuid/v2 v2.0.14 // indirect

piecestore/types.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,10 @@ type PieceInfo struct {
5353
// PieceInfoUndefined is piece info with no information
5454
var PieceInfoUndefined = PieceInfo{}
5555

56+
func (pi PieceInfo) Defined() bool {
57+
return pi.PieceCID.Defined() || len(pi.Deals) > 0
58+
}
59+
5660
// PieceStore is a saved database of piece info that can be modified and queried
5761
type PieceStore interface {
5862
Start(ctx context.Context) error

retrievalmarket/impl/integration_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package retrievalimpl_test
33
import (
44
"bytes"
55
"context"
6+
"fmt"
67
"io"
78
"os"
89
"path/filepath"
@@ -22,7 +23,6 @@ import (
2223
selectorparse "github.com/ipld/go-ipld-prime/traversal/selector/parse"
2324
"github.com/stretchr/testify/assert"
2425
"github.com/stretchr/testify/require"
25-
"golang.org/x/xerrors"
2626

2727
"github.com/filecoin-project/go-address"
2828
dtimpl "github.com/filecoin-project/go-data-transfer/impl"
@@ -71,11 +71,11 @@ func TestClientCanMakeQueryToProvider(t *testing.T) {
7171
})
7272

7373
t.Run("when there is some other error, returns error", func(t *testing.T) {
74-
pieceStore.ReturnErrorFromGetPieceInfo(xerrors.Errorf("someerr"))
74+
pieceStore.ReturnErrorFromGetPieceInfo(fmt.Errorf("someerr"))
7575
expectedQR.Status = retrievalmarket.QueryResponseError
7676
expectedQR.PieceCIDFound = retrievalmarket.QueryItemUnavailable
7777
expectedQR.Size = 0
78-
expectedQR.Message = "failed to fetch piece to retrieve from: could not locate piece: someerr"
78+
expectedQR.Message = "failed to fetch piece to retrieve from: someerr"
7979
actualQR, err := client.Query(bgCtx, retrievalPeer, expectedCIDs[0], retrievalmarket.QueryParams{})
8080
assert.NoError(t, err)
8181
actualQR.MaxPaymentInterval = expectedQR.MaxPaymentInterval

0 commit comments

Comments
 (0)