Commit graph

11812 commits

Author SHA1 Message Date
practicalswift 906bee8e5f Use bracket syntax includes ("#include <foo.h>") 2018-06-06 11:09:05 +02:00
Matt Corallo 25bc9615b7 Document validationinterace callback blocking deadlock potential. 2018-06-05 16:41:25 -04:00
Wladimir J. van der Laan a589f536b5
Merge #13288: rpc: Remove the need to include rpc/blockchain.cpp in order to put GetDifficulty under test
ebec7317ca Drop the chain argument to GetDifficulty (Ben Woosley)

Pull request description:

  By dropping the chain argument to `GetDifficulty`. `GetDifficulty` was called in two ways:
  * with a guaranteed non-null blockindex
  * with no argument

  Change the latter case to be provided `chainActive.Tip()` explicitly.

  Introduced in: #11748

Tree-SHA512: f2c97014be185f3e3de92db15848548650e4a67fab20a41bcfa851c5c63c245915cbe9380f84d9da2081e8756d31a41de417db1d35cfecf41ddb4f25070eb525
2018-06-05 20:38:43 +02:00
Wladimir J. van der Laan 264efdca74
Merge #13367: qa: Increase includeconf test coverage
fa4760fbb3 qa: Increase includeconf test coverage (MarcoFalke)

Pull request description:

  This adds some missing `return false` for error conditions and adds test coverage [1] for those.

  Also, extend recursion warning when the chain was set in one of the includeconfs.

  [1] See the red lines in https://marcofalke.github.io/btc_cov/total.coverage/src/util.cpp.gcov.html for missing coverage.

Tree-SHA512: d32563c9bb277879895a173e699034db5ecdb4061a1ec8890c566d61e36a09efa5eda19a029baf952ff6d568f8b9684a13a0bb90827850075470975e2088fee4
2018-06-05 19:57:31 +02:00
Wladimir J. van der Laan f0fd39f376
Merge #13269: refactoring: Drop UpdateTransaction in favor of UpdateInput
6aa33feadb Drop UpdateTransaction in favor of UpdateInput (Ben Woosley)

Pull request description:

  Updating the input explicitly requires the caller to present a mutable
  input, which more clearly communicates the effects and intent of the call
  (and, often, the enclosing loop).

  In most cases, this input is already immediately available and need not be
  looked up.

Tree-SHA512: 8c7914a8b7ae975d8ad0e9d760e3c5da65776a5f79d060b8ffb6b3ff7a32235f71ad705f2185b368d9263742d7796bb562395d22b806d90e8502d8c496011e57
2018-06-05 19:06:16 +02:00
MarcoFalke 2140f6cbc5
Merge #13351: wallet: Prevent segfault when sending to unspendable witness
fa36aa7965 wallet: Prevent segfault when sending to unspendable witness (MarcoFalke)

Pull request description:

  Previously we wouldn't care about the `txnouttype`, but after 4e91820531 we `switch` on the type.

Tree-SHA512: 6b597aba80cb43881671ad7b3a4ad97753864e8005a05c23fdd8ee79953483c08f241b5c392a9b494298eadc5cfba895b0480d916ef4f11d122fd6196f31b84a
2018-06-05 11:38:09 -04:00
Ben Woosley 2acd1d6716
Drop uint 256 not operator
All the other operators are integer or bit operations, and this is unused
apart from tests.
2018-06-05 02:16:24 -07:00
Jim Posen ec3073a274 index: Move index DBs into index/ directory. 2018-06-04 19:22:30 -07:00
Jim Posen 89eddcd365 index: Remove TxIndexDB from public interface of TxIndex. 2018-06-04 19:22:28 -07:00
Jim Posen 2318affd27 MOVEONLY: Move BaseIndex to its own file. 2018-06-04 19:22:26 -07:00
Jim Posen f376a49241 index: Generalize logged statements in BaseIndex. 2018-06-04 19:22:24 -07:00
Jim Posen 61a1226d87 index: Extract logic from TxIndex into reusable base class. 2018-06-04 19:22:23 -07:00
Jim Posen e5af5fc6fb db: Make reusable base class for index databases. 2018-06-04 19:22:21 -07:00
Jim Posen 9b0ec1a7f9 db: Remove obsolete methods from CBlockTreeDB. 2018-06-04 19:22:20 -07:00
Cory Fields 0231ef6c6d cli: Ignore libevent warnings 2018-06-04 14:55:00 -04:00
Pieter Wuille 57ba401abc Enable double-SHA256-for-64-byte code on 32-bit x86 2018-06-04 11:30:34 -07:00
Giulio Lombardo 989c8990bb Rename “OS X” to the newer “macOS” convention 2018-06-04 13:04:04 +02:00
Wladimir J. van der Laan 0de7cc848e
Merge #13191: Specialized double-SHA256 with 64 byte inputs with SSE4.1 and AVX2
4defdfab94 [MOVEONLY] Move unused Merkle branch code to tests (Pieter Wuille)
4437d6e1f3 8-way AVX2 implementation for double SHA256 on 64-byte inputs (Pieter Wuille)
230294bf5f 4-way SSE4.1 implementation for double SHA256 on 64-byte inputs (Pieter Wuille)
1f0e7ca09c Use SHA256D64 in Merkle root computation (Pieter Wuille)
d0c9632883 Specialized double sha256 for 64 byte inputs (Pieter Wuille)
57f34630fb Refactor SHA256 code (Pieter Wuille)
0df017889b Benchmark Merkle root computation (Pieter Wuille)

Pull request description:

  This introduces a framework for specialized double-SHA256 with 64 byte inputs. 4 different implementations are provided:
  * Generic C++ (reusing the normal SHA256 code)
  * Specialized C++ for 64-byte inputs, but no special instructions
  * 4-way using SSE4.1 intrinsics
  * 8-way using AVX2 intrinsics

  On my own system (AVX2 capable), I get these benchmarks for computing the Merkle root of 9001 leaves (supported lengths / special instructions / parallellism):
  * 7.2 ms with varsize/naive/1way (master, non-SSE4 hardware)
  * 5.8 ms with size64/naive/1way (this PR, non-SSE4 capable systems)
  * 4.8 ms with varsize/SSE4/1way (master, SSE4 hardware)
  * 2.9 ms with size64/SSE4/4way (this PR, SSE4 hardware)
  * 1.1 ms with size64/AVX2/8way (this PR, AVX2 hardware)

Tree-SHA512: efa32d48b32820d9ce788ead4eb583949265be8c2e5f538c94bc914e92d131a57f8c1ee26c6f998e81fb0e30675d4e2eddc3360bcf632676249036018cff343e
2018-06-04 12:11:53 +02:00
practicalswift f41d339b78 bench: Use non-throwing ParseDouble(...) instead of throwing boost::lexical_cast<double>(...) 2018-06-03 21:30:39 +02:00
MarcoFalke fa4760fbb3
qa: Increase includeconf test coverage 2018-06-01 13:24:50 -04:00
Jonas Schnelli 343d4e44ef
Merge #13058: [wallet] createwallet RPC - create new wallet at runtime
f7e153e95 [wallets] [docs] Add release notes for createwallet RPC. (John Newbery)
32167e830 [wallet] [tests] Add tests for `createwallet` RPC. (John Newbery)
942131774 [wallet] [rpc] Add `createwallet` RPC (John Newbery)

Pull request description:

  Adds a `createwallet` RPC to dynamically create a new wallet at runtime.

  Includes tests and release notes.

Tree-SHA512: e0d89e3ae498234e9db5b827c56804cbab64f18a1875e2b5e676172c110278ea1b9e93a8a61b8dd80e2f2a691490bf229e923e4ccb284a1d3e420b8317815866
2018-06-01 10:46:45 +02:00
Wladimir J. van der Laan 0b1c0c462e
Merge #13355: Fix "gmake check" under OpenBSD 6.3 (probably *BSD): Avoid using GNU grep specific regexp handling
db56755ca4 Fix "gmake check" under OpenBSD 6.3 (probably *BSD): Avoid using GNU grep specific regexp handling (practicalswift)

Pull request description:

  Fixes #13337 (!)

  GNU grep and BSD grep differs in the way they handle regexps when extended regular expressions are not enabled via the `-E` flag:

  ```
  $ grep --version | head -1
  grep (GNU grep) 3.1
  $ echo "BOOST_FIXTURE_TEST_SUITE(foo)" | grep "BOOST_FIXTURE_TEST_SUITE(\|BOOST_AUTO_TEST_SUITE("
  BOOST_FIXTURE_TEST_SUITE(foo)
  $
  ```

  ```
  $ grep --version | head -1
  grep version 0.9
  $ echo "BOOST_FIXTURE_TEST_SUITE(foo)" | grep "BOOST_FIXTURE_TEST_SUITE(\|BOOST_AUTO_TEST_SUITE("
  $
  ```

  The portable way to do it is:

  ```
  $ echo "BOOST_FIXTURE_TEST_SUITE(foo)" | grep -E "(BOOST_FIXTURE_TEST_SUITE\\(|BOOST_AUTO_TEST_SUITE\\()"
  BOOST_FIXTURE_TEST_SUITE(foo)
  $
  ```

Tree-SHA512: d83c78f34421504dd8efc3921c98527f499045b702bd34715a5bc78e04ef2a5f49f601a55ad08632e870f137b1edada94a3f530291bc9107d8d6b16fe11e640b
2018-06-01 10:08:53 +02:00
John Newbery f7e153e95f [wallets] [docs] Add release notes for createwallet RPC. 2018-05-31 17:10:20 -04:00
MarcoFalke 24f7011841
Merge #13349: bench: Don't return a bool from main
493a166948 bench: Don't return a bool from main (Wladimir J. van der Laan)

