Commit graph

11124 commits

Author SHA1 Message Date
MarcoFalke b55555da3e
rpc: Add testmempoolaccept 2018-03-24 11:17:08 -04:00
Gregory Sanders cf6ef3c139 shuffle sendmany recipients ordering to shuffle tx outputs 2018-03-23 08:56:08 -04:00
Wladimir J. van der Laan cead84b72d
Merge #11536: Rename account to label where appropriate
d2527bd Rename wallet_accounts.py test (Russell Yanofsky)
045eeb8 Rename account to label where appropriate (Russell Yanofsky)

Pull request description:

  Rename account to label where appropriate

  This change only updates strings and adds RPC aliases, but should simplify the implementation of address labels in https://github.com/bitcoin/bitcoin/pull/7729, by getting renaming out of the way and letting that change focus on semantics.

  The difference between accounts and labels is that labels apply only to addresses, while accounts apply to both addresses and transactions (transactions have "from" and "to" accounts). The code associating accounts with transactions is clumsy and unreliable so we would like get rid of it.

  ---

  There is a rebased version of #7729 atop this PR at https://github.com/ryanofsky/bitcoin/commits/pr/label, see https://github.com/bitcoin/bitcoin/pull/7729#issuecomment-338417139.

Tree-SHA512: b3f934e612922d6290f50137f8ba71ddfaea4485713c7d97e89400a8b73b09b254f9186dffa462c77f5847721f5af9852b5572ade5443d8ee95dd150b3edb7ff
2018-03-22 21:27:53 +01:00
Wladimir J. van der Laan 9552dfb1f6
Merge #12694: Actually disable BnB when there are preset inputs
081bf54 Test that BnB is not used when there are preset inputs (Andrew Chow)
6ef9982 Actually disable BnB when there are preset inputs (Andrew Chow)

Pull request description:

  We don't want to use BnB when there are preset inputs because there
  is some weirdness with making that work with using the KnapsackSolver
  as the fallback. Currently we say that we haven't used bnb when
  there are preset inputs, but we don't actually disable BnB. This fixes
  that.

  I thought this was done originally. I guess it got lost in a rebase somewhere.

Tree-SHA512: 9792c0cdd0736866bddbed20f10b8050104955dc589fba49a0bd61a582ba491c921af2cdcc2269678b7b69275dad5fcf89c71b75c28733c7bacbe52e55891b9c
2018-03-22 21:13:13 +01:00
MarcoFalke f686002a8e
Merge #12742: Make FastRandomContext support standard C++11 RNG interface
1ec1602a45 Make FastRandomContext support standard C++11 RNG interface (Pieter Wuille)

Pull request description:

  This makes it possible to plug it into the various standard C++11 random distribution algorithms and other functions like `std::shuffle`.

Tree-SHA512: 935eae9c4fae31e1964c16d9cf9d0fcfa899e04567f010d8b3e1ff824e55e2392aa838ba743d03c1b2a5010c5b8da04343f453983dfeed83747d85828a564713
2018-03-22 12:21:46 -04:00
Wladimir J. van der Laan c290508a5e
Merge #12630: Provide useful error message if datadir is not writable.
8674e74 Provide relevant error message if datadir is not writable. (murrayn)

Pull request description:

  If the --datadir exists, but is not writable, the current error message on startup is 'Cannot obtain a lock on data directory foo. Bitcoin Core is probably already running.' This is misleading.

  I believe this PR addresses #11668, although the issue is not Windows-specific.

Tree-SHA512: 10cbbaea433072aee4fb3e8938a72073c7a5c841f7a7685c9e12549c322b2925c7d34bac254ac33021b23132bfc352c058712bc9542298cf86f8fd9757f528b2
2018-03-22 15:14:43 +01:00
Wladimir J. van der Laan a6926b065d
Merge #12048: Use best-fit strategy in Arena, now O(log(n)) instead O(n)
5fbf7c4 fix nits: variable naming, typos (Martin Ankerl)
1e0ee90 Use best-fit strategy in Arena, now O(log(n)) instead O(n) (Martin Ankerl)

