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

Restore ability to regenerate merkledag.pb.go #5012

Closed
wants to merge 2 commits into from
Closed

Restore ability to regenerate merkledag.pb.go #5012

wants to merge 2 commits into from

Conversation

mib-kd743naq
Copy link
Contributor

@mib-kd743naq mib-kd743naq commented May 11, 2018

While performing merkledag.proto-related experiments I ran into rather unexpected difficulties regenerating the damn thing. Pushing my work upstream without making any functional changes, to hopefully save several hours to the next person ending up looking there

The TLDR is that one now can get the stack to do the right thing by simply:

$ cd merkledag/pb
$ ./regen_pb.sh

I would not be in any way opposed to this PR being rejected and a better pin being created within gx with all the necessary changes that go with this

Due to the IPLD-PB format relying on a mis-feature of gogo-protobuf, the
process of (re)generating the golang protobuf bindings is way harder than
it ought to be :(

What I do here is compile-and-execute a patched version of the gogofast
encoder, and present it as a temporary generator-plugin to the stock `protoc`
binary. This ensures we still get the effect we want, but the "nonstandard"
generator does not get installed anywhere.

All tests verified to pass despite the seemingly substantial changes in the
generated code

License: MIT
Signed-off-by: Mib Kd743naq <mib.kd743naq@gmail.com>
@mib-kd743naq mib-kd743naq requested a review from Kubuxu as a code owner May 11, 2018 13:27
@mib-kd743naq
Copy link
Contributor Author

@whyrusleeping hrm... the jenkins failure seems to be something unrelated with your (originally ) name on

@Kubuxu
Copy link
Member

Kubuxu commented May 11, 2018

It is because Windows Jenkins was not yet updated to Go 1.10.

set -e

if ! [ -f merkledag.proto ] ; then
echo 1>&2 "You must run the regenerator wihile in the directory containing merkledag.proto"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo, did you mean: "while in the"?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are correct, fixed

@mib-kd743naq
Copy link
Contributor Author

@Kubuxu any thoughts on this PR? It is pretty straightforward as a workaround. If you prefer to re-vendor a patched-up version into gx - I sadly couldn't figure out how to do that :(

@Kubuxu
Copy link
Member

Kubuxu commented May 17, 2018

@mib-kd743naq does this patch apply on a master HEAD of gogo-protobuf?

@mib-kd743naq
Copy link
Contributor Author

@Kubuxu yeah, with offsets:

~/dev$ cat regen_pb
--- marshalto.go.orig   2018-05-11 11:46:57.000000000 +0200
+++ marshalto.go        2018-05-11 11:49:04.265919111 +0200
@@ -132 +132 @@
-       "sort"
+//     "sort"
@@ -1147,2 +1147,2 @@
-               fields := orderFields(message.GetField())
-               sort.Sort(fields)
+//             fields := orderFields(message.GetField())
+//             sort.Sort(fields)
~/dev$ git clone https://github.com/gogo/protobuf
Cloning into 'protobuf'...
remote: Counting objects: 23896, done.
remote: Compressing objects: 100% (344/344), done.
remote: Total 23896 (delta 280), reused 318 (delta 168), pack-reused 23381
Receiving objects: 100% (23896/23896), 31.60 MiB | 1.01 MiB/s, done.
Resolving deltas: 100% (16852/16852), done.
Checking connectivity... done.
~/dev$ patch protobuf/plugin/marshalto/marshalto.go < regen_pb
patching file protobuf/plugin/marshalto/marshalto.go
Hunk #1 succeeded at 138 (offset 6 lines).
Hunk #2 succeeded at 1110 (offset -37 lines).

export PATH=".:$PATH"
protoc -I. -I$GOPATH/src/$GOGO_GX -I$GOPATH/src/$GOGO_GX/protobuf --gofast_gxpin_out=. merkledag.proto

perl -p -i -e "s{github.com/gogo/protobuf}{$GOGO_GX}g" merkledag.pb.go merkledagpb_test.go
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would be great to have a couple comments here describing what this perl does. In case it needs to be rewritten in the future because some platforms wont have perl installed

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note: This is actually a fairly simple one liner that is just replacing github.com/gogo/protobuf with $GOGO_GX (after being expanded by the shell) in the files merkledag.pb.go and merkledagpb_test.go. 's{}{}' is used instead of 's///' to avoid unnecessary escaping.

@whyrusleeping
Copy link
Member

Also, ideally, this would allow us to update to a newer version of the protobuf library.

@mib-kd743naq
Copy link
Contributor Author

mib-kd743naq commented May 29, 2018

@whyrusleeping I guess you maen #3214. I can give it a shot ( will close this PR and try a new one later tonight to reduce churn ).

Is the desire to throw away the tests to make the gx-snapshot smaller still valid?

@whyrusleeping
Copy link
Member

@mib-kd743naq Yeah, having 40MB worth of code in a dependency is pretty annoying. I would love to have that fixed.

@EnchanterIO
Copy link
Contributor

Hey guys, if u manage to figure it out, also have no idea, would be amazing if there could be a new rule in the Makefile new Protobuf section, aside Build like: make protobuf or whatever that would recompile all the IPFS proto files. (I am trying to do something and had to edit the proto definitions)

For now I installed protobuf globally then run into few errors regarding version as it's old but it works.

Good job with the project btw!

@Kubuxu
Copy link
Member

Kubuxu commented Jun 1, 2018

@EnchanterIO, in general, you can run make merkledag/pb/merkledag.pb.go but the problem is getting correct protobuf generator binary.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants