Compare commits
24
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
6deec5f91a | ||
|
|
368a7389f4 | ||
|
|
7c3ef9b635 | ||
|
|
6fa9ee58e3 | ||
|
|
b71107c2b3 | ||
|
|
93daca0614 | ||
|
|
e381336281 | ||
|
|
30c65694b9 | ||
|
|
84542d98d1 | ||
|
|
b9a1b60555 | ||
|
|
aed3b9b148 | ||
|
|
48d51418ef | ||
|
|
50facca935 | ||
|
|
e90d7f54ce | ||
|
|
2587130e45 | ||
|
|
f4be61d90a | ||
|
|
047abede75 | ||
|
|
4a1bf7bb51 | ||
|
|
a407c10b02 | ||
|
|
995b5a6666 | ||
|
|
4badde8595 | ||
|
|
6cce052bf7 | ||
|
|
df4a86a0df | ||
|
|
4a2738ddf1 |
No files matched your search
@@ -120,3 +120,5 @@ share/BitcoindComparisonTool.jar
|
||||
/doc/doxygen/
|
||||
|
||||
libbitcoinconsensus.pc
|
||||
|
||||
cmake-build-*/
|
||||
+2
-2
@@ -29,8 +29,8 @@ before_install:
|
||||
|
||||
install: true
|
||||
script:
|
||||
- if [[ "${TARGET}" == "osx" ]]; then ./reproducible_build.sh -t -o -c; fi
|
||||
- if [[ "${TARGET}" == "linux" ]]; then ./reproducible_build.sh -t -o -c; fi
|
||||
- if [[ "${TARGET}" == "osx" ]]; then ./reproducible_build.sh -t -o -c -f; fi
|
||||
- if [[ "${TARGET}" == "linux" ]]; then ./reproducible_build.sh -t -o -c -f; fi
|
||||
- if [[ "${TARGET}" == "windows" ]]; then ./packaging/build_windows.sh; fi
|
||||
- if [[ "${TARGET}" == "osx" ]]; then zip -j "lbrycrd-${TARGET}.zip" src/lbrycrdd src/lbrycrd-cli src/lbrycrd-tx; fi
|
||||
- if [[ "${TARGET}" == "linux" ]]; then zip -j "lbrycrd-${TARGET}.zip" src/lbrycrdd src/lbrycrd-cli src/lbrycrd-tx; fi
|
||||
|
||||
@@ -0,0 +1,56 @@
|
||||
cmake_minimum_required(VERSION 3.7)
|
||||
project(lbrycrd_clion) # not expecting a full compile -- just something that allows clion syntax checking
|
||||
|
||||
set (CMAKE_CXX_STANDARD 98) # 03 is not supported by cmake, but this will soon be 11 (after upstream bitcoin merge)
|
||||
# I thought that setting the standard would disable the clang-tidy c++11 tips; nope.
|
||||
|
||||
set(BOOST_ROOT "build/boost" CACHE PATH "Boost library path")
|
||||
set(Boost_NO_SYSTEM_PATHS on CACHE BOOL "Do not search system for Boost")
|
||||
find_package(Boost REQUIRED COMPONENTS filesystem program_options thread chrono) # locale coming shortly
|
||||
|
||||
file(GLOB sources
|
||||
src/*.h src/*.cpp
|
||||
src/wallet/*.h src/wallet/*.cpp
|
||||
src/support/*.h src/support/*.cpp src/support/allocators/*.h
|
||||
src/script/*.h src/script/*.cpp
|
||||
src/rpc/*.h src/rpc/*.cpp
|
||||
src/primitives/*.h src/primitives/*.cpp
|
||||
src/policy/*.h src/policy/*.cpp
|
||||
src/crypto/*.h src/crypto/*.cpp
|
||||
src/consensus/*.h src/consensus/*.cpp
|
||||
src/compat/*.h src/compat/*.cpp
|
||||
)
|
||||
list(FILTER sources EXCLUDE REGEX "src/bitcoin*.cpp$")
|
||||
|
||||
include_directories(${Boost_INCLUDE_DIRS}
|
||||
build/bdb/include
|
||||
build/libevent/include
|
||||
build/openssl/include
|
||||
src/support/allocators
|
||||
src/support
|
||||
src/rpc
|
||||
src/policy
|
||||
src/wallet src/script
|
||||
src/leveldb/helpers/memenv
|
||||
src/leveldb/include
|
||||
src/config
|
||||
src/crypto
|
||||
src/compat
|
||||
src/obj
|
||||
src/univalue/include
|
||||
src/secp256k1/include
|
||||
src/
|
||||
)
|
||||
|
||||
add_compile_definitions(HAVE_CONFIG_H)
|
||||
|
||||
add_executable(lbrycrd-cli src/bitcoin-cli.cpp ${sources})
|
||||
add_executable(lbrycrd-tx src/bitcoin-tx.cpp ${sources})
|
||||
add_executable(lbrycrdd src/bitcoind.cpp ${sources})
|
||||
|
||||
file(GLOB tests src/test/*.cpp)
|
||||
foreach(test ${tests})
|
||||
get_filename_component(filename ${test} NAME_WE)
|
||||
add_executable(${filename} ${test} ${sources})
|
||||
target_include_directories(${filename} PRIVATE src/test)
|
||||
endforeach(test)
|
||||
@@ -22,6 +22,29 @@ Run `./lbrycrd-cli getinfo` to check for some basic informations about your LBRY
|
||||
|
||||
Run `./lbrycrd-cli help` to get a list of all commands that you can run. To get help on specific commands run `./lbrycrd-cli [command_name] help`
|
||||
|
||||
### Data directory
|
||||
|
||||
Lbrycrdd will use the below default data directories
|
||||
|
||||
Windows < Vista: C:\Documents and Settings\Username\Application Data\lbrycrd
|
||||
|
||||
Windows >= Vista: C:\Users\Username\AppData\Roaming\lbrycrd
|
||||
|
||||
Mac: ~/Library/Application Support/lbrycrd
|
||||
|
||||
Unix: ~/.lbrycrd
|
||||
|
||||
The data directory contains various things such as your default wallet (wallet.dat), debug logs (debug.log), and blockchain data. You can optionally
|
||||
create a configuration file lbrycrd.conf in the default data directory which will be used by default when running lbrycrdd.
|
||||
For a list of configuration parameters run `./lbrycrdd --help`. Below is a sample lbrycrd.conf to enable JSON RPC server on lbrycrdd.
|
||||
|
||||
```rpcuser=lbry
|
||||
rpcpassword=xyz123456790
|
||||
daemon=1
|
||||
server=1
|
||||
txindex=1
|
||||
```
|
||||
|
||||
## Running from Source
|
||||
|
||||
Run `./reproducible_build.sh -c -t`. This will build the binaries and put them into the `./src` directory.
|
||||
@@ -32,6 +55,13 @@ If you encounter any errors, please check `doc/build-*.md` for further instructi
|
||||
|
||||
Contributions to this project are welcome, encouraged, and compensated. For more details, see [lbry.io/faq/contributing](https://lbry.io/faq/contributing)
|
||||
|
||||
The codebase is in C++03, C++11 is currently not supported but we will be migrating to it in the near future. Recommended GCC version is 4.8 or greater.
|
||||
We follow the same coding guidelines as documented by Bitcoin Core, see [here](/doc/developer-notes.md). To run an automated code formatting check, try:
|
||||
`git diff -U0 master -- '*.h' '*.cpp' | ./contrib/devtools/clang-format-diff.py -p1`. This will check any commits not on master for proper code formatting.
|
||||
We try to avoid altering parts of the code that is inherited from Bitcoin Core unless absolutely necessary. This will make it easier to merge changes from
|
||||
Bitcoin Core. If commits are expected not to be merged upstream (i.e. we broke up a commit from Bitcoin Core in order to use a single feature in it), the commit
|
||||
message must contain the string "NOT FOR UPSTREAM MERGE".
|
||||
|
||||
The `master` branch is regularly built and tested, but is not guaranteed to be
|
||||
completely stable. [Releases](https://github.com/lbryio/lbrycrd/releases) are created
|
||||
regularly to indicate new official, stable release versions.
|
||||
@@ -39,9 +69,7 @@ regularly to indicate new official, stable release versions.
|
||||
Testing and code review is the bottleneck for development; we get more pull
|
||||
requests than we can review and test on short notice. Please be patient and help out by testing
|
||||
other people's pull requests, and remember this is a security-critical project where any mistake might cost people
|
||||
lots of money.
|
||||
|
||||
Developers are strongly encouraged to write [unit tests](/doc/unit-tests.md) for new code, and to
|
||||
lots of money. Developers are strongly encouraged to write [unit tests](/doc/unit-tests.md) for new code, and to
|
||||
submit new unit tests for old code. Unit tests can be compiled and run
|
||||
(assuming they weren't disabled in configure) with: `make check`
|
||||
|
||||
|
||||
@@ -0,0 +1,65 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
import json
|
||||
import math
|
||||
import subprocess as sp
|
||||
import sys
|
||||
|
||||
|
||||
def main():
|
||||
if len(sys.argv) < 2: # pass in the CLI tool so that we don't have to replicate the cookie handling
|
||||
print('Missing required argument: <path to CLI tool> [CLI tool args...]', file=sys.stderr)
|
||||
sys.exit(1)
|
||||
|
||||
cli_tool = sys.argv[1:]
|
||||
if '-regtest' not in cli_tool:
|
||||
cli_tool.append('-regtest')
|
||||
|
||||
result = sp.run(cli_tool + ['getblockchaininfo'], stdout=sp.PIPE, universal_newlines=True)
|
||||
info = json.loads(result.stdout)
|
||||
if not info or info['chain'] != 'lbrycrdreg':
|
||||
print('Unable to query block chain info; are you missing the RPC authentication parameters?', file=sys.stderr)
|
||||
sys.exit(2)
|
||||
|
||||
claimsintrie = json.load(sys.stdin)
|
||||
i = 0
|
||||
total_i = len(claimsintrie)
|
||||
print('Importing ' + str(total_i) + ' names. Progress:')
|
||||
for node in claimsintrie:
|
||||
if 'name' in node and 'claims' in node:
|
||||
prev_amount = sys.float_info.max
|
||||
for claim in node['claims']:
|
||||
amount = claim['amount'] if claim['amount'] < prev_amount else prev_amount / 2.0
|
||||
if amount <= 0.0:
|
||||
amount = 0.0000001
|
||||
prev_amount = amount
|
||||
|
||||
# ensure that we have enough LBC to cover that amount:
|
||||
result = sp.run(cli_tool + ['getbalance'], stdout=sp.PIPE, universal_newlines=True)
|
||||
balance = float(result.stdout)
|
||||
while balance < amount + 10.0: # assuming no fees greater than 10
|
||||
needed_blocks = math.ceil(amount + 100.0 - balance)
|
||||
sp.run(cli_tool + ['generate', str(needed_blocks)], stdout=sp.PIPE, universal_newlines=True)
|
||||
result = sp.run(cli_tool + ['getbalance'], stdout=sp.PIPE, universal_newlines=True)
|
||||
balance = float(result.stdout)
|
||||
|
||||
# insert the claim:
|
||||
name = node['name'].replace('\x00', '') # not dealing with encodings today
|
||||
value = claim['value'].replace('\x00', '')
|
||||
result = sp.run(cli_tool + ['claimname', name, value, "{:17.8f}".format(amount)],
|
||||
stdout=sp.PIPE, universal_newlines=True)
|
||||
txid = result.stdout
|
||||
if not txid or 'error' in txid:
|
||||
print('Failed to create claim named ' + node['name'] +
|
||||
'. Message: ' + txid + ', Amount: ' + str(amount), file=sys.stderr)
|
||||
sys.exit(3)
|
||||
i += 1
|
||||
workdone = i / total_i
|
||||
print('\r[{0:20s}] {1:.1f}%, {2}'.format('#' * int(workdone * 20), workdone * 100, i), end='', flush=True)
|
||||
|
||||
sp.run(cli_tool + ['generate', '20'], stdout=sp.PIPE, universal_newlines=True) # far enough for activation
|
||||
print()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
+62
@@ -0,0 +1,62 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
import datetime
|
||||
import json
|
||||
import math
|
||||
import subprocess as sp
|
||||
import sys
|
||||
|
||||
|
||||
def main():
|
||||
if len(sys.argv) < 2: # pass in the CLI tool so that we don't have to replicate the cookie handling
|
||||
print('Missing required argument: <path to CLI tool> [CLI tool args...]', file=sys.stderr)
|
||||
sys.exit(1)
|
||||
|
||||
cli_tool = sys.argv[1:]
|
||||
if '-regtest' not in cli_tool:
|
||||
cli_tool.append('-regtest')
|
||||
|
||||
result = sp.run(cli_tool + ['getblockchaininfo'], stdout=sp.PIPE, universal_newlines=True)
|
||||
info = json.loads(result.stdout)
|
||||
if not info or info['chain'] != 'lbrycrdreg':
|
||||
print('Unable to query block chain info; are you missing the RPC authentication parameters?', file=sys.stderr)
|
||||
sys.exit(2)
|
||||
|
||||
names = sys.stdin.readlines()
|
||||
i = 0
|
||||
total_i = len(names)
|
||||
print('Importing ' + str(total_i) + ' names. Progress:')
|
||||
# make sure we have neough LBC to start:
|
||||
amount = 1 / 400
|
||||
for name in names:
|
||||
|
||||
# as noted below, we roll the block forward for every 100 names
|
||||
if i % 100 == 0: # before adding any names ensure that we have enough mula to roll the block forward after
|
||||
result = sp.run(cli_tool + ['getbalance'], stdout=sp.PIPE, universal_newlines=True)
|
||||
balance = float(result.stdout)
|
||||
while balance < amount * 100.0 + 10.0: # assuming no fees greater than 10
|
||||
needed_blocks = math.ceil(amount * 100.0 + 10.0 - balance)
|
||||
sp.run(cli_tool + ['generate', str(needed_blocks)], stdout=sp.PIPE, universal_newlines=True)
|
||||
result = sp.run(cli_tool + ['getbalance'], stdout=sp.PIPE, universal_newlines=True)
|
||||
balance = float(result.stdout)
|
||||
|
||||
result = sp.run(cli_tool + ['claimname', name, str(datetime.datetime.utcnow().isoformat()),
|
||||
"{:17.8f}".format(amount)], stdout=sp.PIPE, universal_newlines=True)
|
||||
txid = result.stdout
|
||||
if not txid or 'error' in txid:
|
||||
print('Failed to create claim named ' + name +
|
||||
'. Message: ' + txid + ', Amount: ' + str(amount), file=sys.stderr)
|
||||
sys.exit(3)
|
||||
|
||||
i += 1
|
||||
if i % 100 == 0 or i == total_i: # time to flush
|
||||
sp.run(cli_tool + ['generate', '1'], stdout=sp.PIPE, universal_newlines=True)
|
||||
|
||||
workdone = i / total_i
|
||||
print('\r[{0:20s}] {1:.1f}%, {2}'.format('#' * int(workdone * 20), workdone * 100, i), end='', flush=True)
|
||||
|
||||
print()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
@@ -26,7 +26,7 @@ if ! $VALID; then
|
||||
exit 1
|
||||
fi
|
||||
if $VALID && $REVSIG; then
|
||||
echo "$INPUT" | gpg --trust-model always "$@" | grep "\[GNUPG:\] \(NEWSIG\|SIG_ID\|VALIDSIG\)" 2>/dev/null
|
||||
echo "$INPUT" | gpg --trust-model always "$@" | grep "^\[GNUPG:\] \(NEWSIG\|SIG_ID\|VALIDSIG\)" 2>/dev/null
|
||||
echo "$GOODREVSIG"
|
||||
else
|
||||
echo "$INPUT" | gpg --trust-model always "$@" 2>/dev/null
|
||||
|
||||
+592
-55
@@ -1,39 +1,116 @@
|
||||
Developer Notes
|
||||
===============
|
||||
|
||||
<!-- markdown-toc start -->
|
||||
**Table of Contents**
|
||||
|
||||
- [Developer Notes](#developer-notes)
|
||||
- [Coding Style](#coding-style)
|
||||
- [Doxygen comments](#doxygen-comments)
|
||||
- [Development tips and tricks](#development-tips-and-tricks)
|
||||
- [Compiling for debugging](#compiling-for-debugging)
|
||||
- [Compiling for gprof profiling](#compiling-for-gprof-profiling)
|
||||
- [debug.log](#debuglog)
|
||||
- [Testnet and Regtest modes](#testnet-and-regtest-modes)
|
||||
- [DEBUG_LOCKORDER](#debug_lockorder)
|
||||
- [Valgrind suppressions file](#valgrind-suppressions-file)
|
||||
- [Compiling for test coverage](#compiling-for-test-coverage)
|
||||
- [Locking/mutex usage notes](#lockingmutex-usage-notes)
|
||||
- [Threads](#threads)
|
||||
- [Ignoring IDE/editor files](#ignoring-ideeditor-files)
|
||||
- [Development guidelines](#development-guidelines)
|
||||
- [General Bitcoin Core](#general-bitcoin-core)
|
||||
- [Wallet](#wallet)
|
||||
- [General C++](#general-c)
|
||||
- [C++ data structures](#c-data-structures)
|
||||
- [Strings and formatting](#strings-and-formatting)
|
||||
- [Variable names](#variable-names)
|
||||
- [Threads and synchronization](#threads-and-synchronization)
|
||||
- [Source code organization](#source-code-organization)
|
||||
- [GUI](#gui)
|
||||
- [Subtrees](#subtrees)
|
||||
- [Git and GitHub tips](#git-and-github-tips)
|
||||
- [Scripted diffs](#scripted-diffs)
|
||||
- [RPC interface guidelines](#rpc-interface-guidelines)
|
||||
|
||||
<!-- markdown-toc end -->
|
||||
|
||||
Coding Style
|
||||
---------------
|
||||
|
||||
Various coding styles have been used during the history of the codebase,
|
||||
and the result is not very consistent. However, we're now trying to converge to
|
||||
a single style, so please use it in new code. Old code will be converted
|
||||
gradually.
|
||||
- Basic rules specified in src/.clang-format. Use a recent clang-format-3.5 to format automatically.
|
||||
- Braces on new lines for namespaces, classes, functions, methods.
|
||||
a single style, which is specified below. When writing patches, favor the new
|
||||
style over attempting to mimic the surrounding style, except for move-only
|
||||
commits.
|
||||
|
||||
Do not submit patches solely to modify the style of existing code.
|
||||
|
||||
- **Indentation and whitespace rules** as specified in
|
||||
[src/.clang-format](/src/.clang-format). You can use the provided
|
||||
[clang-format-diff script](/contrib/devtools/README.md#clang-format-diffpy)
|
||||
tool to clean up patches automatically before submission.
|
||||
- Braces on new lines for classes, functions, methods.
|
||||
- Braces on the same line for everything else.
|
||||
- 4 space indentation (no tabs) for every block except namespaces.
|
||||
- No indentation for public/protected/private or for namespaces.
|
||||
- No indentation for `public`/`protected`/`private` or for `namespace`.
|
||||
- No extra spaces inside parenthesis; don't do ( this )
|
||||
- No space after function names; one space after if, for and while.
|
||||
- No space after function names; one space after `if`, `for` and `while`.
|
||||
- If an `if` only has a single-statement `then`-clause, it can appear
|
||||
on the same line as the `if`, without braces. In every other case,
|
||||
braces are required, and the `then` and `else` clauses must appear
|
||||
correctly indented on a new line.
|
||||
|
||||
- **Symbol naming conventions**. These are preferred in new code, but are not
|
||||
required when doing so would need changes to significant pieces of existing
|
||||
code.
|
||||
- Variable and namespace names are all lowercase, and may use `_` to
|
||||
separate words (snake_case).
|
||||
- Class member variables have a `m_` prefix.
|
||||
- Global variables have a `g_` prefix.
|
||||
- Constant names are all uppercase, and use `_` to separate words.
|
||||
- Class names, function names and method names are UpperCamelCase
|
||||
(PascalCase). Do not prefix class names with `C`.
|
||||
- Test suite naming convention: The Boost test suite in file
|
||||
`src/test/foo_tests.cpp` should be named `foo_tests`. Test suite names
|
||||
must be unique.
|
||||
|
||||
- **Miscellaneous**
|
||||
- `++i` is preferred over `i++`.
|
||||
- `nullptr` is preferred over `NULL` or `(void*)0`.
|
||||
- `static_assert` is preferred over `assert` where possible. Generally; compile-time checking is preferred over run-time checking.
|
||||
- `enum class` is preferred over `enum` where possible. Scoped enumerations avoid two potential pitfalls/problems with traditional C++ enumerations: implicit conversions to int, and name clashes due to enumerators being exported to the surrounding scope.
|
||||
|
||||
Block style example:
|
||||
```c++
|
||||
namespace foo
|
||||
{
|
||||
int g_count = 0;
|
||||
|
||||
namespace foo {
|
||||
class Class
|
||||
{
|
||||
bool Function(char* psz, int n)
|
||||
std::string m_name;
|
||||
|
||||
public:
|
||||
bool Function(const std::string& s, int n)
|
||||
{
|
||||
// Comment summarising what this section of code does
|
||||
for (int i = 0; i < n; i++) {
|
||||
for (int i = 0; i < n; ++i) {
|
||||
int total_sum = 0;
|
||||
// When something fails, return early
|
||||
if (!Something())
|
||||
return false;
|
||||
if (!Something()) return false;
|
||||
...
|
||||
if (SomethingElse(i)) {
|
||||
total_sum += ComputeSomething(g_count);
|
||||
} else {
|
||||
DoSomething(m_name, total_sum);
|
||||
}
|
||||
}
|
||||
|
||||
// Success return is usually at the end
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
} // namespace foo
|
||||
```
|
||||
|
||||
Doxygen comments
|
||||
@@ -95,57 +172,146 @@ Not OK (used plenty in the current source, but not picked up):
|
||||
A full list of comment syntaxes picked up by doxygen can be found at http://www.stack.nl/~dimitri/doxygen/manual/docblocks.html,
|
||||
but if possible use one of the above styles.
|
||||
|
||||
Documentation can be generated with `make docs` and cleaned up with `make clean-docs`.
|
||||
|
||||
Development tips and tricks
|
||||
---------------------------
|
||||
|
||||
**compiling for debugging**
|
||||
### Compiling for debugging
|
||||
|
||||
Run configure with the --enable-debug option, then make. Or run configure with
|
||||
CXXFLAGS="-g -ggdb -O0" or whatever debug flags you need.
|
||||
Run configure with `--enable-debug` to add additional compiler flags that
|
||||
produce better debugging builds.
|
||||
|
||||
**debug.log**
|
||||
### Compiling for gprof profiling
|
||||
|
||||
Run configure with the `--enable-gprof` option, then make.
|
||||
|
||||
### debug.log
|
||||
|
||||
If the code is behaving strangely, take a look in the debug.log file in the data directory;
|
||||
error and debugging messages are written there.
|
||||
|
||||
The -debug=... command-line option controls debugging; running with just -debug or -debug=1 will turn
|
||||
The `-debug=...` command-line option controls debugging; running with just `-debug` or `-debug=1` will turn
|
||||
on all categories (and give you a very large debug.log file).
|
||||
|
||||
The Qt code routes qDebug() output to debug.log under category "qt": run with -debug=qt
|
||||
The Qt code routes `qDebug()` output to debug.log under category "qt": run with `-debug=qt`
|
||||
to see it.
|
||||
|
||||
**testnet and regtest modes**
|
||||
### Testnet and Regtest modes
|
||||
|
||||
Run with the -testnet option to run with "play bitcoins" on the test network, if you
|
||||
Run with the `-testnet` option to run with "play bitcoins" on the test network, if you
|
||||
are testing multi-machine code that needs to operate across the internet.
|
||||
|
||||
If you are testing something that can run on one machine, run with the -regtest option.
|
||||
In regression test mode, blocks can be created on-demand; see qa/rpc-tests/ for tests
|
||||
that run in -regtest mode.
|
||||
If you are testing something that can run on one machine, run with the `-regtest` option.
|
||||
In regression test mode, blocks can be created on-demand; see [test/functional/](/test/functional) for tests
|
||||
that run in `-regtest` mode.
|
||||
|
||||
**DEBUG_LOCKORDER**
|
||||
### DEBUG_LOCKORDER
|
||||
|
||||
Bitcoin Core is a multithreaded application, and deadlocks or other multithreading bugs
|
||||
can be very difficult to track down. Compiling with -DDEBUG_LOCKORDER (configure
|
||||
CXXFLAGS="-DDEBUG_LOCKORDER -g") inserts run-time checks to keep track of which locks
|
||||
are held, and adds warnings to the debug.log file if inconsistencies are detected.
|
||||
Bitcoin Core is a multi-threaded application, and deadlocks or other
|
||||
multi-threading bugs can be very difficult to track down. The `--enable-debug`
|
||||
configure option adds `-DDEBUG_LOCKORDER` to the compiler flags. This inserts
|
||||
run-time checks to keep track of which locks are held, and adds warnings to the
|
||||
debug.log file if inconsistencies are detected.
|
||||
|
||||
### Valgrind suppressions file
|
||||
|
||||
Valgrind is a programming tool for memory debugging, memory leak detection, and
|
||||
profiling. The repo contains a Valgrind suppressions file
|
||||
([`valgrind.supp`](https://github.com/bitcoin/bitcoin/blob/master/contrib/valgrind.supp))
|
||||
which includes known Valgrind warnings in our dependencies that cannot be fixed
|
||||
in-tree. Example use:
|
||||
|
||||
```shell
|
||||
$ valgrind --suppressions=contrib/valgrind.supp src/test/test_bitcoin
|
||||
$ valgrind --suppressions=contrib/valgrind.supp --leak-check=full \
|
||||
--show-leak-kinds=all src/test/test_bitcoin --log_level=test_suite
|
||||
$ valgrind -v --leak-check=full src/bitcoind -printtoconsole
|
||||
```
|
||||
|
||||
### Compiling for test coverage
|
||||
|
||||
LCOV can be used to generate a test coverage report based upon `make check`
|
||||
execution. LCOV must be installed on your system (e.g. the `lcov` package
|
||||
on Debian/Ubuntu).
|
||||
|
||||
To enable LCOV report generation during test runs:
|
||||
|
||||
```shell
|
||||
./configure --enable-lcov
|
||||
make
|
||||
make cov
|
||||
|
||||
# A coverage report will now be accessible at `./test_bitcoin.coverage/index.html`.
|
||||
```
|
||||
|
||||
**Sanitizers**
|
||||
|
||||
Bitcoin can be compiled with various "sanitizers" enabled, which add
|
||||
instrumentation for issues regarding things like memory safety, thread race
|
||||
conditions, or undefined behavior. This is controlled with the
|
||||
`--with-sanitizers` configure flag, which should be a comma separated list of
|
||||
sanitizers to enable. The sanitizer list should correspond to supported
|
||||
`-fsanitize=` options in your compiler. These sanitizers have runtime overhead,
|
||||
so they are most useful when testing changes or producing debugging builds.
|
||||
|
||||
Some examples:
|
||||
|
||||
```bash
|
||||
# Enable both the address sanitizer and the undefined behavior sanitizer
|
||||
./configure --with-sanitizers=address,undefined
|
||||
|
||||
# Enable the thread sanitizer
|
||||
./configure --with-sanitizers=thread
|
||||
```
|
||||
|
||||
If you are compiling with GCC you will typically need to install corresponding
|
||||
"san" libraries to actually compile with these flags, e.g. libasan for the
|
||||
address sanitizer, libtsan for the thread sanitizer, and libubsan for the
|
||||
undefined sanitizer. If you are missing required libraries, the configure script
|
||||
will fail with a linker error when testing the sanitizer flags.
|
||||
|
||||
The test suite should pass cleanly with the `thread` and `undefined` sanitizers,
|
||||
but there are a number of known problems when using the `address` sanitizer. The
|
||||
address sanitizer is known to fail in
|
||||
[sha256_sse4::Transform](/src/crypto/sha256_sse4.cpp) which makes it unusable
|
||||
unless you also use `--disable-asm` when running configure. We would like to fix
|
||||
sanitizer issues, so please send pull requests if you can fix any errors found
|
||||
by the address sanitizer (or any other sanitizer).
|
||||
|
||||
Not all sanitizer options can be enabled at the same time, e.g. trying to build
|
||||
with `--with-sanitizers=address,thread` will fail in the configure script as
|
||||
these sanitizers are mutually incompatible. Refer to your compiler manual to
|
||||
learn more about these options and which sanitizers are supported by your
|
||||
compiler.
|
||||
|
||||
Additional resources:
|
||||
|
||||
* [AddressSanitizer](https://clang.llvm.org/docs/AddressSanitizer.html)
|
||||
* [LeakSanitizer](https://clang.llvm.org/docs/LeakSanitizer.html)
|
||||
* [MemorySanitizer](https://clang.llvm.org/docs/MemorySanitizer.html)
|
||||
* [ThreadSanitizer](https://clang.llvm.org/docs/ThreadSanitizer.html)
|
||||
* [UndefinedBehaviorSanitizer](https://clang.llvm.org/docs/UndefinedBehaviorSanitizer.html)
|
||||
* [GCC Instrumentation Options](https://gcc.gnu.org/onlinedocs/gcc/Instrumentation-Options.html)
|
||||
* [Google Sanitizers Wiki](https://github.com/google/sanitizers/wiki)
|
||||
* [Issue #12691: Enable -fsanitize flags in Travis](https://github.com/bitcoin/bitcoin/issues/12691)
|
||||
|
||||
Locking/mutex usage notes
|
||||
-------------------------
|
||||
|
||||
The code is multi-threaded, and uses mutexes and the
|
||||
LOCK/TRY_LOCK macros to protect data structures.
|
||||
`LOCK` and `TRY_LOCK` macros to protect data structures.
|
||||
|
||||
Deadlocks due to inconsistent lock ordering (thread 1 locks cs_main
|
||||
and then cs_wallet, while thread 2 locks them in the opposite order:
|
||||
result, deadlock as each waits for the other to release its lock) are
|
||||
a problem. Compile with -DDEBUG_LOCKORDER to get lock order
|
||||
inconsistencies reported in the debug.log file.
|
||||
Deadlocks due to inconsistent lock ordering (thread 1 locks `cs_main` and then
|
||||
`cs_wallet`, while thread 2 locks them in the opposite order: result, deadlock
|
||||
as each waits for the other to release its lock) are a problem. Compile with
|
||||
`-DDEBUG_LOCKORDER` (or use `--enable-debug`) to get lock order inconsistencies
|
||||
reported in the debug.log file.
|
||||
|
||||
Re-architecting the core code so there are better-defined interfaces
|
||||
between the various components is a goal, with any necessary locking
|
||||
done by the components (e.g. see the self-contained CKeyStore class
|
||||
and its cs_KeyStore lock for example).
|
||||
done by the components (e.g. see the self-contained `CBasicKeyStore` class
|
||||
and its `cs_KeyStore` lock for example).
|
||||
|
||||
Threads
|
||||
-------
|
||||
@@ -170,12 +336,8 @@ Threads
|
||||
|
||||
- DumpAddresses : Dumps IP addresses of nodes to peers.dat.
|
||||
|
||||
- ThreadFlushWalletDB : Close the wallet.dat file if it hasn't been used in 500ms.
|
||||
|
||||
- ThreadRPCServer : Remote procedure call handler, listens on port 8332 for connections and services them.
|
||||
|
||||
- BitcoinMiner : Generates bitcoins (if wallet is enabled).
|
||||
|
||||
- Shutdown : Does an orderly shutdown of everything.
|
||||
|
||||
Ignoring IDE/editor files
|
||||
@@ -229,9 +391,9 @@ General Bitcoin Core
|
||||
- *Rationale*: Makes sure that they pass thorough testing, and that the tester will keep passing
|
||||
on the master branch. Otherwise all new pull requests will start failing the tests, resulting in
|
||||
confusion and mayhem
|
||||
|
||||
|
||||
- *Explanation*: If the test suite is to be updated for a change, this has to
|
||||
be done first
|
||||
be done first
|
||||
|
||||
Wallet
|
||||
-------
|
||||
@@ -240,7 +402,7 @@ Wallet
|
||||
|
||||
- *Rationale*: In RPC code that conditionally uses the wallet (such as
|
||||
`validateaddress`) it is easy to forget that global pointer `pwalletMain`
|
||||
can be NULL. See `qa/rpc-tests/disablewallet.py` for functional tests
|
||||
can be nullptr. See `test/functional/disablewallet.py` for functional tests
|
||||
exercising the API with `-disablewallet`
|
||||
|
||||
- Include `db_cxx.h` (BerkeleyDB header) only when `ENABLE_WALLET` is set
|
||||
@@ -252,7 +414,7 @@ General C++
|
||||
|
||||
- Assertions should not have side-effects
|
||||
|
||||
- *Rationale*: Even though the source code is set to to refuse to compile
|
||||
- *Rationale*: Even though the source code is set to refuse to compile
|
||||
with assertions disabled, having side-effects in assertions is unexpected and
|
||||
makes the code harder to understand
|
||||
|
||||
@@ -263,7 +425,7 @@ General C++
|
||||
the `.h` to the `.cpp` should not result in build errors
|
||||
|
||||
- Use the RAII (Resource Acquisition Is Initialization) paradigm where possible. For example by using
|
||||
`scoped_pointer` for allocations in a function.
|
||||
`unique_ptr` for allocations in a function.
|
||||
|
||||
- *Rationale*: This avoids memory and resource leaks, and ensures exception safety
|
||||
|
||||
@@ -282,19 +444,33 @@ C++ data structures
|
||||
- *Rationale*: Behavior is undefined. In C++ parlor this means "may reformat
|
||||
the universe", in practice this has resulted in at least one hard-to-debug crash bug
|
||||
|
||||
- Watch out for vector out-of-bounds exceptions. `&vch[0]` is illegal for an
|
||||
empty vector, `&vch[vch.size()]` is always illegal. Use `begin_ptr(vch)` and
|
||||
`end_ptr(vch)` to get the begin and end pointer instead (defined in
|
||||
`serialize.h`)
|
||||
- Watch out for out-of-bounds vector access. `&vch[vch.size()]` is illegal,
|
||||
including `&vch[0]` for an empty vector. Use `vch.data()` and `vch.data() +
|
||||
vch.size()` instead.
|
||||
|
||||
- Vector bounds checking is only enabled in debug mode. Do not rely on it
|
||||
|
||||
- Make sure that constructors initialize all fields. If this is skipped for a
|
||||
good reason (i.e., optimization on the critical path), add an explicit
|
||||
comment about this
|
||||
- Initialize all non-static class members where they are defined.
|
||||
If this is skipped for a good reason (i.e., optimization on the critical
|
||||
path), add an explicit comment about this
|
||||
|
||||
- *Rationale*: Ensure determinism by avoiding accidental use of uninitialized
|
||||
values. Also, static analyzers balk about this.
|
||||
Initializing the members in the declaration makes it easy to
|
||||
spot uninitialized ones.
|
||||
|
||||
```cpp
|
||||
class A
|
||||
{
|
||||
uint32_t m_count{0};
|
||||
}
|
||||
```
|
||||
|
||||
- By default, declare single-argument constructors `explicit`.
|
||||
|
||||
- *Rationale*: This is a precaution to avoid unintended conversions that might
|
||||
arise when single-argument constructors are used as implicit conversion
|
||||
functions.
|
||||
|
||||
- Use explicitly signed or unsigned `char`s, or even better `uint8_t` and
|
||||
`int8_t`. Do not use bare `char` unless it is to pass to a third-party API.
|
||||
@@ -321,14 +497,67 @@ Strings and formatting
|
||||
buffer overflows and surprises with `\0` characters. Also some C string manipulations
|
||||
tend to act differently depending on platform, or even the user locale
|
||||
|
||||
- Use `ParseInt32`, `ParseInt64`, `ParseDouble` from `utilstrencodings.h` for number parsing
|
||||
- Use `ParseInt32`, `ParseInt64`, `ParseUInt32`, `ParseUInt64`, `ParseDouble` from `utilstrencodings.h` for number parsing
|
||||
|
||||
- *Rationale*: These functions do overflow checking, and avoid pesky locale issues
|
||||
- *Rationale*: These functions do overflow checking, and avoid pesky locale issues.
|
||||
|
||||
- Avoid using locale dependent functions if possible. You can use the provided
|
||||
[`lint-locale-dependence.sh`](/contrib/devtools/lint-locale-dependence.sh)
|
||||
to check for accidental use of locale dependent functions.
|
||||
|
||||
- *Rationale*: Unnecessary locale dependence can cause bugs that are very tricky to isolate and fix.
|
||||
|
||||
- These functions are known to be locale dependent:
|
||||
`alphasort`, `asctime`, `asprintf`, `atof`, `atoi`, `atol`, `atoll`, `atoq`,
|
||||
`btowc`, `ctime`, `dprintf`, `fgetwc`, `fgetws`, `fprintf`, `fputwc`,
|
||||
`fputws`, `fscanf`, `fwprintf`, `getdate`, `getwc`, `getwchar`, `isalnum`,
|
||||
`isalpha`, `isblank`, `iscntrl`, `isdigit`, `isgraph`, `islower`, `isprint`,
|
||||
`ispunct`, `isspace`, `isupper`, `iswalnum`, `iswalpha`, `iswblank`,
|
||||
`iswcntrl`, `iswctype`, `iswdigit`, `iswgraph`, `iswlower`, `iswprint`,
|
||||
`iswpunct`, `iswspace`, `iswupper`, `iswxdigit`, `isxdigit`, `mblen`,
|
||||
`mbrlen`, `mbrtowc`, `mbsinit`, `mbsnrtowcs`, `mbsrtowcs`, `mbstowcs`,
|
||||
`mbtowc`, `mktime`, `putwc`, `putwchar`, `scanf`, `snprintf`, `sprintf`,
|
||||
`sscanf`, `stoi`, `stol`, `stoll`, `strcasecmp`, `strcasestr`, `strcoll`,
|
||||
`strfmon`, `strftime`, `strncasecmp`, `strptime`, `strtod`, `strtof`,
|
||||
`strtoimax`, `strtol`, `strtold`, `strtoll`, `strtoq`, `strtoul`,
|
||||
`strtoull`, `strtoumax`, `strtouq`, `strxfrm`, `swprintf`, `tolower`,
|
||||
`toupper`, `towctrans`, `towlower`, `towupper`, `ungetwc`, `vasprintf`,
|
||||
`vdprintf`, `versionsort`, `vfprintf`, `vfscanf`, `vfwprintf`, `vprintf`,
|
||||
`vscanf`, `vsnprintf`, `vsprintf`, `vsscanf`, `vswprintf`, `vwprintf`,
|
||||
`wcrtomb`, `wcscasecmp`, `wcscoll`, `wcsftime`, `wcsncasecmp`, `wcsnrtombs`,
|
||||
`wcsrtombs`, `wcstod`, `wcstof`, `wcstoimax`, `wcstol`, `wcstold`,
|
||||
`wcstoll`, `wcstombs`, `wcstoul`, `wcstoull`, `wcstoumax`, `wcswidth`,
|
||||
`wcsxfrm`, `wctob`, `wctomb`, `wctrans`, `wctype`, `wcwidth`, `wprintf`
|
||||
|
||||
- For `strprintf`, `LogPrint`, `LogPrintf` formatting characters don't need size specifiers
|
||||
|
||||
- *Rationale*: Bitcoin Core uses tinyformat, which is type safe. Leave them out to avoid confusion
|
||||
|
||||
Variable names
|
||||
--------------
|
||||
|
||||
Although the shadowing warning (`-Wshadow`) is not enabled by default (it prevents issues rising
|
||||
from using a different variable with the same name),
|
||||
please name variables so that their names do not shadow variables defined in the source code.
|
||||
|
||||
E.g. in member initializers, prepend `_` to the argument name shadowing the
|
||||
member name:
|
||||
|
||||
```c++
|
||||
class AddressBookPage
|
||||
{
|
||||
Mode m_mode;
|
||||
}
|
||||
|
||||
AddressBookPage::AddressBookPage(Mode _mode) :
|
||||
m_mode(_mode)
|
||||
...
|
||||
```
|
||||
|
||||
When using nested cycles, do not name the inner cycle variable the same as in
|
||||
upper cycle etc.
|
||||
|
||||
|
||||
Threads and synchronization
|
||||
----------------------------
|
||||
|
||||
@@ -366,11 +595,57 @@ Source code organization
|
||||
|
||||
- *Rationale*: Shorter and simpler header files are easier to read, and reduce compile time
|
||||
|
||||
- Use only the lowercase alphanumerics (`a-z0-9`), underscore (`_`) and hyphen (`-`) in source code filenames.
|
||||
|
||||
- *Rationale*: `grep`:ing and auto-completing filenames is easier when using a consistent
|
||||
naming pattern. Potential problems when building on case-insensitive filesystems are
|
||||
avoided when using only lowercase characters in source code filenames.
|
||||
|
||||
- Every `.cpp` and `.h` file should `#include` every header file it directly uses classes, functions or other
|
||||
definitions from, even if those headers are already included indirectly through other headers.
|
||||
|
||||
- *Rationale*: Excluding headers because they are already indirectly included results in compilation
|
||||
failures when those indirect dependencies change. Furthermore, it obscures what the real code
|
||||
dependencies are.
|
||||
|
||||
- Don't import anything into the global namespace (`using namespace ...`). Use
|
||||
fully specified types such as `std::string`.
|
||||
|
||||
- *Rationale*: Avoids symbol conflicts
|
||||
|
||||
- Terminate namespaces with a comment (`// namespace mynamespace`). The comment
|
||||
should be placed on the same line as the brace closing the namespace, e.g.
|
||||
|
||||
```c++
|
||||
namespace mynamespace {
|
||||
...
|
||||
} // namespace mynamespace
|
||||
|
||||
namespace {
|
||||
...
|
||||
} // namespace
|
||||
```
|
||||
|
||||
- *Rationale*: Avoids confusion about the namespace context
|
||||
|
||||
- Use `#include <primitives/transaction.h>` bracket syntax instead of
|
||||
`#include "primitives/transactions.h"` quote syntax.
|
||||
|
||||
- *Rationale*: Bracket syntax is less ambiguous because the preprocessor
|
||||
searches a fixed list of include directories without taking location of the
|
||||
source file into account. This allows quoted includes to stand out more when
|
||||
the location of the source file actually is relevant.
|
||||
|
||||
- Use include guards to avoid the problem of double inclusion. The header file
|
||||
`foo/bar.h` should use the include guard identifier `BITCOIN_FOO_BAR_H`, e.g.
|
||||
|
||||
```c++
|
||||
#ifndef BITCOIN_FOO_BAR_H
|
||||
#define BITCOIN_FOO_BAR_H
|
||||
...
|
||||
#endif // BITCOIN_FOO_BAR_H
|
||||
```
|
||||
|
||||
GUI
|
||||
-----
|
||||
|
||||
@@ -379,3 +654,265 @@ GUI
|
||||
- *Rationale*: Model classes pass through events and data from the core, they
|
||||
should not interact with the user. That's where View classes come in. The converse also
|
||||
holds: try to not directly access core data structures from Views.
|
||||
|
||||
- Avoid adding slow or blocking code in the GUI thread. In particular do not
|
||||
add new `interfaces::Node` and `interfaces::Wallet` method calls, even if they
|
||||
may be fast now, in case they are changed to lock or communicate across
|
||||
processes in the future.
|
||||
|
||||
Prefer to offload work from the GUI thread to worker threads (see
|
||||
`RPCExecutor` in console code as an example) or take other steps (see
|
||||
https://doc.qt.io/archives/qq/qq27-responsive-guis.html) to keep the GUI
|
||||
responsive.
|
||||
|
||||
- *Rationale*: Blocking the GUI thread can increase latency, and lead to
|
||||
hangs and deadlocks.
|
||||
|
||||
Subtrees
|
||||
----------
|
||||
|
||||
Several parts of the repository are subtrees of software maintained elsewhere.
|
||||
|
||||
Some of these are maintained by active developers of Bitcoin Core, in which case changes should probably go
|
||||
directly upstream without being PRed directly against the project. They will be merged back in the next
|
||||
subtree merge.
|
||||
|
||||
Others are external projects without a tight relationship with our project. Changes to these should also
|
||||
be sent upstream but bugfixes may also be prudent to PR against Bitcoin Core so that they can be integrated
|
||||
quickly. Cosmetic changes should be purely taken upstream.
|
||||
|
||||
There is a tool in `test/lint/git-subtree-check.sh` to check a subtree directory for consistency with
|
||||
its upstream repository.
|
||||
|
||||
Current subtrees include:
|
||||
|
||||
- src/leveldb
|
||||
- Upstream at https://github.com/google/leveldb ; Maintained by Google, but
|
||||
open important PRs to Core to avoid delay.
|
||||
- **Note**: Follow the instructions in [Upgrading LevelDB](#upgrading-leveldb) when
|
||||
merging upstream changes to the leveldb subtree.
|
||||
|
||||
- src/libsecp256k1
|
||||
- Upstream at https://github.com/bitcoin-core/secp256k1/ ; actively maintaned by Core contributors.
|
||||
|
||||
- src/crypto/ctaes
|
||||
- Upstream at https://github.com/bitcoin-core/ctaes ; actively maintained by Core contributors.
|
||||
|
||||
- src/univalue
|
||||
- Upstream at https://github.com/jgarzik/univalue ; report important PRs to Core to avoid delay.
|
||||
|
||||
Upgrading LevelDB
|
||||
---------------------
|
||||
|
||||
Extra care must be taken when upgrading LevelDB. This section explains issues
|
||||
you must be aware of.
|
||||
|
||||
### File Descriptor Counts
|
||||
|
||||
In most configurations we use the default LevelDB value for `max_open_files`,
|
||||
which is 1000 at the time of this writing. If LevelDB actually uses this many
|
||||
file descriptors it will cause problems with Bitcoin's `select()` loop, because
|
||||
it may cause new sockets to be created where the fd value is >= 1024. For this
|
||||
reason, on 64-bit Unix systems we rely on an internal LevelDB optimization that
|
||||
uses `mmap()` + `close()` to open table files without actually retaining
|
||||
references to the table file descriptors. If you are upgrading LevelDB, you must
|
||||
sanity check the changes to make sure that this assumption remains valid.
|
||||
|
||||
In addition to reviewing the upstream changes in `env_posix.cc`, you can use `lsof` to
|
||||
check this. For example, on Linux this command will show open `.ldb` file counts:
|
||||
|
||||
```bash
|
||||
$ lsof -p $(pidof bitcoind) |\
|
||||
awk 'BEGIN { fd=0; mem=0; } /ldb$/ { if ($4 == "mem") mem++; else fd++ } END { printf "mem = %s, fd = %s\n", mem, fd}'
|
||||
mem = 119, fd = 0
|
||||
```
|
||||
|
||||
The `mem` value shows how many files are mmap'ed, and the `fd` value shows you
|
||||
many file descriptors these files are using. You should check that `fd` is a
|
||||
small number (usually 0 on 64-bit hosts).
|
||||
|
||||
See the notes in the `SetMaxOpenFiles()` function in `dbwrapper.cc` for more
|
||||
details.
|
||||
|
||||
### Consensus Compatibility
|
||||
|
||||
It is possible for LevelDB changes to inadvertently change consensus
|
||||
compatibility between nodes. This happened in Bitcoin 0.8 (when LevelDB was
|
||||
first introduced). When upgrading LevelDB you should review the upstream changes
|
||||
to check for issues affecting consensus compatibility.
|
||||
|
||||
For example, if LevelDB had a bug that accidentally prevented a key from being
|
||||
returned in an edge case, and that bug was fixed upstream, the bug "fix" would
|
||||
be an incompatible consensus change. In this situation the correct behavior
|
||||
would be to revert the upstream fix before applying the updates to Bitcoin's
|
||||
copy of LevelDB. In general you should be wary of any upstream changes affecting
|
||||
what data is returned from LevelDB queries.
|
||||
|
||||
Git and GitHub tips
|
||||
---------------------
|
||||
|
||||
- For resolving merge/rebase conflicts, it can be useful to enable diff3 style using
|
||||
`git config merge.conflictstyle diff3`. Instead of
|
||||
|
||||
<<<
|
||||
yours
|
||||
===
|
||||
theirs
|
||||
>>>
|
||||
|
||||
you will see
|
||||
|
||||
<<<
|
||||
yours
|
||||
|||
|
||||
original
|
||||
===
|
||||
theirs
|
||||
>>>
|
||||
|
||||
This may make it much clearer what caused the conflict. In this style, you can often just look
|
||||
at what changed between *original* and *theirs*, and mechanically apply that to *yours* (or the other way around).
|
||||
|
||||
- When reviewing patches which change indentation in C++ files, use `git diff -w` and `git show -w`. This makes
|
||||
the diff algorithm ignore whitespace changes. This feature is also available on github.com, by adding `?w=1`
|
||||
at the end of any URL which shows a diff.
|
||||
|
||||
- When reviewing patches that change symbol names in many places, use `git diff --word-diff`. This will instead
|
||||
of showing the patch as deleted/added *lines*, show deleted/added *words*.
|
||||
|
||||
- When reviewing patches that move code around, try using
|
||||
`git diff --patience commit~:old/file.cpp commit:new/file/name.cpp`, and ignoring everything except the
|
||||
moved body of code which should show up as neither `+` or `-` lines. In case it was not a pure move, this may
|
||||
even work when combined with the `-w` or `--word-diff` options described above.
|
||||
|
||||
- When looking at other's pull requests, it may make sense to add the following section to your `.git/config`
|
||||
file:
|
||||
|
||||
[remote "upstream-pull"]
|
||||
fetch = +refs/pull/*:refs/remotes/upstream-pull/*
|
||||
url = git@github.com:bitcoin/bitcoin.git
|
||||
|
||||
This will add an `upstream-pull` remote to your git repository, which can be fetched using `git fetch --all`
|
||||
or `git fetch upstream-pull`. Afterwards, you can use `upstream-pull/NUMBER/head` in arguments to `git show`,
|
||||
`git checkout` and anywhere a commit id would be acceptable to see the changes from pull request NUMBER.
|
||||
|
||||
Scripted diffs
|
||||
--------------
|
||||
|
||||
For reformatting and refactoring commits where the changes can be easily automated using a bash script, we use
|
||||
scripted-diff commits. The bash script is included in the commit message and our Travis CI job checks that
|
||||
the result of the script is identical to the commit. This aids reviewers since they can verify that the script
|
||||
does exactly what it's supposed to do. It is also helpful for rebasing (since the same script can just be re-run
|
||||
on the new master commit).
|
||||
|
||||
To create a scripted-diff:
|
||||
|
||||
- start the commit message with `scripted-diff:` (and then a description of the diff on the same line)
|
||||
- in the commit message include the bash script between lines containing just the following text:
|
||||
- `-BEGIN VERIFY SCRIPT-`
|
||||
- `-END VERIFY SCRIPT-`
|
||||
|
||||
The scripted-diff is verified by the tool `test/lint/commit-script-check.sh`
|
||||
|
||||
Commit [`bb81e173`](https://github.com/bitcoin/bitcoin/commit/bb81e173) is an example of a scripted-diff.
|
||||
|
||||
RPC interface guidelines
|
||||
--------------------------
|
||||
|
||||
A few guidelines for introducing and reviewing new RPC interfaces:
|
||||
|
||||
- Method naming: use consecutive lower-case names such as `getrawtransaction` and `submitblock`
|
||||
|
||||
- *Rationale*: Consistency with existing interface.
|
||||
|
||||
- Argument naming: use snake case `fee_delta` (and not, e.g. camel case `feeDelta`)
|
||||
|
||||
- *Rationale*: Consistency with existing interface.
|
||||
|
||||
- Use the JSON parser for parsing, don't manually parse integers or strings from
|
||||
arguments unless absolutely necessary.
|
||||
|
||||
- *Rationale*: Introduces hand-rolled string manipulation code at both the caller and callee sites,
|
||||
which is error prone, and it is easy to get things such as escaping wrong.
|
||||
JSON already supports nested data structures, no need to re-invent the wheel.
|
||||
|
||||
- *Exception*: AmountFromValue can parse amounts as string. This was introduced because many JSON
|
||||
parsers and formatters hard-code handling decimal numbers as floating point
|
||||
values, resulting in potential loss of precision. This is unacceptable for
|
||||
monetary values. **Always** use `AmountFromValue` and `ValueFromAmount` when
|
||||
inputting or outputting monetary values. The only exceptions to this are
|
||||
`prioritisetransaction` and `getblocktemplate` because their interface
|
||||
is specified as-is in BIP22.
|
||||
|
||||
- Missing arguments and 'null' should be treated the same: as default values. If there is no
|
||||
default value, both cases should fail in the same way. The easiest way to follow this
|
||||
guideline is detect unspecified arguments with `params[x].isNull()` instead of
|
||||
`params.size() <= x`. The former returns true if the argument is either null or missing,
|
||||
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
|
||||
are passed as 'null'.
|
||||
|
||||
- Try not to overload methods on argument type. E.g. don't make `getblock(true)` and `getblock("hash")`
|
||||
do different things.
|
||||
|
||||
- *Rationale*: This is impossible to use with `bitcoin-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
|
||||
to a multi-value, or due to other historical reasons. **Always** have false map to 0 and
|
||||
true to 1 in this case.
|
||||
|
||||
- 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.
|
||||
|
||||
- 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
|
||||
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
|
||||
RPCs don't work.
|
||||
|
||||
- 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
|
||||
convert a plaintext command line to JSON. If the types don't match, the method can be unusable
|
||||
from there.
|
||||
|
||||
- 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
|
||||
based on presence of a wallet.
|
||||
|
||||
- *Rationale*: as well as complicating the implementation and interfering
|
||||
with the introduction of multi-wallet, wallet and non-wallet code should be
|
||||
separated to avoid introducing circular dependencies between code units.
|
||||
|
||||
- Try to make the RPC response a JSON object.
|
||||
|
||||
- *Rationale*: If a RPC response is not a JSON object then it is harder to avoid API breakage if
|
||||
new data in the response is needed.
|
||||
|
||||
- Wallet RPCs call BlockUntilSyncedToCurrentChain to maintain consistency with
|
||||
`getblockchaininfo`'s state immediately prior to the call's execution. Wallet
|
||||
RPCs whose behavior does *not* depend on the current chainstate may omit this
|
||||
call.
|
||||
|
||||
- *Rationale*: In previous versions of Bitcoin Core, the wallet was always
|
||||
in-sync with the chainstate (by virtue of them all being updated in the
|
||||
same cs_main lock). In order to maintain the behavior that wallet RPCs
|
||||
return results as of at least the highest best-known block an RPC
|
||||
client may be aware of prior to entering a wallet RPC call, we must block
|
||||
until the wallet is caught up to the chainstate as of the RPC call's entry.
|
||||
This also makes the API much easier for RPC clients to reason about.
|
||||
|
||||
- Be aware of RPC method aliases and generally avoid registering the same
|
||||
callback function pointer for different RPCs.
|
||||
|
||||
- *Rationale*: RPC methods registered with the same function pointer will be
|
||||
considered aliases and only the first method name will show up in the
|
||||
`help` rpc command list.
|
||||
|
||||
- *Exception*: Using RPC method aliases may be appropriate in cases where a
|
||||
new RPC is replacing a deprecated RPC, to avoid both RPCs confusingly
|
||||
showing up in the command list.
|
||||
|
||||
+41
-10
@@ -16,6 +16,7 @@ function HELP {
|
||||
echo "Optional arguments:"
|
||||
echo
|
||||
echo "-c: don't clone a fresh copy of the repo"
|
||||
echo "-f: check formatting of committed code relative to master"
|
||||
echo "-r: remove intermediate files."
|
||||
echo "-l: build only lbrycrd"
|
||||
echo "-d: build only the dependencies"
|
||||
@@ -27,6 +28,7 @@ function HELP {
|
||||
|
||||
CLONE=true
|
||||
CLEAN=false
|
||||
CHECK_CODE_FORMAT=false
|
||||
BUILD_DEPENDENCIES=true
|
||||
BUILD_LBRYCRD=true
|
||||
TIMEOUT=false
|
||||
@@ -35,7 +37,7 @@ THREE_MB=3145728
|
||||
# the script exits due to a timeout
|
||||
OUTPUT_LOG=true
|
||||
|
||||
while getopts :crldoth:w:d: FLAG; do
|
||||
while getopts :crfldoth:w:d: FLAG; do
|
||||
case $FLAG in
|
||||
c)
|
||||
CLONE=false
|
||||
@@ -43,6 +45,9 @@ while getopts :crldoth:w:d: FLAG; do
|
||||
r)
|
||||
CLEAN=true
|
||||
;;
|
||||
f)
|
||||
CHECK_CODE_FORMAT=true
|
||||
;;
|
||||
l)
|
||||
BUILD_DEPENDENCIES=false
|
||||
;;
|
||||
@@ -201,6 +206,7 @@ function brew_if_not_installed() {
|
||||
|
||||
function install_brew_packages() {
|
||||
brew update > /dev/null
|
||||
brew unlink python
|
||||
brew_if_not_installed autoconf
|
||||
brew_if_not_installed automake
|
||||
# something weird happened where glibtoolize was failing to find
|
||||
@@ -209,6 +215,10 @@ function install_brew_packages() {
|
||||
brew_if_not_installed pkg-config
|
||||
brew_if_not_installed protobuf
|
||||
brew_if_not_installed gmp
|
||||
|
||||
if [ "${CHECK_CODE_FORMAT}" = true ]; then
|
||||
brew_if_not_installed clang-format
|
||||
fi
|
||||
}
|
||||
|
||||
function install_apt_packages() {
|
||||
@@ -224,6 +234,12 @@ function install_apt_packages() {
|
||||
build-essential python-dev libbz2-dev libtool \
|
||||
autotools-dev autoconf git pkg-config wget \
|
||||
ca-certificates automake bsdmainutils
|
||||
|
||||
if [ "${CHECK_CODE_FORMAT}" = true ]; then
|
||||
$SUDO apt-get ${QUIET} install -y --no-install-recommends \
|
||||
clang-format-3.4
|
||||
fi
|
||||
|
||||
}
|
||||
|
||||
function build_dependencies() {
|
||||
@@ -232,7 +248,7 @@ function build_dependencies() {
|
||||
else
|
||||
install_apt_packages
|
||||
fi
|
||||
|
||||
|
||||
if [ "$CLEAN" = true ]; then
|
||||
rm -rf "${LBRYCRD_DEPENDENCIES}"
|
||||
rm -rf "${OUTPUT_DIR}"
|
||||
@@ -246,7 +262,7 @@ function build_dependencies() {
|
||||
|
||||
build_dependency "${BDB_PREFIX}" "${LOG_DIR}/bdb_build.log" build_bdb
|
||||
build_dependency "${OPENSSL_PREFIX}" "${LOG_DIR}/openssl_build.log" build_openssl
|
||||
|
||||
|
||||
set +u
|
||||
export PKG_CONFIG_PATH="${PKG_CONFIG_PATH}:${OPENSSL_PREFIX}/lib/pkgconfig/"
|
||||
set -u
|
||||
@@ -277,8 +293,9 @@ function build_openssl() {
|
||||
-fPIC darwin64-x86_64-cc \
|
||||
no-shared no-dso no-engines > "${OPENSSL_LOG}"
|
||||
else
|
||||
[[ $(uname -m) = 'i686' ]] && OS_ARCH="linux-generic32" || OS_ARCH="linux-x86_64"
|
||||
./Configure --prefix="${OPENSSL_PREFIX}" --openssldir="${OPENSSL_PREFIX}/ssl" \
|
||||
linux-x86_64 -fPIC -static no-shared no-dso > "${OPENSSL_LOG}"
|
||||
${OS_ARCH} -fPIC -static no-shared no-dso > "${OPENSSL_LOG}"
|
||||
fi
|
||||
background make "${OPENSSL_LOG}" "Waiting for openssl to finish building"
|
||||
make install >> "${OPENSSL_LOG}" 2>&1
|
||||
@@ -343,18 +360,23 @@ function build_lbrycrd() {
|
||||
LDFLAGS="${LDFLAGS}" \
|
||||
CPPFLAGS="${CPPFLAGS}" >> "${LBRYCRD_LOG}" 2>&1
|
||||
background make "${LBRYCRD_LOG}" "Waiting for lbrycrd to finish building"
|
||||
# tests don't work on OSX. Should definitely figure out why
|
||||
# that is but, for now, not letting that stop the rest
|
||||
# of the build
|
||||
if [ "${OS_NAME}" = "linux" ]; then
|
||||
src/test/test_lbrycrd
|
||||
fi
|
||||
src/test/test_lbrycrd
|
||||
strip src/lbrycrdd
|
||||
strip src/lbrycrd-cli
|
||||
strip src/lbrycrd-tx
|
||||
strip src/test/test_lbrycrd
|
||||
}
|
||||
|
||||
function clang_format_diff(){
|
||||
# run a code formatting check on any commits not in master
|
||||
# requires clang-format
|
||||
if ! git config remote.origin2.url > /dev/null; then
|
||||
git remote add origin2 https://github.com/lbryio/lbrycrd.git
|
||||
fi
|
||||
git fetch origin2
|
||||
git diff -U0 origin2/master -- '*.h' '*.cpp' | ./contrib/devtools/clang-format-diff.py -p1
|
||||
}
|
||||
|
||||
# these variables are needed in both functions
|
||||
LBRYCRD_DEPENDENCIES="$(pwd)/lbrycrd-dependencies"
|
||||
OUTPUT_DIR="$(pwd)/build"
|
||||
@@ -368,6 +390,15 @@ if [ "${BUILD_DEPENDENCIES}" = true ]; then
|
||||
build_dependencies
|
||||
fi
|
||||
|
||||
if [ "${CHECK_CODE_FORMAT}" = true ]; then
|
||||
LINES_W_FORMAT_REQUIRED=$(clang_format_diff | wc -l)
|
||||
if [ ${LINES_W_FORMAT_REQUIRED} -ne 0 ]; then
|
||||
echo "Failed to pass clang format diff: See below for the diff"
|
||||
clang_format_diff
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
|
||||
set +u
|
||||
export PKG_CONFIG_PATH="${PKG_CONFIG_PATH}:${OPENSSL_PREFIX}/lib/pkgconfig/:${LIBEVENT_PREFIX}/lib/pkgconfig/"
|
||||
set -u
|
||||
|
||||
+6
-4
@@ -6,13 +6,16 @@ AlignTrailingComments: true
|
||||
AllowAllParametersOfDeclarationOnNextLine: false
|
||||
AllowShortBlocksOnASingleLine: false
|
||||
AllowShortFunctionsOnASingleLine: All
|
||||
AllowShortIfStatementsOnASingleLine: false
|
||||
AllowShortIfStatementsOnASingleLine: true
|
||||
AllowShortLoopsOnASingleLine: false
|
||||
AlwaysBreakBeforeMultilineStrings: false
|
||||
AlwaysBreakTemplateDeclarations: true
|
||||
BinPackParameters: false
|
||||
BreakBeforeBinaryOperators: false
|
||||
BreakBeforeBraces: Linux
|
||||
BreakBeforeBraces: Custom
|
||||
BraceWrapping:
|
||||
AfterClass: true
|
||||
AfterFunction: true
|
||||
BreakBeforeTernaryOperators: false
|
||||
BreakConstructorInitializersBeforeComma: false
|
||||
ColumnLimit: 0
|
||||
@@ -23,7 +26,6 @@ ContinuationIndentWidth: 4
|
||||
Cpp11BracedListStyle: true
|
||||
DerivePointerAlignment: false
|
||||
DisableFormat: false
|
||||
ForEachMacros: [ foreach, Q_FOREACH, BOOST_FOREACH, BOOST_REVERSE_FOREACH ]
|
||||
IndentCaseLabels: false
|
||||
IndentFunctionDeclarationAfterType: false
|
||||
IndentWidth: 4
|
||||
@@ -49,4 +51,4 @@ SpacesInCStyleCastParentheses: false
|
||||
SpacesInParentheses: false
|
||||
Standard: Cpp03
|
||||
TabWidth: 8
|
||||
UseTab: Never
|
||||
UseTab: Never
|
||||
@@ -60,7 +60,6 @@ BITCOIN_TESTS =\
|
||||
test/merkle_tests.cpp \
|
||||
test/miner_tests.cpp \
|
||||
test/multisig_tests.cpp \
|
||||
test/claimtrie_tests.cpp \
|
||||
test/claimtriecache_tests.cpp \
|
||||
test/claimtriebranching_tests.cpp \
|
||||
test/nameclaim_tests.cpp \
|
||||
|
||||
+32
-22
@@ -526,31 +526,41 @@ claimsForNameType CClaimTrie::getClaimsForName(const std::string& name) const
|
||||
return allClaims;
|
||||
}
|
||||
|
||||
//return effective amount form claim, retuns 0 if claim is not found
|
||||
//return effective amount from claim, retuns 0 if claim is not found
|
||||
CAmount CClaimTrie::getEffectiveAmountForClaim(const std::string& name, uint160 claimId) const
|
||||
{
|
||||
claimsForNameType claims = getClaimsForName(name);
|
||||
CAmount effectiveAmount = 0;
|
||||
bool claim_found = false;
|
||||
for (std::vector<CClaimValue>::iterator it=claims.claims.begin(); it!=claims.claims.end(); ++it)
|
||||
{
|
||||
if (it->claimId == claimId && it->nValidAtHeight < nCurrentHeight)
|
||||
{
|
||||
effectiveAmount += it->nAmount;
|
||||
claim_found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!claim_found)
|
||||
return effectiveAmount;
|
||||
std::vector<CSupportValue> supports;
|
||||
return getEffectiveAmountForClaimWithSupports(name, claimId, supports);
|
||||
}
|
||||
|
||||
for (std::vector<CSupportValue>::iterator it=claims.supports.begin(); it!=claims.supports.end(); ++it)
|
||||
{
|
||||
if (it->supportedClaimId == claimId && it->nValidAtHeight < nCurrentHeight)
|
||||
effectiveAmount += it->nAmount;
|
||||
}
|
||||
return effectiveAmount;
|
||||
//return effective amount from claim and the supports used as inputs, retuns 0 if claim is not found
|
||||
CAmount CClaimTrie::getEffectiveAmountForClaimWithSupports(const std::string& name, uint160 claimId,
|
||||
std::vector<CSupportValue>& supports) const
|
||||
{
|
||||
claimsForNameType claims = getClaimsForName(name);
|
||||
CAmount effectiveAmount = 0;
|
||||
bool claim_found = false;
|
||||
for (std::vector<CClaimValue>::iterator it=claims.claims.begin(); it!=claims.claims.end(); ++it)
|
||||
{
|
||||
if (it->claimId == claimId && it->nValidAtHeight < nCurrentHeight)
|
||||
{
|
||||
effectiveAmount += it->nAmount;
|
||||
claim_found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!claim_found)
|
||||
return effectiveAmount;
|
||||
|
||||
for (std::vector<CSupportValue>::iterator it=claims.supports.begin(); it!=claims.supports.end(); ++it)
|
||||
{
|
||||
if (it->supportedClaimId == claimId && it->nValidAtHeight < nCurrentHeight)
|
||||
{
|
||||
effectiveAmount += it->nAmount;
|
||||
supports.push_back(*it);
|
||||
}
|
||||
}
|
||||
return effectiveAmount;
|
||||
}
|
||||
|
||||
bool CClaimTrie::checkConsistency() const
|
||||
@@ -2671,7 +2681,7 @@ bool CClaimTrieCache::forkForExpirationChange(bool increment) const
|
||||
if (pcursor->GetKey(key))
|
||||
{
|
||||
int height = key.second;
|
||||
// if we've looked throught this in dirtyExprirationQueueRows, don't use it
|
||||
// if we've looked through this in dirtyExprirationQueueRows, don't use it
|
||||
// because its stale
|
||||
if ((key.first == EXP_QUEUE_ROW) & (dirtyHeights.count(height) == 0))
|
||||
{
|
||||
|
||||
@@ -321,6 +321,8 @@ public:
|
||||
|
||||
claimsForNameType getClaimsForName(const std::string& name) const;
|
||||
CAmount getEffectiveAmountForClaim(const std::string& name, uint160 claimId) const;
|
||||
CAmount getEffectiveAmountForClaimWithSupports(const std::string& name, uint160 claimId,
|
||||
std::vector<CSupportValue>& supports) const;
|
||||
|
||||
bool queueEmpty() const;
|
||||
bool supportEmpty() const;
|
||||
|
||||
@@ -58,8 +58,11 @@ struct Params {
|
||||
bool fPowNoRetargeting;
|
||||
int64_t nPowTargetSpacing;
|
||||
int64_t nPowTargetTimespan;
|
||||
/** how long it took claims to expire before the hard fork */
|
||||
int64_t nOriginalClaimExpirationTime;
|
||||
/** how long it takes claims to expire after the hard fork */
|
||||
int64_t nExtendedClaimExpirationTime;
|
||||
/** blocks before the hard fork that changed the expiration time */
|
||||
int64_t nExtendedClaimExpirationForkHeight;
|
||||
int64_t GetExpirationTime(int64_t nHeight) const {
|
||||
return nHeight < nExtendedClaimExpirationForkHeight ?
|
||||
|
||||
@@ -48,12 +48,12 @@ double GetDifficulty(const CBlockIndex* blockindex)
|
||||
double dDiff =
|
||||
(double)0x0000ffff / (double)(blockindex->nBits & 0x00ffffff);
|
||||
|
||||
while (nShift < 29)
|
||||
while (nShift < 31)
|
||||
{
|
||||
dDiff *= 256.0;
|
||||
nShift++;
|
||||
}
|
||||
while (nShift > 29)
|
||||
while (nShift > 31)
|
||||
{
|
||||
dDiff /= 256.0;
|
||||
nShift--;
|
||||
|
||||
+47
-12
@@ -7,6 +7,22 @@
|
||||
// Maximum block decrement that is allowed from rpc calls
|
||||
const int MAX_RPC_BLOCK_DECREMENTS = 50;
|
||||
|
||||
uint160 ParseClaimtrieId(const UniValue& v, std::string strName)
|
||||
{
|
||||
std::string strHex;
|
||||
if (v.isStr())
|
||||
strHex = v.get_str();
|
||||
if (!IsHex(strHex)) // Note: IsHex("") is false
|
||||
throw JSONRPCError(RPC_INVALID_PARAMETER, strName + " must be a 20-character hexadecimal string (not '" + strHex + "')");
|
||||
if (40 != strHex.length())
|
||||
throw JSONRPCError(RPC_INVALID_PARAMETER, strprintf("%s must be of length %d (not %d)", strName, 40, strHex.length()));
|
||||
|
||||
uint160 result;
|
||||
result.SetHex(strHex);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
UniValue getclaimsintrie(const UniValue& params, bool fHelp)
|
||||
{
|
||||
if (fHelp || params.size() > 0)
|
||||
@@ -61,7 +77,7 @@ UniValue getclaimsintrie(const UniValue& params, bool fHelp)
|
||||
__func__, itClaims->outPoint.hash.GetHex());
|
||||
claim.push_back(Pair("error", "No value found for claim"));
|
||||
}
|
||||
else if (coin->vout.size() < itClaims->outPoint.n || coin->vout[itClaims->outPoint.n].IsNull())
|
||||
else if (!coin->IsAvailable(itClaims->outPoint.n))
|
||||
{
|
||||
LogPrintf("%s: the specified txout of %s appears to have been spent\n", __func__, itClaims->outPoint.hash.GetHex());
|
||||
claim.push_back(Pair("error", "Txout spent"));
|
||||
@@ -137,7 +153,7 @@ bool getValueForClaim(const COutPoint& out, std::string& sValue)
|
||||
__func__, out.hash.GetHex());
|
||||
return true;
|
||||
}
|
||||
if (coin->vout.size() < out.n || coin->vout[out.n].IsNull())
|
||||
if(!coin->IsAvailable(out.n))
|
||||
{
|
||||
LogPrintf("%s: the specified txout of %s appears to have been spent\n", __func__, out.hash.GetHex());
|
||||
return true;
|
||||
@@ -367,18 +383,30 @@ UniValue getclaimbyid(const UniValue& params, bool fHelp)
|
||||
" \"amount\" (numeric) txout value\n"
|
||||
" \"effective amount\" (numeric) txout amount plus amount from all supports associated with the claim\n"
|
||||
" \"height\" (numeric) the height of the block in which this claim transaction is located\n"
|
||||
" \"supports\" (array of object) supports for this claim\n"
|
||||
" \"valid at height\" (numeric) the height at which the claim is valid\n"
|
||||
" [\n"
|
||||
" \"txid\" (string) the txid of the support\n"
|
||||
" \"n\" (numeric) the index of the support in the transaction's list of outputs\n"
|
||||
" \"height\" (numeric) the height at which the support was included in the blockchain\n"
|
||||
" \"valid at height\" (numeric) the height at which the support is valid\n"
|
||||
" \"amount\" (numeric) the amount of the support\n"
|
||||
" ]\n"
|
||||
"}\n"
|
||||
);
|
||||
|
||||
LOCK(cs_main);
|
||||
uint160 claimId;
|
||||
claimId.SetHex(params[0].get_str());
|
||||
uint160 claimId = ParseClaimtrieId(params[0], "Claim-id (parameter 1)");
|
||||
UniValue claim(UniValue::VOBJ);
|
||||
std::string name;
|
||||
CClaimValue claimValue;
|
||||
pclaimTrie->getClaimById(claimId, name, claimValue);
|
||||
if (claimValue.claimId == claimId)
|
||||
{
|
||||
std::vector<CSupportValue> supports;
|
||||
CAmount effectiveAmount = pclaimTrie->getEffectiveAmountForClaimWithSupports(
|
||||
name, claimValue.claimId, supports);
|
||||
|
||||
std::string sValue;
|
||||
getValueForClaim(claimValue.outPoint, sValue);
|
||||
claim.push_back(Pair("name", name));
|
||||
@@ -387,9 +415,20 @@ UniValue getclaimbyid(const UniValue& params, bool fHelp)
|
||||
claim.push_back(Pair("txid", claimValue.outPoint.hash.GetHex()));
|
||||
claim.push_back(Pair("n", (int) claimValue.outPoint.n));
|
||||
claim.push_back(Pair("amount", claimValue.nAmount));
|
||||
claim.push_back(Pair("effective amount",
|
||||
pclaimTrie->getEffectiveAmountForClaim(name, claimValue.claimId)));
|
||||
claim.push_back(Pair("effective amount", effectiveAmount));
|
||||
UniValue supportList(UniValue::VARR);
|
||||
BOOST_FOREACH(const CSupportValue& support, supports) {
|
||||
UniValue supportEntry(UniValue::VOBJ);
|
||||
supportEntry.push_back(Pair("txid", support.outPoint.hash.GetHex()));
|
||||
supportEntry.push_back(Pair("n", (int)support.outPoint.n));
|
||||
supportEntry.push_back(Pair("height", support.nHeight));
|
||||
supportEntry.push_back(Pair("valid at height", support.nValidAtHeight));
|
||||
supportEntry.push_back(Pair("amount", support.nAmount));
|
||||
supportList.push_back(supportEntry);
|
||||
}
|
||||
claim.push_back(Pair("supports", supportList));
|
||||
claim.push_back(Pair("height", claimValue.nHeight));
|
||||
claim.push_back(Pair("valid at height", claimValue.nValidAtHeight));
|
||||
}
|
||||
return claim;
|
||||
}
|
||||
@@ -488,10 +527,7 @@ UniValue getclaimsfortx(const UniValue& params, bool fHelp)
|
||||
);
|
||||
|
||||
LOCK(cs_main);
|
||||
|
||||
uint256 hash;
|
||||
hash.SetHex(params[0].get_str());
|
||||
|
||||
uint256 hash = ParseHashV(params[0], "txid (parameter 1)");
|
||||
UniValue ret(UniValue::VARR);
|
||||
|
||||
int op;
|
||||
@@ -717,8 +753,7 @@ UniValue getnameproof(const UniValue& params, bool fHelp)
|
||||
uint256 blockHash;
|
||||
if (params.size() == 2)
|
||||
{
|
||||
std::string strBlockHash = params[1].get_str();
|
||||
blockHash = uint256S(strBlockHash);
|
||||
blockHash = ParseHashV(params[1], "blockhash (optional parameter 2)");
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
File diff suppressed because it is too large.
Load diff
File diff suppressed because it is too large.
Load diff
@@ -34,10 +34,27 @@ public:
|
||||
|
||||
};
|
||||
|
||||
CMutableTransaction BuildTransaction(const uint256& prevhash)
|
||||
{
|
||||
CMutableTransaction tx;
|
||||
tx.nVersion = 1;
|
||||
tx.nLockTime = 0;
|
||||
tx.vin.resize(1);
|
||||
tx.vout.resize(1);
|
||||
tx.vin[0].prevout.hash = prevhash;
|
||||
tx.vin[0].prevout.n = 0;
|
||||
tx.vin[0].scriptSig = CScript();
|
||||
tx.vin[0].nSequence = std::numeric_limits<unsigned int>::max();
|
||||
tx.vout[0].scriptPubKey = CScript();
|
||||
tx.vout[0].nValue = 0;
|
||||
|
||||
return tx;
|
||||
}
|
||||
|
||||
BOOST_FIXTURE_TEST_SUITE(claimtriecache_tests, RegTestingSetup)
|
||||
|
||||
|
||||
BOOST_AUTO_TEST_CASE(merklehash_test)
|
||||
BOOST_AUTO_TEST_CASE(merkle_hash_single_test)
|
||||
{
|
||||
// check empty trie
|
||||
uint256 one(uint256S("0000000000000000000000000000000000000000000000000000000000000001"));
|
||||
@@ -50,7 +67,127 @@ BOOST_AUTO_TEST_CASE(merklehash_test)
|
||||
BOOST_CHECK(one == cc.getMerkleHash());
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(recursiveprune_test)
|
||||
BOOST_AUTO_TEST_CASE(merkle_hash_multiple_test)
|
||||
{
|
||||
CClaimValue unused;
|
||||
uint256 hash0(uint256S("0000000000000000000000000000000000000000000000000000000000000001"));
|
||||
uint160 hash160;
|
||||
CMutableTransaction tx1 = BuildTransaction(hash0);
|
||||
COutPoint tx1OutPoint(tx1.GetHash(), 0);
|
||||
CMutableTransaction tx2 = BuildTransaction(tx1.GetHash());
|
||||
COutPoint tx2OutPoint(tx2.GetHash(), 0);
|
||||
CMutableTransaction tx3 = BuildTransaction(tx2.GetHash());
|
||||
COutPoint tx3OutPoint(tx3.GetHash(), 0);
|
||||
CMutableTransaction tx4 = BuildTransaction(tx3.GetHash());
|
||||
COutPoint tx4OutPoint(tx4.GetHash(), 0);
|
||||
CMutableTransaction tx5 = BuildTransaction(tx4.GetHash());
|
||||
COutPoint tx5OutPoint(tx5.GetHash(), 0);
|
||||
CMutableTransaction tx6 = BuildTransaction(tx5.GetHash());
|
||||
COutPoint tx6OutPoint(tx6.GetHash(), 0);
|
||||
|
||||
uint256 hash1;
|
||||
hash1.SetHex("71c7b8d35b9a3d7ad9a1272b68972979bbd18589f1efe6f27b0bf260a6ba78fa");
|
||||
|
||||
uint256 hash2;
|
||||
hash2.SetHex("c4fc0e2ad56562a636a0a237a96a5f250ef53495c2cb5edd531f087a8de83722");
|
||||
|
||||
uint256 hash3;
|
||||
hash3.SetHex("baf52472bd7da19fe1e35116cfb3bd180d8770ffbe3ae9243df1fb58a14b0975");
|
||||
|
||||
uint256 hash4;
|
||||
hash4.SetHex("c73232a755bf015f22eaa611b283ff38100f2a23fb6222e86eca363452ba0c51");
|
||||
|
||||
BOOST_CHECK(pclaimTrie->empty());
|
||||
|
||||
CClaimTrieCache ntState(pclaimTrie, false);
|
||||
ntState.insertClaimIntoTrie(std::string("test"), CClaimValue(tx1OutPoint, hash160, 50, 100, 200));
|
||||
ntState.insertClaimIntoTrie(std::string("test2"), CClaimValue(tx2OutPoint, hash160, 50, 100, 200));
|
||||
|
||||
BOOST_CHECK(pclaimTrie->empty());
|
||||
BOOST_CHECK(!ntState.empty());
|
||||
BOOST_CHECK(ntState.getMerkleHash() == hash1);
|
||||
|
||||
ntState.insertClaimIntoTrie(std::string("test"), CClaimValue(tx3OutPoint, hash160, 50, 101, 201));
|
||||
BOOST_CHECK(ntState.getMerkleHash() == hash1);
|
||||
ntState.insertClaimIntoTrie(std::string("tes"), CClaimValue(tx4OutPoint, hash160, 50, 100, 200));
|
||||
BOOST_CHECK(ntState.getMerkleHash() == hash2);
|
||||
ntState.insertClaimIntoTrie(std::string("testtesttesttest"), CClaimValue(tx5OutPoint, hash160, 50, 100, 200));
|
||||
ntState.removeClaimFromTrie(std::string("testtesttesttest"), tx5OutPoint, unused);
|
||||
BOOST_CHECK(ntState.getMerkleHash() == hash2);
|
||||
ntState.flush();
|
||||
|
||||
BOOST_CHECK(!pclaimTrie->empty());
|
||||
BOOST_CHECK(pclaimTrie->getMerkleHash() == hash2);
|
||||
BOOST_CHECK(pclaimTrie->checkConsistency());
|
||||
|
||||
CClaimTrieCache ntState1(pclaimTrie, false);
|
||||
ntState1.removeClaimFromTrie(std::string("test"), tx1OutPoint, unused);
|
||||
ntState1.removeClaimFromTrie(std::string("test2"), tx2OutPoint, unused);
|
||||
ntState1.removeClaimFromTrie(std::string("test"), tx3OutPoint, unused);
|
||||
ntState1.removeClaimFromTrie(std::string("tes"), tx4OutPoint, unused);
|
||||
|
||||
BOOST_CHECK(ntState1.getMerkleHash() == hash0);
|
||||
|
||||
CClaimTrieCache ntState2(pclaimTrie, false);
|
||||
ntState2.insertClaimIntoTrie(std::string("abab"), CClaimValue(tx6OutPoint, hash160, 50, 100, 200));
|
||||
ntState2.removeClaimFromTrie(std::string("test"), tx1OutPoint, unused);
|
||||
|
||||
BOOST_CHECK(ntState2.getMerkleHash() == hash3);
|
||||
|
||||
ntState2.flush();
|
||||
|
||||
BOOST_CHECK(!pclaimTrie->empty());
|
||||
BOOST_CHECK(pclaimTrie->getMerkleHash() == hash3);
|
||||
BOOST_CHECK(pclaimTrie->checkConsistency());
|
||||
|
||||
CClaimTrieCache ntState3(pclaimTrie, false);
|
||||
ntState3.insertClaimIntoTrie(std::string("test"), CClaimValue(tx1OutPoint, hash160, 50, 100, 200));
|
||||
BOOST_CHECK(ntState3.getMerkleHash() == hash4);
|
||||
ntState3.flush();
|
||||
BOOST_CHECK(!pclaimTrie->empty());
|
||||
BOOST_CHECK(pclaimTrie->getMerkleHash() == hash4);
|
||||
BOOST_CHECK(pclaimTrie->checkConsistency());
|
||||
|
||||
CClaimTrieCache ntState4(pclaimTrie, false);
|
||||
ntState4.removeClaimFromTrie(std::string("abab"), tx6OutPoint, unused);
|
||||
BOOST_CHECK(ntState4.getMerkleHash() == hash2);
|
||||
ntState4.flush();
|
||||
BOOST_CHECK(!pclaimTrie->empty());
|
||||
BOOST_CHECK(pclaimTrie->getMerkleHash() == hash2);
|
||||
BOOST_CHECK(pclaimTrie->checkConsistency());
|
||||
|
||||
CClaimTrieCache ntState5(pclaimTrie, false);
|
||||
ntState5.removeClaimFromTrie(std::string("test"), tx3OutPoint, unused);
|
||||
|
||||
BOOST_CHECK(ntState5.getMerkleHash() == hash2);
|
||||
ntState5.flush();
|
||||
BOOST_CHECK(!pclaimTrie->empty());
|
||||
BOOST_CHECK(pclaimTrie->getMerkleHash() == hash2);
|
||||
BOOST_CHECK(pclaimTrie->checkConsistency());
|
||||
|
||||
CClaimTrieCache ntState6(pclaimTrie, false);
|
||||
ntState6.insertClaimIntoTrie(std::string("test"), CClaimValue(tx3OutPoint, hash160, 50, 101, 201));
|
||||
|
||||
BOOST_CHECK(ntState6.getMerkleHash() == hash2);
|
||||
ntState6.flush();
|
||||
BOOST_CHECK(!pclaimTrie->empty());
|
||||
BOOST_CHECK(pclaimTrie->getMerkleHash() == hash2);
|
||||
BOOST_CHECK(pclaimTrie->checkConsistency());
|
||||
|
||||
CClaimTrieCache ntState7(pclaimTrie, false);
|
||||
ntState7.removeClaimFromTrie(std::string("test"), tx3OutPoint, unused);
|
||||
ntState7.removeClaimFromTrie(std::string("test"), tx1OutPoint, unused);
|
||||
ntState7.removeClaimFromTrie(std::string("tes"), tx4OutPoint, unused);
|
||||
ntState7.removeClaimFromTrie(std::string("test2"), tx2OutPoint, unused);
|
||||
|
||||
BOOST_CHECK(ntState7.getMerkleHash() == hash0);
|
||||
ntState7.flush();
|
||||
BOOST_CHECK(pclaimTrie->empty());
|
||||
BOOST_CHECK(pclaimTrie->getMerkleHash() == hash0);
|
||||
BOOST_CHECK(pclaimTrie->checkConsistency());
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(recursive_prune_test)
|
||||
{
|
||||
CClaimTrieCacheTest cc(pclaimTrie);
|
||||
BOOST_CHECK_EQUAL(0, cc.cacheSize());
|
||||
|
||||
@@ -332,4 +332,23 @@ BOOST_AUTO_TEST_CASE(rpc_convert_values_generatetoaddress)
|
||||
BOOST_CHECK_EQUAL(result[2].get_int(), 9);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(rpc_claimtrie_validation)
|
||||
{
|
||||
// std::runtime_error: parameter 2 must be hexadecimal string (not 'not_hex')
|
||||
BOOST_CHECK_THROW(CallRPC("getnameproof test not_hex"), runtime_error);
|
||||
// std::runtime_error: Block not found
|
||||
BOOST_CHECK_THROW(CallRPC("getnameproof test aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"), runtime_error);
|
||||
// Generate a block to validate the NO_THROW case.
|
||||
UniValue result = CallRPC("generate 1");
|
||||
BOOST_CHECK_NO_THROW(CallRPC(string("getnameproof test ") + result[0].get_str()));
|
||||
|
||||
BOOST_CHECK_THROW(CallRPC("getclaimsfortx not_hex"), runtime_error);
|
||||
BOOST_CHECK_NO_THROW(CallRPC("getclaimsfortx aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"));
|
||||
|
||||
BOOST_CHECK_THROW(CallRPC("getclaimbyid not_hex"), runtime_error);
|
||||
// Wrong length.
|
||||
BOOST_CHECK_THROW(CallRPC("getclaimbyid a"), runtime_error);
|
||||
BOOST_CHECK_NO_THROW(CallRPC("getclaimbyid aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"));
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_SUITE_END()
|
||||
+3
-3
@@ -455,9 +455,9 @@ void PrintExceptionContinue(const std::exception* pex, const char* pszThread)
|
||||
boost::filesystem::path GetDefaultDataDir()
|
||||
{
|
||||
namespace fs = boost::filesystem;
|
||||
// Windows < Vista: C:\Documents and Settings\Username\Application Data\Bitcoin
|
||||
// Windows >= Vista: C:\Users\Username\AppData\Roaming\Bitcoin
|
||||
// Mac: ~/Library/Application Support/Bitcoin
|
||||
// Windows < Vista: C:\Documents and Settings\Username\Application Data\lbrycrd
|
||||
// Windows >= Vista: C:\Users\Username\AppData\Roaming\lbrycrd
|
||||
// Mac: ~/Library/Application Support/lbrycrd
|
||||
// Unix: ~/.lbrycrd
|
||||
#ifdef WIN32
|
||||
// Windows
|
||||
|
||||
Reference in new issue
Block a user