Pull request description:

  This replaces the first-fit algorithm used in the Arena with a best-fit. According to "Dynamic Storage Allocation: A Survey and Critical Review", Wilson et. al. 1995, http://www.scs.stanford.edu/14wi-cs140/sched/readings/wilson.pdf, both startegies work well in practice.

  The advantage of using best-fit is that we can switch the O(n) allocation to O(log(n)). Additionally, some previously O(log(n)) operations are now O(1) operations by using hash maps. The end effect is that the benchmark runs about 2.5 times faster on my machine:

      # Benchmark, evals, iterations, total, min, max, median
      old: BenchLockedPool, 5, 530, 5.25749, 0.00196938, 0.00199755, 0.00198172
      new: BenchLockedPool, 5, 1300, 5.11313, 0.000781493, 0.000793314, 0.00078606

  I've run all unit tests and benchmarks, and increased the number of iterations so that BenchLockedPool takes about 5 seconds again.

Tree-SHA512: 6551e384671f93f10c60df530a29a1954bd265cc305411f665a8756525e5afe2873a8032c797d00b6e8c07e16d9827465d0b662875433147381474a44119ccce
2018-03-22 14:28:37 +01:00
Wladimir J. van der Laan ad823178e8
Merge #12704: base58: use map instead of strchr() when decode
bcab47b use base58 map instead of strchr() (Kevin Pan)

Pull request description:

  Use array map instead of find string position.

  Test code snippet:

  ```cpp

  #include <assert.h>
  #include <stdint.h>
  #include <stdio.h>
  #include <stdlib.h>

  #include <string>

  int main(int argc, const char * argv[]) {

    static const char* pszBase58 = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz";
    static const int8_t mapBase58[] = {
      -1,-1,-1,-1,-1,-1,-1,-1, -1,-1,-1,-1,-1,-1,-1,-1,
      -1,-1,-1,-1,-1,-1,-1,-1, -1,-1,-1,-1,-1,-1,-1,-1,
      -1,-1,-1,-1,-1,-1,-1,-1, -1,-1,-1,-1,-1,-1,-1,-1,
      -1, 0, 1, 2, 3, 4, 5, 6,  7, 8,-1,-1,-1,-1,-1,-1,
      -1, 9,10,11,12,13,14,15, 16,-1,17,18,19,20,21,-1,
      22,23,24,25,26,27,28,29, 30,31,32,-1,-1,-1,-1,-1,
      -1,33,34,35,36,37,38,39, 40,41,42,43,-1,44,45,46,
      47,48,49,50,51,52,53,54, 55,56,57,-1,-1,-1,-1,-1,
    };

    const std::string b58Str(pszBase58);

    for (size_t i = 0; i < b58Str.length(); i++) {
      const char *ch = strchr(pszBase58, b58Str[i]);
      printf("%d - %d\n", ch - pszBase58, mapBase58[(uint8_t)b58Str[i]]);
      assert(ch - pszBase58 == mapBase58[(uint8_t)b58Str[i]]);
    }

    assert(mapBase58['1'] == 0);
    assert(mapBase58['z'] == 57);

    /** All alphanumeric characters except for "0", "I", "O", and "l" */
    assert(mapBase58['0'] == -1);
    assert(mapBase58['I'] == -1);
    assert(mapBase58['O'] == -1);
    assert(mapBase58['l'] == -1);

    return 0;
  }

  ```

Tree-SHA512: c28376dc8c92cc4a770c3282db4a568ae5f5a08e27f714183eb3d8755421dc7aa11d7b45afa55e70eba46565f378062aac53dc8f150eeeab12ce7b5db5af89c5
2018-03-22 10:00:10 +01:00
Pieter Wuille e0f7515f55
Merge #12750: Replace boost::call_once with std::call_once
57dae3fc4a Replace boost::call_once with std::call_once (donaloconnor)

Pull request description:

  This replaces boost::call_once with the C++11 std::call_once. The aim is to remove unnecessary boost code.

  Tested on Windows/MSVC

