Commit graph

23467 commits

Author SHA1 Message Date
James O'Beirne
6d8affca96 test: refactor: clarify the coins simulation
Adds comments, slight refactor clarifications to make the code
easier to follow.
2023-01-20 10:36:52 -05:00
James O'Beirne
79cedc36af coins: add Sync() method to allow flush without cacheCoins drop
In certain circumstances, we may want to flush to disk without
emptying `cacheCoins`, which affects performance. UTXO snapshot
activation is one such case.

This method is currently unused and this commit does not
change any behavior.

Incorporates feedback from John Newbery.

Co-authored-by: Suhas Daftuar <sdaftuar@gmail.com>
2023-01-20 10:36:48 -05:00
Greg Sanders
f34ada89fd Add unit test for ComputeTapleafHash 2023-01-20 09:36:51 -05:00
willcl-ark
1134686ef9
mempool: Don't share mempool with dbcache in blocksonly
When -blockonly is set, reduce mempool size to 5MB unless -maxmempool
is also set.

See #9569
2023-01-20 12:53:13 +00:00
MarcoFalke
fafeddfe0e
rpc: Throw more user friendly arg type check error 2023-01-20 13:26:47 +01:00
dergoegge
9ab62d71fb [fuzz] Actually use mocked mempool in tx_pool target 2023-01-20 12:15:01 +01:00
fanquake
392dc68e37
Merge bitcoin/bitcoin#26924: refactor: Add missing includes to fix gcc-13 compile error
fadeb6b103 Add missing includes to fix gcc-13 compile error (MarcoFalke)

Pull request description:

  On current master:

  ```
    CXX      support/libbitcoin_util_a-lockedpool.o
  support/lockedpool.cpp: In member function ‘void Arena::free(void*)’:
  support/lockedpool.cpp:99:20: error: ‘runtime_error’ is not a member of ‘std’
     99 |         throw std::runtime_error("Arena: invalid or double free");
        |                    ^~~~~~~~~~~~~
  support/lockedpool.cpp:22:1: note: ‘std::runtime_error’ is defined in header ‘<stdexcept>’; did you forget to ‘#include <stdexcept>’?
     21 | #include <algorithm>
    +++ |+#include <stdexcept>
     22 | #ifdef ARENA_DEBUG
  support/lockedpool.cpp: In member function ‘void LockedPool::free(void*)’:
  support/lockedpool.cpp:320:16: error: ‘runtime_error’ is not a member of ‘std’
    320 |     throw std::runtime_error("LockedPool: invalid address not pointing to any arena");
        |                ^~~~~~~~~~~~~
  support/lockedpool.cpp:320:16: note: ‘std::runtime_error’ is defined in header ‘<stdexcept>’; did you forget to ‘#include <stdexcept>’?

ACKs for top commit:
  hebasto:
    ACK fadeb6b103.
  fanquake:
    ACK fadeb6b103 - tested this fixes compilation with GCC 13. I don't think theres a need to do anything else here, and that'd also just potentially complicate backporting.

Tree-SHA512: 99f79cf385c913138a9cf9fc23be0a3a067b0a28518b8bdc033a7220b85bbc5d18f5356c5bdad2f628c22abb87c18b232724f606eba6326c031518559054be31
2023-01-20 10:26:36 +00:00
MarcoFalke
eebc24bfc6
Merge bitcoin/bitcoin#26887: RPC: make RPCResult::MatchesType return useful errors
3d1a4d8a45 RPC: make RPCResult::MatchesType return useful errors (Anthony Towns)

Pull request description:

  Currently if you don't correctly update the description of the return value for an RPC call, you essentially just get an assertion failure with no useful information; this generates a description of the problems instead.

ACKs for top commit:
  MarcoFalke:
    re-ACK 3d1a4d8a45 🌷

Tree-SHA512: cf0580b7046faab0128672a74f8cc5a1655dfdca6646a2e38b51f0fb5f672c98aad6cd4c5769454a2d644a67da639ccb1c8ff5d24d3d6b4446a082398a643722
2023-01-20 10:37:23 +01:00
Andrew Chow
58da1619be
Merge bitcoin/bitcoin#25877: refactor: Do not use CScript for tapleaf scripts until the tapleaf version is known
dee89438b8 Abstract out ComputeTapbranchHash (Russell O'Connor)
8e3fc99427 Do not use CScript for tapleaf scripts until the tapleaf version is known (Russell O'Connor)

Pull request description:

  While BIP-341 calls the contents of tapleaf a "script", only in the case that the tapleaf version is `0xc0` is this script known to be a tapscript.  Otherwise the tapleaf "script" is simply an uninterpreted string of bytes.

  This PR corrects the issue where the type `CScript` is used prior to the tapleaf version being known to be a tapscript.  This prevents `CScript` methods from erroneously being called on non-tapscript data.

  A second commit abstracts out the TapBranch hash computation in the same manner that the TapLeaf computation is already abstracted.  These two abstractions ensure that the TapLeaf and TapBranch tagged hashes are always constructed properly.

ACKs for top commit:
  ajtowns:
    ACK dee89438b8
  instagibbs:
    ACK dee89438b8
  achow101:
    ACK dee89438b8
  sipa:
    ACK dee89438b8
  aureleoules:
    reACK dee89438b8 - I verified that there is no behavior change.

Tree-SHA512: 4a1d37f3e9a1890e7f5eadcf65562688cc451389581fe6e2da0feb2368708edacdd95392578d8afff05270d88fc61dce732d83d1063d84d12cf47b5f4633ec7e
2023-01-19 17:51:21 -05:00
Anthony Towns
3d1a4d8a45 RPC: make RPCResult::MatchesType return useful errors 2023-01-20 06:24:15 +10:00
MarcoFalke
fadeb6b103
Add missing includes to fix gcc-13 compile error 2023-01-19 19:30:10 +01:00
MarcoFalke
b5c88a5479
Merge bitcoin/bitcoin#26909: net: prevent peers.dat corruptions by only serializing once
5eabb61b23 addrdb: Only call Serialize() once (Martin Zumsande)
da6c7aeca3 hash: add HashedSourceWriter (Martin Zumsande)

Pull request description:

  There have been various reports of corruption of `peers.dat` recently, see #26599.
  As explained in [this post](https://github.com/bitcoin/bitcoin/issues/26599#issuecomment-1381082886) in more detail, the underlying issue is likely that we currently serialize `AddrMan` twice - once for the file stream, once for the hasher that helps create the checksum - and if `AddrMan` changes in between these two calls, the checksum doesn't match the data and the resulting `peers.dat` is corrupted.

  This PR attempts to fix this by introducing and using `HashedSourceWriter` - a class that keeps a running hash while serializing data, similar to the existing `CHashVerifier` which does the analogous thing while unserializing data. Something like this was suggested before, see https://github.com/bitcoin/bitcoin/pull/10248#discussion_r120694343.

  Fixes #26599 (not by changing the behavior in case of a crash, but by hopefully fixing the underlying cause of these corruptions).

ACKs for top commit:
  sipa:
    utACK 5eabb61b23
  naumenkogs:
    utACK 5eabb61b23

Tree-SHA512: f19ad37c37088d3a9825c60de2efe85cc2b7a21b79b9156024d33439e021443ef977a5f8424a7981bcc13d73d11e30eaa82de60e14d88b3568a67b03e02b153b
2023-01-19 16:03:08 +01:00
MarcoFalke
05e3468fb3
Merge bitcoin/bitcoin#26686: fuzz: Enable erlay setting in process_message(s) targets
58c2bbdb55 [fuzz] Enable erlay in process_message(s) targets (dergoegge)

Pull request description:

  The process_message(s) targets can't exercise the Erlay logic at the moment as the config setting is off by default and not switched on in the fuzz targets.

  This PR enables the `-txreconciliation` setting in both targets.

ACKs for top commit:
  fanquake:
    ACK 58c2bbdb55

Tree-SHA512: a2754fd04549bdcac94d8225244c5c83fe4c26114c0c2fdf316257480625e05e4e6b1b791974e1f1021451d3f81cb59a109261fb73178ad03911f0a3db963077
2023-01-19 15:56:58 +01:00
MarcoFalke
92dcbe9cc3
Merge bitcoin/bitcoin#23395: util: Add -shutdownnotify option
d96d97ad30  doc: Add release note for shutdownnotify. (klementtan)
0bd73e2c45 util: Add -shutdownnotify option. (klementtan)

Pull request description:

  **Description**: Similar to `-startupnotify`, this PR adds a new option to allow users to specify a command to be executed when Bitcoin Core shuts down.

  **Note**: The `shutdownnotify` commands will not be executed if bitcoind shut down due to *unexpected* reasons (ie `killall -9 bitcoind`).

  ### Testing:
  **Normal shutdown commands**
  ```
  # start bitcoind with shutdownnotify optioin
  ./src/bitcoind -signet -shutdownnotify="touch foo.txt"

  # shutdown bitcoind
  ./src/bitcoin-cli -signet stop

  # check that foo.txt has been created
  ```

  **Final RPC call**
  Commands:
  ```
  $  ./src/bitcoind -signet -nolisten -noconnect -shutdownnotify="./src/bitcoin-cli -signet getblockchaininfo > tmp.txt"
  $ ./src/bitcoin-cli stop
  $ cat tmp.txt
  ```
  <details>
  <summary>Screen Shot</summary>

  ![image](https://user-images.githubusercontent.com/49265907/141186183-cbc6f82c-400d-4a8b-baba-27c0346c2c8a.png)
  </details>

ACKs for top commit:
  achow101:
    ACK d96d97ad30
  1440000bytes:
    ACK d96d97ad30
  theStack:
    re-ACK d96d97ad30

Tree-SHA512: 16f7406fd232e8b97aea5e58854c84755b0c35c88cb3ef9ee123b29a1475a376122b1e100da860cc336d4d657e6046a70e915fdb9b70c9fd097c6eef1b028161
2023-01-19 10:34:54 +01:00
Andrew Chow
8ae2808a43
Merge bitcoin/bitcoin#25659: wallet: simplify ListCoins implementation
a2ac6f9582 wallet: unify FindNonChangeParentOutput functions (furszy)
b3f4e82737 wallet: simplify ListCoins implementation (furszy)

Pull request description:

  Focused on the following changes:

  1) Removed the entire locked coins lookup that was inside `ListCoins` by including them directly on the `AvailableCoins` result (where we were skipping them before).
  2) Unified both `FindNonChangeParentOutput` functions (only called from `ListCoins`)

ACKs for top commit:
  achow101:
    ACK a2ac6f9582
  aureleoules:
    ACK a2ac6f9582, LGTM
  theStack:
    Code-review ACK a2ac6f9582

Tree-SHA512: f72b21ee1600c5992559b5dcd8ff260527afac2ec696737f998343a0850b84d439e7f86ea52a14cc0cddabf132a30bf5b52fb34950578ac323083d4375b937f1
2023-01-18 14:26:39 -05:00
Hennadii Stepanov
1308b837dc
clang-tidy: Fix performance-no-automatic-move in headers
See https://clang.llvm.org/extra/clang-tidy/checks/performance/no-automatic-move.html
2023-01-18 15:47:06 +00:00
Hennadii Stepanov
0a5dc030b9
clang-tidy: Fix performance-move-const-arg in headers
See https://clang.llvm.org/extra/clang-tidy/checks/performance/move-const-arg.html
2023-01-18 15:47:06 +00:00
fanquake
3fef2944ad
Merge bitcoin/bitcoin#26706: doc: Properly report optional RPC args
fad56f7dd6 doc: Properly report optional RPC args (MarcoFalke)
fa09cb6086 refactor: Introduce is_top_level_arg (MarcoFalke)
fab92a5a5a refactor: Remove const to fix performance-move-const-arg clang-tidy errors (MarcoFalke)

Pull request description:

  `OMITTED_NAMED_ARG` and `OMITTED` are a confusing burden:

  * It puts the burden on developers to pick the right one of the two
  * They can be interchanged without introducing a compile failure or other error
  * Picking the wrong one is leading to incorrect docs
  * They are redundant, because the correct one can already be determined by the surrounding type

  Fix all issues by making them an alias of each other; Pick the right one based on the outer type.

ACKs for top commit:
  fanquake:
    ACK fad56f7dd6

Tree-SHA512: 6e7193a05a852ba1618a9cb3261220c7ad3282bc5595325c04437aa811f529a88e2851e9c7dbf9878389b8aa42e98f8817b7eb0260fbb9e123da0893cbae6ca2
2023-01-18 15:43:00 +00:00
MarcoFalke
78c30814f9
Merge bitcoin/bitcoin#26506: refactor: rpc: use convenience fn to auto parse non-string parameters
6d0ab07e81 refactor: use convenience fn to auto parse non-string parameters (stickies-v)

Pull request description:

  Minimizes code duplication and improves function naming by having a single (overloaded) convenience function `ParseIfNonString` that both checks if the parameter is a non-string parameter and automatically parses the value if so.

ACKs for top commit:
  aureleoules:
    ACK 6d0ab07e81

Tree-SHA512: 8cbf68a17cfbdce1e31a19916f447a2965c139fdef00c19e32a9b679f4a4015dfe69ceea0bbe1723711e1c5033ea8d4005d1f4485dfbeea22226140f8cbe8aa3
2023-01-18 13:12:09 +01:00
MarcoFalke
500f25d880
Merge bitcoin/bitcoin#26727: rpc: remove optional from fStateStats fields
1dc0e4bc6f rpc: remove optional from fStateStats fields (fanquake)

Pull request description:

  These are no-longer optional after #26515, so remove the documentation, and no-op `fStateStats` checks.

ACKs for top commit:
  dergoegge:
    Code review ACK 1dc0e4bc6f

Tree-SHA512: 06d4550e866341b379bfdbc72d67d71a3b7ceceec06ebd4c5e6f178b75fe40cbf4aff51adba1bc52590e69e818cbdecb0366bf1528c59c5c3dff5bbdba8eac68
2023-01-18 12:48:22 +01:00
MarcoFalke
52d6509497
Merge bitcoin/bitcoin#26904: build: move rpc/request from util lib to common
87a08cba43 build: move rpc/request from util lib to common (fanquake)

Pull request description:

  This is JSON RPC related code that doesn't need to be in util, and should not be required by the kernel.

ACKs for top commit:
  TheCharlatan:
    ACK 87a08cba43

Tree-SHA512: 5f335be9f0f9ff02eff073af47558ecf505c1392c05f18ca24a065b12b8d92529ec3942d84978cc5028c38369c496ed0243653e1fa26d4db2fae26dfe55c3d65
2023-01-18 09:27:29 +01:00
Martin Zumsande
5eabb61b23 addrdb: Only call Serialize() once
The previous logic would call it once for serializing into the filestream,
and then again for serializing into the hasher. If AddrMan was changed
in between these calls by another thread, the resulting peers.dat would
be corrupt with non-matching checksum and data.
Fix this by using HashedSourceWriter, which writes the data
to the underlying stream and keeps track of the hash in one go.
2023-01-17 17:20:03 -05:00
Martin Zumsande
da6c7aeca3 hash: add HashedSourceWriter
This class is the counterpart to CHashVerifier, in that it
writes data to an underlying source stream,
while keeping a hash of the written data.
2023-01-17 17:19:56 -05:00
MarcoFalke
f41252f19d
Merge bitcoin/bitcoin#26905: refactor: Remove duplication of clang-tidy's check names
06fc29326b refactor: Remove duplication of clang-tidy's check names (Hennadii Stepanov)

Pull request description:

  This PR removes duplication of `clang-tidy`'s check names.

  No behavior change.

  Split up from https://github.com/bitcoin/bitcoin/pull/26642 as [requested](https://github.com/bitcoin/bitcoin/pull/26642#issuecomment-1385351923).

ACKs for top commit:
  fanquake:
    ACK 06fc29326b

Tree-SHA512: a21bef3d7d7201e14565b526af2eae7a90cf0f792803704a80a70a4c78f07ef2a2eef6a8dced80361efbf13291ecccb0977378b9532fc30970a2070426e4d82c
2023-01-17 16:46:24 +01:00
Hennadii Stepanov
06fc29326b
refactor: Remove duplication of clang-tidy's check names 2023-01-17 15:40:29 +00:00
MarcoFalke
fad56f7dd6
doc: Properly report optional RPC args 2023-01-17 13:14:15 +01:00
MarcoFalke
fa09cb6086
refactor: Introduce is_top_level_arg 2023-01-17 13:13:46 +01:00
MarcoFalke
fab92a5a5a
refactor: Remove const to fix performance-move-const-arg clang-tidy errors
The warnings look like:

src/rpc/util.h:192:19: error: std::move of the const variable 'name' has no effect; remove std::move() or make the variable non-const [performance-move-const-arg,-warnings-as-errors]
        : m_names{std::move(name)},
                  ^~~~~~~~~~    ~
2023-01-17 13:13:01 +01:00
MarcoFalke
fa95f2033a
doc: Fix incorrect sendmany RPC doc
This enables the type check and fixes the wrong docs.

Otherwise the enabled check would lead to test errors, such as:

> "wallet_labels.py", line 96, in run_test
>     node.sendmany(
>
> test_framework.authproxy.JSONRPCException:
>  JSON value of type null is not of expected type string (-3)
2023-01-17 12:59:20 +01:00
fanquake
87a08cba43
build: move rpc/request from util lib to common
This is JSON RPC request code that doesn't need to be in util, and
should not be required by the kernel.
2023-01-17 11:02:08 +00:00
Hennadii Stepanov
b7f6a89a3e
Merge bitcoin-core/gui#686: clang-tidy: Force checks for headers in src/qt
7b7cd11244 clang-tidy, qt: Force checks for headers in `src/qt` (Hennadii Stepanov)
69eacf2c5e clang-tidy, qt: Fix `modernize-use-default-member-init` in headers (Hennadii Stepanov)

Pull request description:

  This PR split from bitcoin/bitcoin#26705 and contains only changes in `src/qt`.

  Effectively, it fixes the clang-tidy's `modernize-use-default-member-init` errors, and forces clang-tidy checks for all headers in the `src/qt` directory.

ACKs for top commit:
  jarolrod:
    ACK 7b7cd11244

Tree-SHA512: 79525bb0f31ae7cad88c781e55091a21467c0485ddc1ed03ad62e051480fda3b3710619ea11af480437edba3c6e038f7c40edc6b373e3a37408c006d11b34686
2023-01-17 09:54:56 +00:00
fanquake
7799f53542
Merge bitcoin/bitcoin#26039: refactor: Run type check against RPCArgs (1/2)
fa9f6d7bcd rpc: Run type check against RPCArgs (MarcoFalke)
faf96721a6 test: Fix wrong types passed to RPCs (MarcoFalke)

Pull request description:

  It seems brittle to require `RPCTypeCheck` being called inside the code logic. Without compile-time enforcement this will lead to places where it is forgotten and thus to inconsistencies and bugs. Fix this by removing the calls to `RPCTypeCheck` and doing the check internally.

  The changes should be reviewed as refactoring changes. However, if they change behavior, it will be a bugfix. For example the changes here happen to also detect/fix bugs like the one fixed in commit 3b5fb6e77a.

ACKs for top commit:
  ajtowns:
    ACK fa9f6d7bcd

Tree-SHA512: fb2c0981fe6e24da3ca7dbc06898730779ea4e02ea485458505a281cf421015e44dad0221a04023fc547ea2c660d94657909843fc85d92b847611ec097532439
2023-01-17 09:39:26 +00:00
Andrew Chow
04e54fd21f
Merge bitcoin/bitcoin#26325: rpc: Return accurate results for scanblocks
5ca7a7be76 rpc: Return accurate results for scanblocks (Aurèle Oulès)

Pull request description:

  Implements #26322.
  Adds a `filter_false_positives` mode to `scanblocks` to accurately verify results from blockfilters.

  If the option is enabled, pre-results given by blockfilters will be filtered out again by checking vouts and vins of all transactions of the relevant blocks against the given descriptors.

  ### Master
  ```bash
  ./src/bitcoin-cli -testnet -named scanblocks action=start scanobjects='["addr(tb1qcxf2gv93c26s6mqz7y6etpqdf70zmn67dualgr)"]'
  {
    "from_height": 0,
    "to_height": 2376055,
    "relevant_blocks": [
      "000000000001bc35077dec4104e0ab1f667ae27059bd907f9a8fac55c802ae36",
      "00000000000120a9c50542d73248fb7c37640c252850f0cf273134ad9febaf61",
      "0000000000000082f7af3835da8b6146b0bfb243b8842f09c495fa1e74d454ed",
      "0000000000000094c32651728193bfbe91f6789683b8d6ac6ae2d22ebd3cb5d3"
    ]
  }
  ```

  ### PR (without `filter_false_positives` mode)
  Same as master
  ```bash
  ./src/bitcoin-cli -testnet -named scanblocks action=start scanobjects='["addr(tb1qcxf2gv93c26s6mqz7y6etpqdf70zmn67dualgr)"]' filter_false_positives=false
  {
    "from_height": 0,
    "to_height": 2376055,
    "relevant_blocks": [
      "000000000001bc35077dec4104e0ab1f667ae27059bd907f9a8fac55c802ae36",
      "00000000000120a9c50542d73248fb7c37640c252850f0cf273134ad9febaf61",
      "0000000000000082f7af3835da8b6146b0bfb243b8842f09c495fa1e74d454ed",
      "0000000000000094c32651728193bfbe91f6789683b8d6ac6ae2d22ebd3cb5d3"
    ]
  }
  ```

  ### PR (with `filter_false_positives` mode)
  ```bash
  ./src/bitcoin-cli -testnet -named scanblocks action=start scanobjects='["addr(tb1qcxf2gv93c26s6mqz7y6etpqdf70zmn67dualgr)"]' filter_false_positives=true
  {
    "from_height": 0,
    "to_height": 2376058,
    "relevant_blocks": [
      "0000000000000082f7af3835da8b6146b0bfb243b8842f09c495fa1e74d454ed",
      "0000000000000094c32651728193bfbe91f6789683b8d6ac6ae2d22ebd3cb5d3"
    ]
  }
  ```

  Also adds a test to check that the blockhash of a transaction will be included in the `relevant_blocks` whether the `filter_false_positives` mode is enabled or not.

ACKs for top commit:
  achow101:
    ACK 5ca7a7be76
  theStack:
    re-ACK 5ca7a7be76
  furszy:
    Code review ACK 5ca7a7be

Tree-SHA512: e8f3cceddddd66f59509717b6314d89e2fef241e13cee81b18fd95e8362cbb95cc40f884342ce6cf892a86febd9e2d434afce05d51892240e67f72ae991852e7
2023-01-16 17:39:51 -05:00
Andrew Chow
b55b11f92a
Merge bitcoin/bitcoin#25375: rpc: add minconf/maxconf options to sendall and fund transaction calls
cfe5aebc79 rpc: add minconf and maxconf options to sendall (ishaanam)
a07a413466 Wallet/RPC: Allow specifying min & max chain depth for inputs used by fund calls (Juan Pablo Civile)

Pull request description:

  This PR adds a "minconf" option to `fundrawtransaction`, `walletcreatefundedpsbt`,  and `sendall`.
  Alternative implementation of #14641
  Fixes #14542

  Edit: This PR now also adds this option to `send`

ACKs for top commit:
  achow101:
    ACK cfe5aebc79
  Xekyo:
    ACK cfe5aebc79
  furszy:
    diff ACK cfe5aebc, only a non-blocking nit.

Tree-SHA512: 836e610926eec3a62308fba88ddbd6a13d8f4dac37352d0309599f893cde9c1df5e9c298fda6e076493068e4d213e4afa7290a9e3bdb5a95a5d507da3f7b59e8
2023-01-16 17:23:51 -05:00
MarcoFalke
faf7b4f1fc
Add BlockManager::IsPruneMode() 2023-01-16 17:31:32 +01:00
MarcoFalke
fae71fe27e
Add BlockManager::GetPruneTarget() 2023-01-16 17:16:30 +01:00
MarcoFalke
fa0f0436d8
Add BlockManager::LoadingBlocks() 2023-01-16 16:38:11 +01:00
MarcoFalke
6b7ccb98a5
Merge bitcoin/bitcoin#26251: refactor: add kernel/cs_main.h
282019cd3d refactor: add kernel/cs_main.* (fanquake)

Pull request description:

  One place to find / include `cs_main`.
  No more:
  > // Actually declared in validation.cpp; can't include because of circular dependency.
  > extern RecursiveMutex cs_main;

  Ultimately, no more need to include `validation.h` (which also includes (heavy/boost filled) `txmempool.h`) everywhere for `cs_main`. See #26087 for another example of why that is useful.

ACKs for top commit:
  ajtowns:
    ACK 282019cd3d

Tree-SHA512: 142835b794873e7a09c3246d6101843ae81ec0c6295e6873130c98a2abfa5f7282748d0f1a37237a779cc71c3bc0a75d03b20313ef5398c83d4814215cbc8287
2023-01-16 13:44:56 +01:00
Hennadii Stepanov
3dd2762cf8
Merge bitcoin-core/gui#690: Catch invalid networks combination crash
f4a11d7baf gui: bugfix, catch invalid networks combination crash (furszy)

Pull request description:

  The app currently crashes if a network is set inside bitcoin.conf and
  another one is provided as param.
  The reason is an uncaught runtime_error.

ACKs for top commit:
  jarolrod:
    tACK f4a11d7baf
  johnny9:
    tACK f4a11d7baf
  john-moffett:
    ACK f4a11d7baf
  pablomartin4btc:
    Tested ACK f4a11d7baf.
  hebasto:
    ACK f4a11d7baf, tested on Ubuntu 22.04 (Qt 5.15.3).

Tree-SHA512: fc5e26ae0a361e37d53d904cc122d07f064f261b309629c6386cb046ab1b3d2c805cbfe0db8ed3e934af52c6cf0ebb0bef9df9117b4330d9b0ea40c76f9270f9
2023-01-15 18:55:59 +00:00
fanquake
07c54de550
Merge bitcoin/bitcoin#26691: Update secp256k1 subtree to libsecp256k1 version 0.2.0
2022917223 Add secp256k1_selftest call (Pieter Wuille)
3bfca788b0 Remove explicit enabling of default modules (Pieter Wuille)
4462cb0498 Adapt to libsecp256k1 API changes (Pieter Wuille)
9d47e7b71b Squashed 'src/secp256k1/' changes from 44c2452fd3..21ffe4b22a (Pieter Wuille)

Pull request description:

  Now that libsecp256k1 has a release (https://lists.linuxfoundation.org/pipermail/bitcoin-dev/2022-December/021271.html), update the subtree to match it.

  The changes themselves are not very impactful for Bitcoin Core, but include:
  * It's no longer needed to specify whether contexts are for signing or verification or both (all contexts support everything), so make use of that in this PR.
  * Verification operations can use the static context now, removing the need for some infrastructure in pubkey.cpp to make sure a context exists.
  * Most modules are now enabled by default, so we can drop explicit enabling for them.
  * CI improvements (in particular, MSVC and more recent MacOS)
  * Introduction of an internal int128 type, which has no effect for GCC/Clang builds, but enables 128-bit multiplication in MSVC, giving a ~20% speedup there (but still slower than GCC/Clang).
  * Release process changes (process documentation, changelog, ...).

ACKs for top commit:
  Sjors:
    ACK 2022917223, but 4462cb0498 could use more eyes on it.
  achow101:
    ACK 2022917223
  jonasnick:
    utACK 2022917223

Tree-SHA512: 8a9fe28852abe74abd6f96fef16a94d5a427b1d99bff4caab1699014d24698aab9b966a5364a46ed1001c07a7c1d825154ed4e6557c7decce952b77330a8616b
2023-01-13 09:40:57 +00:00
fanquake
672f7ad747
doc: remove usages of C++11
Now it's just the standard library.
2023-01-12 13:42:44 +00:00
Andrew Chow
fbe5e1220a
Merge bitcoin/bitcoin#26675: wallet: For feebump, ignore abandoned descendant spends
f9ce0eadf4 For feebump, ignore abandoned descendant spends (John Moffett)

Pull request description:

  Closes #26667

  To be eligible for fee-bumping, a transaction must not have any of its outputs (eg - change) spent in other unconfirmed transactions in the wallet. This behavior is currently [enforced](9e229a542f/src/wallet/feebumper.cpp (L25-L28)) and [tested](9e229a542f/test/functional/wallet_bumpfee.py (L270-L286)).

  However, this check shouldn't apply to spends in abandoned descendant transactions, as explained by #26667.

  `CWallet::IsSpent` already carves out an exception for abandoned transactions, so we can just use that.

  I've also added a new test to cover this case.

ACKs for top commit:
  Sjors:
    re-utACK f9ce0eadf4
  achow101:
    ACK f9ce0eadf4
  furszy:
    ACK f9ce0ead

Tree-SHA512: 19d957d1cf6747668bb114e27a305027bfca5a9bed2b1d9cc9e1b0bd4666486c7c4b60b045a7fe677eb9734d746f5de76390781fb1e9e0bceb4a46d20acd1749
2023-01-11 18:24:53 -05:00
Andrew Chow
2f6a8e5e02
Merge bitcoin/bitcoin#26695: bench: BlockAssembler on a mempool with packages
04528054fc [bench] BlockAssembler with mempool packages (glozow)
6ce265acf4 [test util] lock cs_main before pool.cs in PopulateMempool (glozow)
8791410662 [test util] randomize fee in PopulateMempool (glozow)
cba5934eb6 [miner] allow bypassing TestBlockValidity (glozow)
c058852308 [refactor] parameterize BlockAssembler::Options in PrepareBlock (glozow)
a2de971ba1 [refactor] add helper to apply ArgsManager to BlockAssembler::Options (glozow)

Pull request description:

  Performance of block template building matters as miners likely want to be able to start mining on a block with transactions asap after a block is found. We would want to know if a mempool PR accidentally caused, for example, a 100x slowdown. An `AssembleBlock()` bench exists, but it operates on a mempool with 101 transactions, each with 0 ancestors or descendants and with the same fee. Adding a bench with a more complex mempool is useful because (1) it's more realistic (2) updating packages can potentially cause the algorithm to take a long time.

ACKs for top commit:
  kevkevinpal:
    Tested ACK [0452805](04528054fc)
  achow101:
    ACK 04528054fc
  stickies-v:
    ACK 04528054f

Tree-SHA512: 38c138d6a75616651f9b1faf4e3a1cd833437a486f4e84308fbee958e8462bb570582c88f7ba7ab99d80191e97855ac2cf27c43cc21585d3e4b0e227effe2fb5
2023-01-11 18:11:11 -05:00
ishaanam
cfe5aebc79 rpc: add minconf and maxconf options to sendall 2023-01-11 17:08:35 -05:00
Juan Pablo Civile
a07a413466 Wallet/RPC: Allow specifying min & max chain depth for inputs used by fund calls
Enables users to craft BIP-125 replacements with changes to the output
list, ensuring that if additional funds are needed they will be added.
2023-01-11 17:08:23 -05:00
Andrew Chow
908212506d
Merge bitcoin/bitcoin#26821: refactor: Make ThreadHTTP return void
45553e11c9 refactor: Make `ThreadHTTP` return void (Hennadii Stepanov)

Pull request description:

  The `bool` return value was introduced in 755aa05174 (https://github.com/bitcoin/bitcoin/pull/8421).

  It has been not used since 8d3f46ec39 (https://github.com/bitcoin/bitcoin/pull/14670).

  No behavior change.

ACKs for top commit:
  achow101:
    ACK 45553e11c9
  brunoerg:
    crACK 45553e11c9
  w0xlt:
    ACK 45553e11c9
  stickies-v:
    ACK 45553e11c

Tree-SHA512: 1593a5740e729967fbe1363235cd5b77ecf431b29bc740a89a6c70fc838ad97a2e4a2cd7cd63aa482f7c50bc2ffabc8cd53e8f64d6032603cb3b662229bc3dc2
2023-01-11 16:46:45 -05:00
MarcoFalke
fa9f6d7bcd
rpc: Run type check against RPCArgs 2023-01-11 17:42:09 +01:00
fanquake
329d7e379d
Merge bitcoin/bitcoin#26328: doc: fix -netinfo relaytxes help
0f5fc4f656 doc: fix up -netinfo relaytxes help (Jon Atack)

Pull request description:

  Addresses https://github.com/bitcoin/bitcoin/pull/26109#discussion_r995502563 by Marco Falke (thanks!)

ACKs for top commit:
  mzumsande:
    Code Review ACK 0f5fc4f656

Tree-SHA512: d7345d1a94b15c4ec1a2bb0be5c04c472411d90cefb4c16ed524933d2bfc36816bb7519c2e109b2e41ff451b039dd2ddaa6d5db917ad54745332f2a1d8b85570
2023-01-11 16:39:11 +00:00
MarcoFalke
9887fc7898
Merge bitcoin/bitcoin#26758: refactor: Add performance-no-automatic-move clang-tidy check
9567bfeab9 clang-tidy: Add `performance-no-automatic-move` check (Hennadii Stepanov)

Pull request description:

  Split from bitcoin/bitcoin#26642 as [requested](https://github.com/bitcoin/bitcoin/pull/26642#discussion_r1054673201).

  For the problem description see https://clang.llvm.org/extra/clang-tidy/checks/performance/no-automatic-move.html.

  The following types are affected:
  - `std::pair<CAddress, NodeSeconds>`
  - `std::vector<CAddress>`
  - `UniValue`, also see bitcoin/bitcoin#25429
  - `QColor`
  - `CBlock`
  - `MempoolAcceptResult`
  - `std::shared_ptr<CWallet>`
  - `std::optional<SelectionResult>`
  - `CTransactionRef`, which is `std::shared_ptr<const CTransaction>`

ACKs for top commit:
  andrewtoth:
    ACK 9567bfeab9
  aureleoules:
    ACK 9567bfeab9

Tree-SHA512: 9b6a5d539205b41d2c86402d384318ed2e1d89e66333ebd200a48fd7df3ce6f6c60a3e989eda5cc503fb34b8d82526f95e56776e1af51e63b49e3a1fef72dbcb
2023-01-11 16:18:34 +01:00
glozow
26002570ab
Merge bitcoin/bitcoin#26646: validation, bugfix: provide more info in *MempoolAcceptResult
264f9ef17f [validation] return MempoolAcceptResult for every tx on PCKG_TX failure (glozow)
dae81e01e8 [refactor] rename variables in AcceptPackage for clarity (glozow)
da484bc738 [doc] release note effective-feerate and effective-includes RPC results (glozow)
5eab397b98 [validation] remove PackageMempoolAcceptResult::m_package_feerate (glozow)
601bac88cb [rpc] return effective-includes in testmempoolaccept and submitpackage (glozow)
1691eaa818 [rpc] return effective-feerate in testmempoolaccept and submitpackage (glozow)
d6c7b78ef2 [validation] return wtxids of other transactions whose fees were used (glozow)
1605886380 [validation] return effective feerate from mempool validation (glozow)
5d35b4a7de [test] package validation quits early due to non-policy, non-missing-inputs failure (glozow)
be2e4d94e5 [validation] when quitting early in AcceptPackage, set package_state and tx result (glozow)

Pull request description:

  This PR fixes a bug and improves the mempool accept interface to return information more predictably.

  Bug: In package validation, we first try the transactions individually (see doc/policy/packages.md for more explanation) and, if they all failed for missing inputs and policy-related (i.e. fee) reasons, we'll try package validation. Otherwise, we'll just "quit early" since, for example, if a transaction had an invalid signature, adding a child will not help make it valid. Currently, when we quit early, we're not setting the `package_state` to be invalid, so the caller might think it succeeded. Also, we're returning no results - it makes more sense to return the individual transaction failure. Thanks instagibbs for catching https://github.com/bitcoin/bitcoin/pull/25038#discussion_r1013293248!

  Also, make the package results interface generally more useful/predictable:
  - Always return the feerate at which a transaction was considered for `CheckFeeRate` in `MempoolAcceptResult::m_effective_feerate` when it was successful. This can replace the current `PackageMempoolAcceptResult::m_package_feerate`, which only sometimes exists.
  - Always provide an entry for every transaction in `PackageMempoolAcceptResult::m_tx_results` when the error is `PCKG_TX`.

ACKs for top commit:
  instagibbs:
    reACK 264f9ef17f
  achow101:
    ACK 264f9ef17f
  naumenkogs:
    reACK 264f9ef17f

Tree-SHA512: ce7fd9927a80030317cc6157822596e85a540feff5dbf5eea7c62da2eb50c917cdddc9da1e2ff62cc18b98b27d360151811546bd9d498859679a04bbee090837
2023-01-11 13:25:39 +00:00
MarcoFalke
dbca00ef76
Merge bitcoin/bitcoin#26838: doc: I2P documentation updates
3e1d2941e9 doc: remove recommended I2P router versions (jonatack)
295849abb5 doc: update/clarify/de-emphasize I2P transient address section (jonatack)
dffa319457 doc: update bandwidth section of I2P documentation (jonatack)
0ed9cc5892 doc: clarify -i2pacceptincoming help documentation (jonatack)

Pull request description:

  Address the documentation updates requested in issue #26754, clarify/simplify the -i2pacceptincoming help, and a few other fixups.

ACKs for top commit:
  willcl-ark:
    ACK 3e1d294
  1440000bytes:
    ACK 3e1d2941e9
  w0xlt:
    ACK 3e1d2941e9
  vasild:
    ACK 3e1d2941e9

Tree-SHA512: e647221884af34646b99150617f4d4cc8d5fce325a769294f49047b9d8c9c8ab2b365cfdd9f56b3bd0303da706233f03d24cececf6e161c53f04ed947751052a
2023-01-11 13:03:54 +01:00
Andrew Chow
4586ae2da1
Merge bitcoin/bitcoin#26679: wallet: Skip rescanning if wallet is more recent than tip
3784009534 wallet: Skip rescanning if wallet is more recent than tip (Andrew Chow)

Pull request description:

  If a wallet has key birthdates that are more recent than the currrent chain tip, or a bestblock height higher than the current tip, we should not attempt to rescan as there is nothing to scan for.

  Fixes #26655

ACKs for top commit:
  ishaanam:
    re-utACK 3784009534
  w0xlt:
    utACK 3784009534
  furszy:
    Code review ACK 37840095

Tree-SHA512: f0d90b62940d97d50f21e1e01fa6dcb54409fad819cea4283612825c4d93d733df323cd92787fed43956b0a8e386a5bf88218f1f5749c913398667a5c8f54470
2023-01-10 19:56:32 -05:00
Andrew Chow
9addbd7890 wallet: Automatically abandon orphaned coinbases and their children 2023-01-10 18:23:45 -05:00
Andrew Chow
68f88bc03f
Merge bitcoin/bitcoin#26186: rpc: Sanitize label name in various RPCs with tests
65e78bda7c test: Invalid label name coverage (Aurèle Oulès)
552b51e682 refactor: Add sanity checks in LabelFromValue (Aurèle Oulès)
67e7ba8e1a rpc: Sanitize label name in various RPCs (Aurèle Oulès)

Pull request description:

  The following RPCs did not sanitize the optional label name:
  - importprivkey
  - importaddress
  - importpubkey
  - importmulti
  - importdescriptors
  - listsinceblock

  Thus is was possible to import an address with a label `*` which should not be possible.
  The wildcard label is used for backwards compatibility in the `listtransactions` rpc.
  I added test coverage for these RPCs.

ACKs for top commit:
  ajtowns:
    ACK 65e78bda7c
  achow101:
    ACK 65e78bda7c
  furszy:
    diff ACK 65e78bd
  stickies-v:
    re-ACK 65e78bda7c
  theStack:
    re-ACK 65e78bda7c

Tree-SHA512: ad99f2824d4cfae352166b76da4ca0069b7c2eccf81aaa0654be25bbb3c6e5d6b005d93960f3f4154155f80e12be2d0cebd5529922ae3d2a36ee4eed82440b31
2023-01-10 17:31:19 -05:00
Jon Atack
0f5fc4f656 doc: fix up -netinfo relaytxes help
Co-authored-by: "MarcoFalke <*~=`'#}+{/-|&$^_@721217.xyz>"
2023-01-10 12:55:04 -08:00
Sebastian Falbesoner
3076f1815d doc: net: fix link to onion address encoding scheme [ONIONADDRESS]
Instead of referring to a fixed line number to a file in master (which
is obviously always quickly outdated), use a permalink tied to the
latest commit.
2023-01-10 14:23:27 +01:00
glozow
264f9ef17f
[validation] return MempoolAcceptResult for every tx on PCKG_TX failure
This makes the interface more predictable and useful. The caller
understands one or more transactions failed, and can learn what happened
with each transaction. We already have this information, so we might as
well return it.

It doesn't make sense to do this for other PackageValidationResult
values because:
- PCKG_RESULT_UNSET: this means everything succeeded, so the individual
  failures are no longer accurate.
- PCKG_MEMPOOL_ERROR: something went wrong with the mempool logic;
  transaction failures might not be meaningful.
- PCKG_POLICY: this means something was wrong with the package as a
  whole. The caller should use the PackageValidationState to find the
  error, rather than looking at individual MempoolAcceptResults.
2023-01-10 11:10:50 +00:00
glozow
dae81e01e8 [refactor] rename variables in AcceptPackage for clarity 2023-01-10 11:09:03 +00:00
glozow
5eab397b98 [validation] remove PackageMempoolAcceptResult::m_package_feerate
This value creates an extremely confusing interface as its existence is
dependent upon implementation details (whether something was submitted
on its own, etc). MempoolAcceptResult::m_effective_feerate is much more
helpful, as it always exists for submitted transactions.
2023-01-10 11:09:03 +00:00
glozow
601bac88cb [rpc] return effective-includes in testmempoolaccept and submitpackage 2023-01-10 11:07:38 +00:00
glozow
1691eaa818 [rpc] return effective-feerate in testmempoolaccept and submitpackage 2023-01-10 11:06:10 +00:00
glozow
d6c7b78ef2 [validation] return wtxids of other transactions whose fees were used 2023-01-10 10:36:57 +00:00
Andrew Chow
1aedc3b6c8
Merge bitcoin/bitcoin#26618: rpc: Prevent unloading a wallet when rescanning
109cbb819d doc: Add release notes for #26618 (Aurèle Oulès)
b13902d2e4 rpc: Prevent unloading a wallet when rescanning (Aurèle Oulès)

Pull request description:

  Fixes #26463.

  This PR prevents a user from unloading a wallet if it is currently rescanning.

  To test:

  ```bash
  ./src/bitcoin-cli -testnet -named createwallet wallet_name=wo disable_private_keys=true
  ./src/bitcoin-cli -testnet -rpcwallet=wo importdescriptors '[{
    "desc": "addr(mmcuW74MyJUZuLnWXGQLoNXPrS9RbFz6gD)#tpnrahgc",
        "timestamp": 0,
        "active": false,
        "internal": false,
        "next": 0
  }]'
  ./src/bitcoin-cli -testnet unloadwallet wo
  error code: -4
  error message:
  Wallet is currently rescanning. Abort existing rescan or wait.

ACKs for top commit:
  achow101:
    ACK 109cbb819d
  w0xlt:
    ACK 109cbb819d
  kouloumos:
    ACK 109cbb819d
  promag:
    ACK 109cbb819d

Tree-SHA512: 15fdddf4cf9f3fa08f52069fe4a25a76e04a55bb2586b031bfb0393dce7f175dcdb52823e132a7dff6a894539beeb980a1aad2a792790be036be6977628149b2
2023-01-09 16:56:40 -05:00
jonatack
0ed9cc5892 doc: clarify -i2pacceptincoming help documentation
and also hoist the default setting to a constexpr and
remove unused f-string operators in a related functional test.
2023-01-09 08:18:47 -08:00
glozow
1605886380 [validation] return effective feerate from mempool validation 2023-01-06 17:37:01 +00:00
glozow
5d35b4a7de [test] package validation quits early due to non-policy, non-missing-inputs failure 2023-01-06 17:37:01 +00:00
glozow
be2e4d94e5 [validation] when quitting early in AcceptPackage, set package_state and tx result
Bug: not setting package_state means package_state.IsValid() == true and
the caller does not know that this failed.

We won't be validating this transaction again, so it makes sense to return this
failure to the caller.

Rename package_state to package_state_quit_early to make it more clear
what this variable is used for and what its scope is.

Co-authored-by: Greg Sanders <gsanders87@gmail.com>
2023-01-06 17:37:01 +00:00
brunoerg
b99f1f20f7 p2p, rpc: don't allow past absolute timestamp in setban 2023-01-06 13:33:38 -03:00
Aurèle Oulès
5ca7a7be76
rpc: Return accurate results for scanblocks
This makes use of undo data to accurately verify results
from blockfilters.
2023-01-06 12:01:22 +01:00
MarcoFalke
2cfe379623
Merge bitcoin/bitcoin#26823: refactor: Work around Werror=free-nonheap-object in AssumeCalculateMemPoolAncestors
faa86eeb41 refactor: Work around Werror=free-nonheap-object in AssumeCalculateMemPoolAncestors (MarcoFalke)

Pull request description:

  This works around the s390x gcc bug mentioned in https://github.com/bitcoin/bitcoin/issues/26820

ACKs for top commit:
  achow101:
    ACK faa86eeb41

Tree-SHA512: 041d5daa157ea1856b0a8027181085d70624f5f8822049ace9963e90c653bbb8c91d1f16b8a5bf460687eb4ed13f1db72e3885a511aadbad6dede93d9f9ccd6d
2023-01-06 08:04:44 +01:00
fanquake
b358bde020
randomenv: consolidate WIN32 #ifdefs
Order includes.
Remove // for xyz comments
2023-01-05 19:45:03 +00:00
fanquake
fff80cd248
random: remove windows-only compat.h include in randomenv
Note that this was probably only here to indirectly receive windows.h
via another include in compat.h (windows.h or winreg.h aren't included
there).

Also note that compat.h is already pulled in here for everyone via
util/time.h, so including inside a windows only ifdef is secondarily
redundant.
2023-01-05 19:38:49 +00:00
MarcoFalke
faa86eeb41
refactor: Work around Werror=free-nonheap-object in AssumeCalculateMemPoolAncestors 2023-01-05 19:48:14 +01:00
Hennadii Stepanov
45553e11c9
refactor: Make ThreadHTTP return void
The `bool` return value was introduced in 755aa05174.

It has been not used since 8d3f46ec39.

No behavior change.
2023-01-05 17:54:08 +00:00
Andrew Chow
b4fb0a3255
Merge bitcoin/bitcoin#26761: wallet: fully migrate address book entries for watchonly/solvable wallets
730e14a317 test: wallet: check that labels are migrated to watchonly wallet (Sebastian Falbesoner)
d5f4ae7fac wallet: fully migrate address book entries for watchonly/solvable wallets (Sebastian Falbesoner)

Pull request description:

  Currently `migratewallet` migrates the address book (i.e. labels and purposes) for watchonly and solvable wallets only in RAM, but doesn't persist them on disk. Fix this by adding another loop for both of the special wallet types after which writes the corresponding NAME and PURPOSE entries to the database in a single batch. Also adds a corresponding test that checks if labels were migrated correctly for a watchonly wallet.

ACKs for top commit:
  achow101:
    ACK 730e14a317
  furszy:
    code ACK 730e14a3, left a non-blocking nit.
  aureleoules:
    ACK 730e14a317

Tree-SHA512: 159487e11e858924ef762e0190ccaea185bdff239e3d2280c8d63c4ac2649ec71714dc4d53dec644f03488f91c3b4bbbbf3434dad23bc0fcecb6657f353ea766
2023-01-05 12:22:51 -05:00
MarcoFalke
3212d104f4
Merge bitcoin/bitcoin#23829: refactor: use braced init for integer literals instead of c style casts
f2fc03ec85 refactor: use braced init for integer constants instead of c style casts (Pasta)

Pull request description:

  See https://github.com/bitcoin/bitcoin/pull/23810 for more context. This is broken out from that PR, as it is less breaking, and should be trivial to review and merge.

  EDIT: Long term, the intention is to remove all C-style casts, as they can dangerously introduce reinterpret_casts. This is one step which removes a number of trivially removable C-style casts

ACKs for top commit:
  aureleoules:
    ACK f2fc03ec85

Tree-SHA512: 2fd11b92c9147e3f970ec3e130e3b3dce70e707ff02950a8c697d4b111ddcbbfa16915393db20cfc8f384bc76f13241c9b994a187987fcecd16a61f8cc0af14c
2023-01-05 17:30:52 +01:00
fanquake
282019cd3d
refactor: add kernel/cs_main.*
Co-authored-by: Anthony Towns <aj@erisian.com.au>
2023-01-05 09:05:14 +00:00
Andrew Chow
360e047a71
Merge bitcoin/bitcoin#26747: wallet: fix confusing error / GUI crash on cross-chain legacy wallet restore
21ad4e26ec test: add coverage for cross-chain wallet restore (Sebastian Falbesoner)
8c7222bda3 wallet: fix GUI crash on cross-chain legacy wallet restore (Sebastian Falbesoner)

Pull request description:

  Restoring a wallet backup from another chain should result in a dedicated error message (we have _"Wallet files should not be reused across chains. Restart bitcoind with -walletcrosschain to override."_ for that). Unfortunately this is currently not the case for legacy wallet restores, as in the course of cleaning up the newly created wallet directory a `filesystem_error` exception is thrown due to the directory not being empty; the wallet database did indeed load successfully (otherwise we wouldn't know that the chain doesn't match) and hence BDB-related files and directories are already created in the wallet directory.

  For bitcoind, this leads to a very confusing error message:
  ```
  $ ./src/bitcoin-cli restorewallet test123 ~/.bitcoin/regtest/wallets/regtest_wallet/wallet.dat
  error code: -1
  error message: filesystem error: in remove: Directory not empty ["/home/thestack/.bitcoin/wallets/test123"]
  ```

  Even worse, the GUI crashes in such a scenario:
  ```
  libc++abi: terminating with uncaught exception of type std::__1::__fs::filesystem::filesystem_error: filesystem error: in remove: Directory not empty ["/home/thestack/.bitcoin/wallets/foobar"]
  Abort trap (core dumped)
  ```

  Fix this by simply deleting the whole folder via `fs::remove_all`. With this, the expected error message appears both for the `restorewallet` RPC call and in the GUI (as a message-box):

  ```
  $ ./src/bitcoin-cli restorewallet test123 ~/.bitcoin/regtest/wallets/regtest_wallet/wallet.dat
  error code: -4
  error message:
  Wallet loading failed. Wallet files should not be reused across chains. Restart bitcoind with -walletcrosschain to override.
  ```

ACKs for top commit:
  achow101:
    ACK 21ad4e26ec
  aureleoules:
    ACK 21ad4e26ec
  furszy:
    utACK 21ad4e26

Tree-SHA512: 313f6494c2fbe823bff9b975cb2d9410bb518977a1e59a5159ee9836bc012947fa50b56be0e41b1a2f50d9c0c7f4fddfdf4fbe479d8a59a6ee44bb389c804abc
2023-01-04 17:46:37 -05:00
Andrew Chow
cabeae43ea
Merge bitcoin/bitcoin#26809: compat: use STDIN_FILENO over 0
585c672212 compat: use STDIN_FILENO over 0 (fanquake)

Pull request description:

  This is already used throughout this file, and is self-documenting.

ACKs for top commit:
  john-moffett:
    ACK 585c672212
  achow101:
    ACK 585c672212
  hebasto:
    ACK 585c672212, I have reviewed the code and it looks OK, I agree it can be merged.
  kristapsk:
    utACK 585c672212
  aureleoules:
    ACK 585c672212

Tree-SHA512: c0114ae896ba5404be70b804ee9f454d213f1d789c8f5a578c422dd15a308a214e6851fee76c0ec736a212bc86fb33ec17af1b22e5d23422c375ca4458251356
2023-01-04 17:30:47 -05:00
glozow
196a43eddb
Merge bitcoin/bitcoin#26603: doc: CalculateSequenceLocks: prevHeights entries are set to 0, not removed
f537127271 doc: fix: prevHeights entries are set to 0, not removed (stickies-v)

Pull request description:

  In [`CalculateSequenceLocks`](a035b6a0c4/src/consensus/tx_verify.h (L69)) no items are removed from `prevHeights`, they are just set to 0:

  a035b6a0c4/src/consensus/tx_verify.cpp (L69-L73)

  This PR updates the docs to reflect the actual implementation. Seems to have been wrongly documented since introduction in #7184 already ([implementation](https://github.com/bitcoin/bitcoin/pull/7184/files#diff-34d21af3c614ea3cee120df276c9c4ae95053830d7f1d3deaf009a4625409ad2R742-R749) and [documentation](https://github.com/bitcoin/bitcoin/pull/7184/files#diff-34d21af3c614ea3cee120df276c9c4ae95053830d7f1d3deaf009a4625409ad2R712-R713))

ACKs for top commit:
  hebasto:
    ACK f537127271

Tree-SHA512: 3661501660f6832b2116fd83466ffe95a60b341c14cb09a37489e2a587bea3290b0528690120a0f644c3eea02177aa1fb8968258482fa43b0303e016abb17418
2023-01-04 18:07:31 +00:00
glozow
65ecf24b5c
Merge bitcoin/bitcoin#26752: wallet: Remove mempool_sequence from interface methods
55696a0ac3 wallet: remove `mempool_sequence` from `transactionRemovedFromMempool` (w0xlt)
bf19069c53 wallet: remove `mempool_sequence` from `transactionAddedToMempool` (w0xlt)

Pull request description:

  This PR removes `mempool_sequence` from `transactionRemovedFromMempool` and `transactionAddedToMempool`.

  `mempool_sequence` is  not used in these methods, only in ZMQ notifications.

ACKs for top commit:
  instagibbs:
    ACK 55696a0ac3

Tree-SHA512: 621e89230bcb6edfed83e2758601a2b093822fc2dc4e9bfb00487e340f2bc4c5ac3bf6df3ca00b7fe55bb3df15858820f2bf698f403d2e48b915dd9eb47b63e0
2023-01-04 17:53:58 +00:00
Andrew Chow
a273241480
Merge bitcoin/bitcoin#26020: test: Change coinselection parameter location to make tests independent
b942c94d15 test: Change coinselection parameter location to make tests independent (yancy)

Pull request description:

  the `subtract_fee_outputs` param is expected to be `true` for all subsequent tests.  It should be defined outside of a single test so that if it's removed or changed, all subsequent tests won't fail.  Currently if you remove this [test](https://github.com/bitcoin/bitcoin/blob/master/src/wallet/test/coinselector_tests.cpp#L304:L325) the following [test](https://github.com/bitcoin/bitcoin/blob/master/src/wallet/test/coinselector_tests.cpp#L327:L345) fails.  This change makes the tests independent.

ACKs for top commit:
  achow101:
    ACK b942c94d15
  aureleoules:
    ACK b942c94d15.
  rajarshimaitra:
    tACK b942c94d15
  theStack:
    ACK b942c94d15

Tree-SHA512: 461e19d15351318102ef9f96c68442365d8ca238c48ad7aefe23e8532b33b91dadf6c7840c7894574bccede6da162a55ad7a6f6a330d61a11ce804e68ddc5e9c
2023-01-04 12:41:47 -05:00
Andrew Chow
139ba2bf12
Merge bitcoin/bitcoin#25234: bench: add benchmark for wallet 'AvailableCoins' function.
3a4f8bc242 bench: add benchmark for wallet 'AvailableCoins' function. (furszy)

Pull request description:

  #### Rationale

  `AvailableCoins` is part of several important flows for the wallet; from RPC commands that create transactions like `fundrawtransaction`, `send`, `walletcreatefundedpsbt`, get the available balance, list the available coins with `listunspent` etc. to GUI connected processes that perform the same or similar actions: tx creation, available balance calculation, present the spendable coins in the coin control dialog.

  As we are improving this process in #24699, #25005 and there are more structural changes coming on the way. This benchmark aims to ensure us that, at least, there are no regressions (obviously performance improvements are great but, at least for me, this heads into the direction of having a base metric to compare future structural changes).

  #### Implementation Notes

  There are 5 new benchmarks, one per wallet supported output type (LEGACY, P2SH_SEGWIT, BECH32, BECH32M), plus a multi-output-type wallet benchmark which contains outputs from all the descriptor types.

  The test, by default, fills-up the wallet with 1k transactions, 2k outputs. Mainly to not consume much time if the user just want to verify that no substantial regressions were introduced. But, my expectation for those who are focused on this process is to use a much higher number locally to really note the differences across commits.

ACKs for top commit:
  achow101:
    ACK 3a4f8bc242
  hernanmarino:
    ACK 3a4f8bc242
  aureleoules:
    ACK 3a4f8bc242

Tree-SHA512: d0bb4c165f1efa181b47cb31561e6217eff9135bcd1b6761a7292f9018e456d13d18a1b886c2e2268d35c52f9e1fd8e0f252972424e5c5f00c280620b79c5a1b
2023-01-04 12:11:44 -05:00
stickies-v
6d0ab07e81
refactor: use convenience fn to auto parse non-string parameters
Minimizes code duplication and improves function naming by having
a single (overloaded) convenience function that both checks if
the parameter is a non-string parameter and automatically parses the
value if so.
2023-01-04 16:06:34 +00:00
Aurèle Oulès
552b51e682
refactor: Add sanity checks in LabelFromValue 2023-01-04 13:45:03 +01:00
fanquake
585c672212
compat: use STDIN_FILENO over 0
This is already used throughout this file, and is self-documenting.
2023-01-04 12:00:25 +00:00
fanquake
2ec97825e7
Merge bitcoin/bitcoin#26771: doc: Correct linked Microsoft URLs
f84e445dee doc: Correct linked Microsoft URLs (Suriyaa Sundararuban)

Pull request description:

  Update Microsoft-related links.

Top commit has no ACKs.

Tree-SHA512: 40c7b25a96772259fb04da1946d52f6aac9562262aef472ae75807bfbd246de47d72118140a12f7553037b94b89f95d69dea6ce30e611ac3d71a32d102355150
2023-01-04 11:40:56 +00:00
Aurèle Oulès
67e7ba8e1a
rpc: Sanitize label name in various RPCs
- importprivkey
- importaddress
- importpubkey
- listtransactions
- listsinceblock
- importmulti
- importdescriptors
2023-01-04 12:31:28 +01:00
MarcoFalke
53653060c1
Merge bitcoin/bitcoin#26795: rpc: Correct RPCHelpMan for fundrawtransaction's input_weights field
927b8d4e0c rpc: Correct RPCHelpMan for fundrawtransaction's input_weights field (jdjkelly@gmail.com)

Pull request description:

  `input_weights` is incorrectly documented as a fixed length JSON array, but it is actually a JSON array of JSON objects - this commit changes `input_weights` to use `RPCArg::Type::OBJ`

  The behavior of `input_weights` as an object exists as a functional test in [wallet_fundrawtransaction.py](https://github.com/bitcoin/bitcoin/blob/master/test/functional/wallet_fundrawtransaction.py).

ACKs for top commit:
  achow101:
    ACK 927b8d4e0c

Tree-SHA512: 384f5e16be36dba670d64d96f16f1fde2d0d51357e1094ae13eb71d004af0f4dc8bac965b4d2d724ccf64fb671faad37b73055152a9882af24f65dfceaf1e5fb
2023-01-04 11:09:57 +01:00
glozow
03254c2229
Merge bitcoin/bitcoin#19909: refactor: Remove unused CTxMemPool::clear() helper
fa818e103c txmempool: Remove unused clear() member function (MarcoFalke)

Pull request description:

  Seems odd to have code in Bitcoin Core that is unused.

  Moreover the function was broken (see https://github.com/bitcoin/bitcoin/pull/24145) and is brittle, as there is nothing that prevents similar bugs from re-appearing.

  Fix both issues by replacing it with C++11 member initializers.

ACKs for top commit:
  glozow:
    ACK fa818e103c

Tree-SHA512: e79e44cac7d5a84d9ecc8e3f3b0b9a50e1e3ebec358b20ba5dac175ef07d1fbe338a20f83ee80f746f7c726c79e77f8be49e14bca57a41063da8a5302123c3a9
2023-01-04 08:44:26 +00:00
Pasta
f2fc03ec85
refactor: use braced init for integer constants instead of c style casts 2023-01-03 19:31:29 -06:00
Andrew Chow
3f8591d46b
Merge bitcoin/bitcoin#26661: wallet: Coin Selection, return accurate error messages
76dc547ee7 gui: create tx, launch error dialog if backend throws runtime_error (furszy)
f4d79477ff wallet: coin selection, add duplicated inputs checks (furszy)
0aa065b14e wallet: return accurate error messages from Coin Selection (furszy)
7e8340ab1a wallet: make SelectCoins flow return util::Result (furszy)
e5e147fe97 wallet: refactor eight consecutive 'AttemptSelection' calls into a loop (furszy)

Pull request description:

  Work decoupled from #25806, which cleanup and improves the Coin Selection flow further.

  Adding the capability to propagate specific error messages from the Coin Selection process to the user.
  Instead of always returning the general "Insufficient funds" message which is not always accurate to what happened internally.
  Letting us instruct the user how to proceed under certain circumstances.

  The following error messages were added:

  1) If the selection result exceeds the maximum transaction weight,
     we now will return:
  -> "The inputs size exceeds the maximum weight. Please try sending
  a smaller amount or manually consolidating your wallet's UTXOs".

  2) If the user pre-selected inputs and disallowed the automatic coin
     selection process (no other inputs are allowed), we now will
     return:
  -> "The preselected coins total amount does not cover the transaction
  target. Please allow other inputs to be automatically selected or include
  more coins manually".

  3) The double-counted preset inputs during Coin Selection error will now
  throw an "internal bug detected" message instead of crashing the node.

  The essence of this work comes from several comments:
  1. https://github.com/bitcoin/bitcoin/pull/26560#discussion_r1037395665
  2. https://github.com/bitcoin/bitcoin/pull/25729#discussion_r940619491
  3. https://github.com/bitcoin/bitcoin/pull/25269#pullrequestreview-1135240825
  4. https://github.com/bitcoin/bitcoin/issues/23144 (which is connected to #24845)

ACKs for top commit:
  ishaanam:
    crACK 76dc547ee7
  achow101:
    ACK 76dc547ee7
  aureleoules:
    ACK 76dc547ee7
  theStack:
    ACK 76dc547ee7 🌇

Tree-SHA512: 9de30792d7a5849cae77747aa978e70390b66ee9d082779a56088a024f82e725b0af050e6603aece0ac8229f6d73bc471ba97b4ab69dc7eddf419f5f56ae89a5
2023-01-03 18:53:36 -05:00
Andrew Chow
80fc1af096
Merge bitcoin/bitcoin#26289: Use util::Result in for calculating mempool ancestors
47c4b1f52a mempool: log/halt when CalculateMemPoolAncestors fails unexpectedly (stickies-v)
5481f65849 mempool: add AssumeCalculateMemPoolAncestors helper function (stickies-v)
f911bdfff9 mempool: use util::Result for CalculateMemPoolAncestors (stickies-v)
66e028f739 mempool: use util::Result for CalculateAncestorsAndCheckLimits (stickies-v)

Pull request description:

  Upon reviewing the documentation for `CTxMemPool::CalculateMemPoolAncestors`, I noticed `setAncestors` was meant to be an `out` parameter but actually is an `in,out` parameter, as can be observed by adding `assert(setAncestors.empty());` as the first line in the function and running `make check`. This PR fixes this unexpected behaviour and introduces refactoring improvements to make intents and effects of the code more clear.

  ## Unexpected behaviour
  This behaviour occurs only in the package acceptance path, currently only triggered by `testmempoolaccept` and `submitpackage` RPCs.

  In `MemPoolAccept::AcceptMultipleTransactions()`, we first call `PreChecks()` and then `SubmitPackage()` with the same `Workspace ws` reference. `PreChecks` leaves `ws.m_ancestors` in a potentially non-empty state, before it is passed on to `MemPoolAccept::SubmitPackage`. `SubmitPackage` is the only place where `setAncestors` isn't guaranteed to be empty before calling `CalculateMemPoolAncestors`. The most straightforward fix is to just forcefully clear `setAncestors` at the beginning of CalculateMemPoolAncestors, which is done in the first bugfix commit.

  ## Improvements
  ### Return value instead of out-parameters
  This PR updates the function signatures for `CTxMemPool::CalculateMemPoolAncestors` and `CTxMemPool::CalculateAncestorsAndCheckLimits` to use a `util::Result` return type and eliminate both the `setAncestors` `in,out`-parameter as well as the error string. It simplifies the code and makes the intent and effects more explicit.

  ### Observability
  There are 7 instances where we currently call `CalculateMemPoolAncestors` without actually checking if the function succeeded because we assume that it can't fail, such as in [miner.cpp](69b10212ea/src/node/miner.cpp (L399)). This PR adds a new wrapper `AssumeCalculateMemPoolAncestors` function that logs such unexpected failures, or in case of debug builds even halts the program. It's not crucial to the objective, more of an observability improvement that seems sensible to add on here.

ACKs for top commit:
  achow101:
    ACK 47c4b1f52a
  w0xlt:
    ACK 47c4b1f52a
  glozow:
    ACK 47c4b1f52a
  furszy:
    light code review ACK 47c4b1f5
  aureleoules:
    ACK 47c4b1f52a

Tree-SHA512: d908dad00d1a5645eb865c4877cc0bae74b9cd3332a3641eb4a285431aef119f9fc78172d38b55c592168a73dae83242e6af3348815f7b37cbe2d448a3a58648
2023-01-03 16:30:55 -05:00
furszy
a2ac6f9582
wallet: unify FindNonChangeParentOutput functions
The function is only used in ListCoins.
2023-01-03 17:25:36 -03:00
furszy
b3f4e82737
wallet: simplify ListCoins implementation
Can remove the locked coins lookup if we include them directly
inside the AvailableCoins result
2023-01-03 17:25:35 -03:00
Andrew Chow
cb552c5f21
Merge bitcoin/bitcoin#26192: rpc: Improve error when wallet is already loaded
04609284ad rpc: Improve error when wallet is already loaded (Aurèle Oulès)

Pull request description:

  Currently, trying to load a descriptor (sqlite) wallet that is already loaded throws the following error:
  > error code: -4
  > error message:
  > Wallet file verification failed. SQLiteDatabase: Unable to obtain an exclusive lock on the database, is it being used by another instance of Bitcoin Core?

  I don't think it is very clear what it means for a user.

  While a legacy wallet would throw:
  > error code: -35
  > error message:
  > Wallet file verification failed. Refusing to load database. Data file '/home/user/.bitcoin/signet/wallets/test_wallet/wallet.dat' is already loaded.

  This PR changes the error message for both types of wallet to:
  > error code: -35
  > error message:
  > Wallet file verification failed. Wallet "test_wallet" is already loaded.

ACKs for top commit:
  achow101:
    ACK 04609284ad
  hernanmarino:
    ACK  0460928
  theStack:
    Tested ACK 04609284ad

Tree-SHA512: a8f3d5133bfaef7417a6c05d160910ea08f32ac62bfdf7f5ec305ff5b62e9113b55f385abab4d5a4ad711aabcb1eb7ef746eb41f841b196e8fb5393ab3ccc01e
2023-01-03 13:02:20 -05:00
Andrew Chow
65d7c31b3f
Merge bitcoin/bitcoin#25789: test: clean and extend availablecoins_tests coverage
9622fe64b8 test: move coins result test to wallet_tests.cpp (furszy)
f69347d058 test: extend and simplify availablecoins_tests (furszy)
212ccdf2c2 wallet: AvailableCoins, add arg to include/skip locked coins (furszy)

Pull request description:

  Negative PR with extended test coverage :).

  1) Cleaned duplicated code and added coverage for the 'AvailableCoins' incremental result.

  2) The class `AvailableCoinsTestingSetup` inside `availablecoins_tests.cpp` is a plain copy
  of `ListCoinsTestingSetup` that is inside `wallet_tests.cpp`.

      So, deleted the file and moved the `BasicOutputTypesTest` test case to `wallet_tests.cpp`.

  3) Added arg to include/skip locked coins from the `AvailableCoins` result. This is needed for point (1) as otherwise the wallet will spend the coins that we recently created due its closeness to the recipient amount.
  Note: this last point comes from #25659 where I'm using the same functionality to clean/speedup another flow as well.

ACKs for top commit:
  achow101:
    ACK 9622fe64b8
  theStack:
    ACK 9622fe64b8
  aureleoules:
    reACK 9622fe64b8, nice cleanup!

Tree-SHA512: 1ed9133120bfe8815455d1ad317bb0ff96e11a0cc34ee8098716ab9b001749168fa649212b2fa14b330c1686cb1f29039ff1f88ae306db68881b0428c038f388
2023-01-03 12:52:40 -05:00
Andrew Chow
7bb07bf8bd
Merge bitcoin/bitcoin#25932: refactor: Simplify backtrack logic
81d4a2b14f refactor: Move feerate comparison invariant outside of the loop (yancy)
365aca4045 refactor: Simplify feerate comparison statement (yancy)

Pull request description:

  This is a small nit, however I think it's more understandable to write:

  `utxo_pool.at(0).fee > utxo_pool.at(0).long_term_fee`

  vs

  `(utxo_pool.at(0).fee - utxo_pool.at(0).long_term_fee) > 0`

ACKs for top commit:
  Xekyo:
    ACK 81d4a2b14f
  achow101:
    ACK 81d4a2b14f
  aureleoules:
    ACK 81d4a2b14f

Tree-SHA512: 3e89377989c36716b53114fe40178261671dde5688075fab1c21ec173ac310f8c84ed6af90354d7c329176cb7262dfcaa7191fd19847d3b7147a9a10c3e31176
2023-01-03 12:26:19 -05:00
Andrew Chow
1e6b384d59
Merge bitcoin/bitcoin#26702: refactor: walletdb: drop unused FindWalletTx parameter and rename
f496528556 walletdb: refactor: drop unused `FindWalletTx` parameter and rename (Sebastian Falbesoner)

Pull request description:

  Since commit 3340dbadd3 ("Remove -zapwallettxes"), the `FindWalletTx` helper is only needed to read tx hashes, so drop the other parameter and rename the method accordingly.

ACKs for top commit:
  S3RK:
    code review ACK f496528556
  achow101:
    ACK f496528556
  vincenzopalazzo:
    ACK f496528556

Tree-SHA512: ead85bc724462f9e920f9d7fe89679931361187579ffd6e63427c8bf5305cd5f71da24ed84f3b1bd22a12be46b5abec13f11822e71a3e1a63bf6cf49de950ab5
2023-01-03 11:54:51 -05:00
MarcoFalke
eeee61065f
Use AutoFile and HashVerifier where possible 2023-01-03 12:55:29 +01:00