|
|
|
@ -1114,15 +1114,17 @@ void CWallet::ReacceptWalletTransactions()
@@ -1114,15 +1114,17 @@ void CWallet::ReacceptWalletTransactions()
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void CWalletTx::RelayWalletTransaction() |
|
|
|
|
bool CWalletTx::RelayWalletTransaction() |
|
|
|
|
{ |
|
|
|
|
if (!IsCoinBase()) |
|
|
|
|
{ |
|
|
|
|
if (GetDepthInMainChain() == 0) { |
|
|
|
|
LogPrintf("Relaying wtx %s\n", GetHash().ToString()); |
|
|
|
|
RelayTransaction((CTransaction)*this); |
|
|
|
|
return true; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
set<uint256> CWalletTx::GetConflicts() const |
|
|
|
@ -1324,42 +1326,51 @@ bool CWalletTx::IsTrusted() const
@@ -1324,42 +1326,51 @@ bool CWalletTx::IsTrusted() const
|
|
|
|
|
return true; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void CWallet::ResendWalletTransactions() |
|
|
|
|
std::vector<uint256> CWallet::ResendWalletTransactionsBefore(int64_t nTime) |
|
|
|
|
{ |
|
|
|
|
// Do this infrequently and randomly to avoid giving away
|
|
|
|
|
// that these are our transactions.
|
|
|
|
|
if (GetTime() < nNextResend) |
|
|
|
|
return; |
|
|
|
|
bool fFirst = (nNextResend == 0); |
|
|
|
|
nNextResend = GetTime() + GetRand(30 * 60); |
|
|
|
|
if (fFirst) |
|
|
|
|
return; |
|
|
|
|
|
|
|
|
|
// Only do it if there's been a new block since last time
|
|
|
|
|
if (nTimeBestReceived < nLastResend) |
|
|
|
|
return; |
|
|
|
|
nLastResend = GetTime(); |
|
|
|
|
std::vector<uint256> result; |
|
|
|
|
|
|
|
|
|
// Rebroadcast any of our txes that aren't in a block yet
|
|
|
|
|
LogPrintf("ResendWalletTransactions()\n"); |
|
|
|
|
{ |
|
|
|
|
LOCK(cs_wallet); |
|
|
|
|
// Sort them in chronological order
|
|
|
|
|
multimap<unsigned int, CWalletTx*> mapSorted; |
|
|
|
|
BOOST_FOREACH(PAIRTYPE(const uint256, CWalletTx)& item, mapWallet) |
|
|
|
|
{ |
|
|
|
|
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) |
|
|
|
|
// Don't rebroadcast if newer than nTime:
|
|
|
|
|
if (wtx.nTimeReceived > nTime) |
|
|
|
|
continue; |
|
|
|
|
mapSorted.insert(make_pair(wtx.nTimeReceived, &wtx)); |
|
|
|
|
} |
|
|
|
|
BOOST_FOREACH(PAIRTYPE(const unsigned int, CWalletTx*)& item, mapSorted) |
|
|
|
|
{ |
|
|
|
|
CWalletTx& wtx = *item.second; |
|
|
|
|
wtx.RelayWalletTransaction(); |
|
|
|
|
if (wtx.RelayWalletTransaction()) |
|
|
|
|
result.push_back(wtx.GetHash()); |
|
|
|
|
} |
|
|
|
|
return result; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void CWallet::ResendWalletTransactions(int64_t nBestBlockTime) |
|
|
|
|
{ |
|
|
|
|
// Do this infrequently and randomly to avoid giving away
|
|
|
|
|
// that these are our transactions.
|
|
|
|
|
if (GetTime() < nNextResend) |
|
|
|
|
return; |
|
|
|
|
bool fFirst = (nNextResend == 0); |
|
|
|
|
nNextResend = GetTime() + GetRand(30 * 60); |
|
|
|
|
if (fFirst) |
|
|
|
|
return; |
|
|
|
|
|
|
|
|
|
// Only do it if there's been a new block since last time
|
|
|
|
|
if (nBestBlockTime < nLastResend) |
|
|
|
|
return; |
|
|
|
|
nLastResend = GetTime(); |
|
|
|
|
|
|
|
|
|
// Rebroadcast unconfirmed txes older than 5 minutes before the last
|
|
|
|
|
// block was found:
|
|
|
|
|
std::vector<uint256> relayed = ResendWalletTransactionsBefore(nBestBlockTime-5*60); |
|
|
|
|
if (!relayed.empty()) |
|
|
|
|
LogPrintf("%s: rebroadcast %u unconfirmed transactions\n", __func__, relayed.size()); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** @} */ // end of mapWallet
|
|
|
|
|