Commit graph

6680 commits

Author SHA1 Message Date
merge-script
42326b0fa4
Merge bitcoin/bitcoin#30512: net: Log accepted connection after m_nodes.push_back; Fix intermittent test issue
fa3ea3b83c test: Fix intermittent issue in p2p_v2_misbehaving.py (MarcoFalke)
55555574d1 net: Log accepted connection after m_nodes.push_back (MarcoFalke)

Pull request description:

  Fix the two issues reported in https://github.com/bitcoin/bitcoin/pull/30468/files#r1688444784:

  * Delay a debug log line for consistency.
  * Fix an intermittent test issue.

  They are completely separate fixes, but both `net` related.

ACKs for top commit:
  0xB10C:
    Code Review ACK fa3ea3b83c
  stratospher:
    tested ACK fa3ea3b.

Tree-SHA512: cd6b6e164b317058a305a5c3e38c56c9a814a7469039e1143f1d7addfbc91b0a28506873356b373d97448b46cb6fbe94a1309df82e34c855540b241a09489e8b
2024-08-05 14:51:39 +01:00
merge-script
1afa3c84fc
Merge bitcoin/bitcoin#30562: PayToAnchor(P2A) followups
2a3a24296e test: check that P2A with witness data is still consensus-legal (Greg Sanders)
68bd86cd7c test: P2A is a destination type with an address (Greg Sanders)

Pull request description:

  Followups for https://github.com/bitcoin/bitcoin/pull/30352

  Suggestions taken:
  https://github.com/bitcoin/bitcoin/pull/30352#discussion_r1698542647
  https://github.com/bitcoin/bitcoin/pull/30352#discussion_r1698563426

ACKs for top commit:
  tdb3:
    ACK 2a3a24296e
  glozow:
    ACK 2a3a24296e
  theStack:
    ACK 2a3a24296e

Tree-SHA512: 5de865b2c300fa504dbdbd5879649a6fc328da052ad8bf9479e3fea0c49c516d824908a87523ec1fb30cc536bffe2e116dd523a9b66a07f81f93429e42879f14
2024-08-05 13:27:36 +01:00
Peter Todd
590456e3f1 policy: enable full-rbf by default
Enable full rbf (mempool policy) by default and update tests accordingly.
2024-08-02 20:22:20 +00:00
Sebastian Falbesoner
5e87f30f7c test: check that keyless P2A 'signing' via signrawtransactionwithkey succeeds 2024-08-02 20:13:07 +02:00
Greg Sanders
2a3a24296e test: check that P2A with witness data is still consensus-legal 2024-08-02 13:03:06 -04:00
Greg Sanders
68bd86cd7c test: P2A is a destination type with an address 2024-08-02 13:03:06 -04:00
glozow
2aff9a36c3
Merge bitcoin/bitcoin#30352: policy: Add PayToAnchor(P2A), OP_1 <0x4e73> as a standard output script for spending
75648cea5a test: add P2A ProduceSignature coverage (Greg Sanders)
7998ce6b20 Add release note for P2A output feature (Greg Sanders)
71c9b02a04 test: add P2A coverage for decodescript (Greg Sanders)
1349e9ec15 test: Add anchor mempool acceptance test (Greg Sanders)
9d89209937 policy: stop 3rd party wtxid malleability of anchor spend (Greg Sanders)
b60aaf8b23 policy: make anchor spend standard (Greg Sanders)
455fca86cf policy: Add OP_1 <0x4e73> as a standard output type (Greg Sanders)

