Skip to content

Commit 33c103e

Browse files
committed
Merge #17539: doc: Update and improve Developer Notes
794fe91 doc: Update and improve Developer Notes (Hennadii Stepanov) Pull request description: This PR: - removes outdated things, e.g., global pointer `pwalletMain` etc - adds "Sanitizers" to the TOC - makes filenames, `peer.dat` and `debug.log`, monospaced - specifies that _compile-time_ constant names are all uppercase - rewords using `explicit` with constructors ACKs for top commit: jamesob: lazy ACK bitcoin/bitcoin@794fe91 practicalswift: ACK 794fe91 -- nice improvements! Tree-SHA512: 2c5f035b1627f5fac8dc2453199d9e46bd101f86771de567cd95698de3c61cc459444ec1a68710e1d280195e1e40b42d9f40906297d12f12bf37749eca58297d
2 parents 0b79caf + 794fe91 commit 33c103e

File tree

1 file changed

+16
-24
lines changed

1 file changed

+16
-24
lines changed

doc/developer-notes.md

Lines changed: 16 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,13 @@ Developer Notes
1212
- [Development tips and tricks](#development-tips-and-tricks)
1313
- [Compiling for debugging](#compiling-for-debugging)
1414
- [Compiling for gprof profiling](#compiling-for-gprof-profiling)
15-
- [debug.log](#debuglog)
15+
- [`debug.log`](#debuglog)
1616
- [Testnet and Regtest modes](#testnet-and-regtest-modes)
1717
- [DEBUG_LOCKORDER](#debug_lockorder)
1818
- [Valgrind suppressions file](#valgrind-suppressions-file)
1919
- [Compiling for test coverage](#compiling-for-test-coverage)
2020
- [Performance profiling with perf](#performance-profiling-with-perf)
21+
- [Sanitizers](#sanitizers)
2122
- [Locking/mutex usage notes](#lockingmutex-usage-notes)
2223
- [Threads](#threads)
2324
- [Ignoring IDE/editor files](#ignoring-ideeditor-files)
@@ -63,7 +64,7 @@ tool to clean up patches automatically before submission.
6364
- Braces on the same line for everything else.
6465
- 4 space indentation (no tabs) for every block except namespaces.
6566
- No indentation for `public`/`protected`/`private` or for `namespace`.
66-
- No extra spaces inside parenthesis; don't do ( this ).
67+
- No extra spaces inside parenthesis; don't do `( this )`.
6768
- No space after function names; one space after `if`, `for` and `while`.
6869
- If an `if` only has a single-statement `then`-clause, it can appear
6970
on the same line as the `if`, without braces. In every other case,
@@ -77,7 +78,7 @@ code.
7778
separate words (snake_case).
7879
- Class member variables have a `m_` prefix.
7980
- Global variables have a `g_` prefix.
80-
- Constant names are all uppercase, and use `_` to separate words.
81+
- Compile-time constant names are all uppercase, and use `_` to separate words.
8182
- Class names, function names, and method names are UpperCamelCase
8283
(PascalCase). Do not prefix class names with `C`.
8384
- Test suite naming convention: The Boost test suite in file
@@ -208,15 +209,15 @@ produce better debugging builds.
208209

209210
Run configure with the `--enable-gprof` option, then make.
210211

211-
### debug.log
212+
### `debug.log`
212213

213-
If the code is behaving strangely, take a look in the debug.log file in the data directory;
214+
If the code is behaving strangely, take a look in the `debug.log` file in the data directory;
214215
error and debugging messages are written there.
215216

216217
The `-debug=...` command-line option controls debugging; running with just `-debug` or `-debug=1` will turn
217-
on all categories (and give you a very large debug.log file).
218+
on all categories (and give you a very large `debug.log` file).
218219

219-
The Qt code routes `qDebug()` output to debug.log under category "qt": run with `-debug=qt`
220+
The Qt code routes `qDebug()` output to `debug.log` under category "qt": run with `-debug=qt`
220221
to see it.
221222

222223
### Testnet and Regtest modes
@@ -234,7 +235,7 @@ Bitcoin Core is a multi-threaded application, and deadlocks or other
234235
multi-threading bugs can be very difficult to track down. The `--enable-debug`
235236
configure option adds `-DDEBUG_LOCKORDER` to the compiler flags. This inserts
236237
run-time checks to keep track of which locks are held and adds warnings to the
237-
debug.log file if inconsistencies are detected.
238+
`debug.log` file if inconsistencies are detected.
238239

239240
### Valgrind suppressions file
240241

@@ -276,8 +277,7 @@ the functional test framework. Perf can observe a running process and sample
276277
(at some frequency) where its execution is.
277278

278279
Perf installation is contingent on which kernel version you're running; see
279-
[this StackExchange
280-
thread](https://askubuntu.com/questions/50145/how-to-install-perf-monitoring-tool)
280+
[this thread](https://askubuntu.com/questions/50145/how-to-install-perf-monitoring-tool)
281281
for specific instructions.
282282

283283
Certain kernel parameters may need to be set for perf to be able to inspect the
@@ -312,7 +312,7 @@ or using a graphical tool like [Hotspot](https://github.com/KDAB/hotspot).
312312
See the functional test documentation for how to invoke perf within tests.
313313

314314

315-
**Sanitizers**
315+
### Sanitizers
316316

317317
Bitcoin Core can be compiled with various "sanitizers" enabled, which add
318318
instrumentation for issues regarding things like memory safety, thread race
@@ -373,7 +373,7 @@ Deadlocks due to inconsistent lock ordering (thread 1 locks `cs_main` and then
373373
`cs_wallet`, while thread 2 locks them in the opposite order: result, deadlock
374374
as each waits for the other to release its lock) are a problem. Compile with
375375
`-DDEBUG_LOCKORDER` (or use `--enable-debug`) to get lock order inconsistencies
376-
reported in the debug.log file.
376+
reported in the `debug.log` file.
377377

378378
Re-architecting the core code so there are better-defined interfaces
379379
between the various components is a goal, with any necessary locking
@@ -387,8 +387,6 @@ Threads
387387

388388
- ThreadImport : Loads blocks from `blk*.dat` files or `-loadblock=<file>`.
389389

390-
- StartNode : Starts other threads.
391-
392390
- ThreadDNSAddressSeed : Loads addresses of peers from the DNS.
393391

394392
- ThreadMapPort : Universal plug-and-play startup/shutdown.
@@ -401,7 +399,7 @@ Threads
401399

402400
- ThreadMessageHandler : Higher-level message handling (sending and receiving).
403401

404-
- DumpAddresses : Dumps IP addresses of nodes to peers.dat.
402+
- DumpAddresses : Dumps IP addresses of nodes to `peers.dat`.
405403

406404
- ThreadRPCServer : Remote procedure call handler, listens on port 8332 for connections and services them.
407405

@@ -467,11 +465,6 @@ Wallet
467465

468466
- Make sure that no crashes happen with run-time option `-disablewallet`.
469467

470-
- *Rationale*: In RPC code that conditionally uses the wallet (such as
471-
`validateaddress`), it is easy to forget that global pointer `pwalletMain`
472-
can be nullptr. See `test/functional/disablewallet.py` for functional tests
473-
exercising the API with `-disablewallet`.
474-
475468
- Include `db_cxx.h` (BerkeleyDB header) only when `ENABLE_WALLET` is set.
476469

477470
- *Rationale*: Otherwise compilation of the disable-wallet build will fail in environments without BerkeleyDB.
@@ -546,11 +539,10 @@ class A
546539
}
547540
```
548541
549-
- By default, declare single-argument constructors `explicit`.
542+
- By default, declare constructors `explicit`.
550543
551-
- *Rationale*: This is a precaution to avoid unintended conversions that might
552-
arise when single-argument constructors are used as implicit conversion
553-
functions.
544+
- *Rationale*: This is a precaution to avoid unintended
545+
[conversions](https://en.cppreference.com/w/cpp/language/converting_constructor).
554546
555547
- Use explicitly signed or unsigned `char`s, or even better `uint8_t` and
556548
`int8_t`. Do not use bare `char` unless it is to pass to a third-party API.

0 commit comments

Comments
 (0)