Commit Graph

22862 Commits

Author SHA1 Message Date
Andrew Chow
ccc72fecd7 wallet: Be able to unlock the wallet for migration
Since migration reloads the wallet, the wallet will always be locked
unless the passphrase is given. migratewallet can now take the
passphrase in order to unlock the wallet for migration.

Github-Pull: #26595
Rebased-From: 7fd125b27d
2023-02-27 14:14:14 +00:00
Andrew Chow
50dd8b13df rpc: Allow users to specify wallet name for migratewallet
Github-Pull: #26595
Rebased-From: 6bdbc5ff59
2023-02-27 14:13:46 +00:00
Andrew Chow
648b06256d wallet: Allow MigrateLegacyToDescriptor to take a wallet name
An overload of MigrateLegacyToDescriptor is added which takes the wallet
name. The original that took a wallet pointer is still available, it
just gets the name, closes the wallet, and calls the new overload.

Github-Pull: #26595
Reabsed-From: dbfa345403
2023-02-27 14:13:13 +00:00
Vasil Dimov
ab3bd457cd i2p: use consistent number of tunnels with i2pd and Java I2P
The default number of tunnels in the Java implementation is 2 and in the
C++ i2pd it is 5. Pick a mid-number (3) and explicitly set it in order
to get a consistent behavior with both routers. Do this for persistent
sessions which are created once at startup and can be used to open up
to ~10 outbound connections and can accept up to ~125 incoming
connections. Transient sessions already set number of tunnels to 1.

Suggested in:
https://github.com/bitcoin/bitcoin/issues/26754#issuecomment-1367356129
https://geti2p.net/en/docs/api/samv3

Alleviates: https://github.com/bitcoin/bitcoin/issues/26754

Github-Pull: #26837
Rebased-From: 3c1de032de
2023-02-27 14:01:24 +00:00
Vasil Dimov
29cdf42226 i2p: lower the number of tunnels for transient sessions
This will lower the load on the I2P network. Since we use one transient
session for connecting to just one peer, a higher number of tunnels is
unnecessary.

This was suggested in:
https://github.com/bitcoin/bitcoin/issues/26754#issuecomment-1365449401
https://github.com/bitcoin/bitcoin/issues/26754#issuecomment-1367356129

The options are documented in:
https://geti2p.net/en/docs/protocol/i2cp#options

A tunnel is unidirectional, so even if we make a single outbound
connection we still need an inbound tunnel to receive the messages sent
to us over that connection.

Alleviates: https://github.com/bitcoin/bitcoin/issues/26754

Github-Pull: #26837
Rebased-From: 801b405f85
2023-02-27 14:00:28 +00:00
Vasil Dimov
5027e93b6a i2p: reuse created I2P sessions if not used
In the case of `i2pacceptincoming=0` we use transient addresses
(destinations) for ourselves for each outbound connection. It may
happen that we
* create the session (and thus our address/destination too)
* fail to connect to the particular peer (e.g. if they are offline)
* dispose the unused session.

This puts unnecessary load on the I2P network because session creation
is not cheap. Is exaggerated if `onlynet=i2p` is used in which case we
will be trying to connect to I2P peers more often.

To help with this, save the created but unused sessions and pick them
later instead of creating new ones.

Alleviates: https://github.com/bitcoin/bitcoin/issues/26754

Github-Pull: #26837
Rebased-From: b906b64eb7
2023-02-27 13:59:51 +00:00
Matthew Zipkin
a62c541ae8 wallet: reuse change dest when recreating TX with avoidpartialspends
Github-Pull: #27053
Rebased-From: 14b4921a91
2023-02-22 09:12:50 +00:00
John Moffett
64e7db6f4f Zero out wallet master key upon lock
When an encrypted wallet is locked (for instance via the
RPC `walletlock`), the docs indicate that the key is
removed from memory. However, the vector (with a secure
allocator) is merely cleared. This allows the key to persist
indefinitely in memory. Instead, manually fill the bytes with
zeroes before clearing.

