-
-
Notifications
You must be signed in to change notification settings - Fork 3k
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
Add support for using CidV1 in 'ipfs add' #3743
Conversation
@whyrusleeping I am not sure I am happy with this What I described in #3699 (comment) was only sufficient for adding files with CidV1. It did not handle symbolic links or directories. In order to handle directories I needed to touch the To make sure the root node was CidV1 I decided it was best to pass in the Cid version when creating the adder rather then setting it later. The changes to the merkeldag package are not strictly necessary, but it seams the best way to set the Cid version of a ProtoNode. |
@whyrusleeping one question: Do you think |
@kevina hrm... I think setting cid version to 1 could probably change the default value for raw leaves to true, but i think people should still be able to set raw leaves to false and cid version to 1. Even if we don't allow it through the command line people could manually construct graphs that were that way |
65ea7f3
to
33c65ba
Compare
@whyrusleeping okay, i think this is ready for review |
core/commands/add.go
Outdated
@@ -78,6 +79,7 @@ You can now refer to the added file in a gateway, like so: | |||
cmds.StringOption(chunkerOptionName, "s", "Chunking algorithm to use."), | |||
cmds.BoolOption(pinOptionName, "Pin this object when adding.").Default(true), | |||
cmds.BoolOption(rawLeavesOptionName, "Use raw blocks for leaf nodes. (experimental)"), | |||
cmds.IntOption(cidVersionOptionName, "Cid version. (experimental)").Default(0), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should mention enables raw blocks
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree, but got stuck on how to state in concisely suggestion welcome.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
CID Version. Non-zero value will change default of 'rawleaves' to true.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't like the fact that now every MFS API function will have to take cidversion argument. We will have to either live with it or think about it.
core/commands/add.go
Outdated
if err != nil { | ||
res.SetError(err, cmds.ErrNormal) | ||
return | ||
} | ||
|
||
outChan := make(chan interface{}, 8) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Extract this constant, maybe use the same as AllKeysChan or some other/new but I would prefer it extracted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not new code I just moved things around a little. We can do this in a separate p.r.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This would have taken 10s. General rule many of us try to strive for is to leave code in better shape than we've found it.
merkledag/cidversion.go
Outdated
) | ||
|
||
// CidVersion is a a cid version number that is guaranteed to be valid | ||
type CidVersion struct { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would make it type CidVersion int
. It will be simpler to use and more idiomatic.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also there isn't a reason it couldn't be just a constant?
type CidVerision int
const (
CID0 CidVersion = 0
CID1 CidVersion = 1
)
You can still have methods on it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you went the way you did because as a way of preventing creation of different CID versions but IMO it should be done with helper function when CID version is from User Interface.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because nothing prevents me from doing CidVersion{2}
either way.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because nothing prevents me from doing CidVersion{2} either way.
Um, if you do that outside the merkeldag package you will get
implicit assignment of unexported field 'version' in merkledag.CidVersion literal
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The idea was to provide some additional type safety so once you have a CidVersion you don't need to return an error if the version is invalid as it has already been checked.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ahh, missed that. Ok, but I would still be for having variables aliasing usable values.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Alias added, although not currently used.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also note, I am not against doing the way you suggested.
I just want to be able to assume that once we have a CidVersion we can guarantee we have something valid and don't want to have to return an error (instead we can panic). I think it will be reasonable to assume that the user (in this case the programmer) won't do a cast from an int to to CidVersion and will use the helper function.
@whyrusleeping thoughts.
Also the code is not formatter right: https://ci.ipfs.team/blue/organizations/jenkins/go-ipfs/detail/PR-3743/5/pipeline |
core/commands/add.go
Outdated
@@ -78,6 +79,7 @@ You can now refer to the added file in a gateway, like so: | |||
cmds.StringOption(chunkerOptionName, "s", "Chunking algorithm to use."), | |||
cmds.BoolOption(pinOptionName, "Pin this object when adding.").Default(true), | |||
cmds.BoolOption(rawLeavesOptionName, "Use raw blocks for leaf nodes. (experimental)"), | |||
cmds.IntOption(cidVersionOptionName, "Cid version. (experimental)").Default(0), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
perhaps this option should be a global option. (on the ipfs
command, same places as the timout option).
Otherwise we will have to add this in (and maintain it) for each command that wants to be able to select the output cid version
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree, but thought it would be simpler just to add it for the adder for now.
For example, should every command check for this flag if it is applicable, and if it is not supported yet error out?
core/commands/add.go
Outdated
rawblks, rawblksFound, _ := req.Option(rawLeavesOptionName).Bool() | ||
cidVer, _, _ := req.Option(cidVersionOptionName).Int() | ||
|
||
if cidVer >= 1 && !rawblksFound { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should probably check that cidVer is either zero or one. No other values are supported right now
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This check is already done in the call to NewAdder.
Neither do I. It is only the
@whyrusleeping thoughs? |
core/coreunix/add.go
Outdated
@@ -67,8 +67,15 @@ type AddedObject struct { | |||
Bytes int64 `json:",omitempty"` | |||
} | |||
|
|||
func NewAdder(ctx context.Context, p pin.Pinner, bs bstore.GCBlockstore, ds dag.DAGService) (*Adder, error) { | |||
mr, err := mfs.NewRoot(ctx, ds, unixfs.EmptyDirNode(), nil) | |||
func NewAdder(ctx context.Context, p pin.Pinner, bs bstore.GCBlockstore, ds dag.DAGService, v int) (*Adder, error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lets not change the parameters here. Instead, lets just add a SetCidVersion
method to the adder.
importer/helpers/dagbuilder.go
Outdated
@@ -33,6 +35,9 @@ type DagBuilderParams struct { | |||
// instead of using the unixfs TRaw type | |||
RawLeaves bool | |||
|
|||
// Prefix specifies cid version and hashing function |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
CidVersion only specifies the cid version, not the hashing function
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, fixed. It was a leftover comment from an earlier attempt.
importer/helpers/dagbuilder.go
Outdated
@@ -139,7 +155,11 @@ func (db *DagBuilderHelper) GetNextDataNode() (*UnixfsNode, error) { | |||
raw: true, | |||
}, nil | |||
} else { | |||
blk := NewUnixfsBlock() | |||
blk := &UnixfsNode{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no NewUnixfsBlock
anymore?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Correct. It was only used in one place so I just inlined the code. I removed the function to make sure I cached all possible places where it was called to make sure the correct Cid version was always set.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you want I can turn it into a method like I did for NewUnixfsNode
. But since it was only used in one place I decided it wasn't worth the effort.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah... just to maintain continuity with the previous methods. the whole 'raw' thing here is realllly just legacy code to prevent hashes from changing at this point
mfs/ops.go
Outdated
@@ -104,7 +105,7 @@ func PutNode(r *Root, path string, nd node.Node) error { | |||
|
|||
// Mkdir creates a directory at 'path' under the directory 'd', creating | |||
// intermediary directories as needed if 'mkparents' is set to true | |||
func Mkdir(r *Root, pth string, mkparents bool, flush bool) error { | |||
func Mkdir(r *Root, pth string, mkparents bool, flush bool, cidVer dag.CidVersion) error { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lets have this be a field on the Root
object, that way we can avoid changing the mfs APIs
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good idea. Done.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd like to avoid changing the existing apis on these things.
Other than those comments though, this LGTM.
48d361f
to
2ba6d8a
Compare
@whyrusleeping okay, this should be ready now |
@whyrusleeping target this for 0.4.8? Or do you want to try for a global option instead? |
importer/helpers/dagbuilder.go
Outdated
@@ -33,6 +35,9 @@ type DagBuilderParams struct { | |||
// instead of using the unixfs TRaw type | |||
RawLeaves bool | |||
|
|||
// CID Version to use | |||
CidVersion dag.CidVersion |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think instead of using a struct for this, we should just use a cid.Prefix
. That way we make it much easier for us to switch the hash function in the future
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Construction looks good to me, Just want to switch to setting the whole cid prefix instead of just the version. Will make future changes of this sort much easier on us
@whyrusleeping okay, changed to setting the prefix instead of just the CID version |
merkledag/node.go
Outdated
} | ||
|
||
func (n *ProtoNode) SetPrefix(prefix cid.Prefix) { | ||
n.Prefix = prefix |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lets make sure to set n.Prefix.Codec = cid.DagProtobuf
, just for sanitys sake
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good idea will do.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well it turned out not to be such a good idea...
70fd13d
to
4df10c0
Compare
So commit bb09ffd (implement an HAMT for unixfs directory sharding) complicated things. It should have a fix by the end of Monday. |
@kevina alright, i'm gonna bump this to 0.4.9 then. Thanks! |
cef50ea
to
5adb2a3
Compare
@whyrusleeping so setting the prefix for the MFS root after the fact became problematic. Have a look at the commit "Fixes" and let me know what you think. This commit will be squashed but I kept it separate to make it easier to see the new changes. |
} | ||
|
||
func (adder *Adder) SetMfsRoot(r *mfs.Root) { | ||
adder.mr = r | ||
adder.mroot = r |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd prefer not changing the naming of things, but not a big deal
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can change it back. I did this as a trick to make sure I cached where all instance mr
was used. I thought about naming the method mr()
but that seamed a bit terse for a method name, even if it was only for internal use.
unixfs/io/dirbuilder.go
Outdated
if d.dirnode != nil { | ||
d.dirnode.SetPrefix(prefix) | ||
} | ||
// FIXME: Should we do this? -- kevina |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, we should probably set the shards prefix info too
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay, will do. Have something in a few days.
@kevina update here? |
@whyrusleeping Have something by the end of tomorrow, if not today. |
@whyrusleeping sorry for the delay, this should be good to go. I will squash the "Fixes" commit once you are okay with my changes. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, just needs a rebase 👍
Oh, and could you fix the codeclimate issues? |
License: MIT Signed-off-by: Kevin Atkinson <[email protected]>
License: MIT Signed-off-by: Kevin Atkinson <[email protected]>
License: MIT Signed-off-by: Kevin Atkinson <[email protected]>
License: MIT Signed-off-by: Kevin Atkinson <[email protected]>
…n nil License: MIT Signed-off-by: Kevin Atkinson <[email protected]>
License: MIT Signed-off-by: Kevin Atkinson <[email protected]>
License: MIT Signed-off-by: Kevin Atkinson <[email protected]>
66b3194
to
9350c51
Compare
Rebased but tests are failing again, will fix. |
But |
Some how "make deps" in the shareness directory was not rebuilding things correctly for me. In any case we a green and this is now ready to merge. |
Closed #3699
License: MIT
Signed-off-by: Kevin Atkinson [email protected]