Tree-SHA512: 5e98ea6e5052fffeaf29f845f4ecf1078b38cbb27671c5b7b6167e7f074a391e10020445107979d9e220d029bc9464fb8b2ccb0bea664eeb7af59a789c988b10
2018-03-21 16:01:21 -07:00
MarcoFalke 2b1c50b935
Merge #12747: Fix typos
d27327c79a Fix typos (practicalswift)

Pull request description:

  Fix typos.

Tree-SHA512: f0d13d991acdec0d3adc2f091cd00ccbdda6da3c7623dfb4cbf698bac9eb6b3d88c8ad121256a96cb130f8e97bf54892f3616da0e8dc833dcf713ca7949e2801
2018-03-21 18:04:04 -04:00
donaloconnor 57dae3fc4a Replace boost::call_once with std::call_once 2018-03-21 20:02:45 +00:00
Wladimir J. van der Laan 310dc61ea3
Merge #12723: Qt5: Warning users about invalid-BIP21 URI bitcoin://
b7fbcc5 Qt: Warn users about invalid-BIP21 URI bitcoin:// (Alexey Ivanov)

Pull request description:

  This change affects only Qt5 users, since Qt4 QUrl don't forces lower case for urls. Also bitcoin-qt builds against Qt4 on linux.

  PR for #11645

Tree-SHA512: 6b8cb18b29dbd2754e190a662ed67274a7f0decc6adb00b7e1af107d5f8ea2845b668cf28d6ccf2f1d15e8ef212f5a76910810634a4c15e7fabd1dd2072e7232
2018-03-21 16:57:27 +01:00
MarcoFalke 4ad3b3c72c
Merge #12716: Fix typos and cleanup in various files
4d9b4256d8 Fix typos (Dimitris Apostolou)

Pull request description:

  Unfortunately I messed up my repo while trying to squash #12593 so I created a PR with just the correct fixes.

Tree-SHA512: 295d77b51bd2a9381f1802c263de7ffb2edd670d9647391e32f9a414705b3c8b483bb0e469a9b85ab6a70919ea13397fa8dfda2aea7a398b64b187f178fe6a06
2018-03-21 11:17:43 -04:00
Alexey Ivanov b7fbcc53d0 Qt: Warn users about invalid-BIP21 URI bitcoin:// 2018-03-21 15:40:08 +03:00
practicalswift d27327c79a Fix typos 2018-03-21 10:54:17 +01:00
Dimitris Apostolou 4d9b4256d8 Fix typos 2018-03-21 08:34:44 +02:00
Pieter Wuille 1ec1602a45 Make FastRandomContext support standard C++11 RNG interface
This makes it possible to plug it into the various standard C++11 random
distribution algorithms and other functions like std::shuffle.
2018-03-20 21:24:49 -07:00
Kevin Pan bcab47bc1b use base58 map instead of strchr() 2018-03-21 11:57:57 +08:00
Russell Yanofsky 34ca750320 Remove unnecessary NONNEGATIVE_SIGNED
Switch to unsigned encoding, which is backwards compatible and avoids MSVC
error reported https://github.com/bitcoin/bitcoin/issues/12732
2018-03-20 13:07:17 -04:00
Wladimir J. van der Laan 55f490a79f
Merge #12652: bitcoin-cli: Provide a better error message when bitcoind is not running
8b2ef27 tests: Test connecting with non-existing RPC cookie file (practicalswift)
a2b2476 tests: Test connecting to a non-existing server (practicalswift)
de04fde bitcoin-cli: Provide a better error message when bitcoind is not running (practicalswift)

Pull request description:

  Provide a better `bitcoin-cli` error message when `bitcoind` is not running.

  Before this patch:

  ```
  $ killall -9 bitcoind
  $ bitcoin-cli -testnet echo 'hello world'
  error: Could not locate RPC credentials. No authentication cookie could be found, and RPC password is not set.  See -rpcpassword and -stdinrpcpass.  Configuration file: (/root/.bitcoin/bitcoin.conf)
  ```

  After this patch:

  ```
  $ killall -9 bitcoind
  $ bitcoin-cli -testnet echo 'hello world'
  error: Could not connect to the server 127.0.0.1:18332

  Make sure the bitcoind server is running and that you are connecting to the correct RPC port.
  ```

