Changeset View
Changeset View
Standalone View
Standalone View
doc/developer-notes.md
Show First 20 Lines • Show All 306 Lines • ▼ Show 20 Lines | |||||
Valgrind is a programming tool for memory debugging, memory leak detection, and | Valgrind is a programming tool for memory debugging, memory leak detection, and | ||||
profiling. The repo contains a Valgrind suppressions file | profiling. The repo contains a Valgrind suppressions file | ||||
([`valgrind.supp`](/contrib/valgrind.supp)) | ([`valgrind.supp`](/contrib/valgrind.supp)) | ||||
which includes known Valgrind warnings in our dependencies that cannot be fixed | which includes known Valgrind warnings in our dependencies that cannot be fixed | ||||
in-tree. Example use: | in-tree. Example use: | ||||
```shell | ```shell | ||||
$ valgrind --suppressions=contrib/valgrind.supp src/test/test_bitcoin | $ valgrind --suppressions=contrib/valgrind.supp src/test/test_ecash | ||||
$ valgrind --suppressions=contrib/valgrind.supp --leak-check=full \ | $ valgrind --suppressions=contrib/valgrind.supp --leak-check=full \ | ||||
--show-leak-kinds=all src/test/test_bitcoin --log_level=test_suite | --show-leak-kinds=all src/test/test_ecash --log_level=test_suite | ||||
$ valgrind -v --leak-check=full src/bitcoind -printtoconsole | $ valgrind -v --leak-check=full src/ecashd -printtoconsole | ||||
``` | ``` | ||||
### Compiling for test coverage | ### Compiling for test coverage | ||||
LCOV can be used to generate a test coverage report based upon some test targets | LCOV can be used to generate a test coverage report based upon some test targets | ||||
execution. Some packages are required to generate the coverage report: | execution. Some packages are required to generate the coverage report: | ||||
`c++filt`, `gcov`, `genhtml`, `lcov` and `python3`. | `c++filt`, `gcov`, `genhtml`, `lcov` and `python3`. | ||||
Show All 35 Lines | |||||
$ sudo sysctl -w kernel.perf_event_paranoid=-1 | $ sudo sysctl -w kernel.perf_event_paranoid=-1 | ||||
$ sudo sysctl -w kernel.kptr_restrict=0 | $ sudo sysctl -w kernel.kptr_restrict=0 | ||||
``` | ``` | ||||
Make sure you [understand the security | Make sure you [understand the security | ||||
trade-offs](https://lwn.net/Articles/420403/) of setting these kernel | trade-offs](https://lwn.net/Articles/420403/) of setting these kernel | ||||
parameters. | parameters. | ||||
To profile a running bitcoind process for 60 seconds, you could use an | To profile a running ecashd process for 60 seconds, you could use an | ||||
invocation of `perf record` like this: | invocation of `perf record` like this: | ||||
```sh | ```sh | ||||
$ perf record \ | $ perf record \ | ||||
-g --call-graph dwarf --per-thread -F 140 \ | -g --call-graph dwarf --per-thread -F 140 \ | ||||
-p `pgrep bitcoind` -- sleep 60 | -p `pgrep ecashd` -- sleep 60 | ||||
``` | ``` | ||||
You could then analyze the results by running | You could then analyze the results by running | ||||
```sh | ```sh | ||||
perf report --stdio | c++filt | less | perf report --stdio | c++filt | less | ||||
``` | ``` | ||||
▲ Show 20 Lines • Show All 118 Lines • ▼ Show 20 Lines | |||||
Re-architecting the core code so there are better-defined interfaces | Re-architecting the core code so there are better-defined interfaces | ||||
between the various components is a goal, with any necessary locking | between the various components is a goal, with any necessary locking | ||||
done by the components (e.g. see the self-contained `FillableSigningProvider` class | done by the components (e.g. see the self-contained `FillableSigningProvider` class | ||||
and its `cs_KeyStore` lock for example). | and its `cs_KeyStore` lock for example). | ||||
Threads | Threads | ||||
------- | ------- | ||||
- [Main thread (`bitcoind`)](https://www.bitcoinabc.org/doc/dev/bitcoind_8cpp.html#a0ddf1224851353fc92bfbff6f499fa97) | - [Main thread (`ecashd`)](https://www.bitcoinabc.org/doc/dev/bitcoind_8cpp.html#a0ddf1224851353fc92bfbff6f499fa97) | ||||
: Started from `main()` in `bitcoind.cpp`. Responsible for starting up and | : Started from `main()` in `ecashd.cpp`. Responsible for starting up and | ||||
shutting down the application. | shutting down the application. | ||||
- [ThreadImport (`b-loadblk`)](https://www.bitcoinabc.org/doc/dev/init_8cpp.html#ae9e290a0e829ec0198518de2eda579d1) | - [ThreadImport (`b-loadblk`)](https://www.bitcoinabc.org/doc/dev/init_8cpp.html#ae9e290a0e829ec0198518de2eda579d1) | ||||
: Loads blocks from `blk*.dat` files or `-loadblock=<file>` on startup. | : Loads blocks from `blk*.dat` files or `-loadblock=<file>` on startup. | ||||
- [ThreadScriptCheck (`b-scriptch.x`)](https://www.bitcoinabc.org/doc/dev/validation_8cpp.html#a925a33e7952a157922b0bbb8dab29a20) | - [ThreadScriptCheck (`b-scriptch.x`)](https://www.bitcoinabc.org/doc/dev/validation_8cpp.html#a925a33e7952a157922b0bbb8dab29a20) | ||||
: Parallel script validation threads for transactions in blocks. | : Parallel script validation threads for transactions in blocks. | ||||
▲ Show 20 Lines • Show All 476 Lines • ▼ Show 20 Lines | - Missing arguments and 'null' should be treated the same: as default values. If there is no | ||||
while the latter returns true if is missing, and false if it is null. | while the latter returns true if is missing, and false if it is null. | ||||
- *Rationale*: Avoids surprises when switching to name-based arguments. Missing name-based arguments | - *Rationale*: Avoids surprises when switching to name-based arguments. Missing name-based arguments | ||||
are passed as 'null'. | are passed as 'null'. | ||||
- Try not to overload methods on argument type. E.g. don't make `getblock(true)` and `getblock("hash")` | - Try not to overload methods on argument type. E.g. don't make `getblock(true)` and `getblock("hash")` | ||||
do different things. | do different things. | ||||
- *Rationale*: This is impossible to use with `bitcoin-cli`, and can be surprising to users. | - *Rationale*: This is impossible to use with `ecash-cli`, and can be surprising to users. | ||||
- *Exception*: Some RPC calls can take both an `int` and `bool`, most notably when a bool was switched | - *Exception*: Some RPC calls can take both an `int` and `bool`, most notably when a bool was switched | ||||
to a multi-value, or due to other historical reasons. **Always** have false map to 0 and | to a multi-value, or due to other historical reasons. **Always** have false map to 0 and | ||||
true to 1 in this case. | true to 1 in this case. | ||||
- Don't forget to fill in the argument names correctly in the RPC command table. | - Don't forget to fill in the argument names correctly in the RPC command table. | ||||
- *Rationale*: If not, the call can not be used with name-based arguments. | - *Rationale*: If not, the call can not be used with name-based arguments. | ||||
- Set okSafeMode in the RPC command table to a sensible value: safe mode is when the | - Set okSafeMode in the RPC command table to a sensible value: safe mode is when the | ||||
blockchain is regarded to be in a confused state, and the client deems it unsafe to | blockchain is regarded to be in a confused state, and the client deems it unsafe to | ||||
do anything irreversible such as send. Anything that just queries should be permitted. | do anything irreversible such as send. Anything that just queries should be permitted. | ||||
- *Rationale*: Troubleshooting a node in safe mode is difficult if half the | - *Rationale*: Troubleshooting a node in safe mode is difficult if half the | ||||
RPCs don't work. | RPCs don't work. | ||||
- Add every non-string RPC argument `(method, idx, name)` to the table `vRPCConvertParams` in `rpc/client.cpp`. | - Add every non-string RPC argument `(method, idx, name)` to the table `vRPCConvertParams` in `rpc/client.cpp`. | ||||
- *Rationale*: `bitcoin-cli` and the GUI debug console use this table to determine how to | - *Rationale*: `ecash-cli` and the GUI debug console use this table to determine how to | ||||
convert a plaintext command line to JSON. If the types don't match, the method can be unusable | convert a plaintext command line to JSON. If the types don't match, the method can be unusable | ||||
from there. | from there. | ||||
- A RPC method must either be a wallet method or a non-wallet method. Do not | - A RPC method must either be a wallet method or a non-wallet method. Do not | ||||
introduce new methods such as `signrawtransaction` that differ in behavior | introduce new methods such as `signrawtransaction` that differ in behavior | ||||
based on presence of a wallet. | based on presence of a wallet. | ||||
- *Rationale*: As well as complicating the implementation and interfering | - *Rationale*: As well as complicating the implementation and interfering | ||||
▲ Show 20 Lines • Show All 157 Lines • Show Last 20 Lines |