diff options
author | Andrew Chow <github@achow101.com> | 2022-10-13 13:24:37 -0400 |
---|---|---|
committer | Andrew Chow <github@achow101.com> | 2022-10-13 13:31:54 -0400 |
commit | 885366c67addd86bf06629919aaa6f74a76f44f4 (patch) | |
tree | 33a4783ec25bd9754bf28bcfb1fa737ca3d2d20f /src/wallet/wallet.cpp | |
parent | 3f385c912ea351ab90ba09f8793b499e91a36d74 (diff) | |
parent | e2e4c2969ba753a94587985582123a596f57067b (diff) |
Merge bitcoin/bitcoin#26133: [24.x] Backports for rc2
e2e4c2969ba753a94587985582123a596f57067b tests: Test that PSBT_OUT_TAP_TREE is included correctly (Andrew Chow)
4d42c3a2401c63084bf94433609240daa366753e psbt: Only include m_tap_tree if it has scripts (Andrew Chow)
d810fde8ea64b71567f8b50895ac76bcb7afbfbc psbt: Change m_tap_tree to store just the tuples (Andrew Chow)
a9419eff0cc21d21755165e66cc0e496aab65650 tests: Test that PSBT_OUT_TAP_TREE is combined correctly (Andrew Chow)
4abd2ab18e26999e2dafcb15a58a7979de90af34 psbt: Fix merging of m_tap_tree (Andrew Chow)
1390c96c8e9c56e0d8348ef056f18e3e04f0f63f [BugFix]: Do not allow deserializing PSBT with empty PSBT_OUT_TAP_TREE (Jeremy Rubin)
9b438f06ecfc3fb21d2c5219b71fb4aa77875b8c refactor: revert m_next_resend to not be std::atomic (stickies-v)
43ced0b436b05ed12489a99bbac89f3b4c9ac035 wallet: only update m_next_resend when actually resending (stickies-v)
fc8f2bfa3abc284ae3c1127fcf36535603ecc891 refactor: carve out tx resend timer logic into ShouldResend (stickies-v)
a6fb674f966df27c09dc3d2b81040ce2965b2d7e refactor: remove unused locks for ResubmitWalletTransactions (stickies-v)
5ad82a09b409d416236092062a4201e238dfd68b index: Improve BaseIndex::BlockUntilSyncedToCurrentChain reliability (Ryan Ofsky)
997faf6b6c774dc87ae730f2f08d7f4f08bdfd04 contrib: Fix capture_output in getcoins.py (willcl-ark)
7e0bcfbfef61cb688bc92a96003c1219cad67935 p2p: ProcessHeadersMessage(): fix received_new_header (Larry Ruane)
c97d924880eaad136c5f7776f05bf887657ccca7 Correct sanity-checking script_size calculation (Pieter Wuille)
da6fba6fe785ba2c54f9b88dd5b1b4ceb02c18c9 docs: Add 371 to bips.md (Andrew Chow)
Pull request description:
Will collect backports for rc2 as they become available. Currently:
* https://github.com/bitcoin/bitcoin/pull/25858
* https://github.com/bitcoin/bitcoin/pull/26124
* https://github.com/bitcoin/bitcoin/pull/26149
* https://github.com/bitcoin/bitcoin/pull/26172
* https://github.com/bitcoin/bitcoin/pull/26205
* https://github.com/bitcoin/bitcoin/pull/26212
* https://github.com/bitcoin/bitcoin/pull/26215
ACKs for top commit:
dergoegge:
ACK e2e4c2969ba753a94587985582123a596f57067b
achow101:
ACK e2e4c2969ba753a94587985582123a596f57067b
instagibbs:
ACK https://github.com/bitcoin/bitcoin/pull/26133/commits/e2e4c2969ba753a94587985582123a596f57067b
Tree-SHA512: b6374fe202561057dbe1430d4c40f06f721eb568f91e7275ae1ee7747edf780ce64620382d13ecc4b9571d931dc25d226af8284987cf35ff6a6182c5f64eb10c
Diffstat (limited to 'src/wallet/wallet.cpp')
-rw-r--r-- | src/wallet/wallet.cpp | 40 |
1 files changed, 24 insertions, 16 deletions
diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index 5889de2e36..ac7bf46a14 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -21,6 +21,7 @@ #include <primitives/block.h> #include <primitives/transaction.h> #include <psbt.h> +#include <random.h> #include <script/descriptor.h> #include <script/script.h> #include <script/signingprovider.h> @@ -1903,11 +1904,29 @@ std::set<uint256> CWallet::GetTxConflicts(const CWalletTx& wtx) const return result; } +bool CWallet::ShouldResend() const +{ + // Don't attempt to resubmit if the wallet is configured to not broadcast + if (!fBroadcastTransactions) return false; + + // During reindex, importing and IBD, old wallet transactions become + // unconfirmed. Don't resend them as that would spam other nodes. + // We only allow forcing mempool submission when not relaying to avoid this spam. + if (!chain().isReadyToBroadcast()) return false; + + // Do this infrequently and randomly to avoid giving away + // that these are our transactions. + if (GetTime() < m_next_resend) return false; + + return true; +} + +int64_t CWallet::GetDefaultNextResend() { return GetTime() + (12 * 60 * 60) + GetRand(24 * 60 * 60); } + // Resubmit transactions from the wallet to the mempool, optionally asking the // mempool to relay them. On startup, we will do this for all unconfirmed // transactions but will not ask the mempool to relay them. We do this on startup -// to ensure that our own mempool is aware of our transactions, and to also -// initialize m_next_resend so that the actual rebroadcast is scheduled. There +// to ensure that our own mempool is aware of our transactions. There // is a privacy side effect here as not broadcasting on startup also means that we won't // inform the world of our wallet's state, particularly if the wallet (or node) is not // yet synced. @@ -1934,17 +1953,6 @@ void CWallet::ResubmitWalletTransactions(bool relay, bool force) // even if forcing. if (!fBroadcastTransactions) return; - // During reindex, importing and IBD, old wallet transactions become - // unconfirmed. Don't resend them as that would spam other nodes. - // We only allow forcing mempool submission when not relaying to avoid this spam. - if (!force && relay && !chain().isReadyToBroadcast()) return; - - // Do this infrequently and randomly to avoid giving away - // that these are our transactions. - if (!force && GetTime() < m_next_resend) return; - // resend 12-36 hours from now, ~1 day on average. - m_next_resend = GetTime() + (12 * 60 * 60) + GetRand(24 * 60 * 60); - int submitted_tx_count = 0; { // cs_wallet scope @@ -1979,7 +1987,9 @@ void CWallet::ResubmitWalletTransactions(bool relay, bool force) void MaybeResendWalletTxs(WalletContext& context) { for (const std::shared_ptr<CWallet>& pwallet : GetWallets(context)) { + if (!pwallet->ShouldResend()) continue; pwallet->ResubmitWalletTransactions(/*relay=*/true, /*force=*/false); + pwallet->SetNextResend(); } } @@ -3196,14 +3206,12 @@ bool CWallet::UpgradeWallet(int version, bilingual_str& error) void CWallet::postInitProcess() { - LOCK(cs_wallet); - // Add wallet transactions that aren't already in a block to mempool // Do this here as mempool requires genesis block to be loaded ResubmitWalletTransactions(/*relay=*/false, /*force=*/true); // Update wallet transactions with current mempool transactions. - chain().requestMempoolTransactions(*this); + WITH_LOCK(cs_wallet, chain().requestMempoolTransactions(*this)); } bool CWallet::BackupWallet(const std::string& strDest) const |