@cryptotaxi247 / kubo / commits / 924b2a0a3

don't add nodes to DAG twice.

Now that we add nodes to the DAG when pinning, don't bother adding them twice. License: MIT Signed-off-by: Steven Allen <steven@stebalien.com>

Steven Allen committed Dec 3, 2017 at 18:58 UTC 924b2a0a34342e56738d3c2727ac630d81a2d58e
4 files changed +9 -23
assets/assets.go
+1 -6
@@ -80,11 +80,6 @@ func addAssetList(nd *core.IpfsNode, l []string) (*cid.Cid, error) {
80 return nil, err
81 }
82
83 - dcid, err := nd.DAG.Add(dir)
84 - if err != nil {
85 - return nil, fmt.Errorf("assets: DAG.Add(dir) failed: %s", err)
86 - }
87 -
83 if err := nd.Pinning.Pin(nd.Context(), dir, true); err != nil {
84 return nil, fmt.Errorf("assets: Pinning on init-docu failed: %s", err)
85 }
@@ -93,5 +88,5 @@ func addAssetList(nd *core.IpfsNode, l []string) (*cid.Cid, error) {
88 return nil, fmt.Errorf("assets: Pinning flush failed: %s", err)
89 }
90
96 - return dcid, nil
91 + return dir.Cid(), nil
92 }
cmd/ipfs/init.go
+1 -1
@@ -260,5 +260,5 @@ func initializeIpnsKeyspace(repoRoot string) error {
260 return err
261 }
262
263 - return namesys.InitializeKeyspace(ctx, nd.DAG, nd.Namesys, nd.Pinning, nd.PrivateKey)
263 + return namesys.InitializeKeyspace(ctx, nd.Namesys, nd.Pinning, nd.PrivateKey)
264 }
fuse/ipns/common.go
+4 -8
@@ -13,16 +13,12 @@ import (
13 // InitializeKeyspace sets the ipns record for the given key to
14 // point to an empty directory.
15 func InitializeKeyspace(n *core.IpfsNode, key ci.PrivKey) error {
16 - emptyDir := ft.EmptyDirNode()
17 - nodek, err := n.DAG.Add(emptyDir)
18 - if err != nil {
19 - return err
20 - }
21 -
16 ctx, cancel := context.WithCancel(n.Context())
17 defer cancel()
18
25 - err = n.Pinning.Pin(ctx, emptyDir, false)
19 + emptyDir := ft.EmptyDirNode()
20 +
21 + err := n.Pinning.Pin(ctx, emptyDir, false)
22 if err != nil {
23 return err
24 }
@@ -34,5 +30,5 @@ func InitializeKeyspace(n *core.IpfsNode, key ci.PrivKey) error {
30
31 pub := nsys.NewRoutingPublisher(n.Routing, n.Repo.Datastore())
32
37 - return pub.Publish(ctx, key, path.FromCid(nodek))
33 + return pub.Publish(ctx, key, path.FromCid(emptyDir.Cid()))
34 }
namesys/publisher.go
+3 -8
@@ -7,7 +7,6 @@ import (
7 "fmt"
8 "time"
9
10 - dag "github.com/ipfs/go-ipfs/merkledag"
10 pb "github.com/ipfs/go-ipfs/namesys/pb"
11 path "github.com/ipfs/go-ipfs/path"
12 pin "github.com/ipfs/go-ipfs/pin"
@@ -321,16 +320,12 @@ func ValidateIpnsRecord(k string, val []byte) error {
320 // InitializeKeyspace sets the ipns record for the given key to
321 // point to an empty directory.
322 // TODO: this doesnt feel like it belongs here
324 -func InitializeKeyspace(ctx context.Context, ds dag.DAGService, pub Publisher, pins pin.Pinner, key ci.PrivKey) error {
323 +func InitializeKeyspace(ctx context.Context, pub Publisher, pins pin.Pinner, key ci.PrivKey) error {
324 emptyDir := ft.EmptyDirNode()
326 - nodek, err := ds.Add(emptyDir)
327 - if err != nil {
328 - return err
329 - }
325
326 // pin recursively because this might already be pinned
327 // and doing a direct pin would throw an error in that case
333 - err = pins.Pin(ctx, emptyDir, true)
328 + err := pins.Pin(ctx, emptyDir, true)
329 if err != nil {
330 return err
331 }
@@ -340,7 +335,7 @@ func InitializeKeyspace(ctx context.Context, ds dag.DAGService, pub Publisher, p
335 return err
336 }
337
343 - return pub.Publish(ctx, key, path.FromCid(nodek))
338 + return pub.Publish(ctx, key, path.FromCid(emptyDir.Cid()))
339 }
340
341 func IpnsKeysForID(id peer.ID) (name, ipns string) {