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

feat: support build with rocksdb backend in CI #17346

Merged
merged 2 commits into from
Aug 11, 2023

Conversation

yihuang
Copy link
Collaborator

@yihuang yihuang commented Aug 10, 2023

Description

WIP: #17341

  • bump cometbft-db dependency to switch to grocksdb
  • use nix to install librocksdb in CI.

a little doc:

  • nix build . build simapp in working directory, the result binary is in ./result/bin/simd by default.
  • nix run . -- version run the simapp directly, it's built on the fly.
  • nix run github:cosmos/cosmos-sdk -- version, run the simapp from a remote version, it'll clone code, build, and run it automatically.
  • nix develop, drop into a shell which contains go and librocksdb dependencies.
  • nix develop -c "go version", in case you don't have interactive shell.

Author Checklist

All items are required. Please add a note to the item if the item is not applicable and
please add links to any relevant follow up issues.

I have...

  • included the correct type prefix in the PR title
  • added ! to the type prefix if API or client breaking change
  • targeted the correct branch (see PR Targeting)
  • provided a link to the relevant issue or specification
  • followed the guidelines for building modules
  • included the necessary unit and integration tests
  • added a changelog entry to CHANGELOG.md
  • included comments for documenting Go code
  • updated the relevant documentation or specification
  • reviewed "Files changed" and left comments if necessary
  • run make lint and make test
  • confirmed all CI checks have passed

Reviewers Checklist

All items are required. Please add a note if the item is not applicable and please add
your handle next to the items reviewed if you only reviewed selected items.

I have...

  • confirmed the correct type prefix in the PR title
  • confirmed ! in the type prefix if API or client breaking change
  • confirmed all author checklist items have been addressed
  • reviewed state machine logic
  • reviewed API design and naming
  • reviewed documentation is accurate
  • reviewed tests and test coverage
  • manually tested (if applicable)

@yihuang yihuang changed the title support build with rocksdb backend in CI feat: support build with rocksdb backend in CI Aug 10, 2023
- name: Build rocksdb
if: |
env.GIT_DIFF &&
matrix.go-arch == 'amd64'
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

only do once, since we don't want to cross-compiling librocksdb itself.

@yihuang yihuang marked this pull request as ready for review August 10, 2023 07:21
@yihuang yihuang requested a review from a team as a code owner August 10, 2023 07:21
@yihuang yihuang requested review from alexanderbez and removed request for kocubinski and julienrbrt August 10, 2023 07:23
Copy link
Member

@tac0turtle tac0turtle left a comment

Choose a reason for hiding this comment

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

looks good, once we have store in ci then we can run store tests with rocksdb but for now this is fine.

@yihuang
Copy link
Collaborator Author

yihuang commented Aug 10, 2023

looks good, once we have store in ci then we can run store tests with rocksdb but for now this is fine.

flaky-ed the simapp, more idiomatic nix usage, added a little doc in PR description.

@julienrbrt
Copy link
Member

julienrbrt commented Aug 10, 2023

Say we run a go mod tidy, do we need to update those nix files as well so they are in sync?
A bit worried it will get out of sync fast.

Would not it be simpler to create a docker image with the necessary rocksdb deps and build simapp using it?

@yihuang
Copy link
Collaborator Author

yihuang commented Aug 10, 2023

Say we run a go mod tidy, do we need to update those nix files as well so they are in sync? A bit worried it will get out of sync fast.

Would not it be simpler to create a docker image with the necessary rocksdb deps and build simapp using it?

nix expressions are more maintainable than docker image, much more convenient to use IHO. but take some time to get familiar with first.

@yihuang
Copy link
Collaborator Author

yihuang commented Aug 10, 2023

Say we run a go mod tidy, do we need to update those nix files as well so they are in sync? A bit worried it will get out of sync fast.
Would not it be simpler to create a docker image with the necessary rocksdb deps and build simapp using it?

nix expressions are more maintainable than docker image, much more convenient to use IHO. but take some time to get familiar with first.