Tree-SHA512: bb16e1a9a1ac110ee202c3cb99b5d7c5c1e5487a17e6cd101e12dc69e9525c14dc71f37b128c26ad615369a57547f15d0f1e29b207c1b2f2ee4b4ba7105f3433
2018-03-20 10:42:10 +01:00
Wladimir J. van der Laan e476826338
Merge #12721: Qt: remove "new" button during receive-mode in addressbook
d843db7 Qt: remove "new" button during receive-mode in addressbook (Jonas Schnelli)

Pull request description:

  There are currently two ways how to generate new receiving addresses in the GUI (which leads to code duplication or required refactoring, see #12520).

  Since the address-book is probably something that should be removed in the long run, suppressing the new-button in receive-mode could be a first step in deprecating the address book.

  With this PR, users can still edit existing receiving address book entries and they can still create new sending address book entries.

Tree-SHA512: abe8d1b44bc3e1b53826ccf9d2b3f764264337758d95ca1fe1ef1bac72d47608cf454055fce3720e06634f0a5841a752ce643b4505b47d6e322b6fc71296e961
2018-03-20 09:15:22 +01:00
MarcoFalke 8ee5c7b747
Merge #12727: [RPC] Remove unreachable help conditions in rpcwallet.cpp
e5468a19d1 Remove unreachable help conditions (lutangar)

Pull request description:

  These conditions on `request.fHelp`, which appears in the body of the following functions are never reached:
  * `walletpassphrase`
  * `walletpassphrasechange`
  * `encryptwallet`
  ```
  ...
      if (request.fHelp || request.params.size() != 0) {
          throw std::runtime_error("");
      }
  ...
      if (request.fHelp)
          return true;
  ...
  ```
  The first condition would throw if `request.fHelp` evaluates to `true`.

Tree-SHA512: 1aa41ed233c6bebae27151ab5cc67144d2a408335a3acef3c103e144d6343685f360b1146e14bc8dc1d53d00fcfc6ff1ab6a0eeb0805191172a23b306ab50b79
2018-03-19 16:49:55 -04:00
Wladimir J. van der Laan ee7b67e278
Merge #9753: Add static_assert to prevent VARINT(<signed value>)
499d95e27 Add static_assert to prevent VARINT(<signed value>) (Russell Yanofsky)

Pull request description:

  Using VARINT with signed types is dangerous because negative values will appear to serialize correctly, but then deserialize as positive values mod 128.

  This commit changes the VARINT macro to trigger a compile error by default if called with an signed value, and it updates existing broken uses of VARINT to pass a special flag that lets them keep working with no changes in behavior.

  There is some discussion about this issue here: https://github.com/bitcoin/bitcoin/pull/9693#issuecomment-278701473. I think another good change along these lines would be to make `GetSizeOfVarInt` and `WriteVarInt` throw exceptions if they are passed numbers less than 0 to serialize. But unlike this change, that would be a change in runtime behavior, and need more consideration.

Tree-SHA512: 082c65598cfac6dc1da042bdb47dbc9d5d789fc849fe52921cc238578588f4e5ff976c8b4b2ce42cb75290eb14f3b42ea76e26202c223c5b2aa63ef45c2ea3cc
2018-03-19 17:26:43 +01:00
Wladimir J. van der Laan ebdf84c960
Merge #12700: Document RPC method aliasing
4c317d89e Document RPC method aliasing (Russell Yanofsky)

Pull request description:

  Suggested by @Sjors in https://github.com/bitcoin/bitcoin/pull/11536#issuecomment-372820660

Tree-SHA512: 7bf16238e41b6c6c078e9103d8eac2ac76739a2c16b4f964be49bfde1f20f31a1fb30badf1faaa6ddc301a74f0d785d19567069b50de78c502144479143cb38c
2018-03-19 17:17:57 +01:00
Wladimir J. van der Laan c39dd2ef59
Merge #12408: wallet: Change output type globals to members
fab8a6f60 wallet: Change output type globals to members (MarcoFalke)

Pull request description:

  Output type is used by the wallet when generating addresses or transactions with change, thus it should be a member of `CWallet`.

  Moreover, in light of multiwallet, it makes sense to prepare for per-wallet attributes instead of for-all-wallets globals.

Tree-SHA512: 4fa397cd82522e5bacf4870160a2a0f5e1f2dc046e4b9e2514dee18b187a0e1724d036315f77fa48e48f85533021d5e5525d798160a92d389d75512f3f9e1405
2018-03-19 17:05:35 +01:00
Russell Yanofsky 045eeb8870 Rename account to label where appropriate
This change only updates strings and adds RPC aliases, but should simplify the
implementation of address labels in
https://github.com/bitcoin/bitcoin/pull/7729, by getting renaming out of the
way and letting it focus on semantics.

The difference between accounts and labels is that labels apply only to
addresses, while accounts apply to both addresses and transactions
(transactions have "from" and "to" accounts). The code associating accounts
with transactions is clumsy and unreliable so we would like get rid of it.
2018-03-19 12:05:35 -04:00
lutangar e5468a19d1 Remove unreachable help conditions 2018-03-19 16:48:40 +01:00
Wladimir J. van der Laan 6324c68aa0
Merge #12678: build: Fix a few compilation issues with Clang 7 and -Werror
8ae413235 Remove redundant checks for MSG_* from configure.ac (Vasil Dimov)
71129e026 Do not check for main() in libminiupnpc (Vasil Dimov)
8c632f73c ax_boost_{chrono,unit_test_framework}.m4: take changes from upstream (Vasil Dimov)

Pull request description:

Tree-SHA512: a99ef98c0b94f892eadeda24b3d55c25bedf225b98c6e4178cf6c2d886b44d43e9f75414d0b37db9ac261cec2350666e5e64fab9c104249dd34ff485c51663cb
2018-03-19 16:05:57 +01:00
Jonas Schnelli d843db7733
Qt: remove "new" button during receive-mode in addressbook 2018-03-19 12:13:08 +07:00
MarcoFalke fab8a6f609
wallet: Change output type globals to members 2018-03-17 16:10:01 -04:00
Pieter Wuille af20f9b1d4
Merge #12542: Remove redundant includes. Conform to header include guidelines.
7ef46d063a Remove redundant includes. Conform to header include guidelines. (practicalswift)

Pull request description:

  From the header include guidelines ([developer-notes.md](https://github.com/bitcoin/bitcoin/blob/master/doc/developer-notes.md#source-code-organization)):

  > "One exception is that a `.cpp` file does not need to re-include the includes already included in its corresponding `.h` file."

  Covered in this PR:
  * `rpc/util.h` includes `pubkey.h` + `utilstrencodings.h`. `rpc/util.cpp` includes `rpc/util.h`.
  * `util.h` includes `fs.h`. `util.cpp` includes `util.h`.

Tree-SHA512: a38d9ecefd8165ad151c1ffde52cfbac968526c49db2080988bf6e6a3daa2ebeceb34d08f817e275edf7c650bf3155de01369bfb352522f8e0ae136b2289b194
2018-03-16 16:59:27 -07:00
Pieter Wuille 7be9a9a570
Merge #12683: Fix more constness violations in serialization code
172f5fa738 Support deserializing into temporaries (Pieter Wuille)
2761bca997 Merge READWRITEMANY into READWRITE (Pieter Wuille)

Pull request description:

  This is another fragment of improvements from #10785.

  The current serialization code does not support serializing/deserializing from/to temporaries (like `s >> CFlatData(script)`). As a result, there are many invocations of the `REF` macro which in addition to changing the reference type also changes the constness. This is unnecessary in C++11 as we can use rvalue references now instead.

  The first commit is an extra simplification we can make that removes the duplication of code between `READWRITE` and `READWRITEMANY` (and related functions).

Tree-SHA512: babfa9cb268cc3bc39917e4f0a90e4651c33d85032161e16547a07f3b257b7ca7940e0cbfd69f09439d26fafbb1a6cf6359101043407e2c7aeececf7f20b6eed
2018-03-15 16:57:55 -07:00
Russell Yanofsky 499d95e278 Add static_assert to prevent VARINT(<signed value>)
Using VARINT with signed types is dangerous because negative values will appear
to serialize correctly, but then deserialize as positive values mod 128.

This commit changes the VARINT macro to trigger an error by default if called
with an signed value, and updates broken uses of VARINT to pass a special flag
that lets them keep working with no change in behavior.
2018-03-15 18:57:55 -05:00
Pieter Wuille 2bac3e4841
Merge #12621: Avoid querying unnecessary model data when filtering transactions
1ee72a819f qt: Avoid querying unnecessary model data when filtering transactions (João Barbosa)

Pull request description:

  This change moves down model data querying to where it's needed. The worst case remains the same (all data is queried and the row passes) but for the average case it improves the filter performance.

Tree-SHA512: 3bcaced029cb39dfbc5377246ce76634f9050ee3a3053db4d358fcbf4d8107c649e75841f21d69f1aebcaf1bbffe3eac784e6b03b366fdbbfec1e0da8f78d8ef
2018-03-15 16:45:07 -07:00
Pieter Wuille df529dcc65
Merge #12693: Remove unused variable in SortForBlock
bb079a0e2c Remove unused variable in SortForBlock (Drew Rasmussen)

Pull request description:

  Although txiter is passed to BlockAssembler::SortForBlock, it is never used. Other than BlockAssembler::addPackageTxs, no other method ever makes a call to SortForBlock, thus making this change harmless.

Tree-SHA512: c7df948c5f75f7371844200e0227a26476437f300148d29020e01041b382f5bda31d9c520c9c5425aee88ce8f4a52cd0e594985d69ed8a081b878cda2e4de8c5
2018-03-15 16:31:02 -07:00
Russell Yanofsky 4c317d89e9 Document RPC method aliasing
Suggested by Sjors Provoost <sjors@sprovoost.nl> in
https://github.com/bitcoin/bitcoin/pull/11536#issuecomment-372820660
2018-03-15 16:37:57 -04:00
Andrew Chow 081bf54ee4 Test that BnB is not used when there are preset inputs 2018-03-15 15:22:31 -04:00
Vasil Dimov 8ae413235d
Remove redundant checks for MSG_* from configure.ac
It is redundant to check for the presence of MSG_NOSIGNAL macro in
configure.ac, define HAVE_MSG_NOSIGNAL and then check whether the later
is defined in the source code. Instead we can check directly whether
MSG_NOSIGNAL is defined. Same for MSG_DONTWAIT.

In addition to that, the checks we had in configure.ac produce a
compiler warning about unused variable and thus could fail if
-Werror is present and erroneously proclaim that the macros are
not available.
2018-03-15 20:02:00 +01:00
Wladimir J. van der Laan 947c25ead2
Merge #12431: Only call NotifyBlockTip when chainActive changes
f98b54352 Only call NotifyBlockTip when the active chain changes (James O'Beirne)
152b7fb25 [tests] Add a (failing) test for waitforblockheight (James O'Beirne)

Pull request description:

  This is a subset of the more controversial https://github.com/bitcoin/bitcoin/pull/12407, but this also adds a test demonstrating the bug.

  In InvalidateBlock, we're calling NotifyBlockTip with the now-invalid block's prev regardless of what chain the ancestor block is on. This could create numerous issues, but it at least screws up `waitforblockheight` (or anything else relying on `rpc/blockchain.cpp:latestblock`) when InvalidateBlock is called on a block not in chainActive, which can happen via RPC.

  Only call NotifyBlockTip when the block being marked invalid is on the active chain.

Tree-SHA512: 9a54fe5e8c7eb489daf5df4483c0986129e871e2ca931a456ba869ecb5d5a8d4f7bd27ccc9e711e9292c9ed79ddef896c85d0e81fc76883503e327995b0e914f
2018-03-15 17:05:43 +01:00
Andrew Chow 6ef99826b9 Actually disable BnB when there are preset inputs
We don't want to use BnB when there are preset inputs because there
is some weirdness with making that work with using the KnapsackSolver
as the fallback. Currently we say that we haven't used bnb when
there are preset inputs, but we don't actually disable BnB. This fixes
that.
2018-03-15 02:42:18 -04:00
Drew Rasmussen bb079a0e2c Remove unused variable in SortForBlock 2018-03-14 23:10:39 -07:00
murrayn 8674e74b47 Provide relevant error message if datadir is not writable. 2018-03-14 19:07:30 -07:00
Wladimir J. van der Laan e057589dc6
Merge #10637: Coin Selection with Murch's algorithm
73b5bf2cb Add a test to make sure that negative effective values are filtered (Andrew Chow)
76d2f068a Benchmark BnB in the worst case where it exhausts (Andrew Chow)
6a34ff533 Have SelectCoinsMinConf and SelectCoins use BnB or Knapsack and use it (Andrew Chow)
fab04887c Add a GetMinimumFeeRate function which is wrapped by GetMinimumFee (Andrew Chow)
cd927ff32 Move original knapsack solver tests to coinselector_tests.cpp (Andrew Chow)
fb716f7b2 Move current coin selection algorithm to coinselection.{cpp,h} (Andrew Chow)
4566ab75f Add tests for the Branch and Bound algorithm (Andrew Chow)
4b2716da4 Remove coinselection.h -> wallet.h circular dependency (Andrew Chow)
7d77eb1a5 Use a struct for output eligibility (Andrew Chow)
ce7435cf1 Move output eligibility to a separate function (Andrew Chow)
0185939be Implement Branch and Bound coin selection in a new file (Andrew Chow)
f84fed8eb Store effective value, fee, and long term fee in CInputCoin (Andrew Chow)
12ec29d3b Calculate and store the number of bytes required to spend an input (Andrew Chow)

Pull request description:

  This is an implementation of the [Branch and Bound coin selection algorithm written by Murch](http://murch.one/wp-content/uploads/2016/11/erhardt2016coinselection.pdf) (@xekyo). I have it set so this algorithm will run first and if it fails, it will fall back to the current coin selection algorithm. The coin selection algorithms and tests have been refactored to separate files instead of having them all in wallet.cpp.

  I have added some tests for the new algorithm and a test for all of coin selection in general. However, more tests may be needed, but I will need help with coming up with more test cases.

  This PR uses some code borrowed from #10360 to use effective values when selecting coins.

Tree-SHA512: b0500f406bf671e74984fae78e2d0fbc5e321ddf4f06182c5855e9d1984c4ef2764c7586d03e16fa4b578c340b21710324926f9ca472d5447a0d1ed43eb4357e
2018-03-14 18:01:36 +01:00
Wladimir J. van der Laan 56cc022112
Merge #12080: Add support to search the address book
c316fdf [qt] Add support to search the address book (João Barbosa)

Pull request description:

  This PR adds support to search the address book for both receiving and sending addresses.

  A specialisation of the `QSortFilterProxyModel` is added to implement the custom filtering.

  <img width="757" alt="screen shot 2018-01-03 at 16 05 57" src="https://user-images.githubusercontent.com/3534524/34528196-0347d61e-f0a0-11e7-9bd3-535e9e34ceb8.png">
  <img width="759" alt="screen shot 2018-01-03 at 16 00 58" src="https://user-images.githubusercontent.com/3534524/34528202-07c99f24-f0a0-11e7-8e34-cff6a1ba2364.png">

  Closes #623.

Tree-SHA512: 316e646015c858fc70db6be72dc7922d5bb10a3399e7fa327c992e184cc37a124f11cffefab2dbe0d16bda790c7c0437db364686e66c40b4054b8250b4be15d0
2018-03-14 15:25:34 +01:00
Vasil Dimov 2b3ea39de4
Polish interfaces around PeerLogicValidation
* Make PeerLogicValidation final to prevent deriving from it [1]
* Prevent deletions of NetEventsInterface and CValidationInterface
  objects via a base class pointer

[1] silences the following compiler warning (from Clang 7.0.0):

/usr/include/c++/v1/memory:2285:5: error: delete called on non-final 'PeerLogicValidation' that has
      virtual functions but non-virtual destructor [-Werror,-Wdelete-non-virtual-dtor]
    delete __ptr;
    ^
/usr/include/c++/v1/memory:2598:7: note: in instantiation of member function
      'std::__1::default_delete<PeerLogicValidation>::operator()' requested here
      __ptr_.second()(__tmp);
      ^
init.cpp:201:15: note: in instantiation of member function 'std::__1::unique_ptr<PeerLogicValidation,
      std::__1::default_delete<PeerLogicValidation> >::reset' requested here
    peerLogic.reset();
                  ^
2018-03-14 10:11:01 +01:00
Pieter Wuille 6acd8700bc
Merge #9680: Unify CWalletTx construction
b4bc32a451 [wallet] Get rid of CWalletTx default constructor (Russell Yanofsky)
a128bdc9e1 [wallet] Construct CWalletTx objects in CommitTransaction (Russell Yanofsky)

Pull request description:

  Two commits:

  - `Construct CWalletTx objects in CommitTransaction` moves a bunch of CWalletTx initialization into CWallet::CommitTransaction to dedup some code and avoid future inconsistencies in how wallet transactions are created.
  - `Get rid of CWalletTx default constructor` does what is described and eliminates the possibility of empty transaction entries being inadvertently created by mapWallet[hash] accesses.

  Both of these changes were originally part of #9381

Tree-SHA512: af3841c4f0539e0662d81b33c5369fc70aa06ddde1c59cb00fb21c9e4c7d9ff47f1edc5040cb463af1333838802c56b3ef875b939e2b804ee45b8e0294a4371c
2018-03-13 19:16:39 -07:00
Pieter Wuille 172f5fa738 Support deserializing into temporaries
Currently, the READWRITE macro cannot be passed any non-const temporaries, as
the SerReadWrite function only accepts lvalue references.

Deserializing into a temporary is very common, however. See for example
things like 's >> VARINT(n)'. The VARINT macro produces a temporary wrapper
that holds a reference to n.

Fix this by accepting non-const rvalue references instead of lvalue references.
We don't propagate the rvalue-ness down, as there are no useful optimizations
that only apply to temporaries.

Then use this new functionality to get rid of many (but not all) uses of the
'REF' macro (which casts away constness).
2018-03-13 17:04:31 -07:00
Pieter Wuille 2761bca997 Merge READWRITEMANY into READWRITE 2018-03-13 17:04:28 -07:00
Russell Yanofsky 33eb9071b9 Fix ComputeTimeSmart test failure with -DDEBUG_LOCKORDER
Failure looks like:

    Entering test case "ComputeTimeSmart"
    test_bitcoin: sync.cpp💯 void potential_deadlock_detected(const std::pair<void*, void*>&, const LockStack&, const LockStack&): Assertion `false' failed.
    unknown location(0): fatal error in "ComputeTimeSmart": signal: SIGABRT (application abort requested)
    wallet/test/wallet_tests.cpp(566): last checkpoint

Reproducible with:

    ./configure --enable-debug
    make -C src test/test_bitcoin && src/test/test_bitcoin --log_level=test_suite --run_test=wallet_tests/ComputeTimeSmart

Happens due to "92fabcd443 Add LookupBlockIndex function" which acquires
cs_main from inside CWallet::ComputeTimeSmart.
2018-03-13 19:41:38 -04:00
Wladimir J. van der Laan d42a4fe5aa
Merge #11041: Add LookupBlockIndex
92fabcd44 Add LookupBlockIndex function (João Barbosa)
43a32b739 Add missing cs_lock in CreateWalletFromFile (João Barbosa)
f814a3e8f Fix cs_main lock in LoadExternalBlockFile (João Barbosa)
c651df8b3 Lock cs_main while loading block index in AppInitMain (João Barbosa)
02de6a6bc Assert cs_main is held when accessing mapBlockIndex (João Barbosa)

Pull request description:

  Replace all `mapBlockIndex` lookups with the new `LookupBlockIndex()`. In some cases it avoids a second lookup.

Tree-SHA512: ca31118f028a19721f2191d86f2dd398144d04df345694575a64aeb293be2f85785201480c3c578a0ec99690516205708558c0fd4168b09313378fd4e60a8412
2018-03-13 19:12:35 +01:00