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

cleanup go.mod #137

Merged
merged 13 commits into from
Nov 30, 2020
Merged

cleanup go.mod #137

merged 13 commits into from
Nov 30, 2020

Conversation

zhangchiqing
Copy link
Member

Remove the replace in go.mod to fix circular dependency

@zhangchiqing zhangchiqing force-pushed the leo/remove-replace branch 2 times, most recently from 64798f9 to e5e72dc Compare November 9, 2020 23:32
@zhangchiqing zhangchiqing marked this pull request as ready for review November 9, 2020 23:42
@@ -60,8 +60,6 @@ require (

replace mellium.im/sasl => github.com/mellium/sasl v0.2.1

replace github.com/onflow/flow-go => ./
Copy link
Member

Choose a reason for hiding this comment

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

Why did we have this in the first place?

Copy link
Contributor

Choose a reason for hiding this comment

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

I remember there being a reason for this, but I can't remember why 😓 I'll try to dig up the PR.

I'd say that if everything builds and all the test pass without it, we should remove it.

Copy link
Member

Choose a reason for hiding this comment

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

I think this was temporary during the GH org migration

Copy link
Contributor

Choose a reason for hiding this comment

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

Found the relevant PR: https://github.com/dapperlabs/flow-go/pull/1959#discussion_r361214248

I think it's okay to remove all of these replaces if the tests pass without them

Copy link
Member Author

Choose a reason for hiding this comment

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

I can't remove them all, as you can see, the build will failure.

I can only remove this line to fix the build. But I don't understand why other "replace"s can't be removed

Copy link
Member

Choose a reason for hiding this comment

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

I think part of the issue is the integration package is pinning a very old version of flow-go. With the replace that old version gets replaced by whatever is in the replacement path on the machine but without the replace we actually fetch that old version.

go.mod Outdated Show resolved Hide resolved
@turbolent
Copy link
Member

@turbolent
Copy link
Member

@zhangchiqing flow-go is already using new code of the crypto library, even though that hasn't been "released" yet. crypto needs to get tagged with a new release. cc @tarakby @Kay-Zee

@Kay-Zee
Copy link
Member

Kay-Zee commented Nov 10, 2020

I've release the crypto package, at the same commit as v0.11.0: https://github.com/onflow/flow-go/releases/tag/crypto%2Fv0.11.0

@zhangchiqing
Copy link
Member Author

@zhangchiqing flow-go is already using new code of the crypto library, even though that hasn't been "released" yet. crypto needs to get tagged with a new release. cc @tarakby @Kay-Zee

Does it mean, with the "replace", flow-go will refer to the crypto code on the same commit. Whereas, without the "replace", it will refer to the code on the latest "release"?

If that's the case, I think we should keep the two "replace", so that code is always compatible with the version on the same commit. no?

@turbolent
Copy link
Member

Does it mean, with the "replace", flow-go will refer to the crypto code on the same commit. Whereas, without the "replace", it will refer to the code on the latest "release"?

If that's the case, I think we should keep the two "replace", so that code is always compatible with the version on the same commit. no?

Yes, when the replace statement is there/kept, the latest version of the crypto code is used.
However, Go does not use it (!) when the flow-go itself is used as a dependency elsewhere, and this is oddly by design: golang/go#30354

Keeping the statement will "fix" the issue for this repo, but it breaks downstream dependencies like the emulator, which imports flow-go.

@turbolent
Copy link
Member

See golang/go#30354 (comment):

replace is intended to support local development

go.mod Outdated
Comment on lines 63 to 71
// needed otherwise the code refers to the crypto package will refer to
// the released version of the crypto library, which might not be the latest
replace github.com/onflow/flow-go/crypto => ./crypto
Copy link
Member

Choose a reason for hiding this comment

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

Instead of this replace statement, crypto should be bumped to crypto/v0.11.0

Copy link
Member

Choose a reason for hiding this comment

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

I agree with Bastian on this. We should pin a specific version and keep it up to date. Otherwise importers of flow-go could have crypto-dependent flow-go packages that either don't compile or are invisibly using an older version of crypto.

Copy link
Member Author

Choose a reason for hiding this comment

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

I agree. I was trying that, but for some reason, it didn't work.

The version for crypto has been pinned here. Suppose we no longer need this replace. But if I remove it, make lint will start complaining.

Not sure what's the proper fix.

Copy link
Member

Choose a reason for hiding this comment

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

I guess this is why:

flow-go/crypto/README.md

Lines 16 to 26 in f84b80f

If you wish to only import the Flow cryptography package to your Go project, please follow the following steps:
- Get Flow cryptography package.
```
go get github.com/onflow/flow-go/crypto
```
- Install [CMake](https://cmake.org/install/), which is used for building the package.
- From the package directory in `$GOPATH/pkg/mod/github.com/onflow/`, build the package dependencies.
```
go generate
```

When we pin a version, Go will download a new copy in pkg/mod and that copy hasn't had the extra C build steps applied to it. We would need to follow @tarakby's instructions for the copy managed by go mod. Probably we would need to do that every time we change the version. From a bit of searching it doesn't really seem like Go has a good solution for modules that require a non-Go build step.

Copy link
Contributor

@tarakby tarakby Nov 24, 2020

Choose a reason for hiding this comment

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

I think there is another reason for @zhangchiqing's linter issues that need to be solved.
When we go get Flow crypto lib, the C source code of the package is copied along with Go files to pkg/mod. What I recommended in the readme is only related to the Relic dependency.

Update: Relic dependency is actually what was missing. cgo could work properly once I followed the readme step (still v0.11.0 is an outdated version and needs to be updated)

@zhangchiqing zhangchiqing requested review from Kay-Zee, turbolent and jordanschalm and removed request for m4ksio November 10, 2020 16:49
@@ -23,6 +23,6 @@ require (

replace github.com/onflow/flow-go => ../
Copy link
Member

Choose a reason for hiding this comment

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

Here I think it's ok to keep this at least in the short term 👍. Integration tests aren't really intended to be imported to other projects.

@turbolent
Copy link
Member

Brought it up yesterday again (https://axiomzen.slack.com/archives/C015G65HR2P/p1606232145256900): the replace statements should be removed and crypto should be tagged instead.

@zhangchiqing
Copy link
Member Author

I did the following thing to resolve the dependencies for now:

  1. I made a tag for crypto/v0.12.0
  2. I cherry-picked changes and applied to v0.12.1, and tagged a new version v0.12.2, which pinned crypto to be v0.12.0. This allows projects like emulator / flow-mgmt to depend on flow-go v0.12.2 and crypto v0.12.0 without running into version issues. (however, this might still require to run go generate in $GOPATH/pkg/mod/github.com/onflow/flow-go/crypto@v0.12.0/).
  3. I pinned the crypto version to be v0.12.0 in this repo.

I have tested that it works:

  1. in a project (flow-mgmt), I imported both flow-go and flow-go/crypto:
import (
	flowcrypto "github.com/onflow/flow-go/crypto"
)

func NewBLSKey() {
	hasher := flowcrypto.NewBLSKMAC("G")
	fmt.Println("hasher", hasher)
}
  1. ran go build -tags=relic will fail:
# github.com/onflow/flow-go/crypto
In file included from ../gopath/pkg/mod/github.com/onflow/flow-go/crypto@v0.12.0/bls.go:32:
../gopath/pkg/mod/github.com/onflow/flow-go/crypto@v0.12.0/bls_include.h:8:10: fatal error: 'relic.h' file not found
#include "relic.h"
         ^~~~~~~~~
1 error generated.
  1. I fixed by running go generate:
cd $GOPATH/pkg/mod/github.com/onflow/flow-go/crypto@v0.12.0/
sudo go generate

After that, I'm able to make a build without the error.

crypto/build_dependency.sh Outdated Show resolved Hide resolved
crypto/build_dependency.sh Outdated Show resolved Hide resolved
integration/go.mod Outdated Show resolved Hide resolved
integration/go.mod Outdated Show resolved Hide resolved
@jordanschalm jordanschalm self-requested a review November 30, 2020 18:24
Co-authored-by: Jordan Schalm <jordan@dapperlabs.com>
@turbolent
Copy link
Member

@zhangchiqing Fantastic work, thank you so much for cleaning this up! 👏 🏅

Copy link
Member

@turbolent turbolent left a comment

Choose a reason for hiding this comment

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

Great work!

Copy link
Member

@jordanschalm jordanschalm left a comment

Choose a reason for hiding this comment

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

This changes our setup process as well.

Do we need to update Git submodules any more if we aren't directly working on crypto?

flow-go/README.md

Lines 60 to 64 in a406926

- Clone this repository's submodules:
```bash
git submodule update --init --recursive
```

We also need to ensure the go generate gets run after a fresh install and every time we change the version of flow-go/crypto dependency:

cd $GOPATH/pkg/mod/github.com/onflow/flow-go/crypto@v0.12.0/
sudo go generate

Should we put this in README as a manual step?

Copy link
Contributor

@tarakby tarakby left a comment

Choose a reason for hiding this comment

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

Thank you Leo for looking at this!

@zhangchiqing
Copy link
Member Author

zhangchiqing commented Nov 30, 2020

We also need to ensure the go generate gets run after a fresh install and every time we change the version of flow-go/crypto dependency:

We don't need to run go generate if we are working flow-go itself, because we have the replace statement in go.mod

We also don't need to run go generate if flow-go/crypto is imported as a dependency in other project, and that project doesn't use modules like BLS signature, which requires the relic flag.

It's only needed when flow-go/crypto is imported as a dependency in other project, and that project uses modules that requires to build with relic flag.

@jordanschalm
Copy link
Member

we have the replace statement in go.mod

I see, I was still was thinking we would remove that as well. Thanks @zhangchiqing

@zhangchiqing
Copy link
Member Author

I see, I was still was thinking we would remove that as well

That's the tradeoff. If we remove the "replace", we could ensure the flow-go use the right crypto library. However, everytime we make changes to crypto, and tag a new version, people will have to run go generate, and hate Tarak :p

If we were to remove the "replace", maybe even makes sense to make crypto as a stand alone repo, but we will still have to run go generate every time crypto make change.

so I think it's easier just to keep the replace.

@zhangchiqing zhangchiqing merged commit 7ea3685 into master Nov 30, 2020
@zhangchiqing zhangchiqing deleted the leo/remove-replace branch November 30, 2020 20:46
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