Skip to content

Commit cd7a930

Browse files
committed
fix: partial revert of 1be7c1a; make traverser process identity CIDs
It turns out that there are obscure cases where this matters, so we can't as easily just ignore identity CIDs. Specifically, classic online Filecoin deals that rely on Graphsync _and_ require identity CIDs be stored in the CARv1 that is used to calculate CommP must see the identity CID pass through the LinkSystem. Unfortunately, the easiest way to deal with this is to send them over the wire as if they are a normal block; which happens to be the "safe" backward compatible way too. Less easy way would be to simulate it on both ends and not send them, but we'll take the easy path for now. Extension of tests in here to make sure that the full DAG is transferred even in this case. Blockstore _must_ have identity CIDs in them, or be able to respond properly to them.
1 parent b665467 commit cd7a930

File tree

3 files changed

+22
-31
lines changed

3 files changed

+22
-31
lines changed

impl/graphsync_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -352,8 +352,8 @@ func TestGraphsyncIdentityCIDRoundTrip(t *testing.T) {
352352
})
353353
progressChan, errChan := requestor.Request(ctx, td.host2.ID(), identityDag.RootLink, selectorparse.CommonSelector_ExploreAllRecursively)
354354

355-
identityDag.VerifyWholeDAG(ctx, progressChan)
356355
testutil.VerifyEmptyErrors(ctx, t, errChan)
356+
identityDag.VerifyWholeDAG(ctx, progressChan)
357357
require.Len(t, td.blockStore1, len(identityDag.AllLinks), "did not store all blocks")
358358

359359
// verify listener

ipldutil/traverser.go

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,17 @@
11
package ipldutil
22

33
import (
4-
"bytes"
54
"context"
65
"errors"
76
"io"
87
"sync"
98

10-
"github.com/ipfs/go-cid"
119
dagpb "github.com/ipld/go-codec-dagpb"
1210
"github.com/ipld/go-ipld-prime"
1311
cidlink "github.com/ipld/go-ipld-prime/linking/cid"
1412
"github.com/ipld/go-ipld-prime/node/basicnode"
1513
"github.com/ipld/go-ipld-prime/traversal"
1614
"github.com/ipld/go-ipld-prime/traversal/selector"
17-
"github.com/multiformats/go-multihash"
1815

1916
"github.com/filecoin-project/boost-graphsync/panics"
2017
)
@@ -168,23 +165,7 @@ func (t *traverser) NBlocksTraversed() int {
168165
return t.blocksCount
169166
}
170167

171-
func asIdentity(c cid.Cid) (digest []byte, ok bool, err error) {
172-
dmh, err := multihash.Decode(c.Hash())
173-
if err != nil {
174-
return nil, false, err
175-
}
176-
ok = dmh.Code == multihash.IDENTITY
177-
digest = dmh.Digest
178-
return digest, ok, nil
179-
}
180-
181168
func (t *traverser) loader(lnkCtx ipld.LinkContext, lnk ipld.Link) (io.Reader, error) {
182-
if digest, ok, err := asIdentity(lnk.(cidlink.Link).Cid); ok {
183-
return io.NopCloser(bytes.NewReader(digest)), nil
184-
} else if err != nil {
185-
return nil, err
186-
}
187-
188169
// A StorageReadOpener call came in; update the state and release the lock.
189170
// We can't simply unlock the mutex inside the <-t.responses case,
190171
// as then we'd deadlock with the other side trying to send.

testutil/identity.go

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,17 @@ type TestIdentityDAG struct {
2828
t testing.TB
2929
loader ipld.BlockReadOpener
3030

31-
RootLink ipld.Link
32-
AllLinks []ipld.Link
31+
RootLink ipld.Link
32+
AllLinks []ipld.Link
33+
AllLinksNoIdent []ipld.Link
3334
}
3435

3536
/* ugly, but it makes a DAG with paths that look like this but doesn't involved dag-pb or unixfs */
36-
var identityDagPaths = []string{
37+
var identityDagLinkPaths = []string{
3738
"",
3839
"a/!foo",
3940
"a/b/!bar",
41+
"a/b/c/!baz", // identity
4042
"a/b/c/!baz/identity jump",
4143
"a/b/c/!baz/identity jump/these are my children/blip",
4244
"a/b/c/!baz/identity jump/these are my children/bloop",
@@ -49,13 +51,15 @@ var identityDagPaths = []string{
4951
func SetupIdentityDAG(
5052
ctx context.Context,
5153
t testing.TB,
52-
lsys ipld.LinkSystem) *TestIdentityDAG {
53-
54+
lsys ipld.LinkSystem,
55+
) *TestIdentityDAG {
5456
allLinks := make([]ipld.Link, 0)
57+
allLinksNoIdent := make([]ipld.Link, 0)
5558
store := func(lp datamodel.LinkPrototype, n datamodel.Node) datamodel.Link {
5659
l, err := lsys.Store(linking.LinkContext{}, lp, n)
5760
require.NoError(t, err)
5861
allLinks = append(allLinks, l)
62+
allLinksNoIdent = append(allLinksNoIdent, l)
5963
return l
6064
}
6165

@@ -98,6 +102,11 @@ func SetupIdentityDAG(
98102
identBytes := must(ipld.Encode(ident, dagjson.Encode))(t)
99103
mh := must(multihash.Sum(identBytes, multihash.IDENTITY, len(identBytes)))(t)
100104
bazIdent = cidlink.Link{Cid: cid.NewCidV1(cid.DagJSON, mh)}
105+
w, wc, err := lsys.StorageWriteOpener(linking.LinkContext{})
106+
require.NoError(t, err)
107+
w.Write(identBytes)
108+
require.NoError(t, wc(bazIdent))
109+
allLinks = append(allLinks, bazIdent)
101110
}
102111
bar := store(djlp, basicnode.NewInt(2020202020202020))
103112
foo := store(djlp, basicnode.NewInt(1010101010101010))
@@ -117,10 +126,11 @@ func SetupIdentityDAG(
117126
}))(t))
118127

119128
return &TestIdentityDAG{
120-
t: t,
121-
loader: lsys.StorageReadOpener,
122-
RootLink: root,
123-
AllLinks: reverse(allLinks), // TODO: slices.Reverse post 1.21
129+
t: t,
130+
loader: lsys.StorageReadOpener,
131+
RootLink: root,
132+
AllLinks: reverse(allLinks), // TODO: slices.Reverse post 1.21
133+
AllLinksNoIdent: reverse(allLinksNoIdent),
124134
}
125135
}
126136

@@ -150,15 +160,15 @@ func (tid *TestIdentityDAG) checkResponses(responses []graphsync.ResponseProgres
150160
for ii, response := range responses {
151161
// only check the paths that have links, assume the rest are just describing
152162
// the non-link nodes of the DAG
153-
if response.Path.String() == identityDagPaths[pathIndex] {
163+
if response.Path.String() == identityDagLinkPaths[pathIndex] {
154164
if response.LastBlock.Link != nil {
155165
expectedLink := tid.AllLinks[pathIndex]
156166
require.Equal(tid.t, expectedLink.String(), response.LastBlock.Link.String(), fmt.Sprintf("response %d has correct link (%d)", ii, pathIndex))
157167
}
158168
pathIndex++
159169
}
160170
}
161-
require.Equal(tid.t, len(identityDagPaths), pathIndex, "traverses all nodes")
171+
require.Equal(tid.t, len(identityDagLinkPaths), pathIndex, "traverses all nodes")
162172
}
163173

164174
func must[T any](v T, err error) func(t testing.TB) T {

0 commit comments

Comments
 (0)