Skip to content

Commit 85ff22b

Browse files
committed
docs: update contribution guidelines
1 parent c84a7a9 commit 85ff22b

File tree

1 file changed

+101
-26
lines changed

1 file changed

+101
-26
lines changed

_pages/contribute.md

Lines changed: 101 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,10 @@ permalink: /contribute/
1313
4.2. [Testing](#Testing)<br />
1414
4.3. [Code Documentation and Commenting](#CodeDocumentation)<br />
1515
4.4. [Model Git Commit Messages](#ModelGitCommitMessages)<br />
16-
4.5. [Code Spacing](#CodeSpacing)<br />
17-
4.6. [Protobuf Compilation](#Protobuf)<br />
16+
4.5. [Ideal Git Commit Structure](#IdealGitCommitStructure)<br />
17+
4.6. [Code Spacing](#CodeSpacing)<br />
18+
4.7. [Protobuf Compilation](#Protobuf)<br />
19+
4.8. [Additional Style Constraints On Top of gofmt](ExtraGoFmtStyle)<br />
1820
5. [Code Approval Process](#CodeApproval)<br />
1921
5.1. [Code Review](#CodeReview)<br />
2022
5.2. [Rework Code (if needed)](#CodeRework)<br />
@@ -44,8 +46,8 @@ represent real money and introducing bugs and security vulnerabilities can have
4446
far more dire consequences than in typical projects where having a small bug is
4547
minimal by comparison. In the world of cryptocurrencies, even the smallest bug
4648
in the wrong area can cost people a significant amount of money. For this
47-
reason, the Lightning Network Daemon (lnd) has a formalized and rigorous
48-
development process (heavily insipred by
49+
reason, the Lightning Network Daemon (`lnd`) has a formalized and rigorous
50+
development process (heavily inspired by
4951
[btcsuite](https://github.com/btcsuite)) which is outlined on this page.
5052

5153
We highly encourage code contributions, however it is imperative that you adhere
@@ -84,7 +86,7 @@ security and performance implications.
8486

8587
### 3. Required Reading
8688

87-
- [Effective Go](http://golang.org/doc/effective_go.html) - The entire lnd
89+
- [Effective Go](http://golang.org/doc/effective_go.html) - The entire `lnd`
8890
project follows the guidelines in this document. For your code to be accepted,
8991
it must follow the guidelines therein.
9092
- [Original Satoshi Whitepaper](https://bitcoin.org/bitcoin.pdf) - This is the white paper that started it all. Having a solid
@@ -100,10 +102,10 @@ Note that the core design of the Lightning Network has shifted over time as
100102
concrete implementation and design has expanded our knowledge beyond the
101103
original white paper. Therefore, specific information outlined in the resources
102104
above may be a bit out of date. Many implementers are currently working on an
103-
initial [Version 1 Specification](https://medium.com/@lightningnetwork/lightning-network-meeting-on-interoperability-and-specifications-ea49e47696a4).
105+
initial [Lightning Network Specifications](https://github.com/lightningnetwork/lightning-rfc).
104106
Once the specification is finalized, it will be the most up-to-date
105107
comprehensive document explaining the Lightning Network. As a result, it will
106-
be recommened for newcomers to read first in order to get up to speed.
108+
be recommended for newcomers to read first in order to get up to speed.
107109

108110
<a name="DevelopmentPractices" />
109111

@@ -138,7 +140,7 @@ This approach has several benefits:
138140

139141
#### 4.2. Testing
140142

141-
One of the major design goals of all of lnd's packages and the daemon itself is
143+
One of the major design goals of all of `lnd`'s packages and the daemon itself is
142144
to aim for a high degree of test coverage. This is financial software so bugs
143145
and regressions in the core logic can cost people real money. For this reason
144146
every effort must be taken to ensure the code is as accurate and bug-free as
@@ -166,10 +168,14 @@ A quick summary of test practices follows:
166168
be accompanied by unit tests exercising the new or changed behavior.
167169
- Changes to behavior within the daemon's interaction with the P2P protocol,
168170
or RPC's will need to be accompanied by integration tests which use the
169-
[`networkHarness`framework](https://github.com/lightningnetwork/lnd/blob/master/networktest.go)
171+
[`networkHarness`framework](https://github.com/lightningnetwork/lnd/blob/master/lntest/harness.go)
170172
contained within `lnd`. For example integration tests, see
171173
[`lnd_test.go`](https://github.com/lightningnetwork/lnd/blob/master/lnd_test.go#L181).
172174

175+
Throughout the process of contributing to `lnd`, you'll likely also be
176+
extensively using the commands within our `Makefile`. As a result, we recommend
177+
[perusing the make file documentation](https://github.com/lightningnetwork/lnd/blob/master/docs/MAKEFILE.md).
178+
173179
<a name="CodeDocumentation" />
174180

175181
#### 4.3. Code Documentation and Commenting
@@ -277,7 +283,7 @@ Further paragraphs come after blank lines.
277283
Here are some of the reasons why wrapping your commit messages to 72 columns is
278284
a good thing.
279285
280-
- git log doesnt do any special wrapping of the commit messages. With
286+
- git log doesn't do any special wrapping of the commit messages. With
281287
the default pager of less -S, this means your paragraphs flow far off the edge
282288
of the screen, making them difficult to read. On an 80 column terminal, if we
283289
subtract 4 columns for the indent on the left and 4 more for symmetry on the
@@ -292,19 +298,39 @@ all short-[commit messages are to be prefixed according to the convention
292298
outlined in the Go project](https://golang.org/doc/contribute.html#change). All
293299
commits should begin with the subsystem or package primarily affected by the
294300
change. In the case of a widespread change, the packages are to be delimited by
295-
either a '+' or a ','. This prefix seems minor but can be extremly helpful in
301+
either a '+' or a ','. This prefix seems minor but can be extremely helpful in
296302
determining the scope of a commit at a glance, or when bug hunting to find a
297303
commit which introduced a bug or regression.
298304
305+
<a name="IdealGitCommitStructure" />
306+
307+
#### 4.5. Ideal Git Commit Structure
308+
309+
Within the project we prefer small, contained commits for a pull request over a
310+
single giant commit that touches several files/packages. Ideal commits build on
311+
their own, in order to facilitate easy usage of tools like `git bisect` to `git
312+
cherry-pick`. It's preferred that commits contain an isolated change in a
313+
single package. In this case, the commit header message should begin with the
314+
prefix of the modified package. For example, if a commit was made to modify the
315+
`lnwallet` package, it should start with `lnwallet: `.
316+
317+
In the case of changes that only build in tandem with changes made in other
318+
packages, it is permitted for a single commit to be made which contains several
319+
prefixes such as: `lnwallet+htlcswitch`. This prefix structure along with the
320+
requirement for atomic contained commits (when possible) make things like
321+
scanning the set of commits and debugging easier. In the case of a change that
322+
touches several packages, and can only compile with the change across several
323+
packages, a `multi: ` prefix should be used.
324+
299325
<a name="CodeSpacing" />
300326
301-
#### 4.5. Code Spacing
327+
#### 4.6. Code Spacing
302328
303-
Blocks of code within lnd should be segmented into logical stanzas of
329+
Blocks of code within `lnd` should be segmented into logical stanzas of
304330
operation. Such spacing makes the code easier to follow at a skim, and reduces
305331
unnecessary line noise. Coupled with the commenting scheme specified above,
306332
proper spacing allows readers to quickly scan code, extracting semantics quickly.
307-
Functions should _not_ just be layed out as a bare contiguous block of code.
333+
Functions should _not_ just be laid out as a bare contiguous block of code.
308334
309335
**WRONG**
310336
```go
@@ -348,15 +374,23 @@ Functions should _not_ just be layed out as a bare contiguous block of code.
348374
349375
<a name="Protobuf" />
350376
351-
#### 4.5.6. Protobuf Compilation
377+
#### 4.7. Protobuf Compilation
352378
353379
The `lnd` project uses `protobuf`, and its extension [`gRPC`](www.grpc.io) in
354380
several areas and as the primary RPC interface. In order to ensure uniformity
355381
of all protos checked, in we require that all contributors pin against the
356382
_exact same_ version of `protoc`. As of the writing of this article, the `lnd`
357-
project uses [v3.2.0](https://github.com/google/protobuf/releases/tag/v3.2.0)
383+
project uses [v3.4.0](https://github.com/google/protobuf/releases/tag/v3.4.0)
358384
of `protoc`.
359385
386+
The following commit hashes of related projects are also required in order to
387+
generate identical compiled protos and related files:
388+
* grpc-ecosystem/grpc-gateway: `f2862b476edcef83412c7af8687c9cd8e4097c0f`
389+
* golang/protobuf: `ab9f9a6dab164b7d1246e0e688b0ab7b94d8553e`
390+
391+
For detailed instructions on how to compile modifications to `lnd`'s `protobuf`
392+
definitions, check out the [lnrpc README](https://github.com/lightningnetwork/lnd/blob/master/lnrpc/README.md).
393+
360394
Additionally, in order to maintain a uniform display of the RPC responses
361395
rendered by `lncli`, all added or modified `protof` definitions, _must_ attach
362396
the proper `json_name` option for all fields. An example of such an option can
@@ -373,12 +407,40 @@ Notice how the `json_name` field option corresponds with the name of the field
373407
itself, and uses a `snake_case` style of name formatting. All added or modified
374408
`proto` fields should adhere to the format above.
375409
410+
<a name="ExtraGoFmtStyle" />
411+
412+
#### 4.8. Additional Style Constraints On Top of `gofmt`
413+
414+
Before a PR is submitted, the proposer should ensure that the file passes the
415+
set of linting scripts run by `make lint`. These include `gofmt`. In addition
416+
to `gofmt` we've opted to enforce the following style guidelines.
417+
418+
* ALL columns (on a best effort basis) should be wrapped to 80 line columns.
419+
Editors should be set to treat a tab as 4 spaces.
420+
* When wrapping a line that contains a function call as the unwrapped line
421+
exceeds the column limit, the close paren should be placed on its own
422+
line. Additionally, all arguments should begin in a new line after the
423+
open paren.
424+
425+
**WRONG**
426+
```go
427+
value, err := bar(a
428+
a, b, c)
429+
```
430+
431+
**RIGHT**
432+
```go
433+
value, err := bar(
434+
a, a, b, c,
435+
)
436+
```
437+
376438
<a name="CodeApproval" />
377439
378440
### 5. Code Approval Process
379441
380442
This section describes the code approval process that is used for code
381-
contributions. This is how to get your changes into lnd.
443+
contributions. This is how to get your changes into `lnd`.
382444
383445
<a name="CodeReview" />
384446
@@ -427,17 +489,27 @@ master. In certain cases the code reviewer(s) or interested committers may help
427489
you rework the code, but generally you will simply be given feedback for you to
428490
make the necessary changes.
429491
492+
During the process of responding to review comments, we prefer that changes be
493+
made with [fixup commits](https://robots.thoughtbot.com/autosquashing-git-commits).
494+
The reason for this is two fold: it makes it easier for the reviewer to see
495+
what changes have been made between versions (since Github doesn't easily show
496+
prior versions like Critique) and it makes it easier on the PR author as they
497+
can set it to auto squash the fix up commits on rebase.
498+
430499
This process will continue until the code is finally accepted.
431500
432501
<a name="CodeAcceptance" />
433502
434503
#### 5.3. Acceptance
435504
436-
Once your code is accepted, it will be integrated with the master branch.
437-
Typically it will be rebased and fast-forward merged to master as we prefer to
438-
keep a clean commit history over a tangled weave of merge commits. However,
439-
regardless of the specific merge method used, the code will be integrated with
440-
the master branch and the pull request will be closed.
505+
Once your code is accepted, it will be integrated with the master branch. After
506+
2+ (sometimes 1) LGTM's (approvals) are given on a PR, it's eligible to land in
507+
master. At this final phase, it may be necessary to rebase the PR in order to
508+
resolve any conflicts and also squash fix up commits. Ideally, the set of
509+
[commits by new contributors are PGP signed](https://git-scm.com/book/en/v2/Git-Tools-Signing-Your-Work),
510+
although this isn't a strong requirement (but we prefer it!). In order to keep
511+
these signatures intact, we prefer using merge commits. PR proposers can use
512+
`git rebase --signoff` to sign and rebase at the same time as a final step.
441513
442514
Rejoice as you will now be listed as a [contributor](https://github.com/lightningnetwork/lnd/graphs/contributors)!
443515
@@ -449,7 +521,7 @@ Rejoice as you will now be listed as a [contributor](https://github.com/lightnin
449521
450522
#### 6.1. Contribution Checklist
451523
452-
- [&nbsp;&nbsp;] All changes are Go version 1.5 compliant
524+
- [&nbsp;&nbsp;] All changes are Go version 1.11 compliant
453525
- [&nbsp;&nbsp;] The code being submitted is commented according to the
454526
[Code Documentation and Commenting](#CodeDocumentation) section
455527
- [&nbsp;&nbsp;] For new code: Code is accompanied by tests which exercise both
@@ -459,10 +531,13 @@ Rejoice as you will now be listed as a [contributor](https://github.com/lightnin
459531
- [&nbsp;&nbsp;] Any new logging statements use an appropriate subsystem and
460532
logging level
461533
- [&nbsp;&nbsp;] Code has been formatted with `go fmt`
462-
- [&nbsp;&nbsp;] Running `go test` does not fail any tests
534+
- [&nbsp;&nbsp;] For code and documentation: lines are wrapped at 80 characters
535+
(the tab character should be counted as 8 characters, not 4, as some IDEs do
536+
per default)
537+
- [&nbsp;&nbsp;] Running `make unit` and `make itest` do not fail any tests
463538
- [&nbsp;&nbsp;] Running `go vet` does not report any issues
464-
- [&nbsp;&nbsp;] Running [golint](https://github.com/golang/lint) does not
465-
report any **new** issues that did not already exist
539+
- [&nbsp;&nbsp;] Running `make lint` does not report any **new** issues that
540+
did not already exist
466541
467542
<a name="Licensing" />
468543

0 commit comments

Comments
 (0)