Skip to content

Latest commit

 

History

History
312 lines (241 loc) · 14.5 KB

CONTRIBUTING.md

File metadata and controls

312 lines (241 loc) · 14.5 KB

Contributing

Thank you for considering making contributions to Gaia and related repositories!

Contributing to this repo can mean many things such as participating in discussion or proposing code changes. To ensure a smooth workflow for all contributors, a general procedure for contributing has been established:

  1. Either open or find an issue you'd like to help with
  2. Participate in thoughtful discussion on that issue
  3. If you would like to contribute:
    1. If the issue is a proposal, ensure that the proposal has been accepted
    2. Ensure that nobody else has already begun working on this issue, if they have make sure to contact them to collaborate
    3. If nobody has been assigned the issue and you would like to work on it make a comment on the issue to inform the community of your intentions to begin work
    4. Follow standard Github best practices: fork the repo, branch from the HEAD of main, make some commits, and submit a PR to main
      • For core developers working within the Gaia repo, to ensure a clear ownership of branches, branches must be named with the convention {moniker}/{issue#}-branch-name
    5. Be sure to submit the PR in Draft mode. Submit your PR early, even if it's incomplete as this indicates to the community you're working on something and allows them to provide comments early in the development process
    6. When the code is complete it can be marked Ready for Review
    7. Be sure to include a relevant change log entry in the Unreleased section of CHANGELOG.md (see file for log format)

Note that for very small or blatantly obvious problems (such as typos) it is not required to an open issue to submit a PR, but be aware that for more complex problems/features, if a PR is opened before an adequate design discussion has taken place in a github issue, that PR runs a high likelihood of being rejected.

Take a peek at our coding repo for overall information on repository workflow and standards. Note, we use make tools for installing the linting tools.

Other notes:

  • Looking for a good place to start contributing? How about checking out some good first issues
  • Please make sure to run make format before every commit - the easiest way to do this is have your editor run it for you upon saving a file. Additionally please ensure that your code is lint compliant by running golangci-lint run. A convenience git pre-commit hook that runs the formatters automatically before each commit is available in the contrib/githooks/ directory.

Submissions

Generally, when structuring a submission for the Cosmos ecosystem, the submission might span multiple layers of the technology stack, including the Cosmos SDK and Tendermint dependencies.

Structuring a submission

To accommodate review process we suggest that PRs are categorically broken up. Ideally each PR addresses only a single issue. Additionally, as much as possible code refactoring and cleanup should be submitted as a separate PRs from bugfixes/feature-additions.

In order to simplify reviewing large changes, submissions should have a created an issue with a description of the submission, a description tracking the changes and relevant discussions, and a checklist of changes and tasks to be done.

The issue can then be used to develop multiple well-scoped PRs that are easy to review.

The following PR structuring checklist can be used when submitting changes to the Gaia repository for review:

  • Proto files: PR updating proto files. As a suggested next step, don't regenerate updated protobuf implementations using protgen, since this will break existing code.
  • Broken code: If protogen is run, a PR disabling broken code
  • Validation: PR with validation of types
  • Functionality: PR integrating supporting functionality
  • Servers: PR for msgserver and queryserver
  • CLI: PR for CLI commands
  • Orchestrators: PR for any orchestrators
  • Genesis: PR for genesis
  • Upgrades: PR for upgrades

Process for reviewing PRs

All PRs require at least one review before merge (except docs changes, or variable name-changes which only require one). When reviewing PRs please use the following review explanations:

  • LGTM without an explicit approval means that the changes look good, but you haven't pulled down the code, run tests locally and thoroughly reviewed it.
  • Approval through the GH UI means that you understand the code, documentation/spec is updated in the right places, you have pulled down and tested the code locally. In addition:
    • You must also think through anything which ought to be included but is not
    • You must think through whether any added code could be partially combined (DRYed) with existing code
    • You must think through any potential security issues or incentive-compatibility flaws introduced by the changes
    • Naming must be consistent with conventions and the rest of the codebase
    • Code must live in a reasonable location, considering dependency structures (e.g. not importing testing modules in production code, or including example code modules in production code).
    • if you approve of the PR, you are responsible for fixing any of the issues mentioned here and more
  • If you sat down with the PR submitter and did a pairing review please note that in the Approval, or your PR comments.
  • If you are only making "surface level" reviews, submit any notes as Comments without adding a review.

Updating Documentation

If you open a PR in Gaia, it is mandatory to update the relevant documentation in /docs.

  • If your changes relate specifically to the gaia application, please modify the docs/ folder.

Forking

Please note that Go requires code to live under absolute paths, which complicates forking. While my fork lives at https://github.com/rigeyrigerige/gaia, the code should never exist at $GOPATH/src/github.com/rigeyrigerige/gaia. Instead, we use git remote to add the fork as a new remote for the original repo, $GOPATH/src/github.com/cosmos/gaia, and do all the work there.

For instance, to create a fork and work on a branch of it, I would:

  • Create the fork on github, using the fork button.
  • Go to the original repo checked out locally (i.e. $GOPATH/src/github.com/cosmos/gaia)
  • git remote rename origin upstream
  • git remote add origin git@github.com:rigeyrigerige/gaia.git

Now origin refers to my fork and upstream refers to the Gaia version. So I can git push -u origin main to update my fork, and make pull requests to Gaia from there. Of course, replace rigeyrigerige with your git handle.

To pull in updates from the origin repo, run

  • git fetch upstream
  • git rebase upstream/main (or whatever branch you want)

Please don't make Pull Requests to main.

Dependencies

We use Go Modules to manage dependency versions.

The main branch of every Cosmos repository should just build with go get, which means they should be kept up-to-date with their dependencies so we can get away with telling people they can just go get our software.

When dependencies in Gaia's go.mod are changed, it is generally accepted practice to delete go.sum and then run go mod tidy.

Since some dependencies are not under our control, a third party may break our build, in which case we can fall back on go mod tidy -v.

Testing

When testing a function under a variety of different inputs, we prefer to use table driven tests. Table driven test error messages should follow the following format <desc>, tc #<index>, i #<index>. <desc> is an optional short description of whats failing, tc is the index within the table of the testcase that is failing, and i is when there is a loop, exactly which iteration of the loop failed. The idea is you should be able to see the error message and figure out exactly what failed. Here is an example check:

<some table>
for tcIndex, tc := range cases {
<some code>
for i := 0; i < tc.numTxsToTest; i++ {
<some code>
require.Equal(t, expectedTx[:32], calculatedTx[:32],
"First 32 bytes of the txs differed. tc #%d, i #%d", tcIndex, i)

Branching Model and Release

User-facing repos should adhere to the trunk based development branching model.

Libraries need not follow the model strictly, but would be wise to.

Gaia utilizes semantic versioning.

PR Targeting

Ensure that you base and target your PR on the main branch.

All feature additions should be targeted against main. Bug fixes for an outstanding release candidate should be targeted against the release candidate branch. Release candidate branches themselves should be the only pull requests targeted directly against main.

Development Procedure

  • the latest state of development is on main
  • main must never fail make test or make test_cli
  • main should not fail make lint
  • no --force onto main (except when reverting a broken commit, which should seldom happen)
  • create a development branch either on https://github.com/cosmos/gaia, or your fork (using git remote add origin)
  • before submitting a pull request, begin git rebase on top of main

Pull Merge Procedure

  • ensure pull branch is rebased on main
  • run make test and make test_cli to ensure that all tests pass
  • merge pull request

Semantic PR title

Starts the title of the pull request with feat:, indicating that the contents of the pull request can best be characterized as a new feature. This follows the convention used on top of commit messages:

  • feat for a new feature for the user, not a new feature for build script. Such commit will trigger a release bumping a MINOR version.
  • fix for a bug fix for the user, not a fix to a build script. Such commit will trigger a release bumping a PATCH version.
  • chore for updating grunt tasks etc; no production code change.
  • perf for performance improvements. Such commit will trigger a release bumping a PATCH version.
  • docs for changes to the documentation.
  • style for formatting changes, missing semicolons, etc.
  • refactor for refactoring production code, e.g. renaming a variable.
  • test for adding missing tests, refactoring tests; no production code change.
  • build for updating build configuration, development tools or other changes irrelevant to the user.

This GitHub action helps to follow this guideline.

Branch name

Branch naming conventions

Starts the branch name indicates the content of the pull request:

  • feat: Feature I'm adding or expanding
  • fix: Bug fix
  • chore: No code logic change
  • test: Adding more tests
  • junk: Throwaway branch created to experiment
Use slashes to separate parts

You may use most any delimiter you like in branch names, but I find slashes to be the most flexible. You might prefer to use dashes or dots. But slashes let you do some branch renaming when pushing or fetching to/from a remote.

$ git push origin 'refs/heads/feature/:refs/heads/phord/feat/' $ git push origin 'refs/heads/bug/:refs/heads/review/bugfix/'

For me, slashes also work better for tab expansion (command completion) in my shell. The way I have it configured I can search for branches with different sub-parts by typing the first characters of the part and pressing the TAB key. Zsh then gives me a list of branches which match the part of the token I have typed. This works for preceding tokens as well as embedded ones.

$ git checkout feat<TAB>
Menu:  feat/frabnotz   feat/foo   feat/bar
$ git checkout foo<TAB>
Menu:  feat/foo   fix/foo   chore/foo

It also lets you search for branches in many git commands, like this:

git branch --list "feat/*"
git log --graph --oneline --decorate --branches="feat/*"
gitk --branches="feat/*"

Avoid long descriptive names

Long branch names can be very helpful when you are looking at a list of branches. But it can get in the way when looking at decorated one-line logs as the branch names can eat up most of the single line and abbreviate the visible part of the log. On the other hand long branch names can be more helpful in "merge commits" if you do not habitually rewrite them by hand. The default merge commit message is Merge branch 'branch-name'. You may find it more helpful to have merge messages show up as Merge branch 'fix/CR15032/crash-when-unformatted-disk-inserted' instead of just Merge branch ' fix/CR15032'.

Commit message

  • Do not end the subject line with a period
  • Capitalize the subject line and each paragraph
  • Use the imperative mood in the subject line
  • Wrap lines at 72 characters
  • Information in commit messages
  • Describe why a change is being made.
  • Do not assume the reviewer understands what the original problem was.
  • Do not assume the code is self-evident/self-documenting.
  • Read the commit message to see if it hints at improved code structure.
  • Describe any limitations of the current code.
  • Do not include patch set-specific comments.

Code Guidelines

If you want to contribute to a project and improve it, your help is welcome. We want to make Gaia as good as it can be. Contributing is also a great way to learn more about blockchain technology and improve it. Please read the code guidelines document and follow it.