Github-Pull: #27080
Rebased-From: 3a11adc700
2023-02-20 17:15:38 +00:00
John Moffett
b7e242ecb3 Correctly limit overview transaction list
The way that the main overview page limits the number
of transactions displayed (currently 5) is not
an appropriate use of Qt. If it's run with a DEBUG
build of Qt, it'll result in a segfault in certain
relatively common situations. Instead of artificially
limiting the rowCount() in the subclassed proxy
filter, we hide/unhide the rows in the displaying
QListView upon any changes in the sorted proxy filter.

Github-Pull: bitcoin-core/gui/pull/704
Rebased-From: 08209c039f
2023-02-20 17:15:38 +00:00
MarcoFalke
7cf73dfed5 Add missing includes to fix gcc-13 compile error
Github-Pull: #26924
Rebased-From: fadeb6b103
2023-02-20 17:15:38 +00:00
Martin Zumsande
07397cdede addrdb: Only call Serialize() once
The previous logic would call it once for serializing into the filestream,
and then again for serializing into the hasher. If AddrMan was changed
in between these calls by another thread, the resulting peers.dat would
be corrupt with non-matching checksum and data.
Fix this by using HashedSourceWriter, which writes the data
to the underlying stream and keeps track of the hash in one go.

Github-Pull: #26909
Rebased-From: 5eabb61b23
2023-02-20 17:15:37 +00:00
Martin Zumsande
91f83dbeb1 hash: add HashedSourceWriter
This class is the counterpart to CHashVerifier, in that it
writes data to an underlying source stream,
while keeping a hash of the written data.

Github-Pull: #26909
Rebased-From: da6c7aeca3
2023-02-20 17:15:37 +00:00
John Moffett
5c824ac5e1 For feebump, ignore abandoned descendant spends
To be eligible for fee-bumping, a transaction must not have any
of its outputs (eg - change) spent in other unconfirmed transactions
in the wallet. However, this check should not apply to abandoned
transactions.

A new test case is added to cover this case.

Github-Pull: #26675
Rebased-From: f9ce0eadf4
2023-02-20 17:15:37 +00:00
Andrew Chow
428dcd51e6 wallet: Skip rescanning if wallet is more recent than tip
If a wallet has key birthdates that are more recent than the currrent
chain tip, or a bestblock height higher than the current tip, we should
not attempt to rescan as there is nothing to scan for.

Github-Pull: #26679
Rebased-From: 3784009534
2023-02-20 17:15:37 +00:00
Sebastian Falbesoner
342abfb3f4 wallet: fully migrate address book entries for watchonly/solvable wallets
Currently `migratewallet` migrates the address book (i.e. labels and
purposes) for watchonly and solvable wallets only in RAM, but doesn't
persist them on disk. Fix this by adding another loop for both of the
special wallet types after which writes the corresponding NAME and
PURPOSE entries to the database in a single batch.

Github-Pull: #26761
Rebased-From: d5f4ae7fac
2023-02-20 17:15:36 +00:00
fanquake
2b87e90585 Merge bitcoin/bitcoin#26457: [24.x] backport rpc: skip getpeerinfo for a peer without CNodeStateStats
e72313e6b3 rpc: Require NodeStateStats object in getpeerinfo (Martin Zumsande)

Pull request description:

  Backports #26515.

ACKs for top commit:
  fanquake:
    ACK e72313e6b3

Tree-SHA512: 28e885ea299fe8a3a7538628d413c434bc42c251a2c1ae238bca0652709f5bd781eb157675171ab538f6e2f6f720f1c184200ac3857f6c78f48858949eed49da
2023-01-20 11:34:12 +00:00
Martin Zumsande
e72313e6b3 rpc: Require NodeStateStats object in getpeerinfo
There is no situation in which CNodeStateStats could be
missing for a legitimate reason - this can only happen if
there is a race condition between peer disconnection and
the getpeerinfo call, in which case the disconnected peer
doesn't need to be included in the response.

