Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: alternative identity CID handling #429

Merged
merged 1 commit into from
Sep 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ require (
github.com/ipfs/go-block-format v0.2.0
github.com/ipfs/go-cid v0.4.1
github.com/ipfs/go-datastore v0.6.0
github.com/ipfs/go-graphsync v0.14.9
github.com/ipfs/go-graphsync v0.14.10
github.com/ipfs/go-ipfs-blockstore v1.3.0
github.com/ipfs/go-ipfs-blocksutil v0.0.1
github.com/ipfs/go-ipfs-delay v0.0.1
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -264,8 +264,8 @@ github.com/ipfs/go-datastore v0.6.0 h1:JKyz+Gvz1QEZw0LsX1IBn+JFCJQH4SJVFtM4uWU0M
github.com/ipfs/go-datastore v0.6.0/go.mod h1:rt5M3nNbSO/8q1t4LNkLyUwRs8HupMeN/8O4Vn9YAT8=
github.com/ipfs/go-detect-race v0.0.1 h1:qX/xay2W3E4Q1U7d9lNs1sU9nvguX0a7319XbyQ6cOk=
github.com/ipfs/go-detect-race v0.0.1/go.mod h1:8BNT7shDZPo99Q74BpGMK+4D8Mn4j46UU0LZ723meps=
github.com/ipfs/go-graphsync v0.14.9 h1:AZ1TxnU5LNANXesKr4ZjUtj0rLpqp0Qt5PL6Xf7uhc4=
github.com/ipfs/go-graphsync v0.14.9/go.mod h1:qyHjUvHey6EfKUDMQPwCuVkMOurRG3hcjRm+FaVP6bE=
github.com/ipfs/go-graphsync v0.14.10 h1:2slsmWcHxXGS/T6HR5hilo2sSAX1VsZVxjoOzA3XCAQ=
github.com/ipfs/go-graphsync v0.14.10/go.mod h1:qyHjUvHey6EfKUDMQPwCuVkMOurRG3hcjRm+FaVP6bE=
github.com/ipfs/go-hamt-ipld v0.1.1/go.mod h1:1EZCr2v0jlCnhpa+aZ0JZYp8Tt2w16+JJOAVz17YcDk=
github.com/ipfs/go-ipfs-blockstore v1.3.0 h1:m2EXaWgwTzAfsmt5UdJ7Is6l4gJcaM/A12XwJyvYvMM=
github.com/ipfs/go-ipfs-blockstore v1.3.0/go.mod h1:KgtZyc9fq+P2xJUiCAzbRdhhqJHvsw8u2Dlqy2MyRTE=
Expand Down
29 changes: 29 additions & 0 deletions pkg/internal/itest/http_fetch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -817,6 +817,35 @@ func TestHttpFetch(t *testing.T) {
return []unixfs.DirEntry{trustlesstestutil.MakeDagWithIdentity(t, *remotes[0].LinkSystem)}
},
},
// noDups variants are important because handling of these happens all the
// way up to DuplicateAdderCar
{
name: "non-unixfs graphsync /w noDups",
setHeader: noDups,
expectNoDups: true,
graphsyncRemotes: 1,
generate: func(t *testing.T, rndReader io.Reader, remotes []testpeer.TestPeer) []unixfs.DirEntry {
return []unixfs.DirEntry{trustlesstestutil.MakeDagWithIdentity(t, *remotes[0].LinkSystem)}
},
},
{
name: "non-unixfs bitswap /w noDups",
setHeader: noDups,
expectNoDups: true,
bitswapRemotes: 1,
generate: func(t *testing.T, rndReader io.Reader, remotes []testpeer.TestPeer) []unixfs.DirEntry {
return []unixfs.DirEntry{trustlesstestutil.MakeDagWithIdentity(t, *remotes[0].LinkSystem)}
},
},
{
name: "non-unixfs http /w noDups",
setHeader: noDups,
expectNoDups: true,
httpRemotes: 1,
generate: func(t *testing.T, rndReader io.Reader, remotes []testpeer.TestPeer) []unixfs.DirEntry {
return []unixfs.DirEntry{trustlesstestutil.MakeDagWithIdentity(t, *remotes[0].LinkSystem)}
},
},
}

