/ CONTRIBUTING.md
CONTRIBUTING.md
  1  Contributing to Bitcoin Core
  2  ============================
  3  
  4  The Bitcoin Core project operates an open contributor model where anyone is
  5  welcome to contribute towards development in the form of peer review, testing
  6  and patches. This document explains the practical process and guidelines for
  7  contributing.
  8  
  9  First, in terms of structure, there is no particular concept of "Bitcoin Core
 10  developers" in the sense of privileged people. Open source often naturally
 11  revolves around a meritocracy where contributors earn trust from the developer
 12  community over time. Nevertheless, some hierarchy is necessary for practical
 13  purposes. As such, there are repository maintainers who are responsible for
 14  merging pull requests, the [release cycle](/doc/release-process.md), and
 15  moderation.
 16  
 17  Getting Started
 18  ---------------
 19  
 20  New contributors are very welcome and needed.
 21  
 22  Reviewing and testing is highly valued and the most effective way you can contribute
 23  as a new contributor. It also will teach you much more about the code and
 24  process than opening pull requests. Please refer to the [peer review](#peer-review)
 25  section below.
 26  
 27  Before you start contributing, familiarize yourself with the Bitcoin Core build
 28  system and tests. Refer to the documentation in the repository on how to build
 29  Bitcoin Core and how to run the unit tests, functional tests, and fuzz tests.
 30  
 31  There are many open issues of varying difficulty waiting to be fixed.
 32  If you're looking for somewhere to start contributing, check out the
 33  [good first issue](https://github.com/bitcoin/bitcoin/issues?q=is%3Aopen+is%3Aissue+label%3A%22good+first+issue%22)
 34  list or changes that are
 35  [up for grabs](https://github.com/bitcoin/bitcoin/issues?utf8=%E2%9C%93&q=label%3A%22Up+for+grabs%22).
 36  Some of them might no longer be applicable. So if you are interested, but
 37  unsure, you might want to leave a comment on the issue first.
 38  
 39  You may also participate in the weekly
 40  [Bitcoin Core PR Review Club](https://bitcoincore.reviews/) meeting.
 41  
 42  ### Good First Issue Label
 43  
 44  The purpose of the `good first issue` label is to highlight which issues are
 45  suitable for a new contributor without a deep understanding of the codebase.
 46  
 47  However, good first issues can be solved by anyone. If they remain unsolved
 48  for a longer time, a frequent contributor might address them.
 49  
 50  You do not need to request permission to start working on an issue. However,
 51  you are encouraged to leave a comment if you are planning to work on it. This
 52  will help other contributors monitor which issues are actively being addressed
 53  and is also an effective way to request assistance if and when you need it.
 54  
 55  Communication Channels
 56  ----------------------
 57  
 58  Most communication about Bitcoin Core development happens on IRC, in the
 59  `#bitcoin-core-dev` channel on Libera Chat. The easiest way to participate on IRC is
 60  with the web client, [web.libera.chat](https://web.libera.chat/#bitcoin-core-dev). Chat
 61  history logs can be found
 62  on [https://www.erisian.com.au/bitcoin-core-dev/](https://www.erisian.com.au/bitcoin-core-dev/)
 63  and [https://gnusha.org/bitcoin-core-dev/](https://gnusha.org/bitcoin-core-dev/).
 64  
 65  Discussion about codebase improvements happens in GitHub issues and pull
 66  requests.
 67  
 68  The developer
 69  [mailing list](https://lists.linuxfoundation.org/mailman/listinfo/bitcoin-dev)
 70  should be used to discuss complicated or controversial consensus or P2P protocol changes before working on
 71  a patch set.
 72  
 73  
 74  Contributor Workflow
 75  --------------------
 76  
 77  The codebase is maintained using the "contributor workflow" where everyone
 78  without exception contributes patch proposals using "pull requests" (PRs). This
 79  facilitates social contribution, easy testing and peer review.
 80  
 81  To contribute a patch, the workflow is as follows:
 82  
 83    1. Fork repository ([only for the first time](https://docs.github.com/en/get-started/quickstart/fork-a-repo))
 84    1. Create topic branch
 85    1. Commit patches
 86  
 87  For GUI-related issues or pull requests, the https://github.com/bitcoin-core/gui repository should be used.
 88  For all other issues and pull requests, the https://github.com/bitcoin/bitcoin node repository should be used.
 89  
 90  The master branch for all monotree repositories is identical.
 91  
 92  As a rule of thumb, everything that only modifies `src/qt` is a GUI-only pull
 93  request. However:
 94  
 95  * For global refactoring or other transversal changes the node repository
 96    should be used.
 97  * For GUI-related build system changes, the node repository should be used
 98    because the change needs review by the build systems reviewers.
 99  * Changes in `src/interfaces` need to go to the node repository because they
100    might affect other components like the wallet.
101  
102  For large GUI changes that include build system and interface changes, it is
103  recommended to first open a pull request against the GUI repository. When there
104  is agreement to proceed with the changes, a pull request with the build system
105  and interfaces changes can be submitted to the node repository.
106  
107  The project coding conventions in the [developer notes](doc/developer-notes.md)
108  must be followed.
109  
110  ### Committing Patches
111  
112  In general, [commits should be atomic](https://en.wikipedia.org/wiki/Atomic_commit#Atomic_commit_convention)
113  and diffs should be easy to read. For this reason, do not mix any formatting
114  fixes or code moves with actual code changes.
115  
116  Make sure each individual commit is hygienic: that it builds successfully on its
117  own without warnings, errors, regressions, or test failures.
118  
119  Commit messages should be verbose by default consisting of a short subject line
120  (50 chars max), a blank line and detailed explanatory text as separate
121  paragraph(s), unless the title alone is self-explanatory (like "Correct typo
122  in init.cpp") in which case a single title line is sufficient. Commit messages should be
123  helpful to people reading your code in the future, so explain the reasoning for
124  your decisions. Further explanation [here](https://chris.beams.io/posts/git-commit/).
125  
126  If a particular commit references another issue, please add the reference. For
127  example: `refs #1234` or `fixes #4321`. Using the `fixes` or `closes` keywords
128  will cause the corresponding issue to be closed when the pull request is merged.
129  
130  Commit messages should never contain any `@` mentions (usernames prefixed with "@").
131  
132  Please refer to the [Git manual](https://git-scm.com/doc) for more information
133  about Git.
134  
135    - Push changes to your fork
136    - Create pull request
137  
138  ### Creating the Pull Request
139  
140  The title of the pull request should be prefixed by the component or area that
141  the pull request affects. Valid areas as:
142  
143    - `consensus` for changes to consensus critical code
144    - `doc` for changes to the documentation
145    - `qt` or `gui` for changes to bitcoin-qt
146    - `log` for changes to log messages
147    - `mining` for changes to the mining code
148    - `net` or `p2p` for changes to the peer-to-peer network code
149    - `refactor` for structural changes that do not change behavior
150    - `rpc`, `rest` or `zmq` for changes to the RPC, REST or ZMQ APIs
151    - `script` for changes to the scripts and tools
152    - `test`, `qa` or `ci` for changes to the unit tests, QA tests or CI code
153    - `util` or `lib` for changes to the utils or libraries
154    - `wallet` for changes to the wallet code
155    - `build` for changes to the GNU Autotools or MSVC builds
156    - `guix` for changes to the GUIX reproducible builds
157  
158  Examples:
159  
160      consensus: Add new opcode for BIP-XXXX OP_CHECKAWESOMESIG
161      net: Automatically create onion service, listen on Tor
162      qt: Add feed bump button
163      log: Fix typo in log message
164  
165  The body of the pull request should contain sufficient description of *what* the
166  patch does, and even more importantly, *why*, with justification and reasoning.
167  You should include references to any discussions (for example, other issues or
168  mailing list discussions).
169  
170  The description for a new pull request should not contain any `@` mentions. The
171  PR description will be included in the commit message when the PR is merged and
172  any users mentioned in the description will be annoyingly notified each time a
173  fork of Bitcoin Core copies the merge. Instead, make any username mentions in a
174  subsequent comment to the PR.
175  
176  ### Translation changes
177  
178  Note that translations should not be submitted as pull requests. Please see
179  [Translation Process](https://github.com/bitcoin/bitcoin/blob/master/doc/translation_process.md)
180  for more information on helping with translations.
181  
182  ### Work in Progress Changes and Requests for Comments
183  
184  If a pull request is not to be considered for merging (yet), please
185  prefix the title with [WIP] or use [Tasks Lists](https://docs.github.com/en/github/writing-on-github/getting-started-with-writing-and-formatting-on-github/basic-writing-and-formatting-syntax#task-lists)
186  in the body of the pull request to indicate tasks are pending.
187  
188  ### Address Feedback
189  
190  At this stage, one should expect comments and review from other contributors. You
191  can add more commits to your pull request by committing them locally and pushing
192  to your fork.
193  
194  You are expected to reply to any review comments before your pull request is
195  merged. You may update the code or reject the feedback if you do not agree with
196  it, but you should express so in a reply. If there is outstanding feedback and
197  you are not actively working on it, your pull request may be closed.
198  
199  Please refer to the [peer review](#peer-review) section below for more details.
200  
201  ### Squashing Commits
202  
203  If your pull request contains fixup commits (commits that change the same line of code repeatedly) or too fine-grained
204  commits, you may be asked to [squash](https://git-scm.com/docs/git-rebase#_interactive_mode) your commits
205  before it will be reviewed. The basic squashing workflow is shown below.
206  
207      git checkout your_branch_name
208      git rebase -i HEAD~n
209      # n is normally the number of commits in the pull request.
210      # Set commits (except the one in the first line) from 'pick' to 'squash', save and quit.
211      # On the next screen, edit/refine commit messages.
212      # Save and quit.
213      git push -f # (force push to GitHub)
214  
215  Please update the resulting commit message, if needed. It should read as a
216  coherent message. In most cases, this means not just listing the interim
217  commits.
218  
219  If your change contains a merge commit, the above workflow may not work and you
220  will need to remove the merge commit first. See the next section for details on
221  how to rebase.
222  
223  Please refrain from creating several pull requests for the same change.
224  Use the pull request that is already open (or was created earlier) to amend
225  changes. This preserves the discussion and review that happened earlier for
226  the respective change set.
227  
228  The length of time required for peer review is unpredictable and will vary from
229  pull request to pull request.
230  
231  ### Rebasing Changes
232  
233  When a pull request conflicts with the target branch, you may be asked to rebase it on top of the current target branch.
234  
235      git fetch https://github.com/bitcoin/bitcoin  # Fetch the latest upstream commit
236      git rebase FETCH_HEAD  # Rebuild commits on top of the new base
237  
238  This project aims to have a clean git history, where code changes are only made in non-merge commits. This simplifies
239  auditability because merge commits can be assumed to not contain arbitrary code changes. Merge commits should be signed,
240  and the resulting git tree hash must be deterministic and reproducible. The script in
241  [/contrib/verify-commits](/contrib/verify-commits) checks that.
242  
243  After a rebase, reviewers are encouraged to sign off on the force push. This should be relatively straightforward with
244  the `git range-diff` tool explained in the [productivity
245  notes](/doc/productivity.md#diff-the-diffs-with-git-range-diff). To avoid needless review churn, maintainers will
246  generally merge pull requests that received the most review attention first.
247  
248  Pull Request Philosophy
249  -----------------------
250  
251  Patchsets should always be focused. For example, a pull request could add a
252  feature, fix a bug, or refactor code; but not a mixture. Please also avoid super
253  pull requests which attempt to do too much, are overly large, or overly complex
254  as this makes review difficult.
255  
256  
257  ### Features
258  
259  When adding a new feature, thought must be given to the long term technical debt
260  and maintenance that feature may require after inclusion. Before proposing a new
261  feature that will require maintenance, please consider if you are willing to
262  maintain it (including bug fixing). If features get orphaned with no maintainer
263  in the future, they may be removed by the Repository Maintainer.
264  
265  
266  ### Refactoring
267  
268  Refactoring is a necessary part of any software project's evolution. The
269  following guidelines cover refactoring pull requests for the project.
270  
271  There are three categories of refactoring: code-only moves, code style fixes, and
272  code refactoring. In general, refactoring pull requests should not mix these
273  three kinds of activities in order to make refactoring pull requests easy to
274  review and uncontroversial. In all cases, refactoring PRs must not change the
275  behaviour of code within the pull request (bugs must be preserved as is).
276  
277  Project maintainers aim for a quick turnaround on refactoring pull requests, so
278  where possible keep them short, uncomplex and easy to verify.
279  
280  Pull requests that refactor the code should not be made by new contributors. It
281  requires a certain level of experience to know where the code belongs to and to
282  understand the full ramification (including rebase effort of open pull requests).
283  
284  Trivial pull requests or pull requests that refactor the code with no clear
285  benefits may be immediately closed by the maintainers to reduce unnecessary
286  workload on reviewing.
287  
288  
289  "Decision Making" Process
290  -------------------------
291  
292  The following applies to code changes to the Bitcoin Core project (and related
293  projects such as libsecp256k1), and is not to be confused with overall Bitcoin
294  Network Protocol consensus changes.
295  
296  Whether a pull request is merged into Bitcoin Core rests with the project merge
297  maintainers.
298  
299  Maintainers will take into consideration if a patch is in line with the general
300  principles of the project; meets the minimum standards for inclusion; and will
301  judge the general consensus of contributors.
302  
303  In general, all pull requests must:
304  
305    - Have a clear use case, fix a demonstrable bug or serve the greater good of
306      the project (for example refactoring for modularisation);
307    - Be well peer-reviewed;
308    - Have unit tests, functional tests, and fuzz tests, where appropriate;
309    - Follow code style guidelines ([C++](doc/developer-notes.md), [functional tests](test/functional/README.md));
310    - Not break the existing test suite;
311    - Where bugs are fixed, where possible, there should be unit tests
312      demonstrating the bug and also proving the fix. This helps prevent regression.
313    - Change relevant comments and documentation when behaviour of code changes.
314  
315  Patches that change Bitcoin consensus rules are considerably more involved than
316  normal because they affect the entire ecosystem and so must be preceded by
317  extensive mailing list discussions and have a numbered BIP. While each case will
318  be different, one should be prepared to expend more time and effort than for
319  other kinds of patches because of increased peer review and consensus building
320  requirements.
321  
322  
323  ### Peer Review
324  
325  Anyone may participate in peer review which is expressed by comments in the pull
326  request. Typically reviewers will review the code for obvious errors, as well as
327  test out the patch set and opine on the technical merits of the patch. Project
328  maintainers take into account the peer review when determining if there is
329  consensus to merge a pull request (remember that discussions may have been
330  spread out over GitHub, mailing list and IRC discussions).
331  
332  Code review is a burdensome but important part of the development process, and
333  as such, certain types of pull requests are rejected. In general, if the
334  **improvements** do not warrant the **review effort** required, the PR has a
335  high chance of being rejected. It is up to the PR author to convince the
336  reviewers that the changes warrant the review effort, and if reviewers are
337  "Concept NACK'ing" the PR, the author may need to present arguments and/or do
338  research backing their suggested changes.
339  
340  #### Conceptual Review
341  
342  A review can be a conceptual review, where the reviewer leaves a comment
343   * `Concept (N)ACK`, meaning "I do (not) agree with the general goal of this pull
344     request",
345   * `Approach (N)ACK`, meaning `Concept ACK`, but "I do (not) agree with the
346     approach of this change".
347  
348  A `NACK` needs to include a rationale why the change is not worthwhile.
349  NACKs without accompanying reasoning may be disregarded.
350  
351  #### Code Review
352  
353  After conceptual agreement on the change, code review can be provided. A review
354  begins with `ACK BRANCH_COMMIT`, where `BRANCH_COMMIT` is the top of the PR
355  branch, followed by a description of how the reviewer did the review. The
356  following language is used within pull request comments:
357  
358    - "I have tested the code", involving change-specific manual testing in
359      addition to running the unit, functional, or fuzz tests, and in case it is
360      not obvious how the manual testing was done, it should be described;
361    - "I have not tested the code, but I have reviewed it and it looks
362      OK, I agree it can be merged";
363    - A "nit" refers to a trivial, often non-blocking issue.
364  
365  Project maintainers reserve the right to weigh the opinions of peer reviewers
366  using common sense judgement and may also weigh based on merit. Reviewers that
367  have demonstrated a deeper commitment and understanding of the project over time
368  or who have clear domain expertise may naturally have more weight, as one would
369  expect in all walks of life.
370  
371  Where a patch set affects consensus-critical code, the bar will be much
372  higher in terms of discussion and peer review requirements, keeping in mind that
373  mistakes could be very costly to the wider community. This includes refactoring
374  of consensus-critical code.
375  
376  Where a patch set proposes to change the Bitcoin consensus, it must have been
377  discussed extensively on the mailing list and IRC, be accompanied by a widely
378  discussed BIP and have a generally widely perceived technical consensus of being
379  a worthwhile change based on the judgement of the maintainers.
380  
381  ### Finding Reviewers
382  
383  As most reviewers are themselves developers with their own projects, the review
384  process can be quite lengthy, and some amount of patience is required. If you find
385  that you've been waiting for a pull request to be given attention for several
386  months, there may be a number of reasons for this, some of which you can do something
387  about:
388  
389    - It may be because of a feature freeze due to an upcoming release. During this time,
390      only bug fixes are taken into consideration. If your pull request is a new feature,
391      it will not be prioritized until after the release. Wait for the release.
392    - It may be because the changes you are suggesting do not appeal to people. Rather than
393      nits and critique, which require effort and means they care enough to spend time on your
394      contribution, thundering silence is a good sign of widespread (mild) dislike of a given change
395      (because people don't assume *others* won't actually like the proposal). Don't take
396      that personally, though! Instead, take another critical look at what you are suggesting
397      and see if it: changes too much, is too broad, doesn't adhere to the
398      [developer notes](doc/developer-notes.md), is dangerous or insecure, is messily written, etc.
399      Identify and address any of the issues you find. Then ask e.g. on IRC if someone could give
400      their opinion on the concept itself.
401    - It may be because your code is too complex for all but a few people, and those people
402      may not have realized your pull request even exists. A great way to find people who
403      are qualified and care about the code you are touching is the
404      [Git Blame feature](https://docs.github.com/en/github/managing-files-in-a-repository/managing-files-on-github/tracking-changes-in-a-file). Simply
405      look up who last modified the code you are changing and see if you can find
406      them and give them a nudge. Don't be incessant about the nudging, though.
407    - Finally, if all else fails, ask on IRC or elsewhere for someone to give your pull request
408      a look. If you think you've been waiting for an unreasonably long time (say,
409      more than a month) for no particular reason (a few lines changed, etc.),
410      this is totally fine. Try to return the favor when someone else is asking
411      for feedback on their code, and the universe balances out.
412    - Remember that the best thing you can do while waiting is give review to others!
413  
414  
415  Backporting
416  -----------
417  
418  Security and bug fixes can be backported from `master` to release
419  branches.
420  If the backport is non-trivial, it may be appropriate to open an
421  additional PR to backport the change, but only after the original PR
422  has been merged.
423  Otherwise, backports will be done in batches and
424  the maintainers will use the proper `Needs backport (...)` labels
425  when needed (the original author does not need to worry about it).
426  
427  A backport should contain the following metadata in the commit body:
428  
429  ```
430  Github-Pull: #<PR number>
431  Rebased-From: <commit hash of the original commit>
432  ```
433  
434  Have a look at [an example backport PR](
435  https://github.com/bitcoin/bitcoin/pull/16189).
436  
437  Also see the [backport.py script](
438  https://github.com/bitcoin-core/bitcoin-maintainer-tools#backport).
439  
440  Copyright
441  ---------
442  
443  By contributing to this repository, you agree to license your work under the
444  MIT license unless specified otherwise in `contrib/debian/copyright` or at
445  the top of the file itself. Any work contributed where you are not the original
446  author must contain its license header with the original author(s) and source.