Pull request description:

  Return `1` from `main()` on error, not the bool `false` (introduced in #13112). This is the correct value to return on error, and also shuts up a clang warning.

Tree-SHA512: 52a0f1b2f6ae2697555f71ee2019ce657046f7f379f1f4faf3cce9d5f3fb21fcdc43a4c84895a2a8b6929997ba70bbe87c231f2f9553215b84c22333810d58d9
2018-05-31 05:14:18 -04:00
Wladimir J. van der Laan 36fc8052f6
Merge #13309: Directly operate with CMutableTransaction in SignSignature
6b8b63af14 Generic TransactionSignatureCreator works with both CTransaction and CMutableTransaction (Martin Ankerl)

Pull request description:

  Refactored `TransactionSignatureCreator` into a templated `GenericTransactionSignatureCreator` that works with both `CMutableTransaction` and `CTransaction`.

  The advantage is that now in `SignSignature`, the `MutableTransactionSignatureCreator` can now operate directly with the `CMutableTransaction` without the need to copy the data into a `CTransaction`.

  Running all unit tests brings a very noticable speedup on my machine:

      48.4 sec before this change
      36.4 sec with this change
      --------
      12.0 seconds saved

  running only `--run_test=transaction_tests/test_big_witness_transaction`:

      16.7 sec before this change
       5.9 sec with this change
      --------
      10.8 seconds saved

  This relates to my first attempt with the const_cast hack #13202, and to the slow unit test issue #10026.

  Also see #13050 which modifies the tests but not the production code (like this PR) to get a speedup.

Tree-SHA512: 2cff0e9699f484f26120a40e431a24c8bc8f9e780fd89cb0ecf20c5be3eab6c43f9c359cde244abd9f3620d06c7c354e3b9dd3da41fa2ca1ac1e09386fea25fb
2018-05-31 10:40:11 +02:00
practicalswift db56755ca4 Fix "gmake check" under OpenBSD 6.3 (probably *BSD): Avoid using GNU grep specific regexp handling 2018-05-31 10:30:38 +02:00
Wladimir J. van der Laan 493a166948 bench: Don't return a bool from main
Return `EXIT_SUCCESS` from `main()` on error, not the bool `false`
(introduced in #13112). This is the correct value to return on error,
and also shuts up a clang warning.

Also add a final return for clarity.
2018-05-31 07:22:33 +02:00
MarcoFalke 472fe8a2ce
Merge #13069: docs: Fix typos
d8c4998f31 Fix typos (practicalswift)

Pull request description:

  Fix typos.

Tree-SHA512: 9af52a9799e6892b162e4aa1bcd6585502e10650b8aced59e7346dbb2f08544330081eb79328255fad1d358c095507956e049d354c4383b6965d4d5a7d635425
2018-05-30 16:02:09 -04:00
MarcoFalke fa36aa7965
wallet: Prevent segfault when sending to unspendable witness 2018-05-30 15:46:06 -04:00
MarcoFalke 61fcef0f89
Merge #13112: Throw an error for unknown args
903055730b Test gArgs erroring on unknown args (Andrew Chow)
4f8704d57f Give an error and exit if there are unknown parameters (Andrew Chow)
174f7c8080 Use a struct for arguments and nested map for categories (Andrew Chow)

Pull request description:

  Following #13190, gArgs is aware of all of the command line arguments. This PR has gArgs check whether the arguments provided are actually valid arguments. When an unknown argument is encountered, an error is printed to stderr and the program exist.

  Since gArgs is used for everything that has command line arguments, `bitcoind`, `bitcoin-cli`, `bitcoin-qt`, `bitcoin-tx`, and `bench_bitcoin` are all effected by this change and all now have the same argument checking behavior.

  Closes #1044

Tree-SHA512: 388201319a7d6493204bb5433da47e8e6c8266882e809f6df45f86d925f1f320f2fd13edb3e57ffc6a37415dfdfc689f83929452bca224229783accb367032e7
2018-05-30 13:43:07 -04:00
Wladimir J. van der Laan c4cc8d9930
Merge #13252: Wallet: Refactor ReserveKeyFromKeyPool for safety
4b62bdf513 Wallet: Refactor ReserveKeyFromKeyPool for safety (Ben Woosley)

Pull request description:

  ReserveKeyFromKeyPool's previous behaviour is to set nIndex to -1 if the keypool is
  empty, OR throw an exception for technical failures. Instead, we now return false
  if the keypool is empty, true if the operation succeeded.

  This is to make failure more easily detectable by calling code.

Tree-SHA512: 753f057ad13bd4c28d121f426bf0967ed72b827d97fb24582f9326ec60072abc5482e3db69ccada7c5fc66de9957fc59098432dd223fc4116991cab44c6d7aef
2018-05-30 19:39:17 +02:00
Andrew Chow 4f8704d57f Give an error and exit if there are unknown parameters
If an unknown option is given via either the command line args or
the conf file, throw an error and exit

Update tests for ArgsManager knowing args

Ignore unknown options in the config file for bitcoin-cli

Fix tests and bitcoin-cli to match actual options used
2018-05-30 11:27:50 -04:00
Andrew Chow 174f7c8080 Use a struct for arguments and nested map for categories
Instead of a single map with the category and name as the key,
make m_available_args contain maps. The key will be the category and
the value is a map which actually contains the arguments for that
category. The nested map's key is the argument name, while the value
is a struct that contains the help text and whether the argument is
a debug only argument.
2018-05-30 11:09:15 -04:00
Wladimir J. van der Laan fd96d54f39
Merge #13194: Remove template matching and pseudo opcodes
c814e2e7e8 Remove template matching and pseudo opcodes (Pieter Wuille)

Pull request description:

  The current code contains a rather complex script template matching engine, which is only used for 3 particular script types (P2PK, P2PKH, multisig). The first two of these are trivial to match for otherwise, and a specialized matcher for multisig is both more compact and more efficient than a generic one.

  The goal is being more flexible, so that for example larger standard multisigs inside SegWit outputs are easier to implement.

  As a side-effect, it also gets rid of the pseudo opcodes hack.

Tree-SHA512: 643b409c5c36821519f613a43efd399af0ec99b6131f35cd4024decfb2d483d719e0e921cd088bc9832a7ac797cb4a6b1158b8574c82f7fbebb75f1b31b359df
2018-05-30 16:50:43 +02:00
Martin Ankerl 6b8b63af14 Generic TransactionSignatureCreator works with both CTransaction and CMutableTransaction
Templated version so that no copying of CMutableTransaction into a CTransaction is
necessary. This speeds up the test case transaction_tests/test_big_witness_transaction
from 7.9 seconds to 3.1 seconds on my machine.
2018-05-30 16:01:36 +02:00
Wladimir J. van der Laan 3d4fa83587 Stop translating command line options
Many options are extremely technical, and refer internals, making it
difficult to translate usefully. This came up in discussion of e.g.
 #10949. If a message is not understood by translators (which are
typically end-users, not developers) they'll either translate it
literally, making it harder to understand instead of easier, with the
added drawback of the user no longer being able to google it.

Also the translation was only working for bitcoin-qt as with
the console programs, there is no translation backend. So it was
injecting never-used translation messages for bitcoin-cli, -tx.

For these reasons, stop translating options help completely. This should
not affect the output **in any way** except for bitcoin-qt when a
non-English language is configured in the locale.

This implements #10962.
2018-05-30 14:23:35 +02:00
Karl-Johan Alm e9a1881b90
refactor: add a function for determining if a block is pruned or not 2018-05-30 12:23:44 +09:00
Pieter Wuille c814e2e7e8 Remove template matching and pseudo opcodes
The current code contains a rather complex script template matching engine,
which is only used for 3 particular script types (P2PK, P2PKH, multisig).
The first two of these are trivial to match for otherwise, and a specialized
matcher for multisig is both more compact and more efficient than a generic
one.

The goal is being more flexible, so that for example larger standard multisigs
inside SegWit outputs are more easy to implement.

As a side-effect, it also gets rid of the pseudo opcodes hack.
2018-05-29 14:40:18 -07:00
Pieter Wuille 4defdfab94 [MOVEONLY] Move unused Merkle branch code to tests 2018-05-29 14:20:12 -07:00
Pieter Wuille 4437d6e1f3 8-way AVX2 implementation for double SHA256 on 64-byte inputs 2018-05-29 14:18:05 -07:00
Pieter Wuille 230294bf5f 4-way SSE4.1 implementation for double SHA256 on 64-byte inputs 2018-05-29 14:18:05 -07:00
Pieter Wuille 1f0e7ca09c Use SHA256D64 in Merkle root computation 2018-05-29 14:17:07 -07:00
Pieter Wuille d0c9632883 Specialized double sha256 for 64 byte inputs 2018-05-29 14:05:00 -07:00
MarcoFalke fa7a6cf1b3
policy: Treat segwit as always active 2018-05-29 16:49:52 -04:00
Wladimir J. van der Laan 70d3541313
Merge #13134: net: Add option -enablebip61 to configure sending of BIP61 notifications
87fe292d89 doc: Mention disabling BIP61 in bips.md (Wladimir J. van der Laan)
fe16dd8226 net: Add option `-enablebip61` to configure sending of BIP61 notifications (Wladimir J. van der Laan)

Pull request description:

  This commit adds a boolean option `-peersendreject`, defaulting to `1`, that can be used to disable the sending of [BIP61](https://github.com/bitcoin/bips/blob/master/bip-0061.mediawiki) `reject` messages. This functionality has been requested for various reasons:

  - security (DoS): reject messages can reveal internal state that can be used to target certain resources such as the mempool more easily.

  - bandwidth: a typical node sends lots of reject messages; this counts against upstream bandwidth. Also the reject messages tend to be larger than the message that was rejected.

  On the other hand, reject messages can be useful while developing client software (I found them indispensable while creating bitcoin-submittx), as well as for our own test cases, so whatever the default becomes on the long run, IMO the functionality should be retained as option. But that's a discussion for later, for now it's simply a node operator decision.

  Also adds a RPC test that checks the functionality.

Tree-SHA512: 9488cc53e13cd8e5c6f8eb472a44309572673405c1d1438c3488f627fae622c95e2198bde5ed7d29e56b948e2918bf1920239e9f865889f4c37c097c37a4d7a9
2018-05-29 15:31:54 +02:00
Wladimir J. van der Laan 3fd0c2336a
Merge #13273: Qt/Bugfix: fix handling default wallet with no name
13c3a659c0 Qt/Bugfix: fix handling default wallet with no name (João Barbosa)

Pull request description:

  If one loads a wallet via RPC (`loadwallet w2`), then select w2, select back to the default wallet (which is an empty string), that default wallet cannot be access through the RPC console because the current code only points to the wallet endpoint if the wallet name is not empty.

  This is a quick fix that reenables accessing the default wallet in case an additional wallet has been loaded.

  Using "" for the default wallet may not be ideal in other cases and it may make more sense to change it at a deeper level (wallet.cpp). See discussion here which where the reasons for the current behaviour in master:
  https://github.com/bitcoin/bitcoin/pull/11687#issuecomment-370862718

  @jnewbery @promag @ryanofsky

Tree-SHA512: 74b935886b4e4a6033a2f5e1f44bb69a252e31f4021e19a2054445a8e3e4db1d8ee256290850a84d8569d2d0e21412fce0170e7f0e881259156057587181ee05
2018-05-29 15:24:26 +02:00
Wladimir J. van der Laan 56fe3dc235
Merge #13142: Separate IsMine from solvability
c004ffc9b4 Make handling of invalid in IsMine more uniform (Pieter Wuille)
a53f0feff8 Add some checks for invalid recursion in IsMine (Pieter Wuille)
b5802a9f5f Simplify IsMine logic (Pieter Wuille)
4e91820531 Make IsMine stop distinguishing solvable/unsolvable (Pieter Wuille)
6d714c3419 Make coincontrol use IsSolvable to determine solvability (Pieter Wuille)

Pull request description:

  Our current `IsMine` logic does several things with outputs:
  * Determine "spendability" (roughly corresponding to "could we sign for this")
  * Determine "watching" (is this an output directly or indirectly a watched script)
  * Determine invalidity (is this output definitely not legally spendable, detecting accidental uncompressed pubkeys in witnesses)
  * Determine "solvability" (would we be able to sign for this ignoring the fact that we may be missing some private keys).

  The last item (solvability) is mostly unrelated and only rarely needed (there is just one instance, inside the wallet's coin control logic). This PR changes that instance to use the separate `IsSolvable` function, and stop `IsMine` from distinguishing between solvable and unsolvable.

  As an extra, this also simplifies the `IsMine` logic and adds some extra checks (which wouldn't be hit unless someone adds already invalid scripts to their wallet).

Tree-SHA512: 95a6ef75fbf2eedc5ed938c48a8e5d77dcf09c933372acdd0333129fb7301994a78498f9aacce2c8db74275e19260549dd67a83738e187d40b5090cc04f33adf
2018-05-29 15:12:16 +02:00
Wladimir J. van der Laan a315b79ad2
Merge #13275: Qt: use [default wallet] as name for wallet with no name
2885c131b6 Qt: use [default wallet] as name for wallet with no name (Jonas Schnelli)

Pull request description:

  Loading a wallet from a state where only the default wallet was active results in using an empty string for the initial/default wallet name.

  This is a GUI only quick-fix that overrides wallet(s) with name "" to "[default wallet]". Does not affect `getwalletinfo` or `listwallets`.

  Also, unsure if it should be fixed at a deeper level and if – instead of [default wallet] – it should use `wallet.dat` (the filename of the default wallet).

Tree-SHA512: 1d50dbb200b23df5ac53ce15aeb6453af4da354d6e6e53fe33ff075b477493254d6028b6d3569a7804b1aa616cb9a988a53de818937e37cdcb19cb70a90e2a88
2018-05-28 17:10:36 +02:00
Wladimir J. van der Laan 14a4b49663
Merge #13300: qa: Initialize lockstack to prevent null pointer deref
fa9da85b7c qa: Initialize lockstack to prevent null pointer deref (MarcoFalke)

Pull request description:

  It is currently impossible to call debug methods such as `AssertLock(Not)Held` on a thread without running into undefined behavior, unless a lock was pushed on the stack in this thread.

  Initializing the global `lockstack` seems to fix both issues.

Tree-SHA512: 8cb76b22cb31887ddf15742fdc790f01e8f04ed837367d0fd4996535748d124342e8bfde68952b903847b96ad33406c64907a53ebab9646f78d97fa4365c3061
2018-05-28 16:28:46 +02:00
Wladimir J. van der Laan f5a7733ff7
Merge #13306: build: split warnings out of CXXFLAGS
9e305b56f5 build: split warnings out of CXXFLAGS (Cory Fields)

Pull request description:

  CXXFLAGS should not be modified anyway. Also, this will enable us to selectively disable warnings.

  As discussed with @sipa on IRC. Intention is to be able to filter out warnings from leveldb code so that we can be more aggressive with what we enable.

Tree-SHA512: 1bf686250f7a59c0aff04371f87c5db4e8f5bde604c6ab75e568326fb6d7733f26b113fa52dc1c836fa10baa76770d479a0e5f82a4a1905947dd7f245e0560f4
2018-05-28 16:01:48 +02:00
John Newbery 9421317740 [wallet] [rpc] Add createwallet RPC
Add a `createwallet` RPC to allow wallets to be created dynamically at
runtime. This functionality is currently only available through RPC and
newly created wallets will not be displayed in the GUI.
2018-05-25 12:10:21 -04:00
João Barbosa 54c3bb4cf8 wallet: Unlock spent outputs 2018-05-25 14:27:58 +01:00
Pieter Wuille c004ffc9b4 Make handling of invalid in IsMine more uniform 2018-05-24 10:29:02 -07:00
Wladimir J. van der Laan f8be434133
Merge #13284: gui: fix visual "overflow" of amount input.
5f3cbde9de Increased max width of amount field to prevent number overflow bug. (Brandon Ruggles)

Pull request description:

  Fixes #13231.

  I was able to reproduce this bug within my own Fedora 27 VM. Following @jonasschnelli's advice, I first tried to change `setAlignment(Qt::AlignRight);` to `setAlignment(Qt::AlignLeft);`, however, I realized that this wouldn't fix the underlying overflow problem, as it would only make it easier to see the most significant digits under certain scenarios. The reason for the overflow is that Fedora uses plus and minus buttons on the Qt spin box class, rather than up and down arrows, which is what happens on **most** other operating systems. These plus and minus buttons take up more width, and therefore provide less space for text.

  The solution I went with was the second suggestion by @jonasschnelli, which was to just increase the maximum width of the amount box. After some experimentation, 240 seemed to be the smallest max width that would allow as many digits as one would want in the amount box without overflow, even with the plus and minus buttons in Fedora.

  Please let me know if there are any issues with this PR and I will work to fix them. Thank you!

Tree-SHA512: 155f34cec74af46ec1fe723a5241798d8e15607a4e1cdc493014dcc0ae9818a001c7901831168b5f26a6953ec5a992e4a67c57db1ad377bcf10f12941688ee93
2018-05-24 15:52:21 +02:00
MarcoFalke 536120ec39
Merge #13291: test: Don't include torcontrol.cpp into the test file
97c112d4ca Declare TorReply parsing functions in torcontrol_tests (Ben Woosley)

Pull request description:

  These methods are standalone string parsing methods which were included
  into test via an include of torcontrol.cpp, which is bad practice.

  ~~Splitting them out reveals that they were the only torcontrol.cpp
  methods under test, so the test file is renamed tor_reply_tests.cpp.~~

  Introduced in #10408

Tree-SHA512: 8ff11a9c900a88f910a73dfe16f43581a567e9d60e9298a8a963fc9dd7cffb4d97a644da677610aafb7d89f1dd1cede9afeae2c6344305e021a9a322dbcea0ac
2018-05-24 09:09:35 -04:00
MarcoFalke a9b6957383
Merge #13314: Fix FreeBSD build by including utilstrencodings.h
c865ee1e73 Fix FreeBSD build by including utilstrencodings.h (Wladimir J. van der Laan)

Pull request description:

  `random.cpp` needs to explicitly include `utilstrencodings.h` to get `ARRAYLEN`. This fixes the FreeBSD build.

  This was broken in 84f41946b9 (#13236).

Tree-SHA512: bdc2a28411ae217e40697c0315ef5a37cc2f5b6bc7bbde16684fb7343d1c1c620d67777a88e609a2190115edb08b823cfb5d31ed16356a7cb0d00c3b6f877c0e
2018-05-24 09:04:38 -04:00
Wladimir J. van der Laan 6378eef18f
Merge #13063: Use shared pointer to retain wallet instance
80b4910f7d wallet: Use shared pointer to retain wallet instance (João Barbosa)

Pull request description:

  Currently there are 3 places where it makes sense to retain a wallet shared pointer:
   - `vpwallets`;
   - `interfaces::Wallet` interface instance - used by the UI;
   - wallet RPC functions - given by `GetWalletForJSONRPCRequest`.

  The way it is now it is possible to have, for instance, listunspent RPC and in parallel unload the wallet (once #13111 is merged) without blocking. Once the RPC finishes, the shared pointer will release the wallet.

  It is also possible to get all existing wallets without blocking because the caller keeps a local list of shared pointers.

  This is mostly relevant for wallet unloading.

  This PR replaces #11402.

Tree-SHA512: b7e37c7e1ab56626085afe2d40b1628e8d4f0dbda08df01b7e618ecd2d894ce9b83d4219443f444ba889096286eff002f163cb0a48f37063b62e9ba4ccfa6cce
2018-05-24 11:58:41 +02:00
Wladimir J. van der Laan c865ee1e73 Fix FreeBSD build by including utilstrencodings.h
`random.cpp` needs to explicitly include `utilstrencodings.h` to get
`ARRAYLEN`. This fixes the FreeBSD build.

This was broken in 84f41946b9.
2018-05-24 09:51:47 +02:00
Wladimir J. van der Laan 7f4db9a7c3
Merge #13151: net: Serve blocks directly from disk when possible
0bf431870e net: Serve blocks directly from disk when possible (Wladimir J. van der Laan)

Pull request description:

  In `ProcessGetBlockData`, send the block data directly from disk if type MSG_WITNESS_BLOCK is requested. This is a valid shortcut as the on-disk format matches the network format.

  This is expected to increase performance because a deserialization and subsequent serialization roundtrip is avoided.

Tree-SHA512: 9a9500b4c1354eaae1a6f1c6ef2416c1c1985029852589266f3a70e808f6c7482c135e9ab251a527566935378ab7c32dba4ed43ba5451e802d8e72b77d1ba472
2018-05-23 19:51:28 +02:00
Wladimir J. van der Laan 3c2a41a9fc
Merge #13011: Cache witness hash in CTransaction
fac1223a56 Cache witness hash in CTransaction (MarcoFalke)
faab55fbb1 Make CMutableTransaction constructor explicit (MarcoFalke)

Pull request description:

  This speeds up:
  * compactblocks (v2)
  * ATMP
  * validation and miner (via `BlockWitnessMerkleRoot`)
  * sigcache (see also unrelated #13204)
  * rpc and rest (nice, but irrelevant)

  This presumably slows down rescan, which uses a `CTransaction` and its `GetHash`, but never uses the `GetWitnessHash`. The slow down is proportional to the number of witness transactions in the rescan window. I.e. early in the chain there should be no measurable slow down. Later in the chain, there should be a slow down, but acceptable given the speedups in the modules mentioned above.

Tree-SHA512: 443e86acfcceb5af2163e68840c581d44159af3fd1fce266cab3504b29fcd74c50812b69a00d41582e7e1c5ea292f420ce5e892cdfab691da9c24ed1c44536c7
2018-05-23 19:26:18 +02:00
Wladimir J. van der Laan b9551d3663
Merge #10757: RPC: Introduce getblockstats to plot things
41d0476f62 Tests: Add data file (Anthony Towns)
4cbfb6aad9 Tests: Test new getblockstats RPC (Jorge Timón)
35e77a0288 RPC: Introduce getblockstats (Jorge Timón)
cda8e36f01 Refactor: RPC: Separate GetBlockChecked() from getblock() (Jorge Timón)

Pull request description:

  It returns per block statistics about several things. It should be easy to add more if people think of other things to add or remove some if I went too far (but once written, why not keep it? EDIT: answer: not to test or maintain them).

  The currently available options are: minfee,maxfee,totalfee,minfeerate,maxfeerate,avgfee,avgfeerate,txs,ins,outs (EDIT: see updated list in the rpc call documentation)

  For the x axis, one can use height or block.nTime (I guess I could add mediantime if there's interest [EDIT: nobody showed interest but I implemented mediantime nonetheless, in fact there's no distinction between x or y axis anymore, that's for the caller to judge]).

  To calculate fees, -txindex is required.

Tree-SHA512: 2b2787a3c7dc4a11df1fce62c8a4c748f5347d7f7104205d5f0962ffec1e0370c825b49fd4d58ce8ce86bf39d8453f698bcd46206eea505f077541ca7d59b18c
2018-05-23 19:00:48 +02:00
practicalswift e56771365b Do not use uppercase characters in source code filenames 2018-05-23 16:07:37 +02:00
Cory Fields 9e305b56f5 build: split warnings out of CXXFLAGS
CXXFLAGS should not be modified anyway. Also, this will enable us to
selectively disable warnings.
2018-05-22 17:47:11 -04:00
Jorge Timón 35e77a0288
RPC: Introduce getblockstats 2018-05-22 23:26:32 +02:00
João Barbosa 80b4910f7d wallet: Use shared pointer to retain wallet instance 2018-05-22 16:56:20 +01:00
MarcoFalke 6916024768
Merge #13282: trivial: Mark overrides as such.
60ebc7da4c trivial: Mark overrides as such. (Daniel Kraft)

Pull request description:

  This trivial change adds the `override` keyword to some methods that override virtual base class / interface methods.  This ensures that any future changes to the interface's method signatures which are not correctly mirrored in the subclasses will break at compile time with a clear error message, rather than at runtime.

Tree-SHA512: cc1bfa5f03b5e29d20e3eab07b0b5fa2f77b47f79e08263dbff43e4f463e9dd8f4f537e2c8c9b6cb3663220dcf40cfd77723cd9fcbd623c9efc90a4cd44facfc
2018-05-22 06:44:44 -04:00
MarcoFalke fa9da85b7c
qa: Initialize lockstack to prevent null pointer deref 2018-05-22 06:31:26 -04:00
Ben Woosley 97c112d4ca
Declare TorReply parsing functions in torcontrol_tests
Rather than including the implementation file into the test,
which is bad practice.
2018-05-21 10:53:18 -07:00
John Newbery be87c6f837 [wallet] Fix incorrect comment for DeriveNewSeed. 2018-05-21 12:57:40 -04:00
Ben Woosley ebec7317ca
Drop the chain argument to GetDifficulty
This removes the need to include rpc/blockchain.cpp in order to put
GetDifficulty under test. GetDifficulty was called in two ways:
* with a guaranteed non-null blockindex
* with no argument

Change the latter case to be provided chainActive.Tip() explicitly.
2018-05-20 22:19:42 -07:00
Daniel Kraft 60ebc7da4c trivial: Mark overrides as such.
This trivial change adds the "override" keyword to some methods of
subclasses meant to override interface methods.  This ensures that any
future change to the interface' method signatures which are not correctly
mirrored in the subclass will break at compile time with a clear error message,
rather than fail at runtime (which is harder to debug).
2018-05-20 09:15:39 +02:00
Brandon Ruggles 5f3cbde9de Increased max width of amount field to prevent number overflow bug. 2018-05-20 01:09:16 -04:00
John Newbery 79053a5f2b [rpc] [wallet] Add 'hdmasterkeyid' alias return values.
Restores the  return value in getwalletinfo() and getaddressinfo()
RPC methods for backwards compatibility
2018-05-19 11:21:20 -04:00
John Newbery c75c351419 [refactor] manually change remaining instances of master key to seed. 2018-05-19 11:21:15 -04:00
John Newbery 131d4450b9 scripted-diff: Rename master key to seed
-BEGIN VERIFY SCRIPT-

ren() { git grep -l "\<$1\>" 'src/*.cpp' 'src/*.h' test | xargs sed -i "s:\<$1\>:$2:g"; }
ren GenerateNewHDMasterKey  GenerateNewSeed
ren DeriveNewMasterHDKey    DeriveNewSeed
ren SetHDMasterKey          SetHDSeed
ren hdMasterKeyID           hd_seed_id
ren masterKeyID             seed_id
ren SetMaster               SetSeed
ren hdmasterkeyid           hdseedid
ren hdmaster                hdseed

-END VERIFY SCRIPT-
2018-05-19 11:16:00 -04:00
Jonas Schnelli 2885c131b6
Qt: use [default wallet] as name for wallet with no name 2018-05-19 11:24:40 +02:00
Ben Woosley 6aa33feadb
Drop UpdateTransaction in favor of UpdateInput
Updating the input explicitly requires the caller to present a mutable
input, which more clearly communicates the effects and intent of the method.

In most cases, this input is already immediately available and need not be
looked up.
2018-05-18 11:08:13 -07:00
João Barbosa 13c3a659c0
Qt/Bugfix: fix handling default wallet with no name 2018-05-18 19:59:25 +02:00
Wladimir J. van der Laan d9ebb63919
Merge #13176: Improve CRollingBloomFilter performance: replace modulus with FastMod
9aac9f90d5 replace modulus with FastMod (Martin Ankerl)

Pull request description:

  Not sure if this is optimization is necessary, but anyway I have some spare time so here it is. This replaces the slow modulo operation with a much faster 64bit multiplication & shift. This works when the hash is uniformly distributed between 0 and 2^32-1. This speeds up the benchmark by a factor of about 1.3:

  ```
  RollingBloom, 5, 1500000, 3.73733, 4.97569e-07, 4.99002e-07, 4.98372e-07 # before
  RollingBloom, 5, 1500000, 2.86842, 3.81630e-07, 3.83730e-07, 3.82473e-07 # FastMod
  ```

  Be aware that this changes the internal data of the filter, so this should probably
  not be used for CBloomFilter because of interoperability problems.

Tree-SHA512: 04104f3fb09f56c9d14458a6aad919aeb0a5af944e8ee6a31f00e93c753e22004648c1cd65bf36752b6addec528d19fb665c27b955ce1666a85a928e17afa47a
2018-05-18 18:46:35 +02:00
Wladimir J. van der Laan 1a8b12c69c
Merge #13265: wallet: Exit SyncMetaData if there are no transactions to sync
b0d2ca9fb6 wallet: Exit SyncMetaData if there are no transactions to sync (Wladimir J. van der Laan)

Pull request description:

  Instead of crash with an assertion error, simply exit the function `SyncMetaData` if there is no metadata to sync.

  Fixes #13110.

Tree-SHA512: 44c4789497b5b63963bef66d8b695987dde80764199f6ea0f2c974be19d29c2663f32446a663a2ee9029e143e5d1d9e8a591e52e6e7e795b982782626bec25bb
2018-05-18 12:53:16 +02:00
Jonas Schnelli e54550303b
Merge #13097: ui: Support wallets loaded dynamically
2e7513471 fixup! ui: Support wallets loaded dynamically (João Barbosa)
0e674ba55 ui: Support wallets loaded dynamically (João Barbosa)
1c8fe0bf9 ui: Remove unnecessary variable fFirstWallet (João Barbosa)

Pull request description:

  Add support in the UI for wallets loaded dynamically.

Tree-SHA512: 4016d61580b31e28c49861b1cb0e77fac5417f9676a6ce6156be28cb6059fdf3d3dd4d57dbbc22a574ad428c2a4a3702aedca596a84e644ce148e1084feb29c9
2018-05-18 10:10:46 +02:00
Jonas Schnelli 2a7c53bc2a
Merge #13264: [qt] Satoshi unit
c722f00a7 [qt] Added satoshi unit "Satoshi (sat)" will be displayed in dropdowns and status bars. "sat" will be used when appended to numbers. (GreatSock)
4ddbcbf8c [qt] BitcoinUnits::format with zero decimals Formatting with zero decimals will now result in 123 instead of 123.0 (GreatSock)

Pull request description:

  This adds satoshi as an additional amount unit for the GUI.

Tree-SHA512: c166c96c9a434b6ac700e1628e54f2dbb132c5232d949c0b464f61276a91d56f9bab4a62d50780535f1d34eaac6484f693a1e0611cd7c9d1ed5ebee066c0dd08
2018-05-18 09:17:20 +02:00
João Barbosa 2e75134719 fixup! ui: Support wallets loaded dynamically 2018-05-18 00:46:44 +01:00
Wladimir J. van der Laan b0d2ca9fb6 wallet: Exit SyncMetaData if there are no transactions to sync
Instead of crash with an assertion error, simply exit the function
`SyncMetaData` if there is no metadata to sync.

Fixes #13110.
2018-05-17 22:07:32 +02:00
MarcoFalke 1b53e4f67c
Merge #13236: break circular dependency: random/sync -> util -> random/sync
84f41946b9 break circular dependency: random/sync -> util -> random/sync (Chun Kuan Lee)

Pull request description:

  LogPrintf  has acutally been moved to logging.h

Tree-SHA512: a7135f5fea421e62f010f2e434873bd1c1738f115453377dada7d24900b3b095535d8aa0462c3acffdacf2f4e819e05ad39b13f2de5a36ac8f7b8467c639a0db
2018-05-17 12:26:02 -04:00
GreatSock c722f00a7e [qt] Added satoshi unit
"Satoshi (sat)" will be displayed in dropdowns and status bars.
"sat" will be used when appended to numbers.
2018-05-17 16:14:49 +02:00
GreatSock 4ddbcbf8c4 [qt] BitcoinUnits::format with zero decimals
Formatting with zero decimals will now result in 123 instead of 123.0
2018-05-17 15:50:09 +02:00
Chun Kuan Lee 84f41946b9 break circular dependency: random/sync -> util -> random/sync 2018-05-17 08:13:54 +00:00
Ben Woosley 4b62bdf513
Wallet: Refactor ReserveKeyFromKeyPool for safety
ReserveKeyFromKeyPool's previous behaviour is to set nIndex to -1 if the keypool is
empty, OR throw an exception for technical failures. Instead, we now return false
if the keypool is empty, true if the operation succeeded.

This is to make failure more easily detectable by calling code.
2018-05-16 22:58:02 -07:00
Luke Dashjr 82dda6bed9
GUI: Allow generating Bech32 addresses with a legacy-address default 2018-05-17 09:40:50 +08:00
Luke Dashjr 7ab1c6f6a7
GUI: Rephrase Bech32 checkbox text/tooltip
- "Bech32" isn't very user-friendly
- You don't spend from addresses
2018-05-17 09:31:35 +08:00
John Newbery 81608178cf [wallet] [rpc] Remove getlabeladdress RPC
labels are associated with addresses (rather than addresses being
associated with labels, as was the case with accounts). The
getlabeladdress does not make sense in this model, so remove it.

getaccountaddress is still supported for one release as the accounts
API is deprecated.
2018-05-16 17:45:19 -04:00
João Barbosa 0e674ba557 ui: Support wallets loaded dynamically 2018-05-16 20:48:48 +01:00
João Barbosa 1c8fe0bf90 ui: Remove unnecessary variable fFirstWallet 2018-05-16 20:48:48 +01:00
Wladimir J. van der Laan 4cfe17c338
Merge #10740: [wallet] loadwallet RPC - load wallet at runtime
cd53981 [docs] Add release notes for `loadwallet` RPC. (John Newbery)
a46aeb6 [wallet] [tests] Test loadwallet (John Newbery)
5d15260 [wallet] [rpc] Add loadwallet RPC (John Newbery)
876eb64 [wallet] Pass error message back from CWallet::Verify() (John Newbery)
e0e90db [wallet] Add CWallet::Verify function (John Newbery)
470316c [wallet] setup wallet background flushing in WalletInit directly (John Newbery)
59b87a2 [wallet] Fix potential memory leak in CreateWalletFromFile (John Newbery)

Pull request description:

  Adds a `loadwallet` RPCs. This allows wallets to be loaded dynamically during runtime without having to stop-start the node with new `-wallet` params.

  Includes functional tests and release notes.

  Limitations:

  - currently this functionality is only available through the RPC interface.
  - wallets loaded in this way will not be displayed in the GUI.

Tree-SHA512: f80dfe32b77f5c97ea3732ac538de7d6ed7e7cd0413c2ec91096bb652ad9bccf05d847ddbe81e7cd3cd44eb8030a51a5f00083871228b1b9b0b8398994f6f9f1
2018-05-16 21:39:17 +02:00
Wladimir J. van der Laan 11e7bdfd90
Merge #13023: Fix some concurrency issues in ActivateBestChain()
dd435ad Add unit tests for signals generated by ProcessNewBlock() (Jesse Cohen)
a3ae8e6 Fix concurrency-related bugs in ActivateBestChain (Jesse Cohen)
ecc3c4a Do not unlock cs_main in ABC unless we've actually made progress. (Matt Corallo)

Pull request description:

  Originally this PR was just to add tests around concurrency in block validation - those tests seem to have uncovered another bug in ActivateBestChain - this now fixes that bug and adds tests.

  ActivateBestChain (invoked after a new block is validated) proceeds in steps - acquiring and releasing cs_main while incrementally disconnecting and connecting blocks to sync to the most work chain known (FindMostWorkChain()). Every time cs_main is released the result of FindMostWorkChain() can change - but currently that value is cached across acquisitions of cs_main and only refreshed when an invalid chain is explored. It needs to be refreshed every time cs_main is reacquired. The test added in 6094ce7304 will occasionally fail without the commit fixing this issue 26bfdbaddb

  Original description below
  --

  After a bug discovered where UpdatedBlockTip() notifications could be triggered out of order (#12978), these unit tests check certain invariants about these signals.

  The scheduler test asserts that a SingleThreadedSchedulerClient processes callbacks fully and sequentially.

  The block validation test generates a random chain and calls ProcessNewBlock from multiple threads at random and in parallel. ValidationInterface callbacks verify that the ordering of BlockConnected BlockDisconnected and UpdatedBlockTip events occur as expected.

Tree-SHA512: 4102423a03d2ea28580c7a70add8a6bdb22ef9e33b107c3aadef80d5af02644cdfaae516c44933924717599c81701e0b96fbf9cf38696e9e41372401a5ee1f3c
2018-05-16 18:30:35 +02:00
John Newbery 5d152601e9 [wallet] [rpc] Add loadwallet RPC
The new `loadwallet` RPC method allows an existing wallet to be loaded
dynamically at runtime.

`unloadwallet` and `createwallet` are not implemented. Notably,
`loadwallet` can only be used to load existing wallets, not to create a
new wallet.
2018-05-16 12:00:01 -04:00
John Newbery 876eb64680 [wallet] Pass error message back from CWallet::Verify()
Pass an error message back from CWallet::Verify(), and call
InitError/InitWarning from WalletInit::Verify().

This means that we can call CWallet::Verify() independently from
WalletInit and not have InitErrors printed to stdout. It also means that
the error can be reported to the user if dynamic wallet load fails.
2018-05-16 11:59:58 -04:00
John Newbery e0e90db07b [wallet] Add CWallet::Verify function
This allows a single wallet to be verified. Prior to this commit, all
wallets were verified together by the WalletInit::Verify() function at
start-up.

Individual wallet verification will be done when loading wallets
dynamically at runtime.
2018-05-16 11:55:38 -04:00
Jesse Cohen dd435ad402 Add unit tests for signals generated by ProcessNewBlock()
After a recent bug discovered in callback ordering in MainSignals,
this test checks invariants in ordering of
BlockConnected / BlockDisconnected / UpdatedChainTip signals
2018-05-16 08:28:15 -04:00
Cristian Mircea Messel 73cd5b25b9 [gui] Add proxy icon in statusbar 2018-05-15 23:23:56 +03:00
John Newbery 470316c3bf [wallet] setup wallet background flushing in WalletInit directly
WalletInit::Start calls postInitProcess() for each wallet. Previously
each call to postInitProcess() would attempt to schedule wallet
background flushing.

Just start wallet background flushing once from WalletInit::Start().
2018-05-15 13:28:29 -04:00
John Newbery 59b87a27ef [wallet] Fix potential memory leak in CreateWalletFromFile
Fix proposed by ryanofsky in
https://github.com/bitcoin/bitcoin/pull/12647#discussion_r174875670
2018-05-15 13:28:29 -04:00
MarcoFalke 13da2899ae
Merge #13125: scheduler: Add Clang thread safety annotations for variables guarded by m_cs_callbacks_pending
244f4baf0f scheduler: Add Clang thread safety annotations for variables guarded by m_cs_callbacks_pending (practicalswift)

Pull request description:

  Add Clang thread safety annotations for variables guarded by `m_cs_callbacks_pending`.

Tree-SHA512: 5c4aa14d1918ff119f945084820f7c1c5618e2a38d8bea8ebbfa6acddbccdacfea81fa61f1f796f8b1fcf57f5e3112da63b9bd0fa97fc9a9ef427fc361945e02
2018-05-15 08:42:49 -04:00
Sjors Provoost cbede7dbfd
[qt] OptionsDialog: add prune setting 2018-05-15 12:46:19 +02:00
Wladimir J. van der Laan 1d4662f5dc
Merge #12881: Minor optimizations to bech32::Decode(); add tests.
60f61f9 Tighten up bech32::Decode(); add tests. (murrayn)

Pull request description:

  Just a few minor optimizations to bech32::Decode():

  1) optimize the order and logic of the conditionals
  2) get rid of subsequent '(c < 33 || c > 126)' check which is redundant (already performed above)
  3) add a couple more bech32 tests (mixed-case)

Tree-SHA512: e41af834c8f6b7d34c22c28b724df42c60f72e00df616e70a12efbc4271d15d80627fe1bc36845caf29f615c238499a566298a863cbe119fef457287231053c8
2018-05-15 12:10:34 +02:00
Wladimir J. van der Laan 0bf431870e net: Serve blocks directly from disk when possible
In `ProcessGetBlockData`, send the block data directly from disk if
type MSG_WITNESS_BLOCK is requested. This is a valid shortcut as the
on-disk format matches the network format.

This is expected to increase performance because a deserialization and
subsequent serialization roundtrip is avoided.
2018-05-15 08:11:56 +02:00
Ben Woosley 5b35b92768
Break circular dependency: chain -> pow -> chain
chain.h does not actually depend on the methods defined in pow.h, just its
include of consensus/params.h, which is standalone and can be included instead.

Confirmed by inspection and successful build.
2018-05-14 18:36:39 -07:00
MarcoFalke 81c533c6f4
Merge #13158: [Qt]: Improve sendcoinsdialog readability
f08a385590 [qt]: changes sendcoinsdialog's box layout for improved readability. (marcoagner)

Pull request description:

  I'm addressing two (probably duplicate) issues: https://github.com/bitcoin/bitcoin/issues/11606 and https://github.com/bitcoin/bitcoin/issues/10613.

  Some points worth noting:

  - I've tried to balance the proposed changes on both issues without going too far and remaining a bit conservative. It will be easier to improve based on suggestions where necessary.

  - I preferred to maintain a layout that doesn't ask for an address truncation because, in my view, this wallet should be conservative on this.

  - I didn't follow the idea of aligning the amounts to the right for finding it more natural (and minimalist) to read the information without having to map alignments. Additionally, that approach seems to need more `<hr />`'s (or similar) in order to help the user to map information, which ended up cluttering the box too much (specially with multiple recipients). Thus, I preferred to just give some more space between recipients. Let me know if there are better ideas on this.

  Visually, I went from this (current):
  ![screenshot from 2018-05-03 15-11-30](https://user-images.githubusercontent.com/5016303/39581859-16abec82-4edc-11e8-86d3-eb722f8a7ed6.png)

  To this:
  ![screenshot from 2018-05-03 15-15-41](https://user-images.githubusercontent.com/5016303/39582066-96856adc-4edc-11e8-804c-468aec44cc8d.png)

  As a side note, while doing this, I thought about a better way to show fees and found there's already a PR on this (https://github.com/bitcoin/bitcoin/pull/12189) and thought it is

Tree-SHA512: e94b740fab6c1babd853a97be65c3b6f86ec174c975a926fde66b147f7a47e0cf0fa10f7255ba92aaba68c76a80dde8c688008179a34705a9799bf24d3c5cd46
2018-05-14 17:07:26 -04:00
MarcoFalke c5870ab689
Merge #12963: Fix Clang Static Analyzer warnings
159c32d1f1 Add assertion to guide static analyzers. Clang Static Analyzer needs this guidance. (practicalswift)
fd447a6efe Fix dead stores. Values were stored but never read. Limit scope. (practicalswift)

Pull request description:

  Fix Clang Static Analyzer warnings reported by @kallewoof in #12961:

  * Fix dead stores. Values were stored but never read.
  * Add assertion to guide static analyzers. See #12961 for details.

Tree-SHA512: 83dbec821f45217637316bee978e7543f2d2caeb7f7b0b3aec107fede0fff8baa756da8f6b761ae0d38537740839ac9752f6689109c38a4b05c0c041aaa3a1fb
2018-05-14 10:45:24 -04:00
Wladimir J. van der Laan 682698970d
Merge #13197: util: warn about ignored recursive -includeconf calls
2352aa9 test: Ensure that recursive -includeconf produces appropriate warnings (Karl-Johan Alm)
c5bcc7d util: warn about recursive -includeconf arguments in configuration files (Karl-Johan Alm)

Pull request description:

  This is a follow-up PR to #10267, and addresses https://github.com/bitcoin/bitcoin/pull/10267#issuecomment-387546144.

  ~~I am adding extra work for @jnewbery in #12755 here -- maybe I should just rebase on top of that, but not sure what the appropriate approach is here.~~

Tree-SHA512: 87f0c32436b70424e33616ffb88d7cb699f90d6a583a10237e224b28fc936d6a9df95536c8c52ee8546b3942da92b2a357e61bf87e00d1462bc10d46d3bee352
2018-05-14 16:39:07 +02:00
MarcoFalke 0264836695
Merge #11689: mempool: Fix missing locking in CTxMemPool::check(…) and CTxMemPool::setSanityCheck(…)
47782b49e6 Add Clang thread safety analysis annotations (practicalswift)
0e2dfa8a65 Fix missing locking in CTxMemPool::setSanityCheck(double dFrequency) (practicalswift)
6bc5b7100b Fix missing locking in CTxMemPool::check(const CCoinsViewCache *pcoins) (practicalswift)

Pull request description:

  Fix missing locking in `CTxMemPool::check(const CCoinsViewCache *pcoins)`:
  * reading variable `mapTx` requires holding mutex `cs`
  * reading variable `mapNextTx` requires holding mutex `cs`
  * reading variable `nCheckFrequency` requires holding mutex `cs`

  Fix missing locking in `CTxMemPool::setSanityCheck(double dFrequency)`:
  * writing variable `nCheckFrequency` requires holding mutex `cs`

Tree-SHA512: ce7c365ac89225223fb06e6f469451b121acaa499f35b21ad8a6d2a266c91194639b3703c5428871be033d4f5f7be790cc297bd8c25b2e0c59345ef09c3693d0
2018-05-14 10:29:22 -04:00
MarcoFalke 19a3a9e8fb
Merge #13127: wallet: Add Clang thread safety annotations for variables guarded by cs_db
56921f9369 wallet: Add Clang thread safety annotations for variables guarded by cs_db (practicalswift)

Pull request description:

  Add Clang thread safety annotations for variables guarded by `cs_db`.

Tree-SHA512: d59723598e918143f36408b4f49d31138b5d8968ba191472f6a207a63af147627f21e48fd6cc1606dd901d8a58183271e65ea4346a380db3c09e404764a28063
2018-05-14 09:56:47 -04:00
Wladimir J. van der Laan cb088b1461
Merge #13005: Make --enable-debug to pick better options
9e49db2 Make --enable-debug to pick better options (Evan Klitzke)

Pull request description:

  Cherry-picked (and rebased) 94189645e67f364c4445d62e2b00c282d885cbbf from the "up for grabs" PR: "[build] Make --enable-debug pick better options" (#12695).

  See previous review in #12695.

Tree-SHA512: a93cdadcf13e2ef8519acb1ce4f41ce95057a388347bb0a86a5c164dc7d0b0d14d4bb2a466082d5a100b8d50de65c605c40abaed555e8ea77c99e28800a34439
2018-05-14 15:33:03 +02:00
MarcoFalke 0dec5b5af4
Merge #13081: wallet: Add compile time checking for cs_wallet runtime locking assertions
66b0b1b2a6 Add compile time checking for all cs_wallet runtime locking assertions (practicalswift)

Pull request description:

  Add compile time checking for `cs_wallet` runtime locking assertions.

  This PR is a subset of #12665. The PR was broken up to make reviewing easier.

  The intention is that literally all `EXCLUSIVE_LOCKS_REQUIRED`/`LOCKS_EXCLUDED`:s added in this PR should follow either directly or indirectly from `AssertLockHeld(…)`/`AssertLockNotHeld(…)`:s already existing in the repo.

  Consider the case where function `A(…)` contains `AssertLockHeld(cs_foo)` (without
  first locking `cs_foo` in `A`), and that `B(…)` calls `A(…)` (without first locking `cs_main`):
  * It _directly_ follows that: `A(…)` should have an `EXCLUSIVE_LOCKS_REQUIRED(cs_foo)` annotation.
  * It _indirectly_ follows that: `B(…)` should have an `EXCLUSIVE_LOCKS_REQUIRED(cs_foo)` annotation.

Tree-SHA512: d561d89e98a823922107e56dbd493f0f82e22edac91e51e6422f17daf2b446a70c143b7b157ca618fadd33d0ec63eb7a57dde5a83bfdf1fc19d71459b43e21fd
2018-05-14 09:17:35 -04:00
Wladimir J. van der Laan 7cc1bd3aae
Merge #13161: wallet: Reset BerkeleyDB handle after connection fails
b6f0b4d wallet: Improve logging when BerkeleyDB environment fails to close (Tim Ruffing)
264c643 wallet: Reset BerkeleyDB handle after connection fails (Tim Ruffing)

Pull request description:

  According to the BerkeleyDB docs, the DbEnv handle may not be accessed
  after close() has been called. This change ensures that we create a new
  handle after close() is called. This avoids a segfault when the first
  connection attempt fails and then a second connection attempt tries to
  call open() on the already closed DbEnv handle.

  Without the patch, bitcoindd reliably crashes in the second call to `set_lg_dir()` after `close()` if
  there is an issue with the database:
  ```
  2018-05-03T13:27:21Z Bitcoin Core version v0.16.99.0-a024a1841-dirty (debug build)
  [...]
  2018-05-03T13:27:21Z Using wallet directory /home/tim/.bitcoin
  2018-05-03T13:27:21Z init message: Verifying wallet(s)...
  2018-05-03T13:27:21Z Using BerkeleyDB version Berkeley DB 4.8.30: (April  9, 2010)
  2018-05-03T13:27:21Z Using wallet wallet.dat
  2018-05-03T13:27:21Z BerkeleyEnvironment::Open: LogDir=/home/tim/.bitcoin/database
  2018-05-03T13:27:21Z BerkeleyEnvironment::Open: Error -30974 opening database environment: DB_RUNRECOVERY: Fatal error, run database recovery
  2018-05-03T13:27:21Z Moved old /home/tim/.bitcoin/database to /home/tim/.bitcoin/database.1525354041.bak. Retrying.
  2018-05-03T13:27:21Z BerkeleyEnvironment::Open: LogDir=/home/tim/.bitcoin/database ErrorFile=/home/tim/.bitcoin/db.log
  [1]    14533 segmentation fault (core dumped)  ./src/bitcoind
  ```

  After the fix:
  ```
  2018-05-03T17:19:32Z Bitcoin Core version v0.16.99.0-cc09e3bd0-dirty (release build)
  [...]
  2018-05-03T17:19:32Z Using wallet directory /home/tim/.bitcoin
  2018-05-03T17:19:32Z init message: Verifying wallet(s)...
  2018-05-03T17:19:32Z Using BerkeleyDB version Berkeley DB 4.8.30: (April  9, 2010)
  2018-05-03T17:19:32Z Using wallet wallet.dat
  2018-05-03T17:19:32Z BerkeleyEnvironment::Open: LogDir=/home/tim/.bitcoin/database ErrorFile=/home/tim/.bitcoin/db.log
  2018-05-03T17:19:32Z scheduler thread start
  2018-05-03T17:19:32Z BerkeleyEnvironment::Open: Error -30974 opening database environment: DB_RUNRECOVERY: Fatal error, run database recovery
  2018-05-03T17:19:32Z Moved old /home/tim/.bitcoin/database to /home/tim/.bitcoin/database.1525367972.bak. Retrying.
  2018-05-03T17:19:32Z BerkeleyEnvironment::Open: LogDir=/home/tim/.bitcoin/database ErrorFile=/home/tim/.bitcoin/db.log
  2018-05-03T17:19:32Z Cache configuration:
  2018-05-03T17:19:32Z * Using 2.0MiB for block index database
  2018-05-03T17:19:32Z * Using 8.0MiB for chain state database
  2018-05-03T17:19:32Z * Using 440.0MiB for in-memory UTXO set (plus up to 286.1MiB of unused mempool space)
  2018-05-03T17:19:32Z init message: Loading block index..
  [...]
  ```

Tree-SHA512: b809b318e5014ec47d023dc3dc40826b9706bfb211fa08bc2d29f36971b96caa10ad48d9a3f96c03933be46fa4ff7e00e952ac77bfffb6563767fb08aa4f23d6
2018-05-14 15:06:48 +02:00
practicalswift 66b0b1b2a6 Add compile time checking for all cs_wallet runtime locking assertions 2018-05-14 14:57:25 +02:00
MarcoFalke ea7d6553bc
Merge #13116: Add Clang thread safety annotations for variables guarded by cs_{rpcWarmup,nTimeOffset,warnings}
8499f15e67 Add Clang thread safety annotations for variables guarded by cs_warnings (practicalswift)
cf13ad23d4 Add Clang thread safety annotations for variables guarded by cs_nTimeOffset (practicalswift)
012dec0347 Add Clang thread safety annotations for variables guarded by cs_rpcWarmup (practicalswift)

Pull request description:

  Add Clang thread safety annotations for variables guarded by `cs_{rpcWarmup,nTimeOffset,warnings}`.

Tree-SHA512: 8e0a4b9e36a4450bd75ad32c21d813bb572aaaa5b4a4cbdcbf4678e58ade6265c0b275352391168930a63fcbd09caa3b76e74595a7b14646054c52870c46d007
2018-05-14 08:46:54 -04:00
Wladimir J. van der Laan e03c0db08f
Merge #12560: [wallet] Upgrade path for non-HD wallets to HD
a8da482 Bump wallet version for pre split keypool (Andrew Chow)
dfcd9f3 Use a keypool of presplit keys after upgrading to hd chain split (Andrew Chow)
5c50e93 Allow -upgradewallet to upgradewallets to HD (Andrew Chow)
2bcf2b5 Test sethdseed (Andrew Chow)
b5ba01a Add 'sethdseed' RPC to initialize or replace HD seed (Chris Moore)
dd3c07a Separate HaveKey function that checks whether a key is in a keystore (Andrew Chow)

Pull request description:

  Revival/rebase of #11085

  Adds a new command `sethdseed` which allows you to either set or generate a new HD seed to be used. A new keypool can be generated or the original one kept and new keys added to the keypool will come from the new HD seed.

  Wallets that are not HD will be upgraded to be version FEATURE_HD_SPLIT when the `sethdseed` RPC command is used.

  I have also add some tests for this.

  Additionally `-upgradewallet` can now be used to upgrade a wallet from non-HD to HD. When it is used for such an upgrade, the keypool will be regenerated.

Tree-SHA512: e56c792e150590429ac4a1061e8d6f7b20cca06366e184eb9bbade4cd6ae82699a28fe84f87031eadba97ad2c1606517a105f00fb7b45779c979243020071adb
2018-05-14 11:17:29 +02:00
Wladimir J. van der Laan fe16dd8226 net: Add option -enablebip61 to configure sending of BIP61 notifications
This commit adds a boolean option `-enablebip61`, defaulting to `1`, that
can be used to disable the sending of BIP61 `reject` messages. This
functionality has been requested for various reasons:

- security (DoS): reject messages can reveal internal state that can be
  used to target certain resources such as the mempool more easily.

- bandwidth: a typical node sends lots of reject messages; this counts
  against upstream bandwidth. Also the reject messages tend to be larger
  than the message that was rejected.

On the other hand, reject messages can be useful while developing client
software (I found them indispensable while creating bitcoin-submittx),
as well as for our own test cases, so whatever the default becomes on the
long run, IMO the functionality should be retained as option. But that's
a discussion for later.
2018-05-13 21:03:27 +02:00
MarcoFalke fa0fc1bc7e
bench: Add block assemble benchmark 2018-05-13 12:45:55 -04:00
Pieter Wuille 418ae49ee1
Merge #13199: Bugfix: ensure consistency of m_failed_blocks after reconsiderblock
11fa6bb66e Bugfix: ensure consistency of m_failed_blocks after reconsiderblock (Suhas Daftuar)

Pull request description:

  This was introduced in 015a5258ad and could cause a node to crash (due to assertion failure) when using the `reconsiderblock` rpc.

Tree-SHA512: 820dcd761bf983e36f5d0f16777ed75c833daaf62a6b3a4dbd17f6caaf9287223e3a202d06540ac62f8ba72926b73b0873bb76c6273ddcb19d9408f4c1cd325e
2018-05-12 11:32:09 -07:00
Andrew Chow a8da482a8b Bump wallet version for pre split keypool
Bump the wallet version to indicate support for the pre split keypool.
Also prevents any wallets from upgrading to versions between HD_SPLIT
and PRE_SPLIT_KEYPOOL.
2018-05-12 13:15:21 -04:00
Andrew Chow dfcd9f3e6a Use a keypool of presplit keys after upgrading to hd chain split
After upgrading to HD chain split, we want to continue to use keys
from the old keypool. To do this, before we generate any new keys after
upgrading, we mark all of the keypool entries as being pre-chain
split and move them to a separate pre chain split keypool. Keys are
fetched from that keypool until it is emptied. Only then are the new
internal and external keypools used.
2018-05-12 13:15:21 -04:00
Andrew Chow 5c50e93d52 Allow -upgradewallet to upgradewallets to HD
Changes the maximum upgradewallet version to the latest wallet version
number, 159900. Non-HD wallets will be upgraded to use HD derivation.
Non HD chain split wallets will be upgraded to HD chain split.

If a non-HD wallet is upgraded to HD, the keypool will be entirely
regenerated.

Since upgradewallet is effectively run during a first run, all of the
first run initial setup stuff is combined with the upgrade to HD
2018-05-12 13:15:21 -04:00
Chris Moore b5ba01a187 Add 'sethdseed' RPC to initialize or replace HD seed 2018-05-12 13:15:21 -04:00
Jesse Cohen a3ae8e6873 Fix concurrency-related bugs in ActivateBestChain
If multiple threads are invoking ActivateBestChain, it was possible to have
them working towards different tips, and we could arrive at a less work tip
than we should.  Fix this by introducing a ChainState lock which must
be held for the entire duration of ActivateBestChain to enforce
exclusion in ABC.
2018-05-12 12:44:32 -04:00
Matt Corallo ecc3c4a019 Do not unlock cs_main in ABC unless we've actually made progress.
Technically, some internal datastructures may be in an inconsistent
state if we do this, though there are no known bugs there. Still,
for future safety, its much better to only unlock cs_main if we've
made progress (not just tried a reorg which may make progress).
2018-05-12 12:44:32 -04:00
Wladimir J. van der Laan 6af005c3eb
Merge #11423: [Policy] Several transaction standardness rules
364bae5 qa: Pad scriptPubKeys to get minimum sized txs (MarcoFalke)
7485488 Policy to reject extremely small transactions (Johnson Lau)
0f8719b Add transaction tests for constant scriptCode (Johnson Lau)
9dabfe4 Add constant scriptCode policy in non-segwit scripts (Johnson Lau)

Pull request description:

  This disables `OP_CODESEPARATOR` in non-segwit scripts (even in an unexecuted branch), and makes a positive `FindAndDelete` result invalid. This ensures that the `scriptCode` serialized in `SignatureHash` is always the same as the script passing to the `EvalScript`.

Tree-SHA512: a0552cb920294d130251c48053fa2ff1fbdd26332e62b52147d918837852750f0ce35ce2cd1cbdb86588943312f8154ccb4925e850dbb7c2254bc353070cd5f8
2018-05-12 17:39:46 +02:00
Karl-Johan Alm c5bcc7dbe9
util: warn about recursive -includeconf arguments in configuration files
Since -includeconf cannot be used recursively, the user would not see feedback that an -includeconf
in an -includeconf'd file was silently ignored.
2018-05-10 11:02:20 +09:00
Andrew Chow 4d4185a4f0 Make gArgs aware of the arguments
gArgs knows what the available arguments are and their help. Getting
the help message is moved to gArgs and HelpMessage() is removed
2018-05-09 12:21:05 -04:00
Wladimir J. van der Laan 08c1caf863
Merge #13185: Bugfix: the end of a reorged chain is invalid when connect fails
a2f678d Bugfix: the end of a reorged chain is invalid when connect fails (Pieter Wuille)

Pull request description:

  Introduced in 4e0eed88ac

  When an invalid block is found during a reorg, we know the last of the blocks in the was-to-be-connected chain is invalid, but not necessarily the first. As `vpIndexToConnect` is ordered in decreasing height, the end of the reorg is the front of the vector, and not the back.

  This only affected the warning system.

Tree-SHA512: ddf749f8a78083811a5a17152723f545c1463768d09dc9832ec3682e803a3c106fb768de9fa91c03aa95e644d4e41361a7e4ee791940fd7d51cdefea90de31fc
2018-05-09 17:10:53 +02:00
Suhas Daftuar 11fa6bb66e Bugfix: ensure consistency of m_failed_blocks after reconsiderblock 2018-05-09 10:40:33 -04:00
Tim Ruffing b6f0b4d859
wallet: Improve logging when BerkeleyDB environment fails to close 2018-05-09 15:23:16 +02:00
Wladimir J. van der Laan 7b966d9e6e
Merge #10267: New -includeconf argument for including external configuration files
25b7ab9 doc: Add release notes for -includeconf (Karl-Johan Alm)
0f0badd test: Test includeconf parameter. (Karl-Johan Alm)
629ff8c -includeconf=<path> support in config handler, for including external configuration files (Karl-Johan Alm)

Pull request description:

  Fixes: #10071.

  Done:
  - adds `-includeconf=<path>`, where `<path>` is relative to `datadir` or to the path of the file being read, if in a file
  - protects against circular includes
  - updates help docs

  ~~~Thoughts:~~~
  - ~~~I am not sure how to test this in a neat manner. Feedback on this would be nice. Will dig/think though.~~~

Tree-SHA512: cb31f1b2f69fbc0890d264948eb2e501ac05cf12f5e06a5942f9c1539eb15ea8dc3cae817f4073aecb2fcc21d0386747f14f89d990772003a76e2a6d25642553
2018-05-09 06:36:54 +02:00
marcoagner f08a385590 [qt]: changes sendcoinsdialog's box layout for improved readability.
[qt]: extracts html tags from translator.

[qt]: removes missed tr() call.
2018-05-08 21:19:12 +01:00
Pieter Wuille 57f34630fb Refactor SHA256 code 2018-05-08 07:44:21 -07:00
Pieter Wuille 0df017889b Benchmark Merkle root computation 2018-05-08 07:44:13 -07:00
Pieter Wuille a2f678d355 Bugfix: the end of a reorged chain is invalid when connect fails
Introduced in 4e0eed88ac

When an invalid block is found during a reorg, we know the last of the blocks in
the was-to-be-connected chain is invalid, but not necessarily the first. As
vpIndexToConnect is ordered in decreasing height, the end of the reorg is the
front of the vector, and not the back.

This only affected the warning system.
2018-05-07 11:18:30 -07:00
David A. Harding f30e9be4c1
RPC Docs: gettxout*: clarify bestblock and unspent counts 2018-05-07 11:48:58 -04:00
Jonas Schnelli 5778d44aa8
Merge #13079: Fix rescanblockchain rpc to properly report progress
16be13345 Fix rescanblockchain rpc to property report progress (Ben Woosley)

Pull request description:

  Previously it assumed tip in all cases. This also extracts a RescanVerificationProgress helper object whose role is to manage reporting, in order to simplify ScanForWalletTransactions - more lines in total, but much simpler to follow the core logic.

Tree-SHA512: 5ebed0c56fae4ccfe613ff1d7082cb6da5a86635a8993ed3af70b500a4ea43074121aea9219b2f0321fbfeb7efcb964bdc2199297a64ca0fa85d9d07aa637d40
2018-05-07 15:03:38 +02:00
Wladimir J. van der Laan 57aae632e2
Merge #13131: Add Windows shutdown handler
ddebde7 Add Windows shutdown handler (Chun Kuan Lee)

Pull request description:

  Exit properly when clicked the red X of Windows Console

Tree-SHA512: f030edd08868390662b42abfa1dc6bd702166c6c19f5b1f8e7482e202451e79fb6f37ea672c26c2eb0d32c367bfca86160fbee624696c53828f280b7070be6a0
2018-05-07 14:33:03 +02:00
practicalswift d8c4998f31 Fix typos 2018-05-07 14:32:50 +02:00
Wladimir J. van der Laan bd83704ec6
Merge #13149: Handle unsuccessful fseek(...):s
20ce5af Print a log message if we fail to shrink the debug log file (practicalswift)
29c9bdc Handle unsuccessful fseek(...):s (practicalswift)

Pull request description:

  Handle unsuccessful `fseek(...)`:s.

  **Note to reviewers:** What is the most appropriate course of actions for each of these unsuccessful `fseek(...)`:s?

Tree-SHA512: 5b3d82dbdd15d434d3f08dcb4df62888da4df8541d2586f56a4e529083005f6782c39e10645acd1ec403da83061bbfd8dbf2dddc66e09268d410ad0918c61876
2018-05-07 13:39:19 +02:00
Jonas Schnelli 6a01a50f49
Merge #13180: Fix re-declared scoped enum as unscoped (Causes issues with some compilers)
43f3dec00 Remove enum specifier (to avoid re-declare scoped enum as unscoped) (donaloconnor)

Pull request description:

  MSVC fails to compile with the changes made in #10742

  The problem is enum types were changed to scoped (`enum class`) but in some places `enum` as an unscoped is used.

  This is a very simple fix and I've tested it.

  Edit: Had to remove enum altogether - `enum class` doesn't compile on clang.

Tree-SHA512: 13e21666243585a133c74c81249a1fa4098d6b7aa3cda06be871fa017c0ad9bb7b0725f801160b9d31678448d668718197941fd84702ebdef15128c27d92cd70
2018-05-07 13:28:33 +02:00
Wladimir J. van der Laan a174702bad
Merge #13162: [net] Don't incorrectly log that REJECT messages are unknown.
fad63eb [logging] Don't incorrectly log that REJECT messages are unknown. (John Newbery)

Pull request description:

  Reject messages are logged to debug.log if NET debug logging is enabled.

  Because of the way the `ProcessMessages()` function is structured,
  processing for REJECT messages will also drop through to the default
  branch and incorrectly log `Unknown command "reject" from peer-?`. Fix
  that by exiting from `ProcessMessages()` early.

  without this PR:
  ```
  2018-05-03T17:37:00.930600Z received: reject (21 bytes) peer=0
  2018-05-03T17:37:00.930620Z Reject message code 16: spammy spam
  2018-05-03T17:37:00.930656Z Unknown command "reject" from peer=0
  ```
  with this PR:
  ```
  2018-05-03T17:35:04.751246Z received: reject (21 bytes) peer=0
  2018-05-03T17:35:04.751274Z Reject message code 16: spammy spam
  ```

Tree-SHA512: 5c84c98433ab99e0db2dd481f9c2db6f87ff0d39022ff317a791737e918714bbcb4a23e81118212ed8e594ebcf098ab7f52f7fd5e21ebc3f07b1efb279b9b30b
2018-05-07 12:49:11 +02:00
Jorge Timón cda8e36f01
Refactor: RPC: Separate GetBlockChecked() from getblock()
This does not change functionality
2018-05-07 12:22:42 +02:00
donaloconnor 43f3dec009 Remove enum specifier (to avoid re-declare scoped enum as unscoped) 2018-05-06 22:50:39 +01:00
Martin Ankerl 9aac9f90d5 replace modulus with FastMod
Replaces the slow modulo operation with a much faster 32bit multiplication & shift. This works
because the hash should be uniformly distributed between 0 and 2^32-1. This speeds up the benchmark
by a factor of about 1.3:

RollingBloom, 5, 1500000, 3.73733, 4.97569e-07, 4.99002e-07, 4.98372e-07 # before
RollingBloom, 5, 1500000, 2.86842, 3.81630e-07, 3.83730e-07, 3.82473e-07 # FastMod

Be aware that this changes the position of the bits that are toggled, so this should probably
not be used for CBloomFilter which is serialized.
2018-05-06 13:55:33 +02:00
practicalswift 47782b49e6 Add Clang thread safety analysis annotations 2018-05-05 16:51:22 +02:00
practicalswift 0e2dfa8a65 Fix missing locking in CTxMemPool::setSanityCheck(double dFrequency)
* writing variable 'nCheckFrequency' requires holding mutex 'cs'
2018-05-05 16:50:58 +02:00
practicalswift 6bc5b7100b Fix missing locking in CTxMemPool::check(const CCoinsViewCache *pcoins)
* reading variable 'mapTx' requires holding mutex 'cs'
* reading variable 'mapNextTx' requires holding mutex 'cs'
* reading variable 'nCheckFrequency' requires holding mutex 'cs'
2018-05-05 16:50:58 +02:00
practicalswift cbba1d2da4 Add compile time checking for all ::mempool.cs runtime locking assertions 2018-05-05 08:11:05 +02:00
Andrew Chow dd3c07acce Separate HaveKey function that checks whether a key is in a keystore 2018-05-05 00:43:04 -04:00
MarcoFalke fac1223a56
Cache witness hash in CTransaction 2018-05-04 17:55:12 -04:00
MarcoFalke faab55fbb1
Make CMutableTransaction constructor explicit
Silently converting to a CMutableTransaction will drop all caches
and should thus be done explicitly
2018-05-04 17:40:52 -04:00
Johnson Lau 7485488e90 Policy to reject extremely small transactions
A transaction with 1 segwit input and 1 P2WPHK output has non-witness size of 82 bytes. Anything smaller than this have unnecessary malloc overhead and are not relayed/mined.
2018-05-05 04:26:13 +08:00
Johnson Lau 0f8719bb03 Add transaction tests for constant scriptCode
Tests showing that CONST_SCRIPTCODE is applied only to non-segwit transactions
2018-05-05 04:26:13 +08:00
Johnson Lau 9dabfe49c0 Add constant scriptCode policy in non-segwit scripts
This disables OP_CODESEPARATOR in non-segwit scripts (even in an unexecuted branch), and makes a positive FindAndDelete result invalid. This ensures that the scriptCode serialized in SignatureHash() is always the same as the script passing to the EvalScript.
2018-05-05 04:26:12 +08:00
Johnson Lau 2f1a30c63e Fix MAX_STANDARD_TX_WEIGHT check
As suggested by the constant name and its comment in policy.h, a transaction with a weight of exactly MAX_STANDARD_TX_WEIGHT should be allowed
2018-05-05 00:00:28 +08:00
practicalswift c3f34d06be Make it clear which functions that are intended to be translation unit local
Do not share functions that are meant to be translation unit local with
other translation units. Use internal linkage for those consistently.
2018-05-03 21:47:40 +02:00
Pieter Wuille a53f0feff8 Add some checks for invalid recursion in IsMine 2018-05-03 11:02:01 -07:00
Pieter Wuille b5802a9f5f Simplify IsMine logic 2018-05-03 11:02:01 -07:00
Pieter Wuille 4e91820531 Make IsMine stop distinguishing solvable/unsolvable 2018-05-03 11:02:01 -07:00
Pieter Wuille 6d714c3419 Make coincontrol use IsSolvable to determine solvability 2018-05-03 11:01:57 -07:00
John Newbery fad63ebe0f [logging] Don't incorrectly log that REJECT messages are unknown.
Reject messages are logged to debug.log if NET debug logging is enabled.

Because of the way the `ProcessMessages()` function is structured,
processing for REJECT messages will also drop through to the default
branch and incorrectly log `Unknown command "reject" from peer-?`. Fix
that by exiting from `ProcessMessages()` early.

without this PR:
```
2018-05-03T17:37:00.930600Z received: reject (21 bytes) peer=0
2018-05-03T17:37:00.930620Z Reject message code 16: spammy spam
2018-05-03T17:37:00.930656Z Unknown command "reject" from peer=0
```
with this PR:
```
2018-05-03T17:35:04.751246Z received: reject (21 bytes) peer=0
2018-05-03T17:35:04.751274Z Reject message code 16: spammy spam
```
2018-05-03 13:41:03 -04:00
Ben Woosley 16be13345e
Fix rescanblockchain rpc to property report progress
CWallet::ScanForWalletTransactions did not previously take into account
pindexStop when calculating progress.

Renamed progress vars to progress_*.

rescanblockchain is the only rpc that uses this parameter.
2018-05-03 13:18:10 -04:00
Tim Ruffing 264c643809
wallet: Reset BerkeleyDB handle after connection fails
According to the BerkeleyDB docs, the DbEnv handle may not be accessed
after close() has been called. This change ensures that we create a new
handle after close() is called. This avoids a segfault when the first
connection attempt fails and then a second connection attempt tries to
call open() on the already closed DbEnv handle.
2018-05-03 19:15:11 +02:00
practicalswift 20ce5af4c6 Print a log message if we fail to shrink the debug log file 2018-05-03 15:44:04 +02:00
Wladimir J. van der Laan 7eb7076f70
Merge #12639: Reduce cs_main lock in listunspent
a59dac3 refactor: Avoid extra lookups of mapAddressBook in listunspent RPC (João Barbosa)
d76962e rpc: Reduce cs_main lock in listunspent (João Barbosa)

Pull request description:

  On my system, where the wallet has 10000 unspents, the `cs_main` lock duration changed from 191ms to 36ms. The loop that generates the response takes around 155ms. So, the lock duration is reduced to around 20%.

Tree-SHA512: ddaae591f39da59a9d1a8e9ffe773d857687789476f566ca273d310ad531da6dacff80cac69f3334c601c251ac7c5ed4136656c725aa3d611c6bbf734111946e
2018-05-03 15:37:41 +02:00
Wladimir J. van der Laan b62b437acd
Merge #13148: logging: Fix potential use-after-free in LogPrintStr(...)
0bd4cd3 logging: remove unused return value from LogPrintStr (practicalswift)
76f344d logging: Fix potential use-after-free in LogPrintStr(...) (practicalswift)

Pull request description:

  Fix potential use-after-free in `LogPrintStr(...)`.

  `freopen(…)` frees `m_fileout`.

Tree-SHA512: ceee1f659c10a21525aa648377afeea0a37016339f5269dea54850ba3b475aa316f4931081655717b65f981598fdc9d79a1e79e55f7084c242eeb7bf372bc4b6
2018-05-03 12:53:57 +02:00
Wladimir J. van der Laan 11adab39e6
Merge #13154: Trivial: s/SetBestChain/ChainStateFlushed in comments after #13106
21f5680 Trivial: s/SetBestChain/ChainStateFlushed in comments after #13106 (Russell Yanofsky)

Pull request description:

Tree-SHA512: 373896dd73c3ba202739433b22320a4b7ea6dc80ef84547b4ed72c7ae0d6746b109c8b1879359c43374d1816fe384cc31b24b87879ddefe993887140c2f0df9c
2018-05-03 12:40:08 +02:00
João Barbosa a59dac35ab refactor: Avoid extra lookups of mapAddressBook in listunspent RPC 2018-05-03 11:32:57 +01:00
João Barbosa d76962e056 rpc: Reduce cs_main lock in listunspent 2018-05-03 11:31:21 +01:00
Wladimir J. van der Laan 979150bc23
Merge #12729: Get rid of ambiguous OutputType::NONE value
1e46d8a Get rid of ambiguous OutputType::NONE value (Russell Yanofsky)

Pull request description:

  Based on suggestion by @sipa https://github.com/bitcoin/bitcoin/pull/12119#issuecomment-357982763

  After #12119, the NONE output type was overloaded to refer to either an output type that couldn't be parsed, or to an automatic change output mode.  This change drops the NONE enum and uses a simple bool to indicate parse failure, and a new CHANGE_AUTO enum to refer the change output type.

  This change is almost a pure refactoring except it makes RPCs reject empty string ("") address types instead of treating them like they were unset. This simplifies the parsing code a little bit and could prevent RPC usage mistakes. It's noted in the release notes.

  Follows up #12408 by @MarcoFalke

  Followups for future PRs:

  - [ ] Add explicit support for specifying "auto" in `ParseOutputType` as suggested by promag and sipa: https://github.com/bitcoin/bitcoin/pull/12729#issuecomment-374799567 and https://github.com/bitcoin/bitcoin/pull/12729#discussion_r175969481
  - [ ] Add wallet `AddressChangeType` method to complement `TransactionChangeType`:  https://github.com/bitcoin/bitcoin/pull/12729#discussion_r175969618.

Tree-SHA512: 8b08b272bcb177a0a9e556dcd965840a7fe601ef83ca97938b879c9b1a33b5b3f96939e1bceef11ba7c644ac21bfd6c1dbc6ca715cd1da4ace50475240e4ee48
2018-05-03 11:53:30 +02:00
Wladimir J. van der Laan 2afdc29403
Merge #12507: Interrupt rescan on shutdown request
c4fda76 wallet: Interrupt rescan on shutdown request (João Barbosa)

Pull request description:

  Fixes #10987.

  Here are the steps to test the feature:

  1. start bitcoind, generate a couple of transactions and then stop:
  ```
  bitcoind -regtest -printtoconsole
  bitcoin-cli -regtest generate 100
  ```
  2. apply the following patch
  ```diff
  diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp
  index 2478d67ce..8f8cea40c 100644
  --- a/src/wallet/wallet.cpp
  +++ b/src/wallet/wallet.cpp
  @@ -1671,6 +1671,7 @@ CBlockIndex* CWallet::ScanForWalletTransactions(CBlockIndex* pindexStart, CBlock
           }
           while (pindex && !fAbortRescan && !ShutdownRequested())
           {
  +            MilliSleep(500);
               if (pindex->nHeight % 100 == 0 && dProgressTip - dProgressStart > 0.0) {
                   double gvp = 0;
                   {
  ```
  3. start bitcoind with rescan flag, interrupt with CTRL+C and the output should look like:
  ```
  bitcoind -regtest -printtoconsole -rescan
  ...
  ^C2018-02-22 01:00:55 AddToWallet e8bfb4501b630ad2acb91e88ab0112a779766536d2c564b04faae45ae90e18f7
  2018-02-22 01:00:55 Rescan interrupted by shutdown request at block 5. Progress=1.000000
  2018-02-22 01:00:55  rescan                 1774ms
  2018-02-22 01:00:55 setKeyPool.size() = 1995
  2018-02-22 01:00:55 mapWallet.size() = 10145
  2018-02-22 01:00:55 mapAddressBook.size() = 3
  2018-02-22 01:00:55 Shutdown: In progress...
  2018-02-22 01:00:55 scheduler thread interrupt
  2018-02-22 01:00:55 Shutdown: done
  ```

Tree-SHA512: f9bebe2cdacf0359b6cbfcbc48ac2818a3ae7aa7822ff0c2c0de4ca2fff7c88493380b74a1c5ff2ce1de01fe605b0e5ef3576f124ea9cff8ef25a9e762477b92
2018-05-03 11:27:36 +02:00
Wladimir J. van der Laan ef006d9284
Merge #12928: qt: Initialize non-static class members that were previously neither initialized where defined nor in constructor
3fdc5fe Make sure initialization occurs in the constructor (practicalswift)
1e7813e Remove redundant initializations from the constructor (practicalswift)
f131872 Initialize non-static class members where they are defined (practicalswift)
73bc1b7 Initialize editStatus and autoCompleter. Previously not initialized where defined or in constructor. (practicalswift)

Pull request description:

  Initialize variables previously neither defined where defined nor in constructor:
  * `editStatus`
  * `autoCompleter`

  Also; initialize non-static class members where they are defined in accordance with developer notes.

Tree-SHA512: 84f0cb87ec8394ed7641bfa0731be2ec72e6a920e00ae206ff89e2e7c960358f603c52878311b24601a33aa7cba6ea4f9a78a8ade88112dea0f41efb08e84e25
2018-05-02 16:49:59 +02:00
Russell Yanofsky 21f5680553 Trivial: s/SetBestChain/ChainStateFlushed in comments after #13106 2018-05-02 10:02:48 -04:00
Wladimir J. van der Laan ff2ad2d569 Add missing newlines to LogPrint debug logging
The linter only checked `LogPrintf`, not `LogPrint`.
Fix the remaining cases.
2018-05-02 15:14:04 +02:00
practicalswift 3fdc5fee18 Make sure initialization occurs in the constructor 2018-05-02 13:56:20 +02:00
Wladimir J. van der Laan 598db389c3
Merge #13106: Simplify semantics of ChainStateFlushed callback
9cb6cdc Simplify semantics of ChainStateFlushed callback (Matt Corallo)
50b6533 scripted-diff: Rename SetBestChain callback ChainStateFlushed (Matt Corallo)

Pull request description:

  Previously, ChainStateFlushed would fire either if a full flush
  completed (which can happen due to memory limits, forced flush, or
  on its own DATABASE_WRITE_INTERVAL timer) *or* on a
  ChainStateFlushed-specific DATABASE_WRITE_INTERVAL timer. This is
  both less clear for clients (as there are no guarantees about a
  flush having actually happened prior to the call), and reults in
  extra flushes not clearly intended by the code. We drop the second
  case, providing a strong guarantee without removing the periodit
  timer-based flushing.

  This is a follow-up to discussion in #11857.

Tree-SHA512: 22ba3a0954d265d28413dbf87040790ca5b439820ee7bbadab14028295ec190de82ce5cd664426c82e58b706dc84278868026fa8d066702eb6e6962c9ace1f8e
2018-05-02 13:11:52 +02:00
João Barbosa c4fda7672a wallet: Interrupt rescan on shutdown request 2018-05-02 11:58:02 +01:00
practicalswift 29c9bdcc14 Handle unsuccessful fseek(...):s 2018-05-02 12:12:55 +02:00
practicalswift 0bd4cd398b logging: remove unused return value from LogPrintStr
`LogPrintStr` returns the number of characters printed. This number is
doubled if both logging to console and logging to file is enabled. As
the return value is never used, I've opted to remove it instead of try
to fix it.

Credit: @laanwj
2018-05-02 11:25:20 +02:00
practicalswift 76f344de6d logging: Fix potential use-after-free in LogPrintStr(...) 2018-05-02 10:43:17 +02:00
marcoagner 12ad33a8e4
[doc] qt: fixes broken link on readme 2018-05-01 21:17:54 +01:00
Chun Kuan Lee ddebde71ef Add Windows shutdown handler 2018-05-01 19:39:00 +08:00
Pieter Wuille 5a666428b0
Merge #12954: util: Refactor logging code into a global object
8c2d695c4a util: Store debug log file path in BCLog::Logger member. (Jim Posen)
8e7b961388 scripted-diff: Rename BCLog::Logger member variables. (Jim Posen)
1eac317f25 util: Refactor GetLogCategory. (Jim Posen)
3316a9ebb6 util: Encapsulate logCategories within BCLog::Logger. (Jim Posen)
6a6d764ca5 util: Move debug file management functions into Logger. (Jim Posen)
f55f4fcf05 util: Establish global logger object. (Jim Posen)

Pull request description:

  This is purely a refactor with no behavior changes.

  This creates a new class `BCLog::Logger` to encapsulate all global logging configuration and state.

Tree-SHA512: b34811f54a53b7375d7b6f84925453c6f2419d21179379ee28b3843d0f4ff8e22020de84a5e783453ea927e9074e32de8ecd05a6fa50d7bb05502001aaed8e53
2018-04-30 19:21:14 -07:00
Wladimir J. van der Laan 783bb6455e
Merge #13028: Make vpwallets usage thread safe
e2f58f4 wallet: Make vpwallets usage thread safe (João Barbosa)

Pull request description:

  This PR turns the functions introduced in #13017 thread safe. This is required to correctly support dynamically loading wallets, which is implemented in #10740.

Tree-SHA512: efaa09e501636cf957aa33de83719ce09dc0c2a19daff741a94ef10d6b7ba5dee538355b80c96ead995140f99f5df0c92fb0e22ae1adb8f397eb478280c8d8c7
2018-04-30 17:26:30 +02:00
practicalswift 56921f9369 wallet: Add Clang thread safety annotations for variables guarded by cs_db 2018-04-30 11:42:20 +02:00
practicalswift 244f4baf0f scheduler: Add Clang thread safety annotations for variables guarded by m_cs_callbacks_pending 2018-04-30 11:17:06 +02:00
mryandao f7c414daa9 nit: fix typo for entry description string 2018-04-30 11:41:09 +10:00
Jim Posen 8c2d695c4a util: Store debug log file path in BCLog::Logger member.
This breaks the cyclic between logging and util.
2018-04-29 14:37:19 -07:00
Jim Posen 8e7b961388 scripted-diff: Rename BCLog::Logger member variables.
-BEGIN VERIFY SCRIPT-
sed -i "s/fileout/m_fileout/" src/logging.h src/logging.cpp
sed -i "s/mutexDebugLog/m_file_mutex/" src/logging.h src/logging.cpp
sed -i "s/vMsgsBeforeOpenLog/m_msgs_before_open/" src/logging.h src/logging.cpp
sed -i "s/logCategories/m_categories/" src/logging.h src/logging.cpp
sed -i "s/fPrintToConsole/m_print_to_console/" src/logging.h src/logging.cpp src/init.cpp
sed -i "s/fPrintToDebugLog/m_print_to_file/" src/logging.h src/logging.cpp src/init.cpp src/test/test_bitcoin.cpp src/bench/bench_bitcoin.cpp
sed -i "s/fLogTimestamps/m_log_timestamps/" src/logging.h src/logging.cpp src/init.cpp
sed -i "s/fLogTimeMicros/m_log_time_micros/" src/logging.h src/logging.cpp src/init.cpp
sed -i "s/fReopenDebugLog/m_reopen_file/" src/logging.h src/logging.cpp src/init.cpp
sed -i "s/fStartedNewLine/m_started_new_line/" src/logging.h src/logging.cpp
-END VERIFY SCRIPT-
2018-04-29 14:37:17 -07:00
Jim Posen 1eac317f25 util: Refactor GetLogCategory.
Changing parameter types from pointers to references and uint32_t to
BCLog::LogFlags simplies calling code.
2018-04-29 14:37:17 -07:00
practicalswift 8499f15e67 Add Clang thread safety annotations for variables guarded by cs_warnings 2018-04-29 22:29:53 +02:00
practicalswift cf13ad23d4 Add Clang thread safety annotations for variables guarded by cs_nTimeOffset 2018-04-29 22:29:42 +02:00
practicalswift 012dec0347 Add Clang thread safety annotations for variables guarded by cs_rpcWarmup 2018-04-29 22:29:26 +02:00
MarcoFalke 3315007e03
Merge #13077: Add compile time checking for all cs_KeyStore runtime locking assertions
66dc662c8a Add compile time checking for all cs_KeyStore runtime locking assertions (practicalswift)

Pull request description:

  Add compile time checking for all `cs_KeyStore` runtime locking assertions.

  This PR is a subset of #12665. The PR was broken up to make reviewing easier.

  The intention is that literally all `EXCLUSIVE_LOCKS_REQUIRED`/`LOCKS_EXCLUDED`:s added in this PR should follow either directly or indirectly from `AssertLockHeld(…)`/`AssertLockNotHeld(…)`:s already existing in the repo.

  Consider the case where function `A(…)` contains `AssertLockHeld(cs_foo)` (without
  first locking `cs_foo` in `A`), and that `B(…)` calls `A(…)` (without first locking `cs_main`):
  * It _directly_ follows that: `A(…)` should have an `EXCLUSIVE_LOCKS_REQUIRED(cs_foo)` annotation.
  * It _indirectly_ follows that: `B(…)` should have an `EXCLUSIVE_LOCKS_REQUIRED(cs_foo)` annotation.

Tree-SHA512: 84ee5459e7f75f9affaa4275cb760576ab0e26da8a48b9a4a59b51a25418fe4b862ba832cb01312479a8c9b0e38ee8b6c4076bcbbd73213346d09ec2057fc9f1
2018-04-27 21:47:29 -04:00
Jim Posen 3316a9ebb6 util: Encapsulate logCategories within BCLog::Logger. 2018-04-27 16:10:02 -07:00