-
-
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
patch add-link fails to write result to blockstore #1925
Comments
License: MIT Signed-off-by: Andrew Chin <achin@eminence32.net>
Ok, I dug into this tonight, and forty-three thousand printfs later, I've found the root of this issue. It's kinda gnarly, I'm not sure how to solve this. While the title of this issue says "fails to write to blockstore", that's not quite true -- ipfs ends up writing something to the blockstore, but it's not the thing it gives you the hash for. In the above example, instead of writing
What's the difference and where did But the hash returned by patch-object is the hash of a protobuf object that has a zero-length func (n *Node) Copy() *Node {
nnode := new(Node)
nnode.Data = make([]byte, len(n.Data))
copy(nnode.Data, n.Data)
nnode.Links = make([]*Link, len(n.Links))
copy(nnode.Links, n.Links)
nnode_encoded, _ := nnode.Encoded(true)
n_encoded, _ := n.Encoded(true)
fmt.Println("nnode enc:", nnode_encoded)
fmt.Println("n encoded:", n_encoded)
return nnode
} The result:
The new node has 2 extra bytes on the end. This corresponds to our If this was a greenfield project, I might suggest making the Data field required, so there wouldn't be two different ways to serialize the same object. I'm not sure if we can change it now in a compatible way (maybe if we added a default value?) |
@jbenet has strong opinions about 'optional' vs 'required' in protobuf. The issue here is actually (as you point out) that a zero length array and a nil array are nearly the same in go, but different in protobuf. |
I think this has been encountered before, and the idea we (i think i remember) decided on was do set zero length arrays to nil on marshaling. |
@eminence great detective work! 🔎
yes, we should set them to nil.
it's unfortunate but will be ok. we can always be compatible with what we get and aim towards producing canonical reps. it is unfortunate if other objects exist out there that have an empty also note this will change when https://github.com/ipfs/go-ipld/ lands |
Thanks for the fix! I've confirmed that it's working. On the subject on canonical representations, you can sometimes see weird thing when working with PBNodes that were not generated by go-ipfs:
I asked for a link to Finally, please don't forget about #1926 (either close it, or merge it). Thanks! |
@eminence what tool created the ref in question? |
@whyrusleeping It's a custom tool I created. It creates/manipulates PBNodes and writes them directly to disk (into |
This has been resolved |
This isn't new, mostly recently tested with 36de29a
At this point I expect this new hash (
Qm...Tnu
) to be available, but it isn't:Oddly, the above sequence works if you start with a unixfs-dir object (instead of an empty object)
The text was updated successfully, but these errors were encountered: