]> Git Repo - VerusCoin.git/blame - doc/developer-notes.md
Remove QT translation support files
[VerusCoin.git] / doc / developer-notes.md
CommitLineData
2341e9b5 1Coding
2====================
3
2887bffc
PW
4Various coding styles have been used during the history of the codebase,
5and the result is not very consistent. However, we're now trying to converge to
6a single style, so please use it in new code. Old code will be converted
7gradually.
8- Basic rules specified in src/.clang-format. Use a recent clang-format-3.5 to format automatically.
9 - Braces on new lines for namespaces, classes, functions, methods.
10 - Braces on the same line for everything else.
11 - 4 space indentation (no tabs) for every block except namespaces.
12 - No indentation for public/protected/private or for namespaces.
13 - No extra spaces inside parenthesis; don't do ( this )
14 - No space after function names; one space after if, for and while.
86fe1b86 15
2887bffc
PW
16Block style example:
17```c++
18namespace foo
19{
20class Class
21{
22 bool Function(char* psz, int n)
23 {
24 // Comment summarising what this section of code does
25 for (int i = 0; i < n; i++) {
26 // When something fails, return early
27 if (!Something())
28 return false;
29 ...
30 }
2341e9b5 31
2887bffc
PW
32 // Success return is usually at the end
33 return true;
34 }
35}
36}
86fe1b86 37```
2341e9b5 38
8414cb04
WL
39Doxygen comments
40-----------------
41
42To facilitate the generation of documentation, use doxygen-compatible comment blocks for functions, methods and fields.
43
44For example, to describe a function use:
45```c++
46/**
47 * ... text ...
48 * @param[in] arg1 A description
49 * @param[in] arg2 Another argument description
50 * @pre Precondition for function...
51 */
52bool function(int arg1, const char *arg2)
53```
54A complete list of `@xxx` commands can be found at http://www.stack.nl/~dimitri/doxygen/manual/commands.html.
55As Doxygen recognizes the comments by the delimiters (`/**` and `*/` in this case), you don't
7e6d23b1 56*need* to provide any commands for a comment to be valid; just a description text is fine.
8414cb04
WL
57
58To describe a class use the same construct above the class definition:
59```c++
4fbfebea 60/**
8414cb04
WL
61 * Alerts are for notifying old versions if they become too obsolete and
62 * need to upgrade. The message is displayed in the status bar.
63 * @see GetWarnings()
64 */
65class CAlert
66{
67```
68
69To describe a member or variable use:
70```c++
71int var; //!< Detailed description after the member
72```
73
74Also OK:
75```c++
76///
77/// ... text ...
78///
79bool function2(int arg1, const char *arg2)
80```
81
82Not OK (used plenty in the current source, but not picked up):
83```c++
84//
85// ... text ...
86//
87```
88
89A full list of comment syntaxes picked up by doxygen can be found at http://www.stack.nl/~dimitri/doxygen/manual/docblocks.html,
90but if possible use one of the above styles.
91
3bf5f528
MF
92Development tips and tricks
93---------------------------
94
95**compiling for debugging**
96
97Run configure with the --enable-debug option, then make. Or run configure with
98CXXFLAGS="-g -ggdb -O0" or whatever debug flags you need.
99
100**debug.log**
101
102If the code is behaving strangely, take a look in the debug.log file in the data directory;
103error and debugging messages are written there.
104
73280baa 105The -debug=... command-line option controls debugging; running with just -debug or -debug=1 will turn
3bf5f528
MF
106on all categories (and give you a very large debug.log file).
107
3bf5f528
MF
108**testnet and regtest modes**
109
0fa4dcc0 110Run with the -testnet option to run with "play zcash" on the test network, if you
3bf5f528
MF
111are testing multi-machine code that needs to operate across the internet.
112
113If you are testing something that can run on one machine, run with the -regtest option.
114In regression test mode, blocks can be created on-demand; see qa/rpc-tests/ for tests
115that run in -regtest mode.
116
117**DEBUG_LOCKORDER**
118
0fa4dcc0 119Zcash is a multithreaded application, and deadlocks or other multithreading bugs
3bf5f528
MF
120can be very difficult to track down. Compiling with -DDEBUG_LOCKORDER (configure
121CXXFLAGS="-DDEBUG_LOCKORDER -g") inserts run-time checks to keep track of which locks
122are held, and adds warnings to the debug.log file if inconsistencies are detected.
123
2341e9b5 124Locking/mutex usage notes
8414cb04 125-------------------------
2341e9b5 126
127The code is multi-threaded, and uses mutexes and the
128LOCK/TRY_LOCK macros to protect data structures.
129
130Deadlocks due to inconsistent lock ordering (thread 1 locks cs_main
131and then cs_wallet, while thread 2 locks them in the opposite order:
132result, deadlock as each waits for the other to release its lock) are
133a problem. Compile with -DDEBUG_LOCKORDER to get lock order
134inconsistencies reported in the debug.log file.
135
136Re-architecting the core code so there are better-defined interfaces
137between the various components is a goal, with any necessary locking
138done by the components (e.g. see the self-contained CKeyStore class
139and its cs_KeyStore lock for example).
140
2341e9b5 141Threads
8414cb04 142-------
2341e9b5 143
25ef6ace 144- ThreadScriptCheck : Verifies block scripts.
145
146- ThreadImport : Loads blocks from blk*.dat files or bootstrap.dat.
147
2341e9b5 148- StartNode : Starts other threads.
149
25ef6ace 150- ThreadDNSAddressSeed : Loads addresses of peers from the DNS.
151
152- ThreadMapPort : Universal plug-and-play startup/shutdown
2341e9b5 153
3985a40d 154- ThreadSocketHandler : Sends/Receives data from peers on port 8233.
25ef6ace 155
156- ThreadOpenAddedConnections : Opens network connections to added nodes.
157
2341e9b5 158- ThreadOpenConnections : Initiates new connections to peers.
159
25ef6ace 160- ThreadMessageHandler : Higher-level message handling (sending and receiving).
161
162- DumpAddresses : Dumps IP addresses of nodes to peers.dat.
2341e9b5 163
164- ThreadFlushWalletDB : Close the wallet.dat file if it hasn't been used in 500ms.
25ef6ace 165
3985a40d 166- ThreadRPCServer : Remote procedure call handler, listens on port 8232 for connections and services them.
25ef6ace 167
0fa4dcc0 168- ZcashMiner : Generates zcash (if wallet is enabled).
25ef6ace 169
170- Shutdown : Does an orderly shutdown of everything.
3bf5f528
MF
171
172Pull Request Terminology
173------------------------
174
7e6d23b1 175Concept ACK - Agree with the idea and overall direction, but have neither reviewed nor tested the code changes.
3bf5f528
MF
176
177utACK (untested ACK) - Reviewed and agree with the code changes but haven't actually tested them.
178
179Tested ACK - Reviewed the code changes and have verified the functionality or bug fix.
180
181ACK - A loose ACK can be confusing. It's best to avoid them unless it's a documentation/comment only change in which case there is nothing to test/verify; therefore the tested/untested distinction is not there.
182
7e6d23b1 183NACK - Disagree with the code changes/concept. Should be accompanied by an explanation.
This page took 0.144595 seconds and 4 git commands to generate.