Pull request description:

  This is a sub-feature taken out of the original proposal for ephemeral anchors #30239

  This PR makes *spending* of `OP_1 <0x4e73>` (i.e. `bc1pfeessrawgf`) standard. Creation of this output type is already standard.

  Any future witness output types are considered relay-standard to create, but not to spend. This preserves upgrade hooks, such as a completely new output type for a softfork such as BIP341.  It also gives us a bit of room to use a new output type for policy uses.

  This particular sized witness program has no other known use-cases (https://bitcoin.stackexchange.com/a/110664/17078), s it affords insufficient cryptographic security for a secure commitment to data, such as a script or a public key. This makes this type of output "keyless", or unauthenticated.

  As a witness program, the `scriptSig` of the input MUST be blank, by BIP141. This helps ensure txid-stability of the spending transaction, which may be required for smart contracting wallets. If we do not use segwit, a miner can simply insert an `OP_NOP` in the `scriptSig` without effecting the result of program execution.

  An additional relay restriction is to disallow non-empty witness data, which an adversary may use to penalize the "honest" transactor when RBF'ing the transaction due to the incremental fee requirement of RBF rules.

  The intended use-case for this output type is to "anchor" the transaction with a spending child to bring exogenous CPFP fees into the transaction package, encouraging the inclusion of the package in a block. The minimal size of creation and spending of this output makes it an attractive contrast to outputs like `p2sh(OP_TRUE)` and `p2wsh(OP_TRUE)` which
  are significantly larger in vbyte terms.

  Combined with TRUC transactions which limits the size of child transactions significantly, this is an attractive option for presigned transactions that need to be fee-bumped after the fact.

ACKs for top commit:
  sdaftuar:
    utACK 75648cea5a
  theStack:
    re-ACK 75648cea5a
  ismaelsadeeq:
    re-ACK 75648cea5a via [diff](e7ce6dc070..75648cea5a)
  glozow:
    ACK 75648cea5a
  tdb3:
    ACK 75648cea5a

Tree-SHA512: d529de23d20857e6cdb40fa611d0446b49989eaafed06c28280e8fd1897f1ed8d89a4eabbec1bbf8df3d319910066c3dbbba5a70a87ff0b2967d5205db32ad1e
2024-08-02 15:49:44 +01:00
merge-script
df241970a3
Merge bitcoin/bitcoin#30554: test: Avoid CScript() as default function argument
fa46a1b74b test: Avoid CScript() as default function argument (MarcoFalke)
fadf621825 test: Make leaf_script mandatory when scriptpath is set in TaprootSignatureMsg (MarcoFalke)

Pull request description:

  Unlike other function calls in default arguments, CScript should not cause any issues in the tests, because they are const.

  However, this change allows to enable the "function-call-in-default-argument (B008)" lint rule, which will help to catch severe test bugs, such as https://github.com/bitcoin/bitcoin/issues/30543#issuecomment-2259260024 .

  The lint rule will be enabled in a follow-up, when all violations are fixed.

ACKs for top commit:
  instagibbs:
    utACK fa46a1b74b
  theStack:
    lgtm ACK fa46a1b74b
  ismaelsadeeq:
    Tested ACK fa46a1b74b

Tree-SHA512: bc68b15121d50ead0fc70ad772360a7829908aedeaff8426efcb8a67f33117f67d26b4f5da94fa735dd8de9c9ff65fc10a29323f1b12f238b75486fa7cc32a89
2024-08-02 14:02:04 +01:00
MarcoFalke
faed533743
test: Disable known broken USDT test for now
(cherry picked from commit faf8be7c32)
2024-08-02 14:02:42 +02:00
glozow
b8755164cf
Merge bitcoin/bitcoin#30413: p2p: Lazy init some bloom filters; fuzz version handshake
afd237bb5d [fuzz] Harness for version handshake (dergoegge)
a90ab4aec9 scripted-diff: Rename lazily initialized bloom filters (dergoegge)
82de1bc478 [net processing] Lazily initialize m_recent_confirmed_transactions (dergoegge)
fa0c87f19c [net processing] Lazily initialize m_recent_rejects_reconsiderable (dergoegge)
662e8db2d3 [net processing] Lazily initialize m_recent_rejects (dergoegge)

Pull request description:

  This adds a fuzzing harness dedicated to the version handshake. To avoid determinism issues, the harness creates necessary components each iteration (addrman, peerman, etc). A harness like this would have easily caught https://bitcoincore.org/en/2024/07/03/disclose-timestamp-overflow/.

  As a performance optimization, this PR includes a change to `PeerManager` to lazily initialize various filters (to avoid large unnecessary memory allocations each iteration).

ACKs for top commit:
  brunoerg:
    ACK afd237bb5d
  marcofleon:
    Tested ACK afd237bb5d. I compared the coverage  of `net_processing` from this harness to the `process_message` and `process_messages` harnesses to see the differences. This target hits more specific parts of the version handshake. The stability looks good as well, at about 94%.
  glozow:
    utACK afd237bb5d lazy blooms look ok
  mzumsande:
    Code Review ACK afd237bb5d

Tree-SHA512: 62bba20aec0cd220e62368354891f9790b81ad75e8adf7b22a76a6d4663bd26aedc4cae8083658a75ea9043d60aad3f0e58ad36bd7bbbf93ff1d16e317bf15cc
2024-08-01 09:48:24 +01:00
MarcoFalke
fa46a1b74b
test: Avoid CScript() as default function argument
This does not cause any issues, because CScript in the tests are const.
However, this change allows to enable the
"function-call-in-default-argument (B008)" lint rule.
2024-07-31 15:19:10 +02:00
dergoegge
a90ab4aec9 scripted-diff: Rename lazily initialized bloom filters
-BEGIN VERIFY SCRIPT-
sed -i 's/m_recent_confirmed_transactions/m_lazy_recent_confirmed_transactions/g' $(git grep -l 'm_recent_confirmed_transactions')
sed -i 's/m_recent_rejects_reconsiderable/m_lazy_recent_rejects_reconsiderable/g' $(git grep -l 'm_recent_rejects_reconsiderable')
sed -i 's/m_recent_rejects/m_lazy_recent_rejects/g' $(git grep -l 'm_recent_rejects')
-END VERIFY SCRIPT-
2024-07-31 13:23:46 +01:00
MarcoFalke
fa2269dd65
test: Try previously intermittently broken USDT test again
This reverts commit faf8be7c32.
2024-07-31 14:06:51 +02:00
merge-script
33884e7e60
Merge bitcoin/bitcoin#30545: test: fix intermittent failures in feature_proxy.py
a6efc7e16e test: fix intermittent failures in feature_proxy.py (Martin Zumsande)

Pull request description:

  Fixes #29871

  If addnode connections are made with v2transport and the peer immediately disconnects us, reconnections with v1 are scheduled. This could interfere with later checks depending on timing. Avoid this by using `v2transport=False` in the addnode rpc - this test isn't about the message layer anyway, so running it with v2 would add no value.

ACKs for top commit:
  maflcko:
    ACK a6efc7e16e
  tdb3:
    cr re ACK a6efc7e16e

Tree-SHA512: 39353a392e75e4c6257d971ceecb65fb76ec6d3b121a087869831c24b767a18f57e2ae2968da445c7fa731cb03053c90df37dd2cd6e86f786ad4121bc68ca235
2024-07-31 12:03:22 +01:00
MarcoFalke
fadf621825
test: Make leaf_script mandatory when scriptpath is set in TaprootSignatureMsg
This removes the default value, because there should not be a use-case
to fall back to a an empty leaf_script by default. (If there was, it
could trivially be added back)
2024-07-31 09:57:42 +02:00
Martin Zumsande
ec5e294e4b test: fix constructor of msg_tx
In python, if the default value is a mutable object (here: a class)
its shared over all instances, so that one instance being changed
would affect others to be changed as well.
This was likely the source of various intermittent bugs in the
functional tests.
2024-07-30 17:49:07 -04:00
Greg Sanders
71c9b02a04 test: add P2A coverage for decodescript 2024-07-30 14:06:58 -04:00
Greg Sanders
1349e9ec15 test: Add anchor mempool acceptance test 2024-07-30 14:06:58 -04:00
Martin Zumsande
a6efc7e16e test: fix intermittent failures in feature_proxy.py
If addnode connections are made with v2transport and the peer immediately disconnects us, reconnections
with v1 are scheduled. This could interfere with later checks depending on timing. Avoid this by using
`v2transport=False` in the addnode rpc - this test isn't about the message layer anyway, so running it
with v2 would add no value.
2024-07-30 10:52:53 -04:00
merge-script
38c30a4b50
Merge bitcoin/bitcoin#30515: rpc: add utxo's blockhash and number of confirmations to scantxoutset output
17845e7f21 rpc: add utxo's blockhash and number of confirmations to scantxoutset output (Luis Schwab)

Pull request description:

  This PR resolves #30478 by adding two fields to the `scantxoutset` RPC:
  - blockhash: the blockhash that an UTXO was created
  - confirmations: the number of confirmations an UTXO has relative to the chaintip.

  The rationale for the first field is that a blockhash is a much more reliable identifier than the height:
  > When using the scantxoutset RPC, the current behaviour is to show the block height of the UTXO. This is not optimal, as block height is ambiguous, especially in the case of a block reorganization happening at the same instant of the query. In this case, an UTXO that does not exist would be assumed to exist, unless the chain's tip hash is recorded before the scan, and make sure it still exists after, as per https://github.com/bitcoindevkit/bdk/issues/895#issuecomment-1475766797 comment by evanlinjin.

  The second one was suggested by maflcko, and I agree it's useful for human users:
  > While touching this, another thing to add could be the number of confirmations? I understand that this wouldn't help machine consumers of the interface, but human callers may find it useful?

  This will yield an RPC output like so:

  ```diff
  bitcoin-cli scantxoutset start "[\"addr(bc1q5q9344vdyjkcgv79ve3tldz4jmx4lf7knmnx6r)\"]"
  {
    "success": true,
    "txouts": 185259116,
    "height": 853622,
    "bestblock": "00000000000000000002e97d9be8f0ddf31829cf873061b938c10b0f80f708b2",
    "unspents": [
      {
        "txid": "fae435084345fe26e464994aebc6544875bca0b897bf4ce52a65901ae28ace92",
        "vout": 0,
        "scriptPubKey": "0014a00b1ad58d24ad8433c56662bfb45596cd5fa7d6",
        "desc": "addr(bc1q5q9344vdyjkcgv79ve3tldz4jmx4lf7knmnx6r)#smk4xmt7",
        "amount": 0.00091190,
        "coinbase": false,
        "height": 852741,
  +     "blockhash": "00000000000000000002eefe7e7db44d5619c3dace4c65f3fdcd2913d4945c13",
  +     "confirmations": 882
      }
    ],
    "total_amount": 0.00091190
  }
  ```

ACKs for top commit:
  sipa:
    utACK 17845e7f21
  Eunovo:
    ACK 17845e7f21
  tdb3:
    ACK 17845e7f21

Tree-SHA512: 02366d0004e5d547522115ef0efe6794a35978db53dda12c675cfae38197bf43f0bf89ca99a3d79e3d2cff95186015fe1ab764abb8ab82bda440ae9302ad973b
2024-07-28 13:36:15 +01:00
Luis Schwab
17845e7f21 rpc: add utxo's blockhash and number of confirmations to scantxoutset output 2024-07-27 18:58:11 -03:00
MarcoFalke
fa359255fe
Add -blocksxor boolean option 2024-07-26 17:30:53 +02:00
MarcoFalke
fa530ec543
rpc: Return precise loadtxoutset error messages
The error messages should never happen in normal operation. However, if
they do, they are helpful to return to the user to debug the issue. For
example, to notice a truncated file.
2024-07-26 14:11:24 +02:00
glozow
ec700f0a76
Merge bitcoin/bitcoin#30076: test: fix MiniWallet script-path spend (missing parity bit in leaf version)
e4b0dabb21 test: add functional test for tagged MiniWallet instances (Sebastian Falbesoner)
3162c917e9 test: fix MiniWallet internal key derivation for tagged instances (Sebastian Falbesoner)
c9f7364ab2 test: fix MiniWallet script-path spend (missing parity bit in leaf version) (Sebastian Falbesoner)
7774c314fb test: refactor: return TaprootInfo from P2TR address creation routine (Sebastian Falbesoner)

Pull request description:

  This PR fixes a dormant bug in MiniWallet that exists since support for P2TR was initially added in #23371 (see commit 041abfebe4).

  In the course of spending the output, the leaf version byte of the control block in the witness stack doesn't set the parity bit, i.e. we were so far just lucky that the used combinations of relevant data (internal pubkey, leaf script / version) didn't result in a tweaked pubkey with odd y-parity. If that was the case, we'd get the following validation error:

  `mandatory-script-verify-flag-failed (Witness program hash mismatch) (-26)`

  Since MiniWallets can now optionally be tagged (#29939), resulting in different internal pubkeys, the issue is more prevalent now. Fix it by passing the parity bit, as specified in BIP341.

  Can be tested with the following patch (fails on master, succeeds on PR):
  ```diff
  diff --git a/test/functional/test_framework/mempool_util.py b/test/functional/test_framework/mempool_util.py
  index 148cc935ed..7ebe858681 100644
  --- a/test/functional/test_framework/mempool_util.py
  +++ b/test/functional/test_framework/mempool_util.py
  @@ -42,7 +42,7 @@ def fill_mempool(test_framework, node):
       # Generate UTXOs to flood the mempool
       # 1 to create a tx initially that will be evicted from the mempool later
       # 75 transactions each with a fee rate higher than the previous one
  -    ephemeral_miniwallet = MiniWallet(node, tag_name="fill_mempool_ephemeral_wallet")
  +    ephemeral_miniwallet = MiniWallet(node, tag_name="fill_mempool_ephemeral_wallet3")
       test_framework.generate(ephemeral_miniwallet, 1 + num_of_batches * tx_batch_size)

       # Mine enough blocks so that the UTXOs are allowed to be spent
  ```

  In addition to that, another bug is fixed where the internal key derivation failed, as not every pseudorandom hash results in a valid x-only pubkey. Fix this by treating the hash result as private key and calculate the x-only public key out of that, to be used then as internal key.

  Fixes #30528.

ACKs for top commit:
  glozow:
    ACK e4b0dabb21
  rkrux:
    reACK [e4b0dab](e4b0dabb21)
  hodlinator:
    ACK e4b0dabb21

Tree-SHA512: a16f33f76bcb1012857cc3129438a9f6badf28aa2b1d25696da0d385ba5866b46de0f1f93ba777ed9263fe6952f98d7d9c44ea0c0170a2bcc86cbef90bf6ac58
2024-07-26 11:51:46 +01:00
merge-script
30e8a79aef
Merge bitcoin/bitcoin#30482: rest: Reject truncated hex txid early in getutxos parsing
fac0c3d4bf doc: Add release notes for two pull requests (MarcoFalke)
fa7b57e5f5 refactor: Replace ParseHashStr with FromHex (MarcoFalke)
fa90777245 rest: Reject truncated hex txid early in getutxos parsing (MarcoFalke)
fab6ddbee6 refactor: Expose FromHex in transaction_identifier (MarcoFalke)
fad2991ba0 refactor: Implement strict uint256::FromHex() (MarcoFalke)
fa103db2bb scripted-diff: Rename SetHex to SetHexDeprecated (MarcoFalke)
fafe4b8051 test: refactor: Replace SetHex with uint256 constructor directly (MarcoFalke)

Pull request description:

  In `rest_getutxos` truncated txids such as `aa` or `ff` are accepted. This is brittle at best.

  Fix it by rejecting any truncated (or overlarge) input.

  ----

  Review note: This also starts a major refactor to rework hex parsing in Bitcoin Core, meaning that a few refactor commits are included as well. They are explained individually in the commit message and the work will be continued in the future.

ACKs for top commit:
  stickies-v:
    re-ACK fac0c3d4bf - only doc and test updates to address review comments, thanks!
  hodlinator:
    ACK fac0c3d4bf

Tree-SHA512: 473feb3fcf6118443435d1dd321006135b0b54689bfbbcb1697bb5811a449bef51f475c715de6911ff3c4ea3bdb75f601861ff93347bc4414d6b9e5298105dd7
2024-07-25 13:49:21 +01:00
merge-script
f7ab3ba404
Merge bitcoin/bitcoin#30275: Fee Estimation: change estimatesmartfee default mode to economical
25bf86a225 [test]: ensure `estimatesmartfee` default mode is `economical` (ismaelsadeeq)
41a2545046 [fees]: change `estimatesmartfee` default mode to `economical` (ismaelsadeeq)

Pull request description:

  Fixes #30009

  This PR changes the `estimatesmartfee` default mode to `economical`.

  This was also suggested on IRC https://bitcoin-irc.chaincode.com/bitcoin-core-dev/2024-04-26#1021609

  - `conservative` mode: This is the `estimatesmartfee` RPC mode which considers a longer history of blocks. It potentially returns a higher fee rate and is more likely to be sufficient for the desired target, but it is not as responsive to short-term drops in the prevailing fee market.
  - `economical` mode: This is the `estimatesmartfee` RPC mode where estimates are potentially lower and more responsive to short-term drops in the prevailing fee market.

  Since users are likely to use the default mode, this change will reduce overestimation for many users. The conservative mode remains available for those who wish to opt-in.

  For an in-depth analysis of how significantly the `conservative` mode overestimates, see
  https://delvingbitcoin.org/t/bitcoind-policy-estimator-modes-analysis/964.

ACKs for top commit:
  instagibbs:
    reACK 25bf86a225
  glozow:
    ACK 25bf86a225
  willcl-ark:
    ACK 25bf86a225

Tree-SHA512: 78ebda667eb9c8f87dcc2f0e6c14968bd1de30358dc77a13611b186fb8427ad97d9f537bad6e32e0a1aa477ccd8c64fee4d41e19308ef3cb184ff1664e6ba8a6
2024-07-25 10:44:50 +01:00
MarcoFalke
fa90777245
rest: Reject truncated hex txid early in getutxos parsing 2024-07-24 17:40:13 +02:00
Sergi Delgado Segura
6eeb188d40 test: adds seednode functional tests
Adds functional tests to test the interaction between seednode and the AddrMan
2024-07-24 11:14:02 -04:00
ismaelsadeeq
25bf86a225 [test]: ensure estimatesmartfee default mode is economical 2024-07-24 15:28:47 +01:00
MarcoFalke
fa3ea3b83c
test: Fix intermittent issue in p2p_v2_misbehaving.py
Without the fix, the test could fail intermittently. For example:

 node0 2024-07-22T16:31:54.104994Z [httpworker.0] [rpc/request.cpp:232] [parse] [rpc] ThreadRPCServer method=setmocktime user=__cookie__
 test  2024-07-22T16:31:54.291000Z TestFramework (INFO): Sending first 4 bytes of ellswift which match network magic
 test  2024-07-22T16:31:54.292000Z TestFramework (INFO): If a response is received, assertion failure would happen in our custom data_received() function
 test  2024-07-22T16:31:54.292000Z TestFramework.p2p (DEBUG): Connecting to Bitcoin Node: 127.0.0.1:12644
 test  2024-07-22T16:31:54.293000Z TestFramework.p2p (DEBUG): Connected & Listening: 127.0.0.1:12644
 test  2024-07-22T16:31:54.588000Z TestFramework.p2p (DEBUG): sending 4050 bytes of garbage data
 test  2024-07-22T16:31:54.588000Z TestFramework (INFO): Sending remaining ellswift and garbage which are different from V1_PREFIX. Since a response is
 test  2024-07-22T16:31:54.588000Z TestFramework (INFO): expected now, our custom data_received() function wouldn't result in assertion failure
 node0 2024-07-22T16:31:55.523868Z (mocktime: 2024-07-22T16:31:54Z) [net] [net.cpp:3764] [CNode] [net] Added connection peer=0
 node0 2024-07-22T16:31:55.625145Z (mocktime: 2024-07-22T16:31:54Z) [net] [net.cpp:1814] [CreateNodeFromAcceptedSocket] [net] connection from 127.0.0.1:45154 accepted
 node0 2024-07-22T16:31:55.625769Z (mocktime: 2024-07-22T16:31:54Z) [http] [httpserver.cpp:305] [http_request_cb] [http] Received a POST request for / from 127.0.0.1:33320
 node0 2024-07-22T16:31:55.626543Z (mocktime: 2024-07-22T16:31:54Z) [httpworker.1] [rpc/request.cpp:232] [parse] [rpc] ThreadRPCServer method=getpeerinfo user=__cookie__
 test  2024-07-22T16:31:55.818000Z TestFramework (ERROR): Unexpected exception caught during testing
                                   Traceback (most recent call last):
                                     File "/ci_container_base/ci/scratch/build/bitcoin-x86_64-pc-linux-gnu/test/functional/test_framework/test_framework.py", line 132, in main
                                       self.run_test()
                                     File "/ci_container_base/ci/scratch/build/bitcoin-x86_64-pc-linux-gnu/test/functional/p2p_v2_misbehaving.py", line 133, in run_test
                                       self.test_earlykeyresponse()
                                     File "/ci_container_base/ci/scratch/build/bitcoin-x86_64-pc-linux-gnu/test/functional/p2p_v2_misbehaving.py", line 151, in test_earlykeyresponse
                                       self.wait_until(lambda: node0.getpeerinfo()[-1]["bytesrecv"] > 4)
                                     File "/ci_container_base/ci/scratch/build/bitcoin-x86_64-pc-linux-gnu/test/functional/test_framework/test_framework.py", line 791, in wait_until
                                       return wait_until_helper_internal(test_function, timeout=timeout, timeout_factor=self.options.timeout_factor)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
                                     File "/ci_container_base/ci/scratch/build/bitcoin-x86_64-pc-linux-gnu/test/functional/test_framework/util.py", line 289, in wait_until_helper_internal
                                       if predicate():
                                          ^^^^^^^^^^^
                                     File "/ci_container_base/ci/scratch/build/bitcoin-x86_64-pc-linux-gnu/test/functional/p2p_v2_misbehaving.py", line 151, in <lambda>
                                       self.wait_until(lambda: node0.getpeerinfo()[-1]["bytesrecv"] > 4)
                                                               ~~~~~~~~~~~~~~~~~~~^^^^
                                   IndexError: list index out of range
2024-07-23 19:48:40 +02:00
Ava Chow
8ae79f1155
Merge bitcoin/bitcoin#30403: test, assumeutxo: Remove resolved todo comments and add new test
d63ef73800 test: Add loadtxoutset test with tip on snapshot block (Fabian Jahr)
c2f86d4bcb test: Remove already resolved assumeutxo todo comments (Fabian Jahr)

Pull request description:

  The first commit removes three Todos that have been addressed previously (see commit message for details).

  The second message resolves another todo by adding the missing test case. This is a special case of "the tip has more work than the snapshot" where the tip is the same block as the snapshot base block.

  Related to #28648.

ACKs for top commit:
  jrakibi:
    ACK [d63ef73](d63ef73800)
  achow101:
    ACK d63ef73800
  maflcko:
    ACK d63ef73800
  alfonsoromanz:
    Re ACK d63ef73800

Tree-SHA512: 8d5a25fc0b26531db3a9740132694138f2103b7b42eeb1d4a64095bfc901c1372e23601c0855c7def84c8a4e185d10611e4e830c4e479f1b663ae6ed53abb130
2024-07-23 13:36:11 -04:00
Lőrinc
bccfca0382 Fix lint-spelling warnings
These warnings were often polluting the CI output, e.g. https://github.com/bitcoin/bitcoin/pull/30499/checks?check_run_id=27745036545

> ./test/lint/lint-spelling.py

before the change:
```
doc/design/libraries.md💯 targetted ==> targeted
doc/developer-notes.md:495: dependant ==> dependent
src/bench/sign_transaction.cpp:49: hashIn ==> hashing, hash in
src/bitcoin-chainstate.cpp:213: hashIn ==> hashing, hash in
src/bitcoin-chainstate.cpp:213: hashIn ==> hashing, hash in
src/coins.cpp:24: viewIn ==> viewing, view in
src/coins.cpp:24: viewIn ==> viewing, view in
src/coins.cpp:29: viewIn ==> viewing, view in
src/coins.cpp:29: viewIn ==> viewing, view in
src/coins.h:44: outIn ==> outing, out in
src/coins.h:44: outIn ==> outing, out in
src/coins.h:45: outIn ==> outing, out in
src/coins.h:45: outIn ==> outing, out in
src/coins.h:215: viewIn ==> viewing, view in
src/coins.h:220: viewIn ==> viewing, view in
src/primitives/transaction.h:37: hashIn ==> hashing, hash in
src/primitives/transaction.h:37: hashIn ==> hashing, hash in
src/protocol.cpp:51: hashIn ==> hashing, hash in
src/protocol.cpp:51: hashIn ==> hashing, hash in
src/protocol.h:497: hashIn ==> hashing, hash in
src/qt/forms/optionsdialog.ui:344: incomin ==> incoming
src/qt/optionsdialog.cpp:445: proxys ==> proxies
src/rpc/mining.cpp:987: hashIn ==> hashing, hash in
src/rpc/mining.cpp:987: hashIn ==> hashing, hash in
src/script/interpreter.h:298: amountIn ==> amounting, amount in
src/script/interpreter.h:298: amountIn ==> amounting, amount in
src/script/interpreter.h:299: amountIn ==> amounting, amount in
src/script/interpreter.h:299: amountIn ==> amounting, amount in
src/script/sigcache.h:70: amountIn ==> amounting, amount in
src/script/sigcache.h:70: amountIn ==> amounting, amount in
src/signet.cpp:144: amountIn ==> amounting, amount in
src/test/fuzz/util/net.cpp:386: occured ==> occurred
src/test/fuzz/util/net.cpp:398: occured ==> occurred
src/util/vecdeque.h:79: deques ==> dequeues
src/util/vecdeque.h:160: deques ==> dequeues
src/util/vecdeque.h:184: deques ==> dequeues
src/util/vecdeque.h:194: deques ==> dequeues
src/validation.cpp:2130: re-declared ==> redeclared
src/validation.h:348: outIn ==> outing, out in
src/validation.h:349: outIn ==> outing, out in
test/functional/wallet_bumpfee.py:851: atleast ==> at least
```
2024-07-22 13:59:42 +02:00
glozow
3a29ff5dea
Merge bitcoin/bitcoin#30463: qa: Functional test improvements
a8e3af1a82 qa: Do not assume running `feature_asmap.py` from source directory (Hennadii Stepanov)
9bf7ca6cad qa: Consider `cache` and `config.ini` relative to invocation directory (Hennadii Stepanov)
a0473442d1 scripted-diff: Add `__file__` argument to `BitcoinTestFramework.init()` (Hennadii Stepanov)

Pull request description:

  This PR includes changes split from https://github.com/bitcoin/bitcoin/pull/30454. They improve the functional test framework, allowing users to [run individual functional tests](https://github.com/hebasto/bitcoin/issues/146) from the build directory in the new CMake-based build system.

  This functionality is not available for out-of-source builds using the current Autotools-based build system, which always requires write permissions for the source directory. Nevertheless, this PR can be tested as suggested in https://github.com/bitcoin/bitcoin/pull/30463#issuecomment-2232618421:
  1. Make an out-of-source build:
  ```
  $ ./autogen.sh
  $ mkdir ../build && cd ../build
  $ ../bitcoin/configure
  $ make
  ```
  2. Create a symlink in the build directory to a functional test:
  ```
  $ ln --symbolic ../../../bitcoin/test/functional/wallet_disable.py ./test/functional/
  ```
  3. Run this symlink:
  ```
  $ ./test/functional/wallet_disable.py
  ```
  The last command fails on the master branch:
  ```
  Traceback (most recent call last):
    File "/home/hebasto/git/build/./test/functional/wallet_disable.py", line 31, in <module>
      DisableWalletTest().main()
      ^^^^^^^^^^^^^^^^^^^
    File "/home/hebasto/git/bitcoin/test/functional/test_framework/test_framework.py", line 106, in __init__
      self.parse_args()
    File "/home/hebasto/git/bitcoin/test/functional/test_framework/test_framework.py", line 210, in parse_args
      config.read_file(open(self.options.configfile))
                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  FileNotFoundError: [Errno 2] No such file or directory: '/home/hebasto/git/bitcoin/test/config.ini'

  ```
  and succeeds with this PR.

ACKs for top commit:
  maflcko:
    tested ACK a8e3af1a82 🎨
  glozow:
    ACK a8e3af1a82, tested with the steps in op
  stickies-v:
    ACK a8e3af1a82

Tree-SHA512: 899e4efc09edec13ea3f5b47825d03173fb21d3569c360deda7fa6a56b99b4d24e09ad4f0883bad1ee926b1c706e47ba07c6a6160c63c07c82b3cf4ae5816e91
2024-07-22 12:08:32 +01:00
Fabian Jahr
d63ef73800
test: Add loadtxoutset test with tip on snapshot block
Also pulls out the guarding assert and calls it explicitly before the test function is called. This is already done before the existing call of the test function so it was not needed there.
2024-07-19 00:54:26 +01:00
Fabian Jahr
c2f86d4bcb
test: Remove already resolved assumeutxo todo comments
- "Valid snapshot file, but referencing a snapshot block that turns out
  to be invalid, or has an invalid parent" has been addressed in #30267
- "An ancestor of snapshot block" - If chain tip refers to blocks in this context then any successful load is addressing this because if we have synced past the snapshot base block we fail because we don't need assumeutxo anymore. And if this is about headers then this is the `test_headers_not_synced()` case.
- "A descendant of the snapshot block" - If this refers to blocks the
  `test_snapshot_with_less_work()` addressed this and if it is just headers in this case again it would be represented in all of the successful loads in the test.

Co-authored-by: Alfonso Roman Zubeldia <alfonsoromanz24@gmail.com>
2024-07-19 00:54:01 +01:00
Ava Chow
0cac45755e
Merge bitcoin/bitcoin#30320: assumeutxo: Don't load a snapshot if it's not in the best header chain
55b6d7be68 validation: Don't load a snapshot if it's not in the best header chain. (Martin Zumsande)

Pull request description:

  This was suggested by me in the discussion of #30288, which has more context.

  If the snapshot is not an ancestor of the most-work header (`m_best_header`), syncing from that alternative chain leading to  `m_best_header` should be prioritised. Therefore it's not useful loading the snapshot in this situation.
  If the other chain turns out to be invalid or the chain with the snapshot retrieves additional headers so that it's the most-work one again (see functional test), `m_best_header` will change and loading the snapshot will be possible again.

  Because of the work required to generate a conflicting headers chain, a situation with two conflicting chains should only be possible under extreme circumstances, such as major forks.

ACKs for top commit:
  fjahr:
    re-ACK 55b6d7be68
  achow101:
    ACK 55b6d7be68
  alfonsoromanz:
    Re ACK 55b6d7be68

Tree-SHA512: 4fbea5ab1038ae353fc949a186041cf9b397e7ce4ac59ff36f881c9437b4f22ada922490ead5b2661389eb1ca0f3d1e7e7e6a4261057678643e71594a691ac36
2024-07-18 17:28:22 -04:00
Ava Chow
6144aa21d0
Merge bitcoin/bitcoin#30444: rest: Reject negative outpoint index early in getutxos parsing
fac932bf93 refactor: Use util::Split to avoid a harmless unsigned-integer-overflow (MarcoFalke)
fab54db9f1 rest: Reject negative outpoint index in getutxos parsing (MarcoFalke)

Pull request description:

  In `rest_getutxos` outpoint indexes such as `+N` or `-N` are accepted. This should be harmless, because any index out of range should be treated as a non-existent utxo. However, a negative index can't exist ever, so it seems better to reject all signs, whether `+` or `-`.

ACKs for top commit:
  achow101:
    ACK fac932bf93
  hodlinator:
    ut-ACK fac932bf93
  tdb3:
    re ACK fac932bf93
  danielabrozzoni:
    ACK fac932bf93
  brunoerg:
    reACK fac932bf93

Tree-SHA512: 8f1a75248cb61e1c4beceded6ed170db83b07f30fbcf93a26acfffc00ec4546572366eff87907a7e1423d7d3a2a9e57a0a7a9bacb787c86463f842d7161c16bc
2024-07-18 16:51:42 -04:00
glozow
20ccb30b7a
Merge bitcoin/bitcoin#30453: test: Non-Shy version sender
faed5d3870 test: Non-Shy version sender (MarcoFalke)

Pull request description:

  After `add_outbound_p2p_connection`, the test framework normally sends a version message only in reply to a received version. This is fine, but the protocol does not require this and tolerates a version to be sent earlier.

  However, this is untested, and the missing test coverage leads to bugs being missed. For example https://github.com/bitcoin/bitcoin/pull/30394#pullrequestreview-2166824948

  Fix it by adding a test.

ACKs for top commit:
  brunoerg:
    ACK faed5d3870
  tdb3:
    ACK faed5d3870
  theStack:
    tACK faed5d3870
  glozow:
    ACK faed5d3870

Tree-SHA512: dbf527a39c932e994a1e8248ba78058000811a4bf69275278f1fd1e545716ac4d2d3be5dcf362976bbafa2a49f91d13e3601daf71d29e9c556179b01af62c03c
2024-07-18 17:07:51 +01:00
Ava Chow
efbf4e71ce
Merge bitcoin/bitcoin#29523: Wallet: Add max_tx_weight to transaction funding options (take 2)
734076c6de [wallet, rpc]: add `max_tx_weight` to tx funding options (ismaelsadeeq)
b6fc5043c1 [wallet]: update the data type of `change_output_size`, `change_spend_size` and `tx_noinputs_size` to `int` (ismaelsadeeq)
baab0d2d43 [doc]: update reason for deducting change output weight (ismaelsadeeq)
7f61d31a5c [refactor]: update coin selection algorithms input parameter `max_weight` name (ismaelsadeeq)

Pull request description:

  This PR taken over from #29264

  The PR added an option `max_tx_weight` to transaction funding RPC's that ensures the resulting transaction weight does not exceed the specified `max_tx_weight` limit.

  If `max_tx_weight` is not given `MAX_STANDARD_TX_WEIGHT` is used as the max threshold.

  This PR addressed outstanding review comments in #29264

  For more context and rationale behind this PR see https://delvingbitcoin.org/t/lightning-transactions-with-v3-and-ephemeral-anchors/418/11?u=instagibbs

ACKs for top commit:
  achow101:
    ACK 734076c6de
  furszy:
    utACK 734076c6de
  rkrux:
    reACK [734076c](734076c6de)

Tree-SHA512: 013501aa443d239ee2ac01bccfc5296490c27b4edebe5cfca6b96c842375e895e5cfeb5424e82e359be581460f8be92095855763a62779a18ccd5bdfdd7ddce7
2024-07-17 18:27:59 -04:00
merge-script
5f5862f382
Merge bitcoin/bitcoin#30468: test: bump mocktime only after node has received and sent bytes
c322bddd08 test: bump mocktime after node has received and sent bytes (stratospher)

Pull request description:

  Fixes an intermittent failure for `p2p_v2_misbehaving.py` reported in https://github.com/bitcoin/bitcoin/pull/30420#discussion_r1680462164.

  A [different error message](262260ce1e/src/net.cpp (L1970)) `"socket no message in first %i seconds"` will be displayed if `m_last_send=0` or if `m_last_recv is 0`.  Fix this by:
  1. mocktime bump is done after all the bytes are received. (`m_last_recv is not 0 now`)
  2. wait until bytes are sent by `TestNode`/`bitcoind` (`m_last_send is not 0 now`)

  See https://cirrus-ci.com/task/5359619151757312?logs=ci#L3935 for an example failure (I wasn't able to reproduce the intermittent failure locally but I think the fix is logical)

ACKs for top commit:
  maflcko:
    reACK c322bddd08

Tree-SHA512: 1c05524c2819041eb2001c2baf2c912d4f812a39347f784f212634e8c53131357a73116a46b4b7542bc7fc8c1370c4d36fc9898a2cbdb40bcee61105123c4a35
2024-07-17 16:11:08 +01:00
merge-script
37992244e6
Merge bitcoin/bitcoin#30457: doc: getaddressinfo[isscript] is optional
fa6390df20 doc: getaddressinfo[isscript] is optional (MarcoFalke)

Pull request description:

  `isscript` is unknown for unknown witness versions, so it should be marked optional in the docs

  Fixes https://github.com/bitcoin/bitcoin/issues/30456

ACKs for top commit:
  stickies-v:
    ACK fa6390df20
  tdb3:
    ACK fa6390df20

Tree-SHA512: f728f18e0871923225e0bf29594f8095997456cf55409f42087b5f70f95bef10f984323b48d2b484b6705f23b04e9e8a3fe42446830638fdd70453c18fd7f189
2024-07-17 13:58:34 +01:00
stratospher
c322bddd08 test: bump mocktime after node has received and sent bytes
a different error message "socket no message in first %i seconds"
will be displayed if m_last_send=0 or if m_last_recv is 0. make
the test robust by ensuring that they will not be 0 before
bumping mocktime.
2024-07-17 17:56:19 +05:30
MarcoFalke
faed5d3870
test: Non-Shy version sender 2024-07-17 11:49:01 +02:00
MarcoFalke
fa6390df20
doc: getaddressinfo[isscript] is optional 2024-07-17 06:51:58 +02:00
Ava Chow
6f9db1ebca
Merge bitcoin/bitcoin#30357: Fix cases of calls to FillPSBT errantly returning complete=true
7e36dca657 test: add test for modififed walletprocesspsbt calls (willcl-ark)
39cea21ec5 wallet: fix FillPSBT errantly showing as complete (willcl-ark)

Pull request description:

  Fixes: #30077

  Fix cases of calls to `FillPSBT` returning `complete=true` when it's not
  the case.

  This can happen when some inputs have been signed but the transaction is
  subsequently modified, e.g. in the context of PayJoins.

  Also fixes a related bug where a finalized hex string is attempted to be
  added during `walletprocesspsbt` but a CHECK_NONFATAL causes an abort.

ACKs for top commit:
  achow101:
    ACK 7e36dca657
  ismaelsadeeq:
    Tested ACK 7e36dca657
  pinheadmz:
    re-ACK 7e36dca657

Tree-SHA512: e35d19789899c543866d86d513506494d672e4bed9aa36a995dbec4e72f0a8ec5536b57c4a940a18002ae4a8efd0b007c77ba64e57cd52af98e4ac0e7bf650d6
2024-07-16 17:10:19 -04:00
Hennadii Stepanov
a8e3af1a82
qa: Do not assume running feature_asmap.py from source directory 2024-07-16 22:06:47 +01:00
Hennadii Stepanov
9bf7ca6cad
qa: Consider cache and config.ini relative to invocation directory
In CMake-based build system (1) `config.ini` is created in the build
directory, and (2) `cache` must also be created in the same directory.

This change enables running individual functional tests from the build
directory.
2024-07-16 22:06:47 +01:00
Hennadii Stepanov
a0473442d1
scripted-diff: Add __file__ argument to BitcoinTestFramework.init()
-BEGIN VERIFY SCRIPT-
sed -i -e 's/\s*().main\s*()/(__file__).main()/' $(git ls-files test/functional/*.py)
sed -i -e 's/def __init__(self)/def __init__(self, test_file)/' test/functional/test_framework/test_framework.py
-END VERIFY SCRIPT-
2024-07-16 22:06:47 +01:00
Ava Chow
45750f61d6
Merge bitcoin/bitcoin#22729: Make it possible to disable Tor binds and abort startup on bind failure
bca346a970 net: require P2P binds to succeed (Vasil Dimov)
af552534ab net: report an error if unable to bind on the Tor listening addr:port (Vasil Dimov)
9a7e5f4d68 net: don't extra bind for Tor if binds are restricted (Vasil Dimov)

Pull request description:

  Make it possible to disable the Tor binding on `127.0.0.1:8334` and stop startup if any P2P bind fails instead of "if all P2P binds fail".

  Fixes https://github.com/bitcoin/bitcoin/issues/22726
  Fixes https://github.com/bitcoin/bitcoin/issues/22727

ACKs for top commit:
  achow101:
    ACK bca346a970
  cbergqvist:
    ACK bca346a970
  pinheadmz:
    ACK bca346a970

Tree-SHA512: fabef89a957191eea4f3e3b6109d2b8389f27ecc74440a920b0c10f31fff00a85bcfd1eb3c91826c7169c618f4de8a8d0a260e2caf40fd854f07ea9a980d8603
2024-07-16 16:27:24 -04:00
Ava Chow
ad5579e056
Merge bitcoin/bitcoin#30429: rpc: Use CHECK_NONFATAL over Assert
fa6270737e rpc: Use CHECK_NONFATAL over Assert (MarcoFalke)

Pull request description:

  Any RPC method should not abort the whole node when an internal logic error happens.

  Fix it by just aborting this single RPC method call when an error happens.

  Also, fix the linter to find the fixed cases.

ACKs for top commit:
  achow101:
    ACK fa6270737e
  stickies-v:
    ACK fa6270737e
  tdb3:
    ACK fa6270737e
  hodlinator:
    ACK fa6270737e

Tree-SHA512: dad2f31b01a66578949009499e4385fb4d72f0f897419f2a6e0ea02e799b9a31e6ecb5a67fa5d27fcbc7939fe8acd62dc04e877b35831493b7f2c604dec7dc64
2024-07-16 16:00:33 -04:00
glozow
35dddbccf1
Merge bitcoin/bitcoin#30394: net: fix race condition in self-connect detection
16bd283b3a Reapply "test: p2p: check that connecting to ourself leads to disconnect" (Sebastian Falbesoner)
0dbcd4c148 net: prevent sending messages in `NetEventsInterface::InitializeNode` (Sebastian Falbesoner)
66673f1c13 net: fix race condition in self-connect detection (Sebastian Falbesoner)

Pull request description:

  This PR fixes a recently discovered race condition in the self-connect detection (see #30362 and #30368).

  Initiating an outbound network connection currently involves the following steps after the socket connection is established (see [`CConnman::OpenNetworkConnection`](bd5d1688b4/src/net.cpp (L2923-L2930)) method):
  1. set up node state
  2. queue VERSION message (both steps 1 and 2 happen in [`InitializeNode`](bd5d1688b4/src/net_processing.cpp (L1662-L1683)))
  3. add new node to vector `m_nodes`

  If we connect to ourself, it can happen that the sent VERSION message (step 2) is received and processed locally *before* the node object is added to the connection manager's `m_nodes` vector (step 3). In this case, the self-connect remains undiscovered, as the detection doesn't find the outbound peer in `m_nodes` yet (see `CConnman::CheckIncomingNonce`).

  Fix this by swapping the order of 2. and 3., by taking the `PushNodeVersion` call out of `InitializeNode` and doing that in the `SendMessages` method instead, which is only called for `CNode` instances in `m_nodes`.

  The temporarily reverted test introduced in #30362 is readded. Fixes #30368.

  Thanks go to vasild, mzumsande and dergoegge for suggestions on how to fix this (see https://github.com/bitcoin/bitcoin/issues/30368#issuecomment-2200625017 ff. and https://github.com/bitcoin/bitcoin/pull/30394#discussion_r1668290789).

ACKs for top commit:
  naiyoma:
    tested ACK [16bd283b3a),  built and tested locally,  test passes successfully.
  mzumsande:
    ACK 16bd283b3a
  tdb3:
    ACK 16bd283b3a
  glozow:
    ACK 16bd283b3a
  dergoegge:
    ACK 16bd283b3a

Tree-SHA512: 5b8aced6cda8deb38d4cd3fe4980b8af505d37ffa0925afaa734c5d81efe9d490dc48a42e1d0d45dd2961c0e1172a3d5b6582ae9a2d642f2592a17fbdc184445
2024-07-16 09:40:53 +01:00
merge-script
d41f4a69e7
Merge bitcoin/bitcoin#30420: test: Fix intermittent failure in p2p_v2_misbehaving.py
c6d43367a1 test: Fix intermittent failure in p2p_v2_misbehaving.py (stratospher)

Pull request description:

  Fixes #30419.

  Make sure that ellswift computation is complete in the `NetworkThread` in `test/functional/p2p_v2_misbehaving.py` before sending the ellswift in the `MainThread`.

  One way to reproduce this failure on master would be:

  ```diff
  diff --git a/test/functional/test_framework/v2_p2p.py b/test/functional/test_framework/v2_p2p.py
  index 87600c36de..ea0615ef3b 100644
  --- a/test/functional/test_framework/v2_p2p.py
  +++ b/test/functional/test_framework/v2_p2p.py
  @@ -111,6 +111,7 @@ class EncryptedP2PState:

       def generate_keypair_and_garbage(self, garbage_len=None):
           """Generates ellswift keypair and 4095 bytes garbage at max"""
  +        import time; time.sleep(3)
           self.privkey_ours, self.ellswift_ours = ellswift_create()
           if garbage_len is None:
               garbage_len = random.randrange(MAX_GARBAGE_LEN + 1)

  ```

ACKs for top commit:
  maflcko:
    ACK c6d43367a1
  mzumsande:
    Code Review ACK c6d43367a1
  tdb3:
    cr and t ACK c6d43367a1

Tree-SHA512: dfc3a6afa09773b7e84d35aff0aa14e0b8a4475860e0b31ab5c1a8d54911c814f07138f624fea651fba90cc5c526c0d05c3fe33d2ce0ad833b2be3a3caa9f522
2024-07-16 08:58:42 +01:00
stratospher
c6d43367a1 test: Fix intermittent failure in p2p_v2_misbehaving.py
The ellswift bytes are computed in the NetworkThread and sent in
the MainThread. Add a `wait_until()` to make sure that ellswift
computation is completed in NetworkThread before sending it in
the MainThread. Also wait until bytes sent are actually received
and use mocktime for more robust disconnection checking.
2024-07-15 20:51:05 +05:30
merge-script
c4d45b695e
Merge bitcoin/bitcoin#30295: #28984 package rbf followups
3f00aae140 package rbf: cpfp structure requires package > parent feerate (Greg Sanders)
ad7f1f697f test package rbf boundary conditions more closely (Greg Sanders)
ff4558d441 doc: reword package RBF documentation (Greg Sanders)
de669a883b doc: replace mention of V3 with TRUC (Greg Sanders)

Pull request description:

  Some suggested nits/changes from #28984

ACKs for top commit:
  glozow:
    ACK 3f00aae140
  murchandamus:
    ACK 3f00aae140

Tree-SHA512: 79434cc8aba25a43e99793298cdc99cad807db2c3a2e780a31953f244b95eecd97b90559abd67fbf30996c00966675fa257253a7812ec4727420226162c629ae
2024-07-12 17:15:27 +01:00
MarcoFalke
fab54db9f1
rest: Reject negative outpoint index in getutxos parsing 2024-07-12 17:48:26 +02:00
MarcoFalke
fa6270737e
rpc: Use CHECK_NONFATAL over Assert 2024-07-12 09:27:41 +02:00
Ava Chow
33af14e31b
Merge bitcoin/bitcoin#30353: test: fix inconsistency in fundrawtransaction weight limits test
00b8e26bd6 test: fix inconsistency in fundrawtransaction weight limits test (furszy)

Pull request description:

  Fix https://github.com/bitcoin/bitcoin/pull/30309#discussion_r1657628378 inconsistency.

  Currently, the test is passing due to a mistake in the test inputs
  selection process. We are selecting the parent transaction change
  output as one of the inputs of the transaction to fund, which
  helps to surpass the target amount when it shouldn't due to the
  fee reduction.

  The failure arises when the test behaves as intended by its coder;
  that is, when it does not select the change output. In this case,
  the pre-selected inputs aren't enough to cover the target amount.

  Fix this by excluding the parent transaction's change output from
  the inputs selection and including an extra input to cover the tx
  fee.

  The CI failure can be replicated with the following patch in master:

  ```diff
  diff --git a/test/functional/wallet_fundrawtransaction.py b/test/functional/wallet_fundrawtransaction.py
  --- a/test/functional/wallet_fundrawtransaction.py(revision 9b480f7a25)
  +++ b/test/functional/wallet_fundrawtransaction.py(date 1720652934739)
  @@ -1322,7 +1322,7 @@
           outputs = []
           for _ in range(1472):
               outputs.append({wallet.getnewaddress(address_type="legacy"): 0.1})
  -        txid = self.nodes[0].send(outputs=outputs)["txid"]
  +        txid = self.nodes[0].send(outputs=outputs, change_position=0)["txid"]
           self.generate(self.nodes[0], 1)

           # 272 WU per input (273 when high-s); picking 1471 inputs will exceed the max standard tx weight.
  @@ -1330,7 +1330,7 @@

           # 1) Try to fund transaction only using the preset inputs
           input_weights = []
  -        for i in range(1471):
  +        for i in range(1, 1472):  # skip first output as it is the parent tx change output
               input_weights.append({"txid": txid, "vout": i, "weight": 273})
           assert_raises_rpc_error(-4, "Transaction too large", wallet.fundrawtransaction, hexstring=rawtx, input_weights=input_weights)
  ```

ACKs for top commit:
  achow101:
    ACK 00b8e26bd6
  ismaelsadeeq:
    Code review and Tested ACK 00b8e26bd6

Tree-SHA512: 5ef792961b7fad4999fc30aa03366432103ddf672ca5cbb366c9eab4c2e46d5ae1ab0c073dfc4fbb2b4e63203653bc0e54463c731c5f8655140207ba5f8e542e
2024-07-11 15:08:13 -04:00
Martin Zumsande
55b6d7be68 validation: Don't load a snapshot if it's not in the best header chain.
If the snapshot is not an ancestor of the most-work header (m_best_header),
syncing from that alternative chain should be prioritised.
Therefore don't accept loading a snapshot in this situation.

If that other chain turns out to be invalid, m_best_header
would be reset and loading the snapshot should be possible again.

Because of the work required to generate a conflicting headers chain,
this should only be possible under extreme circumstances, such as major forks.
2024-07-11 13:06:22 -04:00
glozow
d9aa7b23e4
Merge bitcoin/bitcoin#26596: wallet: Migrate legacy wallets to descriptor wallets without requiring BDB
8ce3739edb test: verify wallet is still active post-migration failure (furszy)
771bc60f13 wallet: Use LegacyDataSPKM when loading (Ava Chow)
61d872f1b3 wallet: Move MigrateToDescriptor and DeleteRecords to LegacyDataSPKM (Ava Chow)
b231f4d556 wallet: Move LegacyScriptPubKeyMan::IsMine to LegacyDataSPKM (Ava Chow)
7461d0c006 wallet: Move LegacySPKM data storage and handling to LegacyDataSPKM (Ava Chow)
517e204bac Change MigrateLegacyToDescriptor to reopen wallet as BERKELEY_RO (Ava Chow)

Pull request description:

  #26606 introduced `BerkeleyRODatabase` which is an independent parser for BDB files. This PR uses this in legacy wallet migration so that migration will continue to work once the legacy wallet and BDB are removed. `LegacyDataSPKM` is introduced to have the minimum data and functions necessary for a legacy wallet to be loaded for migration.

ACKs for top commit:
  cbergqvist:
    ACK 8ce3739edb
  theStack:
    Code-review ACK 8ce3739edb
  furszy:
    Code review ACK 8ce3739edb

Tree-SHA512: dccea12d6c597de15e3e42f97ab483cfd069e103611200279a177e021e8e9c4e74387c4f45d2e58b3a1e7e2bdb32a1d2d2060b1f8086c03eeaa0c68579d9d54e
2024-07-11 16:47:02 +01:00
furszy
00b8e26bd6
test: fix inconsistency in fundrawtransaction weight limits test
Currently, the test is passing due to a mistake in the test inputs
selection process. We are selecting the parent transaction change
output as one of the inputs of the transaction to fund, which
helps to surpass the target amount when it shouldn't due to the
fee reduction.

The failure arises when the test behaves as intended by its coder;
that is, when it does not select the change output. In this case,
the pre-selected inputs aren't enough to cover the target amount.

Fix this by excluding the parent transaction's change output from
the inputs selection and including an extra input to cover the tx
fee.
2024-07-10 20:04:21 -03:00
Ava Chow
f4849f6922
Merge bitcoin/bitcoin#29668: prune, rpc: Check undo data when finding pruneheight
8789dc8f31 doc: Add note to getblockfrompeer on missing undo data (Fabian Jahr)
4a1975008b rpc: Make pruneheight also reflect undo data presence (Fabian Jahr)
96b4facc91 refactor, blockstorage: Generalize GetFirstStoredBlock (Fabian Jahr)

Pull request description:

  The function `GetFirstStoredBlock()` helps us find the first block for which we have data. So far this function only looked for a block with `BLOCK_HAVE_DATA`. However, this doesn't mean that we also have the undo data of that block, and undo data might be required for what a user would like to do with those blocks. One example of how this might happen is if some blocks were fetched using the `getblockfrompeer` RPC. Blocks fetched from a peer will have data but no undo data.

  The first commit here allows `GetFirstStoredBlock()` to check for undo data as well by passing a parameter. This alone is useful for #29553 and I would use it there.

  In the second commit I am applying the undo check to the RPCs that report `pruneheight` to the user. I find this much more intuitive because I think the user expects to be able to do all operations on blocks up until the `pruneheight` but that is not the case if undo data is missing. I personally ran into this once before and now again when testing for assumeutxo when I had used `getblockfrompeer`. The following commit adds test coverage for this change of behavior.

  The last commit adds a note in the docs of `getblockfrompeer` that undo data will not be available.

ACKs for top commit:
  achow101:
    ACK 8789dc8f31
  furszy:
    Code review ACK 8789dc8f31.
  stickies-v:
    ACK 8789dc8f31

Tree-SHA512: 90ae8bdd07a496ade579aa25240609c61c9ed173ad38d30533f6c631fe674e5a41727478ade69ca4b71a571ad94c9da4b33ebba6b5d8821109313c2de3bdfb3d
2024-07-10 15:27:05 -04:00
Ava Chow
394651ff10
Merge bitcoin/bitcoin#29996: Assumeutxo: bugfix on loadtxoutset with a divergent chain + test
5b7f70ba26 test: loadtxoutset in divergent chain with less work (Alfonso Roman Zubeldia)
d35efe1efc p2p: Start downloading historical blocks from common ancestor (Martin Zumsande)

Pull request description:

  This PR adds a test to cover the scenario of loading an assumeutxo snapshot when the current chain tip is not an ancestor of the snapshot block but has less work.

  During the review process, a bug was discovered where blocks between the last common ancestor and the background tip were not being requested if the background tip was not an ancestor of the snapshot block. mzumsande suggested a fix (65343ec49a6b73c4197dfc38e1c2f433b0a3838a) to start downloading historical blocks from the last common ancestor to address this issue. This fix has been incorporated into the PR with a slight modification.

  Related to https://github.com/bitcoin/bitcoin/issues/28648

ACKs for top commit:
  fjahr:
    tACK 5b7f70ba26
  achow101:
    ACK 5b7f70ba26
  mzumsande:
    Code Review ACK 5b7f70ba26

Tree-SHA512: f8957349686a6a1292165ea9e0fd8c912d21466072632a10f8ef9d852a5f430bc6b2a531e6884a4dbf2e3adb28b3d512b25919e78f5804a67320ef54c3b1aaf6
2024-07-10 15:18:33 -04:00
Ava Chow
9adebe1455
Merge bitcoin/bitcoin#29154: tests: improve wallet multisig descriptor test and docs
d93b794709 tests: improve wallet multisig descriptor test and docs (Michael Dietz)

Pull request description:

  It is best to store all key origin information
  (master key fingerprint and all derivation steps)
  in the multisig descriptor. Being explicit with
  this information should be beneficial if this approach is used with other wallets/signers (whether hardware or software). There is no harm including all of this with xpubs (if anything it simplifies the test code) and makes this example/docs more complete and safer incase it is referenced by others.

ACKs for top commit:
  S3RK:
    Code Review ACK d93b794709
  achow101:
    ACK d93b794709

Tree-SHA512: 0e5c4d13f060489405e6cf50c8a09911f5a0cee71023649235afd80a5e3aae38d52c6e12ad4660205b9357b09f45596941391bdcf6fceccbe07c4e5a1592a482
2024-07-09 20:09:07 -04:00
Ava Chow
c51c694ede
Merge bitcoin/bitcoin#29431: test/BIP324: disconnection scenarios during v2 handshake
c9dacd958d test: Check that non empty version packet is ignored and no disconnection happens (stratospher)
997cc00b95 test: Check that disconnection happens when AAD isn't filled (stratospher)
b5e6238fdb test: Check that disconnection happens when garbage sent/received are different (stratospher)
ad1482d5a2 test: Check that disconnection happens when wrong garbage terminator is sent (stratospher)
e351576862 test: Check that disconnection happens when >4095 garbage bytes is sent (stratospher)
e075fd131d test: Introduce test types and modify v2 handshake function accordingly (stratospher)
7d07daa623 log: Add V2 handshake timeout (stratospher)
d4a1da8543 test: Make global TRANSPORT_VERSION variable an instance variable (stratospher)
c642b08c4e test: Log when the garbage is actually sent to transport layer (stratospher)
86cca2cba2 test: Support disconnect waiting for add_p2p_connection (stratospher)
bf9669af9c test: Rename early key response test and move random_bitflip to util (stratospher)

Pull request description:

  Add tests for the following v2 handshake scenarios:
  1. Disconnection happens when > `MAX_GARBAGE_LEN` bytes garbage is sent
  2. Disconnection happens when incorrect garbage terminator is sent
  3. Disconnection happens when garbage bytes are tampered with
  4. Disconnection happens when AAD of first encrypted packet after the garbage terminator is not filled
  5. bitcoind ignores non-empty version packet and no disconnection happens

  All these tests require a modified v2 P2P class (different from `EncryptedP2PState` used in `v2_p2p.py`) to implement our custom handshake behaviour based on different scenarios and have been kept in a single test file (`test/functional/p2p_v2_misbehaving.py`). Shifted the test in `test/functional/p2p_v2_earlykeyresponse.py` which is of the same pattern to this file too.

ACKs for top commit:
  achow101:
    ACK c9dacd958d
  mzumsande:
    ACK c9dacd958d
  theStack:
    Code-review ACK c9dacd958d

Tree-SHA512: 90df81f0c7f4ecf0a47762d290a618ded92cde9f83d3ef3cc70e1b005ecb16125ec39a9d80ce95f99e695d29abd63443240cb5490aa57c5bc8fa2e52149a0672
2024-07-09 16:37:27 -04:00
Ryan Ofsky
5239e935cf
Merge bitcoin/bitcoin#30329: fuzz: improve utxo_snapshot target
de71d4dece fuzz: improve utxo_snapshot target (Martin Zumsande)

Pull request description:

  Add the possibility of giving more guidance to the creation of the metadata and/or coins, so that the fuzzer gets the chance
  to reach more error conditions in ActivateSnapshot and sometimes successfully creates a valid snapshot.

  This also changes the asserts for the success case that were outdated (after #29370) and only didn't result in a crash because the fuzzer wasn't able to reach this code before.

ACKs for top commit:
  maflcko:
    re-ACK de71d4dece 🎆
  fjahr:
    utACK de71d4dece
  TheCharlatan:
    ACK de71d4dece

Tree-SHA512: 346974d594164544d8cd3df7d8362c905fd93116215e9f5df308dfdac55bab04d727bfd7fd001cf11318682d11ee329b4b4a43308124c04d64b67840ab8a58a0
2024-07-09 16:13:14 -04:00
Sebastian Falbesoner
16bd283b3a Reapply "test: p2p: check that connecting to ourself leads to disconnect"
This reverts commit 9ec2c53701 with
a tiny change included (identation of the wait_until call).
2024-07-09 21:36:35 +02:00
Greg Sanders
3f00aae140 package rbf: cpfp structure requires package > parent feerate 2024-07-09 13:18:04 -04:00
Greg Sanders
ad7f1f697f test package rbf boundary conditions more closely 2024-07-09 13:18:04 -04:00
Ryan Ofsky
1f9d30744d
Merge bitcoin/bitcoin#29855: psbt: Check non witness utxo outpoint early
9e13ccc50e psbt: Check non witness utxo outpoint early (Ava Chow)

Pull request description:

  A common issue that our fuzzers keep finding is that outpoints don't exist in the non witness utxos. Instead of trying to track this down and checking in various individual places, do the check early during deserialization. This also unifies the error message returned for this class of problems.

ACKs for top commit:
  maflcko:
    lgtm ACK 9e13ccc50e
  S3RK:
    tACK 9e13ccc50e
  dergoegge:
    utACK 9e13ccc50e

Tree-SHA512: 81b8055b146c6358052226578ddfec0ae5bd877968c7f4f62dc3d6a684545ea568f37c7f1bd619918441af9e453ba8b26531a2280d218da37fa15480f1b45d0e
2024-07-08 13:56:52 -04:00
Alfonso Roman Zubeldia
5b7f70ba26 test: loadtxoutset in divergent chain with less work 2024-07-05 12:08:06 +02:00
Martin Zumsande
de71d4dece fuzz: improve utxo_snapshot target
Add the possibility of giving more guidance to the creation of the
metadata and/or coins, so that the fuzzer gets the chance
to reach more error conditions in ActivateSnapshot and sometimes
successfully creates a valid snapshot.

This also changes the asserts for the success case that were outdated,
and only didn't result in a crash because the fuzzer wasn't able
to reach this code before.
2024-07-04 20:12:47 -04:00
merge-script
5c0cd205a1
Merge bitcoin/bitcoin#29625: Several randomness improvements
ce8094246e random: replace construct/assign with explicit Reseed() (Pieter Wuille)
2ae392d561 random: use LogError for init failure (Pieter Wuille)
97e16f5704 tests: make fuzz tests (mostly) deterministic with fixed seed (Pieter Wuille)
2c91330dd6 random: cleanup order, comments, static (Pieter Wuille)
8e31cf9c9b net, net_processing: use existing RNG objects more (Pieter Wuille)
d5fcbe966b random: improve precision of MakeExponentiallyDistributed (Pieter Wuille)
cfb0dfe2cf random: convert GetExponentialRand into rand_exp_duration (Pieter Wuille)
4eaa239dc3 random: convert GetRand{Micros,Millis} into randrange (Pieter Wuille)
82de1b80d9 net: use GetRandMicros for cache expiration (Pieter Wuille)
ddc184d999 random: get rid of GetRand by inlining (Pieter Wuille)
e2d1f84858 random: make GetRand() support entire range (incl. max) (Pieter Wuille)
810cdf6b4e tests: overhaul deterministic test randomness (Pieter Wuille)
6cfdc5b104 random: convert XoRoShiRo128PlusPlus into full RNG (Pieter Wuille)
8cc2f45065 random: move XoRoShiRo128PlusPlus into random module (Pieter Wuille)
8f5ac0d0b6 xoroshiro128plusplus: drop comment about nonexisting copy() (Pieter Wuille)
8924f5120f random: modernize XoRoShiRo128PlusPlus a bit (Pieter Wuille)
ddb7d26cfd random: add RandomMixin::randbits with compile-known bits (Pieter Wuille)
21ce9d8658 random: Improve RandomMixin::randbits (Pieter Wuille)
9b14d3d2da random: refactor: move rand* utilities to RandomMixin (Pieter Wuille)
40dd86fc3b random: use BasicByte concept in randbytes (Pieter Wuille)
27cefc7fd6 random: add a few noexcepts to FastRandomContext (Pieter Wuille)
b3b382dde2 random: move rand256() and randbytes() to .h file (Pieter Wuille)
493a2e024e random: write rand256() in function of fillrand() (Pieter Wuille)

Pull request description:

  This PR contains a number of vaguely-related improvements to the random module.

  The specific changes and more detailed rationale is in the commit messages, but the highlights are:

  * `XoRoShiRo128PlusPlus` (previously a test-only RNG) moves to random.h and becomes `InsecureRandomContext`, which is even faster than `FastRandomContext` but non-cryptographic. It also gets all helper randomness functions (`randrange`, `fillrand`, ...), making it a lot more succinct to use.
  * During tests, **all** randomness is made deterministic (except for `GetStrongRandBytes`) but non-repeating (like `GetRand()` used to be when `g_mock_deterministic_tests` was used), either fixed, or from a random seed (overridden by env var).
  * Several infrequently used top-level functions (`GetRandMillis`, `GetRandMicros`, `GetExponentialRand`) are converted into member functions of `FastRandomContext` (and `InsecureRandomContext`).
  * `GetRand<T>()` (without argument) can now return the maximum value of the type (previously e.g. `GetRand<uint32_t>()` would never return 0xffffffff).

ACKs for top commit:
  achow101:
    ACK ce8094246e
  maflcko:
    re-ACK ce8094246e 🐈
  hodlinator:
    ACK ce8094246e
  dergoegge:
    utACK ce8094246e

Tree-SHA512: 79bc0cbafaf27e95012c1ce2947a8ca6f9a3c78af5f1f16e69354b6fc9b987a28858adf4cd356dc5baf21163e9af8dcc24e70f8d7173be870e8a3ddcdd47c02c
2024-07-04 11:26:43 +01:00
willcl-ark
dea7afd5e4
lint: remove unneeded trailing line fix 2024-07-03 11:14:01 +01:00
willcl-ark
4d942547a8
lint: ignore files ignored by git in mlc
Updating to MLC v0.18.0 includes a new feature which will ignore all
files ignored by git: `--gitignore`.

This helps avoid false-positives flagged by this linter in non-project
files, such as a developer might expect to have in their directory (e.g.
guix-builds, python venvs, etc.)
2024-07-03 09:46:15 +01:00
willcl-ark
7e36dca657
test: add test for modififed walletprocesspsbt calls
This test checks that we can successfully process PSBTs and opt out of
finalization.

Previously trying to call `walletprocesspsbt` would attempt to
auto-finalize (as a convenience), and would not permit opt-out of
finalization, instead aborting via `CHECK_NONFATAL`.
2024-07-03 09:16:17 +01:00
Ava Chow
173ab0ccf2
Merge bitcoin/bitcoin#29720: rpc: Avoid getchaintxstats invalid results
2342b46c45 test: Add coverage for getchaintxstats in assumeutxo context (Fabian Jahr)
faf2a6750b rpc: Reorder getchaintxstats output (MarcoFalke)
fa2dada0c9 rpc: Avoid getchaintxstats invalid results (MarcoFalke)

Pull request description:

  The `getchaintxstats` RPC reply during AU background download may return non-zero, but invalid, values for `window_tx_count` and `txrate`.

  For example, `txcount` may be zero for a to-be-downloaded block, but may be non-zero for an ancestor block which is already downloaded. Thus, the values returned may be negative (and cause intermediate integer sanitizer violations).

  Also, `txcount` may be accurate for the snapshot base block, or a descendant of it. However it may be zero for an ancestor block that still needs to be downloaded. Thus, the values returned may be positive, but wrong.

  Fix all issues by skipping the returned value if either `txcount` is unset (equal to zero).
  Also, skip `txcount` in the returned value, if it is unset (equal to zero).

  Fixes https://github.com/bitcoin/bitcoin/issues/29328

ACKs for top commit:
  fjahr:
    re-ACK 2342b46c45
  achow101:
    ACK 2342b46c45
  mzumsande:
    ACK 2342b46c45

Tree-SHA512: 931cecc40ee5dc0f96be728db7eb297155f8343076cd29c8b8c050c99fd1d568b80f54c9459a34ca7a9489c2474c729796d00eeb1934d6a9f7b4d6a53e3ec430
2024-07-02 18:02:26 -04:00
Ava Chow
3325a0afa4
Merge bitcoin/bitcoin#30272: doc: use TRUC instead of v3 and add release note
926b8e39dc [doc] add release note for TRUC (glozow)
19a9b90617 use version=3 instead of v3 in debug strings (glozow)
881fac8e60 scripted-diff: change names from V3 to TRUC (glozow)
a573dd2617 [doc] replace mentions of v3 with TRUC (glozow)
089b5757df rename mempool_accept_v3.py to mempool_truc.py (glozow)
f543852a89 rename policy/v3_policy.* to policy/truc_policy.* (glozow)

Pull request description:

  Adds a release note for TRUC policy which will be live in v28.0.

  For clarity, replaces mentions of "v3" with "TRUC" in most places. Suggested in
  - https://github.com/bitcoin/bitcoin/pull/29496#discussion_r1629749583
  - https://github.com/bitcoin/bitcoin/pull/29496#discussion_r1624500904

  I changed error strings from "v3-violation" to "TRUC-violation" but left v3 in the debug strings because I think it might be clearer for somebody who is debugging. Similarly, I left some variables unchanged because I think they're more descriptive this way, e.g. `tx_v3_from_v2_and_v3`. I'm happy to debate places that should or shouldn't be documented differently in this PR, whatever is clearest to everyone.

ACKs for top commit:
  instagibbs:
    reACK 926b8e39dc
  achow101:
    ACK 926b8e39dc
  ismaelsadeeq:
    Code review ACK 926b8e39dc

Tree-SHA512: 16c88add0a29dc6d1236c4d45f34a17b850f6727b231953cbd52eb9f7268d1d802563eadfc8b7928c94ed3d7a615275dd103e57e81439ebf3ba2b12efa1e42af
2024-07-02 17:49:32 -04:00
Ava Chow
9251bc7111
Merge bitcoin/bitcoin#30267: assumeutxo: Check snapshot base block is not in invalid chain
2f9bde69f4 test: Remove unnecessary restart in assumeutxo test (Fabian Jahr)
19ce3d407e assumeutxo: Check snapshot base block is not marked invalid (Fabian Jahr)
80315c0118 refactor: Move early loadtxoutset checks into ActiveSnapshot (Fabian Jahr)

Pull request description:

  This was discovered in a discussion in #29996

  If the base block of the snapshot is marked invalid or part of an invalid chain, we currently still load the snapshot and get stuck in a weird state where we have the snapshot chainstate but it will never connect to our valid chain.

  While this scenario is highly unlikely to occur on mainnet, it still seems good to prevent this inconsistent state.

  The behavior change described above is in the second commit.

  The first commit refactors the early checks in the `loadtxoutset` RPC by moving them into `ActivateSnapshot()` in order to have the chance to cover them by unit tests in the future and have a more consistent interface. Previously checks were spread out between `rpc/blockchain.cpp` and `validation.cpp`. In order to be able to return the error message to users of the RPC, the return type of `ActivateSnapshot()` is changed from `bool` to `util::Result`.

  The third commit removes an unnecessary restart introduced in #29428.

ACKs for top commit:
  mzumsande:
    re-ACK 2f9bde6
  alfonsoromanz:
    Re-ACK 2f9bde69f4. The RPC code looks much cleaner after the refactor. Also, it seems very useful to get the error message in the RPC response rather than having to rely on the logs in some scenarios if you are an RPC user.
  achow101:
    ACK 2f9bde69f4

Tree-SHA512: 5328dd88c3c7be3f1be97c9eef52ac3666c27188c30a798b3e949f3ffcb83be075127c107e4046f7f39f961a79911ea3d61b61f3c11e451b3e4c541c264eeed4
2024-07-02 17:06:39 -04:00
Ava Chow
74d61151e5
Merge bitcoin/bitcoin#30365: #27307 follow-up: update mempool conflict tests + docs
7d55796c53 wallet: update mempool conflicts tests + docs (ishaanam)

Pull request description:

  #27307 follow-up:
  - updates description of `mempoolconflicts` and `walletconflicts` in `gettransaction`
  - adds release notes for 27307
  - removes unnecessary line from `wallet_conflicts.py`

ACKs for top commit:
  fjahr:
    ACK 7d55796c53
  achow101:
    ACK 7d55796c53
  furszy:
    utACK 7d55796c53
  tdb3:
    ACK 7d55796c53

Tree-SHA512: b3c368c7072cacdaf5fd18ecb0a88ab76ce02f65d56fce55a3316afa0989b9417c31e563aa8d9dd8f6294add154b4fdeb4ada5081c6b8a5fe9953f0e8a4812f4
2024-07-02 16:51:07 -04:00
Ava Chow
1e16b10cfa
Merge bitcoin/bitcoin#30340: test: Added coverage to Block not found error using gettxoutsetinfo
8ec24bdad8 test: Added coverage to Block not found error using gettxoutsetinfo (kevkevinpal)

Pull request description:

  #### Description
  There were no tests that checked for the `Block not found` error called in `ParseHashOrHeight` when using `gettxoutsetinfo`, this change adds coverage to it.

  You can see there are no tests that do the following by doing the below
  `grep -nri "Block not found.*gettxoutsetinfo" ./test/functional/`

  which leads to no results

ACKs for top commit:
  achow101:
    ACK 8ec24bdad8
  tdb3:
    ACK 8ec24bdad8
  kristapsk:
    ACK 8ec24bdad8
  brunoerg:
    crACK 8ec24bdad8
  alfonsoromanz:
    Re ACK 8ec24bdad8

Tree-SHA512: 2c61c681e7304c679cc3d7dd13af1b795780e85716c25c7423d68104e253d01271e048e21bc21be35dbc7ec1a4fde94e439542f3cfd669fe5a16478c5fa982ab
2024-07-02 16:35:25 -04:00
Ava Chow
6afc707c4f
Merge bitcoin/bitcoin#30339: test: add coverage for node field of getaddednodeinfo RPC
e38eadb2c2 test: change comments to `self.log.info` for `test_addnode_getaddednodeinfo` (brunoerg)
c838e3b610 test: add coverage for `node` field of `getaddednodeinfo` RPC (brunoerg)

Pull request description:

  We currently do not test a successful call to `getaddednodeinfo` filtering by `node`, we only test it with an unknown address and checks whether it fails. This PR adds coverage to it.

ACKs for top commit:
  kevkevinpal:
    ACK [e38eadb](e38eadb2c2)
  achow101:
    ACK e38eadb2c2
  tdb3:
    re ACK e38eadb2c2
  BrandonOdiwuor:
    Code Review ACK e38eadb2c2
  rkrux:
    tACK [e38eadb](e38eadb2c2)

Tree-SHA512: e9f768b7aa86e58b0b0ced089ead57040ff9a5204493da1ab99c8bc897b6dcdce7c856855f74c52010fceef19af1e12a39eee9f8f2e7294b42476b6f980fe754
2024-07-02 16:28:44 -04:00
Vasil Dimov
bca346a970
net: require P2P binds to succeed
In the Tor case, this prevents us from telling the Tor daemon to send
our incoming connections from the Tor network to an address where we
do not listen (we tried to listen but failed probably because another
application is already listening).

In the other cases (IPv4/IPv6 binds) this also prevents unpleasant
surprises caused by continuing operations even on bind failure. For
example, another application may be listening on portX, bitcoind tries
to bind on portX and portY, only succeeds with portY and continues
operation leaving the user thinking that his bitcoind is listening on
portX whereas another application is listening (the error message in
the log could easily be missed).

Avoid having the functional testing framework start multiple `bitcoind`s
that try to listen on the same `127.0.0.1:18445` (Tor listen for
regtest) if `bind_to_localhost_only` is set to `False`.

Also fix a typo in `test-shell.md` related to `bind_to_localhost_only`.

Fixes https://github.com/bitcoin/bitcoin/issues/22727
2024-07-02 14:17:51 +02:00
Vasil Dimov
9a7e5f4d68
net: don't extra bind for Tor if binds are restricted
If only `-bind=addr:port` is given (without `-bind=...=onion`) then we
would bind to `addr:port` _and_ to `127.0.0.1:8334` in addition which
may be unexpected, assuming the semantic of `-bind=addr:port` is
"bind _only_ to `addr:port`".

Change the above to not do the additional bind: if only
`-bind=addr:port` is given (without `-bind=...=onion`) then bind to
`addr:port` (only). If we are creating a Tor hidden service then use
`addr:port` as target (same behavior as before
https://github.com/bitcoin/bitcoin/pull/19991).

This allows disabling binding on the onion port.

Fixes https://github.com/bitcoin/bitcoin/issues/22726
2024-07-02 14:17:50 +02:00
glozow
19a9b90617 use version=3 instead of v3 in debug strings
Make it more clear to the user what we mean by v3.
2024-07-02 12:20:12 +01:00
glozow
881fac8e60 scripted-diff: change names from V3 to TRUC
-BEGIN VERIFY SCRIPT-
sed -i 's/SingleV3Checks/SingleTRUCChecks/g' $(git grep -l 'SingleV3Checks')
sed -i 's/PackageV3Checks/PackageTRUCChecks/g' $(git grep -l 'PackageV3Checks')
sed -i 's/PV3C/PTRUCC/g' src/policy/truc_policy.h
sed -i 's/V3_MAX_VSIZE/TRUC_MAX_VSIZE/g' $(git grep -l 'V3_MAX_VSIZE')
sed -i 's/V3_CHILD_MAX_VSIZE/TRUC_CHILD_MAX_VSIZE/g' $(git grep -l 'V3_CHILD_MAX_VSIZE')
sed -i 's/V3_DESCENDANT_LIMIT/TRUC_DESCENDANT_LIMIT/g' $(git grep -l 'V3_DESCENDANT_LIMIT')
sed -i 's/V3_ANCESTOR_LIMIT/TRUC_ANCESTOR_LIMIT/g' $(git grep -l 'V3_ANCESTOR_LIMIT')
sed -i 's/CheckMempoolV3Invariants/CheckMempoolTRUCInvariants/g' $(git grep -l 'CheckMempoolV3Invariants')
-END VERIFY SCRIPT-
2024-07-02 12:06:07 +01:00
glozow
a573dd2617 [doc] replace mentions of v3 with TRUC
Keep mentions of v3 in debug strings to help people who might not know
that TRUC is applied when version=3.
Also keep variable names in tests, as it is less verbose to keep v3 and v2.
2024-07-02 12:06:07 +01:00
glozow
089b5757df rename mempool_accept_v3.py to mempool_truc.py 2024-07-02 11:57:59 +01:00
Fabian Jahr
2342b46c45 test: Add coverage for getchaintxstats in assumeutxo context 2024-07-02 08:47:24 +02:00
MarcoFalke
fa2dada0c9
rpc: Avoid getchaintxstats invalid results 2024-07-02 08:46:02 +02:00
Sebastian Falbesoner
9ec2c53701 Revert "test: p2p: check that connecting to ourself leads to disconnect"
This reverts commit 5d2fb14baf and
adds a TODO to add it later again once the race condition is fixed.
2024-07-01 20:53:16 +02:00
furszy
8ce3739edb test: verify wallet is still active post-migration failure
The migration process reloads the wallet after all failures.
This commit tests the behavior by trying to obtain a new address
after a decryption failure during migration.
2024-07-01 14:25:55 -04:00
ishaanam
7d55796c53 wallet: update mempool conflicts tests + docs 2024-07-01 12:27:43 -04:00
Pieter Wuille
6cfdc5b104 random: convert XoRoShiRo128PlusPlus into full RNG
Convert XoRoShiRo128PlusPlus into a full RandomMixin-based RNG class,
providing all utility functionality that FastRandomContext has. In doing so,
it is renamed to InsecureRandomContext, highlighting its non-cryptographic
nature.

To do this, a fillrand fallback is added to RandomMixin (where it is used by
InsecureRandomContext), but FastRandomContext still uses its own fillrand.
2024-07-01 10:26:46 -04:00
Pieter Wuille
8cc2f45065 random: move XoRoShiRo128PlusPlus into random module
This is preparation for making it more generally accessible.
2024-07-01 10:26:46 -04:00
Pieter Wuille
ddb7d26cfd random: add RandomMixin::randbits with compile-known bits
In many cases, it is known at compile time how many bits are requested from
randbits. Provide a variant of randbits that accepts this number as a template,
to make sure the compiler can make use of this knowledge. This is used immediately
in rand32() and randbool(), and a few further call sites.
2024-07-01 10:26:46 -04:00
Pieter Wuille
21ce9d8658 random: Improve RandomMixin::randbits
The previous randbits code would, when requesting more randomness than available
in its random bits buffer, discard the remaining entropy and generate new.

Benchmarks show that it's usually better to first consume the existing randomness
and only then generate new ones. This adds some complexity to randbits, but it
doesn't weigh up against the reduced need to generate more randomness.
2024-07-01 10:26:46 -04:00
kevkevinpal
8ec24bdad8
test: Added coverage to Block not found error using gettxoutsetinfo 2024-06-30 10:46:33 -04:00
Sebastian Falbesoner
5d2fb14baf test: p2p: check that connecting to ourself leads to disconnect
The "connect to ourself" detection logic has been first introduced
by Satoshi in October 2009, together with a couple of other changes
and a version bump to "v0.1.6 BETA" (see commit
cc0b4c3b62).
2024-06-29 00:30:14 +02:00
Ryan Ofsky
d38dbaad98
Merge bitcoin/bitcoin#28167: init: Add option for rpccookie permissions (replace 26088)
73f0a6cbd0 doc: detail -rpccookieperms option (willcl-ark)
d2afa2690c test: add rpccookieperms test (willcl-ark)
f467aede78 init: add option for rpccookie permissions (willcl-ark)
7df03f1a92 util: add perm string helper functions (willcl-ark)

Pull request description:

  This PR picks up #26088 by aureleoules which adds a bitcoind launch option `-rpccookieperms` to set the file permissions of the cookie generated by bitcoin core.

  Example usage to make the generated cookie group-readable: `./src/bitcoind -rpccookieperms=group`.

  Accepted values for `-rpccookieperms` are `[owner|group|all]`. We let `fs::perms` handle platform-specific permissions changes.

ACKs for top commit:
  achow101:
    ACK 73f0a6cbd0
  ryanofsky:
    Code review ACK 73f0a6cbd0. Main change since last review is no longer throwing a skip exception in the rpc test on windows, so other checks can run after it, and overall test result is passing, not skipped. Also were clarifying renames and documentation improvements.
  tdb3:
    cr ACK 73f0a6cbd0

Tree-SHA512: e800d59a44aca10e1c58ca69bf3fdde9f6ccf5eab4b7b962645af6d6bc0cfa3a357701e409c8c60d8d7744fcd33a91e77ada11790aa88cd7811ef60fab86ab11
2024-06-27 17:35:08 -04:00
ismaelsadeeq
734076c6de [wallet, rpc]: add max_tx_weight to tx funding options
This allows a transaction's weight to be bound under a certain
weight if possible and desired. This can be beneficial for future
RBF attempts, or whenever a more restricted spend topology is
desired.

Co-authored-by: Greg Sanders <gsanders87@gmail.com>
2024-06-27 15:31:21 +01:00
willcl-ark
d2afa2690c
test: add rpccookieperms test
Tests various perms on non-Windows OSes
2024-06-27 15:08:23 +01:00
Ava Chow
517e204bac Change MigrateLegacyToDescriptor to reopen wallet as BERKELEY_RO
When we reopen the wallet to do the migration, instead of opening using
BDB, open it using the BerkeleyRO implementation.
2024-06-26 16:38:56 -04:00
Ava Chow
1d00601b9b
Merge bitcoin/bitcoin#30309: wallet: notify when preset + automatic inputs exceed max weight
72b226882f wallet: notify when preset + automatic inputs exceed max weight (furszy)

Pull request description:

  Small change. Found it while finishing my review on #29523. This does not interfere with it.

  Basically, we are erroring out early when the automatic coin selection process exceeds the maximum weight, but we are not doing so when the user-preselected inputs combined with the wallet-selected inputs exceed the maximum weight.
  This change avoids signing all inputs before erroring out and introduces test coverage for `fundrawtransaction`.

ACKs for top commit:
  achow101:
    ACK 72b226882f
  tdb3:
    re ACK for 72b226882f
  rkrux:
    tACK [72b2268](72b226882f)
  ismaelsadeeq:
    utACK 72b226882f

Tree-SHA512: d77be19231023383a9c79a5d66b642dcbc6ebfc31a363e0b9f063c44898720a7859ec211cdbc0914ac7a3bfdf15e52fb8fc20d97f171431f70492c0f159dbc36
2024-06-26 12:16:16 -04:00
brunoerg
e38eadb2c2 test: change comments to self.log.info for test_addnode_getaddednodeinfo 2024-06-26 06:22:05 -03:00
brunoerg
c838e3b610 test: add coverage for node field of getaddednodeinfo RPC 2024-06-26 06:16:17 -03:00
Ryan Ofsky
323b0acfcb
Merge bitcoin/bitcoin#30200: Introduce Mining interface
a9716c53f0 rpc: call IsInitialBlockDownload via miner interface (Sjors Provoost)
dda0b0834f rpc: minize getTipHash() calls in gbt (Sjors Provoost)
7b4d3249ce rpc: call processNewBlock via miner interface (Sjors Provoost)
9e228351e7 rpc: getTransactionsUpdated via miner interface (Sjors Provoost)
64ebb0f971 Always pass options to BlockAssembler constructor (Sjors Provoost)
4bf2e361da rpc: call CreateNewBlock via miner interface (Sjors Provoost)
404b01c436 rpc: getblocktemplate getTipHash() via Miner interface (Sjors Provoost)
d8a3496b5a rpc: call TestBlockValidity via miner interface (Sjors Provoost)
8ecb681678 Introduce Mining interface (Sjors Provoost)

Pull request description:

  Introduce a `Mining` interface for the `getblocktemplate`, `generateblock` and other mining RPCs to use now, and for Stratum v2 to use later.

  Suggested here: https://github.com/bitcoin/bitcoin/pull/29346#issuecomment-2108528652

  The selection of methods added to the interface is mostly based on what the Template Provider in #29432 uses. It could be expanded further so that `rpc/mining.cpp` no longer needs `EnsureMemPool` and `EnsureChainman`.

  This PR should be a pure refactor.

ACKs for top commit:
  tdb3:
    re ACK a9716c53f0
  itornaza:
    Code review and std-tests ACK a9716c53f0
  ryanofsky:
    Code review ACK a9716c53f0 with one minor suggestion in case you update. Only changes since last review were other small changes to the interface.

Tree-SHA512: cf97f87d6e9ed89da3835a0730da3b24a7b14c8605ea221149103a5915e79598cf082a95f2bc88e33f1c450e3d4aad88aed1163a29195acca88bcace055af724
2024-06-24 19:29:48 -04:00
merge-script
a57da5e014
Merge bitcoin/bitcoin#30308: QA: Expect PACKAGE_NAME rather than constant "Bitcoin Core"
197b5404b0 QA: Expect PACKAGE_NAME rather than constant "Bitcoin Core" (Luke Dashjr)

Pull request description:

  Followup to #29144

ACKs for top commit:
  kevkevinpal:
    ACK [197b540](197b5404b0)
  tdb3:
    ACK 197b5404b0

Tree-SHA512: 6a2c7f7da56effa7e3eba1d103b1b4442d74a21f2ba588564cddd6d61a46c3721bf0942d4ac947ecbbbfe476501ab7b03a8414d7d0840ce9106b056811583010
2024-06-24 15:17:27 +01:00
Fabian Jahr
4a1975008b
rpc: Make pruneheight also reflect undo data presence 2024-06-23 00:15:24 +02:00
furszy
72b226882f
wallet: notify when preset + automatic inputs exceed max weight
This also avoids signing all inputs prior to erroring out.
2024-06-21 18:13:22 -03:00
stratospher
c9dacd958d test: Check that non empty version packet is ignored and no disconnection happens
This test type is represented using SEND_NON_EMPTY_VERSION_PACKET.
2024-06-21 19:41:00 +05:30
stratospher
997cc00b95 test: Check that disconnection happens when AAD isn't filled
This test type is represented using SEND_NO_AAD. If AAD of the first encrypted packet
sent after the garbage terminator (optional decoy packet/version packet) hasn't been
filled, disconnection happens.
2024-06-21 19:40:58 +05:30
stratospher
b5e6238fdb test: Check that disconnection happens when garbage sent/received are different
This test type is represented using WRONG_GARBAGE.
Here, garbage bytes sent to TestNode are assumed to be tampered with and
do not correspond to the garbage bytes which P2PInterface calculated and
uses.
2024-06-21 19:39:52 +05:30
stratospher
ad1482d5a2 test: Check that disconnection happens when wrong garbage terminator is sent
This test type is represented using WRONG_GARBAGE_TERMINATOR.
since the wrong garbage terminator is sent to TestNode, TestNode
will interpret all of the gabage bytes, wrong garbage terminator,
decoy messages and version packet it receives as garbage bytes.

If the length of all these is more than 4095 + 16, it will result
in a missing garbage terminator error. otherwise, it will result
in a V2 handshake timeout error.

Send only MAX_GARBAGE_LEN//2 bytes of garbage data to TestNode
so that the total length received by the TestNode is at max
= (MAX_GARBAGE_LEN//2) + 16 + 10*120 + 20 = 3283 bytes
(which is less than 4095 + 16 bytes) and we get a consistent
V2 handshake timeout error message.

If we do not limit the garbage length sent, we will intermittently
get both missing garbage terminator error and V2 handshake
timeout error based on the garbage length and decoy packets length
which are chosen at random.
2024-06-21 19:38:51 +05:30
stratospher
e351576862 test: Check that disconnection happens when >4095 garbage bytes is sent
This test type is represented using EXCESS_GARBAGE.
2024-06-21 19:37:13 +05:30
Fabian Jahr
2f9bde69f4
test: Remove unnecessary restart in assumeutxo test 2024-06-21 10:39:39 +02:00
Fabian Jahr
19ce3d407e
assumeutxo: Check snapshot base block is not marked invalid
Co-authored-by: Alfonso Roman Zubeldia <alfonsoromanz24@gmail.com>
2024-06-21 10:39:35 +02:00
Ava Chow
21656e99b5
Merge bitcoin/bitcoin#29862: test: Validate oversized transactions or without inputs
969e047cfb Replace hard-coded constant in test (Lőrinc)
327a31d1a4 Validate oversized transaction (Lőrinc)
1984187840 Validate transaction without inputs (Lőrinc)
c3a8843189 Use SCRIPT_VERIFY_NONE instead of hard-coded 0 in transaction_tests (Lőrinc)

Pull request description:

  Based on https://maflcko.github.io/b-c-cov/test_bitcoin.coverage/src/consensus/tx_check.cpp.gcov.html empty inputs and oversized transactions weren't covered by Boost unit tests (though they're covered by [python](https://github.com/bitcoin/bitcoin/blob/master/test/functional/mempool_accept.py#L231) [tests](https://github.com/bitcoin/bitcoin/blob/master/test/functional/data/invalid_txs.py#L102)).
  <img alt="image" src="https://github.com/bitcoin/bitcoin/assets/1841944/57a74ff5-5466-401f-a4fe-d79e36964adf">

  I have tried including the empty transaction into [tx_invalid.json](https://github.com/bitcoin/bitcoin/blob/master/src/test/data/tx_invalid.json#L34-L36), but it failed for another reason, so I added a separate test case for it in the end.

  The oversized tx data is on the failure threshold now (lower threshold fails for a different reason, but I guess that's fine, we're testing the boundary here).

ACKs for top commit:
  achow101:
    ACK 969e047cfb
  tdb3:
    ACK 969e047cfb pending `MSan, depends` CI failure.
  glozow:
    utACK 969e047cfb

Tree-SHA512: 2a472690eabfdacc276b7e0414d3a4ebc75c227405b202c9fe3c8befad875f6e4d9b40c056fb05971ad3ae479c8f53edebb2eeeb700088856caf5cf58bfca0c1
2024-06-20 13:36:55 -04:00
Ava Chow
a52837b9e9
Merge bitcoin/bitcoin#29575: net_processing: make any misbehavior trigger immediate discouragement
6eecba475e net_processing: make MaybePunishNodeFor{Block,Tx} return void (Pieter Wuille)
ae60d485da net_processing: remove Misbehavior score and increments (Pieter Wuille)
6457c31197 net_processing: make all Misbehaving increments = 100 (Pieter Wuille)
5120ab1478 net_processing: drop 8 headers threshold for incoming BIP130 (Pieter Wuille)
944c54290d net_processing: drop Misbehavior for unconnecting headers (Pieter Wuille)
9f66ac7cf1 net_processing: do not treat non-connecting headers as response (Pieter Wuille)

Pull request description:

  So far, discouragement of peers triggers when their misbehavior score exceeds 100 points. Most types of misbehavior increment the score by 100, triggering immediate discouragement, but some types do not. This PR makes all increments equal to either 100 (meaning any misbehavior will immediately cause disconnection and discouragement) or 0 (making the behavior effectively unconditionally allowed), and then removes the logic for score accumulation.

  This simplifies the code a bit, but also makes protocol expectations clearer: if a peer misbehaves, they get disconnected. There is no good reason why certain types of protocol violations should be permitted 4 times (howmuch=20) or 9 times (howmuch=10), while many others are never allowed. Furthermore, the distinction between these looks arbitrary.

  The specific types of misbehavior that are changed to 100 are:
  * Sending us a `block` which does not connect to our header tree (which necessarily must have been unsollicited). [used to be score 10]
  * Sending us a `headers` with a non-continuous headers sequence. [used to be score 20]
  * Sending us more than 1000 addresses in a single `addr` or `addrv2` message [used to be score 20]
  * Sending us more than 50000 invs in a single `inv` message [used to be score 20]
  * Sending us more than 2000 headers in a single `headers` message [used to be score 20]

  The specific types of misbehavior that are changed to 0 are:
  * Sending us 10 (*) separate BIP130 headers announcements that do not connect to our block tree [used to be score 20]
  * Sending us more than 8 headers in a single `headers` message (which thus does not get treated as a BIP130 announcement) that does not connect to our block tree. [used to be score 10]

  I believe that none of these behaviors are unavoidable, except for the one marked (*) which can in theory happen still due to interaction between BIP130 and variations in system clocks (the max 2 hour in the future rule). This one has been removed entirely. In order to remove the impact of the bug it was designed to deal with, without relying on misbehavior, a separate improvement is included that makes `getheaders`-tracking more accurate.

  In another unrelated improvement, this also gets rid of the 8 header limit heuristic to determine whether an incoming non-connecting `headers` is a potential BIP130 announcement, as this rule is no longer needed to prevent spurious Misbehavior. Instead, any non-connecting `headers` is now treated as a potential announcement.

ACKs for top commit:
  sr-gi:
    ACK [6eecba4](6eecba475e)
  achow101:
    ACK 6eecba475e
  mzumsande:
    Code Review ACK 6eecba475e
  glozow:
    light code review / concept ACK 6eecba475e

Tree-SHA512: e11e8a652c4ec048d8961086110a3594feefbb821e13f45c14ef81016377be0db44b5311751ef635d6e026def1960aff33f644e78ece11cfb54f2b7daa96f946
2024-06-20 13:28:38 -04:00
Fabian Jahr
80315c0118
refactor: Move early loadtxoutset checks into ActiveSnapshot
Also changes the return type of ActiveSnapshot to allow returning the
error message to the user of the loadtxoutset RPC.
2024-06-19 22:32:33 +02:00
Luke Dashjr
197b5404b0 QA: Expect PACKAGE_NAME rather than constant "Bitcoin Core" 2024-06-19 14:59:31 +00:00
Lőrinc
969e047cfb Replace hard-coded constant in test 2024-06-18 19:43:33 +02:00
Sjors Provoost
d8a3496b5a
rpc: call TestBlockValidity via miner interface 2024-06-18 18:47:51 +02:00
Ava Chow
41544b8f96
Merge bitcoin/bitcoin#28984: Cluster size 2 package rbf
94ed4fbf8e Add release note for size 2 package rbf (Greg Sanders)
afd52d8e63 doc: update package RBF comment (Greg Sanders)
6e3c4394cf mempool: Improve logging of replaced transactions (Greg Sanders)
d3466e4cc5 CheckPackageMempoolAcceptResult: Check package rbf invariants (Greg Sanders)
316d7b63c9 Fuzz: pass mempool to CheckPackageMempoolAcceptResult (Greg Sanders)
4d15bcf448 [test] package rbf (glozow)
dc21f61c72 [policy] package rbf (Suhas Daftuar)
5da3967815 PackageV3Checks: Relax assumptions (Greg Sanders)

Pull request description:

  Allows any 2 transaction package with no in-mempool ancestors to do package RBF when directly conflicting with other mempool clusters of size two or less.

  Proposed validation steps:
  1) If the transaction package is of size 1, legacy rbf rules apply.
  2) Otherwise the transaction package consists of a (parent, child) pair with no other in-mempool ancestors (or descendants, obviously), so it is also going to create a cluster of size 2. If larger, fail.
  3) The package rbf may not evict more than 100 transactions from the mempool(bip125 rule 5)
  4) The package is a single chunk
  5) Every directly conflicted mempool transaction is connected to at most 1 other in-mempool transaction (ie the cluster size of the conflict is at most 2).
  6) Diagram check: We ensure that the replacement is strictly superior, improving the mempool
  7) The total fee of the package, minus the total fee of what is being evicted, is at least the minrelayfee * size of the package (equivalent to bip125 rule 3 and 4)

  Post-cluster mempool this will likely be expanded to general package rbf, but this is what we can safely support today.

ACKs for top commit:
  achow101:
    ACK 94ed4fbf8e
  glozow:
    reACK 94ed4fbf8e via range-diff
  ismaelsadeeq:
    re-ACK 94ed4fbf8e
  theStack:
    Code-review ACK 94ed4fbf8e
  murchandamus:
    utACK 94ed4fbf8e

Tree-SHA512: 9bd383e695964f362f147482bbf73b1e77c4d792bda2e91d7f30d74b3540a09146a5528baf86854a113005581e8c75f04737302517b7d5124296bd7a151e3992
2024-06-17 17:22:43 -04:00
Ava Chow
f011022d53
Merge bitcoin/bitcoin#30195: test: Added test coverage to listsinceblock rpc
881724d443 test: Added test coverage to listsinceblock rpc (kevkevinpal)

Pull request description:

  This change is meant to add test coverage to this rpc error https://github.com/bitcoin/bitcoin/blob/master/src/wallet/rpc/transactions.cpp#L666C53-L666C79

  This is done by renaming the first block in the blocks folder

  ---

  Doing a quick grep for the error code in our functional tests leads to zero results
  `grep -nri "Can't read block from disk" ./test/functional/`

ACKs for top commit:
  achow101:
    ACK 881724d443
  tdb3:
    re ACK for 881724d443
  rkrux:
    tACK [881724](881724d443)

Tree-SHA512: c5dff20cf014d0181f49d6b161f1364e1c6b79e8661047f77f07e21e59f4d1f2fd6f745538c8fc5bd6d4244650a840dd64d184634366f7c21fa67141a60af44a
2024-06-17 15:35:49 -04:00
Ava Chow
4bcef32a93
Merge bitcoin/bitcoin#28312: test: fix keys_to_multisig_script (P2MS) helper for n/k > 16
5cf0a1f230 test: add `createmultisig` P2MS encoding test for all n (1..20) (Sebastian Falbesoner)
0570d2c204 test: add unit test for `keys_to_multisig_script` (Sebastian Falbesoner)
0c41fc3fa5 test: fix `keys_to_multisig_script` (P2MS) helper for n/k > 16 (Sebastian Falbesoner)

Pull request description:

  While reviewing #28307, I noticed that the test framework's `key_to_multisig_script` helper (introduced in #23305) is broken for pubkey count (n) and threshold (k) values larger than 16. This is due to the implementation currently enforcing a direct single-byte data push (using `CScriptOp.encode_op_n`), which obviously fails for values 17+. Fix that by passing the numbers directly to the CScript list, where it's automatically converted to minimally-encoded pushes (see class method `CScript.__coerce_instance`, branch `isinstance(other, int)`).

  The second commit adds a unit test to ensure that the encoding  is correct.

ACKs for top commit:
  achow101:
    ACK 5cf0a1f230
  tdb3:
    ACK 5cf0a1f230
  rkrux:
    reACK [5cf0a1f](5cf0a1f230)

Tree-SHA512: 4168a165c3f483ec8e37a27dba1628a7ea0063545a2b7e74d9e20d753fddd7e33d37e1a190434fa6dca39adf9eef5d0211f7a0c1c7b44979f0a3bb350e267562
2024-06-17 15:18:08 -04:00
stratospher
e075fd131d test: Introduce test types and modify v2 handshake function accordingly
Prior to this commit, TestEncryptedP2PState would always
send initial_v2_handshake bytes in 2 parts (as required
by early key response test).

For generalising this test and having different v2 handshake
behaviour based on the test type, special behaviours like
sending initial_v2_handshake bytes in 2 parts are executed
only if test_type is set to EARLY_KEY_RESPONSE.
2024-06-17 09:59:54 +05:30
tdb3
ad06e68399
test: write functional test results to csv
Adds argument --resultsfile to test_runner.py.
Writes comma-separated functional test name, status,
and duration to the file provided with the argument.
Also fixes minor typo in test_runner.py
2024-06-16 22:51:12 -04:00
kevkevinpal
881724d443
test: Added test coverage to listsinceblock rpc
This change adds a test to add coverage to the rpc error that emmits the message "Can't
read block from disk"
2024-06-16 13:30:56 -04:00
Ava Chow
2c79abc7ad
Merge bitcoin/bitcoin#27969: bumpfee: ignore WALLET_INCREMENTAL_RELAY_FEE when user specifies fee_rate
f58beabe75 test: bumpfee with user specified fee_rate ignores walletIncrementalRelayFee (ismaelsadeeq)
436e88f433 bumpfee: ignore WALLET_INCREMENTAL_RELAY_FEE when user specifies fee rate (ismaelsadeeq)

Pull request description:

  Fixes #26973

  When using the `bumpfee` RPC and manually specifying `fee_rate`, there should be no requirement that the new fee must be at least the sum of the original fee and `incrementalFee` (maximum of `relayIncrementalFee` and `WALLET_INCREMENTAL_RELAY_FEE`).

  This restriction should only apply when user did not specify `fee_rate`.
  > because the GUI doesn't let the user specify the new fee rate yet (https://github.com/bitcoin-core/gui/issues/647), it would be very annoying to have to bump 20 times to increment by 20 sat/vbyte.

  The restriction should instead be the new fee must be at least the sum of the original fee and `incrementalFee` (`relayIncrementalFee`)

ACKs for top commit:
  achow101:
    ACK f58beabe75
  murchandamus:
    ACK f58beabe75

Tree-SHA512: 193259f87173b7d5a8e68e0e29f2ca7e75c550e3cf0dee3d6d822b5b1e07c2e6dec0bfc8fb435855736ebced97a10dbdbfef72e8c5abde06fdefcba122f2e7f1
2024-06-14 14:46:04 -04:00
merge-script
8efc346e3b
Merge bitcoin/bitcoin#30278: test: cover more errors for signrawtransactionwithkey RPC
e2779ce98b test: cover more errors for `signrawtransactionwithkey` RPC (brunoerg)

Pull request description:

  This PR adds test coverage for the following errors for the `signrawtransactionwithkey` RPC:

  - Invalid private key
  - TX decode failed

  For reference: https://maflcko.github.io/b-c-cov/total.coverage/src/rpc/rawtransaction.cpp.gcov.html

ACKs for top commit:
  maflcko:
    ACK e2779ce98b
  kevkevinpal:
    ACK [e2779ce](e2779ce98b)
  tdb3:
    ACK e2779ce98b
  BrandonOdiwuor:
    Code Review ACK e2779ce98b

Tree-SHA512: 41c7e990684b60645cf4ccec8aad5ebbe61da221871eb3c1685b2bb1eebda58b29358502cb1525b7c7a2b612e2bebf449ed0bae14ab663b4641c528a9c013b5b
2024-06-14 09:42:20 +01:00
glozow
4d15bcf448 [test] package rbf 2024-06-13 09:52:59 -04:00
Ava Chow
ff21eb2def
Merge bitcoin/bitcoin#30219: Lint: Support running individual lint checks
0fcbfdb7ad Support running individual lint checks (David Gumberg)

Pull request description:

  This PR was split out from  #29965:

  Adds support for running individual tests in the rust lint suite by passing `--lint=LINT_TO_RUN` to the lint runner. This PR also adds a corresponding help message.

  When running with `cargo run`, arguments after a double dash (`--`) are passed to the binary instead of the cargo command. For example, in order to run the linter check that tabs are not used as whitespace:

  ```console
  cd test/lint/test_runner && cargo run -- --lint=tabs_whitespace
  ```

ACKs for top commit:
  maflcko:
    ACK 0fcbfdb7ad
  achow101:
    ACK 0fcbfdb7ad
  marcofleon:
    Tested ACK 0fcbfdb7ad. Ran `cargo run` with various of the individual tests and with bad input. Also ran it with no arguments. Everything works as expected and help message looks good.

Tree-SHA512: 48fe4aa9fbb2acef5f8e3c17382ae22e0e350ae6ad9aeeb1a3c0a9192de98809f98728e32b8db24a36906ace999e35626ebd6cb2ca05f74146d21e9b6fb14615
2024-06-12 17:19:48 -04:00
brunoerg
e2779ce98b test: cover more errors for signrawtransactionwithkey RPC
* Invalid private key
* TX decode failed
2024-06-12 17:07:16 -03:00
Max Edwards
c4762b0aa0 test: allow excluding func test by name and arg
Can now specify test_runner.py --exclude "rpc_bind.py --ipv6" and have only that test variant excluded
2024-06-12 16:50:44 +01:00
merge-script
5ee6b76c69
Merge bitcoin/bitcoin#29325: consensus: Store transaction nVersion as uint32_t
429ec1aaaa refactor: Rename CTransaction::nVersion to version (Ava Chow)
27e70f1f5b consensus: Store transaction nVersion as uint32_t (Ava Chow)

Pull request description:

  Given that the use of a transaction's nVersion is always as an unsigned int, it doesn't make sense to store it as signed and then cast it to unsigned everywhere it is used and displayed.

  Since a few alternative implementations have recently been revealed to have made an error with this signedness that would have resulted in consensus failure, I think it makes sense for us to just make this always unsigned to make it clear that the version is treated as unsigned. This would also help us avoid future potential issues with signedness of this value.

  I believe that this is safe and does not actually change what transactions would or would not be considered both standard and consensus valid. Within consensus, the only use of the version in consensus is in BIP68 validation which was already casting it to uint32_t. Within policy, although it is used as a signed int for the transaction version number check, I do not think that this change would change standardness. Standard transactions are limited to the range [1, 2]. Negative numbers would have fallen under the < 1 condition, but by making it unsigned, they are still non-standard under the > 2 condition.

  Unsigned and signed ints are serialized and unserialized the same way so there is no change in serialization.

ACKs for top commit:
  maflcko:
    ACK 429ec1aaaa 🐿
  glozow:
    ACK 429ec1aaaa
  shaavan:
    ACK 429ec1aaaa 💯

Tree-SHA512: 0bcd92a245d7d16c3665d2d4e815a4ef28207ad4a1fb46c6f0203cdafeab1b82c4e95e4bdce7805d80a4f4a46074f6542abad708e970550d38a00d759e3dcef1
2024-06-12 10:32:31 +01:00
Ava Chow
91e0beede2
Merge bitcoin/bitcoin#30160: util: add BitSet
47f705b33f tests: add fuzz tests for BitSet (Pieter Wuille)
59a6df6bd5 util: add BitSet (Pieter Wuille)

Pull request description:

  Extracted from #30126.

  This introduces the `BitSet` data structure, inspired by `std::bitset`, but with a few features that cannot be implemented on top without efficiency loss:
  * Finding the first set bit (`First`)
  * Finding the last set bit (`Last`)
  * Iterating over all set bits (`begin` and `end`).

  And a few other operators/member functions that help readability for #30126:
  * `operator-` for set subtraction
  * `Overlaps()` for testing whether intersection is non-empty
  * `IsSupersetOf()` for testing (non-strict) supersetness
  * `IsSubsetOf()` for testing (non-strict) subsetness
  * `Fill()` to construct a set with all numbers from 0 to n-1, inclusive
  * `Singleton()` to construct a set with one specific element.

  Everything is tested through a simulation-based fuzz test that compares the behavior with normal `std::bitset` equivalent operations.

ACKs for top commit:
  instagibbs:
    ACK 47f705b33f
  achow101:
    ACK 47f705b33f
  cbergqvist:
    re-ACK 47f705b33f
  theStack:
    Code-review ACK 47f705b33f

Tree-SHA512: e451bf4b801f193239ee434b6b614f5a2ac7bb49c70af5aba24c2ac0c54acbef4672556800e4ac799ae835632bdba716209c5ca8c37433a6883dab4eb7cd67c1
2024-06-11 17:28:51 -04:00
Ava Chow
1bcc91a52c
Merge bitcoin/bitcoin#29521: cli: Detect port errors in rpcconnect and rpcport
24bc46c83b cli: Add warning for duplicate port definition (tdb3)
e208fb5d3b cli: Sanitize ports in rpcconnect and rpcport (tdb3)

Pull request description:

  Adds invalid port detection to bitcoin-cli for -rpcconnect and -rpcport.

  In addition to detecting malformed/invalid ports (e.g. those outside of the 16-bit port range, not numbers, etc.), bitcoin-cli also now considers usage of port 0 to be invalid.  bitcoin-cli previously considered port 0 to be valid and attempted to use it to reach bitcoind.

  Functional tests were added for invalid port detection as well as port prioritization.
  Additionally, a warning is provided when a port is specified in both -rpcconnect and -rpcport.

  This PR is an alternate approach to PR #27820 (e.g. SplitHostPort is unmodified).

  Considered an alternative to 127.0.0.1 being specified in functional tests, but at first glance, this might need an update to test_framework/util.py (e.g.  rpc_url), which might be left to a future PR.

ACKs for top commit:
  S3RK:
    light code review ACK 24bc46c83b
  achow101:
    ACK 24bc46c83b
  cbergqvist:
    re ACK 24bc46c83b

Tree-SHA512: c83ab6a30a08dd1ac8b368a7dcc2b4f23170f0b61dd67ffcad7bcda05096d333bcb9821fba11018151f55b2929c0a333bfec15b8bb863d83f41fc1974c6efca5
2024-06-11 15:55:18 -04:00
Sebastian Falbesoner
e4b0dabb21 test: add functional test for tagged MiniWallet instances 2024-06-11 18:53:17 +02:00
Sebastian Falbesoner
3162c917e9 test: fix MiniWallet internal key derivation for tagged instances
Not every pseudorandom hash result is a valid x-only public key,
so the pubkey tweaking in the course of creating the output public
key would fail about every second time.

Fix this by treating the hash result as private key and calculate
the x-only public key out of that, to be used then as internal key.
2024-06-11 18:53:07 +02:00
merge-script
5bc9b644a4
Merge bitcoin/bitcoin#30264: test: add coverage for errors for combinerawtransaction
ab98e6fd03 test: add coverage for errors for `combinerawtransaction` RPC (brunoerg)

Pull request description:

  This PR adds test coverage for the following errors for the `combinerawtransaction` RPC:

  * Tx decode failed
  * Missing transactions
  * Input not found or already spent

  For reference: https://maflcko.github.io/b-c-cov/total.coverage/src/rpc/rawtransaction.cpp.gcov.html

ACKs for top commit:
  maflcko:
    lgtm ACK ab98e6fd03
  tdb3:
    ACK ab98e6fd03

Tree-SHA512: 8a133c25dad2e1b236e0278a88796f60f763e3fd6fbbc080f926bb23f9dcc55599aa242d6e0c4ec15a179d9ded10a1f17ee5b6063719107ea84e6099f10416b2
2024-06-11 15:29:18 +01:00
merge-script
0fbb8043ce
Merge bitcoin/bitcoin#30252: test: Remove redundant verack check
0000276b31 test: Remove redundant verack check (MarcoFalke)

Pull request description:

  Currently the sync in `connect_nodes` mentions the `version` and `verack` message types, but only checks the `verack`. Neither check is required, as the `pong` check implies both. In case of failure, the debug log will have to be consulted anyway, so the redundant check doesn't add value.

  Also clarify in the comments that the goal is to check the flag `fSuccessfullyConnected` indirectly.

ACKs for top commit:
  furszy:
    utACK 0000276b31
  brunoerg:
    ACK 0000276b31
  tdb3:
    ACK 0000276b31

Tree-SHA512: f9ddcb1436d2f70da462a8dd470ecfc90a534dd6507c23877ef7626e7c02326c077001a42ad0171a87fba5c5275d1970d8c5e5d82c56c8412de944856fdfd6db
2024-06-11 14:11:34 +01:00
Sebastian Falbesoner
c9f7364ab2 test: fix MiniWallet script-path spend (missing parity bit in leaf version)
This commit fixes a dormant bug in MiniWallet that exists since
support for P2TR was initially added in #23371 (see commit
041abfebe4).

In the course of spending the output, the leaf version byte of the
control block in the witness stack doesn't set the parity bit, i.e.
we were so far just lucky that the used combinations of relevant
data (internal pubkey, leaf script / version) didn't result in a
tweaked pubkey with odd y-parity. If that was the case, we'd get the
following validation error:

`mandatory-script-verify-flag-failed (Witness program hash mismatch) (-26)`

Since MiniWallets can now optionally be tagged (#29939), resulting
in different internal pubkeys, the issue is more prevalent now.
Fix it by passing the parity bit, as specified in BIP341.
2024-06-11 14:36:07 +02:00
Sebastian Falbesoner
7774c314fb test: refactor: return TaprootInfo from P2TR address creation routine
Rather than only returning the internal key from the P2TR anyone-can-spend
address creation routine, provide the whole TaprootInfo object, which in turn
contains a dictionary of TaprootLeafInfo object for named leaves.

This data is used in MiniWallet for the default ADDRESS_OP_TRUE mode, in order
to deduplicate the witness script and leaf version of the control block.
2024-06-11 14:36:05 +02:00
glozow
e6e4c18a9b
Merge bitcoin/bitcoin#30162: test: MiniWallet: respect passed feerate for padded txs (using target_weight)
39d135e79f test: MiniWallet: respect fee_rate for target_weight, use in mempool_limit.py (Sebastian Falbesoner)
b2f0a9f8b0 test: add framework functional test for MiniWallet's tx padding (Sebastian Falbesoner)
c17550bc3a test: MiniWallet: fix tx padding (`target_weight`) for large sizes, improve accuracy (Sebastian Falbesoner)

Pull request description:

  MiniWallet allows to create padded transactions that are equal or slightly above a certain `target_weight` (first introduced in PR #25379, commit 1d6b438ef0), which can be useful especially for mempool-related tests, e.g. for policy limit checks or scenarios to trigger mempool eviction. Currently the `target_weight` parameter doesn't play together with `fee_rate` though, as the fee calculation is incorrectly based on the tx vsize before the padding output is added, so the fee-rate is consequently far off. This means users are forced to pass an absolute fee, which can be quite inconvenient and leads to lots of duplicated "calculate absolute fee from fee-rate and vsize" code with the pattern `fee = (feerate / 1000) * (weight // 4)` on the call-sites.

  This PR first improves the tx padding itself to be more accurate, adds a functional test for it, and fixes the `fee_rate` treatment for the `{create,send}_self_transfer` methods. (Next step would be to enable this also for the `_self_transfer_multi` methods, but those currently don't even offer a `fee_rate` parameter). Finally, the ability to pass both `target_weight` and `fee_rate` is used in the `mempool_limit.py` functional test. There might be more use-cases in other tests, that could be done in a follow-up.

ACKs for top commit:
  rkrux:
    tACK [39d135e](39d135e79f)
  ismaelsadeeq:
    Code Review ACK 39d135e79f  🚀
  glozow:
    light review ACK 39d135e79f

Tree-SHA512: 6bf8e853a921576d463291d619cdfd6a7e74cf92f61933a563800ac0b3c023a06569b581243166906f56b3c5e8858fec2d8a6910d55899e904221f847eb0953d
2024-06-11 13:02:03 +01:00
brunoerg
ab98e6fd03 test: add coverage for errors for combinerawtransaction RPC
* Tx decode failed
* Missing transactions
* Input not found or already spent
2024-06-10 15:19:24 -03:00
Ryan Ofsky
b1ba1b178f
Merge bitcoin/bitcoin#30132: indexes: Don't wipe indexes again when continuing a prior reindex
f68cba29b3 blockman: Replace m_reindexing with m_blockfiles_indexed (Ryan Ofsky)
1b1c6dcca0 test: Add functional test for continuing a reindex (TheCharlatan)
201c1a9282 indexes: Don't wipe indexes again when already reindexing (TheCharlatan)
804f09dfa1 kernel: Add less confusing reindex options (Ryan Ofsky)
e172553223 validation: Remove needs_init from LoadBlockIndex (TheCharlatan)
533eab7d67 bugfix: Streamline setting reindex option (TheCharlatan)

Pull request description:

  When restarting `bitcoind` during an ongoing reindex without setting the `-reindex` flag again, the block and coins db is left intact, but any data from the optional indexes is discarded. While not a bug per se, wiping the data again is
  wasteful, both in terms of having to write it again,  as well as potentially leading to longer startup times. So keep the  index data instead when continuing a prior reindex.

  Also includes a bugfix and smaller code cleanups around the reindexing code. The bug was introduced in b47bd95920: "kernel: De-globalize fReindex".

ACKs for top commit:
  stickies-v:
    ACK f68cba29b3
  fjahr:
    Code review ACK f68cba29b3
  furszy:
    Code review ACK f68cba29b3
  ryanofsky:
    Code review ACK f68cba29b3. Only changes since last review were cherry-picking suggested commits that rename variables, improving comments, and making some tweaks to test code.

Tree-SHA512: b252228cc76e9f1eaac56d5bd9e4eac23408e0fc04aeffd97a85417f046229364673ee1ca7410b9b6e7b692b03f13ece17c42a10176da0d7e975a8915deb98ca
2024-06-10 10:12:30 -04:00
Pieter Wuille
59a6df6bd5 util: add BitSet
This adds a bitset module that implements a BitSet<N> class, a variant
of std::bitset with a few additional features that cannot be implemented
in a wrapper without performance loss (specifically, finding first and
last bit set, or iterating over all set bits).
2024-06-10 07:54:48 -04:00
MarcoFalke
0000276b31
test: Remove redundant verack check 2024-06-10 07:58:10 +02:00
merge-script
a44b0f771f
Merge bitcoin/bitcoin#30238: json-rpc 2.0 followups: docs, tests, cli
1f6ab1215b minor: remove unnecessary semicolons from RPC content type examples (Matthew Zipkin)
b225295298 test: use json-rpc 2.0 in all functional tests by default (Matthew Zipkin)
391843b029 bitcoin-cli: use json-rpc 2.0 (Matthew Zipkin)
d39bdf3397 test: remove unused variable in interface_rpc.py (Matthew Zipkin)
0ead71df8c doc: update and link for JSON-RPC 2.0 (Matthew Zipkin)

Pull request description:

  This is a follow-up to #27101.

  - Addresses [post-merge comments ](https://github.com/bitcoin/bitcoin/pull/27101#discussion_r1606723428)
  - bitcoin-cli uses JSON-RPC 2.0
  - functional tests use JSON-RPC 2.0 by default (exceptions are in the regression tests added by #27101)

ACKs for top commit:
  tdb3:
    ACK 1f6ab1215b
  cbergqvist:
    ACK 1f6ab1215b

Tree-SHA512: 49bf14c70464081280216ece538a2f5ec810bac80a86a83ad3284f0f1b017edf755a1a74a45be279effe00218170cafde7c2de58aed07097a95c2c6b837a6b6c
2024-06-08 09:33:49 +01:00
Ava Chow
429ec1aaaa refactor: Rename CTransaction::nVersion to version
In order to ensure that the change of nVersion to a uint32_t in the
previous commit has no effect, rename nVersion to version in this commit
so that reviewers can easily spot if a spot was missed or if there is a
check somewhere whose semantics have changed.
2024-06-07 13:55:23 -04:00
TheCharlatan
1b1c6dcca0
test: Add functional test for continuing a reindex
Co-authored-by: furszy <matiasfurszyfer@protonmail.com>
2024-06-07 19:17:21 +02:00
Ava Chow
27e70f1f5b consensus: Store transaction nVersion as uint32_t
Given that the use of a transaction's nVersion is always as an unsigned
int, it doesn't make sense to store it as signed and then cast it to
unsigned.
2024-06-07 12:40:21 -04:00
Ava Chow
6e4d18f37f
Merge bitcoin/bitcoin#29496: policy: bump TX_MAX_STANDARD_VERSION to 3
30a01134cd [doc] update bips.md for 431 (glozow)
9dbe6a03f0 [test] wallet uses CURRENT_VERSION which is 2 (glozow)
539404fe0f [policy] make v3 transactions standard (glozow)
052ede75af [refactor] use TRUC_VERSION in place of 3 (glozow)

Pull request description:

  Make `nVersion=3` (which is currently nonstandard on mainnet) standard.

  Note that we will treat these transactions as Topologically Restricted Until Confirmation (TRUC). Spec is in BIP 431 and implementation is in #28948, #29306, and #29873

  See #27463 for overall project tracking, and #29319 for information about relevance to cluster mempool.

ACKs for top commit:
  sdaftuar:
    utACK 30a01134c
  achow101:
    ACK 30a01134cd
  instagibbs:
    utACK 30a01134cd
  murchandamus:
    ACK 30a01134cd
  ismaelsadeeq:
    ACK 30a01134cd 🛰️

Tree-SHA512: 2a4aec0442c860e792a061d83e36483c1f1b426f946efbdf664c8db97a596e498b535707e1d3a900218429486ea69fd4552e3d476526a6883cbd5556c6534b48
2024-06-07 12:30:46 -04:00
Matthew Zipkin
b225295298
test: use json-rpc 2.0 in all functional tests by default 2024-06-07 09:26:55 -04:00
Matthew Zipkin
d39bdf3397
test: remove unused variable in interface_rpc.py 2024-06-07 09:26:55 -04:00
Ava Chow
4a020ca443
Merge bitcoin/bitcoin#29401: test: Remove struct.pack from almost all places
fa52e13ee8 test: Remove struct.pack from almost all places (MarcoFalke)
fa826db477 scripted-diff: test: Use int.to_bytes over struct packing (MarcoFalke)
faf2a975ad test: Use int.to_bytes over struct packing (MarcoFalke)
faf3cd659a test: Normalize struct.pack format (MarcoFalke)

Pull request description:

  `struct.pack` has many issues:

  * The format string consists of characters that may be confusing and may need to be looked up in the documentation, as opposed to using easy to understand self-documenting code.

  This lead to many test bugs, which weren't hit, which is fine, but still confusing. Ref: https://github.com/bitcoin/bitcoin/pull/29400, https://github.com/bitcoin/bitcoin/pull/29399, https://github.com/bitcoin/bitcoin/pull/29363, fa3886b7c6, ...

  Fix all issues by using the built-in `int` helpers `to_bytes` via a scripted diff.

  Review notes:

  * For `struct.pack` and `int.to_bytes` the error behavior is the same, although the error messages are not identical.
  * Two `struct.pack` remain. One for float serialization in a C++ code comment, and one for native serialization.

ACKs for top commit:
  achow101:
    ACK fa52e13ee8
  rkrux:
    tACK [fa52e13](fa52e13ee8)
  theStack:
    Code-review ACK fa52e13ee8

Tree-SHA512: ee80d935b68ae43d1654b047e84ceb80abbd20306df35cca848b3f7874634b518560ddcbc7e714e2e7a19241e153dee64556dc4701287ae811e26e4f8c57fe3e
2024-06-06 19:18:55 -04:00
Sebastian Falbesoner
5cf0a1f230 test: add createmultisig P2MS encoding test for all n (1..20) 2024-06-05 16:18:34 +02:00
Sebastian Falbesoner
0570d2c204 test: add unit test for keys_to_multisig_script 2024-06-05 16:18:31 +02:00
Sebastian Falbesoner
0c41fc3fa5 test: fix keys_to_multisig_script (P2MS) helper for n/k > 16
The helper assumes that the n and k values have to be provided as a
single byte push operation, which is only possible for values up to 16.
Fix that by passing the numbers directly to the CScript list, where it's
automatically converted to minimally-encoded pushes (see class
method `CScript.__coerce_instance`, branch `isinstance(other, int)`).

In case of 17..20, this means that the data-pushes are done with two
bytes using OP_PUSH1 (0x01), e.g. for n=20: 0x01,0x14
2024-06-05 16:15:17 +02:00
merge-script
74dc8585b3
Merge bitcoin/bitcoin#30174: test: Set mocktime in p2p_disconnect_ban.py to avoid intermittent test failure
4444de152f test: Set mocktime in p2p_disconnect_ban.py to avoid intermittent test failure (MarcoFalke)
fa6aa4027c test: Fix typos and use names args (MarcoFalke)

Pull request description:

  Otherwise, the test may fail on slow hardware when running in valgrind.

  Also, use named args for the absolute timepoint, while touching this file.

ACKs for top commit:
  tdb3:
    ACK for 4444de152f
  AngusP:
    re-ACK 4444de152f

Tree-SHA512: 660269c8dd18887d69b284f38656899caf028159ce83ddf921f3e9c080a5d0e663989f0e42b4baf4c4939f20f34da0e7e844dff9b7c91d0cab570c60958bd0e1
2024-06-05 11:37:15 +01:00
Ava Chow
c29314ecfc
Merge bitcoin/bitcoin#29998: functional test: ensure confirmed utxo being sourced for 2nd chain
07aba8dd21 functional test: ensure confirmed utxo being sourced for 2nd chain (Greg Sanders)

Pull request description:

  The test could fail/stop testing what we want if non-confirmed utxos become sourced through some internal change to `MiniWallet`; better to just fetch confirmed explicitly.

ACKs for top commit:
  achow101:
    ACK 07aba8dd21
  ismaelsadeeq:
    utACK 07aba8dd21
  theStack:
    ACK 07aba8dd21

Tree-SHA512: 66795fdf881139ed91bde0f8239a46bd9bc70bb311fa97c0e2b5537e1fd2a1fd36bf3a225fc77b9695deb835a9d6d29879aa1e05ea5054b9a33a400e199da014
2024-06-04 21:47:16 -04:00
Ava Chow
76a33be21d
Merge bitcoin/bitcoin#28307: rpc, wallet: fix incorrect segwit redeem script size limit
2451a217dd test: addmultisigaddress, coverage for script size limits (furszy)
53302a0981 bugfix: addmultisigaddress, add unsupported operation for redeem scripts over 520 bytes (furszy)
9be6065cc0 test: coverage for 16-20 segwit multisig scripts (furszy)
9d9a91c4ea rpc: bugfix, incorrect segwit redeem script size used in signrawtransactionwithkey (furszy)
0c9fedfc45 fix incorrect multisig redeem script size limit for segwit (furszy)
f7a173b578 test: rpc_createmultisig, decouple 'test_sortedmulti_descriptors_bip67' (furszy)
4f33dbd8f8 test: rpc_createmultisig, decouple 'test_mixing_uncompressed_and_compressed_keys' (furszy)
25a81705d3 test: rpc_createmultisig, remove unnecessary checkbalances() (furszy)
b5a3289433 test: refactor, multiple cleanups in rpc_createmultisig.py (furszy)
3635d43268 test: rpc_createmultisig, remove manual wallet initialization (furszy)

Pull request description:

  Fixing https://github.com/bitcoin/bitcoin/issues/28250#issuecomment-1674830104 and more.

  Currently, redeem scripts longer than 520 bytes, which are technically valid under segwit rules, have flaws in the following processes:
  1) The multisig creation process fails to deduce the output descriptor, resulting in the generation of an incorrect descriptor. Additionally, the accompanying user warning is also inaccurate.
  2) The `signrawtransactionwithkey` RPC command fail to sign them.
  3) The legacy wallet `addmultisigaddress` wrongly discards them.

  The issue arises because most of these flows are utilizing the legacy spkm keystore, which imposes
  the [p2sh max redeem script size rule](ded6873340/src/script/signingprovider.cpp (L160)) on all scripts. Which blocks segwit redeem scripts longer than
  the max element size in all the previously mentioned processes (`createmultisig`, `addmultisigaddress`, and
  `signrawtransactionwithkey`).

  This PR fixes the problem, enabling the creation of multisig output descriptors involving more than 15 keys and
  allowing the signing of these scripts, along with other post-segwit redeem scripts that surpass the 520-byte
  p2sh limit.

  Important note:
  Instead of adding support for these longer redeem scripts in the legacy wallet, an "unsupported operation"
  error has been added. The reasons behind this decision are:

  1) The introduction of this feature brings about a compatibility-breaking change that requires downgrade
      protection; older wallets would be unable to interact with these "new" legacy wallets.

  2) Considering the ongoing deprecation of the legacy spkm, this issue provides another compelling
      reason to transition towards descriptors.

  Testing notes:
  To easily verify each of the fixes, I decoupled the tests into standalone commits. So they can be
  cherry-picked on top of master. Where `rpc_createmultisig.py` (with and without the `--legacy-wallet`
  arg) will fail without the bugs fixes commits.

  Extra note:
  The initial commits improves the `rpc_createmultisig.py` test in many ways. I found this test very
  antiquated, screaming for an update and cleanup.

ACKs for top commit:
  pinheadmz:
    ACK 2451a217dd
  theStack:
    Code-review ACK 2451a217dd
  achow101:
    ACK 2451a217dd

Tree-SHA512: 71794533cbd46b3a1079fb4e9d190d3ea3b615de0cbfa443466e14f05e4616ca90e12ce2bf07113515ea8113e64a560ad572bb9ea9d4835b6fb67b6ae596167f
2024-06-04 21:39:49 -04:00
Ava Chow
56ea8ed3d3
Merge bitcoin/bitcoin#29428: test: Assumeutxo: snapshots with less work should not be loaded
df6dc2aaae test: Assumeutxo: snapshots with less work should not be loaded (Hernan Marino)

Pull request description:

  This PR adds a test which checks that snapshots with less accumulated work than the node's active chain, should not be loaded and return with an error. Although in a different context of discussion the missing test was detect in a thread in https://github.com/bitcoin/bitcoin/pull/29394 (see https://github.com/bitcoin/bitcoin/pull/29394#discussion_r1484122214)

ACKs for top commit:
  maflcko:
    utACK df6dc2aaae
  kevkevinpal:
    utACK [df6dc2a](df6dc2aaae)
  achow101:
    ACK df6dc2aaae
  alfonsoromanz:
    Re ACK df6dc2aaae. Make is successful and the test passes.

Tree-SHA512: 07a394b4b288cc8ad3f66ed4e70dcda468db18113e9442eb7215cf491768432d55efaaa5b79d633094917e05475a30f0c5e4f64f8f2da293ba306891b4485560
2024-06-04 19:13:03 -04:00
Ava Chow
e54c392356
Merge bitcoin/bitcoin#28979: wallet, rpc: document and update sendall behavior around unconfirmed inputs
71aae72e1f test: test sendall does ancestor aware funding (ishaanam)
36757941a0 wallet, rpc: implement ancestor aware funding for sendall (ishaanam)
544131f3fb rpc, test: test sendall spends unconfirmed change and unconfirmed inputs when specified (ishaanam)

Pull request description:

  This PR:
  - Adds a functional test that `sendall` spends unconfirmed change
  - Adds a functional test that `sendall` spends regular unconfirmed inputs when specified by user
  - Adds ancestor aware funding to `sendall` by using `calculateCombinedBumpFee` and adjusting the effective value accordingly
  - Adds a functional test for ancestor aware funding in `sendall`

ACKs for top commit:
  S3RK:
    ACK 71aae72e1f
  achow101:
    ACK 71aae72e1f
  furszy:
    ACK 71aae72e1f

Tree-SHA512: acaeb7c65166ce53123a1d6cb5012197202246acc02ef9f37a28154cc93afdbd77c25e840ab79bdc7e0b88904014a43ab1ddea79d5337dc310ea210634ab61f0
2024-06-04 18:46:47 -04:00
MarcoFalke
4444de152f
test: Set mocktime in p2p_disconnect_ban.py to avoid intermittent test failure 2024-06-04 21:49:50 +02:00
MarcoFalke
fa6aa4027c
test: Fix typos and use names args 2024-06-04 21:49:47 +02:00
David Gumberg
0fcbfdb7ad Support running individual lint checks
Add support for passing `--lint=LINT_TO_RUN` to the lint runner and
add corresponding help message.
2024-06-04 09:13:44 -04:00
merge-script
80bdd4b6be
Merge bitcoin/bitcoin#30167: doc, rpc: Release notes and follow-ups for #29612
efc1b5be8a test: Add coverage for txid coins count check when loading snapshot (Fabian Jahr)
6b6084850b assumeutxo: Add network magic ctor param to SnapshotMetadata (Fabian Jahr)
1f1f998455 assumeutxo: Deserialize trailing byte instead of Txid (Fabian Jahr)
359967e310 doc: Add release notes for #29612 (Fabian Jahr)

Pull request description:

  This adds release notes for #29612 and addresses post-merge review comments.

ACKs for top commit:
  maflcko:
    utACK efc1b5be8a
  theStack:
    utACK efc1b5be8a

Tree-SHA512: 3b270202e4f7b2576090ef1d970fd54a6840d96fc3621dddd28e888fb8696a97ff69af2e000bcee3b364316ca3f6e2a9b2f1694c6184f0e704dc487823127ce4
2024-06-03 10:29:14 +01:00
glozow
9dbe6a03f0 [test] wallet uses CURRENT_VERSION which is 2 2024-06-02 08:54:50 +02:00
glozow
539404fe0f [policy] make v3 transactions standard
Note that, as CURRENT_VERSION = 2, the wallet will not make transactions
with nVersion=3 yet.
2024-06-02 08:54:50 +02:00
Sebastian Falbesoner
39d135e79f test: MiniWallet: respect fee_rate for target_weight, use in mempool_limit.py 2024-05-31 00:12:00 +02:00
Sebastian Falbesoner
b2f0a9f8b0 test: add framework functional test for MiniWallet's tx padding 2024-05-31 00:12:00 +02:00
Sebastian Falbesoner
c17550bc3a test: MiniWallet: fix tx padding (target_weight) for large sizes, improve accuracy 2024-05-31 00:11:55 +02:00
Pieter Wuille
6457c31197 net_processing: make all Misbehaving increments = 100
This removes the need to actually track misbehavior score (see further commit), because any
Misbehaving node will immediately hit the discouragement threshold.
2024-05-30 08:35:18 -04:00
Pieter Wuille
944c54290d net_processing: drop Misbehavior for unconnecting headers
This misbehavior was originally intended to prevent bandwidth wastage due to
actually observed very broken (but likely non-malicious) nodes that respond
to GETHEADERS with a response unrelated to the request, triggering a request
cycle.

This has however largely been addressed by the previous commit, which causes
non-connecting HEADERS that are received while a GETHEADERS has not been
responded to, to be ignored, as long as they do not time out (2 minutes).
With that, the specific misbehavior is largely irrelevant (for inbound peers,
it is now harmless; for outbound peers, the eviction logic will eventually
kick them out if they're not keeping up with headers at all).
2024-05-30 08:34:59 -04:00
Pieter Wuille
9f66ac7cf1 net_processing: do not treat non-connecting headers as response
Since https://github.com/bitcoin/bitcoin/pull/25454 we keep track of the last
GETHEADERS request that was sent and wasn't responded to. So far, every incoming
HEADERS message is treated as a response to whatever GETHEADERS was last sent,
regardless of its contents.

This commit makes this tracking more accurate, by only treating HEADERS messages
which (1) are empty, (2) connect to our existing block header tree, or (3) are a
continuation of a low-work headers sync as responses that clear the "outstanding
GETHEADERS" state (m_last_getheaders_timestamp).

That means that HEADERS messages which do not satisfy any of the above criteria
will be ignored, not triggering a GETHEADERS, and potentially (for now, but see
later commit) increase misbehavior score.
2024-05-30 08:31:43 -04:00
merge-script
0a7c650fcd
Merge bitcoin/bitcoin#30034: ci: add markdown link check job
4b7d984269 lint: add markdown hyperlink checker (willcl-ark)

Pull request description:

  Potential followup to: #30025

  This should prevent us reintroducing broken markdown links.

  It does not test "online" (external) links, only those within this repo. Both relative and absolute links are parsed successfully if they resolve.

ACKs for top commit:
  maflcko:
    re-utACK 4b7d984269
  davidgumberg:
    reACK 4b7d984269

Tree-SHA512: 9bc40d700b73499c046bb76157bc139f32ec3850f64ef813bbf7f18f9c01a253abe6a857d6f559890165f2bd26e7742c05d86232cd9b8efb33ff85d735f4f095
2024-05-30 12:36:09 +01:00
stratospher
d4a1da8543 test: Make global TRANSPORT_VERSION variable an instance variable
Currently, transport version is a global variable declared as
TRANSPORT_VERSION in v2_p2p.py. Making it an instance variable
would help in sending non empty transport version packets for
testing purposes. It might also help EncryptedP2PState be more
extensible in far future protocol upgrades.
2024-05-27 09:50:32 +05:30
Fabian Jahr
efc1b5be8a
test: Add coverage for txid coins count check when loading snapshot 2024-05-24 18:44:05 +02:00
willcl-ark
4b7d984269
lint: add markdown hyperlink checker
This adds a markdown hyperlink check task to the lint test_runner. It
relies on having the [`mlc`](https://crates.io/crates/mlc) binary found
on $PATH, but will fail with `success` if the binary is not found.

`mlc` is also added to the ci/04_install.sh script run by the
containerfile.

Note that broken markdown hyperlinks will be detected in untracked
markdown files found in a dirty working directory (including e.g.
.venv).
2024-05-24 12:11:50 +01:00
glozow
4c387cb64f
Merge bitcoin/bitcoin#30072: refactor prep for package rbf
2fd34ba504 Add sanity checks for various ATMPArgs booleans (Greg Sanders)
20d8936d8b [refactor] make some members MemPoolAccept-wide (glozow)
cbbfe719b2 cpfp carveout is excluded in packages (glozow)
69f7ab05ba Add m_allow_sibling_eviction as separate ATMPArgs flag (Greg Sanders)
57ee3029dd Add description for m_test_accept (Greg Sanders)

Pull request description:

  First few commits of https://github.com/bitcoin/bitcoin/pull/28984 to set the stage for the package RBF logic.

  These refactors are preparation for evaluating an RBF in a multi-proposed-transaction context instead of only a single proposed transaction. Also, carveouts and sibling evictions only should work in single RBF cases so add logic to preclude multi-tx cases in the future.

  No behavior changes aside from bailing earlier from failed carve-outs.

ACKs for top commit:
  glozow:
    reACK 2fd34ba504 via range-diff
  sr-gi:
    utACK [2fd34ba](2fd34ba504)
  theStack:
    re-ACK 2fd34ba504

Tree-SHA512: 5071c5b8d9b8d2c9faa278c8c4df31de288cb407a68e4d55544c588caff6c86160cce7825453549c6ed69e29d9ccb5ee2d4a518b18f563bfb12f2ced073fe42a
2024-05-24 10:24:50 +01:00
Ava Chow
413844f1c2
Merge bitcoin/bitcoin#29612: rpc: Optimize serialization and enhance metadata of dumptxoutset output
542e13b293 rpc: Enhance metadata of the dumptxoutset output (Fabian Jahr)
4d8e5edbaa assumeutxo: Add documentation on dumptxoutset serialization format (Fabian Jahr)
c14ed7f384 assumeutxo: Add test for changed coin size value (Fabian Jahr)
de95953d87 rpc: Optimize serialization disk space of dumptxoutset (Fabian Jahr)

Pull request description:

  The second attempt at implementing the `dumptxoutset` space optimization as suggested in #25675. Closes #25675.

  This builds on the work done in #26045, addresses open feedback, adds some further improvements (most importantly usage of compact size), documentation, and an additional test.

  The [original snapshot at height 830,000](https://github.com/bitcoin/bitcoin/pull/29551) came in at 10.82 GB. With this change, the same snapshot is 8.94 GB, a reduction of 17.4%.

  This also enhances the metadata of the output file and adds the following data to allow for better error handling and make future upgrades easier:
  - A newly introduced utxo set magic
  - A version number
  - The network magic
  - The block height

ACKs for top commit:
  achow101:
    ACK 542e13b293
  TheCharlatan:
    Re-ACK 542e13b293
  theStack:
    ACK 542e13b293

Tree-SHA512: 0825d30e5c3c364062db3c6cbca4e3c680e6e6d3e259fa70c0c2b2a7020f24a47406a623582040988d5c7745b08649c31110df4c10656aa25f3f27eb35843d99
2024-05-23 12:31:23 -04:00
glozow
cbbfe719b2 cpfp carveout is excluded in packages
The behavior is not new, but this rule exits earlier than before.
Previously, a carve out could have been granted in PreChecks() but then
nullified in PackageMempoolChecks() when CheckPackageLimits() is called
with the default limits.
2024-05-23 12:08:46 -04:00
Ava Chow
867f6af803
Merge bitcoin/bitcoin#29873: policy: restrict all TRUC (v3) transactions to 10kvB
154b2b2296 [fuzz] V3_MAX_VSIZE and effective ancestor/descendant size limits (glozow)
a29f1df289 [policy] restrict all v3 transactions to 10kvB (glozow)
d578e2e354 [policy] explicitly require non-v3 for CPFP carve out (glozow)

Pull request description:

  Opening for discussion / conceptual review.

  We like the idea of a smaller maximum transaction size because:
  - It lowers potential replacement cost (i.e. harder to do Rule 3 pinning via gigantic transaction)
  - They are easier to bin-pack in block template production
  - They equate to a tighter memory limit in data structures that are bounded by a number of transactions (e.g. orphanage and vExtraTxnForCompact). For example, the current memory bounds for orphanage is 100KvB * 100 = 40MB, and guaranteeing 1 tx per peer would require reserving a pretty large space.

  History for `MAX_STANDARD_TX_WEIGHT=100KvB` (copied from https://github.com/bitcoin/bitcoin/pull/29873#issuecomment-2115459510):
  - 2010-09-13 In 3df62878c3 satoshi added a 100kB (MAX_BLOCK_SIZE_GEN/5 with MBS_GEN = MAX_BLOCK_SIZE/2) limit on new transactions in CreateTransaction()
  - 2013-02-04 https://github.com/bitcoin/bitcoin/pull/2273 In gavin gave that constant a name, and made it apply to transaction relay as well

  Lowering `MAX_STANDARD_TX_WEIGHT` for all txns is not being proposed, as there are existing apps/protocols that rely on large transactions. However, it's been brought up that we should consider this for TRUCs (which is especially designed to avoid Rule 3 pinning).

  This reduction should be ok because using nVersion=3 isn't standard yet, so this wouldn't break somebody's existing use case. If we find that this is too small, we can always increase it later. Decreasing would be much more difficult.
  ~[Expected size of a commitment transaction](https://github.com/lightning/bolts/blob/master/03-transactions.md#expected-weight-of-the-commitment-transaction) is within (900 + 172 * 483 + 224) / 4 = 21050vB~ EDIT: this is incorrect, but perhaps not something that should affect how we choose this number.

ACKs for top commit:
  sdaftuar:
    ACK 154b2b2296
  achow101:
    ACK 154b2b2296
  instagibbs:
    ACK 154b2b2296
  t-bast:
    ACK 154b2b2296
  murchandamus:
    crACK 154b2b2296

Tree-SHA512: 89392a460908a8ea9f547d90e00f5181de0eaa9d2c4f2766140a91294ade3229b3d181833cad9afc93a0d0e8c4b96ee2f5aeda7c50ad7e6f3a8320b9e0c5ae97
2024-05-23 11:54:18 -04:00
Ava Chow
e163d864d3
Merge bitcoin/bitcoin#30118: test: improve robustness of connect_nodes()
6629d1d0f8 test: improve robustness of connect_nodes() (furszy)

Pull request description:

  Decoupled from #27837 because this can help other too, found it investigating a CI failure https://cirrus-ci.com/task/5805115213348864?logs=ci#L3200.

  The `connect_nodes` function in the test framework relies on a stable number of peer
  connections to verify that the new connection between the nodes is successfully established.
  This approach is fragile, as any of the peers involved in the process can drop, lose, or
  create a connection at any step, causing subsequent `wait_until` checks to stall indefinitely
  even when the peers in question were connected successfully.

  This commit improves the situation by using the nodes' subversion and the connection
  direction (inbound/outbound) to identify the exact peer connection and perform the
  checks exclusively on it.

ACKs for top commit:
  stratospher:
    reACK 6629d1d.
  achow101:
    ACK 6629d1d0f8
  maflcko:
    utACK 6629d1d0f8
  AngusP:
    re-ACK 6629d1d0f8

Tree-SHA512: 5f345c0ce49ea81b643e97c5cffd133e182838752c27592fcdeac14ad10919fb4b7ff38e289e42a7c3c638a170bd0d0b7a9cd493898997a2082a7b7ceef4aeeb
2024-05-23 10:00:00 -04:00
glozow
83ae1bac9d
Merge bitcoin/bitcoin#30062: net: add ASMap info in getrawaddrman RPC
1e54d61c46 test: add coverage for `mapped_as` from `getrawaddrman` (brunoerg)
8c2714907d net: rpc: return peer's mapped AS in getrawaddrman (brunoerg)

Pull request description:

  This PR adds two new fields in `getrawaddrman` RPC: "mapped_as" and "source_mapped_as". These fields are used to return the ASN (Autonomous System Number) mapped to the peer and its source. With these informations we can have a better view of the bucketing logic with ASMap specially in projects like [addrman-observer](https://github.com/0xb10c/addrman-observer).

ACKs for top commit:
  fjahr:
    Code review ACK 1e54d61c46
  virtu:
    ACK [1e54d61](1e54d61c46)
  0xB10C:
    ACK 1e54d61c46
  glozow:
    ACK 1e54d61c46

Tree-SHA512: af86bcc7a2e69bebd3fa9eaa2e527e0758c44c0a958de7292514d5f99f8f01f5df3bae11400451268e0255f738ff3acccc77f48fe129937512f1e9d9963c4c5e
2024-05-23 12:08:36 +01:00
Hernan Marino
df6dc2aaae test: Assumeutxo: snapshots with less work should not be loaded 2024-05-22 21:06:06 -03:00
brunoerg
1e54d61c46 test: add coverage for mapped_as from getrawaddrman
Test addresses are being mapped according to the ASMap
file provided properly. Compare the result of the `getrawaddrman`
RPC with the result from the ASMap Health Check.
2024-05-22 07:58:08 -03:00
Ava Chow
6c13b1375f
Merge bitcoin/bitcoin#29421: net: make the list of known message types a compile time constant
b3efb48673 protocol: make message types constexpr (Vasil Dimov)
2fa9de06c2 net: make the list of known message types a compile time constant (Vasil Dimov)

Pull request description:

  Turn the `std::vector` to `std::array` because it is cheaper and allows us to have the number of the messages as a compile time constant: `ALL_NET_MESSAGE_TYPES.size()` which can be used in future code to build other `std::array`s with that size.

  ---

  This change is part of https://github.com/bitcoin/bitcoin/pull/29418 but it makes sense on its own and would be good to have it, regardless of the fate of https://github.com/bitcoin/bitcoin/pull/29418. Also, if this is merged, that would reduce the size of https://github.com/bitcoin/bitcoin/pull/29418, thus the current standalone PR.

ACKs for top commit:
  achow101:
    ACK b3efb48673
  jonatack:
    ACK b3efb48673
  maflcko:
    utACK b3efb48673 🎊
  willcl-ark:
    ACK b3efb48673

Tree-SHA512: 6d3860c138c64514ebab13d97ea67893e2d346dfac30a48c3d9bc769a1970407375ea4170afdb522411ced306a14a9af4eede99e964d1fb1ea3efff5d5eb57af
2024-05-21 13:59:33 -04:00
glozow
a29f1df289 [policy] restrict all v3 transactions to 10kvB 2024-05-21 15:06:55 +01:00
furszy
6629d1d0f8
test: improve robustness of connect_nodes()
The 'connect_nodes' function in the test framework relies
on a stable number of peer connections to verify the new
connection between the nodes is successfully established.
This approach is fragile, as any of the peers involved in
the process can drop, lose, or create a connection at any
step, causing subsequent 'wait_until' checks to stall
indefinitely even when the peers in question are connected
successfully.

This commit improves the situation by using the nodes' subversion
and the connection direction (inbound/outbound) to identify the
exact peer connection and perform the checks exclusively on it.
2024-05-21 10:58:44 -03:00
Fabian Jahr
542e13b293
rpc: Enhance metadata of the dumptxoutset output
The following data is added:
- A newly introduced utxo set magic
- A version number
- The network magic
- The block height
2024-05-21 13:57:09 +02:00
Fabian Jahr
c14ed7f384
assumeutxo: Add test for changed coin size value 2024-05-21 13:38:09 +02:00
Fabian Jahr
de95953d87
rpc: Optimize serialization disk space of dumptxoutset
Co-authored-by: Aurèle Oulès <aurele@oules.com>
Co-authored-by: TheCharlatan <seb.kung@gmail.com>
2024-05-21 13:38:07 +02:00
merge-script
5acdc2b97d
Merge bitcoin/bitcoin#26606: wallet: Implement independent BDB parser
d51fbab4b3 wallet, test: Be able to always swap BDB endianness (Ava Chow)
0b753156ce test: Test bdb_ro dump of wallet without reset LSNs (Ava Chow)
c1984f1282 test: Test dumping dbs with overflow pages (Ava Chow)
fd7b16e391 test: Test dumps of other endian BDB files (Ava Chow)
6ace3e953f bdb: Be able to make byteswapped databases (Ava Chow)
d9878903fb Error if LSNs are not reset (Ava Chow)
4d7a3ae78e Berkeley RO Database fuzz test (TheCharlatan)
3568dce9e9 tests: Add BerkeleyRO to db prefix tests (Ava Chow)
70cfbfdadf wallettool: Optionally use BERKELEY_RO as format when dumping BDB wallets (Ava Chow)
dd57713f6e Add MakeBerkeleyRODatabase (Ava Chow)
6e50bee67d Implement handling of other endianness in BerkeleyRODatabase (Ava Chow)
cdd61c9cc1 wallet: implement independent BDB deserializer in BerkeleyRODatabase (Ava Chow)
ecba230979 wallet: implement BerkeleyRODatabase::Backup (Ava Chow)
0c8e728476 wallet: implement BerkeleyROBatch (Ava Chow)
756ff9b478 wallet: add dummy BerkeleyRODatabase and BerkeleyROBatch classes (Ava Chow)
ca18aea5c4 Add AutoFile::seek and tell (Ava Chow)

Pull request description:

  Split from #26596

  This PR adds `BerkeleyRODatabase` which is an independent implementation of a BDB file parser. It provides read only access to a BDB file, and can therefore be used as a read only database backend for wallets. This will be used for dumping legacy wallet records and migrating legacy wallets without the need for BDB itself.

  Wallettool's `dump` command is changed to use `BerkeleyRODatabase` instead of `BerkeleyDatabase` (and `CWallet` itself) to demonstrate that this parser works and to test it against the existing wallettool functional tests.

ACKs for top commit:
  josibake:
    reACK d51fbab4b3
  TheCharlatan:
    Re-ACK d51fbab4b3
  furszy:
    reACK d51fbab4b3
  laanwj:
    re-ACK d51fbab4b3
  theStack:
    ACK d51fbab4b3

Tree-SHA512: 1e7b97edf223b2974eed2e9eac1179fc82bb6359e0a66b7d2a0c8b9fa515eae9ea036f1edf7c76cdab2e75ad994962b134b41056ccfbc33b8d54f0859e86657b
2024-05-21 10:05:09 +01:00
glozow
ecd23656db
Merge bitcoin/bitcoin#30133: test: remove unneeded -maxorphantx=1000 settings
8950053636 test: remove unneeded `-maxorphantx=1000` settings (Sebastian Falbesoner)

Pull request description:

  It's unclear what the motivation for increasing the orphan pool is here, and it seems that this not needed at all. None of these tests involve orphan transactions explicitly, and if they would occur occasionally, there is no good reason to prefer a value of 1000 over the default of 100 (see DEFAULT_MAX_ORPHAN_TRANSACTIONS).

ACKs for top commit:
  maflcko:
    utACK 8950053636
  edilmedeiros:
    Tested ACK 8950053636
  AngusP:
    tACK 8950053636
  glozow:
    ACK 8950053636 From skimming the tests, it appears that none of these need a larger `-maxorphantx`.

Tree-SHA512: 81d4a4fb2ea92b97119f21cbc6c4b1240d863269932e6adf4982aead9726f20652523a4707add3ad38eb332d4452de41de6735265f22e62298f3b4b45de75a57
2024-05-20 09:47:31 +01:00
glozow
063bb2fbb5
Merge bitcoin/bitcoin#30066: test: add conflicting topology test case
9365baa489 test: add conflicting topology test case (Greg Sanders)

Pull request description:

  We want to ensure that even if topologies
  that are acceptable are relaxed, like
  removing package-not-child-with-unconfirmed-parents, that we don't end up accepting packages we shouldn't.

ACKs for top commit:
  glozow:
    reACK 9365baa489
  rkrux:
    reACK [9365baa](9365baa489)

Tree-SHA512: d58661064ca099ac0447c331a5020c74c0cdfe24259aa875592805bbd63de1bf23aa7ced9ff485fef90dc0602fcb997e631aaf1aa2e9805d2cf5f0e5c9b2f0e2
2024-05-20 09:27:37 +01:00
Michael Dietz
d93b794709
tests: improve wallet multisig descriptor test and docs
It is best to store all key origin information
(master key fingerprint and all derivation steps)
in the multisig descriptor. Being explicit with
this information should be beneficial if this approach
is used with other wallets/signers (whether hardware
or software). There is no harm including all of this
with xpubs (if anything it simplifies the test code)
and makes this example/docs more complete and safer
incase it is referenced by others.
2024-05-19 19:59:38 -05:00
Sebastian Falbesoner
8950053636 test: remove unneeded -maxorphantx=1000 settings
It's unclear what the motivation for increasing the orphan pool is, and
it seems that this not needed at all. None of these tests involve orphan
transactions explicitly, and if they would occur occasionally, there is
no good reason to prefer a value of 1000 over the default of 100 (see
DEFAULT_MAX_ORPHAN_TRANSACTIONS).
2024-05-17 22:38:59 +02:00
Ava Chow
4877fcdb42
Merge bitcoin/bitcoin#30048: crypto: add NUMS_H const
9408a04e42 tests, fuzz: use new NUMS_H const (josibake)
b946f8a4c5 crypto: add NUMS_H const (josibake)

Pull request description:

  Broken out from #28122

  ---

  [BIP341](https://github.com/bitcoin/bips/blob/master/bip-0341.mediawiki#constructing-and-spending-taproot-outputs) defines a NUMS point `H` as *H = lift_x(0x50929b74c1a04954b78b4b6035e97a5e078a5a0f28ec96d547bfee9ace803ac0)* which is [constructed](11af7015de/src/modules/rangeproof/main_impl.h (L16)) by taking the hash of the standard uncompressed encoding of the [secp256k1](https://www.secg.org/sec2-v2.pdf) base point G as X coordinate."

  Add this as a constant so it can be used in our codebase. My primary motivation is BIP352 specifies a special case for when taproot spends use `H` as the internal key, but outside of BIP352 it seems generally useful to have `H` in the codebase, for testing or other use cases.

ACKs for top commit:
  paplorinc:
    re-ACK 9408a04e42
  achow101:
    ACK 9408a04e42
  theStack:
    Code-review ACK 9408a04e42

Tree-SHA512: ad84492f5d635c0cb05bd82546079ded7e5138e95361f20d8285a9ad6e69c10ee2cc3fe46e16b46ef03c4253c8bee1051911c6b91264c90c3b1ad33a824bff4b
2024-05-17 14:10:51 -04:00