Skip to content

Commit df993a3

Browse files
committed
feat: switch to raw multihashes for blocks
Part of: #6815
1 parent 7d2f39b commit df993a3

File tree

6 files changed

+43
-102
lines changed

6 files changed

+43
-102
lines changed

core/commands/refs.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ var RefsLocalCmd = &cmds.Command{
134134
Helptext: cmds.HelpText{
135135
Tagline: "List all local references.",
136136
ShortDescription: `
137-
Displays the hashes of all local objects.
137+
Displays the hashes of all local objects. NOTE: This treats all local objects as "raw blocks" and returns CIDv1-Raw CIDs.
138138
`,
139139
},
140140

core/node/storage.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ import (
1414
"github.com/ipfs/go-filestore"
1515
"github.com/ipfs/go-ipfs/core/node/helpers"
1616
"github.com/ipfs/go-ipfs/repo"
17-
"github.com/ipfs/go-ipfs/thirdparty/cidv0v1"
1817
"github.com/ipfs/go-ipfs/thirdparty/verifbs"
1918
)
2019

@@ -61,7 +60,6 @@ func BaseBlockstoreCtor(cacheOpts blockstore.CacheOpts, nilRepo bool, hashOnRead
6160
}
6261

6362
bs = blockstore.NewIdStore(bs)
64-
bs = cidv0v1.NewBlockstore(bs)
6563

6664
if hashOnRead { // TODO: review: this is how it was done originally, is there a reason we can't just pass this directly?
6765
bs.HashOnRead(true)

gc/gc.go

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,16 @@ type Result struct {
2828
Error error
2929
}
3030

31+
// converts a set of CIDs with different codecs to a set of CIDs with the raw codec.
32+
func toRawCids(set *cid.Set) *cid.Set {
33+
newSet := cid.NewSet()
34+
set.ForEach(func(c cid.Cid) error {
35+
newSet.Add(cid.NewCidV1(cid.Raw, c.Hash()))
36+
return nil
37+
})
38+
return newSet
39+
}
40+
3141
// GC performs a mark and sweep garbage collection of the blocks in the blockstore
3242
// first, it creates a 'marked' set and adds to it the following:
3343
// - all recursively pinned blocks, plus all of their descendants (recursively)
@@ -65,6 +75,8 @@ func GC(ctx context.Context, bs bstore.GCBlockstore, dstor dstore.Datastore, pn
6575
}
6676
return
6777
}
78+
// The blockstore reports raw blocks. We need to remove the codecs from the CIDs.
79+
gcs = toRawCids(gcs)
6880
emark.Append(logging.LoggableMap{
6981
"blackSetSize": fmt.Sprintf("%d", gcs.Len()),
7082
})
@@ -90,6 +102,8 @@ func GC(ctx context.Context, bs bstore.GCBlockstore, dstor dstore.Datastore, pn
90102
if !ok {
91103
break loop
92104
}
105+
// NOTE: assumes that all CIDs returned by the keychan are _raw_ CIDv1 CIDs.
106+
// This means we keep the block as long as we want it somewhere (CIDv1, CIDv0, Raw, other...).
93107
if !gcs.Has(k) {
94108
err := bs.DeleteBlock(k)
95109
removed++
@@ -170,7 +184,9 @@ func Descendants(ctx context.Context, getLinks dag.GetLinks, set *cid.Set, roots
170184

171185
for _, c := range roots {
172186
// Walk recursively walks the dag and adds the keys to the given set
173-
err := dag.Walk(ctx, verifyGetLinks, c, set.Visit, dag.Concurrent())
187+
err := dag.Walk(ctx, verifyGetLinks, c, func(k cid.Cid) bool {
188+
return set.Visit(toCidV1(k))
189+
}, dag.Concurrent())
174190

175191
if err != nil {
176192
err = verboseCidError(err)
@@ -181,6 +197,14 @@ func Descendants(ctx context.Context, getLinks dag.GetLinks, set *cid.Set, roots
181197
return nil
182198
}
183199

200+
// toCidV1 converts any CIDv0s to CIDv1s.
201+
func toCidV1(c cid.Cid) cid.Cid {
202+
if c.Version() == 0 {
203+
return cid.NewCidV1(c.Type(), c.Hash())
204+
}
205+
return c
206+
}
207+
184208
// ColoredSet computes the set of nodes in the graph that are pinned by the
185209
// pins in the given pinner.
186210
func ColoredSet(ctx context.Context, pn pin.Pinner, ng ipld.NodeGetter, bestEffortRoots []cid.Cid, output chan<- Result) (*cid.Set, error) {
@@ -241,7 +265,7 @@ func ColoredSet(ctx context.Context, pn pin.Pinner, ng ipld.NodeGetter, bestEffo
241265
return nil, err
242266
}
243267
for _, k := range dkeys {
244-
gcs.Add(k)
268+
gcs.Add(toCidV1(k))
245269
}
246270

247271
ikeys, err := pn.InternalPins(ctx)

go.mod

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,11 @@ require (
2727
github.com/ipfs/go-ds-measure v0.1.0
2828
github.com/ipfs/go-filestore v0.0.3
2929
github.com/ipfs/go-fs-lock v0.0.3
30-
github.com/ipfs/go-ipfs-blockstore v0.1.1
30+
github.com/ipfs/go-ipfs-blockstore v0.1.2-0.20200107182344-e0992be5aac7
3131
github.com/ipfs/go-ipfs-chunker v0.0.3
3232
github.com/ipfs/go-ipfs-cmds v0.1.1
3333
github.com/ipfs/go-ipfs-config v0.2.0
34-
github.com/ipfs/go-ipfs-ds-help v0.0.1
34+
github.com/ipfs/go-ipfs-ds-help v0.0.2-0.20200107180048-11890cc86e62
3535
github.com/ipfs/go-ipfs-exchange-interface v0.0.1
3636
github.com/ipfs/go-ipfs-exchange-offline v0.0.1
3737
github.com/ipfs/go-ipfs-files v0.0.6
@@ -64,8 +64,8 @@ require (
6464
github.com/libp2p/go-libp2p-core v0.3.0
6565
github.com/libp2p/go-libp2p-discovery v0.2.0
6666
github.com/libp2p/go-libp2p-http v0.1.4
67-
github.com/libp2p/go-libp2p-kad-dht v0.4.1
68-
github.com/libp2p/go-libp2p-kbucket v0.2.2
67+
github.com/libp2p/go-libp2p-kad-dht v0.5.0
68+
github.com/libp2p/go-libp2p-kbucket v0.2.3
6969
github.com/libp2p/go-libp2p-loggables v0.1.0
7070
github.com/libp2p/go-libp2p-mplex v0.2.1
7171
github.com/libp2p/go-libp2p-peerstore v0.1.4

go.sum

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -200,8 +200,10 @@ github.com/ipfs/go-fs-lock v0.0.3/go.mod h1:j2WZOYsBPcZG7UJUh1tE61Nj4eZ1vImU69AQ
200200
github.com/ipfs/go-ipfs-blockstore v0.0.1/go.mod h1:d3WClOmRQKFnJ0Jz/jj/zmksX0ma1gROTlovZKBmN08=
201201
github.com/ipfs/go-ipfs-blockstore v0.1.0 h1:V1GZorHFUIB6YgTJQdq7mcaIpUfCM3fCyVi+MTo9O88=
202202
github.com/ipfs/go-ipfs-blockstore v0.1.0/go.mod h1:5aD0AvHPi7mZc6Ci1WCAhiBQu2IsfTduLl+422H6Rqw=
203-
github.com/ipfs/go-ipfs-blockstore v0.1.1 h1:+PAFREAlSxLs9IEtrRcnJ/DqWkGlDa+l547WFZnohNw=
204-
github.com/ipfs/go-ipfs-blockstore v0.1.1/go.mod h1:8gZOgIN5e+Xdg2YSGdwTTRbguSVjYyosIDRQCY8E9QM=
203+
github.com/ipfs/go-ipfs-blockstore v0.1.2-0.20200107173559-39b8fa892f23 h1:1YUM3VG1zFmWZJb0VqKpbqvtIHzZWrJ+u2XzyAxa2mI=
204+
github.com/ipfs/go-ipfs-blockstore v0.1.2-0.20200107173559-39b8fa892f23/go.mod h1:KCm3qqlyBnbrIkkEHYiHO6Nwxse/sM7GjHZ2n6+27UQ=
205+
github.com/ipfs/go-ipfs-blockstore v0.1.2-0.20200107182344-e0992be5aac7 h1:Ad79IyU49J46ATIm50glAqeIcJJmfHzw3LXXoMlwYPY=
206+
github.com/ipfs/go-ipfs-blockstore v0.1.2-0.20200107182344-e0992be5aac7/go.mod h1:TByk/ha1EZ64DGA2FrXH/8HPZvk61IE89W81Iq+RC48=
205207
github.com/ipfs/go-ipfs-blocksutil v0.0.1 h1:Eh/H4pc1hsvhzsQoMEP3Bke/aW5P5rVM1IWFJMcGIPQ=
206208
github.com/ipfs/go-ipfs-blocksutil v0.0.1/go.mod h1:Yq4M86uIOmxmGPUHv/uI7uKqZNtLb449gwKqXjIsnRk=
207209
github.com/ipfs/go-ipfs-chunker v0.0.1 h1:cHUUxKFQ99pozdahi+uSC/3Y6HeRpi9oTeUHbE27SEw=
@@ -217,6 +219,10 @@ github.com/ipfs/go-ipfs-delay v0.0.1 h1:r/UXYyRcddO6thwOnhiznIAiSvxMECGgtv35Xs1I
217219
github.com/ipfs/go-ipfs-delay v0.0.1/go.mod h1:8SP1YXK1M1kXuc4KJZINY3TQQ03J2rwBG9QfXmbRPrw=
218220
github.com/ipfs/go-ipfs-ds-help v0.0.1 h1:QBg+Ts2zgeemK/dB0saiF/ykzRGgfoFMT90Rzo0OnVU=
219221
github.com/ipfs/go-ipfs-ds-help v0.0.1/go.mod h1:gtP9xRaZXqIQRh1HRpp595KbBEdgqWFxefeVKOV8sxo=
222+
github.com/ipfs/go-ipfs-ds-help v0.0.2-0.20200107173535-071cf2672860 h1:1f6exC5H9UZLT6tIBeRKfy1prnO2Fq1gAVEAcvngQGk=
223+
github.com/ipfs/go-ipfs-ds-help v0.0.2-0.20200107173535-071cf2672860/go.mod h1:zjN0aB3d6VyzJTSvcylSYxo+LSR/ELEfNnQM8p/vwc8=
224+
github.com/ipfs/go-ipfs-ds-help v0.0.2-0.20200107180048-11890cc86e62 h1:ib57ZzQCRZ/scmBO32DqWThjwpTqBW/fGqurYDE/rFA=
225+
github.com/ipfs/go-ipfs-ds-help v0.0.2-0.20200107180048-11890cc86e62/go.mod h1:zjN0aB3d6VyzJTSvcylSYxo+LSR/ELEfNnQM8p/vwc8=
220226
github.com/ipfs/go-ipfs-exchange-interface v0.0.1 h1:LJXIo9W7CAmugqI+uofioIpRb6rY30GUu7G6LUfpMvM=
221227
github.com/ipfs/go-ipfs-exchange-interface v0.0.1/go.mod h1:c8MwfHjtQjPoDyiy9cFquVtVHkO9b9Ob3FG91qJnWCM=
222228
github.com/ipfs/go-ipfs-exchange-offline v0.0.1 h1:P56jYKZF7lDDOLx5SotVh5KFxoY6C81I1NSHW1FxGew=
@@ -410,10 +416,10 @@ github.com/libp2p/go-libp2p-interface-connmgr v0.0.1/go.mod h1:GarlRLH0LdeWcLnYM
410416
github.com/libp2p/go-libp2p-interface-connmgr v0.0.4/go.mod h1:GarlRLH0LdeWcLnYM/SaBykKFl9U5JFnbBGruAk/D5k=
411417
github.com/libp2p/go-libp2p-interface-connmgr v0.0.5/go.mod h1:GarlRLH0LdeWcLnYM/SaBykKFl9U5JFnbBGruAk/D5k=
412418
github.com/libp2p/go-libp2p-interface-pnet v0.0.1/go.mod h1:el9jHpQAXK5dnTpKA4yfCNBZXvrzdOU75zz+C6ryp3k=
413-
github.com/libp2p/go-libp2p-kad-dht v0.4.1 h1:N++/IVD7KemtNqwoqBLsmpc1PxROW1cxi81ja+wsJCg=
414-
github.com/libp2p/go-libp2p-kad-dht v0.4.1/go.mod h1:Qf5Ddk5Csgi657ja2u5+NugbWz/QOVeVfrM1HTRDcfQ=
415-
github.com/libp2p/go-libp2p-kbucket v0.2.2 h1:Jg/JUbQix6mvTnj+86FasRqkh01JFQNrN+H26Gxxsg0=
416-
github.com/libp2p/go-libp2p-kbucket v0.2.2/go.mod h1:opWrBZSWnBYPc315q497huxY3sz1t488X6OiXUEYWKA=
419+
github.com/libp2p/go-libp2p-kad-dht v0.5.0 h1:kDMtCftpQOL2s84/dZmw5z4NmBe6ByeDLKpcn6TcyxU=
420+
github.com/libp2p/go-libp2p-kad-dht v0.5.0/go.mod h1:42YDfiKXzIgaIexiEQ3rKZbVPVPziLOyHpXbOCVd814=
421+
github.com/libp2p/go-libp2p-kbucket v0.2.3 h1:XtNfN4WUy0cfeJoJgWCf1lor4Pp3kBkFJ9vQ+Zs+VUM=
422+
github.com/libp2p/go-libp2p-kbucket v0.2.3/go.mod h1:opWrBZSWnBYPc315q497huxY3sz1t488X6OiXUEYWKA=
417423
github.com/libp2p/go-libp2p-loggables v0.0.1/go.mod h1:lDipDlBNYbpyqyPX/KcoO+eq0sJYEVR2JgOexcivchg=
418424
github.com/libp2p/go-libp2p-loggables v0.1.0 h1:h3w8QFfCt2UJl/0/NW4K829HX/0S4KD31PQ7m8UXXO8=
419425
github.com/libp2p/go-libp2p-loggables v0.1.0/go.mod h1:EyumB2Y6PrYjr55Q3/tiJ/o3xoDasoRYM7nOzEpoa90=

thirdparty/cidv0v1/blockstore.go

Lines changed: 0 additions & 87 deletions
This file was deleted.

0 commit comments

Comments
 (0)