4 Various coding styles have been used during the history of the codebase,
5 and the result is not very consistent. However, we're now trying to converge to
6 a single style, so please use it in new code. Old code will be converted
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.
22 bool Function(char* psz, int n)
24 // Comment summarising what this section of code does
25 for (int i = 0; i < n; i++) {
26 // When something fails, return early
32 // Success return is usually at the end
42 To facilitate the generation of documentation, use doxygen-compatible comment blocks for functions, methods and fields.
44 For example, to describe a function use:
48 * @param[in] arg1 A description
49 * @param[in] arg2 Another argument description
50 * @pre Precondition for function...
52 bool function(int arg1, const char *arg2)
54 A complete list of `@xxx` commands can be found at http://www.stack.nl/~dimitri/doxygen/manual/commands.html.
55 As Doxygen recognizes the comments by the delimiters (`/**` and `*/` in this case), you don't
56 *need* to provide any commands for a comment to be valid, just a description text is fine.
58 To describe a class use the same construct above the class definition:
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.
69 To describe a member or variable use:
71 int var; //!< Detailed description after the member
79 bool function2(int arg1, const char *arg2)
82 Not OK (used plenty in the current source, but not picked up):
89 A full list of comment syntaxes picked up by doxygen can be found at http://www.stack.nl/~dimitri/doxygen/manual/docblocks.html,
90 but if possible use one of the above styles.
92 Locking/mutex usage notes
93 -------------------------
95 The code is multi-threaded, and uses mutexes and the
96 LOCK/TRY_LOCK macros to protect data structures.
98 Deadlocks due to inconsistent lock ordering (thread 1 locks cs_main
99 and then cs_wallet, while thread 2 locks them in the opposite order:
100 result, deadlock as each waits for the other to release its lock) are
101 a problem. Compile with -DDEBUG_LOCKORDER to get lock order
102 inconsistencies reported in the debug.log file.
104 Re-architecting the core code so there are better-defined interfaces
105 between the various components is a goal, with any necessary locking
106 done by the components (e.g. see the self-contained CKeyStore class
107 and its cs_KeyStore lock for example).
112 - ThreadScriptCheck : Verifies block scripts.
114 - ThreadImport : Loads blocks from blk*.dat files or bootstrap.dat.
116 - StartNode : Starts other threads.
118 - ThreadDNSAddressSeed : Loads addresses of peers from the DNS.
120 - ThreadMapPort : Universal plug-and-play startup/shutdown
122 - ThreadSocketHandler : Sends/Receives data from peers on port 8333.
124 - ThreadOpenAddedConnections : Opens network connections to added nodes.
126 - ThreadOpenConnections : Initiates new connections to peers.
128 - ThreadMessageHandler : Higher-level message handling (sending and receiving).
130 - DumpAddresses : Dumps IP addresses of nodes to peers.dat.
132 - ThreadFlushWalletDB : Close the wallet.dat file if it hasn't been used in 500ms.
134 - ThreadRPCServer : Remote procedure call handler, listens on port 8332 for connections and services them.
136 - BitcoinMiner : Generates bitcoins (if wallet is enabled).
138 - Shutdown : Does an orderly shutdown of everything.