mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-01-27 19:47:30 -03:00
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
This commit is contained in:
parent
fc8f2bfa3a
commit
43ced0b436
2 changed files with 10 additions and 6 deletions
|
@ -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>
|
||||
|
@ -1920,11 +1921,12 @@ bool CWallet::ShouldResend() const
|
|||
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.
|
||||
|
@ -1951,9 +1953,6 @@ void CWallet::ResubmitWalletTransactions(bool relay, bool force)
|
|||
// even if forcing.
|
||||
if (!fBroadcastTransactions) 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
|
||||
|
@ -1990,6 +1989,7 @@ 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();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -250,7 +250,7 @@ private:
|
|||
int nWalletVersion GUARDED_BY(cs_wallet){FEATURE_BASE};
|
||||
|
||||
/** The next scheduled rebroadcast of wallet transactions. */
|
||||
std::atomic<int64_t> m_next_resend{};
|
||||
std::atomic<int64_t> m_next_resend{GetDefaultNextResend()};
|
||||
/** Whether this wallet will submit newly created transactions to the node's mempool and
|
||||
* prompt rebroadcasts (see ResendWalletTransactions()). */
|
||||
bool fBroadcastTransactions = false;
|
||||
|
@ -348,6 +348,8 @@ private:
|
|||
*/
|
||||
static bool AttachChain(const std::shared_ptr<CWallet>& wallet, interfaces::Chain& chain, const bool rescan_required, bilingual_str& error, std::vector<bilingual_str>& warnings);
|
||||
|
||||
static int64_t GetDefaultNextResend();
|
||||
|
||||
public:
|
||||
/**
|
||||
* Main wallet lock.
|
||||
|
@ -537,6 +539,8 @@ public:
|
|||
};
|
||||
ScanResult ScanForWalletTransactions(const uint256& start_block, int start_height, std::optional<int> max_height, const WalletRescanReserver& reserver, bool fUpdate, const bool save_progress);
|
||||
void transactionRemovedFromMempool(const CTransactionRef& tx, MemPoolRemovalReason reason, uint64_t mempool_sequence) override;
|
||||
/** Set the next time this wallet should resend transactions to 12-36 hours from now, ~1 day on average. */
|
||||
void SetNextResend() { m_next_resend = GetDefaultNextResend(); }
|
||||
/** Return true if all conditions for periodically resending transactions are met. */
|
||||
bool ShouldResend() const;
|
||||
void ResubmitWalletTransactions(bool relay, bool force);
|
||||
|
|
Loading…
Add table
Reference in a new issue