Skip to content

Commit 26b9b71

Browse files
Merge pull request #747 from lightninglabs/docs-lnd
Update lnd documentation
2 parents 5939608 + feb198c commit 26b9b71

File tree

3 files changed

+104
-8
lines changed

3 files changed

+104
-8
lines changed

docs/lnd/INSTALL.md

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -93,23 +93,24 @@ following build dependencies are required:
9393

9494
### Installing Go
9595

96-
`lnd` is written in Go, with a minimum version of 1.19. To install, run one of
97-
the following commands for your OS:
96+
`lnd` is written in Go, with a minimum version of `1.22.6` (or, in case this
97+
document gets out of date, whatever the Go version in the main `go.mod` file
98+
requires). To install, run one of the following commands for your OS:
9899

99100
<details>
100101
<summary>Linux (x86-64)</summary>
101102

102103
```
103104
wget https://dl.google.com/go/go1.22.6.linux-amd64.tar.gz
104-
sha256sum go1.22.5.linux-amd64.tar.gz | awk -F " " '{ print $1 }'
105+
sha256sum go1.22.6.linux-amd64.tar.gz | awk -F " " '{ print $1 }'
105106
```
106107

107108
The final output of the command above should be
108109
`999805bed7d9039ec3da1a53bfbcafc13e367da52aa823cb60b68ba22d44c616`. If it
109110
isn't, then the target REPO HAS BEEN MODIFIED, and you shouldn't install
110111
this version of Go. If it matches, then proceed to install Go:
111112
```
112-
sudo rm -rf /usr/local/go && sudo tar -C /usr/local -xzf go1.22.5.linux-amd64.tar.gz
113+
sudo rm -rf /usr/local/go && sudo tar -C /usr/local -xzf go1.22.6.linux-amd64.tar.gz
113114
export PATH=$PATH:/usr/local/go/bin
114115
```
115116
</details>
@@ -118,16 +119,16 @@ the following commands for your OS:
118119
<summary>Linux (ARMv6)</summary>
119120

120121
```
121-
wget https://dl.google.com/go/go1.22.5.linux-armv6l.tar.gz
122-
sha256sum go1.22.5.linux-armv6l.tar.gz | awk -F " " '{ print $1 }'
122+
wget https://dl.google.com/go/go1.22.6.linux-armv6l.tar.gz
123+
sha256sum go1.22.6.linux-armv6l.tar.gz | awk -F " " '{ print $1 }'
123124
```
124125

125126
The final output of the command above should be
126127
`b566484fe89a54c525dd1a4cbfec903c1f6e8f0b7b3dbaf94c79bc9145391083`. If it
127128
isn't, then the target REPO HAS BEEN MODIFIED, and you shouldn't install
128129
this version of Go. If it matches, then proceed to install Go:
129130
```
130-
sudo rm -rf /usr/local/go && tar -C /usr/local -xzf go1.22.5.linux-armv6l.tar.gz
131+
sudo rm -rf /usr/local/go && tar -C /usr/local -xzf go1.22.6.linux-armv6l.tar.gz
131132
export PATH=$PATH:/usr/local/go/bin
132133
```
133134

docs/lnd/code_formatting_rules.md

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,95 @@ be used for calls to formatting functions like `fmt.Errorf`,
178178
But not for statements that are important for the flow or logic of the code,
179179
like `require.NoErrorf()`.
180180

