From d5c96395c728154d40d426cdac4b9221416b64e8 Mon Sep 17 00:00:00 2001 From: CryptoManiac Date: Tue, 8 Mar 2016 20:59:28 +0300 Subject: [PATCH] ResendTX: forced rebroadcasting of unconfirmed transactions. --- src/main.cpp | 4 ++-- src/main.h | 2 +- src/rpcwallet.cpp | 2 +- src/wallet.cpp | 36 ++++++++++++++++++------------------ src/wallet.h | 2 +- 5 files changed, 23 insertions(+), 23 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 3ab03f2..bdc7e8d 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -181,10 +181,10 @@ void static Inventory(const uint256& hash) } // ask wallets to resend their transactions -void ResendWalletTransactions() +void ResendWalletTransactions(bool fForceResend) { BOOST_FOREACH(CWallet* pwallet, setpwalletRegistered) - pwallet->ResendWalletTransactions(); + pwallet->ResendWalletTransactions(fForceResend); } diff --git a/src/main.h b/src/main.h index c9e3fd5..63884b2 100644 --- a/src/main.h +++ b/src/main.h @@ -133,7 +133,7 @@ std::string GetWarnings(std::string strFor); bool GetTransaction(const uint256 &hash, CTransaction &tx, uint256 &hashBlock); uint256 WantedByOrphan(const CBlock* pblockOrphan); const CBlockIndex* GetLastBlockIndex(const CBlockIndex* pindex, bool fProofOfStake); -void ResendWalletTransactions(); +void ResendWalletTransactions(bool fForceResend=false); bool VerifySignature(const CTransaction& txFrom, const CTransaction& txTo, unsigned int nIn, unsigned int flags, int nHashType); diff --git a/src/rpcwallet.cpp b/src/rpcwallet.cpp index 5ef253f..bab881d 100644 --- a/src/rpcwallet.cpp +++ b/src/rpcwallet.cpp @@ -1862,7 +1862,7 @@ Value resendtx(const Array& params, bool fHelp) "Re-send unconfirmed transactions.\n" ); - ResendWalletTransactions(); + ResendWalletTransactions(true); return Value::null; } diff --git a/src/wallet.cpp b/src/wallet.cpp index 5976cb5..07518d0 100644 --- a/src/wallet.cpp +++ b/src/wallet.cpp @@ -1152,23 +1152,25 @@ void CWalletTx::RelayWalletTransaction() RelayWalletTransaction(txdb); } -void CWallet::ResendWalletTransactions() +void CWallet::ResendWalletTransactions(bool fForceResend) { - // Do this infrequently and randomly to avoid giving away - // that these are our transactions. - static int64_t nNextTime = GetRand(GetTime() + 30 * 60); - if (GetTime() < nNextTime) - return; - bool fFirst = (nNextTime == 0); - nNextTime = GetTime() + GetRand(30 * 60); - if (fFirst) - return; + if (!fForceResend) { + // Do this infrequently and randomly to avoid giving away + // that these are our transactions. + static int64_t nNextTime = GetRand(GetTime() + 30 * 60); + if (GetTime() < nNextTime) + return; + bool fFirst = (nNextTime == 0); + nNextTime = GetTime() + GetRand(30 * 60); + if (fFirst) + return; - // Only do it if there's been a new block since last time - static int64_t nLastTime = 0; - if (nTimeBestReceived < nLastTime) - return; - nLastTime = GetTime(); + // Only do it if there's been a new block since last time + static int64_t nLastTime = 0; + if (nTimeBestReceived < nLastTime) + return; + nLastTime = GetTime(); + } // Rebroadcast any of our txes that aren't in a block yet printf("ResendWalletTransactions()\n"); @@ -1182,7 +1184,7 @@ void CWallet::ResendWalletTransactions() CWalletTx& wtx = item.second; // Don't rebroadcast until it's had plenty of time that // it should have gotten in already by now. - if (nTimeBestReceived - (int64_t)wtx.nTimeReceived > 5 * 60) + if (fForceResend || nTimeBestReceived - (int64_t)wtx.nTimeReceived > 5 * 60) mapSorted.insert(make_pair(wtx.nTimeReceived, &wtx)); } BOOST_FOREACH(PAIRTYPE(const unsigned int, CWalletTx*)& item, mapSorted) @@ -2776,14 +2778,12 @@ void CWallet::GetAddresses(std::map &mapAddresses) con for(std::vector::const_iterator it3 = vAffected.begin(); it3 != vAffected.end(); it3++) { CBitcoinAddress addrAffected(*it3); - if (mapAddresses.find(addrAffected) != mapAddresses.end() && (mapAddresses[addrAffected] == 0 || mapAddresses[addrAffected] > wtx.nTime)) mapAddresses[addrAffected] = wtx.nTime; } vAffected.clear(); } } - } } diff --git a/src/wallet.h b/src/wallet.h index 493e9d9..6e36e9d 100644 --- a/src/wallet.h +++ b/src/wallet.h @@ -212,7 +212,7 @@ public: int ScanForWalletTransactions(CBlockIndex* pindexStart, bool fUpdate = false); int ScanForWalletTransaction(const uint256& hashTx); void ReacceptWalletTransactions(); - void ResendWalletTransactions(); + void ResendWalletTransactions(bool fForceResend=false); int64_t GetBalance() const; int64_t GetWatchOnlyBalance() const; int64_t GetUnconfirmedBalance() const; -- 1.7.1