for _, testCase := range testCases {
Expand Down
6 changes: 3 additions & 3 deletions pkg/internal/itest/testpeer/generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -299,13 +299,13 @@ func newTestPeer(
dstoreDelayed := delayed.New(dstore, bsdelay)

if cfg.bstore == nil {
var err error
cfg.bstore, err = blockstore.CachedBlockstore(ctx,
blockstore.NewIdStore(blockstore.NewBlockstore(dstoreDelayed)),
bstore, err := blockstore.CachedBlockstore(ctx,
blockstore.NewBlockstore(dstoreDelayed),
blockstore.DefaultCacheOpts())
if err != nil {
return TestPeer{}, nil, err
}
cfg.bstore = blockstore.NewIdStore(bstore)
}
lsys := storeutil.LinkSystemForBlockstore(cfg.bstore)
tp := TestPeer{
Expand Down
5 changes: 2 additions & 3 deletions pkg/retriever/bitswapretriever_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import (
"github.com/ipfs/boxo/blockservice"
blocks "github.com/ipfs/go-block-format"
"github.com/ipfs/go-cid"
gstestutil "github.com/ipfs/go-graphsync/testutil"
exchange "github.com/ipfs/go-ipfs-exchange-interface"
"github.com/ipld/go-ipld-prime"
"github.com/ipld/go-ipld-prime/datamodel"
Expand All @@ -42,8 +41,8 @@ func TestBitswapRetriever(t *testing.T) {
lsys.SetReadStorage(store)
lsys.SetWriteStorage(store)
lsys.TrustedStorage = true
tbc1 := gstestutil.SetupBlockChain(ctx, t, lsys, 1000, 100)
tbc2 := gstestutil.SetupBlockChain(ctx, t, lsys, 1000, 100)
tbc1 := trustlesstestutil.SetupBlockChain(ctx, t, lsys, 1000, 100)
tbc2 := trustlesstestutil.SetupBlockChain(ctx, t, lsys, 1000, 100)
var tbc1Cids []cid.Cid
for _, blk := range tbc1.AllBlocks() {
tbc1Cids = append(tbc1Cids, blk.Cid())
Expand Down
5 changes: 2 additions & 3 deletions pkg/retriever/httpretriever_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import (
"github.com/google/uuid"
blocks "github.com/ipfs/go-block-format"
"github.com/ipfs/go-cid"
gstestutil "github.com/ipfs/go-graphsync/testutil"
dagpb "github.com/ipld/go-codec-dagpb"
"github.com/ipld/go-ipld-prime/datamodel"
"github.com/ipld/go-ipld-prime/fluent/qp"
Expand Down Expand Up @@ -47,8 +46,8 @@ func TestHTTPRetriever(t *testing.T) {
lsys.SetReadStorage(store)
lsys.SetWriteStorage(store)
lsys.TrustedStorage = true
tbc1 := gstestutil.SetupBlockChain(ctx, t, lsys, 1000, 100)
tbc2 := gstestutil.SetupBlockChain(ctx, t, lsys, 1000, 100)
tbc1 := trustlesstestutil.SetupBlockChain(ctx, t, lsys, 1000, 100)
tbc2 := trustlesstestutil.SetupBlockChain(ctx, t, lsys, 1000, 100)
var tbc1Cids []cid.Cid
for _, blk := range tbc1.AllBlocks() {
tbc1Cids = append(tbc1Cids, blk.Cid())
Expand Down
8 changes: 8 additions & 0 deletions pkg/storage/duplicateaddercar.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
ipldstorage "github.com/ipld/go-ipld-prime/storage"
trustlessutils "github.com/ipld/go-trustless-utils"
"github.com/ipld/go-trustless-utils/traversal"
"github.com/multiformats/go-multihash"
)

type DeferredWriter interface {
Expand Down Expand Up @@ -114,6 +115,13 @@ func (da *DuplicateAdderCar) BlockWriteOpener() linking.BlockWriteOpener {
var buf bytes.Buffer
var written bool
return &buf, func(lnk ipld.Link) error {
// assume that we will never want to write out identity CIDs, and they
// won't be expected by a traversal (i.e. go-trustless-utils won't expect
// them in a block stream)
if lnk.(cidlink.Link).Cid.Prefix().MhType == multihash.IDENTITY {
return nil
}

if written {
return fmt.Errorf("WriteCommitter already used")
}
Expand Down
Loading