it also serves as an example for other chains how to build their binaries with rocksdb properly, it can do cross-compiling, static-linking out of the box, for example:

  • cross compile a arm64 linux static linked rocksdb powered simd on x86 macos:
    nix build .#legacyPackages.x86_64-darwin.pkgsCross.aarch64-multiplatform.pkgsStatic.simd

@julienrbrt
Copy link
Member

julienrbrt commented Aug 10, 2023

Def sounds interesting, I need to look more into it!

How do you keep gomod2nix.toml in sync?
We run / A bot runs ./scripts/go-mod-tidy-all.sh to go mod tidy our modules. Could you add something in the Makefile and call that from the script so that simapp's go.mod and simapp's gomod2nix.toml stay in sync? Unless it isn't necessary, but I am curious how it updates otherwise.

nix build . build simapp in working directory, the result binary is in ./result/bin/simd by default.

I would love if it could go to ./build instead like make build. Or we should that result folder to the .gitignore.

@yihuang
Copy link
Collaborator Author

yihuang commented Aug 10, 2023

Def sounds interesting, I need to look more into it!

How do you keep gomod2nix.toml in sync? We run / A bot runs ./scripts/go-mod-tidy-all.sh to go mod tidy our modules. Could you add something in the Makefile and call that from the script so that simapp's go.mod and simapp's gomod2nix.toml stay in sync? Unless it isn't necessary, but I am curious how it updates otherwise.

done, added to the script.

nix build . build simapp in working directory, the result binary is in ./result/bin/simd by default.

I would love if it could go to ./build instead like make build. Or we should that result folder to the .gitignore.

the result file is a symbolic link into somewhere in /nix/store, it's just the default choice of nix command, you can pick a different one using -o flag:

nix build . -o ./build/simd

Copy link
Member

@julienrbrt julienrbrt left a comment

Choose a reason for hiding this comment

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

utACK.
I need to go read the nix docs now.

flake.nix Outdated
defaultApp = apps.simd;
devShell = with pkgs; mkShell {
buildInputs = [
go_1_20
Copy link
Member

@julienrbrt julienrbrt Aug 10, 2023

Choose a reason for hiding this comment

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

Can we add a useless comment like // Use Go 1.20 version, that helps when we search / replace the Go version :)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

sure, done

@alexanderbez
Copy link
Contributor

This is so cool and extremely helpful, thanks @yihuang! We should really look into nix for binary creation and distribution. Having a pre-built cross-compiled binary with linked libs out of the box is a game changer IMO

simd = with pkgs; mkShell {
buildInputs = [
go_1_20 # Use Go 1.20 version
rocksdb
Copy link
Contributor

Choose a reason for hiding this comment

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

How do we specifiy which version of the librocksdb we want?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

There are several ways:

  1. Pin to a nixpkgs version that contains the desired rocksdb version, that happens to be the case right now
  2. Override the src tarball in rocksdb derivative, for example in the overlay:
rocksdb = prev.rocksdb.overrides {
  version = xxx;
  src = fetchGithub {
    repo
    hash
    etc..
  };
};

Copy link
Contributor

@alexanderbez alexanderbez left a comment

Choose a reason for hiding this comment

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

LGTM!

Nit: Not sure this actually closes #17341? I think we need to merge this, rebase main onto feature/store-v2 and then update the test-store job.

Also lint needs to be updated prior to merging :)

@julienrbrt
Copy link
Member

Looks like it is blocked on the lint job, however make lint just works fine locally and in other PR. Could you maybe rebase?

WIP: cosmos#17341

- bump cometbft-db dependency to switch to grocksdb
- add nix flakes to help build with rocksdb dependency
@yihuang
Copy link
Collaborator Author

yihuang commented Aug 11, 2023

Nit: Not sure this actually closes #17341?

changed to WIP

@alexanderbez alexanderbez added this pull request to the merge queue Aug 11, 2023
Merged via the queue into cosmos:main with commit d2b93e0 Aug 11, 2023
37 of 41 checks passed
@yihuang yihuang deleted the nix-rocksdb branch August 11, 2023 08:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants