Commit graph

36230 commits

Author SHA1 Message Date
Aurèle Oulès
6b563cae92
wallet: Check max tx weight in coin selector
Co-authored-by: Andrew Chow <github@achow101.com>
2022-12-05 19:32:11 +01:00
Andrew Chow
3eb041f014 wallet: Change coin selection fee assert to error
Returning an error instead of asserting for the low fee check will be
better as it does not crash the node and instructs users to report the
bug.
2022-12-05 12:59:22 -05:00
Andrew Chow
7734a0160d
Merge bitcoin/bitcoin#26640: test: Run mempool_compatibility.py with MiniWallet
fa43f60a0c test: Run mempool_compatibility.py with MiniWallet (MarcoFalke)

Pull request description:

  By using the already existing miniwallet, the test can be run even when no wallet is compiled.

ACKs for top commit:
  glozow:
    ACK fa43f60a0c
  achow101:
    ACK fa43f60a0c

Tree-SHA512: 6877b3f2f364663f04c28ab9f3d69780de6d1b77cc862379bba8c8242bbcfb0d26eb84c56cf721141407c393f1f3b49f667ae4fb32b3566108d71250e8b5d7bc
2022-12-05 12:39:15 -05:00
Andrew Chow
f0c4807a6a
Merge bitcoin/bitcoin#26560: wallet: bugfix, invalid CoinsResult cached total amount
7362f8e5e2 refactor: make CoinsResult total amounts members private (furszy)
3282fad599 wallet: add assert to SelectionResult::Merge for safety (S3RK)
c4e3b7d6a1 wallet: SelectCoins, return early if wallet's UTXOs cannot cover the target (furszy)
cac2725fd0 test: bugfix, coinselector_test, use 'CoinsResult::Erase/Add' instead of direct member access (furszy)
cf79384697 test: Coin Selection, duplicated preset inputs selection (furszy)
341ba7ffd8 test: wallet, coverage for CoinsResult::Erase function (furszy)
f930aefff9 wallet: bugfix, 'CoinsResult::Erase' is erasing only one output of the set (furszy)

Pull request description:

  This comes with #26559.

  Solving few bugs inside the wallet's transaction creation
  process and adding test coverage for them.
  Plus, making use of the `CoinsResult::total_amount` cached value
  inside the Coin Selection process to return early if we don't have
  enough funds to cover the target amount.

  ### Bugs

  1) The `CoinsResult::Erase` method removes only one
  output from the available coins vector (there is a [loop break](c1061be14a/src/wallet/spend.cpp (L112))
  that should have never been there) and not all the preset inputs.

     Which on master is not a problem, because since [#25685](https://github.com/bitcoin/bitcoin/pull/25685)
     we are no longer using the method. But, it's a bug on v24
     (check [#26559](https://github.com/bitcoin/bitcoin/pull/26559)).

     This method it's being fixed and not removed because I'm later using it to solve
     another bug inside this PR.

  2) As we update the total cached amount of the `CoinsResult` object inside
     `AvailableCoins` and we don't use such function inside the coin selection
     tests (we manually load up the `CoinsResult` object), there is a discrepancy
     between the outputs that we add/erase and the total amount cached value.

  ### Improvements

  * This makes use of the `CoinsResult` total amount field to early return
    with an "Insufficient funds" error inside Coin Selection if the tx target
    amount is greater than the sum of all the wallet available coins plus the
    preset inputs amounts (we don't need to perform the entire coin selection
    process if we already know that there aren't enough funds inside our wallet).

  ### Test Coverage

  1) Adds test coverage for the duplicated preset input selection bug that we have in v24.
    Where the wallet invalidly selects the preset inputs twice during the Coin Selection
    process. Which ends up with a "good" Coin Selection result that does not cover the
    total tx target amount. Which, alone, crashes the wallet due an insane fee.
    But.. to make it worst, adding the subtract fee from output functionality
    to this mix ends up with the wallet by-passing the "insane" fee assertion,
    decreasing the output amount to fulfill the insane fee, and.. sadly,
    broadcasting the tx to the network.

  2) Adds test coverage for the `CoinsResult::Erase` method.

  ------------------------------------

  TO DO:
  * [ ] Update [#26559 ](https://github.com/bitcoin/bitcoin/pull/26559) description.

ACKs for top commit:
  achow101:
    ACK 7362f8e5e2
  glozow:
    ACK 7362f8e5e2, I assume there will be a followup PR to add coin selection sanity checks and we can discuss the best way to do that there.
  josibake:
    ACK [7362f8e](7362f8e5e2)

Tree-SHA512: 37a6828ea10d8d36c8d5873ceede7c8bef72ae4c34bef21721fa9dad83ad6dba93711c3170a26ab6e05bdbc267bb17433da08ccb83b82956d05fb16090328cba
2022-12-05 12:00:45 -05:00
fanquake
203886c443
Fixup clang-tidy named argument comments
Fix comments so they are checked/consistent.
Fix incorrect arguments.
2022-12-05 15:51:46 +00:00
MarcoFalke
38cbf43dee
Merge bitcoin/bitcoin#26414: test: Move tx creation to create_self_transfer_multi
0b78110f73 test: Move tx creation to create_self_transfer_multi (kouloumos)

Pull request description:

  Two birds with one stone: replacement of https://github.com/bitcoin/bitcoin/pull/26278 with simplification of the MiniWallet's transaction creation logic.

  Currently the MiniWallet creates simple txns (1 input, 1 output) with `create_self_transfer`.  https://github.com/bitcoin/bitcoin/pull/24637 introduced `create_self_transfer_multi` **which uses** `create_self_transfer` to create a "transaction template" which then adjusts (copy and mutate inputs and outputs) in order to create more complex multi-input multi-output transactions.
  This can more easily lead to issues such as https://github.com/bitcoin/bitcoin/pull/26278 and is more of a maintenance burden.

  This PR simplifies the logic by going the other way around. Now `create_self_transfer` **uses** `create_self_transfer_multi`.
  The transaction creation logic has been moved to `create_self_transfer_multi` which is being called by `create_self_transfer` to construct the simple case of 1 input 1 output transaction.

ACKs for top commit:
  MarcoFalke:
    ACK 0b78110f73 👒

Tree-SHA512: 147e577ed5444bee57865bd375b37c9b49d6539e9875c30c2667e70fcba27fe80bcb4552a4e6efb42760d34b40d5dad826883b778eaeefe29425ec081787b4bd
2022-12-05 16:22:42 +01:00
MarcoFalke
5b3f05b7eb
Merge bitcoin/bitcoin#24226: rpc: warn that nodes ignore requests for old stale blocks
f39d9269eb rpc: warn that nodes ignore requests for old stale blocks (Sjors Provoost)

Pull request description:

  Adds warning to RPC help that `getblockfrompeer` is of little use for stale blocks that are more than a month old.

  This is an anti-fingerprinting measure. See `BlockRequestAllowed` in `net_processing`.

  It's been in Bitcoin Core since 2014, introduced in #2910 and later improved to not rely on checkpoints.
  Older and alternative clients might still serve these blocks, so not throwing an error.

  Allowing whitelisted nodes to fetch these blocks anyway might be nice.

ACKs for top commit:
  fjahr:
    Code review ACK f39d9269eb

Tree-SHA512: db88f9f7521289640c5e629c840dda1c2c3ab70d458e9e7136c60fbaeb02acfb36dc093502d83d4c098c331e22aab81bf8f4c4961d805e3bde0f8f3cfe68d968
2022-12-05 14:01:59 +01:00
MarcoFalke
fa43f60a0c
test: Run mempool_compatibility.py with MiniWallet 2022-12-05 13:13:00 +01:00
fanquake
71abee86db
Merge bitcoin/bitcoin#25993: doc: Add I2P guidance related to bandwidth and i2pd software version
874c861885 doc: Add I2P bandwidth guidance to i2p.md (willcl-ark)

Pull request description:

  Add some general guidance on lowering bandwidth usage when using I2P routers.

ACKs for top commit:
  jonatack:
    ACK 874c861885
  hernanmarino:
    ACK 874c861885
  pablomartin4btc:
    ACK 874c861885.

Tree-SHA512: 3990375b23c01a2ad8e15a51e1b1a0275df8747ecd789ddf1888fbc88c20cde5a3813615982669af5e8d021dc995f6c7b1f080167b33f48574d6f50fc4851498
2022-12-05 11:45:23 +00:00
glozow
8b796866b4
Merge bitcoin/bitcoin#26624: refactor: Rename local variable to distinguish it from type alias
1984db1d50 refactor: Rename local variable to distinguish it from type alias (Hennadii Stepanov)

Pull request description:

  The `txiter` type alias is declared in the `txmempool.h`: 9e59d21fbe/src/txmempool.h (L406)

ACKs for top commit:
  stickies-v:
    ACK 1984db1d5
  vasild:
    ACK 1984db1d50
  jarolrod:
    ACK 1984db1d50

Tree-SHA512: 127bfb62627e2d79d8cdb0bd0ac11b3737568c3631b54b2d1e37984f673a1f60edf7bc102a269f7eb40e4bb124b910b924a89475c6a6ea978b2171219fa30685
2022-12-05 11:15:41 +00:00
fanquake
fe8d15c907
Merge bitcoin/bitcoin#26630: test: Fix intermittent issue in rpc_net.py
fadf7b8fef test: Fix intermittent issue in rpc_net.py (MarcoFalke)

Pull request description:

  Both nodes must be aware of the closed connections before re-connecting, otherwise the test will fail.

  Fixes #25741

ACKs for top commit:
  jarolrod:
    ACK fadf7b8fef

Tree-SHA512: 0492dd59a46516007e903fe8f6288982e305d4fd152a0297dd60e10ac663efc9bdc0bc6d1d2c6ec5f239196dac08319f37b079401fe057e4864b117b0fd9dcbc
2022-12-04 15:04:20 +00:00
MarcoFalke
fadf7b8fef
test: Fix intermittent issue in rpc_net.py 2022-12-03 17:42:05 +01:00
MarcoFalke
cac29f5cd6
Merge bitcoin/bitcoin#26622: test: Add test for sendall min-fee setting
cb44c5923a test: Add sendall test for min-fee setting (Aurèle Oulès)

Pull request description:

  While experimenting with mutation testing it appeared that the minimum fee-rate check was not tested for the `sendall` RPC.

  https://bcm-ui.aureleoules.com/mutations/3581479318544ea6b97f788cec6e6ef1

ACKs for top commit:
  0xB10C:
    ACK cb44c5923a
  ishaanam:
    ACK cb44c5923a
  stickies-v:
    re-ACK [cb44c59](cb44c5923a)

Tree-SHA512: 31978436e1f01cc6abf44addc62b6887e65611e9a7ae7dc72e6a73cdfdb3a6a4f0a6c53043b47ecd1b10fc902385a172921e68818a7f5061c96e5e1ef5280b48
2022-12-03 12:28:13 +01:00
Ryan Ofsky
d1ca563825 bitcoin-cli: Make it an error to specify the "args" parameter two different ways
MarcoFalke reported the case of positional arguments silently overwriting the
named "args" parameter in bitcoin-cli
https://github.com/bitcoin/bitcoin/pull/19762#discussion_r1035761471 and this
behavior is confusing and was not intended when support for "args" parameters
was added to bitcoin-cli in #19762.

Instead of letting one "args" value overwrite the other in the client, just
pass the values to the server verbatim, and let the error be handled server
side.
2022-12-02 17:53:58 -05:00
Ryan Ofsky
6bd1d20b8c rpc: Make it an error server-side to specify same named parameter multiple times
Specifying same named parameter multiple times is still allowed by bitcoin-cli.
The client implementation overwrites earlier option values with later ones
before sending to server. This is tested by interface_bitcoin_cli.py

Rationale for allowing client parameters to be specified multiple times in
bitcoin-cli is that this behavior has been supported for a long time, and that
when using the command line interactively, it can be convenient to override
earlier option values with new values without having to go back and remove the
old value.

But for the RPC server, there isn't really a good use-case for earlier values
to be discarded if multiple values are specified. JSON keys are generally
supposed to be unique and if they aren't it's probably an indication of some
problem generating the RPC request.
2022-12-02 17:53:16 -05:00
Ryan Ofsky
e2c3b18e67 test: Add RPC tests for same named parameter specified more than once
Current behavior isn't ideal and will be changed in upcoming commits, but it's
useful to have test coverage regardless.

MarcoFalke reported the case of bitcoin-cli positional arguments overwriting
the named "args" parameter in
https://github.com/bitcoin/bitcoin/pull/19762#discussion_r1035761471
2022-12-02 17:37:08 -05:00
Hennadii Stepanov
5d332da2cf
doc: Drop no longer relevant comment
The comment was introduced in 4cf3411056,
and since 7e4bd19785 it has been no longer
relevant.
2022-12-02 15:44:34 +00:00
furszy
7362f8e5e2
refactor: make CoinsResult total amounts members private 2022-12-02 12:39:16 -03:00
S3RK
3282fad599
wallet: add assert to SelectionResult::Merge for safety 2022-12-02 12:39:15 -03:00
furszy
c4e3b7d6a1
wallet: SelectCoins, return early if wallet's UTXOs cannot cover the target
The CoinsResult class will now count the raw total amount and the effective
total amount internally (inside the 'CoinsResult::Add' and 'CoinsResult::Erase'
methods).
So there is no discrepancy between what we add/erase and the total values.
(which is what was happening on the coinselector_test because the 'CoinsResult'
object is manually created there, and we were not keeping the total amount
in sync with the outputs being added/removed).
2022-12-02 12:39:15 -03:00
furszy
cac2725fd0
test: bugfix, coinselector_test, use 'CoinsResult::Erase/Add' instead of direct member access
Aside from the cleanup, this solves a bug in the following-up commit. Because, in these
tests, we are manually adding/erasing outputs from the CoinsResult object but never
updating the internal total amount field.
2022-12-02 12:39:15 -03:00
furszy
cf79384697
test: Coin Selection, duplicated preset inputs selection
This exercises the bug inside CoinsResult::Erase that
ends up on (1) a wallet crash or (2) a created and
broadcasted tx that contains a reduced recipient's amount.

This is covered by making the wallet selects the preset
inputs twice during the coin selection process.

Making the wallet think that the selection process result covers
the entire tx target when it does not. It's actually creating
a tx that sends more coins than what inputs are covering for.

Which, combined with the SFFO option, makes the wallet
incorrectly reduce the recipient's amount by the difference
between the original target and the wrongly counted inputs.
Which means, a created and relayed tx sending less coins to
the destination than what the user inputted.
2022-12-02 12:39:15 -03:00
furszy
341ba7ffd8
test: wallet, coverage for CoinsResult::Erase function 2022-12-02 12:39:15 -03:00
fanquake
78aee0fe2c
Merge bitcoin/bitcoin#26569: p2p: Ensure transaction announcements are only queued for fully connected peers
8f2dac5409 [test] Add p2p_tx_privacy.py (dergoegge)
ce63fca13e [net processing] Assume that TxRelay::m_tx_inventory_to_send is empty pre-verack (dergoegge)
845e3a34c4 [net processing] Ensure transaction announcements are only queued for fully connected peers (dergoegge)

Pull request description:

  `TxRelay::m_next_inv_send_time` is initialized to 0, which means that any txids in `TxRelay::m_tx_inventory_to_send` will be announced on the first call to `PeerManagerImpl::SendMessages` for a fully connected peer (i.e. it completed the version handshake).

  Prior to #21160, `TxRelay::m_tx_inventory_to_send` was guaranteed to be empty on the first `SendMessages` call, as transaction announcements were only queued for fully connected peers. #21160 replaced a `CConnman::ForEachNode` call with a loop over `PeerManagerImpl::m_peer_map`, in which the txid for a transaction to be relayed is added to `TxRelay::m_tx_inventory_to_send` for all peers. Even for those peers that have not completed the version handshake. Prior to the PR this was not the case as `ForEachNode` has a "fully connected check" before calling a function for each node.

ACKs for top commit:
  MarcoFalke:
    ACK 8f2dac5409 🔝
  jnewbery:
    utACK 8f2dac5409

Tree-SHA512: e9eaccf7e00633ee0806fff1068b0e413a69a5e389d96c9659f68079915a6381ad5040c61f716cfcde77931d1b563b1049da97a232a95c6cd8355bd3d13404b9
2022-12-02 15:13:31 +00:00
Aurèle Oulès
cb44c5923a
test: Add sendall test for min-fee setting 2022-12-02 13:30:40 +01:00
Hennadii Stepanov
1984db1d50
refactor: Rename local variable to distinguish it from type alias
The `txiter` type alias is declared in the `txmempool.h`.
2022-12-02 11:25:35 +00:00
MarcoFalke
9e59d21fbe
Merge bitcoin/bitcoin#26592: ci: only run USDT interface tests on CirrusCI
2811f40f30 ci: only run USDT interface tests on CirrusCI (0xb10c)

Pull request description:

  As mentioned in #26571, the task running the USDT interface tests fail when run in docker. cc7335edc8 in #25528 added that the tests are run in a **VM** in Cirrus CI. Running them locally in docker containers might not work:

  - We use [bcc] as tracing toolkit which requires the kernel headers to compile the BPF bytecode. As docker containers use the hosts kernel and don't run their own, there is a potential for mismatches between kernel headers available in the container and the host kernel. This results in a failure loading the BPF byte code.
  - Privilges are required to load the BPF byte code into the kernel. Normally, the docker containers aren't run with these.
  - We currently use an untrusted third-party PPA to install the bpfcc-tools package on Ubuntu 22.04. Using this on a local dev system could be a security risk.

  To not hinder the ASan + LSan + UBSan part of the CI task, the USDT tests are disabled on non-CirrusCI runs.

  [bcc]: https://github.com/iovisor/bcc

Top commit has no ACKs.

Tree-SHA512: 7c159b59630b36d5ed927b501fa0ad6f54ff3d98d0902f975cc8122b4147a7f828175807d40a470a85f0f3b6eeb79307d3465a287dbd2f3d75b803769ad0b6e7
2022-12-02 10:52:52 +01:00
MarcoFalke
4037478114
Merge bitcoin/bitcoin#26610: test: Remove unused blocktools imports from wallet_bumpfee
fa15c671f7 test: Remove unused blocktools imports from wallet_bumpfee (MarcoFalke)

Pull request description:

  Seems bloaty and confusing to use "tools" when a single RPC can already achieve the same.

ACKs for top commit:
  theStack:
    ACK fa15c671f7

Tree-SHA512: 87f9c31bbb286fee5e479ae54a1f9131f4d4294d665a985df8b14a0cc837a2a2e145ccd3660612768d88cfa0827a3eef392f85519b6cb7df365ba9fadafb0a41
2022-12-02 09:43:26 +01:00
MarcoFalke
02515117dc
Merge bitcoin/bitcoin#26620: test: refactor: eliminate genesis block timestamp magic numbers
dbed28968a test: refactor: eliminate genesis block timestamp magic numbers (Sebastian Falbesoner)

Pull request description:

  This tiny PR replaces all occurences of the regtest/testnet genesis block timestamp (found via `git grep 1296688602`) with the constant `TIME_GENESIS_BLOCK` to increase the readability.

ACKs for top commit:
  aureleoules:
    ACK dbed28968a

Tree-SHA512: be39d5c2631ad20eb775c2a077b1b1f056a1a4930aa44e6fdec73b974fd4bdf8da0103a3a38e3514b68fcf6a6316e007a371c523da5076a315545c9bf3091aee
2022-12-01 18:37:59 +01:00
MarcoFalke
c6e7f224c1 util: Add StrFormatInternalBug and STR_INTERNAL_BUG 2022-12-01 12:22:47 -05:00
MarcoFalke
a04121bdf9
Merge bitcoin/bitcoin#26617: test: add extra_args to BitcoinTestFramework class
150340aeac test: remove unneeded extra_args code (josibake)
989a52e0a5 test: add extra_args to BTF class (josibake)

Pull request description:

  ## problem
  If you try to add `extra_args` when using `TestShell`, you will get the following error:

  ```python
  >>> import sys
  >>>
  >>> sys.path.insert(0, "/home/josibake/bitcoin/test/functional")
  >>>
  >>> from test_framework.test_shell import TestShell
  >>> test = TestShell().setup(num_nodes=2, extra_args=[[],['-fallbackfee=0.0002']])
  Traceback (most recent call last):
    File "<stdin>", line 1, in <module>
    File "/home/josibake/bitcoin/test/functional/test_framework/test_shell.py", line 41, in setup
      raise KeyError(key + " not a valid parameter key!")
  KeyError: 'extra_args not a valid parameter key!'
  >>>
  ```

  ## solution

  add `self.extra_args = None` so that `extra_args` is recognized as a valid parameter to be passed to `BitcoinTestFramework`

  ```python
  >>> import sys
  >>>
  >>> sys.path.insert(0, "/home/josibake/bitcoin/test/functional")
  >>>
  >>> from test_framework.test_shell import TestShell
  >>> test = TestShell().setup(num_nodes=2, extra_args=[[],['-fallbackfee=0.0002']])
  2022-12-01T11:23:23.765000Z TestFramework (INFO): Initializing test directory /tmp/bitcoin_func_test_sbwthbb_
  ```

ACKs for top commit:
  willcl-ark:
    re-ACK 150340aeac

Tree-SHA512: e6fa2a780a8f2d3472c322e8cdb00ec35cb220c3b4d6ca02291eb8b41c0d8676a635fbc79c6be80e3bb71d700a2501a4b73f762478f533ae453d492d449307bb
2022-12-01 17:50:46 +01:00
josibake
150340aeac
test: remove unneeded extra_args code 2022-12-01 16:55:43 +01:00
Sebastian Falbesoner
dbed28968a test: refactor: eliminate genesis block timestamp magic numbers 2022-12-01 12:59:59 +01:00
josibake
989a52e0a5
test: add extra_args to BTF class
this allows us to pass extra_args when using TestShell
2022-12-01 12:14:10 +01:00
fanquake
e334f7a545
Merge bitcoin/bitcoin#26594: wallet: Avoid a segfault in migratewallet failure cleanup
5e65a216d1 wallet: Explicitly say migratewallet on encrypted wallets is unsupported (Andrew Chow)
88afc73ae0 tests: Test for migrating encrypted wallets (Andrew Chow)
86ef7b3c7b wallet: Avoid null pointer deref when cleaning up migratewallet (Andrew Chow)

Pull request description:

  When `migratewallet` fails, we do an automatic cleanup in order to reset everything so that the user does not experience any interruptions. However, this apparently has a segfault in it, caused by the the pointers to the watchonly and solvables wallets being nullptr. If those wallets are not created (either not needed, or failed early on), we will accidentally attempt to dereference these nullptrs, which causes a segfault.

  This failure can be easily reached by trying to migrate an encrypted wallet. Currently, we can't migrate encrypted wallets because of how we unload wallets before migrating, and therefore forget the encryption key if the wallet was unlocked. So any encrypted wallets will fail, entering the cleanup, and because watchonly and solvables wallets don't exist yet, the segfault is reached.

  This PR fixes this by not putting those nullptrs in a place that we will end up dereferencing them later. It also adds a test that uses the encrypted wallet issue.

ACKs for top commit:
  S3RK:
    reACK 5e65a216d1
  stickies-v:
    ACK [5e65a21](5e65a216d1)
  furszy:
    diff ACK 5e65a21

Tree-SHA512: f75643797220d4232ad3ab8cb4b46d0f3667f00486e910ca748c9b6d174d446968f1ec4dd7f907da1be9566088849da7edcd8cd8f12de671c3241b513deb8e80
2022-12-01 10:17:09 +00:00
dergoegge
8f2dac5409 [test] Add p2p_tx_privacy.py 2022-11-30 16:36:16 +00:00
Andrew Chow
e2bfd41f83
Merge bitcoin/bitcoin#25942: test: add ismine test for descriptor ScriptPubKeyMan
1b77db2653 test: add `ismine` test for descriptor scriptpubkeyman (w0xlt)

Pull request description:

  Currently `src/wallet/test/ismine_tests.cpp` has tests for the legacy ScriptPubKeyMan only.
  This PR adds tests for the descriptor ScriptPubKeyMan.

ACKs for top commit:
  ishaanam:
    ACK 1b77db2653
  achow101:
    ACK 1b77db2653
  furszy:
    ACK 1b77db26 with a non-blocking comment.

Tree-SHA512: 977b5d1e71f9468331aeb4ebaf3708dd651f9f3018d4544a395b87ca6d7fb8bfa6d20acc1a4f6e096e240e81d30fb7a6e8add190e52536e7a3cb5a80f392883f
2022-11-30 11:28:32 -05:00
MarcoFalke
fa15c671f7
test: Remove unused blocktools imports from wallet_bumpfee 2022-11-30 16:59:21 +01:00
Andrew Chow
5e65a216d1 wallet: Explicitly say migratewallet on encrypted wallets is unsupported 2022-11-30 10:30:57 -05:00
dergoegge
ce63fca13e [net processing] Assume that TxRelay::m_tx_inventory_to_send is empty pre-verack
This commit documents our assumption about
TxRelay::m_tx_inventory_to_send being empty prior to version handshake
completion.

The added Assume acts as testing oracle for our fuzzing tests to
potentially detect if the assumption is violated.
2022-11-30 12:22:05 +00:00
fanquake
bcee94d107
Merge bitcoin/bitcoin#26359: p2p: Erlay support signaling follow-ups
46339d29b1 test, refactor: Reorder sendtxrcncl tests for better readability (Gleb Naumenko)
14263c13f1 p2p, refactor: Extend logs for unexpected sendtxrcncl (Gleb Naumenko)
87493e112e p2p, test, refactor: Minor code improvements (Gleb Naumenko)
00c5dec818 p2p: Clarify sendtxrcncl policies (Gleb Naumenko)
ac6ee5ba21 test: Expand unit and functional tests for txreconciliation (Gleb Naumenko)
bc84e24a4f p2p, refactor: Switch to enum class for ReconciliationRegisterResult (Gleb Naumenko)
a60f729e29 p2p: Drop roles from sendtxrcncl (Gleb Naumenko)
6772cbf69c tests: stabilize sendtxrcncl test (Gleb Naumenko)

Pull request description:

  Non-trivial changes include:
  - Getting rid of roles in `sendtxrcncl` message (summarized in the [BIP PR](https://github.com/bitcoin/bips/pull/1376));
  - Disconnect the peer if it send `sendtxrcncl` although we are in `blocksonly` and notified the peer with `fRelay=0`;
  - Don't send `sendtxrcncl` to feeler connections.

ACKs for top commit:
  vasild:
    ACK 46339d29b1
  ariard:
    ACK 46339d2
  mzumsande:
    Code Review ACK 46339d29b1

Tree-SHA512: b5cc6934b4670c12b7dbb3189e739ef747ee542ec56678bf4e4355bfb481b746d32363c173635685b71969b3fe4bd52b1c8ebd3ea3b35c82044bba69220f6417
2022-11-30 10:52:44 +00:00
Hennadii Stepanov
38941a703e
refactor: Move txmempool_entry.h --> kernel/mempool_entry.h 2022-11-30 10:37:57 +00:00
MarcoFalke
3be21060d6
Merge bitcoin/bitcoin#26600: test: Set wallet type in test_runner when only one type is allowed
fadb8696dd test: Set wallet type in test_runner when only one type is allowed (MarcoFalke)

Pull request description:

  Currently devs are free to set or not set the wallet type in the test_runner when only one type is allowed to be set.

  This is inconsistent and causes review comments such as:

  * https://github.com/bitcoin/bitcoin/pull/24865#discussion_r1009752111

ACKs for top commit:
  achow101:
    ACK fadb8696dd

Tree-SHA512: 1ca0946df07b5bf6778fea957d74393757781c324d554fec2f7d03bf1915033e644d9a4c3d77e0b24090ab593d7ed3cb3c9169666bc39fff423706fceaa1af80
2022-11-30 10:23:05 +01:00
Andrew Chow
88afc73ae0 tests: Test for migrating encrypted wallets
Due to an oversight, we cannot currently migrate encrypted wallets,
regardless of whether they are unlocked. Migrating such wallets will
trigger an error, and result in the cleanup being run. This conveniently
allows us to check some parts of the cleanup code.
2022-11-29 19:31:27 -05:00
Andrew Chow
86ef7b3c7b wallet: Avoid null pointer deref when cleaning up migratewallet
If migratewallet fails, we do a cleanup which removes the watchonly and
solvables wallets if they were created. However, if they were not, their
pointers are nullptr and we don't check for that, which causes a
segfault during the cleanup. So check that they aren't nullptr before
cleaning them up.
2022-11-29 19:31:27 -05:00
Andrew Chow
5690848dfb
Merge bitcoin/bitcoin#26532: wallet: bugfix, invalid crypted key "checksum_valid" set
13d9760829 test: load wallet, coverage for crypted keys (furszy)
373c99633e refactor: move DuplicateMockDatabase to wallet/test/util.h (furszy)
ee7a984f85 refactor: unify test/util/wallet.h with wallet/test/util.h (furszy)
cc5a5e8121 wallet: bugfix, invalid crypted key "checksum_valid" set (furszy)

Pull request description:

  At wallet load time, the crypted key "checksum_valid" variable is always set to false. Which, on every wallet decryption call, forces the process to re-write all the ckeys to db when it's not needed.

  Note:
  The first commit fixes the issue, the two commits in the middle are cleanups so `DuplicateMockDatabase`
  can be used without duplicating code. And, the last one is pure test coverage for the crypted keys loading
  process.

  Includes test coverage for the following scenarios:

  1) "All ckeys checksums valid" test:
  Loads an encrypted wallet with all the crypted keys with a valid checksum and
  verifies that 'CWallet::Unlock' doesn't force an entire crypted keys re-write.

      (we force a complete ckeys re-write if we find any missing crypted key checksum
  during the wallet loading process)

  2) "Missing checksum in one ckey" test:
  Verifies that loading up a wallet with, at least one, 'ckey' with no checksum
  triggers a complete re-write of the crypted keys.

  3) "Invalid ckey checksum error" test:
  Verifies that loading up a ckey with an invalid checksum stops the wallet loading
  process with a corruption error.

  4) "Invalid ckey pubkey error" test:
  Verifies that loading up a ckey with an invalid pubkey stops the wallet loading
  process with a corruption error.

ACKs for top commit:
  achow101:
    ACK 13d9760829
  aureleoules:
    ACK 13d9760829

Tree-SHA512: 9ea630ee4a355282fbeee61ca04737294382577bb4b2631f50e732568fdab8f72491930807fbda58206446c4f26200cdc34d8afa14dbe1241aec713887d06a0b
2022-11-29 18:54:57 -05:00
Andrew Chow
a63192afb8
Merge bitcoin/bitcoin#19762: rpc: Allow named and positional arguments to be used together
d8b12a75db rpc: Allow named and positional arguments to be used together (Ryan Ofsky)

Pull request description:

  It's nice to be able to use named options and positional arguments together.

  Most shell tools accept both, and python functions combine options and arguments allowing them to be passed with even more flexibility. This change adds support for python's approach so as a motivating example:

  ```sh
  bitcoin-cli -named createwallet wallet_name=mywallet load_on_startup=1
  ```

  Can be shortened to:

  ```sh
  bitcoin-cli -named createwallet mywallet load_on_startup=1
  ```

  JSON-RPC standard doesn't have a convention for passing named and positional parameters together, so this implementation makes one up and interprets any unused `"args"` named parameter as a positional parameter array.

  This change is backwards compatible. It doesn't change the interpretation of any previously valid calls, just treats some previously invalid calls as valid.

  Another use case even if you only occasionally use named arguments is that you can define an alias:

  ```
  alias bcli='bitcoin-cli -named'
  ```

  And now use both named named and unnamed arguments from the same alias without having to manually add `-named` option for named arguments or see annoying error "No '=' in named argument... this needs to be present for every argument (even if it is empty)`" for unnamed arguments

ACKs for top commit:
  achow101:
    ACK d8b12a75db
  stickies-v:
    re-ACK d8b12a75d
  aureleoules:
    re-ACK d8b12a75db

Tree-SHA512: 0cff8b50f584bcbbd376624adccf40536566ed8d1bcd6c88ad565dbc208f19d5e7a48c994efd6329d42b560149340d330397278f08a2912af5f3418d8c8837a9
2022-11-29 18:37:55 -05:00
stickies-v
f537127271
doc: fix: prevHeights entries are set to 0, not removed 2022-11-29 17:58:36 +00:00
furszy
f930aefff9
wallet: bugfix, 'CoinsResult::Erase' is erasing only one output of the set
The loop break shouldn't have being there.
2022-11-29 12:30:31 -03:00
dergoegge
845e3a34c4 [net processing] Ensure transaction announcements are only queued for fully connected peers 2022-11-29 13:54:50 +00:00