Github-Pull: bitcoin#26515
Rebased-From: 6fefd49
2023-01-11 09:18:32 -08:00
Andrew Chow
0662105e88 qt: Load PSBTs using istreambuf_iterator rather than istream_iterator
istream_iterator eats whitespace charactesr which causes parsing
failures for PSBTs that contain the bytes corresponding to those
characters.

Github-Pull: bitcoin-core/gui#687
Rebased-From: bb5ea1d9a9
2022-12-21 09:52:40 +01:00
furszy
8b726bf556 test: Coin Selection, duplicated preset inputs selection
This exercises the bug inside CoinsResult::Erase that
ends up on (1) a wallet crash or (2) a created and
broadcasted tx that contains a reduced recipient's amount.

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

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

Which, combined with the SFFO option, makes the wallet
incorrectly reduce the recipient's amount by the difference
between the original target and the wrongly counted inputs.
Which means, a created and relayed tx sending less coins to
the destination than what the user inputted.

Github-Pull: #26560
Rebased-From: cf79384697
2022-12-05 17:43:46 +00:00
furszy
9d73176d00 test: wallet, coverage for CoinsResult::Erase function
Github-Pull: #26560
Rebased-From: 341ba7ffd8
2022-12-05 17:43:31 +00:00
furszy
195f0dfd0e wallet: bugfix, 'CoinsResult::Erase' is erasing only one output of the set
The loop break shouldn't have being there.

Github-Pull: #26560
Rebased-From: f930aefff9
2022-12-05 17:40:54 +00:00
dergoegge
c8426706de [net processing] Assume that TxRelay::m_tx_inventory_to_send is empty pre-verack
This commit documents our assumption about
TxRelay::m_tx_inventory_to_send being empty prior to version handshake
completion.

The added Assume acts as testing oracle for our fuzzing tests to
potentially detect if the assumption is violated.

Github-Pull: #26569
Rebased-From: ce63fca13e
2022-12-02 16:04:13 +00:00
dergoegge
e15b306017 [net processing] Ensure transaction announcements are only queued for fully connected peers
Github-Pull: #26569
Rebased-From: 845e3a34c4
2022-12-02 15:58:24 +00:00
Andrew Chow
95fded1069 wallet: Explicitly say migratewallet on encrypted wallets is unsupported
Github-Pull: #26594
Rebased-From: 5e65a216d1
2022-12-01 10:22:14 +00:00
Andrew Chow
7a97a56ffb wallet: Avoid null pointer deref when cleaning up migratewallet
If migratewallet fails, we do a cleanup which removes the watchonly and
solvables wallets if they were created. However, if they were not, their
pointers are nullptr and we don't check for that, which causes a
segfault during the cleanup. So check that they aren't nullptr before
cleaning them up.

Github-Pull: #26594
Rebased-From: 86ef7b3c7b
2022-12-01 10:21:00 +00:00
John Moffett
39af5f2164 Fixes bitcoin#26490 by preventing notifications
MacOS 13 sends a window focus change notification after the main
window has been destroyed but before the QTApplication has been
destroyed. This results in the menu bar receiving a notification
despite it no longer existing. The solution is to pass the main
window as context when subscribing to the notifications. Qt
automatically unsubscribes to notifications if the sender OR
context is destroyed.

Github-Pull: bitcoin-core/gui#680
Rebased-From: 8a5014cd8a
2022-11-17 14:43:34 +00:00
Hennadii Stepanov
7948fdd060 qt: 24.0rc4 translations update 2022-11-09 11:22:59 +00:00
Sebastian Falbesoner
42c74a0a4c rpc: doc: add missing option "bech32m" for change_type parameters
Affects the help of the `fundrawtransaction`, `send` and
`walletcratefundedpsbt` RPCs.

Github-Pull: #26449
Rebased-From: c3b1fe59db
2022-11-07 10:32:10 +00:00
Andrew Chow
2159676b6e psbt: Include output pubkey in additional pubkeys to sign
In addition to the pubkeys in hd_keypaths and tap_bip32_keypaths, also
see if the descriptor can produce a SigningProvider for the output
pubkey.

Also slightly refactors this area to reduce code duplication.

Github-Pull: #26418
Rebased-From: 8781a1b6bb
2022-11-04 15:55:48 +00:00
Andrew Chow
754eefd21c sign: Fill in taproot pubkey info for all script path sigs
Taproot pubkey info was not being added for multi_a signing. The filling
of this info is moved into the common function CreateTaprootScriptSig so
that any signing of taproot scripts will include the pubkey info.

Github-Pull: #26418
Rebased-From: 323890d0d7
2022-11-04 15:55:16 +00:00
fanquake
067dc42b79 Merge bitcoin/bitcoin#26434: [24.x] [gui] Bugfix: Check for readlink buffer overflow and handle gracefully
e049fd76f0 Bugfix: Check for readlink buffer overflow and handle gracefully (Luke Dashjr)

Pull request description:

  Identical commit taken as-is from https://github.com/bitcoin/bitcoin/pull/25548 for backport

ACKs for top commit:
  hebasto:
    ACK e049fd76f0

Tree-SHA512: 37e63d570de898187c1bc8dd311c299c527adea51faa08aa6a3923bdb9390e3263902ace3d52a1cfc34ac2ba84e9358961574f886be1f64b5749a62e3c50ad57
2022-11-01 13:31:40 +00:00
fanquake
2e8880abc0 Merge bitcoin/bitcoin#26410: [24.x] rc3 backports
d5701900fc rpc: make `address` field optional (w0xlt)
e4b8c9b2bf rpc: add non-regression test about deriveaddresses crash when index is 2147483647 (muxator)
bf2bf73bcb rpc: fix crash in deriveaddresses when derivation index is 2147483647 (muxator)
b04f5f9608 test: Test for out of bounds vout in sendall (Andrew Chow)
dedee6af57 wallet: Check utxo prevout index out of bounds in sendall (Andrew Chow)
931db785ee test: Test that sendall works with watchonly spending specific utxos (Andrew Chow)
bbe864a13a wallet: Correctly check ismine for sendall (Andrew Chow)
4b7d30d026 Adjust `.tx/config` for new Transifex CLI (Hennadii Stepanov)

Pull request description:

  Backports:
  * https://github.com/bitcoin/bitcoin/pull/26321
  * https://github.com/bitcoin/bitcoin/pull/26344
  * https://github.com/bitcoin/bitcoin/pull/26275
  * https://github.com/bitcoin/bitcoin/pull/26349

ACKs for top commit:
  instagibbs:
    ACK d5701900fc
  hebasto:
    ACK d5701900fc, I've cherry-picked commits manually and got zero diff with this PR branch.

Tree-SHA512: dad64f4074b4f06d666c0f2d804eda92df241bcce0a49c28486311a151f2e9d46b75e1bce02de570dcc85957c9ce936debb2a4faa045800c9757c6c495115d7c
2022-10-31 15:04:41 +00:00
fanquake
a8f014b342 Merge bitcoin/bitcoin#26379: qt: 24.0rc3 translations update
33a61018b2 qt: 24.0rc3 translations update (Hennadii Stepanov)

Pull request description:

  This PR pulls the recent translations from the [Transifex.com](https://www.transifex.com/bitcoin/bitcoin) using the [`bitcoin-maintainer-tools/update-translations.py`](https://github.com/bitcoin-core/bitcoin-maintainer-tools/blob/main/update-translations.py) tool.

  According to our [Release Process docs](https://github.com/bitcoin/bitcoin/blob/master/doc/release-process.md#before-every-release-candidate), it is supposed to be merged (just) before `v24.0rc3` tagging.

  Will keep this PR updated regularly until merging.

Top commit has no ACKs.

Tree-SHA512: ab8c44961356333cb60e102f54852b9721fb0d4a9dbe719c049007f522218391e29898c698b7e142512f98d21ef4c6b500b00c6ce107600690421ab2ade1cc70
2022-10-31 14:59:00 +00:00
Hennadii Stepanov
33a61018b2 qt: 24.0rc3 translations update 2022-10-30 19:28:56 +00:00
w0xlt
d5701900fc rpc: make address field optional
Github-Pull: #26349
Rebased-From: eb679a7896
2022-10-28 18:01:36 +08:00
muxator
bf2bf73bcb rpc: fix crash in deriveaddresses when derivation index is 2147483647
2147483647 is the maximum positive value of a signed int32, and - currently -
the maximum value that the deriveaddresses bitcoin RPC call accepts as
derivation index due to its input validation routines.

Before this change, when the derivation index (and thus range_end) reached
std::numeric_limits<int_32_t>::max(), the "i" variable in the for cycle (which
is declared as int, and as such 32 bits in size on most platforms) would be
incremented at the end of the first iteration and then warp back to
-2147483648. This caused SIGABRT in bitcoind and a core dump.

This change assigns "i" an explicit size of 64 bits on every platform,
sidestepping the problem.

Fixes #26274.

Github-Pull: #26275
Rebased-From: addf9d6502
2022-10-28 18:00:37 +08:00
Andrew Chow
dedee6af57 wallet: Check utxo prevout index out of bounds in sendall
Github-Pull: #26344
Rebased-From: b132c85650
2022-10-28 17:59:30 +08:00
Andrew Chow
bbe864a13a wallet: Correctly check ismine for sendall
sendall should be using a bitwise AND for sendall's IsMine check rather
than an equality as IsMine will never return ISMINE_ALL.

Github-Pull: #26344
Rebased-From: 6bcd7e2a3b
2022-10-28 17:58:28 +08:00
dergoegge
e23def8fcc [net processing] Handle IsContinuationOfLowWorkHeadersSync return value correctly when new headers sync is started 2022-10-24 15:41:35 +01:00
Andrew Chow
4d42c3a240 psbt: Only include m_tap_tree if it has scripts
Github-Pull: #25858
Rebased-From: 30ff25cf37
2022-10-13 23:45:36 +08:00
Andrew Chow
d810fde8ea psbt: Change m_tap_tree to store just the tuples
Instead of having an entire TaprootBuilder which may or may not be
complete, and could potentially have future changes that interact oddly
with taproot tree tuples, have m_tap_tree be just the tuples.

When needed in other a TaprootBuilder for actual use, the tuples will be
added to a a TaprootBuilder that, in the future, can take in whatever
other data is needed as well.

Github-Pull: #25858
Rebased-From: 0577d423ad
2022-10-13 23:45:06 +08:00
Andrew Chow
4abd2ab18e psbt: Fix merging of m_tap_tree
Merging should be checking that the current PSBTOutput doesn't have a
taptree and the other one's is copied over. The original merging had
this inverted and would remove m_tap_tree if the other did not have it.

Github-Pull: #25858
Rebased-From: 7df6e1bb77
2022-10-13 23:44:01 +08:00
Jeremy Rubin
1390c96c8e [BugFix]: Do not allow deserializing PSBT with empty PSBT_OUT_TAP_TREE
Github-Pull: #25858
Rebased-From: 0652dc53b2
2022-10-13 23:43:29 +08:00
stickies-v
9b438f06ec refactor: revert m_next_resend to not be std::atomic
Since m_next_resend is now only called from MaybeResendWalletTxs()
we don't have any potential race conditions anymore, so the usage
of std::atomic can be reverted.

Github-Pull: #26205
Rebased-From: b01682a812
2022-10-13 23:38:20 +08:00
stickies-v
43ced0b436 wallet: only update m_next_resend when actually resending
We only want to relay our resubmitted transactions once every 12-36h.
By separating the timer update logic out of ResubmitWalletTransactions
and into MaybeResendWalletTxs we avoid non-relay calls (previously in
the separate ReacceptWalletTransactions function) from resetting that
timer.

Github-Pull: #26205
Rebased-From: 9245f45670
2022-10-13 23:37:36 +08:00
stickies-v
fc8f2bfa3a refactor: carve out tx resend timer logic into ShouldResend
Moves the logic of whether or not transactions should actually be
resent out of the function that's resending them. This reduces
responsibilities of ResubmitWalletTransactions and allows
carving out the updating of m_next_resend in a future commit.

Github-Pull: #26205
Rebased-From: 7fbde8af5c
2022-10-13 23:36:56 +08:00
stickies-v
a6fb674f96 refactor: remove unused locks for ResubmitWalletTransactions
ReacceptWalletTransactions is replaced by ResubmitWalletTransactions
which already handles acquiring the necessary locks internally.

Github-Pull: #26205
Rebased-From: 01f3534632
2022-10-13 23:36:13 +08:00
Ryan Ofsky
5ad82a09b4 index: Improve BaseIndex::BlockUntilSyncedToCurrentChain reliability
Since commit f08c9fb0c6 from PR
https://github.com/bitcoin/bitcoin/pull/21726, index
`BlockUntilSyncedToCurrentChain` behavior has been less reliable, and there has
also been a race condition in the `coinstatsindex_initial_sync` unit test.

It seems better for `BlockUntilSyncedToCurrentChain` to actually wait for the
last connected block to be fully processed, than to be able to return before
prune locks are set, so this switches the order of `m_best_block_index =
block;` and `UpdatePruneLock` statements in `SetBestBlockIndex` to make it more
reliable.

Also since commit f08c9fb0c6, there has been a
race condition in the `coinstatsindex_initial_sync` test. Before that commit,
the atomic index best block pointer `m_best_block_index` was updated as the
last step of `BaseIndex::BlockConnected`, so `BlockUntilSyncedToCurrentChain`
could safely be used in tests to wait for the last `BlockConnected`
notification to be finished before stopping and destroying the index. But
after that commit, calling `BlockUntilSyncedToCurrentChain` is no longer
sufficient, and there is a race between the test shutdown code which destroys
the index object and the new code introduced in that commit calling
`AllowPrune()` and `GetName()` on the index object. Reproducibility
instructions for this are in
https://github.com/bitcoin/bitcoin/issues/25365#issuecomment-1259744133

This commit fixes the `coinstatsindex_initial_sync` race condition, even though
it will require an additional change to silence TSAN false positives,
https://github.com/bitcoin/bitcoin/pull/26188, after it is fixed. So this
partially addresses but does not resolve the bug reporting TSAN errors
https://github.com/bitcoin/bitcoin/issues/25365.

There is no known race condition outside of test code currently, because the
bitcoind `Shutdown` function calls `FlushBackgroundCallbacks` not
`BlockUntilSyncedToCurrentChain` to safely shut down.

Co-authored-by: Vasil Dimov <vd@FreeBSD.org>
Co-authored-by: MacroFake <falke.marco@gmail.com>

Github-Pull: #26215
Rebased-From: 8891949bdc
2022-10-11 09:20:07 +08:00
Larry Ruane
7e0bcfbfef p2p: ProcessHeadersMessage(): fix received_new_header
Follow-up to #25717. The commit "Utilize anti-DoS headers download
strategy" changed how this bool variable is computed, so that its value
is now the opposite of what it should be.

GitHub-Pull: #26172
Rebased-From: bdcafb9133
2022-10-11 09:19:58 +08:00
Pieter Wuille
c97d924880 Correct sanity-checking script_size calculation
GitHub-Pull: #26149
Rebased-From: 648f6950cd
2022-10-11 09:19:57 +08:00