181+
#### Exceptions and additional styling for structured logging
182+
183+
When making use of structured logging calls (there are any `btclog.Logger`
184+
methods ending in `S`), a few different rules and exceptions apply.
185+
186+
1) **Static messages:** Structured log calls take a `context.Context` as a first
187+
parameter and a _static_ string as the second parameter (the `msg` parameter).
188+
Formatted strings should ideally not be used for the construction of the `msg`
189+
parameter. Instead, key-value pairs (or `slog` attributes) should be used to
190+
provide additional variables to the log line.
191+
192+
**WRONG**
193+
```go
194+
log.DebugS(ctx, fmt.Sprintf("User %d just spent %.8f to open a channel", userID, 0.0154))
195+
```
196+
197+
**RIGHT**
198+
```go
199+
log.InfoS(ctx, "Channel open performed",
200+
slog.Int("user_id", userID),
201+
btclog.Fmt("amount", "%.8f", 0.00154))
202+
```
203+
204+
2) **Key-value attributes**: The third parameter in any structured log method is
205+
a variadic list of the `any` type but it is required that these are provided in
206+
key-value pairs such that an associated `slog.Attr` variable can be created for
207+
each key-value pair. The simplest way to specify this is to directly pass in the
208+
key-value pairs as raw literals as follows:
209+
210+
```go
211+
log.InfoS(ctx, "Channel open performed", "user_id", userID, "amount", 0.00154)
212+
```
213+
This does work, but it becomes easy to make a mistake and accidentally leave out
214+
a value for each key provided leading to a nonsensical log line. To avoid this,
215+
it is suggested to make use of the various `slog.Attr` helper functions as
216+
follows:
217+
218+
```go
219+
log.InfoS(ctx, "Channel open performed",
220+
slog.Int("user_id", userID),
221+
btclog.Fmt("amount", "%.8f", 0.00154))
222+
```
223+
224+
3) **Line wrapping**: Structured log lines are an exception to the 80-character
225+
line wrapping rule. This is so that the key-value pairs can be easily read and
226+
reasoned about. If it is the case that there is only a single key-value pair
227+
and the entire log line is still less than 80 characters, it is acceptable to
228+
have the key-value pair on the same line as the log message. However, if there
229+
are multiple key-value pairs, it is suggested to use the one line per key-value
230+
pair format. Due to this suggestion, it is acceptable for any single key-value
231+
pair line to exceed 80 characters for the sake of readability.
232+
233+
**WRONG**
234+
```go
235+
// Example 1.
236+
log.InfoS(ctx, "User connected",
237+
"user_id", userID)
238+
239+
// Example 2.
240+
log.InfoS(ctx, "Channel open performed", "user_id", userID,
241+
btclog.Fmt("amount", "%.8f", 0.00154), "channel_id", channelID)
242+
243+
// Example 3.
244+
log.InfoS(ctx, "Bytes received",
245+
"user_id", userID,
246+
btclog.Hex("peer_id", peerID.SerializeCompressed()),
247+
btclog.Hex("message", []bytes{
248+
0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
249+
})))
250+
```
251+
252+
**RIGHT**
253+
```go
254+
// Example 1.
255+
log.InfoS(ctx, "User connected", "user_id", userID)
256+
257+
// Example 2.
258+
log.InfoS(ctx, "Channel open performed",
259+
slog.Int("user_id", userID),
260+
btclog.Fmt("amount", "%.8f", 0.00154),
261+
slog.String("channel_id", channelID))
262+
263+
// Example 3.
264+
log.InfoS(ctx, "Bytes received",
265+
"user_id", userID,
266+
btclog.Hex("peer_id", peerID.SerializeCompressed()),
267+
btclog.Hex("message", []bytes{0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08})))
268+
```
269+
181270
### Wrapping long function definitions
182271

183272
If one is forced to wrap lines of function arguments that exceed the

docs/lnd/release-notes/release-notes-0.19.0.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,13 @@
163163
a log line. The options for this include "off" (default), "short" (source file
164164
name and line number) and "long" (full path to source file and line number).
165165
Finally, the new `--logging.console.style` option can be used under the `dev`
166-
build tag to add styling to console logging.
166+
build tag to add styling to console logging.
167+
168+
* [Start adding a commit hash fingerprint to log lines by
169+
default](https://github.com/lightningnetwork/lnd/pull/9314). This can be
170+
disabled with the new `--logging.no-commit-hash"` option. Note that this extra
171+
info will currently only appear in a few log lines, but more will be added in
172+
future as the structured logging change is propagated throughout LND.
167173

168174
* [Add max files and max file size](https://github.com/lightningnetwork/lnd/pull/9233)
169175
options to the `logging` config namespace under new `--logging.file.max-files`

0 commit comments

Comments
 (0)